private static DynamicMessage sdcFieldToProtobufMsg ( Record record , Field field , String fieldPath , Descriptors . Descriptor desc , Map < String , Set < Descriptors . FieldDescriptor > > messageTypeToExtensionMap , Map < String , Object > defaultValueMap ) throws DataGeneratorException { if ( field == null ) { return null ; } // compute all fields to look for including extensions DynamicMessage . Builder builder = DynamicMessage . newBuilder ( desc ) ; List < Descriptors . FieldDescriptor > fields = new ArrayList <> ( ) ; fields . addAll ( desc . getFields ( ) ) ; if ( messageTypeToExtensionMap . containsKey ( desc . getFullName ( ) ) ) { fields . addAll ( messageTypeToExtensionMap . get ( desc . getFullName ( ) ) ) ; } // root field is always a Map in a record representing protobuf data Map < String , Field > valueAsMap = field . getValueAsMap ( ) ; for ( Descriptors . FieldDescriptor f : fields ) { Field mapField = valueAsMap . get ( f . getName ( ) ) ; // Repeated field if ( f . isMapField ( ) ) { handleMapField ( record , mapField , fieldPath , messageTypeToExtensionMap , defaultValueMap , f , builder ) ; } else if ( f . isRepeated ( ) ) { if ( mapField != null ) { handleRepeatedField ( record , mapField , fieldPath , messageTypeToExtensionMap , defaultValueMap , f , builder ) ; } } else { // non repeated field handleNonRepeatedField ( record , valueAsMap , fieldPath , messageTypeToExtensionMap , defaultValueMap , desc , f , builder ) ; } } // if record has unknown fields for this field path, handle it try { handleUnknownFields ( record , fieldPath , builder ) ; } catch ( IOException e ) { throw new DataGeneratorException ( Errors . PROTOBUF_05 , e . toString ( ) , e ) ; } return builder . build ( ) ; }
Serializes a field path in a record to a protobuf message using the specified descriptor .