Skip to content

Instantly share code, notes, and snippets.

@cabo
Created April 13, 2026 08:21
Show Gist options
  • Select an option

  • Save cabo/ab4cd9ece948587b3c0e43223c2d941c to your computer and use it in GitHub Desktop.

Select an option

Save cabo/ab4cd9ece948587b3c0e43223c2d941c to your computer and use it in GitHub Desktop.
Quick decode of coap option number
#!/usr/bin/env ruby -KU
ARGV.each do |arg|
i = Integer(arg)
puts "Option number: #{i} = 0b#{"%b" % i} = 0x#{"%x" % i}"
no_cache_key = false
descr = " "
descr << " C = #{i[0]}"
if i[0] != 0
puts " Critical"
else
puts " Elective"
end
descr << ", U = #{i[1]}"
if i[1] != 0
puts " Unsafe-to-forward"
else
descr << ", N = #{"%03b" % i[2..4]}"
puts " Safe-to-forward"
if i[2..4] == 7
puts " No Cache Key"
no_cache_key = true
end
end
unless no_cache_key
puts " Cache Key"
end
puts descr
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment