Interface Serializer<T>

Type Parameters:
T - a type of serializable object
All Known Implementing Classes:
BlockSerializer, CheckingSerializerDecorator, TransactionLocationSerializer, UtcZonedDateTimeSerializer

public interface Serializer<T>
Converts Java objects into a binary representation in some format, and vice versa.

Implementations must ensure that for any object o, toBytes(Object) produces such an array, that being passed to fromBytes(byte[]), is converted to another object o2, that is equal to the original object o.

This interface is designed to be primarily used by storage proxies and proof validators.

See Also:
StandardSerializers
  • Method Summary

    Modifier and Type Method Description
    T fromBytes​(byte[] serializedValue)
    De-serializes a value from a given byte array.
    byte[] toBytes​(T value)
    Serializes a given value into a byte array.
  • Method Details

    • toBytes

      byte[] toBytes​(T value)
      Serializes a given value into a byte array.
      Parameters:
      value - a value to serialize, must not be null
      Returns:
      a byte array containing a serialized value
      Throws:
      java.lang.NullPointerException - if value is null
    • fromBytes

      T fromBytes​(byte[] serializedValue)
      De-serializes a value from a given byte array.
      Parameters:
      serializedValue - an array containing a serialized value of type T, must not be null
      Returns:
      a value
      Throws:
      java.lang.NullPointerException - if the array is null
      java.lang.IllegalArgumentException - if the array cannot be decoded into a value of type T (e.g., contains 2 bytes when 4 are expected)