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 Read and WriterTo methods to envelopes #622

Closed
wants to merge 1 commit into from

Conversation

emcfarlane
Copy link
Contributor

Allow src and dst to be set for envelope read/writers. Envelopes also implement io.Reader and io.WriterTo methods to allow passing envelopes as a message payload.

Requirement for #611 to avoid copying the buffers. See #609

Allow src and dst to be set for envelope read/writers. Envelopes also
implement io.Reader and io.WriterTo methods to allow passing envelopes
as a message payload.
@emcfarlane emcfarlane requested a review from jhump November 2, 2023 15:44
@emcfarlane emcfarlane self-assigned this Nov 2, 2023
if !env.IsSet(flagEnvelopeCompressed) &&
w.compressionPool != nil &&
env.Data.Len() > w.compressMinBytes {
if err := w.compress(env.Data); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Behaviour change on Write, now mutates the *env to compress, if needed. Nothing currently depended on the *env being unchanged.

Copy link
Member

Choose a reason for hiding this comment

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

These kinds of changes (mostly code motion) are sooo much easier to review if you don't change behavior at all. Was this change actually necessary? If not, please just omit and maybe do in a follow-up.

e.offset += n
wroteN += int64(n)
return wroteN, err
}
Copy link
Contributor Author

@emcfarlane emcfarlane Nov 2, 2023

Choose a reason for hiding this comment

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

For #611 will also need to add func (e *envelope) Rewind() { b.offset = 0}

Copy link
Member

Choose a reason for hiding this comment

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

I think it would be way cleaner if envelope were immutable once sent. So that means we'd instead want a NewReader() io.Reader method, so that thing can be mutable/rewindable. That way, if any synchronization becomes necessary (as exists in the payload thingie in #611), it can live in that reader impl and not leak into the envelope struct itself.

@jhump jhump mentioned this pull request Nov 2, 2023
6 tasks
@jhump jhump changed the title Add Read an WriterTo methods to envelopes Add Read and WriterTo methods to envelopes Nov 2, 2023
Copy link
Member

@jhump jhump left a comment

Choose a reason for hiding this comment

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

I don't see why we're changing from currying the writer in the envelopeWriter to not. That seems unrelated and unnecessary.

I know you stated in the description that you don't see why it's "necessary", but I'm afraid I don't see why it's necessary to change. This seems like aesthetic choice (IMO, low value) that expands the blast radius of this PR by several files and dozens of call sites. If it's not needed for the change, let's please leave it out. In fact, it seems like you'll end up having to undo/redo it anyway to actually change duplexHTTPCall so it has a send(*envelope) method instead of implementing io.Writer.

In fact, I think it's actually worth making that change (changing duplexHTTPCall to actually use what's in this branch) in this PR, so we can see what that looks like even before the unary-request specialization change.

if !env.IsSet(flagEnvelopeCompressed) &&
w.compressionPool != nil &&
env.Data.Len() > w.compressMinBytes {
if err := w.compress(env.Data); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

These kinds of changes (mostly code motion) are sooo much easier to review if you don't change behavior at all. Was this change actually necessary? If not, please just omit and maybe do in a follow-up.

e.offset += n
wroteN += int64(n)
return wroteN, err
}
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be way cleaner if envelope were immutable once sent. So that means we'd instead want a NewReader() io.Reader method, so that thing can be mutable/rewindable. That way, if any synchronization becomes necessary (as exists in the payload thingie in #611), it can live in that reader impl and not leak into the envelope struct itself.

@emcfarlane emcfarlane marked this pull request as draft November 2, 2023 19:03
@emcfarlane
Copy link
Contributor Author

currying the writer in the envelopeWriter to not. That seems unrelated and unnecessary.

I don't understand what you are asking for. How can I call a different method on duplexHTTPCall and still wrap it as an io.Writer?

I know you stated in the description that you don't see why it's "necessary", but I'm afraid I don't see why it's necessary to change.

I didn't, but they aren't. Why do we have a different call sites for unary vs envelope? The only difference should be the prefix which we can cover by wrapping in an envelope payload. I'll make a proposal for the work and post it in the issue.

@jhump
Copy link
Member

jhump commented Nov 2, 2023

How can I call a different method on duplexHTTPCall and still wrap it as an io.Writer?

You can't, hence me suggesting that the changes here will need to be undone/re-done to weave a different type through.

Why do we have a different call sites for unary vs envelope?

Sorry, I guess I need to go look at a little more of the code to get adequate context for this.

@emcfarlane
Copy link
Contributor Author

emcfarlane commented Nov 2, 2023

Closing, will discuss the internal API changes needed in #609

@emcfarlane emcfarlane closed this Nov 2, 2023
@emcfarlane emcfarlane deleted the ed/envelope-writers branch November 2, 2023 21:05
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