Table of Contents

Interface INpgsqlTypeHandler<T>

Namespace
Npgsql.TypeHandling
Assembly
Npgsql.dll

Type handlers that wish to support reading other types in additional to the main one can implement this interface for all those types.

public interface INpgsqlTypeHandler<T>

Type Parameters

T

Methods

Read(NpgsqlReadBuffer, int, bool, FieldDescription)

Reads a value of type T with the given length from the provided buffer, using either sync or async I/O.

ValueTask<T> Read(NpgsqlReadBuffer buf, int len, bool async, FieldDescription fieldDescription)

Parameters

buf NpgsqlReadBuffer

The buffer from which to read.

len int

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

async bool

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

ValueTask<T>

The fully-read value.

ValidateAndGetLength(T, 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 shold be thrown. Also returns the byte length needed to write the value.

int ValidateAndGetLength(T value, ref NpgsqlLengthCache lengthCache, NpgsqlParameter parameter)

Parameters

value T

The value to be written to PostgreSQL

lengthCache NpgsqlLengthCache

A cache where the length calculated during the validation phase can be stored for use at the writing phase.

parameter NpgsqlParameter

The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

Returns

int

The number of bytes required to write the value.

Write(T, NpgsqlWriteBuffer, NpgsqlLengthCache, NpgsqlParameter, bool)

Writes a value to the provided buffer.

Task Write(T value, NpgsqlWriteBuffer buf, NpgsqlLengthCache lengthCache, NpgsqlParameter parameter, bool async)

Parameters

value T

The value to write.

buf NpgsqlWriteBuffer

The buffer to which to write.

lengthCache NpgsqlLengthCache

A cache where the length calculated during the validation phase can be stored for use at the writing phase.

parameter NpgsqlParameter

The NpgsqlParameter instance where this value resides. Can be used to access additional information relevant to the write process (e.g. Size).

async bool

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

Returns

Task