Created
April 11, 2017 00:14
-
-
Save knoguchi/7a94a8aaec5902d34a6ef1d93e0b31b9 to your computer and use it in GitHub Desktop.
Packed field test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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