Browse Source

varintLengthField.reserveLen() should return 0 during decode

Vlad Hanciuta 8 years ago
parent
commit
033fed9b92
1 changed files with 6 additions and 0 deletions
  1. 6 0
      length_field.go

+ 6 - 0
length_field.go

@@ -31,10 +31,12 @@ func (l *lengthField) check(curOffset int, buf []byte) error {
 type varintLengthField struct {
 	startOffset int
 	length      int64
+	consumed    bool
 }
 
 func (l *varintLengthField) decode(pd packetDecoder) error {
 	var err error
+	l.consumed = true
 	l.length, err = pd.getVarint()
 	return err
 }
@@ -51,6 +53,10 @@ func (l *varintLengthField) adjustLength(currOffset int) int {
 }
 
 func (l *varintLengthField) reserveLength() int {
+	if l.consumed { // the field was consumed during the decode
+		l.consumed = false
+		return 0
+	}
 	var tmp [binary.MaxVarintLen64]byte
 	return binary.PutVarint(tmp[:], l.length)
 }