| 225 | } |
| 226 | |
| 227 | func (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 | |
| 251 | func (r *redisCache) Put(reader io.Reader, contentMetadata ContentMetadata, key *Key) (time.Duration, error) { |
| 252 | medatadata := r.encodeMetadata(&contentMetadata) |