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

Add ProtoReader API for length-delimited stream reads #2747

Merged
merged 1 commit into from
Dec 13, 2023

Conversation

JakeWharton
Copy link
Member

Closes #633

Comment on lines +137 to +139
check(state == STATE_TAG || state == STATE_LENGTH_DELIMITED) {
"Unexpected call to nextDelimited()"
}
Copy link
Member Author

Choose a reason for hiding this comment

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

It's not clear this is useful. Could eliminate and only have the one function.

Copy link
Member

Choose a reason for hiding this comment

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

Could we make it clearer by telling which state we're in? I don't mind whether we keep it or not

Copy link
Member Author

Choose a reason for hiding this comment

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

The message is the same as other places in this file. I can update them all separately to include the current state.

@JakeWharton JakeWharton force-pushed the jw.next-length-delimited.2023-12-12 branch from b06b8d0 to cf6698e Compare December 13, 2023 00:46
@@ -32,4 +32,25 @@ class ProtoReaderTest {
assertEquals(-1, reader.nextTag())
reader.endMessageAndGetUnknownFields(token)
}

@Test fun lengthDelimited() {
val encoded = "0208020608ffffffff07".decodeHex()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
val encoded = "0208020608ffffffff07".decodeHex()
// Bytes representing:
// ── 0 ┐
// ╰- 0 ┐
// ╰- 1: 2147483647
val encoded = "0208020608ffffffff07".decodeHex()

Copy link
Member Author

Choose a reason for hiding this comment

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

This is not a single proto. It's two protos prefixed with their varint32-encoded lengths. I'll add a comment.

Copy link
Member

Choose a reason for hiding this comment

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

sweet

Comment on lines +137 to +139
check(state == STATE_TAG || state == STATE_LENGTH_DELIMITED) {
"Unexpected call to nextDelimited()"
}
Copy link
Member

Choose a reason for hiding this comment

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

Could we make it clearer by telling which state we're in? I don't mind whether we keep it or not

@JakeWharton JakeWharton force-pushed the jw.next-length-delimited.2023-12-12 branch from cf6698e to 2ea68d1 Compare December 13, 2023 18:18
@JakeWharton JakeWharton merged commit 877bc89 into master Dec 13, 2023
15 checks passed
@JakeWharton JakeWharton deleted the jw.next-length-delimited.2023-12-12 branch December 13, 2023 19:40
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

Successfully merging this pull request may close these issues.

How to read length-delimited messages?
2 participants