Show / Hide Table of Contents

Class ByteaHandler

A type handler for the PostgreSQL bytea data type.

Inheritance
System.Object
NpgsqlTypeHandler
NpgsqlTypeHandler<System.Byte[]>
ByteaHandler
Implements
INpgsqlTypeHandler<System.Byte[]>
INpgsqlTypeHandler<System.ArraySegment<System.Byte>>
Inherited Members
NpgsqlTypeHandler<Byte[]>.Read(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
NpgsqlTypeHandler<Byte[]>.Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
NpgsqlTypeHandler<Byte[]>.Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)
NpgsqlTypeHandler<Byte[]>.ValidateAndGetLength(Byte[], NpgsqlLengthCache, NpgsqlParameter)
NpgsqlTypeHandler<Byte[]>.Write(Byte[], NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
NpgsqlTypeHandler<Byte[]>.ValidateAndGetLength<TAny>(TAny, NpgsqlLengthCache, NpgsqlParameter)
NpgsqlTypeHandler<Byte[]>.WriteWithLength<TAny>(TAny, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
NpgsqlTypeHandler<Byte[]>.ValidateObjectAndGetLength(Object, NpgsqlLengthCache, NpgsqlParameter)
NpgsqlTypeHandler<Byte[]>.WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
NpgsqlTypeHandler<Byte[]>.CreateArrayHandler(PostgresArrayType)
NpgsqlTypeHandler<Byte[]>.CreateRangeHandler(PostgresRangeType)
NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, Boolean, FieldDescription)
NpgsqlTypeHandler.Read<TAny>(NpgsqlReadBuffer, Int32, FieldDescription)
NpgsqlTypeHandler.ValidateAndGetLength<TAny>(TAny, NpgsqlLengthCache, NpgsqlParameter)
NpgsqlTypeHandler.ValidateObjectAndGetLength(Object, NpgsqlLengthCache, NpgsqlParameter)
NpgsqlTypeHandler.WriteObjectWithLength(Object, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)
NpgsqlTypeHandler.CreateArrayHandler(PostgresArrayType)
NpgsqlTypeHandler.CreateRangeHandler(PostgresRangeType)
NpgsqlTypeHandler.CreateConversionButNoParamException(Type)
System.Object.ToString()
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: Npgsql.TypeHandlers
Assembly: Npgsql.dll
Syntax
public class ByteaHandler : NpgsqlTypeHandler<byte[]>, INpgsqlTypeHandler<byte[]>, INpgsqlTypeHandler<ArraySegment<byte>>
Remarks

See http://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)

Constructs a ByteaHandler.

Declaration
public ByteaHandler(PostgresType postgresType)
Parameters
Type Name Description
PostgresType postgresType

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 ValueTask<byte[]> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription = null)
Parameters
Type Name Description
NpgsqlReadBuffer buf

The buffer from which to read.

System.Int32 len

The byte length of the value. The buffer might not contain the full length, requiring I/O to be performed.

System.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<System.Byte[]>

The fully-read value.

Overrides
Npgsql.TypeHandling.NpgsqlTypeHandler<System.Byte[]>.Read(Npgsql.NpgsqlReadBuffer, System.Int32, System.Boolean, Npgsql.BackendMessages.FieldDescription)

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
System.ArraySegment<System.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
System.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
System.Byte[] value
NpgsqlLengthCache lengthCache
NpgsqlParameter parameter
Returns
Type Description
System.Int32
Overrides
Npgsql.TypeHandling.NpgsqlTypeHandler<System.Byte[]>.ValidateAndGetLength(System.Byte[], Npgsql.NpgsqlLengthCache, Npgsql.NpgsqlParameter)

Write(ArraySegment<Byte>, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

Writes a value to the provided buffer.

Declaration
public Task Write(ArraySegment<byte> value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)
Parameters
Type Name Description
System.ArraySegment<System.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).

System.Boolean async

If I/O will be necessary (i.e. the buffer is full), determines whether it will be done synchronously or asynchronously.

Returns
Type Description
System.Threading.Tasks.Task

Write(Byte[], NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, Boolean)

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)
Parameters
Type Name Description
System.Byte[] value
NpgsqlWriteBuffer buf
NpgsqlLengthCache lengthCache
NpgsqlParameter parameter
System.Boolean async
Returns
Type Description
System.Threading.Tasks.Task
Overrides
Npgsql.TypeHandling.NpgsqlTypeHandler<System.Byte[]>.Write(System.Byte[], Npgsql.NpgsqlWriteBuffer, Npgsql.NpgsqlLengthCache, Npgsql.NpgsqlParameter, System.Boolean)

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
System.Int32 len
System.Boolean async
FieldDescription fieldDescription
Returns
Type Description
ValueTask<System.ArraySegment<System.Byte>>

Implements

INpgsqlTypeHandler<T>
INpgsqlTypeHandler<T>
In This Article
Back to top Generated by DocFX