Exemple #1
0
func (evt *Event) ToStruct(data interface{}) interface{} {
	t := reflect.TypeOf(data)

	struct_field_ids := make([]uint64, 0)
	tdb_field_ids := make([]uint64, 0)

	for i := 0; i < t.NumField(); i++ {
		field := t.Field(i)
		field_name := field.Tag.Get("tdb")
		if field_name != "" {
			tdb_id := evt.trail.db.fieldNameToId[field_name]
			struct_field_ids = append(struct_field_ids, uint64(i))
			tdb_field_ids = append(tdb_field_ids, tdb_id)
		}
	}

	v := reflect.New(t)
	v.Elem().Field(0).SetInt(int64(evt.Timestamp))
	for k := 1; k < len(tdb_field_ids); k++ {
		var vlength C.uint64_t
		itemValue := C.tdb_get_item_value(evt.trail.db.db, evt.items[tdb_field_ids[k]-1], &vlength)
		value := C.GoStringN(itemValue, C.int(vlength))
		v.Elem().Field(int(struct_field_ids[k])).SetString(value)
	}
	return v
}
Exemple #2
0
func (evt *Event) ToMap() map[string]string {
	fields := make(map[string]string)
	var vlength C.uint64_t

	for _, item := range evt.items {
		itemValue := C.tdb_get_item_value(evt.trail.db.db, item, &vlength)
		value := C.GoStringN(itemValue, C.int(vlength))
		key := C.GoString(C.tdb_get_field_name(evt.trail.db.db, C.tdb_item_field(item)))
		fields[key] = value
	}
	return fields
}
Exemple #3
0
func (evt *Event) Get(index int) string {
	var vlength C.uint64_t
	itemValue := C.tdb_get_item_value(evt.trail.db.db, evt.items[index], &vlength)
	value := C.GoStringN(itemValue, C.int(vlength))
	return value
}