Skip to content

Commit 3750d00

Browse files
Apply review comments
1 parent 5c3e614 commit 3750d00

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

marshal.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,7 +1792,7 @@ func unmarshalVector(info VectorType, data []byte, value interface{}) error {
17921792
for i := 0; i < info.Dimensions; i++ {
17931793
offset := 0
17941794
if isVectorVariableLengthType(info.SubType) {
1795-
m, p, err := readUnsignedVInt(data, 0)
1795+
m, p, err := readUnsignedVInt(data)
17961796
if err != nil {
17971797
return err
17981798
}
@@ -1858,24 +1858,24 @@ func writeUnsignedVInt(buf *bytes.Buffer, v uint64) {
18581858
buf.Write(tmp)
18591859
}
18601860

1861-
func readUnsignedVInt(data []byte, start int) (uint64, int, error) {
1862-
if len(data) <= start {
1861+
func readUnsignedVInt(data []byte) (uint64, int, error) {
1862+
if len(data) <= 0 {
18631863
return 0, 0, errors.New("unexpected eof")
18641864
}
1865-
firstByte := data[start]
1865+
firstByte := data[0]
18661866
if firstByte&0x80 == 0 {
1867-
return uint64(firstByte), start + 1, nil
1867+
return uint64(firstByte), 1, nil
18681868
}
18691869
numBytes := bits.LeadingZeros32(uint32(^firstByte)) - 24
18701870
ret := uint64(firstByte & (0xff >> uint(numBytes)))
1871-
if len(data) < start+numBytes+1 {
1872-
return 0, 0, fmt.Errorf("data expect to have %d bytes, but it has only %d", start+numBytes+1, len(data))
1871+
if len(data) < numBytes+1 {
1872+
return 0, 0, fmt.Errorf("data expect to have %d bytes, but it has only %d", numBytes+1, len(data))
18731873
}
1874-
for i := start; i < start+numBytes; i++ {
1874+
for i := 0; i < numBytes; i++ {
18751875
ret <<= 8
18761876
ret |= uint64(data[i+1] & 0xff)
18771877
}
1878-
return ret, start + numBytes + 1, nil
1878+
return ret, numBytes + 1, nil
18791879
}
18801880

18811881
func computeUnsignedVIntSize(v uint64) int {

marshal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ func TestReadUnsignedVInt(t *testing.T) {
25302530
}
25312531
for _, test := range tests {
25322532
t.Run(fmt.Sprintf("%d", test.decodedInt), func(t *testing.T) {
2533-
actual, _, err := readUnsignedVInt(test.encodedVint, 0)
2533+
actual, _, err := readUnsignedVInt(test.encodedVint)
25342534
if err != nil {
25352535
t.Fatalf("Expected no error, got %v", err)
25362536
}

0 commit comments

Comments
 (0)