mps

morphux package server
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/mps

commit 9896e01598d9c408604bc75db912c09cc9d651ae
parent 3eb558025629aa5ad0a53a2a815b2f5023cfa40f
Author: Pierre Avisse <gosti@ns332675.ip-176-31-110.eu>
Date:   Sun, 26 Mar 2017 23:24:31 +0200

fix header

Diffstat:
Mmessage/header.go | 21+++++++++++++++------
Mnetwork.go | 9++++-----
Mtest_database/mock3.db | 0
3 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/message/header.go b/message/header.go @@ -35,13 +35,22 @@ func (h *Header) Build(Type, number uint8, data []byte) { } -//BuildWithHeader Is theorically faster than generating header and Packing it -// func BuildWithHeader(Type, number uint8, data []byte) []byte { +func (p *Header) Pack() ([]byte, error) { + barrel := barrel.NewBarrel() + load := barrel.Load(p, []byte{}, true) + + err := barrel.Pack(load) + + return barrel.Bytes(), err +} + +//BuildHeader Is theorically faster than generating header and Packing it +func BuildHeader(Type, number uint8, data []byte) []byte { -// hash := "" + hash := "" -// header := []byte{Type, , len(hash), hash} + header := []byte{Type, byte(len(data) & 0xff), byte(len(data) >> 8), byte(len(hash))} -// return append() + return header -// } +} diff --git a/network.go b/network.go @@ -62,13 +62,12 @@ func ParseRequest(data []byte, conn net.Conn, db *sql.DB) error { header_data, err := resp_header.Pack() - tosend := append(header_data, resp_data...) + fmt.Println("header", header_data, resp_header, message.BuildHeader(0x20, 1, resp_data)) - fmt.Printf("PKG DATA TO BE SENT : %#v\n", tosend) + tosend := append(message.BuildHeader(0x20, 1, resp_data), 0x1) + tosend = append(tosend, resp_data...) - i, err := conn.Write(tosend) - - fmt.Println(i) + _, err = conn.Write(tosend) if err != nil { return err diff --git a/test_database/mock3.db b/test_database/mock3.db Binary files differ.