use of org.infinispan.protostream.WrappedMessage in project protostream by infinispan.
the class ProtoSchemaBuilderTest method testGenericMessage.
@Test
public void testGenericMessage() throws Exception {
SerializationContext ctx = createContext();
String schema = new ProtoSchemaBuilder().fileName("generic_message.proto").addClass(GenericMessage.class).addClass(GenericMessage.OtherMessage.class).build(ctx);
assertTrue(schema.contains("message GenericMessage"));
GenericMessage genericMessage = new GenericMessage();
genericMessage.field1 = new WrappedMessage(3.1415d);
genericMessage.field2 = new WrappedMessage("qwerty".getBytes());
genericMessage.field3 = new WrappedMessage(new WrappedMessage("azerty"));
genericMessage.field4 = new WrappedMessage(new GenericMessage.OtherMessage("asdfg"));
byte[] bytes = ProtobufUtil.toWrappedByteArray(ctx, genericMessage);
GenericMessage o = ProtobufUtil.fromWrappedByteArray(ctx, bytes);
assertNotNull(o);
assertEquals(Double.class, genericMessage.field1.getValue().getClass());
assertEquals(3.1415d, genericMessage.field1.getValue());
assertArrayEquals("qwerty".getBytes(), (byte[]) genericMessage.field2.getValue());
assertEquals("azerty", ((WrappedMessage) genericMessage.field3.getValue()).getValue());
assertEquals("asdfg", ((GenericMessage.OtherMessage) genericMessage.field4.getValue()).field1);
}
use of org.infinispan.protostream.WrappedMessage in project protostream by infinispan.
the class AutoProtoSchemaBuilderTest method testGenericMessage.
@Test
public void testGenericMessage() throws Exception {
SerializationContext ctx = ProtobufUtil.newSerializationContext();
GeneratedSchema generatedSchema = new TestGenericMessageSerializationContextInitializerImpl();
generatedSchema.registerSchema(ctx);
generatedSchema.registerMarshallers(ctx);
assertTrue(generatedSchema.getProtoFile().contains("message GenericMessage"));
GenericMessage genericMessage = new GenericMessage();
genericMessage.field1 = new WrappedMessage(3.1415d);
genericMessage.field2 = new WrappedMessage("qwerty".getBytes());
genericMessage.field3 = new WrappedMessage(new WrappedMessage("azerty"));
genericMessage.field4 = new WrappedMessage(new GenericMessage.OtherMessage("asdfg"));
byte[] bytes = ProtobufUtil.toWrappedByteArray(ctx, genericMessage);
GenericMessage o = ProtobufUtil.fromWrappedByteArray(ctx, bytes);
assertNotNull(o);
assertEquals(Double.class, genericMessage.field1.getValue().getClass());
assertEquals(3.1415d, genericMessage.field1.getValue());
assertArrayEquals("qwerty".getBytes(), (byte[]) genericMessage.field2.getValue());
assertEquals("azerty", ((WrappedMessage) genericMessage.field3.getValue()).getValue());
assertEquals("asdfg", ((GenericMessage.OtherMessage) genericMessage.field4.getValue()).field1);
}
Aggregations