Class SimpleTypeSerializer<T>

    • Constructor Detail

      • SimpleTypeSerializer

        public SimpleTypeSerializer​(DataType dataType)
    • Method Detail

      • readValue

        public T readValue​(Buffer buffer,
                           GraphBinaryReader context,
                           boolean nullable)
                    throws IOException
        Description copied from interface: TypeSerializer
        Reads the value from the buffer (not the type information) and returns an instance of T.

        Implementors should throw an exception when a complex type doesn't support reading without the type information.

        Specified by:
        readValue in interface TypeSerializer<T>
        Throws:
        IOException
      • readValue

        protected abstract T readValue​(Buffer buffer,
                                       GraphBinaryReader context)
                                throws IOException
        Reads a non-nullable value according to the type format.
        Parameters:
        buffer - A buffer which reader index has been set to the beginning of the {value}.
        context - The binary reader.
        Returns:
        Throws:
        IOException
      • readSizePrefix

        protected static int readSizePrefix​(Buffer buffer)
                                     throws IOException
        Reads a length or element-count prefix and validates it before it is used to size an allocation. The same check serves both kinds of prefix: a byte length, where each counted unit is one wire byte, and an element count, where each counted element occupies at least one wire byte. A negative value, or one larger than the number of bytes actually remaining in the buffer, therefore cannot be legitimate, so it is rejected rather than allowed to drive a large allocation from a small message.
        Throws:
        IOException
      • cappedInitialCapacity

        protected static int cappedInitialCapacity​(int size)
        Caps the initial capacity used to pre-size a growable container (ArrayList, HashMap) from a validated wire count. Safe to use only for containers that grow on demand, never for a fixed-size array or a byte buffer that must hold exactly size entries.
      • writeValue

        protected abstract void writeValue​(T value,
                                           Buffer buffer,
                                           GraphBinaryWriter context)
                                    throws IOException
        Writes a non-nullable value into a buffer using the provided allocator.
        Parameters:
        value - A non-nullable value.
        buffer - The buffer allocator to use.
        context - The binary writer.
        Throws:
        IOException