Exemplo n.º 1
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())
}
Exemplo n.º 2
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())
}