Class: Nl::DataTypes::Binary
- Inherits:
-
Base
- Object
- Base
- Nl::DataTypes::Binary
show all
- Defined in:
- nl/lib/nl/datatypes.rb
Instance Method Summary
collapse
Methods inherited from Base
#coerce, #nlattr_type_flags
Constructor Details
#initialize(length: nil, check:) ⇒ Binary
Returns a new instance of Binary.
99
100
101
102
|
# File 'nl/lib/nl/datatypes.rb', line 99
def initialize(length: nil, check:)
super(check:)
@length = length
end
|
Instance Method Details
#decode(decoder, context: nil, nlattr_type_flags: 0) ⇒ Object
112
113
114
|
# File 'nl/lib/nl/datatypes.rb', line 112
def decode(decoder, context: nil, nlattr_type_flags: 0)
checked(decoder.get_string(@length || decoder.remaining))
end
|
#encode(encoder, value, context: nil) ⇒ Object
104
105
106
107
108
109
110
|
# File 'nl/lib/nl/datatypes.rb', line 104
def encode(encoder, value, context: nil)
value = checked(value)
if @length && value.bytesize != @length
raise ArgumentError, "binary value must be exactly #{@length} bytes, got #{value.bytesize}"
end
encoder.put_string(value)
end
|