Skip to content

thrift: transport and protocol write code#3789

Merged
zuercher merged 1 commit intoenvoyproxy:masterfrom
turbinelabs:stephan/thrift-translation
Jul 9, 2018
Merged

thrift: transport and protocol write code#3789
zuercher merged 1 commit intoenvoyproxy:masterfrom
turbinelabs:stephan/thrift-translation

Conversation

@zuercher
Copy link
Copy Markdown
Member

@zuercher zuercher commented Jul 3, 2018

Matches the read side implementations. Transport writes require having the
entire protocol message and so the write methods do not mirror reads. This
is further preparation for a Thrift router that can translate requests between
transports and protocols.

Risk Level: low, code not used
Testing: unit tests
Docs Changes: n/a
Release Notes: n/a

Signed-off-by: Stephan Zuercher stephan@turbinelabs.io

Matches the read side implementations. Transport writes require having the
entire protocol message and so the write methods do not mirror reads.

*Risk Level*: low, code not used
*Testing*: unit tests
*Docs Changes*: n/a
*Release Notes*: n/a

Signed-off-by: Stephan Zuercher <stephan@turbinelabs.io>
Copy link
Copy Markdown
Contributor

@brian-pane brian-pane left a comment

Choose a reason for hiding this comment

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

Thanks for this PR. This looks good overall. I'm still reading through it, but here are my (minor) comments and questions on the first half.

return;
}

BufferHelper::writeI16(buffer, field_id);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Negative values for field_id are okay, right?

Copy link
Copy Markdown
Member Author

@zuercher zuercher Jul 9, 2018

Choose a reason for hiding this comment

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

According to the protocol specs, it's a signed, 16-bit integer. The thrift code generator will not let you choose negative values or 0. That said, I think I'll allow negative values, just in case.


BufferHelper::writeI8(buffer, static_cast<int8_t>(key_type));
BufferHelper::writeI8(buffer, static_cast<int8_t>(value_type));
BufferHelper::writeI32(buffer, static_cast<int32_t>(size));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we verify that size is nonnegative? (Same question applies to writeListBegin and writeSetBegin)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There's a comparison of size against INT32_MAX (which is 0x7fffffff) which guarantees that static_cast<int32_t>(size) is non-negative.

Copy link
Copy Markdown
Contributor

@brian-pane brian-pane left a comment

Choose a reason for hiding this comment

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

I just read through the rest, and it looks ok to me.

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM from skim. Small optional nit. Can do in followup if you want.


void BinaryProtocolImpl::writeMapBegin(Buffer::Instance& buffer, FieldType key_type,
FieldType value_type, uint32_t size) {
if (size > INT32_MAX) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: std::numeric_limits here and elsewhere?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll do this in a follow-up.

@zuercher zuercher merged commit fd57604 into envoyproxy:master Jul 9, 2018
@zuercher zuercher deleted the stephan/thrift-translation branch July 19, 2018 20:54
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.

3 participants