Ejemplo n.º 1
0
// protoToKey decodes a protocol buffer representation of a key into an
// equivalent *Key object.
func protoToKey(p *pb.Key) (*Key, error) {
	var key *Key
	for _, el := range p.GetPathElement() {
		key = &Key{
			namespace: p.GetPartitionId().GetNamespace(),
			kind:      el.GetKind(),
			id:        el.GetId(),
			name:      el.GetName(),
			parent:    key,
		}
	}
	if !key.valid() { // Also detects key == nil.
		return nil, ErrInvalidKey
	}
	return key, nil
}
Ejemplo n.º 2
0
func protoToKey(p *pb.Key) *Key {
	keys := make([]*Key, len(p.GetPathElement()))
	for i, el := range p.GetPathElement() {
		keys[i] = &Key{
			namespace: p.GetPartitionId().GetNamespace(),
			kind:      el.GetKind(),
			id:        el.GetId(),
			name:      el.GetName(),
		}
	}
	for i := 0; i < len(keys)-1; i++ {
		keys[i+1].parent = keys[i]
	}
	return keys[len(keys)-1]
}