diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2016-10-31 14:56:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-31 14:56:38 +0000 |
commit | 659386309f36c482ddc0bb9e854ebda3da216491 (patch) | |
tree | eb156bfbfad599f3dd88e184a7f690f67c64337d /formats/idxfile/decoder.go | |
parent | 5944d8a185ff1f91e0e108dab1d756fd88692c3b (diff) | |
download | go-git-659386309f36c482ddc0bb9e854ebda3da216491.tar.gz |
utils: binary, new package that collect all the spare helper functions about binary operations (#102)
Diffstat (limited to 'formats/idxfile/decoder.go')
-rw-r--r-- | formats/idxfile/decoder.go | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/formats/idxfile/decoder.go b/formats/idxfile/decoder.go index 57b508d..884d32b 100644 --- a/formats/idxfile/decoder.go +++ b/formats/idxfile/decoder.go @@ -2,11 +2,11 @@ package idxfile import ( "bytes" - "encoding/binary" "errors" "io" "gopkg.in/src-d/go-git.v4/core" + "gopkg.in/src-d/go-git.v4/utils/binary" ) var ( @@ -70,7 +70,7 @@ func validateHeader(r io.Reader) error { } func readVersion(idx *Idxfile, r io.Reader) error { - v, err := readInt32(r) + v, err := binary.ReadUint32(r) if err != nil { return err } @@ -80,21 +80,19 @@ func readVersion(idx *Idxfile, r io.Reader) error { } idx.Version = v - return nil } func readFanout(idx *Idxfile, r io.Reader) error { var err error - for i := 0; i < 255; i++ { - idx.Fanout[i], err = readInt32(r) + idx.Fanout[i], err = binary.ReadUint32(r) if err != nil { return err } } - idx.ObjectCount, err = readInt32(r) + idx.ObjectCount, err = binary.ReadUint32(r) return err } @@ -115,7 +113,7 @@ func readObjectNames(idx *Idxfile, r io.Reader) error { func readCRC32(idx *Idxfile, r io.Reader) error { c := int(idx.ObjectCount) for i := 0; i < c; i++ { - if err := binary.Read(r, binary.BigEndian, &idx.Entries[i].CRC32); err != nil { + if err := binary.Read(r, &idx.Entries[i].CRC32); err != nil { return err } } @@ -126,7 +124,7 @@ func readCRC32(idx *Idxfile, r io.Reader) error { func readOffsets(idx *Idxfile, r io.Reader) error { c := int(idx.ObjectCount) for i := 0; i < c; i++ { - o, err := readInt32(r) + o, err := binary.ReadUint32(r) if err != nil { return err } @@ -148,12 +146,3 @@ func readChecksums(idx *Idxfile, r io.Reader) error { return nil } - -func readInt32(r io.Reader) (uint32, error) { - var v uint32 - if err := binary.Read(r, binary.BigEndian, &v); err != nil { - return 0, err - } - - return v, nil -} |