Fix EOF bug with uint16 and uint64 readers in deserialize
@@ -139,22 +139,22 @@ func (c *Deserializer2) ReadEP(r io.Reader) (uint64, uint16, error) {
func (c *Deserializer2) ReadLink(r io.Reader, res *DeserializationResult) error {
source, err := c.readUint64(r)
if err != nil {
- return errors.Errorf("failed to read source node id: %v", err)
+ return err
}
level, err := c.readUint16(r)
if err != nil {
- return errors.Errorf("failed to read source node level: %v", err)
+ return err
}
target, err := c.readUint64(r)
if err != nil {
- return errors.Errorf("failed to read target node id: %v", err)
+ return err
}
newNodes, changed, err := growIndexToAccomodateNode(res.Nodes, source, c.logger)
if err != nil {
- return errors.Errorf("failed to grow index: %v", err)
+ return err
}
if changed {
@@ -266,8 +266,8 @@ func (c *Deserializer2) ReadDeleteNode(r io.Reader, res *DeserializationResult)
func (c *Deserializer2) readUint64(r io.Reader) (uint64, error) {
var value uint64
tmpBuf := make([]byte, 8)
- if _, err := r.Read(tmpBuf); err != nil {
- return value, errors.Errorf("failed to read uint64: %s", err)
+ if _, err := io.ReadFull(r, tmpBuf); err != nil {
+ return 0, err
}
value = binary.LittleEndian.Uint64(tmpBuf)
@@ -278,10 +278,9 @@ func (c *Deserializer2) readUint64(r io.Reader) (uint64, error) {
func (c *Deserializer2) readUint16(r io.Reader) (uint16, error) {
var value uint16
tmpBuf := make([]byte, 2)
- if _, err := r.Read(tmpBuf); err != nil {
- return value, errors.Errorf("failed to read uint16: %s", err)
+ if _, err := io.ReadFull(r, tmpBuf); err != nil {
+ return 0, err
}
-
value = binary.LittleEndian.Uint16(tmpBuf)
return value, nil
@@ -290,7 +289,7 @@ func (c *Deserializer2) readUint16(r io.Reader) (uint16, error) {
func (c *Deserializer2) ReadCommitType(r io.Reader) (HnswCommitType, error) {
tmpBuf := make([]byte, 1)
if _, err := r.Read(tmpBuf); err != nil {
- return 0, errors.Errorf("failed to read commit type: %s", err)
+ return 0, err
}
return HnswCommitType(tmpBuf[0]), nil
@@ -301,9 +300,9 @@ func (c *Deserializer2) readUint64Slice(r io.Reader, length int) ([]uint64, erro
for i := 0; i < length; i++ {
v, err := c.readUint64(r)
if err != nil {
- return values, errors.Errorf("failed to read uint64: %s", err)
+ return values, err
}
- values = append(values, v)
+ values[i] = v
}
