本文整理汇总了Java中io.protostuff.StringSerializer.STRING.deser方法的典型用法代码示例。如果您正苦于以下问题:Java STRING.deser方法的具体用法?Java STRING.deser怎么用?Java STRING.deser使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.protostuff.StringSerializer.STRING
的用法示例。
在下文中一共展示了STRING.deser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readString
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
/**
* 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));
}
}
示例2: testEmptyDeeperFoo
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
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);
}
示例3: protobufRoundTrip
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
static <T> void protobufRoundTrip(T message, Schema<T> schema,
Pipe.Schema<T> pipeSchema) throws Exception
{
byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf());
ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf);
byte[] yaml = YamlIOUtil.toByteArray(
ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length), pipeSchema, buf());
byte[] yamlFromStream = YamlIOUtil.toByteArray(
ProtobufIOUtil.newPipe(protobufStream), pipeSchema, buf());
assertTrue(yaml.length == yamlFromStream.length);
String strYaml = STRING.deser(yaml);
String strYamlFromStream = STRING.deser(yamlFromStream);
assertEquals(strYaml, strYamlFromStream);
}
示例4: testBarNumeric
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
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));
}
}
示例5: parseLong
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
/**
* 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);
}
示例6: readString
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
public String readString() throws IOException {
final int length = readRawVarint32();
if (length < 0) {
throw negativeSize();
}
if (buffer.readableBytes() < length) {
throw misreportedSize();
}
if (buffer.hasArray()) {
final int currPosition = buffer.readerIndex();
buffer.skipBytes(length);
return STRING.deser(buffer.array(),
buffer.arrayOffset() + currPosition,
length);
} else {
byte[] tmp = new byte[length];
buffer.readBytes(tmp);
return STRING.deser(tmp);
}
}
示例7: testBar
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
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);
}
示例8: testFooNumeric
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
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));
}
示例9: testBar
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
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);
}
}
示例10: testEmptyInnerFoo
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
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);
}
示例11: testFoo
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
public void testFoo() throws Exception
{
Bar bar = new Bar();
bar.setSomeInt(1);
bar.setSomeBytes(ByteString.copyFromUtf8(ESCAPE_TARGET));
bar.setSomeString(ESCAPE_TARGET);
ArrayList<Bar> bars = new ArrayList<Bar>();
bars.add(bar);
bars.add(bar);
ArrayList<String> strings = new ArrayList<String>();
strings.add(ESCAPE_TARGET);
strings.add("");
strings.add(ESCAPE_TARGET);
Foo foo = new Foo();
foo.setSomeBar(bars);
foo.setSomeString(strings);
byte[] protostuff = ProtostuffIOUtil.toByteArray(foo, foo.cachedSchema(), buf());
byte[] json = JsonIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff),
Foo.getPipeSchema(), false);
byte[] json2 = JsonXIOUtil.toByteArray(ProtostuffIOUtil.newPipe(protostuff),
Foo.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);
}
示例12: parseInt
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
static int parseInt(final byte[] buffer, int start, final int length,
final int radix, final boolean positive) throws NumberFormatException
{
int max = Integer.MIN_VALUE / radix;
int result = 0;
for (int offset = start, limit = start + length; offset < limit;)
{
int digit = Character.digit(buffer[offset++], radix);
if (digit == -1)
{
throw new NumberFormatException(STRING.deser(buffer, start, length));
}
if (max > result)
{
throw new NumberFormatException(STRING.deser(buffer, start, length));
}
int next = result * radix - digit;
if (next > result)
{
throw new NumberFormatException(STRING.deser(buffer, start, length));
}
result = next;
}
if (positive)
{
result = -result;
if (result < 0)
{
throw new NumberFormatException(STRING.deser(buffer, start, length));
}
}
return result;
}
示例13: roundTrip
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
@Override
protected <T> void roundTrip(T message, Schema<T> schema,
Pipe.Schema<T> pipeSchema) throws Exception
{
byte[] protobuf = ProtobufIOUtil.toByteArray(message, schema, buf());
ByteArrayInputStream protobufStream = new ByteArrayInputStream(protobuf);
byte[] protostuff = ProtostuffIOUtil.toByteArray(
ProtobufIOUtil.newPipe(protobuf, 0, protobuf.length),
pipeSchema, buf());
byte[] protostuffFromStream = ProtostuffIOUtil.toByteArray(
ProtobufIOUtil.newPipe(protobufStream), pipeSchema, buf());
assertTrue(protostuff.length == protostuffFromStream.length);
assertEquals(STRING.deser(protostuff),
STRING.deser(protostuffFromStream));
T parsedMessage = schema.newMessage();
ProtostuffIOUtil.mergeFrom(protostuff, parsedMessage, schema);
SerializableObjects.assertEquals(message, parsedMessage);
ByteArrayInputStream protostuffStream = new ByteArrayInputStream(
protostuff);
byte[] protobufRoundTrip = ProtobufIOUtil.toByteArray(
ProtostuffIOUtil.newPipe(protostuff, 0, protostuff.length),
pipeSchema, buf());
byte[] protobufRoundTripFromStream = ProtobufIOUtil.toByteArray(
ProtostuffIOUtil.newPipe(protostuffStream), pipeSchema, buf());
assertTrue(protobufRoundTrip.length == protobufRoundTripFromStream.length);
String strProtobufRoundTrip = STRING.deser(protobufRoundTrip);
assertEquals(strProtobufRoundTrip,
STRING.deser(protobufRoundTripFromStream));
assertTrue(protobufRoundTrip.length == protobuf.length);
assertEquals(strProtobufRoundTrip, STRING.deser(protobuf));
}
示例14: roundTrip
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
@Override
protected <T> void roundTrip(T message, Schema<T> schema,
Pipe.Schema<T> pipeSchema) throws Exception
{
byte[] json = JsonXIOUtil.toByteArray(message, schema, isNumeric(), buf());
ByteArrayInputStream jsonStream = new ByteArrayInputStream(json);
byte[] protostuff = ProtostuffIOUtil.toByteArray(
JsonIOUtil.newPipe(json, 0, json.length, isNumeric()), pipeSchema, buf());
byte[] protostuffFromStream = ProtostuffIOUtil.toByteArray(
JsonIOUtil.newPipe(jsonStream, isNumeric()), pipeSchema, buf());
assertTrue(Arrays.equals(protostuff, protostuffFromStream));
T parsedMessage = schema.newMessage();
ProtostuffIOUtil.mergeFrom(protostuff, parsedMessage, schema);
SerializableObjects.assertEquals(message, parsedMessage);
ByteArrayInputStream protostuffStream = new ByteArrayInputStream(protostuff);
byte[] jsonRoundTrip = JsonXIOUtil.toByteArray(
ProtostuffIOUtil.newPipe(protostuff, 0, protostuff.length), pipeSchema, isNumeric(), buf());
byte[] jsonRoundTripFromStream = JsonXIOUtil.toByteArray(
ProtostuffIOUtil.newPipe(protostuffStream), pipeSchema, isNumeric(), buf());
assertTrue(jsonRoundTrip.length == jsonRoundTripFromStream.length);
String strJsonRoundTrip = STRING.deser(jsonRoundTrip);
assertEquals(strJsonRoundTrip, STRING.deser(jsonRoundTripFromStream));
assertTrue(jsonRoundTrip.length == json.length);
assertEquals(strJsonRoundTrip, STRING.deser(json));
}
示例15: roundTrip
import io.protostuff.StringSerializer.STRING; //导入方法依赖的package包/类
@Override
protected <T> void roundTrip(T message, Schema<T> schema,
Pipe.Schema<T> pipeSchema) throws Exception
{
byte[] xml = XmlIOUtil.toByteArray(message, schema);
ByteArrayInputStream xmlStream = new ByteArrayInputStream(xml);
byte[] protostuff = ProtostuffIOUtil.toByteArray(
XmlIOUtil.newPipe(xml, 0, xml.length), pipeSchema, buf());
byte[] protostuffFromStream = ProtostuffIOUtil.toByteArray(
XmlIOUtil.newPipe(xmlStream), pipeSchema, buf());
assertTrue(Arrays.equals(protostuff, protostuffFromStream));
T parsedMessage = schema.newMessage();
ProtostuffIOUtil.mergeFrom(protostuff, parsedMessage, schema);
SerializableObjects.assertEquals(message, parsedMessage);
ByteArrayInputStream protostuffStream = new ByteArrayInputStream(protostuff);
byte[] xmlRoundTrip = XmlIOUtil.toByteArray(
ProtostuffIOUtil.newPipe(protostuff, 0, protostuff.length), pipeSchema);
byte[] xmlRoundTripFromStream = XmlIOUtil.toByteArray(
ProtostuffIOUtil.newPipe(protostuffStream), pipeSchema);
assertTrue(xmlRoundTrip.length == xmlRoundTripFromStream.length);
String strXmlRoundTrip = STRING.deser(xmlRoundTrip);
assertEquals(strXmlRoundTrip, STRING.deser(xmlRoundTripFromStream));
assertTrue(xmlRoundTrip.length == xml.length);
assertEquals(strXmlRoundTrip, STRING.deser(xml));
}