Class StandardSerializers

java.lang.Object
com.exonum.binding.common.serialization.StandardSerializers

public final class StandardSerializers
extends java.lang.Object
A collection of pre-defined serializers.
  • Method Summary

    Modifier and Type Method Description
    static Serializer<java.lang.Boolean> bool()
    Returns a serializer of booleans.
    static Serializer<byte[]> bytes()
    Returns a serializer of byte arrays, which passes them as is.
    static Serializer<java.lang.Double> doubles()
    Returns a serializer of doubles in little-endian byte order.
    static Serializer<java.lang.Integer> fixed32()
    Returns a serializer of integers as four bytes in little-endian byte order.
    static Serializer<java.lang.Long> fixed64()
    Returns a serializer of longs as eight bytes in little-endian byte order.
    static Serializer<java.lang.Float> floats()
    Returns a serializer of floats in little-endian byte order.
    static Serializer<HashCode> hash()
    Returns a serializer of hash codes.
    static Serializer<PrivateKey> privateKey()
    Returns a serializer of private keys.
    static <MessageT extends com.google.protobuf.MessageLite>
    Serializer<MessageT>
    protobuf​(java.lang.Class<MessageT> messageType)
    Returns a serializer for the given protocol buffer message type.
    static Serializer<PublicKey> publicKey()
    Returns a serializer of public keys.
    static Serializer<java.lang.Integer> sint32()
    Returns a serializer of signed integers using variable length encoding.
    static Serializer<java.lang.Long> sint64()
    Returns a serializer of signed longs using variable length encoding.
    static Serializer<java.lang.String> string()
    Returns a serializer of strings in UTF-8.
    static Serializer<TransactionMessage> transactionMessage()
    Returns a serializer of transaction messages.
    static Serializer<java.lang.Integer> uint32()
    Returns a serializer of unsigned integers using variable length encoding.
    static Serializer<java.lang.Long> uint64()
    Returns a serializer of unsigned longs using variable length encoding.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • bytes

      public static Serializer<byte[]> bytes()
      Returns a serializer of byte arrays, which passes them as is.
    • bool

      public static Serializer<java.lang.Boolean> bool()
      Returns a serializer of booleans.
    • fixed32

      public static Serializer<java.lang.Integer> fixed32()
      Returns a serializer of integers as four bytes in little-endian byte order. More efficient than uint32() if values are often greater than 2^28.
    • uint32

      public static Serializer<java.lang.Integer> uint32()
      Returns a serializer of unsigned integers using variable length encoding. These more efficiently encodes values for the range [0; 2^21-1] than fixed32().
    • sint32

      public static Serializer<java.lang.Integer> sint32()
      Returns a serializer of signed integers using variable length encoding. These more efficiently encodes values for the range [-2^20; 2^20-1] than fixed32(). If your values are strictly non-negative, consider using uint32().
    • fixed64

      public static Serializer<java.lang.Long> fixed64()
      Returns a serializer of longs as eight bytes in little-endian byte order. More efficient than uint32() if values are often greater than 2^56.
    • uint64

      public static Serializer<java.lang.Long> uint64()
      Returns a serializer of unsigned longs using variable length encoding. These more efficiently encodes values for the range [0; 2^49-1] than fixed64().
    • sint64

      public static Serializer<java.lang.Long> sint64()
      Returns a serializer of signed longs using variable length encoding. These more efficiently encodes values for the range [-2^48; 2^48-1] than fixed64().
    • floats

      public static Serializer<java.lang.Float> floats()
      Returns a serializer of floats in little-endian byte order.
    • doubles

      public static Serializer<java.lang.Double> doubles()
      Returns a serializer of doubles in little-endian byte order.
    • string

      public static Serializer<java.lang.String> string()
      Returns a serializer of strings in UTF-8. Deserializer will reject malformed input, but replace the characters not representable in UTF-16 with the default replacement character.
    • hash

      public static Serializer<HashCode> hash()
      Returns a serializer of hash codes.
    • publicKey

      public static Serializer<PublicKey> publicKey()
      Returns a serializer of public keys.
    • privateKey

      public static Serializer<PrivateKey> privateKey()
      Returns a serializer of private keys.
    • transactionMessage

      public static Serializer<TransactionMessage> transactionMessage()
      Returns a serializer of transaction messages.
    • protobuf

      public static <MessageT extends com.google.protobuf.MessageLite> Serializer<MessageT> protobuf​(java.lang.Class<MessageT> messageType)
      Returns a serializer for the given protocol buffer message type. The returned serializer uses deterministic serialization mode.
      Type Parameters:
      MessageT - the type of a message; must have a public static #parseFrom(byte[]) method — as any auto-generated protobuf message does
      Parameters:
      messageType - the class of a protobuf message
      Throws:
      java.lang.IllegalArgumentException - if MessageT does not contain the static factory method #parseFrom(byte[])