예제 #1
0
func ObjectMetaParse(data []byte) ObjectMeta {

	m := ObjectMeta{}

	if len(data) > 69 {

		//
		m.Type = data[1]
		m.seek = int(binary.BigEndian.Uint16(data[2:4]))

		//
		m.LogVersion = binary.BigEndian.Uint64(data[4:12])
		m.Version = binary.BigEndian.Uint64(data[12:20])

		//
		m.Created = binary.BigEndian.Uint64(data[20:28])
		m.Updated = binary.BigEndian.Uint64(data[28:36])
		m.Expired = binary.BigEndian.Uint64(data[36:44])

		//
		m.Group = binary.BigEndian.Uint32(data[56:60])
		m.User = binary.BigEndian.Uint32(data[60:64])
		m.Mode = binary.BigEndian.Uint32(data[64:68])

		//
		if m.Type == ObjectTypeFold {
			m.Num = binary.BigEndian.Uint32(data[52:56])
		} else if m.Type == ObjectTypeGeneral {
			m.Sum = binary.BigEndian.Uint32(data[52:56])
		}

		//
		m.Size = binary.BigEndian.Uint64(data[44:52])

		//
		if m.Expired > 0 {
			m.Ttl = (dbutil.MetaTimeParse(m.Expired).UnixNano() - time.Now().UTC().UnixNano()) / 1e6
		}

		//
		if len(data) >= m.seek {
			m.Name = string(data[69:m.seek])
		}
	}

	return m
}
예제 #2
0
파일: t_raw.go 프로젝트: lessos/lessdb
func (db *DB) _raw_ssttl_get(ns byte, key []byte) *skv.Reply {

	key = skv.RawNsKeyConcat(ns, key)

	rpl, ttl := skv.NewReply(""), int64(0)

	if ttlat := dbutil.BytesToUint64(db.RawGet(skv.RawTtlEntry(key)).Bytes()); ttlat > 0 {
		ttl = (dbutil.MetaTimeParse(ttlat).UnixNano() - time.Now().UTC().UnixNano()) / 1e6
	}

	if ttl < 0 {
		ttl = 0
	}

	rpl.Data = append(rpl.Data, []byte(strconv.FormatInt(ttl, 10)))

	return rpl
}