Skip to content

Remove test-utility wrapper for Buffer::toString().#51

Merged
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
jmarantz:use-buffer-to-string-method
Jun 27, 2018
Merged

Remove test-utility wrapper for Buffer::toString().#51
mattklein123 merged 2 commits intoenvoyproxy:masterfrom
jmarantz:use-buffer-to-string-method

Conversation

@jmarantz
Copy link
Contributor

No description provided.

Signed-off-by: Joshua Marantz <jmarantz@google.com>
lookupPort("listener_0"), buffer,
[&](Network::ClientConnection&, const Buffer::Instance& data) -> void {
response.append(TestUtility::bufferToString(data));
response.append(Buffer::OwnedImpl(data).toString());
Copy link
Member

Choose a reason for hiding this comment

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

Why can't toString() just be called on data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah -- this is the trick :)

In envoyproxy/envoy#3629 @htuch challenged me why we need another interface function (toString()) which is somewhat overlapping with serialize(). So I noted that removing it from the abstract interface and just having that function on BufferOwned::Impl worked (that's the way it is checked in now).

However it doesn't work to just say buffer_interface_var->toString(), even though it worked to call TestUtility::bufferToString(buffer_interface_var). The reason that worked is that OwnedImpl has an implicit constructor from const BufferInstance&, so the compiler automatically finds that.

So in envoyproxy/envoy#3736 I worked around that by adding the new interface in Buffer::Instance, but in this PR, in a different repo, I don't have that. So I help the compiler out by explicitly constructing the Buffer::OwnedImpl from the Buffer::Instance before referencing.

I could also go back to envoyproxy/envoy#3736 and remove the Buffer::Interface::toString(), and instead rely on explicit construction of an OwnedImpl in order to access its toString(). I think that happens about 10 of the 53 times this gets called in that repo. I'm fine either way.

Copy link
Member

Choose a reason for hiding this comment

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

We can also just force merge this even though it doesn't pass tests, and then update the SHA here once the other thing merges. That's probably cleaner?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's fine with me too if it's OK to wind up with Buffer::Instance::toString() permanently.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I don't follow. It's on the interface in your current PR. At that point, can't you just do data.toString()?

Signed-off-by: Joshua Marantz <jmarantz@google.com>
@mattklein123 mattklein123 merged commit 92307d7 into envoyproxy:master Jun 27, 2018
@jmarantz jmarantz deleted the use-buffer-to-string-method branch June 27, 2018 02:23
@mattklein123
Copy link
Member

@jmarantz just force merged, please come back and update the SHA here when the other one merges.

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.

2 participants