Ejemplo n.º 1
0
func DecodeLabelTKey(tk storage.TKey) (label uint64, err error) {
	ibytes, err := tk.ClassBytes(keyLabel)
	if err != nil {
		return
	}
	label = binary.BigEndian.Uint64(ibytes[0:8])
	return
}
Ejemplo n.º 2
0
// DecodeSizeLabelTKey returns a size and a label from a size+label key component.
func DecodeSizeLabelTKey(tk storage.TKey) (label, size uint64, err error) {
	ibytes, err := tk.ClassBytes(keySizeLabel)
	if err != nil {
		return
	}
	size = binary.BigEndian.Uint64(ibytes[0:8])
	label = binary.BigEndian.Uint64(ibytes[8:16])
	return
}
Ejemplo n.º 3
0
// DecodeTKey returns a label and block index bytes from a label block RLE key.
// The block index bytes are returned because different block indices may be used (e.g., CZYX),
// and its up to caller to determine which one is used for this particular key.
func DecodeTKey(tk storage.TKey) (label uint64, block dvid.IZYXString, err error) {
	ibytes, err := tk.ClassBytes(keyLabelBlockRLE)
	if err != nil {
		return
	}
	label = binary.BigEndian.Uint64(ibytes[0:8])
	block = dvid.IZYXString(ibytes[8:])
	return
}
Ejemplo n.º 4
0
// DecodeTKey returns a spatial index from a image block key.
// TODO: Extend this when necessary to allow any form of spatial indexing like CZYX.
func DecodeTKey(tk storage.TKey) (*dvid.IndexZYX, error) {
	ibytes, err := tk.ClassBytes(keyImageBlock)
	if err != nil {
		return nil, err
	}
	var zyx dvid.IndexZYX
	if err = zyx.IndexFromBytes(ibytes); err != nil {
		return nil, fmt.Errorf("Cannot recover ZYX index from image block key %v: %v\n", tk, err)
	}
	return &zyx, nil
}
Ejemplo n.º 5
0
func DecodeBlockTKey(tk storage.TKey) (pt dvid.ChunkPoint3d, err error) {
	ibytes, err := tk.ClassBytes(keyBlock)
	if err != nil {
		return
	}
	var idx dvid.IndexZYX
	if err = idx.IndexFromBytes(ibytes); err != nil {
		return
	}
	pt = dvid.ChunkPoint3d(idx)
	return
}
Ejemplo n.º 6
0
// DecodeTypeLabelTKey decodes a type-specific key into a (index type, label) tuple.
func DecodeTypeLabelTKey(tk storage.TKey) (i IndexType, label uint64, err error) {
	var ibytes []byte
	ibytes, err = tk.ClassBytes(keyTypeLabel)
	if err != nil {
		return
	}
	if len(ibytes) != 9 {
		err = fmt.Errorf("labelsz label size type-specific key is wrong size: expected 9, got %d bytes", len(ibytes))
		return
	}
	i = IndexType(ibytes[0])
	label = binary.BigEndian.Uint64(ibytes[1:])
	return
}
Ejemplo n.º 7
0
// DecodeTKey returns the string key used for this keyvalue.
func DecodeTKey(tk storage.TKey) (string, error) {
	ibytes, err := tk.ClassBytes(keyStandard)
	if err != nil {
		return "", err
	}
	sz := len(ibytes) - 1
	if sz <= 0 {
		return "", fmt.Errorf("empty key")
	}
	if ibytes[sz] != 0 {
		return "", fmt.Errorf("expected 0 byte ending key of keyvalue key, got %d", ibytes[sz])
	}
	return string(ibytes[:sz]), nil
}
Ejemplo n.º 8
0
// DecodeTagTKey returns the Tag corresponding to this type-specific key.
func DecodeTagTKey(tk storage.TKey) (Tag, error) {
	ibytes, err := tk.ClassBytes(keyTag)
	if err != nil {
		return "", err
	}
	sz := len(ibytes) - 1
	if sz <= 0 {
		return "", fmt.Errorf("empty tag")
	}
	if ibytes[sz] != 0 {
		return "", fmt.Errorf("expected 0 byte ending tag key, got %d", ibytes[sz])
	}
	return Tag(ibytes[:sz]), nil
}
Ejemplo n.º 9
0
// DecodeTypeSizeLabelTKey decodes a type-specific key into a (index type, size, label) tuple.
func DecodeTypeSizeLabelTKey(tk storage.TKey) (i IndexType, sz uint32, label uint64, err error) {
	var ibytes []byte
	ibytes, err = tk.ClassBytes(keyTypeSizeLabel)
	if err != nil {
		return
	}
	if len(ibytes) != 13 {
		err = fmt.Errorf("labelsz element size type-specific key is wrong size: expected 13, got %d bytes", len(ibytes))
		return
	}
	i = IndexType(ibytes[0])
	sz = math.MaxUint32 - binary.BigEndian.Uint32(ibytes[1:5])
	label = binary.BigEndian.Uint64(ibytes[5:])
	return
}