MCPcopy Create free account
hub / github.com/nutsdb/nutsdb / readCompatInt64

Function readCompatInt64

hintfile.go:353–400  ·  view source on GitHub ↗
(r *bufio.Reader, fieldsRead *int)

Source from the content-addressed store, hash-verified

351}
352
353func readCompatInt64(r *bufio.Reader, fieldsRead *int) (int64, error) {
354 var scratch [binary.MaxVarintLen64]byte
355 var i int
356
357 for {
358 b, err := r.ReadByte()
359 if err != nil {
360 if err == io.EOF {
361 if i == 0 {
362 if fieldsRead != nil && *fieldsRead == 0 {
363 return 0, io.EOF
364 }
365 return 0, ErrHintFileCorrupted
366 }
367 return 0, ErrHintFileCorrupted
368 }
369 if err == io.ErrUnexpectedEOF {
370 return 0, ErrHintFileCorrupted
371 }
372 return 0, err
373 }
374
375 scratch[i] = b
376 i++
377
378 if b < 0x80 || i == len(scratch) {
379 break
380 }
381 }
382
383 if i == len(scratch) && scratch[i-1]&0x80 != 0 {
384 return 0, ErrHintFileCorrupted
385 }
386
387 val, n, err := decodeCompatInt64(scratch[:i])
388 if err != nil {
389 return 0, err
390 }
391 if n != i {
392 return 0, ErrHintFileCorrupted
393 }
394
395 if fieldsRead != nil {
396 (*fieldsRead)++
397 }
398
399 return val, nil
400}
401
402// Close closes the hint file
403func (r *HintFileReader) Close() error {

Callers 1

ReadMethod · 0.85

Calls 1

decodeCompatInt64Function · 0.85

Tested by

no test coverage detected