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
-
.included(base) ⇒ Object
Include the module.
Instance Method Summary collapse
-
#serialize ⇒ String
Serializes the record to a binary format.
-
#to_binary ⇒ String
Returns the binary decoded from the serialized string.
-
#to_bytes ⇒ Array
Returns the bytes of the binary data as an array of integers.
-
#to_io ⇒ IO
Returns a StringIO stream of the binary data.
Class Method Details
.included(base) ⇒ Object
Include the module
19 20 21 |
# File 'lib/solace/concerns/binary_serializable.rb', line 19 def self.included(base) base.extend ClassMethods end |
Instance Method Details
#serialize ⇒ String
Serializes the record to a binary format
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_binary ⇒ String
Returns the binary decoded from the serialized string
Expects the class to have a ‘serialize` method that returns a base64 string.
28 29 30 |
# File 'lib/solace/concerns/binary_serializable.rb', line 28 def to_binary Base64.decode64(serialize) end |
#to_bytes ⇒ Array
Returns the bytes of the binary data as an array of integers
42 43 44 |
# File 'lib/solace/concerns/binary_serializable.rb', line 42 def to_bytes to_binary.bytes end |
#to_io ⇒ IO
Returns a StringIO stream of the binary data
35 36 37 |
# File 'lib/solace/concerns/binary_serializable.rb', line 35 def to_io StringIO.new(to_binary) end |