| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Go Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style | |
| 3 // license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Package seq implements the machine-dependent seq serialization format. | |
| 6 // | |
| 7 // Implementations of Transact and FinalizeRef are provided by a | |
| 8 // specific foreign language binding package, e.g. go.mobile/bind/java. | |
| 9 // | |
| 10 // Designed only for use by the code generated by gobind. Don't try to | |
| 11 // use this directly. | |
| 12 package seq // import "golang.org/x/mobile/bind/seq" | |
| 13 | |
| 14 // TODO(crawshaw): | |
| 15 // There is opportunity for optimizing these language | |
| 16 // bindings which requires deconstructing seq into something | |
| 17 // gnarly. So don't get too attached to the design. | |
| 18 | |
| 19 import "fmt" | |
| 20 | |
| 21 // Transact calls a method on a foreign object instance. | |
| 22 // It blocks until the call is complete. | |
| 23 var Transact func(ref *Ref, code int, in *Buffer) (out *Buffer) | |
| 24 | |
| 25 // FinalizeRef is the finalizer used on foreign objects. | |
| 26 var FinalizeRef func(ref *Ref) | |
| 27 | |
| 28 // A Func can be registered and called by a foreign language. | |
| 29 type Func func(out, in *Buffer) | |
| 30 | |
| 31 // Registry holds functions callable from gobind generated bindings. | |
| 32 // Functions are keyed by descriptor and function code. | |
| 33 var Registry = make(map[string]map[int]Func) | |
| 34 | |
| 35 // Register registers a function in the Registry. | |
| 36 func Register(descriptor string, code int, fn Func) { | |
| 37 m := Registry[descriptor] | |
| 38 if m == nil { | |
| 39 m = make(map[int]Func) | |
| 40 Registry[descriptor] = m | |
| 41 } | |
| 42 if m[code] != nil { | |
| 43 panic(fmt.Sprintf("registry.Register: %q/%d already registered",
descriptor, code)) | |
| 44 } | |
| 45 m[code] = fn | |
| 46 } | |
| OLD | NEW |