Package io.protostuff
Class YamlOutput
java.lang.Object
io.protostuff.WriteSession
io.protostuff.YamlOutput
- All Implemented Interfaces:
Output
,StatefulOutput
An output used for writing data with yaml format.
-
Nested Class Summary
Nested classes/interfaces inherited from class io.protostuff.WriteSession
WriteSession.FlushHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final byte[]
private static final byte[]
private static final byte[]
private static final byte
static final int
The extra indention for the yaml output.private static final byte[]
private int
private int
static final int
Returns 2 if line break is using CRLF ("\r\n"), 1 if using LF ("\n")private Schema
<?> private static final byte[]
Fields inherited from class io.protostuff.WriteSession
flushHandler, head, nextBufferSize, out, sink, size, tail
-
Constructor Summary
ConstructorsConstructorDescriptionYamlOutput
(LinkedBuffer buffer, Schema<?> schema) YamlOutput
(LinkedBuffer buffer, OutputStream out, Schema<?> schema) YamlOutput
(LinkedBuffer buffer, OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize, 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.private static int
inc
(int target, int byAmount) private static LinkedBuffer
newLine
(int indent, WriteSink sink, WriteSession session, LinkedBuffer lb) void
reset()
Resets this output for re-use.void
updateLast
(Schema<?> schema, Schema<?> lastSchema) Updates the schema iflastSchema
was indeed the last schema used.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, ByteBuffer value, boolean repeated) Writes a ByteBuffer field.void
writeDouble
(int fieldNumber, double value, boolean repeated) Writes a double field.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 static LinkedBuffer
writeKey
(String name, int indent, boolean repeated, WriteSink sink, WriteSession session, LinkedBuffer lb) <T> void
writeObject
(int fieldNumber, T value, Schema<T> schema, boolean repeated) Writes an object(using its schema) field.(package private) YamlOutput
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.void
writeString
(int fieldNumber, CharSequence value, boolean repeated) Writes a String field.(package private) static LinkedBuffer
writeTag
(String name, boolean repeated, WriteSink sink, WriteSession session, LinkedBuffer lb) 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.Methods inherited from class io.protostuff.WriteSession
flush, flush, flush, getSize, toByteArray
-
Field Details
-
LINE_BREAK_LEN
public static final int LINE_BREAK_LENReturns 2 if line break is using CRLF ("\r\n"), 1 if using LF ("\n") -
EXTRA_INDENT
public static final int EXTRA_INDENTThe extra indention for the yaml output. (Increases readability) -
COLON_AND_SPACE
private static final byte[] COLON_AND_SPACE -
DASH_AND_SPACE
private static final byte[] DASH_AND_SPACE -
EMPTY_ARRAY
private static final byte[] EMPTY_ARRAY -
TRUE
private static final byte[] TRUE -
FALSE
private static final byte[] FALSE -
EXCLAMATION
private static final byte EXCLAMATION- See Also:
-
indent
private int indent -
lastNumber
private int lastNumber -
schema
-
-
Constructor Details
-
YamlOutput
-
YamlOutput
public YamlOutput(LinkedBuffer buffer, OutputStream out, WriteSession.FlushHandler flushHandler, int nextBufferSize, Schema<?> schema) -
YamlOutput
-
-
Method Details
-
reset
public void reset()Resets this output for re-use.- Overrides:
reset
in classWriteSession
-
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
Before serializing a message/object tied to a schema, this should be called. -
updateLast
Description copied from interface:StatefulOutput
Updates the schema iflastSchema
was indeed the last schema used.- Specified by:
updateLast
in interfaceStatefulOutput
-
writeSequenceDelim
- Throws:
IOException
-
inc
private static int inc(int target, int byAmount) -
writeBool
Description copied from interface:Output
Writes a boolean field.- Specified by:
writeBool
in interfaceOutput
- Throws:
IOException
-
writeDouble
Description copied from interface:Output
Writes a double field.- Specified by:
writeDouble
in interfaceOutput
- Throws:
IOException
-
writeFloat
Description copied from interface:Output
Writes a float field.- Specified by:
writeFloat
in interfaceOutput
- Throws:
IOException
-
writeEnum
Description copied from interface:Output
Writes a enum(its number) field.- Specified by:
writeEnum
in interfaceOutput
- Throws:
IOException
-
writeFixed32
Description copied from interface:Output
Writes a fixed int(4 bytes) field.- Specified by:
writeFixed32
in interfaceOutput
- Throws:
IOException
-
writeInt32
Description copied from interface:Output
Writes a variable int field.- Specified by:
writeInt32
in interfaceOutput
- Throws:
IOException
-
writeSFixed32
Description copied from interface:Output
Writes a signed+fixed int(4 bytes) field.- Specified by:
writeSFixed32
in interfaceOutput
- Throws:
IOException
-
writeUInt32
Description copied from interface:Output
Writes an unsigned int field.- Specified by:
writeUInt32
in interfaceOutput
- Throws:
IOException
-
writeSInt32
Description copied from interface:Output
Writes a signed int field.- Specified by:
writeSInt32
in interfaceOutput
- Throws:
IOException
-
writeFixed64
Description copied from interface:Output
Writes a fixed long(8 bytes) field.- Specified by:
writeFixed64
in interfaceOutput
- Throws:
IOException
-
writeInt64
Description copied from interface:Output
Writes a variable long field.- Specified by:
writeInt64
in interfaceOutput
- Throws:
IOException
-
writeSFixed64
Description copied from interface:Output
Writes a signed+fixed long(8 bytes) field.- Specified by:
writeSFixed64
in interfaceOutput
- Throws:
IOException
-
writeSInt64
Description copied from interface:Output
Writes a signed long field.- Specified by:
writeSInt64
in interfaceOutput
- Throws:
IOException
-
writeUInt64
Description copied from interface:Output
Writes an unsigned long field.- Specified by:
writeUInt64
in interfaceOutput
- Throws:
IOException
-
writeString
Description copied from interface:Output
Writes a String field.- Specified by:
writeString
in interfaceOutput
- Throws:
IOException
-
writeBytes
Description copied from interface:Output
Writes a ByteString(wraps byte array) field.- Specified by:
writeBytes
in interfaceOutput
- Throws:
IOException
-
writeByteArray
Description copied from interface:Output
Writes a byte array field.- Specified by:
writeByteArray
in 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:Output
Writes a binary or a pre-encoded utf8 string.- Specified by:
writeByteRange
in interfaceOutput
- Throws:
IOException
-
writeObject
public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException Description copied from interface:Output
Writes an object(using its schema) field.- Specified by:
writeObject
in interfaceOutput
- Throws:
IOException
-
writeTag
static LinkedBuffer writeTag(String name, boolean repeated, WriteSink sink, WriteSession session, LinkedBuffer lb) throws IOException - Throws:
IOException
-
writeKey
private static LinkedBuffer writeKey(String name, int indent, boolean repeated, WriteSink sink, WriteSession session, LinkedBuffer lb) throws IOException - Throws:
IOException
-
newLine
private static LinkedBuffer newLine(int indent, WriteSink sink, WriteSession session, LinkedBuffer lb) throws IOException - Throws:
IOException
-
writeBytes
Writes a ByteBuffer field.- Specified by:
writeBytes
in interfaceOutput
- Throws:
IOException
-