Class: Solace::Serializers::MessageSerializer
- Inherits:
-
BaseSerializer
- Object
- BaseSerializer
- Solace::Serializers::MessageSerializer
- Defined in:
- lib/solace/serializers/message_serializer.rb
Overview
Serializes a Solana message to a binary format.
Instance Attribute Summary
Attributes inherited from BaseSerializer
Instance Method Summary collapse
-
#encode_accounts ⇒ Array<Integer>
Encodes the accounts of the transaction.
-
#encode_address_lookup_table ⇒ Array<Integer>
Encodes the address lookup table of the transaction.
-
#encode_instructions ⇒ Array<Integer>
Encodes the instructions of the transaction.
-
#encode_message_header ⇒ Array<Integer>
Encodes the message header of the transaction.
-
#encode_recent_blockhash ⇒ Array<Integer>
Encodes the recent blockhash of the transaction.
-
#encode_version ⇒ Array<Integer>
Encodes the version of the message.
Methods inherited from BaseSerializer
Constructor Details
This class inherits a constructor from Solace::Serializers::BaseSerializer
Instance Method Details
#encode_accounts ⇒ Array<Integer>
Encodes the accounts of the transaction
The BufferLayout is:
- [Number of accounts (compact u16)]
- [Accounts (variable length)]
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_table ⇒ Array<Integer>
Encodes the address lookup table of the transaction
The BufferLayout is:
- [Number of address lookup tables (compact u16)]
- [Address lookup tables (variable length)]
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_instructions ⇒ Array<Integer>
Encodes the instructions of the transaction
The BufferLayout is:
- [Number of instructions (compact u16)]
- [Instructions (variable length)]
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_header ⇒ Array<Integer>
Encodes the message header of the transaction
The BufferLayout is:
- [Message header (3 bytes)]
38 39 40 |
# File 'lib/solace/serializers/message_serializer.rb', line 38 def record.header end |
#encode_recent_blockhash ⇒ Array<Integer>
Encodes the recent blockhash of the transaction
The BufferLayout is:
- [Recent blockhash (32 bytes)]
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_version ⇒ Array<Integer>
Encodes the version of the message
The BufferLayout is:
- [Version (1 byte)]
28 29 30 |
# File 'lib/solace/serializers/message_serializer.rb', line 28 def encode_version [0x80 | record.version] if record.versioned? end |