2
0
mirror of synced 2025-02-24 07:18:15 +00:00
mobile/bind/seq/seq.go
Hyang-Ah (Hana) Kim 334412418f bind: replace {Read,Write}UTF16 with {Read,Write}String for string.
This is to enable more flexible encoding/decoding of Go string.
For Java, we use UTF16 to be compatible with java string.
For other languages, we will want other way to represent a string.

Change-Id: Iccd53e2eea18d37636c3c619d06cb473facef0cd
Reviewed-on: https://go-review.googlesource.com/8628
Reviewed-by: David Crawshaw <crawshaw@golang.org>
2015-04-09 12:44:56 +00:00

53 lines
1.7 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
}
// 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)