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
{{ message }}
Repository navigation
Support writing binary data from ReadOnlyMemory<byte> #2392
Originally raised in #2390. Writing from ReadOnlySpan<byte> isn't going to be possible as it can't exist on the heap (and ADO.NET requires NpgsqlParameter.Value to be set to it).
Is there any reason in principle to not also support DbCommand.ValueDbParameter.Value being set to Memory<byte> or ArraySegment<byte>, as a convenience? (Counterargument: no one's ever asked for it; once ReadOnlyMemory<byte> is supported, it's easy to add .AsMemory() at the call site as a workaround.)
being set to Memory or ArraySegment, as a convenience?
You're asking about supporting Memory<byte> in addition to ReadOnlyMemory<byte>, right? If so, in general, write APIs seem to accept the read-only types (e.g. Stream.Write(ReadOnlySpan), with an implicit cast making the transition easier. It's true that ADO.NET is a bit more tricky, since you set Value of type object, so implicit casting doesn't work and users will have to do it explicitly - except if you use the typed NpgsqlParameter<T>. So I'm not too sure, maybe we should wait for someone to complain first?
If so, in general, write APIs seem to accept the read-only types
It's fairly common for DbParameter.Value to be bound to byte[], which is not a read-only type. (Nor is ArraySegment<byte>.) Supporting Memory<byte> seemed similar (and avoided the casting problems).
If so, in general, write APIs seem to accept the read-only types
It's fairly common for DbParameter.Value to be bound to byte[], which is not a read-only type. (Nor is ArraySegment.) Supporting Memory seemed similar (and avoided the casting problems).
That's true, but that's because there's no read-only alternative to byte[]. It seems that for all Span/Memory APIs which were added to the BCL, the read-only version is accepted for write operations. Again, this doesn't make a big difference for BCL APIs since there's an implicit cast.
Note: this option will only be available when targeting .NET Standard 2.1, since there's no (efficient) way to write Memory to Socket/NetworkStream in .NET Standard 2.0. We could in theory target a version of .NET Core under 3.0, but that seems a bit unnecessary.
Activity
[-]Support writing binary data from Memory<byte>[/-][+]Support writing binary data from ReadOnlyMemory<byte>[/+]bgrainger commentedon Mar 27, 2019
Is there any reason in principle to not also support
DbCommand.ValueDbParameter.Valuebeing set toMemory<byte>orArraySegment<byte>, as a convenience? (Counterargument: no one's ever asked for it; onceReadOnlyMemory<byte>is supported, it's easy to add.AsMemory()at the call site as a workaround.)roji commentedon Mar 27, 2019
You mean
DbParameter.Value, right?You're asking about supporting
Memory<byte>in addition toReadOnlyMemory<byte>, right? If so, in general, write APIs seem to accept the read-only types (e.g. Stream.Write(ReadOnlySpan), with an implicit cast making the transition easier. It's true that ADO.NET is a bit more tricky, since you setValueof type object, so implicit casting doesn't work and users will have to do it explicitly - except if you use the typedNpgsqlParameter<T>. So I'm not too sure, maybe we should wait for someone to complain first?PS Npgsql already supports writing
ArraySegment<byte>.bgrainger commentedon Mar 27, 2019
Yes, fixed.
It's fairly common for
DbParameter.Valueto be bound tobyte[], which is not a read-only type. (Nor isArraySegment<byte>.) SupportingMemory<byte>seemed similar (and avoided the casting problems).Good to know. MySqlConnector does now, too. :)
roji commentedon Mar 27, 2019
That's true, but that's because there's no read-only alternative to byte[]. It seems that for all Span/Memory APIs which were added to the BCL, the read-only version is accepted for write operations. Again, this doesn't make a big difference for BCL APIs since there's an implicit cast.
roji commentedon Apr 18, 2019
Note: this option will only be available when targeting .NET Standard 2.1, since there's no (efficient) way to write Memory to Socket/NetworkStream in .NET Standard 2.0. We could in theory target a version of .NET Core under 3.0, but that seems a bit unnecessary.
Work around binary writing support
Work around binary writing support (#2445)