Swap len and encoding fields in chunk entry
This commit is contained in:
parent
df96d97dab
commit
da068500c6
13
chunks.go
13
chunks.go
|
@ -194,14 +194,14 @@ func (w *chunkWriter) WriteChunks(chks ...*ChunkMeta) error {
|
||||||
for _, chk := range chks {
|
for _, chk := range chks {
|
||||||
chk.Ref = seq | uint64(w.n)
|
chk.Ref = seq | uint64(w.n)
|
||||||
|
|
||||||
|
if err := w.write([]byte{byte(chk.Chunk.Encoding())}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
n = binary.PutUvarint(b, uint64(len(chk.Chunk.Bytes())))
|
n = binary.PutUvarint(b, uint64(len(chk.Chunk.Bytes())))
|
||||||
|
|
||||||
if err := w.write(b[:n]); err != nil {
|
if err := w.write(b[:n]); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := w.write([]byte{byte(chk.Chunk.Encoding())}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := w.write(chk.Chunk.Bytes()); err != nil {
|
if err := w.write(chk.Chunk.Bytes()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -283,16 +283,17 @@ func (s *chunkReader) Chunk(ref uint64) (chunks.Chunk, error) {
|
||||||
if int(off) >= len(b) {
|
if int(off) >= len(b) {
|
||||||
return nil, errors.Errorf("offset %d beyond data size %d", off, len(b))
|
return nil, errors.Errorf("offset %d beyond data size %d", off, len(b))
|
||||||
}
|
}
|
||||||
b = b[off:]
|
|
||||||
|
enc := chunks.Encoding(b[off])
|
||||||
|
b = b[off+1:]
|
||||||
|
|
||||||
l, n := binary.Uvarint(b)
|
l, n := binary.Uvarint(b)
|
||||||
if n < 0 {
|
if n < 0 {
|
||||||
return nil, fmt.Errorf("reading chunk length failed")
|
return nil, fmt.Errorf("reading chunk length failed")
|
||||||
}
|
}
|
||||||
b = b[n:]
|
b = b[n:]
|
||||||
enc := chunks.Encoding(b[0])
|
|
||||||
|
|
||||||
c, err := chunks.FromData(enc, b[1:1+l])
|
c, err := chunks.FromData(enc, b[0:l])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue