Search in sources :

Example 26 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class PerformanceBenchmarks method testGetRepeatedFieldList.

private static void testGetRepeatedFieldList() {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllRepeatedFields(builder, 25);
    TypicalData data = builder.build();
    for (int i = 0; i < 2000; i++) {
        data.getRepeatedInt32List();
        data.getRepeatedInt64List();
        data.getRepeatedUint32List();
        data.getRepeatedUint64List();
        data.getRepeatedBoolList();
        data.getRepeatedFloatList();
        data.getRepeatedDoubleList();
        data.getRepeatedStringList();
        data.getRepeatedBytesList();
        data.getRepeatedEnumList();
    }
}
Also used : TypicalData(protos.TypicalData)

Example 27 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedDouble.

public void testSetAndGetRepeatedDouble() throws Exception {
    TypicalData data = TypicalData.newBuilder().addRepeatedDouble(0.5).build();
    assertEquals(1, data.getRepeatedDoubleCount());
    assertEquals(0.5, data.getRepeatedDouble(0), 0.0001);
}
Also used : TypicalData(protos.TypicalData)

Example 28 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetRepeatedEnum.

public void testSetAndGetRepeatedEnum() throws Exception {
    TypicalData data = TypicalData.newBuilder().addRepeatedEnum(TypicalData.EnumType.VALUE1).build();
    assertEquals(1, data.getRepeatedEnumCount());
    assertEquals(TypicalData.EnumType.VALUE1, data.getRepeatedEnum(0));
    assertEquals(TypicalData.EnumType.VALUE1, data.getRepeatedEnumList().get(0));
}
Also used : TypicalData(protos.TypicalData)

Example 29 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class CompatibilityTest method testSetAndGetExtensions.

public void testSetAndGetExtensions() throws Exception {
    TypicalDataMessage extensionMessage = TypicalDataMessage.newBuilder().setMyMessageInt(321).build();
    List<Integer> repeatedInts = new ArrayList<Integer>();
    repeatedInts.add(1);
    repeatedInts.add(2);
    List<TypicalDataMessage> repeatedData = new ArrayList<TypicalDataMessage>();
    repeatedData.add(TypicalDataMessage.newBuilder().setMyMessageInt(432).build());
    repeatedData.add(TypicalDataMessage.newBuilder().setMyMessageInt(543).build());
    TypicalData.Builder dataBuilder = TypicalData.newBuilder().setExtension(Typical.myPrimitiveExtension, 123).setExtension(Typical.myExtension, extensionMessage).setExtension(Typical.myRepeatedPrimitiveExtension, repeatedInts).addExtension(Typical.myRepeatedPrimitiveExtension, 3).setExtension(Typical.myRepeatedExtension, repeatedData).setExtension(Typical.myEnumExtension, TypicalData.EnumType.VALUE1).setExtension(Typical.myBytesExtension, ByteString.copyFrom("abc".getBytes())).setExtension(Typical.myBoolExtension, Boolean.TRUE).setExtension(MsgWithNestedExtensions.intExt, 456);
    checkGetExtensions(dataBuilder);
    checkGetExtensions(dataBuilder.build());
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    dataBuilder.build().writeTo(out);
    byte[] msgBytes = asBytes(new int[] { 0xC2, 0x3E, 0x03, 0x08, 0xC1, 0x02, 0xC8, 0x3E, 0x7B, 0xD0, 0x3E, 0x01, 0xD0, 0x3E, 0x02, 0xD0, 0x3E, 0x03, 0xDA, 0x3E, 0x03, 0x08, 0xB0, 0x03, 0xDA, 0x3E, 0x03, 0x08, 0x9F, 0x04, 0xE0, 0x3E, 0x01, 0xEA, 0x3E, 0x03, 0x61, 0x62, 0x63, 0xF0, 0x3E, 0x01, 0x80, 0x7D, 0xC8, 0x03 });
    checkBytes(msgBytes, out.toByteArray());
    ExtensionRegistry registry = ExtensionRegistry.newInstance();
    Typical.registerAllExtensions(registry);
    ByteArrayInputStream in = new ByteArrayInputStream(msgBytes);
    TypicalData data = TypicalData.newBuilder().mergeFrom(in, registry).build();
    checkGetExtensions(data);
}
Also used : TypicalDataMessage(protos.TypicalDataMessage) TypicalData(protos.TypicalData) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ExtensionRegistry(com.google.protobuf.ExtensionRegistry)

Example 30 with TypicalData

use of protos.TypicalData in project j2objc by google.

the class PerformanceBenchmarks method testGetRepeatedFieldsWithDescriptors.

private static void testGetRepeatedFieldsWithDescriptors() {
    TypicalData.Builder builder = TypicalData.newBuilder();
    setAllRepeatedFields(builder, 25);
    TypicalData data = builder.build();
    List<FieldDescriptor> fields = getRepeatedFieldDescriptors();
    for (int i = 0; i < 50; i++) {
        for (int j = 0; j < 25; j++) {
            for (FieldDescriptor field : fields) {
                data.getRepeatedField(field, j);
            }
        }
    }
}
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