summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7323a9e)
raw | patch | inline | side by side (parent: 7323a9e)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 19 Sep 2014 23:22:22 +0000 (16:22 -0700) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 19 Sep 2014 23:22:22 +0000 (16:22 -0700) |
These are the low-level functions which only decode/encode the header.
client/client.go | patch | blob | history | |
proto/proto.go | patch | blob | history |
diff --git a/client/client.go b/client/client.go
index 131fdd5f1634e82b046a594babef1216c7f4a5ea..34a0434a1eeda23886d00ad34565b97c1226c22f 100644 (file)
--- a/client/client.go
+++ b/client/client.go
// Any blocked Send or Receive operations will be unblocked and return errors.
func (c Conn) Close() { c.c.Close() }
-// Send encodes the specified message and sends it to the server.
+// Send sends the specified raw message to the server.
//
// Send operations block until the full message could be written to the
// underlying sockets. This ensures that server and client don't get out of
// sync.
func (c Conn) Send(m *proto.Message) error {
- return proto.Encode(c.c, m)
+ return proto.Write(c.c, m)
}
-// Receive waits for a reply from the server and returns the decoded message.
+// Receive waits for a reply from the server and returns the raw message.
//
// Receive operations block until a full message could be read from the
// underlying socket. This ensures that server and client don't get out of
// sync.
func (c Conn) Receive() (*proto.Message, error) {
- return proto.Decode(c.c)
+ return proto.Read(c.c)
}
// vim: set tw=78 sw=4 sw=4 noexpandtab :
diff --git a/proto/proto.go b/proto/proto.go
index 5aadf9aee1885e45f8cc9157545683f6292d57f4..7f53f3d82c0732e2b9643f1937e15eb01e113c6e 100644 (file)
--- a/proto/proto.go
+++ b/proto/proto.go
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
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)))