Class ArrayOfNumbersSerDe

java.lang.Object
org.apache.datasketches.common.ArrayOfItemsSerDe<Number>
org.apache.datasketches.common.ArrayOfNumbersSerDe

public class ArrayOfNumbersSerDe extends ArrayOfItemsSerDe<Number>
Methods of serializing and deserializing arrays of the object version of primitive types of Number. The array can be a mix of primitive object types.

This class serializes numbers with a leading byte (ASCII character) indicating the type. The class keeps the values byte aligned, even though only 3 bits are strictly necessary to encode one of the 6 different primitives with object types that extend Number.

Classes handled are: Long, Integer, Short, Byte, Double, and Float.

Author:
Jon Malkin
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    deserializeFromMemory(org.apache.datasketches.memory.Memory mem, int numItems)
    Deserialize a contiguous sequence of serialized items from the given Memory starting at a Memory offset of zero and extending numItems.
    deserializeFromMemory(org.apache.datasketches.memory.Memory mem, long offsetBytes, int numItems)
    Deserialize a contiguous sequence of serialized items from the given Memory starting at the given Memory offsetBytes and extending numItems.
    Returns the concrete class of type T
    byte[]
    Serialize a single unserialized item to a byte array.
    byte[]
    Serialize an array of unserialized items to a byte array of contiguous serialized items.
    int
    sizeOf(Number item)
    Returns the serialized size in bytes of a single unserialized item.
    int
    sizeOf(Number[] items)
    Returns the serialized size in bytes of the array of items.
    int
    sizeOf(org.apache.datasketches.memory.Memory mem, long offsetBytes, int numItems)
    Returns the serialized size in bytes of the number of contiguous serialized items in Memory.
    Returns a human readable string of an item.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ArrayOfNumbersSerDe

      public ArrayOfNumbersSerDe()
  • Method Details

    • serializeToByteArray

      public byte[] serializeToByteArray(Number item)
      Description copied from class: ArrayOfItemsSerDe
      Serialize a single unserialized item to a byte array.
      Specified by:
      serializeToByteArray in class ArrayOfItemsSerDe<Number>
      Parameters:
      item - the item to be serialized
      Returns:
      serialized representation of the given item
    • serializeToByteArray

      public byte[] serializeToByteArray(Number[] items)
      Description copied from class: ArrayOfItemsSerDe
      Serialize an array of unserialized items to a byte array of contiguous serialized items.
      Specified by:
      serializeToByteArray in class ArrayOfItemsSerDe<Number>
      Parameters:
      items - array of items to be serialized
      Returns:
      contiguous, serialized representation of the given array of unserialized items
    • deserializeFromMemory

      public Number[] deserializeFromMemory(org.apache.datasketches.memory.Memory mem, int numItems)
      Description copied from class: ArrayOfItemsSerDe
      Deserialize a contiguous sequence of serialized items from the given Memory starting at a Memory offset of zero and extending numItems.
      Overrides:
      deserializeFromMemory in class ArrayOfItemsSerDe<Number>
      Parameters:
      mem - Memory containing a contiguous sequence of serialized items
      numItems - number of items in the contiguous serialized sequence.
      Returns:
      array of deserialized items
      See Also:
    • deserializeFromMemory

      public Number[] deserializeFromMemory(org.apache.datasketches.memory.Memory mem, long offsetBytes, int numItems)
      Description copied from class: ArrayOfItemsSerDe
      Deserialize a contiguous sequence of serialized items from the given Memory starting at the given Memory offsetBytes and extending numItems.
      Specified by:
      deserializeFromMemory in class ArrayOfItemsSerDe<Number>
      Parameters:
      mem - Memory containing a contiguous sequence of serialized items
      offsetBytes - the starting offset in the given Memory.
      numItems - number of items in the contiguous serialized sequence.
      Returns:
      array of deserialized items
    • sizeOf

      public int sizeOf(Number item)
      Description copied from class: ArrayOfItemsSerDe
      Returns the serialized size in bytes of a single unserialized item.
      Specified by:
      sizeOf in class ArrayOfItemsSerDe<Number>
      Parameters:
      item - a specific item
      Returns:
      the serialized size in bytes of a single unserialized item.
    • sizeOf

      public int sizeOf(Number[] items)
      Description copied from class: ArrayOfItemsSerDe
      Returns the serialized size in bytes of the array of items.
      Overrides:
      sizeOf in class ArrayOfItemsSerDe<Number>
      Parameters:
      items - an array of items.
      Returns:
      the serialized size in bytes of the array of items.
    • sizeOf

      public int sizeOf(org.apache.datasketches.memory.Memory mem, long offsetBytes, int numItems)
      Description copied from class: ArrayOfItemsSerDe
      Returns the serialized size in bytes of the number of contiguous serialized items in Memory. The capacity of the given Memory can be much larger that the required size of the items.
      Specified by:
      sizeOf in class ArrayOfItemsSerDe<Number>
      Parameters:
      mem - the given Memory.
      offsetBytes - the starting offset in the given Memory.
      numItems - the number of serialized items contained in the Memory
      Returns:
      the serialized size in bytes of the given number of items.
    • toString

      public String toString(Number item)
      Description copied from class: ArrayOfItemsSerDe
      Returns a human readable string of an item.
      Specified by:
      toString in class ArrayOfItemsSerDe<Number>
      Parameters:
      item - a specific item
      Returns:
      a human readable string of an item.
    • getClassOfT

      public Class<Number> getClassOfT()
      Description copied from class: ArrayOfItemsSerDe
      Returns the concrete class of type T
      Specified by:
      getClassOfT in class ArrayOfItemsSerDe<Number>
      Returns:
      the concrete class of type T