Skip to content

Commit 40c4856

Browse files
committed
Update SerializingContext code.
1 parent f546463 commit 40c4856

File tree

4 files changed

+131
-0
lines changed

4 files changed

+131
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.kurrent.dbclient.v2;
2+
3+
import java.nio.ByteBuffer;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Functional interface for deserializing bytes into an object.
8+
*/
9+
@FunctionalInterface
10+
public interface DeserializeFunction {
11+
/**
12+
* Deserializes the given bytes into an object according to the provided metadata.
13+
*
14+
* @param data The bytes to be deserialized.
15+
* @param metadata The metadata providing additional information for the deserialization process.
16+
* @return A CompletableFuture that resolves to the deserialized object.
17+
*/
18+
CompletableFuture<Object> deserialize(ByteBuffer data, Metadata metadata);
19+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package io.kurrent.dbclient.v2;
2+
3+
import java.nio.ByteBuffer;
4+
import java.util.concurrent.CompletableFuture;
5+
import java.util.concurrent.CancellationException;
6+
7+
/**
8+
* Defines the interface for a schema serializer.
9+
*/
10+
public interface SchemaSerializer {
11+
/**
12+
* The type of the schema.
13+
*
14+
* @return The data format of the schema.
15+
*/
16+
SchemaDataFormat getDataFormat();
17+
18+
/**
19+
* Serializes the given value into bytes according to the provided context.
20+
*
21+
* @param value The object to be serialized.
22+
* @param context The context providing additional information for the serialization process.
23+
* @return A CompletableFuture that resolves to a ByteBuffer containing the serialized data.
24+
*/
25+
CompletableFuture<ByteBuffer> serialize(Object value, SerializationContext context);
26+
27+
/**
28+
* Deserializes the given bytes into an object according to the provided context.
29+
*
30+
* @param data The bytes to be deserialized.
31+
* @param context The context providing additional information for the deserialization process.
32+
* @return A CompletableFuture that resolves to the deserialized object.
33+
*/
34+
CompletableFuture<Object> deserialize(ByteBuffer data, SerializationContext context);
35+
36+
/**
37+
* Serializes the given message.
38+
*
39+
* @param message The message to be serialized.
40+
* @return A CompletableFuture that resolves to a ByteBuffer containing the serialized data.
41+
*/
42+
CompletableFuture<ByteBuffer> serialize(Message message);
43+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package io.kurrent.dbclient.v2;
2+
3+
/**
4+
* Allows the serialization operations to be autonomous.
5+
*/
6+
public final class SerializationContext {
7+
private final Metadata metadata;
8+
private final String stream;
9+
private final SchemaInfo schemaInfo;
10+
11+
/**
12+
* Initializes a new instance of the SerializationContext class with the specified metadata, stream, and cancellation flag.
13+
*
14+
* @param metadata The metadata providing additional information for the serialization process.
15+
* @param stream The stream that the record belongs to.
16+
*/
17+
public SerializationContext(Metadata metadata, String stream) {
18+
this.metadata = metadata;
19+
this.stream = stream;
20+
this.schemaInfo = SchemaInfo.fromMetadata(this.metadata);
21+
}
22+
23+
/**
24+
* Gets the metadata providing additional information for the serialization process.
25+
*
26+
* @return The metadata.
27+
*/
28+
public Metadata getMetadata() {
29+
return metadata;
30+
}
31+
32+
/**
33+
* Gets the stream that the record belongs to.
34+
*
35+
* @return The stream.
36+
*/
37+
public String getStream() {
38+
return stream;
39+
}
40+
41+
/**
42+
* Gets the schema information extracted from the headers.
43+
* If the headers do not contain schema information, it will return an undefined schema information.
44+
*
45+
* @return The schema information.
46+
*/
47+
public SchemaInfo getSchemaInfo() {
48+
return schemaInfo;
49+
}
50+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package io.kurrent.dbclient.v2;
2+
3+
import java.nio.ByteBuffer;
4+
import java.util.concurrent.CompletableFuture;
5+
6+
/**
7+
* Functional interface for serializing an object into bytes.
8+
*/
9+
@FunctionalInterface
10+
public interface SerializeFunction {
11+
/**
12+
* Serializes the given value into bytes according to the provided metadata.
13+
*
14+
* @param value The object to be serialized.
15+
* @param metadata The metadata providing additional information for the serialization process.
16+
* @return A CompletableFuture that resolves to a ByteBuffer containing the serialized data.
17+
*/
18+
CompletableFuture<ByteBuffer> serialize(Object value, Metadata metadata);
19+
}

0 commit comments

Comments
 (0)