Class: BinaryCodec::FieldHeader
- Inherits:
-
Object
- Object
- BinaryCodec::FieldHeader
- Defined in:
- lib/binary-codec/enums/fields.rb
Instance Attribute Summary collapse
-
#nth ⇒ Object
readonly
Returns the value of attribute nth.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type:, nth:) ⇒ FieldHeader
constructor
A new instance of FieldHeader.
- #to_bytes ⇒ Object
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
#nth ⇒ Object (readonly)
Returns the value of attribute nth.
7 8 9 |
# File 'lib/binary-codec/enums/fields.rb', line 7 def nth @nth end |
#type ⇒ Object (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_bytes ⇒ Object
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 |