Browse Source

Build a slice right away, instead of creating them for every call that takes a slice not an array

Evan Huus 12 years ago
parent
commit
9b0aef62c7
1 changed files with 6 additions and 6 deletions
  1. 6 6
      client.go

+ 6 - 6
client.go

@@ -20,9 +20,9 @@ func NewClient(addr string) (client *Client, err error) {
 }
 
 func (client *Client) write(buf []byte) (err error) {
-	var size [4]byte
-	binary.BigEndian.PutUint32(size[:], uint32(len(buf)))
-	_, err = client.conn.Write(size[:])
+	size := make([]byte, 4)
+	binary.BigEndian.PutUint32(size, uint32(len(buf)))
+	_, err = client.conn.Write(size)
 	if err != nil {
 		return err
 	}
@@ -34,15 +34,15 @@ func (client *Client) write(buf []byte) (err error) {
 }
 
 func (client *Client) read() (buf []byte, err error) {
-	var size [4]byte
-	n, err := client.conn.Read(size[:])
+	size := make([]byte, 4)
+	n, err := client.conn.Read(size)
 	if err != nil {
 		return nil, err
 	}
 	if n != 4 {
 		return nil, nil
 	}
-	s := binary.BigEndian.Uint32(size[:])
+	s := binary.BigEndian.Uint32(size)
 	buf = make([]byte, s)
 	n, err = client.conn.Read(buf)
 	if err != nil {