Search in sources :

Example 21 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedBytes.

public void testSetAndGetRepeatedBytes() throws Exception {
    List<ByteString> list = new ArrayList<ByteString>();
    list.add(ByteString.copyFrom("def".getBytes()));
    list.add(ByteString.copyFrom("ghi".getBytes()));
    TypicalData data = TypicalData.newBuilder().addRepeatedBytes(ByteString.copyFrom("abc".getBytes())).addAllRepeatedBytes(list).setRepeatedBytes(2, ByteString.copyFrom("jkl".getBytes())).build();
    assertEquals(3, data.getRepeatedBytesCount());
    assertEquals("abc", new String(data.getRepeatedBytes(0).toByteArray()));
    byte[] bytes = data.toByteArray();
    TypicalData other = TypicalData.parseFrom(bytes);
    assertEquals("abc", new String(other.getRepeatedBytes(0).toByteArray()));
    assertEquals("def", new String(other.getRepeatedBytesList().get(1).toByteArray()));
    assertEquals("jkl", new String(other.getRepeatedBytes(2).toByteArray()));
}
Also used : TypicalData(protos.TypicalData) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString)

Example 22 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testMergeFrom.

public void testMergeFrom() throws Exception {
    TypicalData input = TypicalData.newBuilder().setMyInt(42).setMyMessage(TypicalDataMessage.newBuilder().setMyMessageInt(43)).build();
    TypicalData output = TypicalData.newBuilder().mergeFrom(input.toByteString(), ExtensionRegistry.getEmptyRegistry()).build();
    assertEquals(42, output.getMyInt());
    assertEquals(43, output.getMyMessage().getMyMessageInt());
}
Also used : TypicalData(protos.TypicalData)

Example 23 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testParseDelimitedFromEmptyStream.

public void testParseDelimitedFromEmptyStream() throws Exception {
    TypicalData output = TypicalData.parseDelimitedFrom(new ByteArrayInputStream(new byte[0]));
    assertNull(output);
}
Also used : TypicalData(protos.TypicalData) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 24 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class PerformanceBenchmarks method testGetRepeatedFields.

private static void testGetRepeatedFields() {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllRepeatedFields(builder, 25);
    TypicalData data = builder.build();
    for (int i = 0; i < 3000; i++) {
        for (int j = 0; j < 25; j++) {
            data.getRepeatedInt32(j);
            data.getRepeatedInt64(j);
            data.getRepeatedUint32(j);
            data.getRepeatedUint64(j);
            data.getRepeatedBool(j);
            data.getRepeatedFloat(j);
            data.getRepeatedDouble(j);
            data.getRepeatedString(j);
            data.getRepeatedBytes(j);
            data.getRepeatedEnum(j);
        }
    }
}
Also used : TypicalData(protos.TypicalData)

Example 25 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class PerformanceBenchmarks method testGetPrimitiveFieldsWithDescriptors.

private static void testGetPrimitiveFieldsWithDescriptors() {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllPrimitiveFields(builder);
    TypicalData data = builder.build();
    List<FieldDescriptor> fields = getPrimitiveFieldDescriptors();
    for (int i = 0; i < 10000; i++) {
        for (FieldDescriptor field : fields) {
            data.getField(field);
        }
    }
}
Also used : TypicalData(protos.TypicalData) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Aggregations

TypicalData (protos.TypicalData)39 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TypicalDataMessage (protos.TypicalDataMessage)5 ByteString (com.google.protobuf.ByteString)3 FieldDescriptor (com.google.protobuf.Descriptors.FieldDescriptor)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)3 ArrayList (java.util.ArrayList)3 MessageLite (com.google.protobuf.MessageLite)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Descriptor (com.google.protobuf.Descriptors.Descriptor)1 EnumDescriptor (com.google.protobuf.Descriptors.EnumDescriptor)1 EnumValueDescriptor (com.google.protobuf.Descriptors.EnumValueDescriptor)1 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)1 ExtensionRegistryLite (com.google.protobuf.ExtensionRegistryLite)1 GeneratedMessage (com.google.protobuf.GeneratedMessage)1 ExtendableMessageOrBuilder (com.google.protobuf.GeneratedMessage.ExtendableMessageOrBuilder)1 Message (com.google.protobuf.Message)1 ProtocolMessageEnum (com.google.protobuf.ProtocolMessageEnum)1