Created
September 12, 2021 22:13
-
-
Save cabo/a5f44e3ba3182b2cfb2cf07c15477389 to your computer and use it in GitHub Desktop.
What is the state of consumption of the various ranges available for allocating CBOR tags?
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 | |
# coding: utf-8 | |
require 'rexml/document' | |
require 'open-uri' | |
# require 'open-uri/cached' | |
CBOR_TAGS = "https://www.iana.org/assignments/cbor-tags/cbor-tags.xml" | |
ACCEPT_XML = {"Accept" => "application/xml"} | |
xml_src = URI(CBOR_TAGS).open(ACCEPT_XML).read | |
# puts xml_src | |
doc = REXML::Document.new(xml_src) | |
def count_range(s) | |
a, b = s.split("-").map {Integer(_1)} | |
[a, if b | |
b - a + 1 | |
else | |
1 | |
end] | |
end | |
RANGES = [24, 0x100, 0x10000, 0x100000000, 0x10000000000000000] | |
RANGE_COUNTS = [0] * 5 | |
RANGE_UNASSIGNEDS = [0] * 5 | |
RANGE_LABELS = [0, 1, 2, 4, 8].map {"1+#{_1}"} | |
def to_range(val) | |
i = 0 | |
while RANGES[i] <= val | |
i += 1 | |
end | |
i | |
end | |
NS = {"xmlns" => "http://www.iana.org/assignments"} | |
REXML::XPath.each(doc.root, "/xmlns:registry/xmlns:registry/xmlns:record", NS) do |x| | |
value = x.elements['value'] | |
a, n = count_range(value.text) | |
r = to_range(a) | |
semantics = x.elements['semantics'] | |
if semantics.text | |
RANGE_COUNTS[r] += n | |
else | |
RANGE_UNASSIGNEDS[r] += n | |
end | |
end | |
puts "range used % free total" | |
(0...5).each do |i| | |
total = RANGES[i] - (i == 0 ? 0 : RANGES[i-1]) | |
ct = RANGE_COUNTS[i] | |
ua = RANGE_UNASSIGNEDS[i] | |
if total != ct + ua | |
puts "huh" | |
end | |
s = "%0#4.2f" % (ct*100.0/total) | |
puts "%d %s %5d %05s %20d %20d" % [i, RANGE_LABELS[i], ct, s, ua, total] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment