Package com.google.protobuf
Class CodedOutputStream.ArrayEncoder
- java.lang.Object
-
- com.google.protobuf.ByteOutput
-
- com.google.protobuf.CodedOutputStream
-
- com.google.protobuf.CodedOutputStream.ArrayEncoder
-
- Direct Known Subclasses:
CodedOutputStream.HeapNioEncoder
- Enclosing class:
- CodedOutputStream
private static class CodedOutputStream.ArrayEncoder extends CodedOutputStream
ACodedOutputStream
that writes directly to a byte array.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.google.protobuf.CodedOutputStream
CodedOutputStream.OutOfSpaceException
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
private int
limit
private int
offset
private int
position
-
Fields inherited from class com.google.protobuf.CodedOutputStream
DEFAULT_BUFFER_SIZE, LITTLE_ENDIAN_32_SIZE, wrapper
-
-
Constructor Summary
Constructors Constructor Description ArrayEncoder(byte[] buffer, int offset, int length)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
flush()
Flushes the stream and forces any buffered bytes to be written.int
getTotalBytesWritten()
Get the total number of bytes successfully written to this stream.int
spaceLeft()
If writing to a flat array, return the space left in the array.void
write(byte value)
Writes a single byte.void
write(byte[] value, int offset, int length)
Writes a sequence of bytes.void
write(java.nio.ByteBuffer value)
Writes a sequence of bytes.void
writeBool(int fieldNumber, boolean value)
Write abool
field, including tag, to the stream.void
writeByteArray(int fieldNumber, byte[] value)
Write abytes
field, including tag, to the stream.void
writeByteArray(int fieldNumber, byte[] value, int offset, int length)
Write abytes
field, including tag, to the stream.void
writeByteArrayNoTag(byte[] value, int offset, int length)
Write abytes
field to the stream.void
writeByteBuffer(int fieldNumber, java.nio.ByteBuffer value)
Write abytes
field, including tag, to the stream.void
writeBytes(int fieldNumber, ByteString value)
Write abytes
field, including tag, to the stream.void
writeBytesNoTag(ByteString value)
Write abytes
field to the stream.void
writeFixed32(int fieldNumber, int value)
Write afixed32
field, including tag, to the stream.void
writeFixed32NoTag(int value)
Write afixed32
field to the stream.void
writeFixed64(int fieldNumber, long value)
Write afixed64
field, including tag, to the stream.void
writeFixed64NoTag(long value)
Write afixed64
field to the stream.void
writeInt32(int fieldNumber, int value)
Write anint32
field, including tag, to the stream.void
writeInt32NoTag(int value)
Write anint32
field to the stream.void
writeLazy(byte[] value, int offset, int length)
Writes a sequence of bytes.void
writeLazy(java.nio.ByteBuffer value)
Writes a sequence of bytes.void
writeMessage(int fieldNumber, MessageLite value)
Write an embedded message field, including tag, to the stream.(package private) void
writeMessage(int fieldNumber, MessageLite value, Schema schema)
Write an embedded message field, including tag, to the stream.void
writeMessageNoTag(MessageLite value)
Write an embedded message field to the stream.(package private) void
writeMessageNoTag(MessageLite value, Schema schema)
Write an embedded message field to the stream.void
writeMessageSetExtension(int fieldNumber, MessageLite value)
Write a MessageSet extension field to the stream.void
writeRawBytes(java.nio.ByteBuffer value)
Write a ByteBuffer.void
writeRawMessageSetExtension(int fieldNumber, ByteString value)
Write an unparsed MessageSet extension field to the stream.void
writeString(int fieldNumber, java.lang.String value)
Write astring
field, including tag, to the stream.void
writeStringNoTag(java.lang.String value)
Write astring
field to the stream.void
writeTag(int fieldNumber, int wireType)
Encode and write a tag.void
writeUInt32(int fieldNumber, int value)
Write auint32
field, including tag, to the stream.void
writeUInt32NoTag(int value)
Write auint32
field to the stream.void
writeUInt64(int fieldNumber, long value)
Write auint64
field, including tag, to the stream.void
writeUInt64NoTag(long value)
Write auint64
field to the stream.-
Methods inherited from class com.google.protobuf.CodedOutputStream
checkNoSpaceLeft, computeBoolSize, computeBoolSizeNoTag, computeByteArraySize, computeByteArraySizeNoTag, computeByteBufferSize, computeByteBufferSizeNoTag, computeBytesSize, computeBytesSizeNoTag, computeDoubleSize, computeDoubleSizeNoTag, computeEnumSize, computeEnumSizeNoTag, computeFixed32Size, computeFixed32SizeNoTag, computeFixed64Size, computeFixed64SizeNoTag, computeFloatSize, computeFloatSizeNoTag, computeGroupSize, computeGroupSize, computeGroupSizeNoTag, computeGroupSizeNoTag, computeInt32Size, computeInt32SizeNoTag, computeInt64Size, computeInt64SizeNoTag, computeLazyFieldMessageSetExtensionSize, computeLazyFieldSize, computeLazyFieldSizeNoTag, computeLengthDelimitedFieldSize, computeMessageSetExtensionSize, computeMessageSize, computeMessageSize, computeMessageSizeNoTag, computeMessageSizeNoTag, computePreferredBufferSize, computeRawMessageSetExtensionSize, computeRawVarint32Size, computeRawVarint64Size, computeSFixed32Size, computeSFixed32SizeNoTag, computeSFixed64Size, computeSFixed64SizeNoTag, computeSInt32Size, computeSInt32SizeNoTag, computeSInt64Size, computeSInt64SizeNoTag, computeStringSize, computeStringSizeNoTag, computeTagSize, computeUInt32Size, computeUInt32SizeNoTag, computeUInt64Size, computeUInt64SizeNoTag, encodeZigZag32, encodeZigZag64, inefficientWriteStringNoTag, isSerializationDeterministic, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newSafeInstance, newUnsafeInstance, useDeterministicSerialization, writeBoolNoTag, writeByteArrayNoTag, writeDouble, writeDoubleNoTag, writeEnum, writeEnumNoTag, writeFloat, writeFloatNoTag, writeGroup, writeGroup, writeGroupNoTag, writeGroupNoTag, writeInt64, writeInt64NoTag, writeRawByte, writeRawByte, writeRawBytes, writeRawBytes, writeRawBytes, writeRawLittleEndian32, writeRawLittleEndian64, writeRawVarint32, writeRawVarint64, writeSFixed32, writeSFixed32NoTag, writeSFixed64, writeSFixed64NoTag, writeSInt32, writeSInt32NoTag, writeSInt64, writeSInt64NoTag
-
-
-
-
Method Detail
-
writeTag
public final void writeTag(int fieldNumber, int wireType) throws java.io.IOException
Description copied from class:CodedOutputStream
Encode and write a tag.- Specified by:
writeTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeInt32
public final void writeInt32(int fieldNumber, int value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write anint32
field, including tag, to the stream.- Specified by:
writeInt32
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeUInt32
public final void writeUInt32(int fieldNumber, int value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write auint32
field, including tag, to the stream.- Specified by:
writeUInt32
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeFixed32
public final void writeFixed32(int fieldNumber, int value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write afixed32
field, including tag, to the stream.- Specified by:
writeFixed32
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeUInt64
public final void writeUInt64(int fieldNumber, long value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write auint64
field, including tag, to the stream.- Specified by:
writeUInt64
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeFixed64
public final void writeFixed64(int fieldNumber, long value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write afixed64
field, including tag, to the stream.- Specified by:
writeFixed64
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeBool
public final void writeBool(int fieldNumber, boolean value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write abool
field, including tag, to the stream.- Specified by:
writeBool
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeString
public final void writeString(int fieldNumber, java.lang.String value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write astring
field, including tag, to the stream.- Specified by:
writeString
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeBytes
public final void writeBytes(int fieldNumber, ByteString value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream.- Specified by:
writeBytes
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeByteArray
public final void writeByteArray(int fieldNumber, byte[] value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream.- Specified by:
writeByteArray
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeByteArray
public final void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws java.io.IOException
Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream.- Specified by:
writeByteArray
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeByteBuffer
public final void writeByteBuffer(int fieldNumber, java.nio.ByteBuffer value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write abytes
field, including tag, to the stream. This method will write all content of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write the remaining bytes of a ByteBuffer, you can callwriteByteBuffer(fieldNumber, byteBuffer.slice())
.- Specified by:
writeByteBuffer
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeBytesNoTag
public final void writeBytesNoTag(ByteString value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write abytes
field to the stream.- Specified by:
writeBytesNoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeByteArrayNoTag
public final void writeByteArrayNoTag(byte[] value, int offset, int length) throws java.io.IOException
Description copied from class:CodedOutputStream
Write abytes
field to the stream. Visible for testing.- Specified by:
writeByteArrayNoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeRawBytes
public final void writeRawBytes(java.nio.ByteBuffer value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write a ByteBuffer. This method will write all content of the ByteBuffer regardless of the current position and limit (i.e., the number of bytes to be written is value.capacity(), not value.remaining()). Furthermore, this method doesn't alter the state of the passed-in ByteBuffer. Its position, limit, mark, etc. will remain unchanged. If you only want to write the remaining bytes of a ByteBuffer, you can callwriteRawBytes(byteBuffer.slice())
.- Specified by:
writeRawBytes
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeMessage
public final void writeMessage(int fieldNumber, MessageLite value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write an embedded message field, including tag, to the stream.- Specified by:
writeMessage
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeMessage
final void writeMessage(int fieldNumber, MessageLite value, Schema schema) throws java.io.IOException
Description copied from class:CodedOutputStream
Write an embedded message field, including tag, to the stream.- Specified by:
writeMessage
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeMessageSetExtension
public final void writeMessageSetExtension(int fieldNumber, MessageLite value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write a MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Specified by:
writeMessageSetExtension
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeRawMessageSetExtension
public final void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write an unparsed MessageSet extension field to the stream. For historical reasons, the wire format differs from normal fields.- Specified by:
writeRawMessageSetExtension
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeMessageNoTag
public final void writeMessageNoTag(MessageLite value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write an embedded message field to the stream.- Specified by:
writeMessageNoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeMessageNoTag
final void writeMessageNoTag(MessageLite value, Schema schema) throws java.io.IOException
Description copied from class:CodedOutputStream
Write an embedded message field to the stream.- Specified by:
writeMessageNoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
write
public final void write(byte value) throws java.io.IOException
Description copied from class:ByteOutput
Writes a single byte.- Specified by:
write
in classCodedOutputStream
- Parameters:
value
- the byte to be written- Throws:
java.io.IOException
- thrown if an error occurred while writing
-
writeInt32NoTag
public final void writeInt32NoTag(int value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write anint32
field to the stream.- Specified by:
writeInt32NoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeUInt32NoTag
public final void writeUInt32NoTag(int value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write auint32
field to the stream.- Specified by:
writeUInt32NoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeFixed32NoTag
public final void writeFixed32NoTag(int value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write afixed32
field to the stream.- Specified by:
writeFixed32NoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeUInt64NoTag
public final void writeUInt64NoTag(long value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write auint64
field to the stream.- Specified by:
writeUInt64NoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
writeFixed64NoTag
public final void writeFixed64NoTag(long value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write afixed64
field to the stream.- Specified by:
writeFixed64NoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
write
public final void write(byte[] value, int offset, int length) throws java.io.IOException
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
must copyvalue
if it will not be processed prior to the return of this method call, sincevalue
may be reused/altered by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
write
in classCodedOutputStream
- Parameters:
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting fromoffset
- Throws:
java.io.IOException
- thrown if an error occurred while writing
-
writeLazy
public final void writeLazy(byte[] value, int offset, int length) throws java.io.IOException
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
is free to retain a reference to the value beyond the scope of this method call (e.g. write later) since it is considered immutable and is guaranteed not to change by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
writeLazy
in classCodedOutputStream
- Parameters:
value
- the bytes to be writtenoffset
- the offset of the start of the writable rangelength
- the number of bytes to write starting fromoffset
- Throws:
java.io.IOException
- thrown if an error occurred while writing
-
write
public final void write(java.nio.ByteBuffer value) throws java.io.IOException
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
must copyvalue
if it will not be processed prior to the return of this method call, sincevalue
may be reused/altered by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
write
in classCodedOutputStream
- Parameters:
value
- the bytes to be written. Upon returning from this call, theposition
of this buffer will be set to thelimit
- Throws:
java.io.IOException
- thrown if an error occurred while writing
-
writeLazy
public final void writeLazy(java.nio.ByteBuffer value) throws java.io.IOException
Description copied from class:ByteOutput
Writes a sequence of bytes. TheByteOutput
is free to retain a reference to the value beyond the scope of this method call (e.g. write later) since it is considered immutable and is guaranteed not to change by the caller.NOTE: This method MUST NOT modify the
value
. Doing so is a programming error and will lead to data corruption which will be difficult to debug.- Specified by:
writeLazy
in classCodedOutputStream
- Parameters:
value
- the bytes to be written. Upon returning from this call, theposition
of this buffer will be set to thelimit
- Throws:
java.io.IOException
- thrown if an error occurred while writing
-
writeStringNoTag
public final void writeStringNoTag(java.lang.String value) throws java.io.IOException
Description copied from class:CodedOutputStream
Write astring
field to the stream.- Specified by:
writeStringNoTag
in classCodedOutputStream
- Throws:
java.io.IOException
-
flush
public void flush()
Description copied from class:CodedOutputStream
Flushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.- Specified by:
flush
in classCodedOutputStream
-
spaceLeft
public final int spaceLeft()
Description copied from class:CodedOutputStream
If writing to a flat array, return the space left in the array. Otherwise, throwsUnsupportedOperationException
.- Specified by:
spaceLeft
in classCodedOutputStream
-
getTotalBytesWritten
public final int getTotalBytesWritten()
Description copied from class:CodedOutputStream
Get the total number of bytes successfully written to this stream. The returned value is not guaranteed to be accurate if exceptions have been found in the middle of writing.- Specified by:
getTotalBytesWritten
in classCodedOutputStream
-
-