Module: Solace::Concerns::BinarySerializable

Included in:
AddressLookupTable, Instruction, Message, Transaction
Defined in:
lib/solace/concerns/binary_serializable.rb

Overview

Adds binary serialization support to a class

Transactions, Messages, Instructions, and AddressLookupTables are all binary serializable. These classes use this concern to add binary serialization support.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object

Include the module

Parameters:

  • base (Class)

    The base class to include the module into

Since:

  • 0.0.1



19
20
21
# File 'lib/solace/concerns/binary_serializable.rb', line 19

def self.included(base)
  base.extend ClassMethods
end

Instance Method Details

#serializeString

Serializes the record to a binary format

Returns:

  • (String)

    The serialized record (binary)

Since:

  • 0.0.1



49
50
51
52
53
# File 'lib/solace/concerns/binary_serializable.rb', line 49

def serialize
  self.class::SERIALIZER.new(self).call
rescue NameError => e
  raise "SERIALIZER must be defined: #{e.message}"
end

#to_binaryString

Returns the binary decoded from the serialized string

Expects the class to have a ‘serialize` method that returns a base64 string.

Returns:

  • (String)

    The binary decoded from the serialized string

Since:

  • 0.0.1



28
29
30
# File 'lib/solace/concerns/binary_serializable.rb', line 28

def to_binary
  Base64.decode64(serialize)
end

#to_bytesArray

Returns the bytes of the binary data as an array of integers

Returns:

  • (Array)

    The bytes of the binary data as an array of integers

Since:

  • 0.0.1



42
43
44
# File 'lib/solace/concerns/binary_serializable.rb', line 42

def to_bytes
  to_binary.bytes
end

#to_ioIO

Returns a StringIO stream of the binary data

Returns:

  • (IO)

    The StringIO stream of the binary data

Since:

  • 0.0.1



35
36
37
# File 'lib/solace/concerns/binary_serializable.rb', line 35

def to_io
  StringIO.new(to_binary)
end