Search in sources :

Example 6 with StringMsg

use of protos.StringMsg in project j2objc by google.

the class StringsTest method testReallyLongNonAsciiString.

public void testReallyLongNonAsciiString() throws Exception {
    char[] chars = new char[10000];
    Arrays.fill(chars, '﷽');
    String str = new String(chars);
    StringMsg msg = StringMsg.newBuilder().setNonAsciiF(str).build();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msg.writeTo(out);
    byte[] bytes = out.toByteArray();
    assertEquals(30004, bytes.length);
    for (int i = 4; i < 30004; ) {
        assertEquals((byte) 0xef, bytes[i++]);
        assertEquals((byte) 0xb7, bytes[i++]);
        assertEquals((byte) 0xbd, bytes[i++]);
    }
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    StringMsg msg2 = StringMsg.parseFrom(in);
    assertEquals(str, msg2.getNonAsciiF());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringMsg(protos.StringMsg) ByteString(com.google.protobuf.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 7 with StringMsg

use of protos.StringMsg in project j2objc by google.

the class StringsTest method testReallyLongString.

public void testReallyLongString() throws Exception {
    char[] chars = new char[10000];
    Arrays.fill(chars, 'a');
    String str = new String(chars);
    StringMsg msg = StringMsg.newBuilder().setAsciiF(str).build();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    msg.writeTo(out);
    byte[] bytes = out.toByteArray();
    assertEquals(10003, bytes.length);
    for (int i = 3; i < 10003; i++) {
        assertEquals('a', bytes[i]);
    }
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    StringMsg msg2 = StringMsg.parseFrom(in);
    assertEquals(str, msg2.getAsciiF());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StringMsg(protos.StringMsg) ByteString(com.google.protobuf.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

StringMsg (protos.StringMsg)7 ByteString (com.google.protobuf.ByteString)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 ExtensionRegistry (com.google.protobuf.ExtensionRegistry)2