Top Fields Constructors Methods
com.fasterxml.jackson.dataformat.protobuf

public Class ProtobufGenerator

extends GeneratorBase
Class Inheritance
Imports
java.io.*, java.math.BigDecimal, .BigInteger, java.nio.charset.Charset, com.fasterxml.jackson.core.*, com.fasterxml.jackson.core.base.GeneratorBase, com.fasterxml.jackson.core.io.IOContext, com.fasterxml.jackson.core.json.JsonWriteContext, com.fasterxml.jackson.core.util.JacksonFeatureSet, com.fasterxml.jackson.dataformat.protobuf.schema.FieldType, .ProtobufField, .ProtobufMessage, .ProtobufSchema, .WireType

Field Summary

Modifier and TypeField and Description
protected ByteAccumulator
_buffered

Object used in cases where we need to buffer content to calculate length-prefix.

protected boolean
_complete

Flag that is set when the whole content is complete, can be output.

protected byte[]
_currBuffer

Currently active output buffer, place where appends occur.

protected ProtobufField
_currField

Field to be output next; set when JsonToken#FIELD_NAME is written, cleared once value has been written

protected ProtobufMessage
_currMessage

Type of protobuf message that is currently being output: usually matches write context, but for arrays may indicate "parent" of array.

protected int
protected int
protected boolean
protected byte[]
_origCurrBuffer

