I have message type name in string and raw bytes. how to create java object by these meterials? b.proto
pakage foo;
message Bar {
required int32 id = 1;
required string name = 2;
}
TestMain.java
foo.Bar bar = foo.Bar.newBuilder()
.setId(1).setName("foobar").build();
byte[] rawbytes = bar.toByteArray();
String typeName = bar.getDescriptorForType().getFullName();
foo.Bar b = (foo.Bar) howTo(rawbyte, typeName);
foo.Barat compile-time (your last line shows that twice), you can go the normal route of deserialization. Please give more details about what you're trying to do.howToover using:foo.Boom bm = foo.Boom.parseFrom(rawBytes)? If you were trying to then use this just as a generic message that would make more sense, but if you know at compile-time what type you need, it just seems pointless.