Azure / azure-amqp

AMQP C# library
Other
94 stars 70 forks source link

Expose method returning raw bytes of AMQP message #238

Open JoshLove-msft opened 1 year ago

JoshLove-msft commented 1 year ago
          We might want to ask the AMQP team to add an API for it.

_Originally posted by @KrzysztofCwalina in https://github.com/Azure/azure-sdk-for-net/pull/33682#discussion_r1087328556_

Currently, we need to either use ToStream or GetPayload to get the raw bytes for the AMQP message. ToStream returns a stream which we need to convert back into bytes. GetPayload returns a list of array segments that we would need to concatenate. Also, GetPayload is only available in hotfix, not in main. It would be good to have an API to get the raw bytes of an AMQP message directly. Similarly, it would be good to have an API that creates the message from bytes, rather than needing to convert the bytes first to a stream.

xinchen10 commented 1 year ago

Is this for usability or performance? At least the new GetBytes API would not improve performance over the ToStream method. The message serialization internally avoids creating a big buffer to hold the entire message. it is always a segmented list of byte arrays for various parts of the message. To give a single byte array (or other types) the new API would need to copy all bytes into the returned type. It is just a matter of where the bytes are copied: in the library or by the user.

The deserialization from a byte array (or something similar) is a valid request. That would save a few lines of code for the user and improve usability a little bit.