2
0
mirror of synced 2025-02-23 14:58:12 +00:00
mobile/bind/seq/seq.go
David Symonds 7b659348a5 mobile: add import comments.
Change-Id: I0ff6d42a8e11f49df6fc3066e86be75015b93631
Reviewed-on: https://go-review.googlesource.com/1238
Reviewed-by: Andrew Gerrand <adg@golang.org>
2014-12-10 01:59:04 +00:00

47 lines
1.5 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"
// Transact calls a method on a foreign object instance.
// It blocks until the call is complete.
var Transact func(ref *Ref, 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
}