func (c *bleReadWriteCloser) Write(b []byte) (n int, err error) { env, freeFunc := jutil.GetEnv() // This method will invoke the freeFunc(). if _, err := jutil.CallCallbackMethod(env, freeFunc, c.jStream, "write", []jutil.Sign{jutil.ByteArraySign}, b); err != nil { return 0, err } return len(b), nil }
func (l *bleListener) Accept(ctx *context.T) (flow.Conn, error) { env, freeFunc := jutil.GetEnv() // This method will invoke the freeFunc(). jStream, err := jutil.CallCallbackMethod(env, freeFunc, l.jListener, "accept", nil) if err != nil { return nil, err } env, freeFunc = jutil.GetEnv() defer freeFunc() return newConnection(env, jStream), nil }
func (c *bleReadWriteCloser) Read(b []byte) (n int, err error) { env, freeFunc := jutil.GetEnv() // This method will invoke the freeFunc(). jResult, err := jutil.CallCallbackMethod(env, freeFunc, c.jStream, "read", []jutil.Sign{jutil.IntSign}, len(b)) if err != nil { return 0, err } env, freeFunc = jutil.GetEnv() defer freeFunc() defer jutil.DeleteGlobalRef(env, jResult) data := jutil.GoByteArray(env, jResult) return copy(b, data), nil }