Skip to content

Instantly share code, notes, and snippets.

@knoguchi
Created April 11, 2017 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save knoguchi/7a94a8aaec5902d34a6ef1d93e0b31b9 to your computer and use it in GitHub Desktop.
Save knoguchi/7a94a8aaec5902d34a6ef1d93e0b31b9 to your computer and use it in GitHub Desktop.
Packed field test
public void testPacked() throws Exception
{
byte[] protobufData;
final String SCHEMA_STR =
"package mypackage;\n"
+ "message t1 {\n"
+ " repeated uint32 report_code = 1 [packed=true];\n"
+ "}";
ProtobufSchema schema = MAPPER.schemaLoader()
.load(new StringReader(SCHEMA_STR));
//create binary of proto
PackedWrapper.t1 obj = PackedWrapper.t1.newBuilder()
.addReportCode(100)
.addReportCode(200)
.build();
ByteArrayOutputStream out = new ByteArrayOutputStream();
protobufData = obj.toByteArray();
JsonNode example = MAPPER.readerFor(JsonNode.class)
.with(schema)
.readValue(protobufData);
assertNotNull(example);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment