Package io.protostuff

Class KvpInput

  • All Implemented Interfaces:
    Input

    public final class KvpInput
    extends java.lang.Object
    implements Input
    An input for deserializing kvp-encoded messages. A kvp encoding is a binary encoding w/c contains a key-value sequence. On the wire, a serialized field (key-value) would look like: [key-len][key][value-len][value]

    The keys and values are length-delimited (uint16 little endian).

    Note that this encoding does not support nested messages. This encoding is mostly useful for headers w/c contain information about the content it carries (see http://projects.unbit.it/uwsgi/wiki/uwsgiProtocol).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) byte[] buffer  
      (package private) static int DEFAULT_BUFFER_SIZE  
      (package private) java.io.InputStream in  
      (package private) int limit  
      (package private) static int MAX_VALUE_SIZE  
      (package private) boolean numeric  
      (package private) int offset  
    • Constructor Summary

      Constructors 
      Constructor Description
      KvpInput​(java.io.InputStream in, boolean numeric)  
      KvpInput​(java.io.InputStream in, byte[] buffer, boolean numeric)  
      KvpInput​(java.io.InputStream in, byte[] buffer, int offset, int limit, boolean numeric)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private byte[] fill​(byte[] data, int dataOffset, int len)  
      <T> void handleUnknownField​(int fieldNumber, Schema<T> schema)
      The underlying implementation should handle the unknown field.
      <T> T mergeObject​(T value, Schema<T> schema)
      Merges an object(with schema) field value.
      private boolean readable​(int minimum)
      Returns true if there are minimum bytes available for reading.
      boolean readBool()
      Reads a boolean field value.
      byte[] readByteArray()
      Reads a byte array field value.
      java.nio.ByteBuffer readByteBuffer()
      Reads a byte array/ByteBuffer value.
      ByteString readBytes()
      Reads a ByteString field value.
      void readBytes​(java.nio.ByteBuffer bb)
      Reads a field value into a ByteBuffer.
      double readDouble()
      Reads a double field value.
      int readEnum()
      Reads an enum(its number) field value.
      <T> int readFieldNumber​(Schema<T> schema)
      Reads the field number of a message/object tied to the given schema.
      int readFixed32()
      Reads a fixed int(4 bytes) field value.
      long readFixed64()
      Reads a fixed long(8 bytes) field value.
      float readFloat()
      Reads a float field value.
      int readInt32()
      Reads a variable int field value.
      long readInt64()
      Reads a variable long field value.
      int readSFixed32()
      Reads a signed+fixed int(4 bytes) field value.
      long readSFixed64()
      Reads a signed+fixed long(8 bytes) field value.
      int readSInt32()
      Reads a signed int field value.
      long readSInt64()
      Reads a signed long field value.
      java.lang.String readString()
      Reads a String field value.
      int readUInt32()
      Reads an unsigned int field value.
      long readUInt64()
      Reads an unsigned long field value.
      void transferByteRangeTo​(Output output, boolean utf8String, int fieldNumber, boolean repeated)
      Transfer the byte range to the output.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_BUFFER_SIZE

        static final int DEFAULT_BUFFER_SIZE
      • MAX_VALUE_SIZE

        static final int MAX_VALUE_SIZE
      • in

        final java.io.InputStream in
      • buffer

        final byte[] buffer
      • numeric

        final boolean numeric
      • offset

        int offset
      • limit

        int limit
    • Constructor Detail

      • KvpInput

        public KvpInput​(java.io.InputStream in,
                        boolean numeric)
      • KvpInput

        public KvpInput​(java.io.InputStream in,
                        byte[] buffer,
                        boolean numeric)
      • KvpInput

        public KvpInput​(java.io.InputStream in,
                        byte[] buffer,
                        int offset,
                        int limit,
                        boolean numeric)
    • Method Detail

      • readable

        private boolean readable​(int minimum)
                          throws java.io.IOException
        Returns true if there are minimum bytes available for reading.

        The caller is responsible that the arg minimum is not larger than the buffer size.

        Throws:
        java.io.IOException
      • fill

        private byte[] fill​(byte[] data,
                            int dataOffset,
                            int len)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • readFieldNumber

        public <T> int readFieldNumber​(Schema<T> schema)
                                throws java.io.IOException
        Description copied from interface: Input
        Reads the field number of a message/object tied to the given schema.
        Specified by:
        readFieldNumber in interface Input
        Throws:
        java.io.IOException
      • handleUnknownField

        public <T> void handleUnknownField​(int fieldNumber,
                                           Schema<T> schema)
                                    throws java.io.IOException
        Description copied from interface: Input
        The underlying implementation should handle the unknown field.
        Specified by:
        handleUnknownField in interface Input
        Throws:
        java.io.IOException
      • mergeObject

        public <T> T mergeObject​(T value,
                                 Schema<T> schema)
                          throws java.io.IOException
        Description copied from interface: Input
        Merges an object(with schema) field value. The provided schema handles the deserialization for the object.
        Specified by:
        mergeObject in interface Input
        Throws:
        java.io.IOException
      • readBool

        public boolean readBool()
                         throws java.io.IOException
        Description copied from interface: Input
        Reads a boolean field value.
        Specified by:
        readBool in interface Input
        Throws:
        java.io.IOException
      • readBytes

        public ByteString readBytes()
                             throws java.io.IOException
        Description copied from interface: Input
        Reads a ByteString field value.
        Specified by:
        readBytes in interface Input
        Throws:
        java.io.IOException
      • readBytes

        public void readBytes​(java.nio.ByteBuffer bb)
                       throws java.io.IOException
        Description copied from interface: Input
        Reads a field value into a ByteBuffer.
        Specified by:
        readBytes in interface Input
        Throws:
        java.io.IOException
      • readDouble

        public double readDouble()
                          throws java.io.IOException
        Description copied from interface: Input
        Reads a double field value.
        Specified by:
        readDouble in interface Input
        Throws:
        java.io.IOException
      • readFloat

        public float readFloat()
                        throws java.io.IOException
        Description copied from interface: Input
        Reads a float field value.
        Specified by:
        readFloat in interface Input
        Throws:
        java.io.IOException
      • readUInt32

        public int readUInt32()
                       throws java.io.IOException
        Description copied from interface: Input
        Reads an unsigned int field value.
        Specified by:
        readUInt32 in interface Input
        Throws:
        java.io.IOException
      • readUInt64

        public long readUInt64()
                        throws java.io.IOException
        Description copied from interface: Input
        Reads an unsigned long field value.
        Specified by:
        readUInt64 in interface Input
        Throws:
        java.io.IOException
      • readInt32

        public int readInt32()
                      throws java.io.IOException
        Description copied from interface: Input
        Reads a variable int field value.
        Specified by:
        readInt32 in interface Input
        Throws:
        java.io.IOException
      • readInt64

        public long readInt64()
                       throws java.io.IOException
        Description copied from interface: Input
        Reads a variable long field value.
        Specified by:
        readInt64 in interface Input
        Throws:
        java.io.IOException
      • readEnum

        public int readEnum()
                     throws java.io.IOException
        Description copied from interface: Input
        Reads an enum(its number) field value.
        Specified by:
        readEnum in interface Input
        Throws:
        java.io.IOException
      • readFixed32

        public int readFixed32()
                        throws java.io.IOException
        Description copied from interface: Input
        Reads a fixed int(4 bytes) field value.
        Specified by:
        readFixed32 in interface Input
        Throws:
        java.io.IOException
      • readFixed64

        public long readFixed64()
                         throws java.io.IOException
        Description copied from interface: Input
        Reads a fixed long(8 bytes) field value.
        Specified by:
        readFixed64 in interface Input
        Throws:
        java.io.IOException
      • readSFixed32

        public int readSFixed32()
                         throws java.io.IOException
        Description copied from interface: Input
        Reads a signed+fixed int(4 bytes) field value.
        Specified by:
        readSFixed32 in interface Input
        Throws:
        java.io.IOException
      • readSFixed64

        public long readSFixed64()
                          throws java.io.IOException
        Description copied from interface: Input
        Reads a signed+fixed long(8 bytes) field value.
        Specified by:
        readSFixed64 in interface Input
        Throws:
        java.io.IOException
      • readSInt32

        public int readSInt32()
                       throws java.io.IOException
        Description copied from interface: Input
        Reads a signed int field value.
        Specified by:
        readSInt32 in interface Input
        Throws:
        java.io.IOException
      • readSInt64

        public long readSInt64()
                        throws java.io.IOException
        Description copied from interface: Input
        Reads a signed long field value.
        Specified by:
        readSInt64 in interface Input
        Throws:
        java.io.IOException
      • readByteArray

        public byte[] readByteArray()
                             throws java.io.IOException
        Description copied from interface: Input
        Reads a byte array field value.
        Specified by:
        readByteArray in interface Input
        Throws:
        java.io.IOException
      • readString

        public java.lang.String readString()
                                    throws java.io.IOException
        Description copied from interface: Input
        Reads a String field value.
        Specified by:
        readString in interface Input
        Throws:
        java.io.IOException
      • transferByteRangeTo

        public void transferByteRangeTo​(Output output,
                                        boolean utf8String,
                                        int fieldNumber,
                                        boolean repeated)
                                 throws java.io.IOException
        Description copied from interface: Input
        Transfer the byte range to the output. Capable of zero-copy transfer depending on the type of input.
        Specified by:
        transferByteRangeTo in interface Input
        Throws:
        java.io.IOException
      • readByteBuffer

        public java.nio.ByteBuffer readByteBuffer()
                                           throws java.io.IOException
        Reads a byte array/ByteBuffer value.
        Specified by:
        readByteBuffer in interface Input
        Throws:
        java.io.IOException