Class: BinaryCodec::FieldHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/binary-codec/enums/fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, nth:) ⇒ FieldHeader

Returns a new instance of FieldHeader.



9
10
11
12
# File 'lib/binary-codec/enums/fields.rb', line 9

def initialize(type:, nth:)
  @type = type
  @nth = nth
end

Instance Attribute Details

#nthObject (readonly)

Returns the value of attribute nth.



7
8
9
# File 'lib/binary-codec/enums/fields.rb', line 7

def nth
  @nth
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/binary-codec/enums/fields.rb', line 7

def type
  @type
end

Instance Method Details

#to_bytesObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/binary-codec/enums/fields.rb', line 14

def to_bytes
  header = []
  if type < 16
    if nth < 16
      header.push((type << 4) | nth)
    else
      header.push(type << 4, nth)
    end
  elsif nth < 16
    header.push(nth,type)
  else
    header.push(0, type, nth)
  end

  header
end