MCPcopy Create free account
hub / github.com/ContentSquare/chproxy / decodeMetadata

Method decodeMetadata

cache/redis_cache.go:227–249  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

225}
226
227func (r *redisCache) decodeMetadata(b []byte) (*ContentMetadata, int, error) {
228 if len(b) < 8 {
229 return nil, 0, &RedisCacheCorruptionError{}
230 }
231 cLength := uint64(b[7]) | (uint64(b[6]) << 8) | (uint64(b[5]) << 16) | (uint64(b[4]) << 24) | uint64(b[3])<<32 | (uint64(b[2]) << 40) | (uint64(b[1]) << 48) | (uint64(b[0]) << 56)
232 offset := 8
233 cType, sizeCType, err := r.decodeString(b[offset:])
234 if err != nil {
235 return nil, 0, err
236 }
237 offset += sizeCType
238 cEncoding, sizeCEncoding, err := r.decodeString(b[offset:])
239 if err != nil {
240 return nil, 0, err
241 }
242 offset += sizeCEncoding
243 metadata := &ContentMetadata{
244 Length: int64(cLength),
245 Type: cType,
246 Encoding: cEncoding,
247 }
248 return metadata, offset, nil
249}
250
251func (r *redisCache) Put(reader io.Reader, contentMetadata ContentMetadata, key *Key) (time.Duration, error) {
252 medatadata := r.encodeMetadata(&contentMetadata)

Callers 3

GetMethod · 0.95
TestMetadataFromToByteFunction · 0.80

Calls 1

decodeStringMethod · 0.95

Tested by 2

TestMetadataFromToByteFunction · 0.64