DecodeObject decode the object from binary
(b []byte)
| 19 | |
| 20 | // DecodeObject decode the object from binary |
| 21 | func DecodeObject(b []byte) (obj *Object, err error) { |
| 22 | if len(b) < ObjectEncodingLength { |
| 23 | return nil, ErrInvalidLength |
| 24 | } |
| 25 | obj = &Object{ |
| 26 | ID: make([]byte, 16), |
| 27 | CreatedAt: int64(binary.BigEndian.Uint64(b[16:])), |
| 28 | UpdatedAt: int64(binary.BigEndian.Uint64(b[24:])), |
| 29 | ExpireAt: int64(binary.BigEndian.Uint64(b[32:])), // 40 bit fields |
| 30 | Type: ObjectType(b[40]), // 41 bit |
| 31 | Encoding: ObjectEncoding(b[41]), // 42 bit |
| 32 | } |
| 33 | copy(obj.ID, b[0:16]) |
| 34 | return obj, nil |
| 35 | } |
| 36 | |
| 37 | // EncodeInt64 encode the int64 object to binary |
| 38 | func EncodeInt64(v int64) ([]byte, error) { |