Class: Solana::Ruby::Kit::Codecs::Decoder
- Inherits:
-
Object
- Object
- Solana::Ruby::Kit::Codecs::Decoder
- Extended by:
- T::Sig
- Defined in:
- lib/solana/ruby/kit/codecs/decoder.rb
Overview
Mirrors the TypeScript Decoder<T> interface from @solana/codecs-core.
A Decoder knows how to turn binary bytes into a Ruby value. Fixed-size decoders advertise their byte length via fixed_size; variable-size decoders leave it nil.
The inner block receives (bytes, offset) and must return [value, bytes_consumed].
Instance Attribute Summary collapse
-
#fixed_size ⇒ Object
readonly
Returns the value of attribute fixed_size.
Instance Method Summary collapse
- #decode(bytes, offset: 0) ⇒ Object
-
#initialize(fixed_size: nil, &block) ⇒ Decoder
constructor
A new instance of Decoder.
Constructor Details
#initialize(fixed_size: nil, &block) ⇒ Decoder
27 28 29 30 31 32 33 |
# File 'lib/solana/ruby/kit/codecs/decoder.rb', line 27 def initialize(fixed_size: nil, &block) @fixed_size = fixed_size @fn = T.let( block, T.proc.params(bytes: String, offset: Integer).returns([T.untyped, Integer]) ) end |
Instance Attribute Details
#fixed_size ⇒ Object (readonly)
Returns the value of attribute fixed_size.
18 19 20 |
# File 'lib/solana/ruby/kit/codecs/decoder.rb', line 18 def fixed_size @fixed_size end |
Instance Method Details
#decode(bytes, offset: 0) ⇒ Object
38 39 40 |
# File 'lib/solana/ruby/kit/codecs/decoder.rb', line 38 def decode(bytes, offset: 0) @fn.call(bytes.b, offset) end |