Class ByteaHandler
A type handler for the PostgreSQL bytea data type.
Implements
Inherited Members
Namespace: Npgsql.Internal.TypeHandlers
Assembly: Npgsql.dll
Syntax
public class ByteaHandler : NpgsqlTypeHandler<byte[]>, INpgsqlTypeHandler<byte[]>, INpgsqlTypeHandler<ArraySegment<byte>>, INpgsqlTypeHandler<ReadOnlyMemory<byte>>, INpgsqlTypeHandler<Memory<byte>>
Remarks
See https://www.postgresql.org/docs/current/static/datatype-binary.html.
The type handler API allows customizing Npgsql's behavior in powerful ways. However, although it is public, it should be considered somewhat unstable, and may change in breaking ways, including in non-major releases. Use it at your own risk.
Constructors
ByteaHandler(PostgresType)
Declaration
public ByteaHandler(PostgresType pgType)
Parameters
Type | Name | Description |
---|---|---|
PostgresType | pgType |
Methods
Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Reads a value of type TDefault
with the given length from the provided buffer,
using either sync or async I/O.
Declaration
public override async ValueTask<byte[]> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | The buffer from which to read. |
Int32 | len | The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed. |
Boolean | async | If I/O is required to read the full length of the value, whether it should be performed synchronously or asynchronously. |
FieldDescription | fieldDescription | Additional PostgreSQL information about the type, such as the length in varchar(30). |
Returns
Type | Description |
---|---|
ValueTask<Byte[]> | The fully-read value. |
Overrides
ValidateAndGetLength(ArraySegment<Byte>, ref NpgsqlLengthCache, NpgsqlParameter)
Responsible for validating that a value represents a value of the correct and which can be written for PostgreSQL - if the value cannot be written for any reason, an exception should be thrown. Also returns the byte length needed to write the value.
Declaration
public int ValidateAndGetLength(ArraySegment<byte> value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<Byte> | value | |
NpgsqlLengthCache | lengthCache | A cache where the length calculated during the validation phase can be stored for use at the writing phase. |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |
Returns
Type | Description |
---|---|
Int32 | The number of bytes required to write the value. |
ValidateAndGetLength(Byte[], ref NpgsqlLengthCache, NpgsqlParameter)
Called to validate and get the length of a value of a generic NpgsqlParameter<T>.
Declaration
public override int ValidateAndGetLength(byte[] value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter |
Returns
Type | Description |
---|---|
Int32 |
Overrides
ValidateAndGetLength(Memory<Byte>, ref NpgsqlLengthCache, NpgsqlParameter)
Responsible for validating that a value represents a value of the correct and which can be written for PostgreSQL - if the value cannot be written for any reason, an exception should be thrown. Also returns the byte length needed to write the value.
Declaration
public int ValidateAndGetLength(Memory<byte> value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
Memory<Byte> | value | |
NpgsqlLengthCache | lengthCache | A cache where the length calculated during the validation phase can be stored for use at the writing phase. |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |
Returns
Type | Description |
---|---|
Int32 | The number of bytes required to write the value. |
ValidateAndGetLength(ReadOnlyMemory<Byte>, ref NpgsqlLengthCache, NpgsqlParameter)
Responsible for validating that a value represents a value of the correct and which can be written for PostgreSQL - if the value cannot be written for any reason, an exception should be thrown. Also returns the byte length needed to write the value.
Declaration
public int ValidateAndGetLength(ReadOnlyMemory<byte> value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyMemory<Byte> | value | |
NpgsqlLengthCache | lengthCache | A cache where the length calculated during the validation phase can be stored for use at the writing phase. |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |
Returns
Type | Description |
---|---|
Int32 | The number of bytes required to write the value. |
Write(ArraySegment<Byte>, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
Writes a value to the provided buffer.
Declaration
public Task Write(ArraySegment<byte> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ArraySegment<Byte> | value | |
NpgsqlWriteBuffer | buf | The buffer to which to write. |
NpgsqlLengthCache | lengthCache | A cache where the length calculated during the validation phase can be stored for use at the writing phase. |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |
Boolean | async | If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task |
Write(Byte[], NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
Called to write the value of a generic NpgsqlParameter<T>.
Declaration
public override Task Write(byte[] value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Byte[] | value | |
NpgsqlWriteBuffer | buf | |
NpgsqlLengthCache | lengthCache | |
NpgsqlParameter | parameter | |
Boolean | async | |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task |
Overrides
Write(Memory<Byte>, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
Writes a value to the provided buffer.
Declaration
public Task Write(Memory<byte> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
Memory<Byte> | value | |
NpgsqlWriteBuffer | buf | The buffer to which to write. |
NpgsqlLengthCache | lengthCache | A cache where the length calculated during the validation phase can be stored for use at the writing phase. |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |
Boolean | async | If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task |
Write(ReadOnlyMemory<Byte>, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean, CancellationToken)
Writes a value to the provided buffer.
Declaration
public async Task Write(ReadOnlyMemory<byte> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async, CancellationToken cancellationToken = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
ReadOnlyMemory<Byte> | value | |
NpgsqlWriteBuffer | buf | The buffer to which to write. |
NpgsqlLengthCache | lengthCache | A cache where the length calculated during the validation phase can be stored for use at the writing phase. |
NpgsqlParameter | parameter | The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size). |
Boolean | async | If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously. |
CancellationToken | cancellationToken | An optional token to cancel the asynchronous operation. The default value is None. |
Returns
Type | Description |
---|---|
Task |
Explicit Interface Implementations
INpgsqlTypeHandler<ArraySegment<Byte>>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Declaration
ValueTask<ArraySegment<byte>> INpgsqlTypeHandler<ArraySegment<byte>>.Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | |
Int32 | len | |
Boolean | async | |
FieldDescription | fieldDescription |
Returns
Type | Description |
---|---|
ValueTask<ArraySegment<Byte>> |
INpgsqlTypeHandler<Memory<Byte>>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Declaration
ValueTask<Memory<byte>> INpgsqlTypeHandler<Memory<byte>>.Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | |
Int32 | len | |
Boolean | async | |
FieldDescription | fieldDescription |
Returns
Type | Description |
---|---|
ValueTask<Memory<Byte>> |
INpgsqlTypeHandler<ReadOnlyMemory<Byte>>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
Declaration
ValueTask<ReadOnlyMemory<byte>> INpgsqlTypeHandler<ReadOnlyMemory<byte>>.Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescriptioncancellationToken)
Parameters
Type | Name | Description |
---|---|---|
NpgsqlReadBuffer | buf | |
Int32 | len | |
Boolean | async | |
FieldDescription | fieldDescriptioncancellationToken |
Returns
Type | Description |
---|---|
ValueTask<ReadOnlyMemory<Byte>> |