Example #1
0
func (obj *logeObject) encode(object interface{}) []byte {
	if !obj.hasValue(object) {
		return nil
	}

	if obj.LinkName == "" {
		return obj.Type.Encode(object)
	}

	var set = object.(*linkSet)
	enc, err := spack.EncodeToBytes(set.ReadKeys(), obj.DB.linkTypeSpec)
	if err != nil {
		panic(fmt.Sprintf("Link encode error: %v\n", err))
	}
	return enc
}
Example #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))
		}
	}

}