コード例 #1
0
ファイル: h5pt.go プロジェクト: jonlawlor/go-hdf5
// Append appends packets to the end of a packet table.
func (t *Table) Append(data interface{}) error {
	rv := reflect.Indirect(reflect.ValueOf(data))
	rt := rv.Type()
	c_nrecords := C.size_t(0)
	c_data := unsafe.Pointer(nil)

	switch rt.Kind() {

	case reflect.Array:
		c_nrecords = C.size_t(rv.Len())
		c_data = unsafe.Pointer(rv.UnsafeAddr())

	case reflect.Slice:
		c_nrecords = C.size_t(rv.Len())
		slice := (*reflect.SliceHeader)(unsafe.Pointer(rv.UnsafeAddr()))
		c_data = unsafe.Pointer(slice.Data)

	case reflect.String:
		c_nrecords = C.size_t(rv.Len())
		str := (*reflect.StringHeader)(unsafe.Pointer(rv.UnsafeAddr()))
		c_data = unsafe.Pointer(str.Data)

	case reflect.Ptr:
		c_nrecords = C.size_t(1)
		c_data = unsafe.Pointer(rv.Elem().UnsafeAddr())

	default:
		c_nrecords = C.size_t(1)
		c_data = unsafe.Pointer(rv.UnsafeAddr())
	}

	err := C.H5PTappend(t.id, c_nrecords, c_data)
	return h5err(err)
}
コード例 #2
0
ファイル: h5pt.go プロジェクト: pombredanne/go-hdf5
// Appends packets to the end of a packet table.
// herr_t H5PTappend( hid_t table_id, size_t nrecords, const void *data)
func (t *Table) Append(data interface{}) error {
	rt := reflect.TypeOf(data)
	v := reflect.ValueOf(data)
	c_nrecords := C.size_t(0)
	c_data := unsafe.Pointer(nil)

	switch rt.Kind() {

	case reflect.Array:
		//fmt.Printf("-->array\n")
		c_nrecords = C.size_t(v.Len())
		c_data = unsafe.Pointer(v.UnsafeAddr())

	case reflect.Slice:
		fmt.Printf("-->slice\n")
		c_nrecords = C.size_t(v.Len())
		slice := (*reflect.SliceHeader)(unsafe.Pointer(v.UnsafeAddr()))
		c_data = unsafe.Pointer(slice.Data)
		//c_data = unsafe.Pointer(v.Index(0).Addr().UnsafeAddr())
		//c_data = unsafe.Pointer(&c_data)

	case reflect.String:
		c_nrecords = C.size_t(v.Len())
		str := (*reflect.StringHeader)(unsafe.Pointer(v.UnsafeAddr()))
		c_data = unsafe.Pointer(str.Data)

	case reflect.Ptr:
		//fmt.Printf("-->ptr %v\n", v.Elem())
		c_nrecords = C.size_t(1)
		c_data = unsafe.Pointer(v.Elem().UnsafeAddr())

	default:
		//fmt.Printf("-->\n")
		c_nrecords = C.size_t(1)
		c_data = unsafe.Pointer(v.UnsafeAddr())
	}

	fmt.Printf(":: append(%d, %d, %v)\n", c_nrecords, c_data, t.id)
	err := C.H5PTappend(t.id, c_nrecords, c_data)
	fmt.Printf(":: append(%d, %d) -> %v\n", c_nrecords, c_data, err)
	return togo_err(err)
}