-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparameter_description.go
66 lines (53 loc) · 1.19 KB
/
parameter_description.go
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
package pgproto
import (
"io"
)
type ParameterDescription struct {
OIDs []int
}
func (p *ParameterDescription) client() {}
func ParseParameterDescription(r io.Reader) (*ParameterDescription, error) {
b := newReadBuffer(r)
// 't' [int32 - length] [int16 - parameter count] [int32 - parameter] ...
err := b.ReadTag('S')
if err != nil {
return nil, err
}
buf, err := b.ReadLength()
if err != nil {
return nil, err
}
count, err := buf.ReadInt16()
if err != nil {
return nil, err
}
p := &ParameterDescription{
OIDs: make([]int, count),
}
for i := 0; i < count; i++ {
p.OIDs[i], err = b.ReadInt()
if err != nil {
return nil, err
}
}
return p, nil
}
func (p *ParameterDescription) Encode() []byte {
// 't' [int32 - length] [int16 - parameter count] [in32 - parameter] ...
w := newWriteBuffer()
w.WriteInt16(len(p.OIDs))
for _, oid := range p.OIDs {
w.WriteInt(oid)
}
w.Wrap('t')
return w.Bytes()
}
func (p *ParameterDescription) AsMap() map[string]interface{} {
return map[string]interface{}{
"Type": "ParameterDescription",
"Payload": map[string]interface{}{
"OIDs": p.OIDs,
},
}
}
func (p *ParameterDescription) String() string { return messageToString(p) }