示例#1
0
文件: first.go 项目: ericfode/femebe
func (s *Startup) FillMessage(m *femebe.Message) {
	buf := bytes.NewBuffer(make([]byte, 0, 1024))

	// Startup-message type word
	buf.Write([]byte{0x00, 0x03, 0x00, 0x00})

	for name, value := range s.Params {
		femebe.WriteCString(buf, name)
		femebe.WriteCString(buf, value)
	}

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

	m.InitFromBytes(femebe.MSG_TYPE_FIRST, buf.Bytes())
}
示例#2
0
func TestBackendKeyReading(t *testing.T) {
	buf := bytes.Buffer{}
	const PID = 1234
	const KEY = 5768
	femebe.WriteInt32(&buf, PID)
	femebe.WriteInt32(&buf, KEY)

	var m femebe.Message
	m.InitFromBytes(MSG_BACKEND_KEY_DATA_K, buf.Bytes())

	kd, err := ReadBackendKeyData(&m)
	if err != nil {
		t.Fatal()
	}

	if kd.pid != PID {
		t.Fatal()
	}

	if kd.key != KEY {
		t.Fatal()
	}
}