Module: Bindef::Extras::TLV

Included in:
Bindef
Defined in:
lib/bindef/extras/tlv.rb

Overview

Potentially useful TLV (tag-length-value) commands.

Writing a single sufficiently generic TLV command without really abusing Ruby's syntax is hard. Instead, we provide specialized commands for empirically common TLV widths.

Instance Method Summary collapse

Instance Method Details

#tlv_u16(type, hsh) ⇒ Object

Emit a uint16_t type, a uint16_t length, and a value.

Parameters:

  • type (Integer)

    the type number

  • hsh (Hash)

    a mapping of command => value

See Also:



31
32
33
34
35
36
37
38
39
# File 'lib/bindef/extras/tlv.rb', line 31

def tlv_u16(type, hsh)
  u16 type

  cmd, value = hsh.shift

  send cmd, value do |blob|
    u16 blob.bytesize
  end
end

#tlv_u32(type, hsh) ⇒ Object

Emit a uint32_t type, a uint32_t length, and a value.

Parameters:

  • type (Integer)

    the type number

  • hsh (Hash)

    a mapping of command => value

See Also:



45
46
47
48
49
50
51
52
53
# File 'lib/bindef/extras/tlv.rb', line 45

def tlv_u32(type, hsh)
  u32 type

  cmd, value = hsh.shift

  send cmd, value do |blob|
    u32 blob.bytesize
  end
end

#tlv_u8(type, hsh) ⇒ Object

Emit a uint8_t type, a uint8_t length, and a value.

Examples:

tlv_u8 1, u32: 0xFF00FF00 # Emits: "\x01\x04\xFF\x00\xFF\x00"
tlv_u8 2, str: "hello" # Emits: "\x02\x05hello"

Parameters:

  • type (Integer)

    the type number

  • hsh (Hash)

    a mapping of command => value



17
18
19
20
21
22
23
24
25
# File 'lib/bindef/extras/tlv.rb', line 17

def tlv_u8(type, hsh)
  u8 type

  cmd, value = hsh.shift

  send cmd, value do |blob|
    u8 blob.bytesize
  end
end