@Test public void combineWithUnknownFields_innerMessagesUnknownsIgnored() throws InvalidProtocolBufferException { TestInnerMessageWithNewString test = TestInnerMessageWithNewString.newBuilder() .setInner(TestInnerMessageWithNewString.Inner.newBuilder() .setA("a1") .setB("b1") .build()) .build(); TestInnerMessage localRepresentation = TestInnerMessage.newBuilder() .setInner(TestInnerMessage.Inner.newBuilder() .setA("a2") .build()) .build(); TestInnerMessage combined = ProtoUtil.combineWithUnknownFields(localRepresentation, test.toByteArray()); TestInnerMessageWithNewString reparsedTest = TestInnerMessageWithNewString.parseFrom(combined.toByteArray()); Assert.assertEquals("a2", reparsedTest.getInner().getA()); Assert.assertEquals("", reparsedTest.getInner().getB()); }
@SuppressWarnings({"rawtypes", "unchecked"}) public static <Proto extends GeneratedMessageLite> Proto combineWithUnknownFields(Proto proto, byte[] serializedWithUnknownFields) { if (serializedWithUnknownFields == null) { return proto; } try { Proto protoWithUnknownFields = (Proto) proto.getParserForType().parseFrom(serializedWithUnknownFields); byte[] unknownFields = getUnknownFields(protoWithUnknownFields); if (unknownFields == null) { return proto; } byte[] combined = ByteUtil.combine(proto.toByteArray(), unknownFields); return (Proto) proto.getParserForType().parseFrom(combined); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(); } }
ProtoUtil { @SuppressWarnings({"rawtypes", "unchecked"}) public static <Proto extends GeneratedMessageLite> Proto combineWithUnknownFields(Proto proto, byte[] serializedWithUnknownFields) { if (serializedWithUnknownFields == null) { return proto; } try { Proto protoWithUnknownFields = (Proto) proto.getParserForType().parseFrom(serializedWithUnknownFields); byte[] unknownFields = getUnknownFields(protoWithUnknownFields); if (unknownFields == null) { return proto; } byte[] combined = ByteUtil.combine(proto.toByteArray(), unknownFields); return (Proto) proto.getParserForType().parseFrom(combined); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(); } } }
ProtoUtil { @SuppressWarnings({"rawtypes", "unchecked"}) public static <Proto extends GeneratedMessageLite> Proto combineWithUnknownFields(Proto proto, byte[] serializedWithUnknownFields) { if (serializedWithUnknownFields == null) { return proto; } try { Proto protoWithUnknownFields = (Proto) proto.getParserForType().parseFrom(serializedWithUnknownFields); byte[] unknownFields = getUnknownFields(protoWithUnknownFields); if (unknownFields == null) { return proto; } byte[] combined = ByteUtil.combine(proto.toByteArray(), unknownFields); return (Proto) proto.getParserForType().parseFrom(combined); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(); } } private  ProtoUtil(); }
ProtoUtil { @SuppressWarnings({"rawtypes", "unchecked"}) public static <Proto extends GeneratedMessageLite> Proto combineWithUnknownFields(Proto proto, byte[] serializedWithUnknownFields) { if (serializedWithUnknownFields == null) { return proto; } try { Proto protoWithUnknownFields = (Proto) proto.getParserForType().parseFrom(serializedWithUnknownFields); byte[] unknownFields = getUnknownFields(protoWithUnknownFields); if (unknownFields == null) { return proto; } byte[] combined = ByteUtil.combine(proto.toByteArray(), unknownFields); return (Proto) proto.getParserForType().parseFrom(combined); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(); } } private  ProtoUtil(); @SuppressWarnings("rawtypes") static boolean hasUnknownFields(GeneratedMessageLite rootProto); @SuppressWarnings({"rawtypes", "unchecked"}) static Proto combineWithUnknownFields(Proto proto, byte[] serializedWithUnknownFields); }
ProtoUtil { @SuppressWarnings({"rawtypes", "unchecked"}) public static <Proto extends GeneratedMessageLite> Proto combineWithUnknownFields(Proto proto, byte[] serializedWithUnknownFields) { if (serializedWithUnknownFields == null) { return proto; } try { Proto protoWithUnknownFields = (Proto) proto.getParserForType().parseFrom(serializedWithUnknownFields); byte[] unknownFields = getUnknownFields(protoWithUnknownFields); if (unknownFields == null) { return proto; } byte[] combined = ByteUtil.combine(proto.toByteArray(), unknownFields); return (Proto) proto.getParserForType().parseFrom(combined); } catch (InvalidProtocolBufferException e) { throw new IllegalArgumentException(); } } private  ProtoUtil(); @SuppressWarnings("rawtypes") static boolean hasUnknownFields(GeneratedMessageLite rootProto); @SuppressWarnings({"rawtypes", "unchecked"}) static Proto combineWithUnknownFields(Proto proto, byte[] serializedWithUnknownFields);  }