Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 5: In function encode_varint - Why use < 0xfd instead of < 0x100 for one byte strings, similar to the larger options? #274

Closed
derekpa opened this issue Oct 5, 2023 · 1 comment

Comments

@derekpa
Copy link

derekpa commented Oct 5, 2023

Why not use the full byte capacity or the first one byte option, selecting values < 0xfd instead of < 0x100?

Thanks.

if i < 0x100: return bytes([i]) elif i < 0x10000: return b'\xfd' + int_to_little_endian(i, 2)

instead of

if i < 0xfd: return bytes([i]) elif i < 0x10000: return b'\xfd' + int_to_little_endian(i, 2)

@derekpa derekpa changed the title function encode_varint use one byte strings for values < 0xfd instead of < 0xff Chapter 5 function encode_varint use one byte strings for values < 0xfd instead of < 0xff Oct 5, 2023
@derekpa derekpa changed the title Chapter 5 function encode_varint use one byte strings for values < 0xfd instead of < 0xff Chapter 5 function encode_varint Why use < 0xfd instead of < 0x100 for one byte strings, similar to the larger options? Oct 5, 2023
@derekpa derekpa changed the title Chapter 5 function encode_varint Why use < 0xfd instead of < 0x100 for one byte strings, similar to the larger options? Chapter 5: In function encode_varint - Why use < 0xfd instead of < 0x100 for one byte strings, similar to the larger options? Oct 5, 2023
@derekpa
Copy link
Author

derekpa commented Oct 5, 2023

OK, I assume its because 0xfd to 0xff are used as flags. Makes sense.

@derekpa derekpa closed this as completed Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant