Class: Solace::Serializers::InstructionSerializer

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

Overview

Serializes a Solana instruction 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 instruction

The BufferLayout is:

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

Returns:

  • (Array<Integer>)

    The bytes of the encoded accounts

Since:

  • 0.0.1



36
37
38
# File 'lib/solace/serializers/instruction_serializer.rb', line 36

def encode_accounts
  Codecs.encode_compact_u16(record.accounts.size).bytes + record.accounts
end

#encode_dataArray<Integer>

Encodes the data of the instruction

The BufferLayout is:

- [Number of data bytes (compact u16)]
- [Data bytes (variable length u8)]

Returns:

  • (Array<Integer>)

    The bytes of the encoded data

Since:

  • 0.0.1



47
48
49
# File 'lib/solace/serializers/instruction_serializer.rb', line 47

def encode_data
  Codecs.encode_compact_u16(record.data.size).bytes + record.data
end

#encode_program_indexInteger

Encodes the program index of the instruction

The BufferLayout is:

- [Program index (u8)]

Returns:

  • (Integer)

    The bytes of the encoded program index

Since:

  • 0.0.1



25
26
27
# File 'lib/solace/serializers/instruction_serializer.rb', line 25

def encode_program_index
  record.program_index
end