Search in sources :

Example 1 with MessageData

use of protos.MessageData in project j2objc by google.

the class MessagesTest method testMergeFromInputStream.

public void testMergeFromInputStream() throws Exception {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    MessageFields.registerAllExtensions(registry);
    ByteArrayInputStream in = new ByteArrayInputStream(ALL_MESSAGES_BYTES);
    MessageData.Builder builder = MessageData.newBuilder().mergeFrom(in, registry);
    MessageData msg = builder.build();
    checkFields(builder);
    checkFields(msg);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MessageData(protos.MessageData) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 2 with MessageData

use of protos.MessageData in project j2objc by google.

the class MessagesTest method testParseReversedMessageSets.

public void testParseReversedMessageSets() throws Exception {
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    MessageFields.registerAllExtensions(registry);
    MessageData msg = MessageData.parseFrom(ALL_MESSAGES_WITH_MESSAGE_SETS_REVERSED_BYTES, registry);
    checkFields(msg);
}
Also used : MessageData(protos.MessageData) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 3 with MessageData

use of protos.MessageData in project j2objc by google.

the class MessagesTest method testSerialization.

public void testSerialization() throws Exception {
    MessageData msg = getFilledMessage();
    assertEquals(168, msg.getSerializedSize());
    byte[] bytes1 = msg.toByteArray();
    checkBytes(ALL_MESSAGES_BYTES, bytes1);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msg.writeTo(out);
    byte[] bytes2 = out.toByteArray();
    checkBytes(ALL_MESSAGES_BYTES, bytes2);
}
Also used : MessageData(protos.MessageData) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 4 with MessageData

use of protos.MessageData 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);
}
Also used : MessageData(protos.MessageData) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 5 with MessageData

use of protos.MessageData 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());
}
Also used : SubMsg(protos.MessageData.SubMsg) GroupF(protos.MessageData.GroupF) MessageData(protos.MessageData) GroupFe(protos.GroupFe) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Aggregations

MessageData (protos.MessageData)6 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 GroupFe (protos.GroupFe)1 GroupF (protos.MessageData.GroupF)1 SubMsg (protos.MessageData.SubMsg)1