Module: OMQ::QoS::CommandExt

Defined in:
lib/omq/qos/zmtp/command_ext.rb

Overview

Prepended onto Protocol::ZMTP::Codec::Command to add ACK/NACK/CLR/COMP data extraction methods.

Instance Method Summary collapse

Instance Method Details

#ack_dataArray(String, String)

Extracts algorithm prefix and hash bytes from an ACK command's data.

Returns:

  • (Array(String, String))

    [algorithm, hash_bytes]



63
64
65
66
67
# File 'lib/omq/qos/zmtp/command_ext.rb', line 63

def ack_data
  algo      = @data.byteslice(0, 1)
  hash_size = Protocol::ZMTP::Codec::Command::ACK_HASH_SIZES.fetch(algo, 8)
  [algo, @data.byteslice(1, hash_size)]
end

#clr_dataArray(String, String)

Same layout as ACK.

Returns:

  • (Array(String, String))

    [algorithm, hash_bytes]



73
74
75
# File 'lib/omq/qos/zmtp/command_ext.rb', line 73

def clr_data
  ack_data
end

#comp_dataArray(String, String)

Same layout as ACK — COMP carries only the digest.

Returns:

  • (Array(String, String))

    [algorithm, hash_bytes]



81
82
83
# File 'lib/omq/qos/zmtp/command_ext.rb', line 81

def comp_data
  ack_data
end

#nack_dataArray(String, String, Integer, String)

Extracts algorithm, hash bytes, NACK code, and error message from a NACK command's data. See OMQ::QoS::CommandClassExt#nack for the wire layout.

Returns:

  • (Array(String, String, Integer, String))

    [algorithm, hash_bytes, code, message]



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/omq/qos/zmtp/command_ext.rb', line 92

def nack_data
  algo      = @data.byteslice(0, 1)
  hash_size = Protocol::ZMTP::Codec::Command::ACK_HASH_SIZES.fetch(algo, 8)
  hash      = @data.byteslice(1, hash_size)
  off       = 1 + hash_size
  header    = @data.byteslice(off, 3)

  if header && header.bytesize == 3
    code, msg_len = header.unpack("Cn")
    message       = @data.byteslice(off + 3, msg_len) || "".b
  else
    code, message = 0, "".b
  end

  [algo, hash, code, message]
end