io.protostuff.StringSerializer.STRING Java Examples
The following examples show how to use
io.protostuff.StringSerializer.STRING.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JsonEscapeTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testBar() throws Exception { Bar bar = new Bar(); bar.setSomeInt(1); bar.setSomeBytes(ByteString.copyFromUtf8(ESCAPE_TARGET)); bar.setSomeString(ESCAPE_TARGET); byte[] protostuff = ProtostuffIOUtil.toByteArray(bar, bar.cachedSchema(), buf()); byte[] json = JsonIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Bar.getPipeSchema(), false); byte[] json2 = JsonXIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff), Bar.getPipeSchema(), false, buf()); assertTrue(json.length == json2.length); String strJson = STRING.deser(json); String strJson2 = STRING.deser(json2); assertEquals(strJson, strJson2); System.err.println(strJson); System.err.println(strJson2); }
Example #2
Source File: YamlSerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testEmptyInnerBar() throws Exception { Bar barCompare = new Bar(); Baz baz = new Baz(); barCompare.setSomeBaz(baz); byte[] data = toByteArray(barCompare, barCompare.cachedSchema()); ByteArrayOutputStream out = new ByteArrayOutputStream(); writeTo(out, barCompare, barCompare.cachedSchema()); byte[] data2 = out.toByteArray(); String text = STRING.deser(data); String text2 = STRING.deser(data2); assertEquals(text, text2); print(text); }
Example #3
Source File: YamlSerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testBaz() throws Exception { for (Baz bazCompare : new Baz[] { baz, negativeBaz }) { byte[] data = toByteArray(bazCompare, bazCompare.cachedSchema()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int total = writeTo(out, bazCompare, bazCompare.cachedSchema()); assertTrue(data.length == total); byte[] data2 = out.toByteArray(); assertTrue(data.length == data2.length); String text = STRING.deser(data); String text2 = STRING.deser(data2); assertEquals(text, text2); } }
Example #4
Source File: YamlSerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testEmptyInnerFoo() throws Exception { Foo fooCompare = new Foo(); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(new Bar()); fooCompare.setSomeBar(bars); byte[] data = toByteArray(fooCompare, fooCompare.cachedSchema()); ByteArrayOutputStream out = new ByteArrayOutputStream(); writeTo(out, fooCompare, fooCompare.cachedSchema()); byte[] data2 = out.toByteArray(); String text = STRING.deser(data); String text2 = STRING.deser(data2); assertEquals(text, text2); print(text); }
Example #5
Source File: YamlSerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testBar() throws Exception { for (Bar barCompare : new Bar[] { bar, negativeBar }) { byte[] data = toByteArray(barCompare, barCompare.cachedSchema()); ByteArrayOutputStream out = new ByteArrayOutputStream(); int total = writeTo(out, barCompare, barCompare.cachedSchema()); assertTrue(data.length == total); byte[] data2 = out.toByteArray(); assertTrue(data.length == data2.length); String text = STRING.deser(data); String text2 = STRING.deser(data2); assertEquals(text, text2); } }
Example #6
Source File: YamlSerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testEmptyDeeperFoo() throws Exception { Bar bar = new Bar(); Baz baz = new Baz(); bar.setSomeBaz(baz); ArrayList<Bar> bars = new ArrayList<Bar>(); bars.add(bar); Foo foo = new Foo(); foo.setSomeBar(bars); byte[] data = toByteArray(foo, foo.cachedSchema()); ByteArrayOutputStream out = new ByteArrayOutputStream(); writeTo(out, foo, foo.cachedSchema()); byte[] data2 = out.toByteArray(); String text = STRING.deser(data); String text2 = STRING.deser(data2); assertEquals(text, text2); print(text); }
Example #7
Source File: XmlCoreSerDeserTest.java From protostuff with Apache License 2.0 | 6 votes |
@Test public void testUnknownScalarFields() throws Exception { String[] regularMessages = new String[] { "<?xml version='1.0' encoding='UTF-8'?>" + "<Baz><int>1</int><string>string</string>" + "<double>555.444</double><id>1</id></Baz>", "<?xml version='1.0' encoding='UTF-8'?>" + "<Baz><int>1</int><string>string</string>" + "<id>2</id><double>555.444</double></Baz>", "<?xml version='1.0' encoding='UTF-8'?>" + "<Baz><id>3</id><int>1</int>" + "<string>string</string><double>555.444</double>" + "<bytes><![CDATA[b2]]></bytes></Baz>" }; for (int i = 0; i < regularMessages.length; i++) { Baz b = new Baz(); XmlIOUtil.mergeFrom(STRING.ser(regularMessages[i]), b, b.cachedSchema()); assertTrue(i + 1 == b.getId()); } }
Example #8
Source File: KvpByteArrayInput.java From protostuff with Apache License 2.0 | 6 votes |
@Override public <T> int readFieldNumber(Schema<T> schema) throws IOException { if (offset == limit) return 0; final int size = buffer[offset++] | (buffer[offset++] << 8); final int number = numeric ? parseInt(buffer, offset, size, 10, true) : schema.getFieldNumber(STRING.deser(buffer, offset, size)); offset += size; if (number == 0) { // skip unknown fields. handleUnknownField(number, schema); return readFieldNumber(schema); } return number; }
Example #9
Source File: JsonCompareOutputsTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testFoo() throws Exception { Foo fooCompare = foo; byte[] jo = JSON_OUTPUT.serialize(fooCompare); byte[] jbo = JSON_BUFFERED_OUTPUT.serialize(fooCompare); byte[] jso = JSON_STREAMED_OUTPUT.serialize(fooCompare); assertTrue(jo.length == jbo.length); assertTrue(jso.length == jo.length); String joString = STRING.deser(jo); String jboString = STRING.deser(jbo); assertEquals(joString, jboString); assertEquals(joString, STRING.deser(jso)); }
Example #10
Source File: JsonCompareOutputsTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testFooNumeric() throws Exception { Foo fooCompare = foo; byte[] jo = JSON_OUTPUT_NUMERIC.serialize(fooCompare); byte[] jbo = JSON_BUFFERED_OUTPUT_NUMERIC.serialize(fooCompare); byte[] jso = JSON_STREAMED_OUTPUT_NUMERIC.serialize(fooCompare); assertTrue(jo.length == jbo.length); assertTrue(jso.length == jo.length); String joString = STRING.deser(jo); String jboString = STRING.deser(jbo); assertEquals(joString, jboString); assertEquals(joString, STRING.deser(jso)); }
Example #11
Source File: JsonCompareOutputsTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testBar() throws Exception { for (Bar barCompare : new Bar[] { bar, negativeBar }) { byte[] jo = JSON_OUTPUT.serialize(barCompare); byte[] jbo = JSON_BUFFERED_OUTPUT.serialize(barCompare); byte[] jso = JSON_STREAMED_OUTPUT.serialize(barCompare); assertTrue(jo.length == jbo.length); assertTrue(jso.length == jo.length); String joString = STRING.deser(jo); String jboString = STRING.deser(jbo); assertEquals(joString, jboString); assertEquals(joString, STRING.deser(jso)); } }
Example #12
Source File: JsonCompareOutputsTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testBarNumeric() throws Exception { for (Bar barCompare : new Bar[] { bar, negativeBar }) { byte[] jo = JSON_OUTPUT_NUMERIC.serialize(barCompare); byte[] jbo = JSON_BUFFERED_OUTPUT_NUMERIC.serialize(barCompare); byte[] jso = JSON_STREAMED_OUTPUT_NUMERIC.serialize(barCompare); assertTrue(jo.length == jbo.length); assertTrue(jso.length == jo.length); String joString = STRING.deser(jo); String jboString = STRING.deser(jbo); assertEquals(joString, jboString); assertEquals(joString, STRING.deser(jso)); } }
Example #13
Source File: JsonCompareOutputsTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testBaz() throws Exception { for (Baz bazCompare : new Baz[] { baz, negativeBaz }) { byte[] jo = JSON_OUTPUT.serialize(bazCompare); byte[] jbo = JSON_BUFFERED_OUTPUT.serialize(bazCompare); byte[] jso = JSON_STREAMED_OUTPUT.serialize(bazCompare); assertTrue(jo.length == jbo.length); assertTrue(jso.length == jo.length); String joString = STRING.deser(jo); String jboString = STRING.deser(jbo); assertEquals(joString, jboString); assertEquals(joString, STRING.deser(jso)); } }
Example #14
Source File: JsonCompareOutputsTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testBazNumeric() throws Exception { for (Baz bazCompare : new Baz[] { baz, negativeBaz }) { byte[] jo = JSON_OUTPUT_NUMERIC.serialize(bazCompare); byte[] jbo = JSON_BUFFERED_OUTPUT_NUMERIC.serialize(bazCompare); byte[] jso = JSON_STREAMED_OUTPUT_NUMERIC.serialize(bazCompare); assertTrue(jo.length == jbo.length); assertTrue(jso.length == jo.length); String joString = STRING.deser(jo); String jboString = STRING.deser(jbo); assertEquals(joString, jboString); assertEquals(joString, STRING.deser(jso)); } }
Example #15
Source File: StreamedStringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testDouble() throws Exception { for (double i : double_targets) { ByteArrayOutputStream out = new ByteArrayOutputStream(); LinkedBuffer lb = new LinkedBuffer(BUF_SIZE); WriteSession session = new WriteSession(lb, out); StreamedStringSerializer.writeDouble(i, session, lb); LinkedBuffer.writeTo(out, lb); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE); WriteSession session2 = new WriteSession(lb2, out2); StreamedStringSerializer.writeDouble(i, session2, lb2); LinkedBuffer.writeTo(out2, lb2); byte[] buffered = out.toByteArray(); byte[] buffered_needed_to_flush = out2.toByteArray(); byte[] builtin = STRING.ser(Double.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_flush); } }
Example #16
Source File: YamlPipeTest.java From protostuff with Apache License 2.0 | 6 votes |
static <T> void protostuffRoundTrip(T message, Schema<T> schema, Pipe.Schema<T> pipeSchema) throws Exception { byte[] protostuff = ProtostuffIOUtil.toByteArray(message, schema, buf()); ByteArrayInputStream protostuffStream = new ByteArrayInputStream(protostuff); byte[] yaml = YamlIOUtil.toByteArray( ProtostuffIOUtil.newPipe(protostuff, 0, protostuff.length), pipeSchema, buf()); byte[] yamlFromStream = YamlIOUtil.toByteArray( ProtostuffIOUtil.newPipe(protostuffStream), pipeSchema, buf()); assertTrue(yaml.length == yamlFromStream.length); String strYaml = STRING.deser(yaml); String strYamlFromStream = STRING.deser(yamlFromStream); assertEquals(strYaml, strYamlFromStream); }
Example #17
Source File: StreamedStringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testFloat() throws Exception { for (float i : float_targets) { ByteArrayOutputStream out = new ByteArrayOutputStream(); LinkedBuffer lb = new LinkedBuffer(BUF_SIZE); WriteSession session = new WriteSession(lb, out); StreamedStringSerializer.writeFloat(i, session, lb); LinkedBuffer.writeTo(out, lb); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE); WriteSession session2 = new WriteSession(lb2, out2); StreamedStringSerializer.writeFloat(i, session2, lb2); LinkedBuffer.writeTo(out2, lb2); byte[] buffered = out.toByteArray(); byte[] buffered_needed_to_flush = out2.toByteArray(); byte[] builtin = STRING.ser(Float.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_flush); } }
Example #18
Source File: StreamedStringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testLong() throws Exception { for (long i : long_targets) { ByteArrayOutputStream out = new ByteArrayOutputStream(); LinkedBuffer lb = new LinkedBuffer(BUF_SIZE); WriteSession session = new WriteSession(lb, out); StreamedStringSerializer.writeLong(i, session, lb); LinkedBuffer.writeTo(out, lb); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE); WriteSession session2 = new WriteSession(lb2, out2); StreamedStringSerializer.writeLong(i, session2, lb2); LinkedBuffer.writeTo(out2, lb2); byte[] buffered = out.toByteArray(); byte[] buffered_needed_to_flush = out2.toByteArray(); byte[] builtin = STRING.ser(Long.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_flush); } }
Example #19
Source File: CodedInput.java From protostuff with Apache License 2.0 | 6 votes |
/** * Read a {@code string} field value from the stream. */ @Override public String readString() throws IOException { final int size = readRawVarint32(); if (size <= (bufferSize - bufferPos) && size > 0) { // Fast path: We already have the bytes in a contiguous buffer, so // just copy directly from it. final String result = STRING.deser(buffer, bufferPos, size); bufferPos += size; return result; } else { // Slow path: Build a byte array first then copy it. return STRING.deser(readRawBytes(size)); } }
Example #20
Source File: StreamedStringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testInt() throws Exception { for (int i : int_targets) { ByteArrayOutputStream out = new ByteArrayOutputStream(); LinkedBuffer lb = new LinkedBuffer(BUF_SIZE); WriteSession session = new WriteSession(lb, out); StreamedStringSerializer.writeInt(i, session, lb); LinkedBuffer.writeTo(out, lb); ByteArrayOutputStream out2 = new ByteArrayOutputStream(); LinkedBuffer lb2 = new LinkedBuffer(NUM_BUF_SIZE); WriteSession session2 = new WriteSession(lb2, out2); StreamedStringSerializer.writeInt(i, session2, lb2); LinkedBuffer.writeTo(out2, lb2); byte[] buffered = out.toByteArray(); byte[] buffered_needed_to_flush = out2.toByteArray(); byte[] builtin = STRING.ser(Integer.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_flush); } }
Example #21
Source File: B64CodeTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testStringDecodeTo() throws Exception { for (String str : new String[] { "abcdefgh", "1", "12", "123", "1234", "12345" }) { byte[] b64Encoded = B64Code.encode(str.getBytes("UTF-8")); byte[] decoded = new byte[16]; int decodedLen = B64Code.decodeTo(decoded, 0, b64Encoded, 0, b64Encoded.length); String encodedString = new String(b64Encoded, "UTF-8"); byte[] decodedFromString = new byte[16]; int decodedFromStringLen = B64Code.decodeTo(decodedFromString, 0, encodedString, 0, encodedString.length()); assertEquals(STRING.deser(decoded, 0, decodedLen), STRING.deser(decodedFromString, 0, decodedFromStringLen)); assertEquals(str, STRING.deser(decoded, 0, decodedLen)); } }
Example #22
Source File: NumberParser.java From protostuff with Apache License 2.0 | 6 votes |
/** * Parse an ascii int from a raw buffer. */ public static int parseInt(final byte[] buffer, final int start, final int length, final int radix) throws NumberFormatException { if (length == 0) throw new NumberFormatException(STRING.deser(buffer, start, length)); if (buffer[start] == '-') { if (length == 1) throw new NumberFormatException(STRING.deser(buffer, start, length)); return parseInt(buffer, start + 1, length - 1, radix, false); } return parseInt(buffer, start, length, radix, true); }
Example #23
Source File: B64CodeTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testDecodeTo() throws Exception { for (String str : new String[] { "abcdefgh", "1", "12", "123", "1234", "12345" }) { byte[] b64Encoded = B64Code.encode(str.getBytes("UTF-8")); byte[] decoded = new byte[16]; int decodedLen = B64Code.decodeTo(decoded, 0, b64Encoded, 0, b64Encoded.length); byte[] decodedFromString = B64Code.decode(new String(b64Encoded, "UTF-8")); String a = STRING.deser(decoded, 0, decodedLen); String b = STRING.deser(decodedFromString); boolean x = a.equals(b); int lenA = a.length(); int lenB = b.length(); assertEquals(STRING.deser(decoded, 0, decodedLen), STRING.deser(decodedFromString)); assertEquals(str, STRING.deser(decoded, 0, decodedLen)); } }
Example #24
Source File: NumberParser.java From protostuff with Apache License 2.0 | 6 votes |
/** * Parse an ascii long from a raw buffer. */ public static long parseLong(final byte[] buffer, final int start, final int length, final int radix) throws NumberFormatException { if (length == 0) throw new NumberFormatException(STRING.deser(buffer, start, length)); if (buffer[start] == '-') { if (length == 1) throw new NumberFormatException(STRING.deser(buffer, start, length)); return parseLong(buffer, start + 1, length - 1, radix, false); } return parseLong(buffer, start, length, radix, true); }
Example #25
Source File: ByteBufInput.java From turbo-rpc with Apache License 2.0 | 6 votes |
@Override public String readString() throws IOException { if (SerializationConstants.INCOMPATIBLE_FAST_STRING_FORMAT) { return readStringFast(); } final int length = readRawVarint32(); if (length < 0) { throw negativeSize(); } if (byteBuf.readableBytes() < length) { throw misreportedSize(); } byte[] bytes = ThreadLocalBytes.current(); byteBuf.readBytes(bytes, 0, length); return STRING.deser(bytes, 0, length); }
Example #26
Source File: StringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testInt() throws Exception { for (int i : int_targets) { LinkedBuffer lb = new LinkedBuffer(256); WriteSession session = new WriteSession(lb); StringSerializer.writeInt(i, session, lb); LinkedBuffer lb2 = new LinkedBuffer(1); WriteSession session2 = new WriteSession(lb2); StringSerializer.writeInt(i, session2, lb2); byte[] buffered = session.toByteArray(); byte[] buffered_needed_to_grow = session2.toByteArray(); byte[] builtin = STRING.ser(Integer.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_grow); } }
Example #27
Source File: StringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testLong() throws Exception { for (long i : long_targets) { LinkedBuffer lb = new LinkedBuffer(256); WriteSession session = new WriteSession(lb); StringSerializer.writeLong(i, session, lb); LinkedBuffer lb2 = new LinkedBuffer(1); WriteSession session2 = new WriteSession(lb2); StringSerializer.writeLong(i, session2, lb2); byte[] buffered = session.toByteArray(); byte[] buffered_needed_to_grow = session2.toByteArray(); byte[] builtin = STRING.ser(Long.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_grow); } }
Example #28
Source File: StringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testFloat() throws Exception { for (float i : float_targets) { LinkedBuffer lb = new LinkedBuffer(256); WriteSession session = new WriteSession(lb); StringSerializer.writeFloat(i, session, lb); LinkedBuffer lb2 = new LinkedBuffer(1); WriteSession session2 = new WriteSession(lb2); StringSerializer.writeFloat(i, session2, lb2); byte[] buffered = session.toByteArray(); byte[] buffered_needed_to_grow = session2.toByteArray(); byte[] builtin = STRING.ser(Float.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_grow); } }
Example #29
Source File: StringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testDouble() throws Exception { for (double i : double_targets) { LinkedBuffer lb = new LinkedBuffer(256); WriteSession session = new WriteSession(lb); StringSerializer.writeDouble(i, session, lb); LinkedBuffer lb2 = new LinkedBuffer(1); WriteSession session2 = new WriteSession(lb2); StringSerializer.writeDouble(i, session2, lb2); byte[] buffered = session.toByteArray(); byte[] buffered_needed_to_grow = session2.toByteArray(); byte[] builtin = STRING.ser(Double.toString(i)); assertEquals(builtin, buffered); assertEquals(builtin, buffered_needed_to_grow); } }
Example #30
Source File: StringSerializerTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testLegacySurrogatePairs() throws Exception { LinkedBuffer lb = new LinkedBuffer(256); WriteSession session = new WriteSession(lb); StringSerializer.writeUTF8(surrogatePairs, session, lb); byte[] buffered = session.toByteArray(); // By default, STRING.deser should not use the custom // decoder (specifically, should not check the decoded // string for REPLACE characters). This means that legacy // encoded Strings with surrogate pairs will result in // malformed Strings assertNotSame(surrogatePairs, STRING.deser(legacySurrogatePairSerialized)); // New Strings, however, should be deserialized fine assertEquals(surrogatePairs, STRING.deser(buffered)); }