package util import ( "C" ) import ( "encoding/json" "nosql_db_sdk_ffi/util/ptrproxy" "unsafe" "github.com/oracle/nosql-go-sdk/nosqldb/types" ) //export ffi_map_new func ffi_map_new(rust_json string) (GoMapPtr, UtilError) { var go_map map[string]interface{} err := json.Unmarshal([]byte(rust_json), &go_map) // println(rust_json) // forループを使用してキーと値を表示 // for key, value := range go_map { // fmt.Printf("Key: %s, Value: %d\n", key, value) // } if err != nil { return nil, C.CString(err.Error()) } value := types.NewMapValue(go_map) return GoMapPtr(ptrproxy.Ref(unsafe.Pointer(value))), nil } //export ffi_go_map_to_string func ffi_go_map_to_string(unsafe_go_map_ptr GoMapPtr) (*C.char, UtilError) { go_map_ptr, ok := ptrproxy.Deref(unsafe.Pointer(unsafe_go_map_ptr)) if !ok { return nil, C.CString("NosqldbPutRequestPtr cannot deref") } go_map := (*types.MapValue)(go_map_ptr) value, err := json.Marshal(go_map) if !ok { return nil, C.CString(err.Error()) } return C.CString(string(value)), nil }