|
37 | 37 | import com.google.protobuf.ByteString;
|
38 | 38 | import com.google.protobuf.Descriptors;
|
39 | 39 | import com.google.protobuf.Descriptors.FileDescriptor.Syntax;
|
| 40 | +import com.google.protobuf.DiscardUnknownFieldsParser; |
| 41 | +import com.google.protobuf.Parser; |
40 | 42 | import org.slf4j.Logger;
|
41 | 43 | import org.slf4j.LoggerFactory;
|
42 | 44 |
|
|
53 | 55 | */
|
54 | 56 | public class ProtoToRowConverter {
|
55 | 57 | private static final Logger LOG = LoggerFactory.getLogger(ProtoToRowConverter.class);
|
56 |
| - private final Method parseFromMethod; |
57 | 58 | private final Method decodeMethod;
|
| 59 | + private final Parser<?> protoParser; |
58 | 60 | private boolean isCodeSplit = false;
|
59 | 61 |
|
60 | 62 | public ProtoToRowConverter(RowType rowType, PbFormatConfig formatConfig)
|
@@ -124,14 +126,16 @@ public ProtoToRowConverter(RowType rowType, PbFormatConfig formatConfig)
|
124 | 126 | codegenAppender.code());
|
125 | 127 | decodeMethod =
|
126 | 128 | generatedClass.getMethod(PbConstant.GENERATED_DECODE_METHOD, messageClass);
|
127 |
| - parseFromMethod = messageClass.getMethod(PbConstant.PB_METHOD_PARSE_FROM, byte[].class); |
| 129 | + Method parserMethod = messageClass.getMethod(PbConstant.PB_METHOD_PARSER); |
| 130 | + Parser originalProtoParser = (Parser) parserMethod.invoke(null); |
| 131 | + protoParser = DiscardUnknownFieldsParser.wrap(originalProtoParser); |
128 | 132 | } catch (Exception ex) {
|
129 | 133 | throw new PbCodegenException(ex);
|
130 | 134 | }
|
131 | 135 | }
|
132 | 136 |
|
133 | 137 | public RowData convertProtoBinaryToRow(byte[] data) throws Exception {
|
134 |
| - Object messageObj = parseFromMethod.invoke(null, data); |
| 138 | + Object messageObj = protoParser.parseFrom(data); |
135 | 139 | return (RowData) decodeMethod.invoke(null, messageObj);
|
136 | 140 | }
|
137 | 141 |
|
|
0 commit comments