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

VarInt decoding pseudocode #4316

Merged
merged 5 commits into from Nov 3, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions draft-ietf-quic-transport.md
Expand Up @@ -7491,12 +7491,12 @@ sequence of bytes to read from.

~~~
ReadVarint(data):
first_byte = data.peek()
prefix = first_byte >> 6
num_bytes = 1 << prefix
mask = (1 << (num_bytes * 8 - 2)) - 1

return data.read(num_bytes) & mask
v = data.next_byte()
length = (1 << (v >> 6))
v = v & 0x3f
repeat length-1 times:
v = (v << 8) + data.next_byte()
return v
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v is also in network byte-order, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but I'm not sure that's necessary to mention. We haven't changed it over the course of the algorithm.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How could it not be in network byte order? Unless next_byte does something other than read the next byte.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that we might want to say that the value still needs to converted into host byte order before it can be used.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this do that? I mean, the operations here are numeric, so unless << means "divide by 2^n", we're good, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah -- there's nothing here that is endian-specific.

~~~
{: #alg-varint title="Sample Variable-Length Integer Decoding Algorithm"}

Expand Down