Class CodedOutputStream

  • Direct Known Subclasses:
    CodedOutputStream.AbstractBufferedEncoder

    public abstract class CodedOutputStream
    extends java.lang.Object
    Protobuf wire encoder.

    This class is internal and is hence not for public use. Its APIs are unstable and can change at any time.

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private CodedOutputStream()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static int computeBoolSizeNoTag​(boolean unused)
      Compute the number of bytes that would be needed to encode a bool field.
      static int computeByteArraySizeNoTag​(byte[] value)
      Compute the number of bytes that would be needed to encode a bytes field.
      static int computeByteBufferSizeNoTag​(java.nio.ByteBuffer value)
      Compute the number of bytes that would be needed to encode a bytes field.
      static int computeDoubleSizeNoTag​(double unused)
      Compute the number of bytes that would be needed to encode a double field, including tag.
      (package private) static int computeEnumSizeNoTag​(int value)
      Compute the number of bytes that would be needed to encode an enum field.
      (package private) static int computeFixed32SizeNoTag​(int unused)
      Compute the number of bytes that would be needed to encode a fixed32 field.
      (package private) static int computeFixed64SizeNoTag​(long unused)
      Compute the number of bytes that would be needed to encode a fixed64 field.
      (package private) static int computeFloatSizeNoTag​(float unused)
      Compute the number of bytes that would be needed to encode a float field, including tag.
      (package private) static int computeInt32SizeNoTag​(int value)
      Compute the number of bytes that would be needed to encode an int32 field, including tag.
      static int computeInt64SizeNoTag​(long value)
      Compute the number of bytes that would be needed to encode an int64 field, including tag.
      (package private) static int computeLengthDelimitedFieldSize​(int fieldLength)  
      (package private) static int computeSFixed32SizeNoTag​(int unused)
      Compute the number of bytes that would be needed to encode an sfixed32 field.
      (package private) static int computeSFixed64SizeNoTag​(long unused)
      Compute the number of bytes that would be needed to encode an sfixed64 field.
      (package private) static int computeSInt32SizeNoTag​(int value)
      Compute the number of bytes that would be needed to encode an sint32 field.
      (package private) static int computeSInt64SizeNoTag​(long value)
      Compute the number of bytes that would be needed to encode an sint64 field.
      (package private) static int computeTagSize​(int fieldNumber)
      Compute the number of bytes that would be needed to encode a tag.
      (package private) static int computeUInt32SizeNoTag​(int value)
      Compute the number of bytes that would be needed to encode a uint32 field.
      (package private) static int computeUInt64SizeNoTag​(long value)
      Compute the number of bytes that would be needed to encode a uint64 field, including tag.
      (package private) static int encodeZigZag32​(int n)
      Encode a ZigZag-encoded 32-bit value.
      (package private) static long encodeZigZag64​(long n)
      Encode a ZigZag-encoded 64-bit value.
      (package private) abstract void flush()
      Flushes the stream and forces any buffered bytes to be written.
      (package private) static CodedOutputStream newInstance​(java.io.OutputStream output)
      Create a new CodedOutputStream wrapping the given OutputStream.
      (package private) abstract void write​(byte value)  
      (package private) abstract void write​(byte[] value, int offset, int length)  
      (package private) void writeBoolNoTag​(boolean value)
      Write a bool field to the stream.
      (package private) void writeByteArrayNoTag​(byte[] value)
      Write a bytes field to the stream.
      (package private) abstract void writeByteArrayNoTag​(byte[] value, int offset, int length)
      Write a bytes field to the stream.
      (package private) abstract void writeByteBufferNoTag​(java.nio.ByteBuffer value)  
      (package private) void writeDoubleNoTag​(double value)
      Write a double field to the stream.
      (package private) void writeEnumNoTag​(int value)
      Write an enum field to the stream.
      (package private) abstract void writeFixed32NoTag​(int value)
      Write a fixed32 field to the stream.
      (package private) abstract void writeFixed64NoTag​(long value)
      Write a fixed64 field to the stream.
      (package private) void writeFloatNoTag​(float value)
      Write a float field to the stream.
      (package private) abstract void writeInt32NoTag​(int value)
      Write an int32 field to the stream.
      (package private) void writeInt64NoTag​(long value)
      Write an int64 field to the stream.
      (package private) void writeRawBytes​(byte[] value)
      Write an array of bytes.
      (package private) void writeSFixed32NoTag​(int value)
      Write a sfixed32 field to the stream.
      (package private) void writeSFixed64NoTag​(long value)
      Write a sfixed64 field to the stream.
      (package private) void writeSInt32NoTag​(int value)
      Write a sint32 field to the stream.
      (package private) void writeSInt64NoTag​(long value)
      Write a sint64 field to the stream.
      (package private) abstract void writeUInt32NoTag​(int value)
      Write a uint32 field to the stream.
      (package private) abstract void writeUInt64NoTag​(long value)
      Write a uint64 field to the stream.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CodedOutputStream

        private CodedOutputStream()
    • Method Detail

      • newInstance

        static CodedOutputStream newInstance​(java.io.OutputStream output)
        Create a new CodedOutputStream wrapping the given OutputStream.

        NOTE: The provided OutputStream MUST NOT retain access or modify the provided byte arrays. Doing so may result in corrupted data, which would be difficult to debug.

      • writeRawBytes

        final void writeRawBytes​(byte[] value)
                          throws java.io.IOException
        Write an array of bytes.
        Throws:
        java.io.IOException
      • writeInt32NoTag

        abstract void writeInt32NoTag​(int value)
                               throws java.io.IOException
        Write an int32 field to the stream.
        Throws:
        java.io.IOException
      • writeUInt32NoTag

        abstract void writeUInt32NoTag​(int value)
                                throws java.io.IOException
        Write a uint32 field to the stream.
        Throws:
        java.io.IOException
      • writeSInt32NoTag

        final void writeSInt32NoTag​(int value)
                             throws java.io.IOException
        Write a sint32 field to the stream.
        Throws:
        java.io.IOException
      • writeFixed32NoTag

        abstract void writeFixed32NoTag​(int value)
                                 throws java.io.IOException
        Write a fixed32 field to the stream.
        Throws:
        java.io.IOException
      • writeSFixed32NoTag

        final void writeSFixed32NoTag​(int value)
                               throws java.io.IOException
        Write a sfixed32 field to the stream.
        Throws:
        java.io.IOException
      • writeInt64NoTag

        final void writeInt64NoTag​(long value)
                            throws java.io.IOException
        Write an int64 field to the stream.
        Throws:
        java.io.IOException
      • writeUInt64NoTag

        abstract void writeUInt64NoTag​(long value)
                                throws java.io.IOException
        Write a uint64 field to the stream.
        Throws:
        java.io.IOException
      • writeSInt64NoTag

        final void writeSInt64NoTag​(long value)
                             throws java.io.IOException
        Write a sint64 field to the stream.
        Throws:
        java.io.IOException
      • writeFixed64NoTag

        abstract void writeFixed64NoTag​(long value)
                                 throws java.io.IOException
        Write a fixed64 field to the stream.
        Throws:
        java.io.IOException
      • writeSFixed64NoTag

        final void writeSFixed64NoTag​(long value)
                               throws java.io.IOException
        Write a sfixed64 field to the stream.
        Throws:
        java.io.IOException
      • writeFloatNoTag

        final void writeFloatNoTag​(float value)
                            throws java.io.IOException
        Write a float field to the stream.
        Throws:
        java.io.IOException
      • writeDoubleNoTag

        final void writeDoubleNoTag​(double value)
                             throws java.io.IOException
        Write a double field to the stream.
        Throws:
        java.io.IOException
      • writeBoolNoTag

        final void writeBoolNoTag​(boolean value)
                           throws java.io.IOException
        Write a bool field to the stream.
        Throws:
        java.io.IOException
      • writeEnumNoTag

        final void writeEnumNoTag​(int value)
                           throws java.io.IOException
        Write an enum field to the stream. The provided value is the numeric value used to represent the enum value on the wire (not the enum ordinal value).
        Throws:
        java.io.IOException
      • writeByteArrayNoTag

        final void writeByteArrayNoTag​(byte[] value)
                                throws java.io.IOException
        Write a bytes field to the stream.
        Throws:
        java.io.IOException
      • write

        abstract void write​(byte value)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • write

        abstract void write​(byte[] value,
                            int offset,
                            int length)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • computeTagSize

        static int computeTagSize​(int fieldNumber)
        Compute the number of bytes that would be needed to encode a tag.
      • computeInt32SizeNoTag

        static int computeInt32SizeNoTag​(int value)
        Compute the number of bytes that would be needed to encode an int32 field, including tag.
      • computeUInt32SizeNoTag

        static int computeUInt32SizeNoTag​(int value)
        Compute the number of bytes that would be needed to encode a uint32 field.
      • computeSInt32SizeNoTag

        static int computeSInt32SizeNoTag​(int value)
        Compute the number of bytes that would be needed to encode an sint32 field.
      • computeFixed32SizeNoTag

        static int computeFixed32SizeNoTag​(int unused)
        Compute the number of bytes that would be needed to encode a fixed32 field.
      • computeSFixed32SizeNoTag

        static int computeSFixed32SizeNoTag​(int unused)
        Compute the number of bytes that would be needed to encode an sfixed32 field.
      • computeInt64SizeNoTag

        public static int computeInt64SizeNoTag​(long value)
        Compute the number of bytes that would be needed to encode an int64 field, including tag.
      • computeUInt64SizeNoTag

        static int computeUInt64SizeNoTag​(long value)
        Compute the number of bytes that would be needed to encode a uint64 field, including tag.
      • computeSInt64SizeNoTag

        static int computeSInt64SizeNoTag​(long value)
        Compute the number of bytes that would be needed to encode an sint64 field.
      • computeFixed64SizeNoTag

        static int computeFixed64SizeNoTag​(long unused)
        Compute the number of bytes that would be needed to encode a fixed64 field.
      • computeSFixed64SizeNoTag

        static int computeSFixed64SizeNoTag​(long unused)
        Compute the number of bytes that would be needed to encode an sfixed64 field.
      • computeFloatSizeNoTag

        static int computeFloatSizeNoTag​(float unused)
        Compute the number of bytes that would be needed to encode a float field, including tag.
      • computeDoubleSizeNoTag

        public static int computeDoubleSizeNoTag​(double unused)
        Compute the number of bytes that would be needed to encode a double field, including tag.
      • computeBoolSizeNoTag

        public static int computeBoolSizeNoTag​(boolean unused)
        Compute the number of bytes that would be needed to encode a bool field.
      • computeEnumSizeNoTag

        static int computeEnumSizeNoTag​(int value)
        Compute the number of bytes that would be needed to encode an enum field. The provided value is the numeric value used to represent the enum value on the wire (not the enum ordinal value).
      • computeByteArraySizeNoTag

        public static int computeByteArraySizeNoTag​(byte[] value)
        Compute the number of bytes that would be needed to encode a bytes field.
      • computeByteBufferSizeNoTag

        public static int computeByteBufferSizeNoTag​(java.nio.ByteBuffer value)
        Compute the number of bytes that would be needed to encode a bytes field.
      • computeLengthDelimitedFieldSize

        static int computeLengthDelimitedFieldSize​(int fieldLength)
      • encodeZigZag32

        static int encodeZigZag32​(int n)
        Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)
        Parameters:
        n - A signed 32-bit integer.
        Returns:
        An unsigned 32-bit integer, stored in a signed int because Java has no explicit unsigned support.
      • encodeZigZag64

        static long encodeZigZag64​(long n)
        Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers into values that can be efficiently encoded with varint. (Otherwise, negative values must be sign-extended to 64 bits to be varint encoded, thus always taking 10 bytes on the wire.)
        Parameters:
        n - A signed 64-bit integer.
        Returns:
        An unsigned 64-bit integer, stored in a signed int because Java has no explicit unsigned support.
      • flush

        abstract void flush()
                     throws java.io.IOException
        Flushes the stream and forces any buffered bytes to be written. This does not flush the underlying OutputStream.
        Throws:
        java.io.IOException
      • writeByteArrayNoTag

        abstract void writeByteArrayNoTag​(byte[] value,
                                          int offset,
                                          int length)
                                   throws java.io.IOException
        Write a bytes field to the stream.
        Throws:
        java.io.IOException
      • writeByteBufferNoTag

        abstract void writeByteBufferNoTag​(java.nio.ByteBuffer value)
                                    throws java.io.IOException
        Throws:
        java.io.IOException