Skip to content

Commit

Permalink
Rename Read/WriteByte to avoid govet warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
prashantv committed Aug 3, 2015
1 parent 34451a9 commit 2fa4570
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions fragmentation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func (ch fragmentChannel) newFragment(initial bool, checksum Checksum) (*writabl
wbuf := typed.NewWriteBuffer(make([]byte, testFragmentSize))
fragment := new(writableFragment)
fragment.flagsRef = wbuf.DeferByte()
wbuf.WriteByte(byte(checksum.TypeCode()))
wbuf.WriteSingleByte(byte(checksum.TypeCode()))
fragment.checksumRef = wbuf.DeferBytes(checksum.Size())
fragment.checksum = checksum
fragment.contents = wbuf
Expand All @@ -393,8 +393,8 @@ func (ch fragmentChannel) recvNextFragment(initial bool) (*readableFragment, err
rbuf := typed.NewReadBuffer(<-ch)
fragment := new(readableFragment)
fragment.done = func() {}
fragment.flags = rbuf.ReadByte()
fragment.checksumType = ChecksumType(rbuf.ReadByte())
fragment.flags = rbuf.ReadSingleByte()
fragment.checksumType = ChecksumType(rbuf.ReadSingleByte())
fragment.checksum = rbuf.ReadBytes(fragment.checksumType.ChecksumSize())
fragment.contents = rbuf
return fragment, rbuf.Err()
Expand Down
8 changes: 4 additions & 4 deletions frame.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ func (fh FrameHeader) String() string { return fmt.Sprintf("%v[%d]", fh.messageT

func (fh *FrameHeader) read(r *typed.ReadBuffer) error {
fh.size = r.ReadUint16()
fh.messageType = messageType(r.ReadByte())
fh.reserved1 = r.ReadByte()
fh.messageType = messageType(r.ReadSingleByte())
fh.reserved1 = r.ReadSingleByte()
fh.ID = r.ReadUint32()
r.ReadBytes(len(fh.reserved))
return r.Err()
}

func (fh *FrameHeader) write(w *typed.WriteBuffer) error {
w.WriteUint16(fh.size)
w.WriteByte(byte(fh.messageType))
w.WriteByte(fh.reserved1)
w.WriteSingleByte(byte(fh.messageType))
w.WriteSingleByte(fh.reserved1)
w.WriteUint32(fh.ID)
w.WriteBytes(fh.reserved[:])
return w.Err()
Expand Down
12 changes: 6 additions & 6 deletions messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ const (
type transportHeaders map[TransportHeaderName]string

func (ch transportHeaders) read(r *typed.ReadBuffer) {
nh := r.ReadByte()
nh := r.ReadSingleByte()
for i := 0; i < int(nh); i++ {
k := r.ReadLen8String()
v := r.ReadLen8String()
Expand All @@ -171,7 +171,7 @@ func (ch transportHeaders) read(r *typed.ReadBuffer) {
}

func (ch transportHeaders) write(w *typed.WriteBuffer) {
w.WriteByte(byte(len(ch)))
w.WriteSingleByte(byte(len(ch)))

for k, v := range ch {
w.WriteLen8String(k.String())
Expand Down Expand Up @@ -236,15 +236,15 @@ func (m *callRes) ID() uint32 { return m.id }
func (m *callRes) messageType() messageType { return messageTypeCallRes }

func (m *callRes) read(r *typed.ReadBuffer) error {
m.ResponseCode = ResponseCode(r.ReadByte())
m.ResponseCode = ResponseCode(r.ReadSingleByte())
m.Tracing.read(r)
m.Headers = transportHeaders{}
m.Headers.read(r)
return r.Err()
}

func (m *callRes) write(w *typed.WriteBuffer) error {
w.WriteByte(byte(m.ResponseCode))
w.WriteSingleByte(byte(m.ResponseCode))
m.Tracing.write(w)
m.Headers.write(w)
return w.Err()
Expand All @@ -270,14 +270,14 @@ type errorMessage struct {
func (m *errorMessage) ID() uint32 { return m.id }
func (m *errorMessage) messageType() messageType { return messageTypeError }
func (m *errorMessage) read(r *typed.ReadBuffer) error {
m.errCode = SystemErrCode(r.ReadByte())
m.errCode = SystemErrCode(r.ReadSingleByte())
m.id = r.ReadUint32()
m.message = r.ReadLen16String()
return r.Err()
}

func (m *errorMessage) write(w *typed.WriteBuffer) error {
w.WriteByte(byte(m.errCode))
w.WriteSingleByte(byte(m.errCode))
w.WriteUint32(m.id)
w.WriteLen16String(m.message)
return w.Err()
Expand Down
6 changes: 3 additions & 3 deletions reqres.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func (w *reqResWriter) newFragment(initial bool, checksum Checksum) (*writableFr
if err := message.write(wbuf); err != nil {
return nil, err
}
wbuf.WriteByte(byte(checksum.TypeCode()))
wbuf.WriteSingleByte(byte(checksum.TypeCode()))
fragment.checksumRef = wbuf.DeferBytes(checksum.Size())
fragment.checksum = checksum
fragment.contents = wbuf
Expand Down Expand Up @@ -252,12 +252,12 @@ func (r *reqResReader) failed(err error) error {
func parseInboundFragment(framePool FramePool, frame *Frame, message message) (*readableFragment, error) {
rbuf := typed.NewReadBuffer(frame.SizedPayload())
fragment := new(readableFragment)
fragment.flags = rbuf.ReadByte()
fragment.flags = rbuf.ReadSingleByte()
if err := message.read(rbuf); err != nil {
return nil, err
}

fragment.checksumType = ChecksumType(rbuf.ReadByte())
fragment.checksumType = ChecksumType(rbuf.ReadSingleByte())
fragment.checksum = rbuf.ReadBytes(fragment.checksumType.ChecksumSize())
fragment.contents = rbuf
fragment.done = func() {
Expand Down
4 changes: 2 additions & 2 deletions tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ func (s *Span) read(r *typed.ReadBuffer) error {
s.traceID = r.ReadUint64()
s.parentID = r.ReadUint64()
s.spanID = r.ReadUint64()
s.flags = r.ReadByte()
s.flags = r.ReadSingleByte()
return r.Err()
}

func (s *Span) write(w *typed.WriteBuffer) error {
w.WriteUint64(s.traceID)
w.WriteUint64(s.parentID)
w.WriteUint64(s.spanID)
w.WriteByte(s.flags)
w.WriteSingleByte(s.flags)
return w.Err()
}

Expand Down
12 changes: 6 additions & 6 deletions typed/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func NewReadBufferWithSize(size int) *ReadBuffer {
return &ReadBuffer{buffer: make([]byte, size), remaining: nil}
}

// ReadByte reads the next byte from the buffer
func (r *ReadBuffer) ReadByte() byte {
// ReadSingleByte reads the next byte from the buffer
func (r *ReadBuffer) ReadSingleByte() byte {
if r.err != nil {
return 0
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func (r *ReadBuffer) ReadUint64() uint64 {

// ReadLen8String reads an 8-bit length preceded string value
func (r *ReadBuffer) ReadLen8String() string {
n := r.ReadByte()
n := r.ReadSingleByte()
return r.ReadString(int(n))
}

Expand Down Expand Up @@ -177,8 +177,8 @@ func NewWriteBufferWithSize(size int) *WriteBuffer {
return NewWriteBuffer(make([]byte, size))
}

// WriteByte writes a single byte to the buffer
func (w *WriteBuffer) WriteByte(n byte) {
// WriteSingleByte writes a single byte to the buffer
func (w *WriteBuffer) WriteSingleByte(n byte) {
if w.err != nil {
return
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (w *WriteBuffer) WriteString(s string) {

// WriteLen8String writes an 8-bit length preceded string
func (w *WriteBuffer) WriteLen8String(s string) {
w.WriteByte(byte(len(s)))
w.WriteSingleByte(byte(len(s)))
w.WriteString(s)
}

Expand Down
10 changes: 5 additions & 5 deletions typed/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ func TestSimple(t *testing.T) {

{
w.Wrap(buf)
w.WriteByte(0xFC)
w.WriteSingleByte(0xFC)
r.Wrap(buf)
assert.Equal(t, byte(0xFC), r.ReadByte())
assert.Equal(t, byte(0xFC), r.ReadSingleByte())
}

{
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestReadWrite(t *testing.T) {
w.WriteUint64(0x0123456789ABCDEF)
w.WriteUint32(0xABCDEF01)
w.WriteUint16(0x2345)
w.WriteByte(0xFF)
w.WriteSingleByte(0xFF)
w.WriteString(s)
w.WriteBytes(bslice)
w.WriteLen8String("hello")
Expand All @@ -86,7 +86,7 @@ func TestReadWrite(t *testing.T) {
assert.Equal(t, uint64(0x0123456789ABCDEF), r.ReadUint64())
assert.Equal(t, uint32(0xABCDEF01), r.ReadUint32())
assert.Equal(t, uint16(0x2345), r.ReadUint16())
assert.Equal(t, byte(0xFF), r.ReadByte())
assert.Equal(t, byte(0xFF), r.ReadSingleByte())
assert.Equal(t, s, r.ReadString(len(s)))
assert.Equal(t, bslice, r.ReadBytes(len(bslice)))
assert.Equal(t, "hello", r.ReadLen8String())
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestDeferredWrites(t *testing.T) {
s := r.ReadString(5)
assert.Equal(t, "where", s)

u8 := r.ReadByte()
u8 := r.ReadSingleByte()
assert.Equal(t, byte(0x44), u8)
assert.NoError(t, r.Err())
}

0 comments on commit 2fa4570

Please sign in to comment.