What is Nostr?
Tyler the Enginigger /
npub1a8p…2ncx
2024-11-07 01:07:21
in reply to nevent1q…gvtk

Tyler the Enginigger on Nostr: # encode a unsigned variable length integer def encode_uvint(value): output = ...


# encode a unsigned variable length integer
def encode_uvint(value):
output = bytearray()
while value >= 0x80:
output.append((value & 0x7F) + 0x80)
value >>= 8
output.append(value)
return output

# decode a unsigned variable length integer
# return the number of bytes consumed and the value
# On failure, the returned number of bytes consumed is -1
def decode_uvint(data):
result = 0
shift = 0
offset = 0
while True:
if offset >= len(data):
return (-1, None)
result |= (data[offset] & 0x7f) << shift
if data[offset] & 0x80 == 0:
return (offset + 1, result)
shift += 7
offset += 1
Author Public Key
npub1a8p5fz2ja6dsntqvngf7x2ej7gp43q2w8e85lfnxqexsqdslpmdqhe2ncx