func GetKeyAsBytes(datum *pb.Datum) ([]byte, error) {
	return gencoder.MarshalKey(datum.Key)
}
func GetKeyAsBytes(datum *pb.Datum) ([]byte, error) {
var byteBuffer bytes.Buffer
encoder := gob.NewEncoder(&byteBuffer)
if err := encoder.Encode(*datum.Key); err != nil {
log.Printf("Encoding error %v\n", err)
return nil, err
}
return byteBuffer.Bytes(), nil
}
func GetValueAsBytes(datum *pb.Datum) ([]byte, error) {
var byteBuffer bytes.Buffer
encoder := gob.NewEncoder(&byteBuffer)
if err := encoder.Encode(*datum.Value); err != nil {
log.Printf("Encoding error %v\n", err)
return nil, err
}
return byteBuffer.Bytes(), nil
}
func GetKeyAsBytes(datum *pb.Datum) ([]byte, error) {
return proto.Marshal(datum.Key)
}
func GetValueAsBytes(datum *pb.Datum) ([]byte, error) {
return proto.Marshal(datum.Value)
}
func ToDatumKey(byteArray []byte) (*pb.DatumKey, error) {
var element pb.DatumKey
r := bytes.NewReader(byteArray)
decoder := gob.NewDecoder(r)
if err := decoder.Decode(&element); err != nil {
log.Printf("Decoding error %v\n", err)
return nil, err
}
return &element, nil
}
func ToDatumValue(byteArray []byte) (*pb.DatumValue, error) {
var element pb.DatumValue
r := bytes.NewReader(byteArray)
decoder := gob.NewDecoder(r)
if err := decoder.Decode(&element); err != nil {
log.Printf("Decoding error %v\n", err)
return nil, err
}
return &element, nil
}
func ToDatumKey(byteArray []byte) (*pb.DatumKey, error) {
var element pb.DatumKey
err := proto.Unmarshal(byteArray, &element)
if err != nil {
return nil, err
}
return &element, nil
}
func ToDatumValue(byteArray []byte) (*pb.DatumValue, error) {
var element pb.DatumValue
err := proto.Unmarshal(byteArray, &element)
if err != nil {
return nil, err
}
return &element, nil
}
Gencode
package data
import (
	pb "github.com/bgokden/veri/veriservice"
	"github.com/bgokden/veri/data/gencoder"
)
func NewDatum(feature []float32,
	dim1 uint32,
	dim2 uint32,
	size1 uint32,
	size2 uint32,
	groupLabel []byte,
	label []byte,
	version uint64,
) *pb.Datum {
	return &pb.Datum{
		Key: &pb.DatumKey{
			Feature:    feature,
			Dim1:       dim1,
			Dim2:       dim2,
			Size1:      size1,
			Size2:      size1,
			GroupLabel: groupLabel,
		},
		Value: &pb.DatumValue{
			Label:   label,
			Version: version,
		},
	}
}