Package io.protostuff
Class JsonXOutput
- java.lang.Object
-
- io.protostuff.WriteSession
-
- io.protostuff.JsonXOutput
-
- All Implemented Interfaces:
Output
,StatefulOutput
public final class JsonXOutput extends WriteSession implements 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 io.protostuff.WriteSession
WriteSession.FlushHandler
-
-
Field Summary
Fields Modifier and Type Field Description private static byte
COMMA
private static byte[]
COMMA_AND_QUOTE
private static byte[]
COMMA_AND_START_OBJECT
private static byte
END_ARRAY
private static byte[]
END_ARRAY__COMMA__QUOTE
private static byte[]
END_ARRAY_AND_END_OBJECT
private static byte
END_OBJECT
private static byte[]
FALSE
(package private) static byte[]
HEX_BYTES
private static byte[]
KEY_SUFFIX
private static byte[]
KEY_SUFFIX_ARRAY
private static byte[]
KEY_SUFFIX_ARRAY_OBJECT
private static byte[]
KEY_SUFFIX_ARRAY_STRING
private static byte[]
KEY_SUFFIX_OBJECT
private static byte[]
KEY_SUFFIX_STRING
private int
lastNumber
private boolean
lastRepeated
private boolean
numeric
private static byte
QUOTE
private Schema<?>
schema
(package private) static int[]
sOutputEscapes
private static byte
START_ARRAY
private static byte
START_OBJECT
private static byte[]
TRUE
-
Fields inherited from class io.protostuff.WriteSession
flushHandler, head, nextBufferSize, out, sink, size, tail
-
-
Constructor Summary
Constructors Constructor Description JsonXOutput(LinkedBuffer head, boolean numeric, Schema<?> schema)
JsonXOutput(LinkedBuffer head, java.io.OutputStream out, boolean numeric, Schema<?> schema)
JsonXOutput(LinkedBuffer head, java.io.OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize, boolean numeric, Schema<?> schema)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description JsonXOutput
clear()
The buffer will be cleared (tail will point to the head) and the size will be reset to zero.int
getLastNumber()
Gets the last field number written.boolean
isLastRepeated()
Returns true if the last written field was a repeated field.boolean
isNumeric()
Returns whether the incoming messages' field names are numeric.void
reset()
Resets this output for re-use.void
updateLast(Schema<?> schema, Schema<?> lastSchema)
Updates the schema iflastSchema
was indeed the last schema used.JsonXOutput
use(Schema<?> schema)
Before serializing a message/object tied to a schema, this should be called.void
writeBool(int fieldNumber, boolean value, boolean repeated)
Writes a boolean field.void
writeByteArray(int fieldNumber, byte[] value, boolean repeated)
Writes a byte array field.void
writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated)
Writes a binary or a pre-encoded utf8 string.void
writeBytes(int fieldNumber, ByteString value, boolean repeated)
Writes a ByteString(wraps byte array) field.void
writeBytes(int fieldNumber, java.nio.ByteBuffer value, boolean repeated)
Writes a ByteBuffer field.(package private) JsonXOutput
writeCommaAndStartObject()
void
writeDouble(int fieldNumber, double value, boolean repeated)
Writes a double field.(package private) JsonXOutput
writeEndArray()
(package private) JsonXOutput
writeEndObject()
void
writeEnum(int fieldNumber, int value, boolean repeated)
Writes a enum(its number) field.void
writeFixed32(int fieldNumber, int value, boolean repeated)
Writes a fixed int(4 bytes) field.void
writeFixed64(int fieldNumber, long value, boolean repeated)
Writes a fixed long(8 bytes) field.void
writeFloat(int fieldNumber, float value, boolean repeated)
Writes a float field.void
writeInt32(int fieldNumber, int value, boolean repeated)
Writes a variable int field.void
writeInt64(int fieldNumber, long value, boolean repeated)
Writes a variable long field.private LinkedBuffer
writeKey(int fieldNumber, WriteSink sink, byte[] keySuffix)
<T> void
writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated)
Writes an object(using its schema) field.void
writeSFixed32(int fieldNumber, int value, boolean repeated)
Writes a signed+fixed int(4 bytes) field.void
writeSFixed64(int fieldNumber, long value, boolean repeated)
Writes a signed+fixed long(8 bytes) field.void
writeSInt32(int fieldNumber, int value, boolean repeated)
Writes a signed int field.void
writeSInt64(int fieldNumber, long value, boolean repeated)
Writes a signed long field.(package private) JsonXOutput
writeStartArray()
(package private) JsonXOutput
writeStartObject()
void
writeString(int fieldNumber, java.lang.CharSequence value, boolean repeated)
Writes a String field.void
writeUInt32(int fieldNumber, int value, boolean repeated)
Writes an unsigned int field.void
writeUInt64(int fieldNumber, long value, boolean repeated)
Writes an unsigned long field.private static LinkedBuffer
writeUTF8Escaped(byte[] input, int inStart, int inLen, WriteSink sink, WriteSession session, LinkedBuffer lb)
private static LinkedBuffer
writeUTF8Escaped(java.lang.CharSequence str, WriteSink sink, WriteSession session, LinkedBuffer lb)
-
Methods inherited from class io.protostuff.WriteSession
flush, flush, flush, getSize, toByteArray
-
-
-
-
Field Detail
-
START_OBJECT
private static final byte START_OBJECT
- See Also:
- Constant Field Values
-
END_OBJECT
private static final byte END_OBJECT
- See Also:
- Constant Field Values
-
START_ARRAY
private static final byte START_ARRAY
- See Also:
- Constant Field Values
-
END_ARRAY
private static final byte END_ARRAY
- See Also:
- Constant Field Values
-
COMMA
private static final byte COMMA
- See Also:
- Constant Field Values
-
QUOTE
private static final byte QUOTE
- See Also:
- Constant Field Values
-
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
private Schema<?> 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 Detail
-
JsonXOutput
public JsonXOutput(LinkedBuffer head, boolean numeric, Schema<?> schema)
-
JsonXOutput
public JsonXOutput(LinkedBuffer head, java.io.OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize, boolean numeric, Schema<?> schema)
-
JsonXOutput
public JsonXOutput(LinkedBuffer head, java.io.OutputStream out, boolean numeric, Schema<?> schema)
-
-
Method Detail
-
reset
public void reset()
Resets this output for re-use.- Overrides:
reset
in classWriteSession
-
clear
public JsonXOutput clear()
Description copied from class:WriteSession
The buffer will be cleared (tail will point to the head) and the size will be reset to zero.- Overrides:
clear
in classWriteSession
-
use
public JsonXOutput use(Schema<?> schema)
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
public void updateLast(Schema<?> schema, Schema<?> lastSchema)
Description copied from interface:StatefulOutput
Updates the schema iflastSchema
was indeed the last schema used.- Specified by:
updateLast
in interfaceStatefulOutput
-
writeCommaAndStartObject
JsonXOutput writeCommaAndStartObject() throws java.io.IOException
- Throws:
java.io.IOException
-
writeStartObject
JsonXOutput writeStartObject() throws java.io.IOException
- Throws:
java.io.IOException
-
writeEndObject
JsonXOutput writeEndObject() throws java.io.IOException
- Throws:
java.io.IOException
-
writeStartArray
JsonXOutput writeStartArray() throws java.io.IOException
- Throws:
java.io.IOException
-
writeEndArray
JsonXOutput writeEndArray() throws java.io.IOException
- Throws:
java.io.IOException
-
writeKey
private LinkedBuffer writeKey(int fieldNumber, WriteSink sink, byte[] keySuffix) throws java.io.IOException
- Throws:
java.io.IOException
-
writeBool
public void writeBool(int fieldNumber, boolean value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a boolean field.
-
writeByteArray
public void writeByteArray(int fieldNumber, byte[] value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a byte array field.- Specified by:
writeByteArray
in interfaceOutput
- Throws:
java.io.IOException
-
writeByteRange
public void writeByteRange(boolean utf8String, int fieldNumber, byte[] value, int offset, int length, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a binary or a pre-encoded utf8 string.- Specified by:
writeByteRange
in interfaceOutput
- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(int fieldNumber, ByteString value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a ByteString(wraps byte array) field.- Specified by:
writeBytes
in interfaceOutput
- Throws:
java.io.IOException
-
writeDouble
public void writeDouble(int fieldNumber, double value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a double field.- Specified by:
writeDouble
in interfaceOutput
- Throws:
java.io.IOException
-
writeEnum
public void writeEnum(int fieldNumber, int value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a enum(its number) field.
-
writeFixed32
public void writeFixed32(int fieldNumber, int value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a fixed int(4 bytes) field.- Specified by:
writeFixed32
in interfaceOutput
- Throws:
java.io.IOException
-
writeFixed64
public void writeFixed64(int fieldNumber, long value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a fixed long(8 bytes) field.- Specified by:
writeFixed64
in interfaceOutput
- Throws:
java.io.IOException
-
writeFloat
public void writeFloat(int fieldNumber, float value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a float field.- Specified by:
writeFloat
in interfaceOutput
- Throws:
java.io.IOException
-
writeInt32
public void writeInt32(int fieldNumber, int value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a variable int field.- Specified by:
writeInt32
in interfaceOutput
- Throws:
java.io.IOException
-
writeInt64
public void writeInt64(int fieldNumber, long value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a variable long field.- Specified by:
writeInt64
in interfaceOutput
- Throws:
java.io.IOException
-
writeSFixed32
public void writeSFixed32(int fieldNumber, int value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a signed+fixed int(4 bytes) field.- Specified by:
writeSFixed32
in interfaceOutput
- Throws:
java.io.IOException
-
writeSFixed64
public void writeSFixed64(int fieldNumber, long value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a signed+fixed long(8 bytes) field.- Specified by:
writeSFixed64
in interfaceOutput
- Throws:
java.io.IOException
-
writeSInt32
public void writeSInt32(int fieldNumber, int value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a signed int field.- Specified by:
writeSInt32
in interfaceOutput
- Throws:
java.io.IOException
-
writeSInt64
public void writeSInt64(int fieldNumber, long value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a signed long field.- Specified by:
writeSInt64
in interfaceOutput
- Throws:
java.io.IOException
-
writeString
public void writeString(int fieldNumber, java.lang.CharSequence value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes a String field.- Specified by:
writeString
in interfaceOutput
- Throws:
java.io.IOException
-
writeUInt32
public void writeUInt32(int fieldNumber, int value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes an unsigned int field.- Specified by:
writeUInt32
in interfaceOutput
- Throws:
java.io.IOException
-
writeUInt64
public void writeUInt64(int fieldNumber, long value, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes an unsigned long field.- Specified by:
writeUInt64
in interfaceOutput
- Throws:
java.io.IOException
-
writeObject
public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws java.io.IOException
Description copied from interface:Output
Writes an object(using its schema) field.- Specified by:
writeObject
in interfaceOutput
- Throws:
java.io.IOException
-
writeUTF8Escaped
private static LinkedBuffer writeUTF8Escaped(byte[] input, int inStart, int inLen, WriteSink sink, WriteSession session, LinkedBuffer lb) throws java.io.IOException
- Throws:
java.io.IOException
-
writeUTF8Escaped
private static LinkedBuffer writeUTF8Escaped(java.lang.CharSequence str, WriteSink sink, WriteSession session, LinkedBuffer lb) throws java.io.IOException
- Throws:
java.io.IOException
-
writeBytes
public void writeBytes(int fieldNumber, java.nio.ByteBuffer value, boolean repeated) throws java.io.IOException
Writes a ByteBuffer field.- Specified by:
writeBytes
in interfaceOutput
- Throws:
java.io.IOException
-
-