コード例 #1
0
ファイル: packstream_test.go プロジェクト: FylmTM/boltlib
func TestHandshakeMessage(t *testing.T) {
	readBuffer := &bytes.Buffer{}
	writeBuffer := &bytes.Buffer{}

	ps := packstream.NewPackstream(readBuffer, writeBuffer)
	ps.WriteHandshakeMessage()

	handshakeMessage, err := ioutil.ReadAll(writeBuffer)
	assert.Nil(t, err)

	expected := []byte{
		0x00, 0x00, 0x00, 0x01,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00,
	}
	assert.Equal(t, expected, handshakeMessage)
}
コード例 #2
0
ファイル: main.go プロジェクト: FylmTM/boltlib
func main() {
	con, err := Connect("127.0.0.1", "7687")
	if err != nil {
		log.Fatal(err)
	}

	defer con.Close()

	readBuffer := &bytes.Buffer{}
	writeBuffer := &bytes.Buffer{}

	ps := packstream.NewPackstream(readBuffer, writeBuffer)

	ps.WriteHandshakeMessage()
	buf := make([]byte, 256)

	handshakeMessage, err := ioutil.ReadAll(writeBuffer)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Writing handshake", handshakeMessage)
	n, err := con.Write(handshakeMessage)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Written bytes", n)

	n, err = con.Read(buf)
	if err != nil {
		log.Fatal(err)
	}
	readBuffer.Write(buf[:n])
	fmt.Println("Read bytes", buf[:n])

	version, err := ps.ReadVersion()
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Got version", version)
}