upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/rbf0_encode.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/rbf0_encode.py')
-rw-r--r--tools/rbf0_encode.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/tools/rbf0_encode.py b/tools/rbf0_encode.py
index eaf9d9c04..2cf46a68e 100644
--- a/tools/rbf0_encode.py
+++ b/tools/rbf0_encode.py
@@ -66,17 +66,23 @@ class _Writer:
66 if index > self.emitted: 66 if index > self.emitted:
67 raise EncodeError("descriptor", f"descriptor {index} is used before descriptor {self.emitted}") 67 raise EncodeError("descriptor", f"descriptor {index} is used before descriptor {self.emitted}")
68 self.out += bytes((index, kind)) 68 self.out += bytes((index, kind))
69 name = node.get("name", "")
69 if index == self.emitted: 70 if index == self.emitted:
70 name = node.get("name", "")
71 if index in self.bad_names: 71 if index in self.bad_names:
72 raise EncodeError("utf8", f"descriptor {index} name had invalid UTF-8") 72 raise EncodeError("utf8", f"descriptor {index} name had invalid UTF-8")
73 if index < len(self.names) and self.names[index] not in (None, name): 73 if index < len(self.names) and self.names[index] not in (None, name):
74 raise EncodeError("descriptor", f"descriptor {index} is named both {self.names[index]!r} and {name!r}") 74 raise EncodeError("descriptor", f"descriptor {index} is named both {self.names[index]!r} and {name!r}")
75 if index == len(self.names):
76 self.names.append(name)
77 else:
78 self.names[index] = name
75 raw = name.encode("utf-8") 79 raw = name.encode("utf-8")
76 if len(raw) > 0xFFFF: 80 if len(raw) > 0xFFFF:
77 raise EncodeError("length", f"descriptor {index} name is {len(raw)} bytes") 81 raise EncodeError("length", f"descriptor {index} name is {len(raw)} bytes")
78 self.out += struct.pack("<H", len(raw)) + raw 82 self.out += struct.pack("<H", len(raw)) + raw
79 self.emitted += 1 83 self.emitted += 1
84 elif index < len(self.names) and self.names[index] not in (None, name):
85 raise EncodeError("descriptor", f"descriptor {index} is named both {self.names[index]!r} and {name!r}")
80 86
81 def float_bits(self, value, special): 87 def float_bits(self, value, special):
82 if special is not None: 88 if special is not None: