Source File
row_description.go
Belonging Package
github.com/jackc/pgproto3/v2
package pgproto3
import (
)
const (
TextFormat = 0
BinaryFormat = 1
)
type FieldDescription struct {
Name []byte
TableOID uint32
TableAttributeNumber uint16
DataTypeOID uint32
DataTypeSize int16
TypeModifier int32
Format int16
}
func ( FieldDescription) () ([]byte, error) {
return json.Marshal(struct {
string
uint32
uint16
uint32
int16
int32
int16
}{
: string(.Name),
: .TableOID,
: .TableAttributeNumber,
: .DataTypeOID,
: .DataTypeSize,
: .TypeModifier,
: .Format,
})
}
type RowDescription struct {
Fields []FieldDescription
}
func (*RowDescription) () {}
func ( *RowDescription) ( []byte) error {
if len() < 2 {
return &invalidMessageFormatErr{messageType: "RowDescription"}
}
:= int(binary.BigEndian.Uint16())
:= 2
.Fields = .Fields[0:0]
for := 0; < ; ++ {
var FieldDescription
:= bytes.IndexByte([:], 0)
if < 0 {
return &invalidMessageFormatErr{messageType: "RowDescription"}
}
.Name = [ : +]
+= + 1
if len([:]) < 18 {
return &invalidMessageFormatErr{messageType: "RowDescription"}
}
.TableOID = binary.BigEndian.Uint32([:])
+= 4
.TableAttributeNumber = binary.BigEndian.Uint16([:])
+= 2
.DataTypeOID = binary.BigEndian.Uint32([:])
+= 4
.DataTypeSize = int16(binary.BigEndian.Uint16([:]))
+= 2
.TypeModifier = int32(binary.BigEndian.Uint32([:]))
+= 4
.Format = int16(binary.BigEndian.Uint16([:]))
+= 2
.Fields = append(.Fields, )
}
return nil
}
func ( *RowDescription) ( []byte) []byte {
= append(, 'T')
:= len()
= pgio.AppendInt32(, -1)
= pgio.AppendUint16(, uint16(len(.Fields)))
for , := range .Fields {
= append(, .Name...)
= append(, 0)
= pgio.AppendUint32(, .TableOID)
= pgio.AppendUint16(, .TableAttributeNumber)
= pgio.AppendUint32(, .DataTypeOID)
= pgio.AppendInt16(, .DataTypeSize)
= pgio.AppendInt32(, .TypeModifier)
= pgio.AppendInt16(, .Format)
}
pgio.SetInt32([:], int32(len([:])))
return
}
func ( RowDescription) () ([]byte, error) {
return json.Marshal(struct {
string
[]FieldDescription
}{
: "RowDescription",
: .Fields,
})
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |