use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project java-chassis by ServiceComb.
the class TestAnySchema method json.
@Test
public void json() throws Throwable {
Root root = new Root();
root.setAny("abc");
scbRootBytes = rootSerializer.serialize(root);
root = rootDeserializer.deserialize(scbRootBytes);
Assert.assertEquals("abc", root.getAny());
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project java-chassis by ServiceComb.
the class TestCompatibilityOfImplementations method testEmptyCollection.
@Test
@SuppressWarnings("unchecked")
public void testEmptyCollection() throws Exception {
ProtobufRoot.Root.Builder builder = ProtobufRoot.Root.newBuilder();
byte[] values = protobuf.serialize(builder);
Assert.assertEquals(values.length, 0);
ProtobufRoot.Root.Builder o = (ProtobufRoot.Root.Builder) protobuf.deserialize(values);
Assert.assertTrue(o.getFixed32SNotPackedList().isEmpty());
builder = ProtobufRoot.Root.newBuilder().addFixed32SNotPacked(30);
values = protobuf.serialize(builder);
Assert.assertArrayEquals(new byte[] { (byte) -123, (byte) 6, (byte) 30, (byte) 0, (byte) 0, (byte) 0 }, values);
o = (ProtobufRoot.Root.Builder) protobuf.deserialize(values);
Assert.assertEquals(30, (int) o.getFixed32SNotPackedList().get(0));
Root root = new Root();
root.setFixed32sNotPacked(new ArrayList<>());
values = scbWeak.serialize(root);
Assert.assertEquals(values.length, 0);
Map<String, Object> newRootMap = (Map<String, Object>) scbWeak.deserialize(values);
Assert.assertEquals(null, // This is different , because depends on default model initializer
newRootMap.get("fixed32sNotPacked"));
List<Integer> iValues = new ArrayList<>();
iValues.add(30);
root.setFixed32sNotPacked(iValues);
values = scbWeak.serialize(root);
Assert.assertArrayEquals(new byte[] { (byte) -123, (byte) 6, (byte) 30, (byte) 0, (byte) 0, (byte) 0 }, values);
newRootMap = (Map<String, Object>) scbWeak.deserialize(values);
Assert.assertEquals(30, (int) ((List<Integer>) newRootMap.get("fixed32sNotPacked")).get(0));
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project incubator-servicecomb-java-chassis by apache.
the class TestAnySchema method json_fromMapWithoutType.
@SuppressWarnings("unchecked")
@Test
public void json_fromMapWithoutType() throws Throwable {
Map<String, Object> map = new HashMap<>();
map.put("name", "n1");
Root root = new Root();
root.setAny(map);
scbRootBytes = rootSerializer.serialize(root);
root = rootDeserializer.deserialize(scbRootBytes);
Assert.assertThat(root.getAny(), Matchers.instanceOf(Map.class));
Assert.assertThat((Map<? extends String, ? extends String>) root.getAny(), Matchers.hasEntry("name", "n1"));
RootDeserializer<Map<String, Object>> deserializer = protoMapper.createRootDeserializer("Root", Map.class);
map = deserializer.deserialize(scbRootBytes);
Assert.assertThat((Map<? extends String, ? extends String>) map.get("any"), Matchers.hasEntry("name", "n1"));
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project incubator-servicecomb-java-chassis by apache.
the class TestAnySchema method json.
@Test
public void json() throws Throwable {
Root root = new Root();
root.setAny("abc");
scbRootBytes = rootSerializer.serialize(root);
root = rootDeserializer.deserialize(scbRootBytes);
Assert.assertEquals("abc", root.getAny());
}
use of org.apache.servicecomb.foundation.protobuf.internal.model.Root in project incubator-servicecomb-java-chassis by apache.
the class Protostuff method deserialize.
@Override
public Object deserialize(byte[] bytes) throws IOException {
Input input = new ByteArrayInput(bytes, false);
Root result = new Root();
rootSchema.mergeFrom(input, result);
return result;
}
Aggregations