| Modifier and Type | Field and Description |
|---|---|
protected boolean |
preserveProtoFieldNames |
protected boolean |
writeEnumsAsInts |
| Constructor and Description |
|---|
JsonSink() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
beginArray() |
abstract JsonSink |
beginObject() |
abstract JsonSink |
clear()
Clears internal state.
|
protected abstract void |
endArray() |
abstract JsonSink |
endObject() |
RepeatedByte |
getBytes() |
CharSequence |
getChars() |
static JsonSink |
newInstance()
Create a new
JsonSink with a new internal buffer. |
static JsonSink |
newInstance(RepeatedByte output)
Create a new
JsonSink that writes directly to the
given output. |
static JsonSink |
newPrettyInstance()
Create a new
JsonSink with a new internal buffer. |
JsonSink |
reserve(int length)
Ensures that the underlying buffer can hold at least
the desired number of bytes.
|
JsonSink |
setOutput(RepeatedByte output)
Changes the output to the given bytes.
|
JsonSink |
setPreserveProtoFieldNames(boolean preserveProtoFieldNames)
The serialized JSON object keys map to the value defined by the 'json_name'
option, or the lowerCamelCase version of the field name in the proto file.
|
JsonSink |
setPrettyPrinting(boolean prettyPrinting)
Sets the output to be pretty printed (newlines and spaces) for increased
readability, or minified (default without whitespace) for efficiency.
|
JsonSink |
setWriteEnumsAsInts(boolean writeEnumsAsInts)
Serializes enum values as JSON integers rather than human-
readable strings.
|
protected void |
writeBinary(RepeatedByte value) |
JsonSink |
writeBool(FieldName name,
boolean value) |
protected abstract void |
writeBoolean(boolean value) |
JsonSink |
writeBytes(FieldName name,
RepeatedByte value) |
JsonSink |
writeDouble(FieldName name,
double value) |
JsonSink |
writeEnum(FieldName name,
int value,
ProtoEnum.EnumConverter<?> converter) |
protected void |
writeEnumValue(int number,
ProtoEnum.EnumConverter<?> converter) |
protected abstract void |
writeFieldName(FieldName name) |
JsonSink |
writeFixed32(FieldName name,
int value) |
JsonSink |
writeFixed64(FieldName name,
long value) |
JsonSink |
writeFloat(FieldName name,
float value) |
JsonSink |
writeGroup(FieldName name,
ProtoMessage value) |
JsonSink |
writeInt32(FieldName name,
int value) |
JsonSink |
writeInt64(FieldName name,
long value) |
JsonSink |
writeMessage(FieldName name,
ProtoMessage<?> value) |
JsonSink |
writeMessage(ProtoMessage<?> value)
Writes a top level object {content}
|
JsonSink |
writeMessageSilent(ProtoMessage<?> value)
Convenience overload for writing to in-memory sinks that don't throw IOException
|
protected abstract void |
writeMessageValue(ProtoMessage<?> value) |
protected abstract void |
writeNumber(double value) |
protected abstract void |
writeNumber(float value) |
protected abstract void |
writeNumber(int value) |
protected abstract void |
writeNumber(long value) |
JsonSink |
writeRepeatedBool(FieldName name,
RepeatedBoolean value) |
JsonSink |
writeRepeatedBytes(FieldName name,
RepeatedBytes value) |
JsonSink |
writeRepeatedDouble(FieldName name,
RepeatedDouble value) |
JsonSink |
writeRepeatedEnum(FieldName name,
RepeatedEnum<?> value) |
JsonSink |
writeRepeatedFixed32(FieldName name,
RepeatedInt value) |
JsonSink |
writeRepeatedFixed64(FieldName name,
RepeatedLong value) |
JsonSink |
writeRepeatedFloat(FieldName name,
RepeatedFloat value) |
JsonSink |
writeRepeatedGroup(FieldName name,
RepeatedMessage<?> value) |
JsonSink |
writeRepeatedInt32(FieldName name,
RepeatedInt value) |
JsonSink |
writeRepeatedInt64(FieldName name,
RepeatedLong value) |
JsonSink |
writeRepeatedMessage(FieldName name,
RepeatedMessage<?> value) |
JsonSink |
writeRepeatedMessage(RepeatedMessage<?> value)
Writes a top-level array [content]
|
JsonSink |
writeRepeatedMessageSilent(RepeatedMessage<?> value)
Convenience overload for writing to in-memory sinks that don't throw IOException
|
JsonSink |
writeRepeatedSFixed32(FieldName name,
RepeatedInt value) |
JsonSink |
writeRepeatedSFixed64(FieldName name,
RepeatedLong value) |
JsonSink |
writeRepeatedSInt32(FieldName name,
RepeatedInt value) |
JsonSink |
writeRepeatedSInt64(FieldName name,
RepeatedLong value) |
JsonSink |
writeRepeatedString(FieldName name,
RepeatedString value) |
JsonSink |
writeRepeatedUInt32(FieldName name,
RepeatedInt value) |
JsonSink |
writeRepeatedUInt64(FieldName name,
RepeatedLong value) |
JsonSink |
writeSFixed32(FieldName name,
int value) |
JsonSink |
writeSFixed64(FieldName name,
long value) |
JsonSink |
writeSInt32(FieldName name,
int value) |
JsonSink |
writeSInt64(FieldName name,
long value) |
protected abstract void |
writeString(CharSequence value) |
JsonSink |
writeString(FieldName name,
CharSequence value) |
JsonSink |
writeString(FieldName name,
Utf8String value) |
protected abstract void |
writeString(Utf8String value) |
JsonSink |
writeUInt32(FieldName name,
int value) |
JsonSink |
writeUInt64(FieldName name,
long value) |
protected boolean writeEnumsAsInts
protected boolean preserveProtoFieldNames
public static JsonSink newInstance(RepeatedByte output)
JsonSink that writes directly to the
given output. If more bytes are written than fit in the
array, the size will grow as needed.
Note that growing is quite inefficient, so the buffers should have an appropriate initial size and be reused.
public static JsonSink newInstance()
JsonSink with a new internal buffer. The
size of the buffer will grow as needed. The resulting buffer
can be accessed with getBytes()
The output is minimized JSON without extra whitespace for sending data over the wire. Enums are serialized as strings by default.
public static JsonSink newPrettyInstance()
JsonSink with a new internal buffer. The
size of the buffer will grow as needed. The resulting buffer
can be accessed with getBytes()
The output contains extra whitespace to improve human readability
public JsonSink setOutput(RepeatedByte output)
public JsonSink reserve(int length)
public abstract JsonSink clear()
public RepeatedByte getBytes()
public CharSequence getChars()
public JsonSink setWriteEnumsAsInts(boolean writeEnumsAsInts)
Unknown values will still be serialized as numbers.
writeEnumsAsInts - true if values should use stringspublic JsonSink setPreserveProtoFieldNames(boolean preserveProtoFieldNames)
This option lets users choose to preserve the original field names as defined in the proto file. Conforming parsers accept both keys.
preserveProtoFieldNames - true uses the original field names as JSON object keyspublic JsonSink setPrettyPrinting(boolean prettyPrinting)
prettyPrinting - true adds whitespace to make the result more human-readablepublic JsonSink writeMessageSilent(ProtoMessage<?> value)
public JsonSink writeRepeatedMessageSilent(RepeatedMessage<?> value)
public JsonSink writeMessage(ProtoMessage<?> value) throws IOException
IOExceptionpublic JsonSink writeRepeatedMessage(RepeatedMessage<?> value) throws IOException
IOExceptionpublic JsonSink writeFixed64(FieldName name, long value) throws IOException
IOExceptionpublic JsonSink writeSFixed64(FieldName name, long value) throws IOException
IOExceptionpublic JsonSink writeUInt64(FieldName name, long value) throws IOException
IOExceptionpublic JsonSink writeSInt64(FieldName name, long value) throws IOException
IOExceptionpublic JsonSink writeFixed32(FieldName name, int value) throws IOException
IOExceptionpublic JsonSink writeSFixed32(FieldName name, int value) throws IOException
IOExceptionpublic JsonSink writeUInt32(FieldName name, int value) throws IOException
IOExceptionpublic JsonSink writeSInt32(FieldName name, int value) throws IOException
IOExceptionpublic JsonSink writeGroup(FieldName name, ProtoMessage value) throws IOException
IOExceptionpublic JsonSink writeRepeatedFixed64(FieldName name, RepeatedLong value) throws IOException
IOExceptionpublic JsonSink writeRepeatedSFixed64(FieldName name, RepeatedLong value) throws IOException
IOExceptionpublic JsonSink writeRepeatedUInt64(FieldName name, RepeatedLong value) throws IOException
IOExceptionpublic JsonSink writeRepeatedSInt64(FieldName name, RepeatedLong value) throws IOException
IOExceptionpublic JsonSink writeRepeatedFixed32(FieldName name, RepeatedInt value) throws IOException
IOExceptionpublic JsonSink writeRepeatedSFixed32(FieldName name, RepeatedInt value) throws IOException
IOExceptionpublic JsonSink writeRepeatedUInt32(FieldName name, RepeatedInt value) throws IOException
IOExceptionpublic JsonSink writeRepeatedSInt32(FieldName name, RepeatedInt value) throws IOException
IOExceptionpublic JsonSink writeRepeatedGroup(FieldName name, RepeatedMessage<?> value) throws IOException
IOExceptionpublic JsonSink writeDouble(FieldName name, double value) throws IOException
IOExceptionpublic JsonSink writeFloat(FieldName name, float value) throws IOException
IOExceptionpublic JsonSink writeInt64(FieldName name, long value) throws IOException
IOExceptionpublic JsonSink writeInt32(FieldName name, int value) throws IOException
IOExceptionpublic JsonSink writeEnum(FieldName name, int value, ProtoEnum.EnumConverter<?> converter) throws IOException
IOExceptionpublic JsonSink writeBool(FieldName name, boolean value) throws IOException
IOExceptionpublic JsonSink writeBytes(FieldName name, RepeatedByte value) throws IOException
IOExceptionpublic JsonSink writeMessage(FieldName name, ProtoMessage<?> value) throws IOException
IOExceptionpublic JsonSink writeString(FieldName name, Utf8String value) throws IOException
IOExceptionpublic JsonSink writeString(FieldName name, CharSequence value) throws IOException
IOExceptionpublic JsonSink writeRepeatedDouble(FieldName name, RepeatedDouble value) throws IOException
IOExceptionpublic JsonSink writeRepeatedInt64(FieldName name, RepeatedLong value) throws IOException
IOExceptionpublic JsonSink writeRepeatedFloat(FieldName name, RepeatedFloat value) throws IOException
IOExceptionpublic JsonSink writeRepeatedInt32(FieldName name, RepeatedInt value) throws IOException
IOExceptionpublic JsonSink writeRepeatedMessage(FieldName name, RepeatedMessage<?> value) throws IOException
IOExceptionpublic JsonSink writeRepeatedString(FieldName name, RepeatedString value) throws IOException
IOExceptionpublic JsonSink writeRepeatedEnum(FieldName name, RepeatedEnum<?> value) throws IOException
IOExceptionpublic JsonSink writeRepeatedBool(FieldName name, RepeatedBoolean value) throws IOException
IOExceptionpublic JsonSink writeRepeatedBytes(FieldName name, RepeatedBytes value) throws IOException
IOExceptionprotected void writeEnumValue(int number,
ProtoEnum.EnumConverter<?> converter)
throws IOException
IOExceptionprotected abstract void writeFieldName(FieldName name) throws IOException
name - utf8 encoded bytes including end quotes and colonIOExceptionprotected abstract void writeNumber(double value)
throws IOException
IOExceptionprotected abstract void writeNumber(float value)
throws IOException
IOExceptionprotected abstract void writeNumber(long value)
throws IOException
IOExceptionprotected abstract void writeNumber(int value)
throws IOException
IOExceptionprotected abstract void writeBoolean(boolean value)
throws IOException
IOExceptionprotected abstract void writeString(Utf8String value) throws IOException
IOExceptionprotected abstract void writeString(CharSequence value) throws IOException
IOExceptionprotected void writeBinary(RepeatedByte value) throws IOException
IOExceptionprotected abstract void writeMessageValue(ProtoMessage<?> value) throws IOException
IOExceptionpublic abstract JsonSink beginObject() throws IOException
IOExceptionpublic abstract JsonSink endObject() throws IOException
IOExceptionprotected abstract void beginArray()
throws IOException
IOExceptionprotected abstract void endArray()
throws IOException
IOExceptionCopyright © 2019–2024 HEBI Robotics. All rights reserved.