The first allocated (or recycled) buffer instance; needed to avoid issue [dataformat-protobuf#14].

protected final OutputStream
_output

Ultimate destination

protected ProtobufWriteContext
_pbContext

Current context, in form we can use it.

protected ProtobufWriteContext
_rootContext

Reference to the root context since that is needed for serialization

protected ProtobufSchema
protected final StreamWriteConstraints
protected boolean
_writeTag

Flag that indicates whether values should be written with tag or not; false for packed arrays, true for others.

protected static final JsonWriteContext
BOGUS_WRITE_CONTEXT

Since our context object does NOT implement standard write context, need to do something like use a placeholder...

protected static final ProtobufField
UNKNOWN_FIELD

This instance is used as a placeholder for cases where we do not know actual field and want to simply skip over any values that caller tries to write for it.

protected static final ProtobufMessage
UNKNOWN_MESSAGE

This is used as a placeholder for case where we don't have an actual message to use, but know (from context) that one is expected.

private static final Charset
Inherited from com.fasterxml.jackson.core.base.GeneratorBase:
_cfgNumbersAsStrings_closed_features_ioContext_objectCodec_writeContextDERIVED_FEATURES_MASKMAX_BIG_DECIMAL_SCALESURR1_FIRSTSURR1_LASTSURR2_FIRSTSURR2_LASTWRITE_BINARYWRITE_BOOLEANWRITE_NULLWRITE_NUMBERWRITE_RAWWRITE_STRING

Constructor Summary

AccessConstructor and Description
public
ProtobufGenerator(IOContext ctxt, int jsonFeatures, ObjectCodec codec, OutputStream output)

Method Summary

Modifier and TypeMethod and Description
protected void
protected void
_encodeLongerString(char[] text, int offset, int clen)

protected void
protected final void
protected final void
_ensureRoom(int needed)

private final void
_finishBuffering()

Helper method called when the current buffering scope is closed; when packed array is completed (`writeEndArray()`) or record is completed (`writeEndObject()`).

protected void
_releaseBuffers()

Implements abstract com.fasterxml.jackson.core.base.GeneratorBase._releaseBuffers.

Method called to release any buffers generator may be holding, once generator is being closed.

protected void
private void
_reportErrorF(String format, Object... args)

protected void
private final void
_startBuffering(int typedTag)

Method called when buffering an entry that should be prefixed with a type tag.

private final void
_startBuffering()

Method called when buffering an entry that should not be prefixed with a type tag.

private void
private void
protected final void
protected void
_verifyValueWrite(String
Additional message used for generating exception message if value output is NOT legal in current generator output state.
typeMsg
)

Implements abstract com.fasterxml.jackson.core.base.GeneratorBase._verifyValueWrite.

Method called before trying to write a value (scalar or structured), to verify that this is legal in current output state, as well as to output separators if and as necessary.

protected void
protected void
protected void
_writeEnum(int index)

private final void
_writeInt32(int v)

private final void
private final void
_writeInt64(long v64)

private final void
_writeInt64NoTag(long v64)

protected void
_writeLengthPrefixed(byte[] data, int offset, int len)

private void
_writeNonPackedArray(int[] array, int i, int end)

private void
_writeNonPackedArray(long[] array, int i, int end)

private void
_writeNonPackedArray(double[] array, int i, int end)

private void
_writePackedArray(int[] array, int i, int end)

private void
_writePackedArray(long[] array, int i, int end)

private void
_writePackedArray(double[] array, int i, int end)

private final int
_writeTag(int ptr)

private final void
_writeVInt(int v)

private final int
_writeVIntMax(int v, int ptr)

private final void
private final void
_writeVLong(long v)

private final int
_writeVLongMax(long v, int ptr)

private final void
public void
assignCurrentValue(Object
Current value to assign for the current context of this generator
v
)

Overrides com.fasterxml.jackson.core.base.GeneratorBase.assignCurrentValue.

Helper method, usually equivalent to: getOutputContext().setCurrentValue(v);

public boolean
canUseSchema(FormatSchema
Schema to check
schema
)

Overrides com.fasterxml.jackson.core.JsonGenerator.canUseSchema.

Method that can be used to verify that given schema can be used with this generator (using setSchema).

public boolean
canWriteBinaryNatively()

Overrides com.fasterxml.jackson.core.JsonGenerator.canWriteBinaryNatively.

Introspection method that may be called to see if the underlying data format supports "native" binary data; that is, an efficient output of binary content without encoding.

public void
close()

Overrides com.fasterxml.jackson.core.base.GeneratorBase.close.

Implements java.io.Closeable.close.

Method called to close this generator, so that no more content can be written.

public Object
currentValue()

Overrides com.fasterxml.jackson.core.base.GeneratorBase.currentValue.

Helper method, usually equivalent to: getOutputContext().getCurrentValue();

Note that "current value" is NOT populated (or used) by Streaming parser or generators; it is only used by higher-level data-binding functionality.

public final void
flush()

Implements abstract com.fasterxml.jackson.core.base.GeneratorBase.flush.

Implements java.io.Flushable.flush.

Method called to flush any buffered content to the underlying target (output stream, writer), and to flush the target itself as well.

public Object
getCurrentValue()

Overrides com.fasterxml.jackson.core.JsonGenerator.getCurrentValue.

Deprecated

Alias for currentValue(), to be deprecated in later Jackson 2.x versions (and removed from Jackson 3.0).

public int
getOutputBuffered()

Overrides com.fasterxml.jackson.core.JsonGenerator.getOutputBuffered.

Calculating actual amount of buffering is somewhat complicated, and can not necessarily give 100% accurate answer due to presence of VInt encoding for length indicators.

public Object
getOutputTarget()

Overrides com.fasterxml.jackson.core.JsonGenerator.getOutputTarget.

Method that can be used to get access to object that is used as target for generated output; this is usually either OutputStream or Writer, depending on what generator was constructed with.

public ProtobufSchema
getSchema()

Overrides com.fasterxml.jackson.core.JsonGenerator.getSchema.

Method for accessing Schema that this generator uses, if any; null if none.

public JacksonFeatureSet<StreamWriteCapability>
getWriteCapabilities()

Overrides com.fasterxml.jackson.core.JsonGenerator.getWriteCapabilities.

Accessor for getting metadata on capabilities of this generator, based on underlying data format being read (directly or indirectly).

public void
setCurrentValue(Object
Current value to assign for the current context of this generator
v
)

Overrides com.fasterxml.jackson.core.JsonGenerator.setCurrentValue.

Deprecated

Alias for assignCurrentValue, to be deprecated in later Jackson 2.x versions (and removed from Jackson 3.0).

public ProtobufGenerator
setPrettyPrinter(PrettyPrinter
PrettyPrinter to assign, if any; null if none
pp
)

Overrides com.fasterxml.jackson.core.JsonGenerator.setPrettyPrinter.

Method for setting a custom pretty printer, which is usually used to add indentation for improved human readability.

public void
public void
setSchema(FormatSchema
Schema to use
schema
)

Overrides com.fasterxml.jackson.core.JsonGenerator.setSchema.

Method to call to make this generator use specified schema.

public StreamWriteConstraints
streamWriteConstraints()

Overrides com.fasterxml.jackson.core.JsonGenerator.streamWriteConstraints.

Get the constraints to apply when performing streaming writes.

public ProtobufGenerator
useDefaultPrettyPrinter()

Overrides com.fasterxml.jackson.core.base.GeneratorBase.useDefaultPrettyPrinter.

Not sure whether to throw an exception or just do no-op; for now, latter.

public Version
version()

Overrides com.fasterxml.jackson.core.base.GeneratorBase.version.

Implements com.fasterxml.jackson.core.Versioned.version.

Implemented with standard version number detection algorithm, typically using a simple generated class, with information extracted from Maven project file during build.

public void
writeArray(int[]
Array that contains values to write
array
,
int
Offset of the first element to write, within array
offset
,
int
Number of elements in array to write, from `offset` to `offset + len - 1`
length
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeArray.

Value write method that can be called to write a single array (sequence of JsonToken#START_ARRAY, zero or more JsonToken#VALUE_NUMBER_INT, JsonToken#END_ARRAY)

public void
writeArray(long[]
Array that contains values to write
array
,
int
Offset of the first element to write, within array
offset
,
int
Number of elements in array to write, from `offset` to `offset + len - 1`
length
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeArray.

Value write method that can be called to write a single array (sequence of JsonToken#START_ARRAY, zero or more JsonToken#VALUE_NUMBER_INT, JsonToken#END_ARRAY)

public void
writeArray(double[]
Array that contains values to write
array
,
int
Offset of the first element to write, within array
offset
,
int
Number of elements in array to write, from `offset` to `offset + len - 1`
length
)

Overrides com.fasterxml.jackson.core.JsonGenerator.writeArray.

Value write method that can be called to write a single array (sequence of JsonToken#START_ARRAY, zero or more JsonToken#VALUE_NUMBER_FLOAT, JsonToken#END_ARRAY)

public void
writeBinary(Base64Variant
Base64 variant to use: defines details such as whether padding is used (and if so, using which character); what is the maximum line length before adding linefeed, and also the underlying alphabet to use.
b64variant
,
byte[]
Buffer that contains binary data to write
data
,
int
Offset in data of the first byte of data to write
offset
,
int
Length of data to write
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeBinary.

Method that will output given chunk of binary data as base64 encoded, as a complete String value (surrounded by double quotes).

public void
writeBoolean(boolean
Boolean value to write
state
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeBoolean.

Method for outputting literal JSON boolean value (one of Strings 'true' and 'false').

public final void
writeEndArray()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeEndArray.

Method for writing closing marker of a JSON Array value (character ']'; plus possible white space decoration if pretty-printing is enabled).

public final void
writeEndObject()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeEndObject.

Method for writing closing marker of an Object value (character '}'; plus possible white space decoration if pretty-printing is enabled).

public final void
writeFieldName(String
Field name to write
name
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeFieldName.

Method for writing a field name (JSON String surrounded by double quotes: syntactically identical to a JSON String value), possibly decorated by white space if pretty-printing is enabled.

public final void
writeFieldName(SerializableString
Field name to write
sstr
)

Overrides com.fasterxml.jackson.core.base.GeneratorBase.writeFieldName.

Method similar to writeFieldName(String), main difference being that it may perform better as some of processing (such as quoting of certain characters, or encoding into external encoding if supported by generator) can be done just once and reused for later calls.

public void
writeNull()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNull.

Method for outputting literal JSON null value.

public void
writeNumber(int
Number value to write
v
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.

public void
writeNumber(long
Number value to write
v
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.

public void
writeNumber(BigInteger
Number value to write
v
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting given value as JSON number.

public void
writeNumber(double
Number value to write
d
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.

public void
writeNumber(float
Number value to write
f
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.

public void
writeNumber(BigDecimal
Number value to write
v
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Method for outputting indicate JSON numeric value.

public void
writeNumber(String
Textual (possibly formatted) number representation to write
encodedValue
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeNumber.

Write method that can be used for custom numeric types that can not be (easily?) converted to "standard" Java number types.

public void
writeRaw(String
Textual contents to include as-is in output.
text
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public void
writeRaw(String
String that has contents to include as-is in output
text
,
int
Offset within text of the first character to output
offset
,
int
Length of content (from text, starting at offset offset) to output
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public void
writeRaw(char[]
Buffer that has contents to include as-is in output
text
,
int
Offset within text of the first character to output
offset
,
int
Length of content (from text, starting at offset offset) to output
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public void
writeRaw(char
Character to included in output
c
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRaw.

Method that will force generator to copy input text verbatim with no modifications (including that no escaping is done and no separators are added even if context [array, object] would otherwise require such).

public void
writeRawUTF8String(byte[]
Buffer that contains String value to write
text
,
int
Offset in buffer of the first byte of String value to write
offset
,
int
Length of the String value (in characters) to write
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeRawUTF8String.

Method similar to writeString(String) but that takes as its input a UTF-8 encoded String that is to be output as-is, without additional escaping (type of which depends on data format; backslashes for JSON).

public void
writeRawValue(String
Textual contents to included in output
text
)

Overrides com.fasterxml.jackson.core.base.GeneratorBase.writeRawValue.

Method that will force generator to copy input text verbatim without any modifications, but assuming it must constitute a single legal JSON value (number, string, boolean, null, Array or List).

public void
public void
public final void
writeStartArray()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeStartArray.

Method for writing starting marker of a Array value (for JSON this is character '['; plus possible white space decoration if pretty-printing is enabled).

public final void
writeStartObject()

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeStartObject.

Method for writing starting marker of an Object value (character '{'; plus possible white space decoration if pretty-printing is enabled).

public void
writeString(String
Text value to write
text
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.

public void
writeString(char[]
Buffer that contains String value to write
text
,
int
Offset in buffer of the first character of String value to write
offset
,
int
Length of the String value (in characters) to write
clen
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeString.

Method for outputting a String value.

public final void
writeString(SerializableString
Pre-encoded String value to write
sstr
)

Overrides com.fasterxml.jackson.core.base.GeneratorBase.writeString.

Method similar to writeString(String), but that takes SerializableString which can make this potentially more efficient to call as generator may be able to reuse quoted and/or encoded representation.

public final void
writeUTF8String(byte[]
Buffer that contains String value to write
text
,
int
Offset in buffer of the first byte of String value to write
offset
,
int
Length of the String value (in characters) to write
len
)

Implements abstract com.fasterxml.jackson.core.JsonGenerator.writeUTF8String.

Method similar to writeString(String) but that takes as its input a UTF-8 encoded String which has not been escaped using whatever escaping scheme data format requires (for JSON that is backslash-escaping for control characters and double-quotes; for other formats something else).

Inherited from com.fasterxml.jackson.core.base.GeneratorBase:
_asString_checkRangeBoundsForByteArray_checkRangeBoundsForCharArray_checkRangeBoundsForString_checkStdFeatureChanges_constructDefaultPrettyPrinter_decodeSurrogatedisableenablegetCodecgetCurrentValuegetFeatureMaskgetOutputContextisClosedisEnabledoverrideStdFeaturessetCodecsetCurrentValuesetFeatureMaskwriteBinarywriteObjectwriteRawValuewriteStartObjectwriteTree