forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPregeneratedMessages.cs
More file actions
57 lines (48 loc) · 2.35 KB
/
PregeneratedMessages.cs
File metadata and controls
57 lines (48 loc) · 2.35 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
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace Npgsql
{
static class PregeneratedMessages
{
static PregeneratedMessages()
{
#pragma warning disable CS8625
// This is the only use of a write buffer without a connector, for in-memory construction of
// pregenerated messages.
var buf = new NpgsqlWriteBuffer(null, new MemoryStream(), NpgsqlWriteBuffer.MinimumSize, Encoding.ASCII);
#pragma warning restore CS8625
BeginTransRepeatableRead = Generate(buf, "BEGIN ISOLATION LEVEL REPEATABLE READ");
BeginTransSerializable = Generate(buf, "BEGIN TRANSACTION ISOLATION LEVEL SERIALIZABLE");
BeginTransReadCommitted = Generate(buf, "BEGIN TRANSACTION ISOLATION LEVEL READ COMMITTED");
BeginTransReadUncommitted = Generate(buf, "BEGIN TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
CommitTransaction = Generate(buf, "COMMIT");
RollbackTransaction = Generate(buf, "ROLLBACK");
KeepAlive = Generate(buf, "SELECT NULL");
DiscardAll = Generate(buf, "DISCARD ALL");
}
internal static byte[] Generate(NpgsqlWriteBuffer buf, string query)
{
Debug.Assert(query.All(c => c < 128));
var queryByteLen = Encoding.ASCII.GetByteCount(query);
buf.WriteByte(FrontendMessageCode.Query);
buf.WriteInt32(4 + // Message length (including self excluding code)
queryByteLen + // Query byte length
1); // Null terminator
buf.WriteString(query, queryByteLen, false).Wait();
buf.WriteByte(0);
var bytes = buf.GetContents();
buf.Clear();
return bytes;
}
internal static readonly byte[] BeginTransRepeatableRead;
internal static readonly byte[] BeginTransSerializable;
internal static readonly byte[] BeginTransReadCommitted;
internal static readonly byte[] BeginTransReadUncommitted;
internal static readonly byte[] CommitTransaction;
internal static readonly byte[] RollbackTransaction;
internal static readonly byte[] KeepAlive;
internal static readonly byte[] DiscardAll;
}
}