Class CodedOutputStream.ArrayEncoder

Direct Known Subclasses:
CodedOutputStream.HeapNioEncoder
Enclosing class:
CodedOutputStream

private static class CodedOutputStream.ArrayEncoder extends CodedOutputStream
A CodedOutputStream that writes directly to a byte array.
  • Field Details

    • buffer

      private final byte[] buffer
    • offset

      private final int offset
    • limit

      private final int limit
    • position

      private int position
  • Constructor Details

    • ArrayEncoder

      ArrayEncoder(byte[] buffer, int offset, int length)
  • Method Details

    • writeTag

      public final void writeTag(int fieldNumber, int wireType) throws IOException
      Description copied from class: CodedOutputStream
      Encode and write a tag.
      Specified by:
      writeTag in class CodedOutputStream
      Throws:
      IOException
    • writeInt32

      public final void writeInt32(int fieldNumber, int value) throws IOException
      Description copied from class: CodedOutputStream
      Write an int32 field, including tag, to the stream.
      Specified by:
      writeInt32 in class CodedOutputStream
      Throws:
      IOException
    • writeUInt32

      public final void writeUInt32(int fieldNumber, int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint32 field, including tag, to the stream.
      Specified by:
      writeUInt32 in class CodedOutputStream
      Throws:
      IOException
    • writeFixed32

      public final void writeFixed32(int fieldNumber, int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed32 field, including tag, to the stream.
      Specified by:
      writeFixed32 in class CodedOutputStream
      Throws:
      IOException
    • writeUInt64

      public final void writeUInt64(int fieldNumber, long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint64 field, including tag, to the stream.
      Specified by:
      writeUInt64 in class CodedOutputStream
      Throws:
      IOException
    • writeFixed64

      public final void writeFixed64(int fieldNumber, long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed64 field, including tag, to the stream.
      Specified by:
      writeFixed64 in class CodedOutputStream
      Throws:
      IOException
    • writeBool

      public final void writeBool(int fieldNumber, boolean value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bool field, including tag, to the stream.
      Specified by:
      writeBool in class CodedOutputStream
      Throws:
      IOException
    • writeString

      public final void writeString(int fieldNumber, String value) throws IOException
      Description copied from class: CodedOutputStream
      Write a string field, including tag, to the stream.
      Specified by:
      writeString in class CodedOutputStream
      Throws:
      IOException
    • writeBytes

      public final void writeBytes(int fieldNumber, ByteString value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field, including tag, to the stream.
      Specified by:
      writeBytes in class CodedOutputStream
      Throws:
      IOException
    • writeByteArray

      public final void writeByteArray(int fieldNumber, byte[] value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field, including tag, to the stream.
      Specified by:
      writeByteArray in class CodedOutputStream
      Throws:
      IOException
    • writeByteArray

      public final void writeByteArray(int fieldNumber, byte[] value, int offset, int length) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field, including tag, to the stream.
      Specified by:
      writeByteArray in class CodedOutputStream
      Throws:
      IOException
    • writeByteBuffer

      public final void writeByteBuffer(int fieldNumber, ByteBuffer value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes 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 call writeByteBuffer(fieldNumber, byteBuffer.slice()).
      Specified by:
      writeByteBuffer in class CodedOutputStream
      Throws:
      IOException
    • writeBytesNoTag

      public final void writeBytesNoTag(ByteString value) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field to the stream.
      Specified by:
      writeBytesNoTag in class CodedOutputStream
      Throws:
      IOException
    • writeByteArrayNoTag

      public final void writeByteArrayNoTag(byte[] value, int offset, int length) throws IOException
      Description copied from class: CodedOutputStream
      Write a bytes field to the stream. Visible for testing.
      Specified by:
      writeByteArrayNoTag in class CodedOutputStream
      Throws:
      IOException
    • writeRawBytes

      public final void writeRawBytes(ByteBuffer value) throws 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 call writeRawBytes(byteBuffer.slice()).
      Specified by:
      writeRawBytes in class CodedOutputStream
      Throws:
      IOException
    • writeMessage

      public final void writeMessage(int fieldNumber, MessageLite value) throws IOException
      Description copied from class: CodedOutputStream
      Write an embedded message field, including tag, to the stream.
      Specified by:
      writeMessage in class CodedOutputStream
      Throws:
      IOException
    • writeMessageSetExtension

      public final void writeMessageSetExtension(int fieldNumber, MessageLite value) throws 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 class CodedOutputStream
      Throws:
      IOException
    • writeRawMessageSetExtension

      public final void writeRawMessageSetExtension(int fieldNumber, ByteString value) throws 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 class CodedOutputStream
      Throws:
      IOException
    • writeMessageNoTag

      public final void writeMessageNoTag(MessageLite value) throws IOException
      Description copied from class: CodedOutputStream
      Write an embedded message field to the stream.
      Specified by:
      writeMessageNoTag in class CodedOutputStream
      Throws:
      IOException
    • write

      public final void write(byte value) throws IOException
      Description copied from class: ByteOutput
      Writes a single byte.
      Specified by:
      write in class CodedOutputStream
      Parameters:
      value - the byte to be written
      Throws:
      IOException - thrown if an error occurred while writing
    • writeInt32NoTag

      public final void writeInt32NoTag(int value) throws IOException
      Description copied from class: CodedOutputStream
      Write an int32 field to the stream.
      Specified by:
      writeInt32NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeUInt32NoTag

      public final void writeUInt32NoTag(int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint32 field to the stream.
      Specified by:
      writeUInt32NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeFixed32NoTag

      public final void writeFixed32NoTag(int value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed32 field to the stream.
      Specified by:
      writeFixed32NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeUInt64NoTag

      public final void writeUInt64NoTag(long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a uint64 field to the stream.
      Specified by:
      writeUInt64NoTag in class CodedOutputStream
      Throws:
      IOException
    • writeFixed64NoTag

      public final void writeFixed64NoTag(long value) throws IOException
      Description copied from class: CodedOutputStream
      Write a fixed64 field to the stream.
      Specified by:
      writeFixed64NoTag in class CodedOutputStream
      Throws:
      IOException
    • write

      public final void write(byte[] value, int offset, int length) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput must copy value if it will not be processed prior to the return of this method call, since value 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 class CodedOutputStream
      Parameters:
      value - the bytes to be written
      offset - the offset of the start of the writable range
      length - the number of bytes to write starting from offset
      Throws:
      IOException - thrown if an error occurred while writing
    • writeLazy

      public final void writeLazy(byte[] value, int offset, int length) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput 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 class CodedOutputStream
      Parameters:
      value - the bytes to be written
      offset - the offset of the start of the writable range
      length - the number of bytes to write starting from offset
      Throws:
      IOException - thrown if an error occurred while writing
    • write

      public final void write(ByteBuffer value) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput must copy value if it will not be processed prior to the return of this method call, since value 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 class CodedOutputStream
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
      Throws:
      IOException - thrown if an error occurred while writing
    • writeLazy

      public final void writeLazy(ByteBuffer value) throws IOException
      Description copied from class: ByteOutput
      Writes a sequence of bytes. The ByteOutput 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 class CodedOutputStream
      Parameters:
      value - the bytes to be written. Upon returning from this call, the position of this buffer will be set to the limit
      Throws:
      IOException - thrown if an error occurred while writing
    • writeStringNoTag

      public final void writeStringNoTag(String value) throws IOException
      Description copied from class: CodedOutputStream
      Write a string field to the stream.
      Specified by:
      writeStringNoTag in class CodedOutputStream
      Throws:
      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 class CodedOutputStream
    • spaceLeft

      public final int spaceLeft()
      Description copied from class: CodedOutputStream
      If writing to a flat array, return the space left in the array, which can be a negative value if writing past the limit specified in CodedOutputStream.newInstance(byte[], int, int) but before the end of the array. Otherwise, throws UnsupportedOperationException.
      Specified by:
      spaceLeft in class CodedOutputStream
    • 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 class CodedOutputStream