Class CompactRawIntegerSerialiser

  • All Implemented Interfaces:
    Serializable, Serialiser<Integer,​byte[]>, ToBytesSerialiser<Integer>

    public class CompactRawIntegerSerialiser
    extends Object
    implements ToBytesSerialiser<Integer>
    Serialises integers using a variable-length scheme that means smaller integers get serialised into a smaller number of bytes. For example, integers i which are between -112 and 127 inclusive are serialised into one byte. Very large integers may be serialised into 5 bytes. This is particularly well suited to serialising count properties in power-law graphs where the majority of counts will be very small. Note that CompactRawLongSerialiser does not use any more bytes than this serialiser if it is serialising a long value that is less than or equal to Integer.MAX_VALUE and greater than or equal to Integer.MIN_VALUE. This means that, in terms of serialised size, there is no benefit to using an integer instead of a long.
    See Also:
    Serialized Form
    • Constructor Detail

      • CompactRawIntegerSerialiser

        public CompactRawIntegerSerialiser()
    • Method Detail

      • canHandle

        public boolean canHandle​(Class clazz)
        Description copied from interface: Serialiser
        Check whether the serialiser can serialise a particular class.

        //Warning: Due to erasure you may get false positives. e.g.

         
         Set<Foo> set = Sets.newHashSet();
         boolean b = new Serialiser<Set<Bar>, byte[]>().canHandle(set.getClass());
         b will incorrectly be true because of type erasure between Set<Foo> Set<Bar>
         
         
        Specified by:
        canHandle in interface Serialiser<Integer,​byte[]>
        Parameters:
        clazz - the object class to serialise
        Returns:
        boolean true if it can be handled
      • deserialise

        public Integer deserialise​(byte[] allBytes,
                                   int offset,
                                   int length)
                            throws SerialisationException
        Specified by:
        deserialise in interface ToBytesSerialiser<Integer>
        Parameters:
        allBytes - The bytes to be decoded into characters
        offset - The index of the first byte to decode
        length - The number of bytes to decode
        Returns:
        T the deserialised object
        Throws:
        SerialisationException - issues during deserialisation
      • preservesObjectOrdering

        public boolean preservesObjectOrdering()
        Description copied from interface: ToBytesSerialiser
        Indicates whether the serialisation process preserves the ordering of the T, i.e. if x and y are objects of class T, and x is less than y, then this method should return true if the serialised form of x is guaranteed to be less than the serialised form of y (using the standard ordering of byte arrays). If T is not Comparable then this test makes no sense and false should be returned.
        Specified by:
        preservesObjectOrdering in interface Serialiser<Integer,​byte[]>
        Specified by:
        preservesObjectOrdering in interface ToBytesSerialiser<Integer>
        Returns:
        true if the serialisation will preserve the order of the T, otherwise false.
      • isConsistent

        public boolean isConsistent()
        Description copied from interface: Serialiser
        Indicates whether the serialisation process produces a predictable, consistent OUTPUT, from a given INPUT, ie the same object should always serialise in the same way for this to be true.
        Specified by:
        isConsistent in interface Serialiser<Integer,​byte[]>
        Returns:
        true if serialisation is consistent for a given object, otherwise false.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object