forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInternalCharHandler.cs
More file actions
81 lines (65 loc) · 3.28 KB
/
InternalCharHandler.cs
File metadata and controls
81 lines (65 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using Npgsql.BackendMessages;
using Npgsql.PostgresTypes;
using Npgsql.TypeHandling;
using Npgsql.TypeMapping;
using NpgsqlTypes;
namespace Npgsql.TypeHandlers
{
/// <summary>
/// A type handler for the PostgreSQL "char" type, used only internally.
/// </summary>
/// <remarks>
/// See http://www.postgresql.org/docs/current/static/datatype-character.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.
/// </remarks>
[TypeMapping("char", NpgsqlDbType.InternalChar)]
public class InternalCharHandler : NpgsqlSimpleTypeHandler<char>,
INpgsqlSimpleTypeHandler<byte>, INpgsqlSimpleTypeHandler<short>, INpgsqlSimpleTypeHandler<int>, INpgsqlSimpleTypeHandler<long>
{
/// <inheritdoc />
public InternalCharHandler(PostgresType postgresType) : base(postgresType) {}
#region Read
/// <inheritdoc />
public override char Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription = null)
=> (char)buf.ReadByte();
byte INpgsqlSimpleTypeHandler<byte>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
=> buf.ReadByte();
short INpgsqlSimpleTypeHandler<short>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
=> buf.ReadByte();
int INpgsqlSimpleTypeHandler<int>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
=> buf.ReadByte();
long INpgsqlSimpleTypeHandler<long>.Read(NpgsqlReadBuffer buf, int len, FieldDescription? fieldDescription)
=> buf.ReadByte();
#endregion
#region Write
/// <inheritdoc />
public override int ValidateAndGetLength(char value, NpgsqlParameter? parameter) => 1;
/// <inheritdoc />
public int ValidateAndGetLength(byte value, NpgsqlParameter? parameter) => 1;
/// <inheritdoc />
public int ValidateAndGetLength(short value, NpgsqlParameter? parameter) => 1;
/// <inheritdoc />
public int ValidateAndGetLength(int value, NpgsqlParameter? parameter) => 1;
/// <inheritdoc />
public int ValidateAndGetLength(long value, NpgsqlParameter? parameter) => 1;
/// <inheritdoc />
public override void Write(char value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
=> buf.WriteByte(checked((byte)value));
/// <inheritdoc />
public void Write(byte value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
=> buf.WriteByte(value);
/// <inheritdoc />
public void Write(short value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
=> buf.WriteByte(checked((byte)value));
/// <inheritdoc />
public void Write(int value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
=> buf.WriteByte(checked((byte)value));
/// <inheritdoc />
public void Write(long value, NpgsqlWriteBuffer buf, NpgsqlParameter? parameter)
=> buf.WriteByte(checked((byte)value));
#endregion
}
}