class Eth::Rlp::Sedes::BigEndianInt

A serializable, big-endian, unsigned integer type.

def deserialize(serial)

Raises:
  • (DeserializationError) - if provided serial is not of minimal length.
  • (DeserializationError) - if provided serial is of wrong size.

Returns:
  • (Integer) - a number.

Parameters:
  • serial (String) -- the serialized integer.
def deserialize(serial)
  raise DeserializationError, "Invalid serialization (wrong size)" if @size && serial.size != @size
  raise DeserializationError, "Invalid serialization (not minimal length)" if !@size && serial.size > 0 && serial[0] == Constant::BYTE_ZERO
  serial = serial || Constant::BYTE_ZERO
  Util.big_endian_to_int(serial)
end

def initialize(size = nil)

Parameters:
  • size (Integer) -- the size of the big endian.
def initialize(size = nil)
  @size = size
end

def serialize(obj)

Raises:
  • (SerializationError) - if provided integer is too big for @size.
  • (SerializationError) - if provided integer is negative.
  • (SerializationError) - if provided object is not an integer.

Returns:
  • (String) - a serialized big-endian integer.

Parameters:
  • obj (Integer) -- the integer to be serialized.
def serialize(obj)
  raise SerializationError, "Can only serialize integers" unless obj.is_a?(Integer)
  raise SerializationError, "Cannot serialize negative integers" if obj < 0
  raise SerializationError, "Integer too large (does not fit in #{@size} bytes)" if @size && obj >= 256 ** @size
  s = obj == 0 ? Constant::BYTE_EMPTY : Util.int_to_big_endian(obj)
  @size ? "#{Constant::BYTE_ZERO * [0, @size - s.size].max}#{s}" : s
end