forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloseMessage.cs
More file actions
executable file
·45 lines (38 loc) · 1.33 KB
/
CloseMessage.cs
File metadata and controls
executable file
·45 lines (38 loc) · 1.33 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
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Text;
namespace Npgsql.FrontendMessages
{
class CloseMessage : SimpleFrontendMessage
{
/// <summary>
/// The name of the prepared statement or portal to close (an empty string selects the unnamed prepared statement or portal).
/// </summary>
internal string Name { get; set; }
/// <summary>
/// Whether to close a statement or a portal
/// </summary>
internal StatementOrPortal StatementOrPortal { get; set; }
const byte Code = (byte)'C';
internal CloseMessage(StatementOrPortal type, string name="")
{
StatementOrPortal = type;
Name = name;
}
internal override int Length { get { return 1 + 4 + 1 + Name.Length; } }
internal override void Write(NpgsqlBuffer buf)
{
Contract.Requires(Name != null && Name.All(c => c < 128));
buf.WriteByte(Code);
buf.WriteInt32(Length);
buf.WriteByte((byte)StatementOrPortal);
buf.WriteBytesNullTerminated(Encoding.ASCII.GetBytes(Name));
}
public override string ToString()
{
return String.Format("[Close {0}={1}]", StatementOrPortal, Name);
}
}
}