Class: Solace::Serializers::MessageDeserializer

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

Instance Attribute Summary

Attributes inherited from BaseDeserializer

#io, #record

Instance Method Summary collapse

Methods inherited from BaseDeserializer

#call, #initialize

Methods inherited from Base

call, #call

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



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

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:



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

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:



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

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



57
58
59
# File 'lib/solace/serializers/message_deserializer.rb', line 57

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



81
82
83
# File 'lib/solace/serializers/message_deserializer.rb', line 81

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



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

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