Search in sources :

Example 1 with ExtBase

use of com.groupon.jesos.TestProtos.ExtBase in project jesos by groupon.

the class TestProtobufRegistry method testRoundtrip.

@Test
public void testRoundtrip() throws Exception {
    ExtensionRegistry e = ProtobufRegistry.INSTANCE.mutableExtensionRegistry();
    TestProtos.registerAllExtensions(e);
    ExtBase extBase = ExtBase.newBuilder().setA("172.42.1.2").setB("br0").setD(24).setC("172.42.1.1").setE("00:11:22:33:44:55").build();
    Base base = Base.newBuilder().setExtension(ExtBase.type, extBase).setType(Base.Type.EXT_BASE).build();
    byte[] bytes = base.toByteArray();
    Base generated = Base.parseFrom(new ByteArrayInputStream(bytes), e);
    ExtBase extGenerated = generated.getExtension(ExtBase.type);
    assertEquals(extBase.getA(), extGenerated.getA());
    assertEquals(extBase.getB(), extGenerated.getB());
    assertEquals(extBase.getC(), extGenerated.getC());
    assertEquals(extBase.getD(), extGenerated.getD());
    assertEquals(extBase.getE(), extGenerated.getE());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ExtBase(com.groupon.jesos.TestProtos.ExtBase) ExtBase(com.groupon.jesos.TestProtos.ExtBase) Base(com.groupon.jesos.TestProtos.Base) ExtensionRegistry(com.google.protobuf.ExtensionRegistry) Test(org.junit.Test)

Aggregations

ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1 Base (com.groupon.jesos.TestProtos.Base)1 ExtBase (com.groupon.jesos.TestProtos.ExtBase)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Test (org.junit.Test)1