Skip to content

Commit f97c195

Browse files
Remove Serde#schema. This is a leftover from a previous design, and it's currently unused. It might look different in future.
1 parent a3c4291 commit f97c195

File tree

5 files changed

+74
-48
lines changed

5 files changed

+74
-48
lines changed

sdk-api-kotlin/src/main/kotlin/dev/restate/sdk/kotlin/Service.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ private constructor(
121121
private val LOG = LogManager.getLogger()
122122
}
123123

124-
fun toHandlerDefinition() =
125-
HandlerDefinition(
126-
handlerSignature.name,
127-
handlerType,
128-
handlerSignature.requestSerde.schema(),
129-
handlerSignature.responseSerde.schema(),
130-
this)
124+
fun toHandlerDefinition() = HandlerDefinition(handlerSignature.name, handlerType, this)
131125

132126
override fun handle(
133127
syscalls: Syscalls,

sdk-api/src/main/java/dev/restate/sdk/Service.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,7 @@ public BiFunction<Context, REQ, RES> getRunner() {
132132
}
133133

134134
public HandlerDefinition<Service.Options> toHandlerDefinition() {
135-
return new HandlerDefinition<>(
136-
this.handlerSignature.name,
137-
this.handlerType,
138-
this.handlerSignature.requestSerde.schema(),
139-
this.handlerSignature.responseSerde.schema(),
140-
this);
135+
return new HandlerDefinition<>(this.handlerSignature.name, this.handlerType, this);
141136
}
142137

143138
@Override

sdk-common/src/main/java/dev/restate/sdk/common/Serde.java

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
import java.util.Objects;
1515
import org.jspecify.annotations.Nullable;
1616

17-
/** Interface defining serialization and deserialization of concrete types. */
17+
/**
18+
* Interface defining serialization and deserialization of concrete types.
19+
*
20+
* <p>You can create a custom one using {@link #using(String, ThrowingFunction, ThrowingFunction)}.
21+
*/
1822
public interface Serde<T> {
1923

2024
byte[] serialize(@Nullable T value);
@@ -30,20 +34,20 @@ default T deserialize(ByteString byteString) {
3034
return deserialize(byteString.toByteArray());
3135
}
3236

37+
// --- Metadata about the serialized/deserialized content
38+
3339
/**
34-
* @return the schema of this object.
40+
* Content-type to use in request/responses.
41+
*
42+
* <p>If null, the SDK assumes the produced output is empty. This might change in the future.
3543
*/
36-
default @Nullable Object schema() {
37-
return null;
38-
}
39-
4044
default @Nullable String contentType() {
41-
return null;
45+
return "application/octet-stream";
4246
}
4347

4448
/**
45-
* Create a {@link Serde} from {@code serializer}/{@code deserializer} lambdas. Before invoking
46-
* the serializer, we check that {@code value} is non-null.
49+
* Like {@link #using(String, ThrowingFunction, ThrowingFunction)}, using content-type {@code
50+
* application/octet-stream}.
4751
*/
4852
static <T> Serde<T> using(
4953
ThrowingFunction<T, byte[]> serializer, ThrowingFunction<byte[], T> deserializer) {
@@ -59,4 +63,59 @@ public T deserialize(byte[] value) {
5963
}
6064
};
6165
}
66+
67+
/**
68+
* Create a {@link Serde} from {@code serializer}/{@code deserializer} lambdas, tagging with
69+
* {@code contentType}. Before invoking the serializer, we check that {@code value} is non-null.
70+
*/
71+
static <T> Serde<T> using(
72+
String contentType,
73+
ThrowingFunction<T, byte[]> serializer,
74+
ThrowingFunction<byte[], T> deserializer) {
75+
return new Serde<>() {
76+
@Override
77+
public byte[] serialize(T value) {
78+
return serializer.asFunction().apply(Objects.requireNonNull(value));
79+
}
80+
81+
@Override
82+
public T deserialize(byte[] value) {
83+
return deserializer.asFunction().apply(value);
84+
}
85+
86+
@Override
87+
public @Nullable String contentType() {
88+
return contentType;
89+
}
90+
};
91+
}
92+
93+
static <T> Serde<T> withContentType(String contentType, Serde<T> inner) {
94+
return new Serde<>() {
95+
@Override
96+
public byte[] serialize(@Nullable T value) {
97+
return inner.serialize(value);
98+
}
99+
100+
@Override
101+
public ByteString serializeToByteString(@Nullable T value) {
102+
return inner.serializeToByteString(value);
103+
}
104+
105+
@Override
106+
public T deserialize(ByteString byteString) {
107+
return inner.deserialize(byteString);
108+
}
109+
110+
@Override
111+
public T deserialize(byte[] value) {
112+
return inner.deserialize(value);
113+
}
114+
115+
@Override
116+
public @Nullable String contentType() {
117+
return contentType;
118+
}
119+
};
120+
}
62121
}

sdk-common/src/main/java/dev/restate/sdk/common/syscalls/HandlerDefinition.java

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,11 @@
1414
public final class HandlerDefinition<O> {
1515
private final String name;
1616
private final HandlerType handlerType;
17-
private final Object inputSchema;
18-
private final Object outputSchema;
1917
private final InvocationHandler<O> handler;
2018

21-
public HandlerDefinition(
22-
String name,
23-
HandlerType handlerType,
24-
Object inputSchema,
25-
Object outputSchema,
26-
InvocationHandler<O> handler) {
19+
public HandlerDefinition(String name, HandlerType handlerType, InvocationHandler<O> handler) {
2720
this.name = name;
2821
this.handlerType = handlerType;
29-
this.inputSchema = inputSchema;
30-
this.outputSchema = outputSchema;
3122
this.handler = handler;
3223
}
3324

@@ -39,14 +30,6 @@ public HandlerType getHandlerType() {
3930
return handlerType;
4031
}
4132

42-
public Object getInputSchema() {
43-
return inputSchema;
44-
}
45-
46-
public Object getOutputSchema() {
47-
return outputSchema;
48-
}
49-
5033
public InvocationHandler<O> getHandler() {
5134
return handler;
5235
}
@@ -56,14 +39,11 @@ public boolean equals(Object object) {
5639
if (this == object) return true;
5740
if (object == null || getClass() != object.getClass()) return false;
5841
HandlerDefinition<?> that = (HandlerDefinition<?>) object;
59-
return Objects.equals(name, that.name)
60-
&& Objects.equals(inputSchema, that.inputSchema)
61-
&& Objects.equals(outputSchema, that.outputSchema)
62-
&& Objects.equals(handler, that.handler);
42+
return Objects.equals(name, that.name) && Objects.equals(handler, that.handler);
6343
}
6444

6545
@Override
6646
public int hashCode() {
67-
return Objects.hash(name, inputSchema, outputSchema, handler);
47+
return Objects.hash(name, handler);
6848
}
6949
}

sdk-core/src/test/java/dev/restate/sdk/core/ComponentDiscoveryHandlerTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ void handleWithMultipleServices() {
3232
new ServiceDefinition<>(
3333
"MyGreeter",
3434
ServiceType.SERVICE,
35-
List.of(
36-
new HandlerDefinition<>(
37-
"greet", HandlerType.EXCLUSIVE, null, null, null)))));
35+
List.of(new HandlerDefinition<>("greet", HandlerType.EXCLUSIVE, null)))));
3836

3937
DeploymentManifestSchema manifest = deploymentManifest.manifest();
4038

0 commit comments

Comments
 (0)