Class: Solace::Serializers::MessageSerializer

Inherits:
BaseSerializer show all
Defined in:
lib/solace/serializers/message_serializer.rb

Overview

Serializes a Solana message to a binary format.

Since:

  • 0.0.1

Instance Attribute Summary

Attributes inherited from BaseSerializer

#record

Instance Method Summary collapse

Methods inherited from BaseSerializer

#call, #initialize

Constructor Details

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

Instance Method Details

#encode_accountsArray<Integer>

Encodes the accounts of the transaction

The BufferLayout is:

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

Returns:

  • (Array<Integer>)

    The bytes of the encoded accounts

Since:

  • 0.0.1



49
50
51
52
# File 'lib/solace/serializers/message_serializer.rb', line 49

def encode_accounts
  Codecs.encode_compact_u16(record.accounts.size).bytes +
    record.accounts.map { Codecs.base58_to_bytes(_1) }
end

#encode_address_lookup_tableArray<Integer>

Encodes the address lookup table of the transaction

The BufferLayout is:

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

Returns:

  • (Array<Integer>)

    The bytes of the encoded address lookup table

Since:

  • 0.0.1



85
86
87
88
89
90
# File 'lib/solace/serializers/message_serializer.rb', line 85

def encode_address_lookup_table
  return unless record.versioned?

  Codecs.encode_compact_u16(record.address_lookup_tables.size).bytes +
    record.address_lookup_tables.map(&:to_bytes)
end

#encode_instructionsArray<Integer>

Encodes the instructions of the transaction

The BufferLayout is:

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

Returns:

  • (Array<Integer>)

    The bytes of the encoded instructions

Since:

  • 0.0.1



73
74
75
76
# File 'lib/solace/serializers/message_serializer.rb', line 73

def encode_instructions
  Codecs.encode_compact_u16(record.instructions.size).bytes +
    record.instructions.map(&:to_bytes)
end

#encode_message_headerArray<Integer>

Encodes the message header of the transaction

The BufferLayout is:

- [Message header (3 bytes)]

Returns:

  • (Array<Integer>)

    The bytes of the encoded message header

Since:

  • 0.0.1



38
39
40
# File 'lib/solace/serializers/message_serializer.rb', line 38

def encode_message_header
  record.header
end

#encode_recent_blockhashArray<Integer>

Encodes the recent blockhash of the transaction

The BufferLayout is:

- [Recent blockhash (32 bytes)]

Returns:

  • (Array<Integer>)

    The bytes of the encoded recent blockhash

Since:

  • 0.0.1



60
61
62
63
64
# File 'lib/solace/serializers/message_serializer.rb', line 60

def encode_recent_blockhash
  raise 'Failed to serialize message: recent blockhash is nil' if record.recent_blockhash.nil?

  Codecs.base58_to_bytes(record.recent_blockhash)
end

#encode_versionArray<Integer>

Encodes the version of the message

The BufferLayout is:

- [Version (1 byte)]

Returns:

  • (Array<Integer>)

    | nil The bytes of the encoded version

Since:

  • 0.0.1



28
29
30
# File 'lib/solace/serializers/message_serializer.rb', line 28

def encode_version
  [0x80 | record.version] if record.versioned?
end