Skip to content

Commit

Permalink
vendor: update kvproto (pingcap#2812)
Browse files Browse the repository at this point in the history
Use shared bytes for coprocessor.Response.
  • Loading branch information
coocood authored and shenli committed Mar 11, 2017
1 parent 779a38b commit 8b0efb7
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 65 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 21 additions & 12 deletions _vendor/src/github.com/pingcap/kvproto/pkg/util/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,10 @@ func WriteMessage(w io.Writer, msgID uint64, msg proto.Message) error {

// ReadMessage reads a protocol buffer message from reader.
func ReadMessage(r io.Reader, msg proto.Message) (uint64, error) {
var header [msgHeaderSize]byte
_, err := io.ReadFull(r, header[:])
msgID, msgLen, err := ReadHeader(r)
if err != nil {
return 0, errors.Trace(err)
}

if magic := binary.BigEndian.Uint16(header[0:2]); magic != msgMagic {
return 0, errors.Errorf("mismatch header magic %x != %x", magic, msgMagic)
}

// skip version now.

msgLen := binary.BigEndian.Uint32(header[4:8])
msgID := binary.BigEndian.Uint64(header[8:])

body := make([]byte, msgLen)
_, err = io.ReadFull(r, body)
if err != nil {
Expand All @@ -70,3 +59,23 @@ func ReadMessage(r io.Reader, msg proto.Message) (uint64, error) {

return msgID, nil
}

// ReadHeader reads a protocol header from reader.
func ReadHeader(r io.Reader) (msgID uint64, msgLen uint32, err error) {
var header [msgHeaderSize]byte
_, err = io.ReadFull(r, header[:])
if err != nil {
return 0, 0, errors.Trace(err)
}

if magic := binary.BigEndian.Uint16(header[0:2]); magic != msgMagic {
return 0, 0, errors.Errorf("mismatch header magic %x != %x", magic, msgMagic)
}

// Skip version now.
// TODO: check version.

msgLen = binary.BigEndian.Uint32(header[4:8])
msgID = binary.BigEndian.Uint64(header[8:])
return
}
6 changes: 3 additions & 3 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ import:
- go-tipb
- sharedbytes
- package: github.com/pingcap/kvproto
version: 854b7eeb43e436a692463a18f03dabfe917ebe2b
version: 55b670bb63ef8f6c317003273acfce1127df5721
- package: github.com/gogo/protobuf
version: ^0.3.0
subpackages:
Expand Down

0 comments on commit 8b0efb7

Please sign in to comment.