Beispiel #1
0
func (l *Location) fromPair(p kvl.Pair) error {
	var typ string
	err := tuple.UnpackInto(p.Key, &typ, &l.UUID)
	if err != nil {
		return err
	}
	if typ != "location" {
		return ErrBadKeyType
	}

	var version int
	left, err := tuple.UnpackIntoPartial(p.Value,
		&version, &l.URL, &l.Name, &l.Dead, &l.LastSeen)
	if err != nil {
		return err
	}

	if version != 0 {
		return ErrUnknownMetaVersion
	}

	l.AllocSplit = nil
	for len(left) > 0 {
		var next string
		left, err = tuple.UnpackIntoPartial(left, &next)
		if err != nil {
			return err
		}
		l.AllocSplit = append(l.AllocSplit, next)
	}

	return nil
}
Beispiel #2
0
func (f *File) fromPair(p kvl.Pair) error {
	var typ string
	err := tuple.UnpackInto(p.Key, &typ, &f.Path)
	if err != nil {
		return err
	}
	if typ != "file" {
		return ErrBadKeyType
	}

	var version int
	left, err := tuple.UnpackIntoPartial(p.Value, &version, &f.Size, &f.SHA256,
		&f.WriteTime, &f.PrefixID, &f.DataChunks, &f.MappingValue)
	if version != 0 {
		return ErrUnknownMetaVersion
	}

	f.Locations = nil
	for len(left) > 0 {
		var next [16]byte
		left, err = tuple.UnpackIntoPartial(left, &next)
		if err != nil {
			return err
		}
		f.Locations = append(f.Locations, next)
	}

	return nil
}
Beispiel #3
0
func indexFn(p kvl.Pair) []kvl.Pair {
	if p.IsZero() {
		return nil
	}

	var typ string
	_, err := tuple.UnpackIntoPartial(p.Key, &typ)
	if err != nil {
		return nil
	}

	switch typ {
	case "file":
		var f File
		err := f.fromPair(p)
		if err != nil {
			return nil
		}
		return f.indexPairs()

	case "location":
		var l Location
		err := l.fromPair(p)
		if err != nil {
			return nil
		}
		return l.indexPairs()

	default:
		return nil
	}
}
Beispiel #4
0
func walParse(data []byte) ([]int64, error) {
	var timestamps []int64
	if len(data) > 0 {
		var err error
		var length int
		data, err = tuple.UnpackIntoPartial(data, &length)
		if err != nil {
			return nil, err
		}

		timestamps = make([]int64, length)
		for i := range timestamps {
			data, err = tuple.UnpackIntoPartial(data, &timestamps[i])
			if err != nil {
				return nil, err
			}
		}
	}

	return timestamps, nil
}