func (i *invoker) Prepare(ctx *context.T, method string, numArgs int) (argptrs []interface{}, tags []*vdl.Value, err error) { env, freeFunc := jutil.GetEnv() jContext, err := jcontext.JavaContext(env, ctx, nil) if err != nil { freeFunc() return nil, nil, err } // Have all input arguments be decoded into *vdl.Value. argptrs = make([]interface{}, numArgs) for i := 0; i < numArgs; i++ { value := new(vdl.Value) argptrs[i] = &value } // This method will invoke the freeFunc(). jVomTags, err := jutil.CallStaticFutureMethod(env, freeFunc, jServerRPCHelperClass, "prepare", []jutil.Sign{invokerSign, contextSign, jutil.StringSign}, i.jInvoker, jContext, jutil.CamelCase(method)) if err != nil { return nil, nil, err } env, freeFunc = jutil.GetEnv() defer freeFunc() defer jutil.DeleteGlobalRef(env, jVomTags) vomTags, err := jutil.GoByteArrayArray(env, jVomTags) if err != nil { return nil, nil, err } tags = make([]*vdl.Value, len(vomTags)) for i, vomTag := range vomTags { var err error if tags[i], err = jutil.VomDecodeToValue(vomTag); err != nil { return nil, nil, err } } return }
func decodeArgs(env jutil.Env, jVomArgs C.jobjectArray) ([]interface{}, error) { vomArgs, err := jutil.GoByteArrayArray(env, jutil.Object(uintptr(unsafe.Pointer(jVomArgs)))) if err != nil { return nil, err } // VOM-decode each arguments into a *vdl.Value. args := make([]interface{}, len(vomArgs)) for i := 0; i < len(vomArgs); i++ { var err error if args[i], err = jutil.VomDecodeToValue(vomArgs[i]); err != nil { return nil, err } } return args, nil }
func (i *invoker) Invoke(ctx *context.T, call rpc.StreamServerCall, method string, argptrs []interface{}) (results []interface{}, err error) { env, freeFunc := jutil.GetEnv() jContext, err := jcontext.JavaContext(env, ctx, nil) if err != nil { freeFunc() return nil, err } jStreamServerCall, err := javaStreamServerCall(env, jContext, call) if err != nil { freeFunc() return nil, err } vomArgs := make([][]byte, len(argptrs)) for i, argptr := range argptrs { arg := interface{}(jutil.DerefOrDie(argptr)) var err error if vomArgs[i], err = vom.Encode(arg); err != nil { freeFunc() return nil, err } } // This method will invoke the freeFunc(). jResult, err := jutil.CallStaticFutureMethod(env, freeFunc, jServerRPCHelperClass, "invoke", []jutil.Sign{invokerSign, contextSign, streamServerCallSign, jutil.StringSign, jutil.ArraySign(jutil.ArraySign(jutil.ByteSign))}, i.jInvoker, jContext, jStreamServerCall, jutil.CamelCase(method), vomArgs) if err != nil { return nil, err } env, freeFunc = jutil.GetEnv() defer freeFunc() defer jutil.DeleteGlobalRef(env, jResult) vomResults, err := jutil.GoByteArrayArray(env, jResult) if err != nil { return nil, err } results = make([]interface{}, len(vomResults)) for i, vomResult := range vomResults { var err error if results[i], err = jutil.VomDecodeToValue(vomResult); err != nil { return nil, err } } return results, nil }