Example #1
0
func InitCommandComplete(m *Message, cmdTag string) {
	msgBytes := make([]byte, 0, len([]byte(cmdTag)))
	buf := bytes.NewBuffer(msgBytes)
	WriteCString(buf, cmdTag)

	m.InitFromBytes(MsgCommandCompleteC, buf.Bytes())
}
Example #2
0
func InitCancelRequest(m *Message, backendPid, secretKey uint32) {
	buf := bytes.NewBuffer(make([]byte, 0, 12))
	// Special CancelRequest message "type"
	WriteUint32(buf, 80877102)
	WriteUint32(buf, backendPid)
	WriteUint32(buf, secretKey)
	m.InitFromBytes(MsgTypeFirst, buf.Bytes())
}
Example #3
0
func InitDataRow(m *Message, encodedData [][]byte) {
	dataSize := 0
	for _, colVal := range encodedData {
		dataSize += len(colVal)
	}
	msgBytes := make([]byte, 0, 2+dataSize)
	buf := bytes.NewBuffer(msgBytes)
	colCount := int16(len(encodedData))
	WriteInt16(buf, colCount)
	for _, colVal := range encodedData {
		buf.Write(colVal)
	}

	m.InitFromBytes(MsgDataRowD, buf.Bytes())
}
Example #4
0
func InitStartupMessage(m *Message, params map[string]string) {
	buf := bytes.NewBuffer(make([]byte, 0, 1024))
	// Protocol V3 header
	// TODO: make this configurable. maybe.
	buf.Write([]byte{0x00, 0x03, 0x00, 0x00})

	for name, value := range params {
		WriteCString(buf, name)
		WriteCString(buf, value)
	}

	buf.Write([]byte{'\000'})

	m.InitFromBytes(MsgTypeFirst, buf.Bytes())
}
Example #5
0
func InitRowDescription(m *Message, fields []FieldDescription) {
	// use a heuristic estimate for length to avoid having to
	// resize the msgBytes array
	fieldLenEst := (10 + 4 + 2 + 4 + 2 + 4 + 2)
	msgBytes := make([]byte, 0, len(fields)*fieldLenEst)
	buf := bytes.NewBuffer(msgBytes)
	WriteInt16(buf, int16(len(fields)))
	for _, field := range fields {
		WriteCString(buf, field.Name)
		WriteUint32(buf, uint32(field.TableOid))
		WriteInt16(buf, field.TableAttNo)
		WriteUint32(buf, uint32(field.TypeOid))
		WriteInt16(buf, field.TypLen)
		WriteInt32(buf, field.Atttypmod)
		WriteInt16(buf, int16(field.Format))
	}

	m.InitFromBytes(MsgRowDescriptionT, buf.Bytes())
}
Example #6
0
func InitQuery(m *Message, query string) {
	msgBytes := make([]byte, 0, len([]byte(query))+1)
	buf := bytes.NewBuffer(msgBytes)
	WriteCString(buf, query)
	m.InitFromBytes(MsgQueryQ, buf.Bytes())
}