use of org.infinispan.protostream.TagWriter in project protostream by infinispan.
the class TagWriterImplTest method testOutputStreamEncodeAndDecode.
@Test
public void testOutputStreamEncodeAndDecode() throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream(MAX_BYTE_ARRAY_SIZE);
doTest(new Factory() {
@Override
public TagWriter newWriter(SerializationContext ctx) {
return TagWriterImpl.newInstance(ctx, baos);
}
@Override
public TagReader newReader(SerializationContext ctx) {
return TagReaderImpl.newInstance(ctx, new ByteArrayInputStream(baos.toByteArray()));
}
});
}
use of org.infinispan.protostream.TagWriter in project protostream by infinispan.
the class FullBufferReadTest method testFullArrayMarshaller.
@Test
public void testFullArrayMarshaller() throws Exception {
SerializationContext ctx = createContext();
FileDescriptorSource fileDescriptorSource = new FileDescriptorSource().addProtoFile("file.proto", file);
ctx.registerProtoFiles(fileDescriptorSource);
class MockMarshallerFuncs implements MarshallerFuncs<X> {
public byte[] actualBytes = null;
public boolean isInputStream = false;
@Override
public X read(ReadContext rc) throws IOException {
TagReader r = rc.getReader();
isInputStream = r.isInputStream();
actualBytes = r.fullBufferArray();
return null;
}
@Override
public void write(WriteContext wc, X p) throws IOException {
TagWriter w = wc.getWriter();
w.writeInt32(1, p.f1);
w.writeInt64(2, p.f2);
}
}
MockMarshallerFuncs mockMarshallerFuncs = new MockMarshallerFuncs();
ctx.registerMarshallerProvider(new MockProtobufMarshaller<>(X.class, "test.X", mockMarshallerFuncs));
byte[] fullMsgBytes = ProtobufUtil.toWrappedByteArray(ctx, new X(1234, 4321L));
ProtobufUtil.fromWrappedByteArray(ctx, fullMsgBytes);
assertNotNull(mockMarshallerFuncs.actualBytes);
assertEquals(6, mockMarshallerFuncs.actualBytes.length);
assertFalse(mockMarshallerFuncs.isInputStream);
byte[] expectedBytes = { 8, -46, 9, 16, -31, 33 };
assertNotNull(expectedBytes);
assertTrue(Arrays.equals(mockMarshallerFuncs.actualBytes, expectedBytes));
}
Aggregations