Method: Avro::LogicalTypes::BytesDecimal#encode

Defined in:
lib/avro/logical_types.rb

#encode(value) ⇒ Object

Encode the provided value into a byte array

Parameters:

  • value (BigDecimal, Float, Integer)

    The numeric value to encode

Raises:

  • (ArgumentError)

    If the provided value is not a numeric type

  • (RangeError)

    If the provided value has a scale higher than the schema permits, or does not fit into the schema’s precision



119
120
121
122
123
# File 'lib/avro/logical_types.rb', line 119

def encode(value)
  raise ArgumentError, ERROR_VALUE_MUST_BE_NUMERIC unless value.is_a?(Numeric)

  to_byte_array(unscaled_value(value.to_d)).pack(PACK_UNSIGNED_CHARS).freeze
end