github.com/c-darwin/mobile@v0.0.0-20160313183840-ff625c46f7c9/bind/seq/seq.go (about)

     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 "github.com/c-darwin/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 (
    20  	"fmt"
    21  
    22  	_ "github.com/c-darwin/mobile/internal/mobileinit"
    23  )
    24  
    25  // Transact calls a method on a foreign object instance.
    26  // It blocks until the call is complete.
    27  var Transact func(ref *Ref, desc string, code int, in *Buffer) (out *Buffer)
    28  
    29  // FinalizeRef is the finalizer used on foreign objects.
    30  var FinalizeRef func(ref *Ref)
    31  
    32  // A Func can be registered and called by a foreign language.
    33  type Func func(out, in *Buffer)
    34  
    35  // Registry holds functions callable from gobind generated bindings.
    36  // Functions are keyed by descriptor and function code.
    37  var Registry = make(map[string]map[int]Func)
    38  
    39  // Register registers a function in the Registry.
    40  func Register(descriptor string, code int, fn Func) {
    41  	m := Registry[descriptor]
    42  	if m == nil {
    43  		m = make(map[int]Func)
    44  		Registry[descriptor] = m
    45  	}
    46  	if m[code] != nil {
    47  		panic(fmt.Sprintf("registry.Register: %q/%d already registered", descriptor, code))
    48  	}
    49  	m[code] = fn
    50  }
    51  
    52  // DecString decodes a string encoded in the Buffer.
    53  var DecString func(in *Buffer) string
    54  
    55  // EncString encodes a Go string into the Buffer.
    56  var EncString func(out *Buffer, v string)