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

Show how to read large field values (e.g. strings, binary values) into streams with ODataMessageReader #337

Open
habbes opened this issue Oct 24, 2024 · 0 comments

Comments

@habbes
Copy link
Contributor

habbes commented Oct 24, 2024

When you have fields which large values, usually strings or binary data encoded as base64 strings, deserializing these fields might lead to large heap allocations due to reading the entire value into memory. ODataMessageWriter exposes a ReadAsStreamFunc property that the user can assign a delegate that returns true for any property that should be deserialized into a stream. This feature is not documented but is useful work performance-sensitive services working which large payloads.

Basically, there are two steps:

  • Register a ReadAsStreamFunc on the message writer settings which return true for the properties that you want to stream. ODL will call your function for each property and, if you return true, will enter a new reader state ODataReaderState.Stream.
  • Handle the ODataReaderState.Stream state by creating stream or text reader, depending on the type of the property, and read the stream.

Here's a test that demonstrates the feature: https://github.com/OData/odata.net/blob/release-7.x/test/FunctionalTests/Microsoft.OData.Core.Tests/JsonLight/ODataJsonLightReaderTests.cs#L846

We should add a tutorial article this and/or mention it in the performance guidelines

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

No branches or pull requests

1 participant