Skip to content

Commit 03a66ec

Browse files
committed
IPROTO-266 Allow for custom Encoder/Decoder implementations for TagWriter/TagReader
1 parent b3074e5 commit 03a66ec

File tree

3 files changed

+178
-154
lines changed

3 files changed

+178
-154
lines changed

core/src/main/java/org/infinispan/protostream/ProtobufUtil.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public static void writeTo(ImmutableSerializationContext ctx, OutputStream out,
7575
write(ctx, TagWriterImpl.newInstance(ctx, out), t);
7676
}
7777

78+
public static void writeTo(ImmutableSerializationContext ctx, TagWriterImpl.Encoder encoder, Object t) throws IOException {
79+
write(ctx, TagWriterImpl.newInstance(ctx, encoder), t);
80+
}
81+
7882
public static byte[] toByteArray(ImmutableSerializationContext ctx, Object t) throws IOException {
7983
ByteArrayOutputStream baos = new ByteArrayOutputStream(DEFAULT_ARRAY_BUFFER_SIZE);
8084
writeTo(ctx, baos, t);
@@ -112,6 +116,10 @@ public static <A> A fromByteBuffer(ImmutableSerializationContext ctx, ByteBuffer
112116
return readFrom(TagReaderImpl.newInstance(ctx, byteBuffer), clazz);
113117
}
114118

119+
public static <A> A fromDecoder(ImmutableSerializationContext ctx, TagReaderImpl.Decoder decoder, Class<A> clazz) throws IOException {
120+
return readFrom(TagReaderImpl.newInstance(ctx, decoder), clazz);
121+
}
122+
115123
/**
116124
* Parses a top-level message that was wrapped according to the org.infinispan.protostream.WrappedMessage proto
117125
* definition.
@@ -137,6 +145,10 @@ public static <A> A fromWrappedStream(ImmutableSerializationContext ctx, InputSt
137145
return WrappedMessage.read(ctx, TagReaderImpl.newInstance(ctx, in));
138146
}
139147

148+
public static <A> A fromWrappedDecoder(ImmutableSerializationContext ctx, TagReaderImpl.Decoder decoder) throws IOException {
149+
return WrappedMessage.read(ctx, TagReaderImpl.newInstance(ctx, decoder));
150+
}
151+
140152
//todo [anistor] should make it possible to plug in a custom wrapping strategy instead of the default one
141153
public static byte[] toWrappedByteArray(ImmutableSerializationContext ctx, Object t) throws IOException {
142154
return toWrappedByteArray(ctx, t, DEFAULT_ARRAY_BUFFER_SIZE);
@@ -162,6 +174,10 @@ public static void toWrappedStream(ImmutableSerializationContext ctx, OutputStre
162174
WrappedMessage.write(ctx, TagWriterImpl.newInstance(ctx, out, bufferSize), t);
163175
}
164176

177+
public static void toWrappedEncoder(ImmutableSerializationContext ctx, TagWriterImpl.Encoder encoder, Object t) throws IOException {
178+
WrappedMessage.write(ctx, TagWriterImpl.newInstance(ctx, encoder), t);
179+
}
180+
165181
/**
166182
* Converts a Protobuf encoded message to its <a href="https://developers.google.com/protocol-buffers/docs/proto3#json">
167183
* canonical JSON representation</a>.

0 commit comments

Comments
 (0)