-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
blob_cache.go
33 lines (29 loc) · 906 Bytes
/
blob_cache.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package protocol
import (
"bytes"
"encoding/binary"
)
// CacheBlob represents a blob as used in the client side blob cache protocol. It holds a hash of its data and
// the full data of it.
type CacheBlob struct {
// Hash is the hash of the blob. The hash is computed using xxHash, and must be deterministic for the same
// chunk data.
Hash int64
// Payload is the data of the blob. When sent, the client will associate the Hash of the blob with the
// Payload in it.
Payload []byte
}
// WriteBlob writes a CacheBlob x to Buffer dst.
func WriteBlob(dst *bytes.Buffer, x CacheBlob) error {
return chainErr(
binary.Write(dst, binary.LittleEndian, x.Hash),
WriteByteSlice(dst, x.Payload),
)
}
// Blob reads a CacheBlob x from Buffer src.
func Blob(src *bytes.Buffer, x *CacheBlob) error {
return chainErr(
binary.Read(src, binary.LittleEndian, &x.Hash),
ByteSlice(src, &x.Payload),
)
}