Permalink
Browse files

use a type as argument for header()

  • Loading branch information...
1 parent b442ef9 commit 50096abb5afff0edb41dda04ea8af1fb3fcfb4e0 John Mac committed with Jun 18, 2010
Showing with 15 additions and 6 deletions.
  1. +1 −1 mongo/connection.go
  2. +14 −5 mongo/message.go
View
2 mongo/connection.go
@@ -56,7 +56,7 @@ func (self *Connection) Disconnect() os.Error {
func (c *Connection) writeMessage(m message) os.Error {
body := m.Bytes()
- hb := header(int32(len(body)+16), m.RequestID(), 0, m.OpCode())
+ hb := header(msgHeader{int32(len(body)+16), m.RequestID(), 0, m.OpCode()})
msg := bytes.Add(hb, body)
_, err := c.conn.Write(msg)
View
19 mongo/message.go
@@ -38,12 +38,21 @@ var last_req int32
// *** Standard Message Header
// ***
-func header(length, reqID, respTo, opCode int32) []byte {
+type msgHeader struct {
+ messageLength int32 // total message size, including this
+ requestID int32 // identifier for this message
+ responseTo int32 // requestID from the original request (used in reponses from db)
+ opCode int32 // request type - see Request Opcodes
+}
+
+func header(h msgHeader) []byte {
b := make([]byte, 16)
- binary.LittleEndian.PutUint32(b[0:4], uint32(length))
- binary.LittleEndian.PutUint32(b[4:8], uint32(reqID))
- binary.LittleEndian.PutUint32(b[8:12], uint32(respTo))
- binary.LittleEndian.PutUint32(b[12:16], uint32(opCode))
+
+ binary.LittleEndian.PutUint32(b[0:4], uint32(h.messageLength))
+ binary.LittleEndian.PutUint32(b[4:8], uint32(h.requestID))
+ binary.LittleEndian.PutUint32(b[8:12], uint32(h.responseTo))
+ binary.LittleEndian.PutUint32(b[12:16], uint32(h.opCode))
+
return b
}

0 comments on commit 50096ab

Please sign in to comment.