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/encoder.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/encoder.go')
-rw-r--r-- | formats/idxfile/encoder.go | 24 |
1 files changed, 5 insertions, 19 deletions
diff --git a/formats/idxfile/encoder.go b/formats/idxfile/encoder.go index 0fe9ae6..164414a 100644 --- a/formats/idxfile/encoder.go +++ b/formats/idxfile/encoder.go @@ -2,13 +2,11 @@ package idxfile import ( "crypto/sha1" - "encoding/binary" - "fmt" "hash" "io" "sort" - "gopkg.in/src-d/go-git.v4/core" + "gopkg.in/src-d/go-git.v4/utils/binary" ) // An Encoder writes idx files to an output stream. @@ -56,13 +54,13 @@ func (e *Encoder) encodeHeader(idx *Idxfile) (int, error) { return c, err } - return c + 4, e.writeInt32(idx.Version) + return c + 4, binary.WriteUint32(e, idx.Version) } func (e *Encoder) encodeFanout(idx *Idxfile) (int, error) { fanout := idx.calculateFanout() for _, c := range fanout { - if err := e.writeInt32(c); err != nil { + if err := binary.WriteUint32(e, c); err != nil { return 0, err } } @@ -71,31 +69,23 @@ func (e *Encoder) encodeFanout(idx *Idxfile) (int, error) { } func (e *Encoder) encodeHashes(idx *Idxfile) (int, error) { - repet := make(map[core.Hash]int, 0) - sz := 0 for _, ent := range idx.Entries { i, err := e.Write(ent.Hash[:]) sz += i - repet[ent.Hash]++ if err != nil { return sz, err } } - for h, c := range repet { - if c > 1 { - fmt.Println(h, c) - } - } return sz, nil } func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) { sz := 0 for _, ent := range idx.Entries { - err := binary.Write(e, binary.BigEndian, ent.CRC32) + err := binary.Write(e, ent.CRC32) sz += 4 if err != nil { @@ -109,7 +99,7 @@ func (e *Encoder) encodeCRC32(idx *Idxfile) (int, error) { func (e *Encoder) encodeOffsets(idx *Idxfile) (int, error) { sz := 0 for _, ent := range idx.Entries { - if err := e.writeInt32(uint32(ent.Offset)); err != nil { + if err := binary.WriteUint32(e, uint32(ent.Offset)); err != nil { return sz, err } @@ -133,10 +123,6 @@ func (e *Encoder) encodeChecksums(idx *Idxfile) (int, error) { return 40, nil } -func (e *Encoder) writeInt32(value uint32) error { - return binary.Write(e, binary.BigEndian, value) -} - type EntryList []Entry func (p EntryList) Len() int { return len(p) } |