Skip to content

Conversation

markb74
Copy link
Contributor

@markb74 markb74 commented Nov 26, 2019

Add a new a Metadata.BinaryStreamMarshaller interface which serializes to/from instances of InputStream, and a corresponding Key.of() factory method.

Values set with this type of key will be kept unserialized internally, alongside a reference to the Marshaller. A new method InternalMetadata.serializePartial(), returns values which are either
byte[] or InputStream, allowing transport-specific handling of lazily-serialized values.

For the regular serialize() method, stream-marshalled values will be converted to byte[] via InputStreams.

Transport-internal code can also create metadata with pre-parsed values.

First add a new a Metadata.BinaryStreamMarshaller interface which
serializes to/from instances of InputStream, and a corresponding
Key.of() factory method.

Values set with this type of key will be kept unserialized internally,
alongside a reference to the Marshaller.x A new method
InternalMetadata.serializePartial(), returns values which are either
byte[] or InputStream, and allows transport-specific handling of
lazily-serialized values.

For the regular serialize() method, stream-marshalled values will be
converted to byte[] via an InputStreams.
First add a new a Metadata.BinaryStreamMarshaller interface which
serializes to/from instances of InputStream, and a corresponding
Key.of() factory method.

Values set with this type of key will be kept unserialized internally,
alongside a reference to the Marshaller.x A new method
InternalMetadata.serializePartial(), returns values which are either
byte[] or InputStream, and allows transport-specific handling of
lazily-serialized values.

For the regular serialize() method, stream-marshalled values will be
converted to byte[] via an InputStreams.
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 26, 2019

CLA Check
The committers are authorized under a signed CLA.

@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Nov 26, 2019
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Nov 26, 2019
@ejona86 ejona86 self-requested a review November 26, 2019 16:28
@ejona86 ejona86 requested a review from dapengzhang0 November 26, 2019 18:36
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

Looks pretty good. One important detail to nail down.

Relax test guarantees for streamed values, and return Object from
InternalMetadata.parsedValue
@markb74 markb74 requested a review from ejona86 November 29, 2019 12:06
@markb74 markb74 requested a review from dapengzhang0 December 4, 2019 15:04
Copy link
Contributor

@dapengzhang0 dapengzhang0 left a comment

Choose a reason for hiding this comment

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

Mostly LGTM, just need some more look to be more confident.

* @return the marshaller object for this key, or null.
*/
@Nullable
final <M> M getMarshaller(Class<M> marshallerClass) {
Copy link
Contributor

@dapengzhang0 dapengzhang0 Dec 11, 2019

Choose a reason for hiding this comment

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

Seems this method is only for binary stream marshaller, why not just

    @Nullable
    @SuppressWarnings("unchecked")
    final BinaryStreamMarshaller<T> getBinaryStreamMarshaller() {
      if (marshaller instanceof BinaryStreamMarshaller) {
        return (BinaryStreamMarshaller<T>) marshaller;
      }
      return null;
    }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to avoid having the Key class directly depend on a single Marshaller type really. This approach let me avoid that, while supporting other marshaller types as well. If figured this approach was worth it since we'd discussed possibly adding a TextStreamMarshaller later on.

I'm happy either way though, so I'll defer to your preference.

Copy link
Member

Choose a reason for hiding this comment

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

I saw the method and thought it was a bit odd, but it didn't see an obvious simple alternative that everyone would agree is superior. It is a bit weirder to be BinaryStreamMarshaller-specific as long as it is on the Key class. I'd be prone to moving the method to LazyStreamBinaryKey. But it just seemed beside the point and what is here is fine. We can always change it later.

Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

One key detail still, but it wouldn't involve much code churn.

@markb74 markb74 requested a review from dapengzhang0 December 12, 2019 12:44
@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Dec 12, 2019
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Dec 12, 2019
@ejona86 ejona86 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Dec 12, 2019
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Dec 12, 2019
@ejona86 ejona86 merged commit d107859 into grpc:master Dec 12, 2019
@ejona86
Copy link
Member

ejona86 commented Dec 12, 2019

@markb74, thank you! Thank you for working with us on the back-and-forth!

@lock lock bot locked as resolved and limited conversation to collaborators Mar 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants