From 414ad0469c90b2c5487394646571e4e737d747be Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Fri, 19 Sep 2014 16:22:22 -0700 Subject: [PATCH] Renamed proto.Decode/proto.Encode to proto.Read/proto.Write. These are the low-level functions which only decode/encode the header. --- client/client.go | 8 ++++---- proto/proto.go | 13 +++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/client/client.go b/client/client.go index 131fdd5..34a0434 100644 --- a/client/client.go +++ b/client/client.go @@ -120,22 +120,22 @@ func Connect(addr, user string) (*Conn, error) { // 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 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))) -- 2.30.2