2
0
mirror of synced 2025-02-22 14:28:14 +00:00
mobile/bind/seq/seq.go
Hyang-Ah (Hana) Kim c261c465a9 bind: seq.Transact requires interface descriptor.
seq.Transact is called when Go calls a method of a foreign object
that implements a Go interface. Currently, we assume that the foreign
object has an instance method that can conduct the message routing,
so the object id and the method code is sufficient for transact.

Passing the interface descriptor (e.g.  go.testpkg.I) however allows
the bind internal to use non-instance methods to implement the routing.

Change-Id: I1f61a04f919fbd09117ea332d678cd50e4861e46
Reviewed-on: https://go-review.googlesource.com/12685
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-07-27 18:08:41 +00:00

57 lines
1.8 KiB
Go

// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package seq implements the machine-dependent seq serialization format.
//
// Implementations of Transact and FinalizeRef are provided by a
// specific foreign language binding package, e.g. go.mobile/bind/java.
//
// Designed only for use by the code generated by gobind. Don't try to
// use this directly.
package seq // import "golang.org/x/mobile/bind/seq"
// TODO(crawshaw):
// There is opportunity for optimizing these language
// bindings which requires deconstructing seq into something
// gnarly. So don't get too attached to the design.
import (
"fmt"
_ "golang.org/x/mobile/internal/mobileinit"
)
// Transact calls a method on a foreign object instance.
// It blocks until the call is complete.
var Transact func(ref *Ref, desc string, code int, in *Buffer) (out *Buffer)
// FinalizeRef is the finalizer used on foreign objects.
var FinalizeRef func(ref *Ref)
// A Func can be registered and called by a foreign language.
type Func func(out, in *Buffer)
// Registry holds functions callable from gobind generated bindings.
// Functions are keyed by descriptor and function code.
var Registry = make(map[string]map[int]Func)
// Register registers a function in the Registry.
func Register(descriptor string, code int, fn Func) {
m := Registry[descriptor]
if m == nil {
m = make(map[int]Func)
Registry[descriptor] = m
}
if m[code] != nil {
panic(fmt.Sprintf("registry.Register: %q/%d already registered", descriptor, code))
}
m[code] = fn
}
// DecString decodes a string encoded in the Buffer.
var DecString func(in *Buffer) string
// EncString encodes a Go string into the Buffer.
var EncString func(out *Buffer, v string)