X-Git-Url: https://git.tokkee.org/?p=sysdb%2Fgo.git;a=blobdiff_plain;f=proto%2Fproto.go;h=7f53f3d82c0732e2b9643f1937e15eb01e113c6e;hp=5aadf9aee1885e45f8cc9157545683f6292d57f4;hb=414ad0469c90b2c5487394646571e4e737d747be;hpb=7323a9e21572ac808614512b5e3730aab758d131 diff --git a/proto/proto.go b/proto/proto.go index 5aadf9a..7f53f3d 100644 --- a/proto/proto.go +++ b/proto/proto.go @@ -87,13 +87,14 @@ type Message struct { Raw []byte } -// Decodes reads a raw message encoded in the SysDB wire format from r. The -// raw body of the message will still be encoded in the wire format. +// Read reads a raw message encoded in the SysDB wire format from r. The +// function parses the header but the raw body of the message will still be +// encoded in the wire format. // // The reader has to be in blocking mode. Otherwise, the client and server // will be out of sync after reading a partial message and cannot recover from // that. -func Decode(r io.Reader) (*Message, error) { +func Read(r io.Reader) (*Message, error) { var header [8]byte if _, err := io.ReadFull(r, header[:]); err != nil { return nil, err @@ -109,13 +110,13 @@ func Decode(r io.Reader) (*Message, error) { return &Message{Status(typ), msg}, nil } -// Encode writes a raw message to w. The raw body of m has to be encoded in -// the SysDB wire format. +// Write writes a raw message to w. The raw body of m has to be encoded in the +// SysDB wire format. The function adds the right header to the message. // // The writer has to be in blocking mode. Otherwise, the client and server // will be out of sync after writing a partial message and cannot recover from // that. -func Encode(w io.Writer, m *Message) error { +func Write(w io.Writer, m *Message) error { var header [8]byte nbo.PutUint32(header[:4], uint32(m.Type)) nbo.PutUint32(header[4:], uint32(len(m.Raw)))