Class: Arpie::FixedBinaryType
Constant Summary
Constants included
from Arpie
MTU, VERSION
Instance Method Summary
collapse
Methods inherited from BinaryType
#check_limit, #required_opts
Methods included from Arpie
#bogon!, #incomplete!
Instance Method Details
#binary_size(opts) ⇒ Object
3
4
5
|
# File 'lib/arpie/binary/fixed_type.rb', line 3
def binary_size opts
opts[:value].size
end
|
#from(binary, opts) ⇒ Object
7
8
9
10
11
12
13
14
15
|
# File 'lib/arpie/binary/fixed_type.rb', line 7
def from binary, opts
opts[:value] or raise ArgumentError, "Requires option :value"
sz = opts[:value].size
binary.size >= sz or incomplete!
existing = binary.unpack("a#{sz}")[0]
existing == opts[:value] or bogon! nil, ":fixed did not match data in packet"
[opts[:value], opts[:value].size]
end
|
#to(object, opts) ⇒ Object
17
18
19
20
21
|
# File 'lib/arpie/binary/fixed_type.rb', line 17
def to object, opts
opts[:value] or raise ArgumentError, "Requires option :value"
object == opts[:value] or bogon! nil, ":fixed did not match data in structure"
opts[:value]
end
|