You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Would it make sense to add a similar option to read JSON columns as byte[] (instead of a string)?
On .NET 6.0 and later, MySqlDataReader could expose a GetUtf8JsonReader method that returns a Utf8JsonReader. This would allow users to call JsonNode.Parse or JsonSerializer.Deserialize to read straight from MySqlConnector's buffer.
Reasons not to do this could be:
Utf8JsonReader is a ref struct that can't be used in async methods
Exposing ReadOnlyMemory<byte> would allow JsonDocument.Parse to be called, but that could introduce serious lifetime issues because "the ReadOnlyMemory value will be used for the entire lifetime of the JsonDocument object, and the caller must ensure that the data therein does not change during the object lifetime." (ReadOnlyMemory<byte> would also allow Utf8JsonReader to be constructed from its .Span, enabling the scenarios above.)
The text was updated successfully, but these errors were encountered:
The existing MySqlDataReader.GetStream() API creates a Stream on the already-in-memory data, and can be used with JsonNode.Parse, JsonDocument.Parse, and JsonSerializer.Deserialize. It's probably the best approach to recommend; maybe some documentation showing samples of how to use it should be added.
From #1451 (comment):
On .NET 6.0 and later,
MySqlDataReader
could expose aGetUtf8JsonReader
method that returns a Utf8JsonReader. This would allow users to call JsonNode.Parse or JsonSerializer.Deserialize to read straight from MySqlConnector's buffer.Reasons not to do this could be:
Utf8JsonReader
is aref struct
that can't be used in async methodsMySqlDataReader.Read(Async)
is called again; see discussion at Span-based way to read binary data in ADO.NET dotnet/runtime#24899Exposing
ReadOnlyMemory<byte>
would allow JsonDocument.Parse to be called, but that could introduce serious lifetime issues because "the ReadOnlyMemory value will be used for the entire lifetime of the JsonDocument object, and the caller must ensure that the data therein does not change during the object lifetime." (ReadOnlyMemory<byte>
would also allowUtf8JsonReader
to be constructed from its.Span
, enabling the scenarios above.)The text was updated successfully, but these errors were encountered: