Пример #1
0
func (obj *logeObject) decode(blob []byte, toJSON bool) (object interface{}, upgraded bool) {
	if obj.LinkName == "" {
		object, upgraded = obj.Type.Decode(blob, toJSON)
	} else {
		var links linkList
		spack.DecodeFromBytes(&links, obj.DB.linkTypeSpec, blob)
		object = &linkSet{Original: links}
		upgraded = false
	}
	return
}
Пример #2
0
func (store *levelDBStore) tagVersions(typ *logeType) {
	var vt = typ.SpackType
	var prefix = encodeTaggedKey([]uint16{ldb_LINK_INFO_TAG, vt.Tag}, "")
	var it = store.iteratePrefix(prefix, []byte{}, defaultReadOptions)
	defer it.Close()

	for it = it; it.Valid(); it.Next() {
		var info = &linkInfo{}
		spack.DecodeFromBytes(info, linkInfoSpec, it.Value())
		typ.Links[info.Name] = info
	}

	var maxTag uint16 = 0
	var missing = make([]*linkInfo, 0)

	for _, info := range typ.Links {
		if info.Tag > maxTag {
			maxTag = info.Tag
		}
		if info.Tag == 0 {
			missing = append(missing, info)
		}
	}

	for _, info := range missing {
		maxTag++
		info.Tag = maxTag
		var key = encodeTaggedKey([]uint16{ldb_LINK_INFO_TAG, vt.Tag}, info.Name)
		enc, _ := spack.EncodeToBytes(info, linkInfoSpec)
		fmt.Printf("Updating link: %s::%s (%d)\n", typ.Name, info.Name, info.Tag)
		var err = store.db.Put(defaultWriteOptions, key, enc)
		if err != nil {
			panic(fmt.Sprintf("Write error: %v\n", err))
		}
	}

}