Class: Solace::Serializers::MessageDeserializer

Inherits:
BaseDeserializer show all
Defined in:
lib/solace/serializers/message_deserializer.rb

Overview

Deserializes a binary message into a Solace::Message object.

Since:

  • 0.0.1

Instance Attribute Summary

Attributes inherited from BaseDeserializer

#io, #record

Instance Method Summary collapse

Methods inherited from BaseDeserializer

#call, #initialize

Constructor Details

This class inherits a constructor from Solace::Serializers::BaseDeserializer

Instance Method Details

#next_extract_accountsArray<String>

Extract account keys from the message

The BufferLayout is:

- [Number of accounts (compact u16)]
- [Accounts (variable length u8)]

Returns:

  • (Array<String>)

    The account keys of the message

Since:

  • 0.0.1



66
67
68
69
70
71
# File 'lib/solace/serializers/message_deserializer.rb', line 66

def next_extract_accounts
  count, = Codecs.decode_compact_u16(io)
  record.accounts = count.times.map do
    Codecs.bytes_to_base58 io.read(32).bytes
  end
end

#next_extract_address_lookup_tableArray<Solace::AddressLookupTable>

Extract address lookup table from the message

The BufferLayout is:

- [Number of address lookup tables (compact u16)]
- [Address lookup tables (variable length)]

Returns:

Since:

  • 0.0.1



104
105
106
107
108
109
110
111
# File 'lib/solace/serializers/message_deserializer.rb', line 104

def next_extract_address_lookup_table
  return unless record.versioned?

  count, = Codecs.decode_compact_u16(io)
  record.address_lookup_tables = count.times.map do
    Solace::AddressLookupTable.deserialize(io)
  end
end

#next_extract_instructionsArray<Solace::Instruction>

Extract instructions from the message

The BufferLayout is:

- [Number of instructions (compact u16)]
- [Instructions (variable length)]

Returns:

Since:

  • 0.0.1



90
91
92
93
94
95
# File 'lib/solace/serializers/message_deserializer.rb', line 90

def next_extract_instructions
  count, = Codecs.decode_compact_u16(io)
  record.instructions = count.times.map do
    Solace::Instruction.deserialize(io)
  end
end

#next_extract_message_headerArray<Integer>

Extract message header from the message

The BufferLayout is:

- [Message header (3 bytes)]

Returns:

  • (Array<Integer>)

    The message header of the message

Since:

  • 0.0.1



55
56
57
# File 'lib/solace/serializers/message_deserializer.rb', line 55

def next_extract_message_header
  record.header = io.read(3).bytes
end

#next_extract_recent_blockhashString

Extract recent blockhash from the message

The BufferLayout is:

- [Recent blockhash (32 bytes)]

Returns:

  • (String)

    The recent blockhash of the message

Since:

  • 0.0.1



79
80
81
# File 'lib/solace/serializers/message_deserializer.rb', line 79

def next_extract_recent_blockhash
  record.recent_blockhash = Codecs.bytes_to_base58 io.read(32).bytes
end

#next_extract_versionInteger

Extract version from the message

Checks for version prefix and extracts version. If the prefix is not found, it assumes a legacy message and sets no version.

The BufferLayout is:

- [Version prefix (1 byte)]
- [Version (variable length)]

Returns:

  • (Integer)

    The version of the message

Since:

  • 0.0.1



38
39
40
41
42
43
44
45
46
47
# File 'lib/solace/serializers/message_deserializer.rb', line 38

def next_extract_version
  next_byte = io.read(1).unpack1('C')

  if next_byte & 0x80 == 0x80
    record.version = next_byte & 0x7F
  else
    io.seek(-1, IO::SEEK_CUR)
    record.version = nil
  end
end