use of com.google.protobuf.DynamicMessage in project beam by apache.
the class ProtoDynamicMessageSchemaTest method testNullMapRowToProto.
@Test
public void testNullMapRowToProto() {
ProtoDynamicMessageSchema schemaProvider = schemaFromDescriptor(MapPrimitive.getDescriptor());
SerializableFunction<Row, DynamicMessage> fromRow = schemaProvider.getFromRowFunction();
MapPrimitive proto = parseFrom(fromRow.apply(NULL_MAP_PRIMITIVE_ROW).toString(), MapPrimitive.newBuilder()).build();
assertEquals(NULL_MAP_PRIMITIVE_PROTO, proto);
}
use of com.google.protobuf.DynamicMessage in project beam by apache.
the class DynamicProtoCoder method getParser.
/**
* Get the memoized {@link Parser}, possibly initializing it lazily.
*/
@Override
protected Parser<DynamicMessage> getParser() {
if (memoizedParser == null) {
DynamicMessage protoMessageInstance = DynamicMessage.newBuilder(domain.getDescriptor(messageName)).build();
memoizedParser = protoMessageInstance.getParserForType();
}
return memoizedParser;
}
use of com.google.protobuf.DynamicMessage in project beam by apache.
the class DynamicProtoCoderTest method testDynamicMessage.
@Test
public void testDynamicMessage() throws Exception {
DynamicMessage message = DynamicMessage.newBuilder(MessageA.getDescriptor()).setField(MessageA.getDescriptor().findFieldByNumber(MessageA.FIELD1_FIELD_NUMBER), "foo").build();
Coder<DynamicMessage> coder = DynamicProtoCoder.of(message.getDescriptorForType());
// Special code to check the DynamicMessage equality (@see IsDynamicMessageEqual)
for (Coder.Context context : ALL_CONTEXTS) {
CoderProperties.coderDecodeEncodeInContext(coder, context, message, IsDynamicMessageEqual.equalTo(message));
}
}
use of com.google.protobuf.DynamicMessage in project beam by apache.
the class BeamRowToStorageApiProtoTest method testMessageFromTableRow.
@Test
public void testMessageFromTableRow() throws Exception {
Descriptor descriptor = BeamRowToStorageApiProto.getDescriptorFromSchema(NESTED_SCHEMA);
DynamicMessage msg = BeamRowToStorageApiProto.messageFromBeamRow(descriptor, NESTED_ROW);
assertEquals(3, msg.getAllFields().size());
Map<String, FieldDescriptor> fieldDescriptors = descriptor.getFields().stream().collect(Collectors.toMap(FieldDescriptor::getName, Functions.identity()));
DynamicMessage nestedMsg = (DynamicMessage) msg.getField(fieldDescriptors.get("nested"));
assertBaseRecord(nestedMsg);
}
Aggregations