Define constants for header size and format index
diff --git a/rpc_util.go b/rpc_util.go
index e8f35b8..bd40eef 100644
--- a/rpc_util.go
+++ b/rpc_util.go
@@ -138,15 +138,18 @@
// EOF is returned with nil msg and 0 pf if the entire stream is done. Other
// non-nil error is returned if something is wrong on reading.
func (p *parser) recvMsg() (pf payloadFormat, msg []byte, err error) {
+ const headerSize = 5
+ const formatIndex = 1
+
var hdr msgFixedHeader
- var buf [5]byte
+ var buf [headerSize]byte
if _, err := io.ReadFull(p.s, buf[:]); err != nil {
return 0, nil, err
}
- hdr.T = payloadFormat(buf[0])
- hdr.Length = binary.BigEndian.Uint32(buf[1:])
+ hdr.T = payloadFormat(buf[formatIndex])
+ hdr.Length = binary.BigEndian.Uint32(buf[formatIndex:])
if hdr.Length == 0 {
return hdr.T, nil, nil