Ejemplo n.º 1
0
// Marshal a protobuf struct into a database thang.
func marshalDBT(dbt *C.DBT, val proto.Message) (err error) {
	buf, err := proto.Marshal(val)
	if err != nil {
		return
	}

	if len(buf) > 0 {
		dbt.data = unsafe.Pointer(&buf[0])
		dbt.size = C.u_int32_t(len(buf))
	} else {
		dbt.data = nil
		dbt.size = 0
	}

	return
}
Ejemplo n.º 2
0
// Marshal the key of a record into a database thang.
func (db Database) marshalKey(dbt *C.DBT, rec proto.Message) (err error) {
	key := recordKey(rec)

	dbtype, err := db.Type()
	if err != nil {
		return
	}

	switch dbtype {
	case Numbered, Queue:
		dbt.data = unsafe.Pointer(key.(*uint32))
		dbt.size = 4

	default:
		err = marshalDBT(dbt, key.(proto.Message))
	}

	return
}