Created
April 13, 2026 08:21
-
-
Save cabo/ab4cd9ece948587b3c0e43223c2d941c to your computer and use it in GitHub Desktop.
Quick decode of coap option number
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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