use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class MessagesTest method testParseFromByteArray.
public void testParseFromByteArray() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
MessageFields.registerAllExtensions(registry);
MessageData msg = MessageData.parseFrom(ALL_MESSAGES_BYTES, registry);
checkFields(msg);
}
use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class MessagesTest method testMergeExistingMessageFields.
public void testMergeExistingMessageFields() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
MessageFields.registerAllExtensions(registry);
MessageData toMerge = MessageData.newBuilder().setMsgF(SubMsg.newBuilder().setUintF(123).build()).setGroupF(GroupF.newBuilder().setUintF(234).build()).addMsgR(SubMsg.newBuilder().setUintF(345).build()).addGroupR(GroupR.newBuilder().setUintF(456).build()).setExtension(MessageFields.msgFe, SubMsg.newBuilder().setUintF(567).build()).setExtension(MessageFields.groupFe, GroupFe.newBuilder().setUintF(678).build()).addExtension(MessageFields.msgRe, SubMsg.newBuilder().setUintF(789).build()).addExtension(MessageFields.groupRe, GroupRe.newBuilder().setUintF(890).build()).build();
byte[] toMergeBytes = toMerge.toByteArray();
// Save the singular fields so we can verify that they aren't modified by merging.
SubMsg field1 = SubMsg.newBuilder().setIntF(321).build();
GroupF field2 = GroupF.newBuilder().setIntF(432).build();
SubMsg field3 = SubMsg.newBuilder().setIntF(765).build();
GroupFe field4 = GroupFe.newBuilder().setIntF(876).build();
MessageData.Builder builder = MessageData.newBuilder().setMsgF(field1).setGroupF(field2).addMsgR(SubMsg.newBuilder().setIntF(543).build()).addGroupR(GroupR.newBuilder().setIntF(654).build()).setExtension(MessageFields.msgFe, field3).setExtension(MessageFields.groupFe, field4).addExtension(MessageFields.msgRe, SubMsg.newBuilder().setIntF(987).build()).addExtension(MessageFields.groupRe, GroupRe.newBuilder().setIntF(98).build());
MessageData.Builder builder1 = builder.build().toBuilder();
builder1.mergeFrom(toMerge);
checkMergedFields(builder1);
MessageData.Builder builder2 = builder.build().toBuilder();
builder2.mergeFrom(toMergeBytes, registry);
// TODO(kstanger): This is a bug in the native ObjC runtime. It fails to
// merge message type extension fields when reading from data. Instead it
// just overwrites the existing message field.
//checkMergedFields(builder2);
assertFalse(field1.hasUintF());
assertFalse(field2.hasUintF());
assertFalse(field3.hasUintF());
assertFalse(field4.hasUintF());
}
use of com.google.protobuf.ExtensionRegistry in project j2objc by google.
the class CompatibilityTest method testMergeAndParseFromInputStream.
public void testMergeAndParseFromInputStream() throws Exception {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
registry.add(Typical.myPrimitiveExtension);
byte[] rawData = asBytes(new int[] { 0x08, 0x06, 0x60, 0x01, 0x7A, 0x03, 0x62, 0x61, 0x72, 0xC8, 0x3E, 0x2D });
checkMergeAndParse(TypicalData.newBuilder().mergeFrom(new ByteArrayInputStream(rawData), registry).build(), true);
checkMergeAndParse(TypicalData.parseFrom(new ByteArrayInputStream(rawData), registry), true);
// test API without ExtensionRegistry
checkMergeAndParse(TypicalData.newBuilder().mergeFrom(new ByteArrayInputStream(rawData)).build(), false);
checkMergeAndParse(TypicalData.parseFrom(new ByteArrayInputStream(rawData)), false);
}
use of com.google.protobuf.ExtensionRegistry in project heron by twitter.
the class ExtraActionUtils method getExtraActionInfo.
public static ExtraActionInfo getExtraActionInfo(String extraActionFile) {
ExtensionRegistry registry = ExtensionRegistry.newInstance();
ExtraActionsBase.registerAllExtensions(registry);
try (InputStream stream = Files.newInputStream(Paths.get(extraActionFile))) {
CodedInputStream coded = CodedInputStream.newInstance(stream);
return ExtraActionInfo.parseFrom(coded, registry);
} catch (IOException e) {
throw new RuntimeException("ERROR: failed to deserialize extra action file " + extraActionFile + ": " + e.getMessage(), e);
}
}
use of com.google.protobuf.ExtensionRegistry in project beam by apache.
the class ProtobufUtilTest method testRecursiveDescriptorsMessageCWithExtensions.
@Test
public void testRecursiveDescriptorsMessageCWithExtensions() {
// With extensions, Message C has a reference to Message A and Message B.
ExtensionRegistry registry = ExtensionRegistry.newInstance();
Proto2CoderTestMessages.registerAllExtensions(registry);
assertThat(getRecursiveDescriptorFullNames(MessageC.class, registry), equalTo(MESSAGE_C_EXT));
}
Aggregations