Class JsonXOutput
java.lang.Object
io.protostuff.WriteSession
io.protostuff.JsonXOutput
- All Implemented Interfaces:
Output, StatefulOutput
An optimized json output which is efficient in writing numeric keys and pre-encoded utf8 strings (in byte array
form).
This is the appropriate output sink to use when writing from binary (protostuff,protobuf,etc) pipes.
-
Nested Class Summary
Nested classes/interfaces inherited from class WriteSession
WriteSession.FlushHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byteprivate static final byte[]private static final byte[]private static final byteprivate static final byte[]private static final byte[]private static final byteprivate static final byte[](package private) static final byte[]private static final byte[]private static final byte[]private static final byte[]private static final byte[]private static final byte[]private static final byte[]private intprivate booleanprivate final booleanprivate static final byteprivate Schema<?> (package private) static final int[]private static final byteprivate static final byteprivate static final byte[]Fields inherited from class WriteSession
flushHandler, head, nextBufferSize, out, sink, size, tail -
Constructor Summary
ConstructorsConstructorDescriptionJsonXOutput(LinkedBuffer head, boolean numeric, Schema<?> schema) JsonXOutput(LinkedBuffer head, OutputStream out, boolean numeric, Schema<?> schema) JsonXOutput(LinkedBuffer head, OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize, boolean numeric, Schema<?> schema) -
Method Summary
Modifier and TypeMethodDescriptionclear()The buffer will be cleared (tail will point to the head) and the size will be reset to zero.intGets the last field number written.booleanReturns true if the last written field was a repeated field.booleanReturns whether the incoming messages' field names are numeric.voidreset()Resets this output for re-use.voidupdateLast(Schema<?> schema, Schema<?> lastSchema) Updates the schema iflastSchemawas indeed the last schema used.Before serializing a message/object tied to a schema, this should be called.voidwriteBool(int fieldNumber, boolean value, boolean repeated) Writes a boolean field.voidwriteByteArray(int fieldNumber, byte[] value, boolean repeated) Writes a byte array field.voidwriteByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) Writes a binary or a pre-encoded utf8 string.voidwriteBytes(int fieldNumber, ByteString value, boolean repeated) Writes a ByteString(wraps byte array) field.voidwriteBytes(int fieldNumber, ByteBuffer value, boolean repeated) Writes a ByteBuffer field.(package private) JsonXOutputvoidwriteDouble(int fieldNumber, double value, boolean repeated) Writes a double field.(package private) JsonXOutput(package private) JsonXOutputvoidwriteEnum(int fieldNumber, int value, boolean repeated) Writes a enum(its number) field.voidwriteFixed32(int fieldNumber, int value, boolean repeated) Writes a fixed int(4 bytes) field.voidwriteFixed64(int fieldNumber, long value, boolean repeated) Writes a fixed long(8 bytes) field.voidwriteFloat(int fieldNumber, float value, boolean repeated) Writes a float field.voidwriteInt32(int fieldNumber, int value, boolean repeated) Writes a variable int field.voidwriteInt64(int fieldNumber, long value, boolean repeated) Writes a variable long field.private LinkedBuffer<T> voidwriteObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) Writes an object(using its schema) field.voidwriteSFixed32(int fieldNumber, int value, boolean repeated) Writes a signed+fixed int(4 bytes) field.voidwriteSFixed64(int fieldNumber, long value, boolean repeated) Writes a signed+fixed long(8 bytes) field.voidwriteSInt32(int fieldNumber, int value, boolean repeated) Writes a signed int field.voidwriteSInt64(int fieldNumber, long value, boolean repeated) Writes a signed long field.(package private) JsonXOutput(package private) JsonXOutputvoidwriteString(int fieldNumber, CharSequence value, boolean repeated) Writes a String field.voidwriteUInt32(int fieldNumber, int value, boolean repeated) Writes an unsigned int field.voidwriteUInt64(int fieldNumber, long value, boolean repeated) Writes an unsigned long field.private static LinkedBufferwriteUTF8Escaped(byte[] input, int inStart, int inLen, WriteSink sink, WriteSession session, LinkedBuffer lb) private static LinkedBufferwriteUTF8Escaped(CharSequence str, WriteSink sink, WriteSession session, LinkedBuffer lb) Methods inherited from class WriteSession
flush, flush, flush, getSize, toByteArray
-
Field Details
-
START_OBJECT
private static final byte START_OBJECT- See Also:
-
END_OBJECT
private static final byte END_OBJECT- See Also:
-
START_ARRAY
private static final byte START_ARRAY- See Also:
-
END_ARRAY
private static final byte END_ARRAY- See Also:
-
COMMA
private static final byte COMMA- See Also:
-
QUOTE
private static final byte QUOTE- See Also:
-
TRUE
private static final byte[] TRUE -
FALSE
private static final byte[] FALSE -
KEY_SUFFIX_ARRAY
private static final byte[] KEY_SUFFIX_ARRAY -
KEY_SUFFIX_ARRAY_OBJECT
private static final byte[] KEY_SUFFIX_ARRAY_OBJECT -
KEY_SUFFIX_ARRAY_STRING
private static final byte[] KEY_SUFFIX_ARRAY_STRING -
KEY_SUFFIX_OBJECT
private static final byte[] KEY_SUFFIX_OBJECT -
KEY_SUFFIX_STRING
private static final byte[] KEY_SUFFIX_STRING -
KEY_SUFFIX
private static final byte[] KEY_SUFFIX -
COMMA_AND_QUOTE
private static final byte[] COMMA_AND_QUOTE -
COMMA_AND_START_OBJECT
private static final byte[] COMMA_AND_START_OBJECT -
END_ARRAY_AND_END_OBJECT
private static final byte[] END_ARRAY_AND_END_OBJECT -
END_ARRAY__COMMA__QUOTE
private static final byte[] END_ARRAY__COMMA__QUOTE -
schema
-
numeric
private final boolean numeric -
lastRepeated
private boolean lastRepeated -
lastNumber
private int lastNumber -
HEX_BYTES
static final byte[] HEX_BYTES -
sOutputEscapes
static final int[] sOutputEscapes
-
-
Constructor Details
-
JsonXOutput
-
JsonXOutput
public JsonXOutput(LinkedBuffer head, OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize, boolean numeric, Schema<?> schema) -
JsonXOutput
-
-
Method Details
-
reset
-
clear
Description copied from class:WriteSessionThe buffer will be cleared (tail will point to the head) and the size will be reset to zero.- Overrides:
clearin classWriteSession
-
use
Before serializing a message/object tied to a schema, this should be called. -
isNumeric
public boolean isNumeric()Returns whether the incoming messages' field names are numeric. -
getLastNumber
public int getLastNumber()Gets the last field number written. -
isLastRepeated
public boolean isLastRepeated()Returns true if the last written field was a repeated field. -
updateLast
Description copied from interface:StatefulOutputUpdates the schema iflastSchemawas indeed the last schema used.- Specified by:
updateLastin interfaceStatefulOutput
-
writeCommaAndStartObject
- Throws:
IOException
-
writeStartObject
- Throws:
IOException
-
writeEndObject
- Throws:
IOException
-
writeStartArray
- Throws:
IOException
-
writeEndArray
- Throws:
IOException
-
writeKey
- Throws:
IOException
-
writeBool
Description copied from interface:OutputWrites a boolean field.- Specified by:
writeBoolin interfaceOutput- Throws:
IOException
-
writeByteArray
Description copied from interface:OutputWrites a byte array field.- Specified by:
writeByteArrayin interfaceOutput- Throws:
IOException
-
writeByteRange
public void writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) throws IOException Description copied from interface:OutputWrites a binary or a pre-encoded utf8 string.- Specified by:
writeByteRangein interfaceOutput- Throws:
IOException
-
writeBytes
Description copied from interface:OutputWrites a ByteString(wraps byte array) field.- Specified by:
writeBytesin interfaceOutput- Throws:
IOException
-
writeDouble
Description copied from interface:OutputWrites a double field.- Specified by:
writeDoublein interfaceOutput- Throws:
IOException
-
writeEnum
Description copied from interface:OutputWrites a enum(its number) field.- Specified by:
writeEnumin interfaceOutput- Throws:
IOException
-
writeFixed32
Description copied from interface:OutputWrites a fixed int(4 bytes) field.- Specified by:
writeFixed32in interfaceOutput- Throws:
IOException
-
writeFixed64
Description copied from interface:OutputWrites a fixed long(8 bytes) field.- Specified by:
writeFixed64in interfaceOutput- Throws:
IOException
-
writeFloat
Description copied from interface:OutputWrites a float field.- Specified by:
writeFloatin interfaceOutput- Throws:
IOException
-
writeInt32
Description copied from interface:OutputWrites a variable int field.- Specified by:
writeInt32in interfaceOutput- Throws:
IOException
-
writeInt64
Description copied from interface:OutputWrites a variable long field.- Specified by:
writeInt64in interfaceOutput- Throws:
IOException
-
writeSFixed32
Description copied from interface:OutputWrites a signed+fixed int(4 bytes) field.- Specified by:
writeSFixed32in interfaceOutput- Throws:
IOException
-
writeSFixed64
Description copied from interface:OutputWrites a signed+fixed long(8 bytes) field.- Specified by:
writeSFixed64in interfaceOutput- Throws:
IOException
-
writeSInt32
Description copied from interface:OutputWrites a signed int field.- Specified by:
writeSInt32in interfaceOutput- Throws:
IOException
-
writeSInt64
Description copied from interface:OutputWrites a signed long field.- Specified by:
writeSInt64in interfaceOutput- Throws:
IOException
-
writeString
Description copied from interface:OutputWrites a String field.- Specified by:
writeStringin interfaceOutput- Throws:
IOException
-
writeUInt32
Description copied from interface:OutputWrites an unsigned int field.- Specified by:
writeUInt32in interfaceOutput- Throws:
IOException
-
writeUInt64
Description copied from interface:OutputWrites an unsigned long field.- Specified by:
writeUInt64in interfaceOutput- Throws:
IOException
-
writeObject
public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException Description copied from interface:OutputWrites an object(using its schema) field.- Specified by:
writeObjectin interfaceOutput- Throws:
IOException
-
writeUTF8Escaped
private static LinkedBuffer writeUTF8Escaped(byte[] input, int inStart, int inLen, WriteSink sink, WriteSession session, LinkedBuffer lb) throws IOException - Throws:
IOException
-
writeUTF8Escaped
private static LinkedBuffer writeUTF8Escaped(CharSequence str, WriteSink sink, WriteSession session, LinkedBuffer lb) throws IOException - Throws:
IOException
-
writeBytes
Writes a ByteBuffer field.- Specified by:
writeBytesin interfaceOutput- Throws:
IOException
-