Skip to content

Add ReadOnlyMemory overload to BasicPublish #788

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

Merged

Conversation

Anarh2404
Copy link
Contributor

Proposed Changes

Add ReadOnlyMemory overload to BasicPublish.
That allows to send part of the array without creating a new one.

Types of Changes

  • Bug fix (non-breaking change which fixes issue #NNNN)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause an observable behavior change in existing systems)
  • Documentation improvements (corrections, new content, etc)
  • Cosmetic change (whitespace, formatting, etc)

Checklist

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

@michaelklishin
Copy link
Contributor

I definitely like the idea but one thing in the implementation colored me surprised.

@lukebakken lukebakken self-assigned this Mar 29, 2020
@lukebakken lukebakken added this to the 6.0.0 milestone Mar 29, 2020
@stebet
Copy link
Contributor

stebet commented Mar 29, 2020

The byte[] overload for publish might be unnecessary now since byte[] can be implicitly cast to ReadOnlySpan. I'll review this later tonight :)

@@ -1108,10 +1108,14 @@ public void MaybeEmitModelMethod(MethodInfo method)

public string SanitisedFullName(Type t)
{
if (t.FullName.StartsWith("System.Collections.Generic.IDictionary`2[[System.String"))
if (t.Equals(typeof(IDictionary<string, object>)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

The previous approach had a potential bug in that it would treat any IDictionary<string, T> as IDictionary<string, object>, so this is definitely better.

@bording
Copy link
Collaborator

bording commented Mar 29, 2020

The byte[] overload for publish might be unnecessary now since byte[] can be implicitly cast to ReadOnlySpan. I'll review this later tonight :)

@stebet I was just about to suggest the same thing. Seems like it makes sense to drop the byte[] overloads entirely.

@stebet
Copy link
Contributor

stebet commented Mar 29, 2020

Yeah. I'll review later and do some experiments.

@Anarh2404
Copy link
Contributor Author

It makes sense. I can update this PR.
@michaelklishin @lukebakken what do you think?

@michaelklishin
Copy link
Contributor

@Anarh2404 @stebet @bording there is a lot of code out there on the Internet that demonstrates using a byte array. Having an overload is a must but we can make it secondary to the one that uses ReadOnlyMemory. So, we always use ReadOnlyMemory internally but provide at least one additional overload.

We can update our tutorials use ReadOnlyMemory although we'd have to briefly explain what it is.

@bording
Copy link
Collaborator

bording commented Mar 29, 2020

@Anarh2404 @stebet @bording there is a lot of code out there on the Internet that demonstrates using a byte array. Having an overload is a must but we can make it secondary to the one that uses ReadOnlyMemory. So, we always use ReadOnlyMemory internally but provide at least one additional overload.

We can update our tutorials use ReadOnlyMemory although we'd have to briefly explain what it is.

The reason we're suggesting this is that nothing changes to the consumer. They continue to use byte arrays.

ReadOnlyMemory<byte> is a struct that has implicit conversions defined for byte[] and can also accept other backing sources.

There's no reason to keep having a byte[] overload when you have ReadOnlyMemory<byte>.

@michaelklishin
Copy link
Contributor

OK, thanks for clarifying.

@stebet
Copy link
Contributor

stebet commented Mar 29, 2020

ReadOnlySpan is actually the lowest abstraction. If this can be modified to work with rhat, it should work with pretty much everything (Span, arraysegments, byte arrays, memory).

@Anarh2404
Copy link
Contributor Author

ReadOnlySpan may be a problem when a fully async version is being developed, because ReadOnlySpan cannot be an argument of an async methods.

@michaelklishin michaelklishin merged commit eb48e2d into rabbitmq:master Mar 29, 2020
@michaelklishin
Copy link
Contributor

michaelklishin commented Mar 29, 2020

Always great to both extend the API for more modern ways of doing things and remove the original API bits without losing backwards compatibility 😮 Thank you so much @Anarh2404 @bording @stebet! 👏

@Anarh2404 Anarh2404 deleted the basicpublish-readonlymemory-overload branch March 29, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants