Documentation
¶
Overview ¶
Package bridge is the Go side of the Nimbus Native C ABI (include/nn.h).
An app registers its handlers in init() — before the host starts the runtime — and then talks to the host with Send and CallHost. Everything that crosses is a byte slice; the wire format gives the bytes meaning.
On a device the bridge is the C ABI (bridge_native.go). In dev mode (`nimbus native dev`, build tag nimbusdev) the same API runs on the laptop over a socket to the device (bridge_dev.go).
Index ¶
Constants ¶
const ABIVersion = C.NN_ABI_VERSION
ABIVersion is the nn.h version this runtime speaks.
Variables ¶
var ErrNotStarted = errors.New("bridge: host has not started the runtime")
ErrNotStarted is returned by Send before the host has started the runtime.
Functions ¶
func CallHost ¶
CallHost asks the host something only it can answer, synchronously — text measurement during layout, later native modules. Safe from any goroutine.
func Logf ¶
Logf writes a line to the platform log: stderr here (the Xcode and simulator consoles show it), logcat on Android.
func Main ¶
func Main()
Main is for the app's main function. On a device the host owns the process and main never runs; in dev mode (bridge_dev.go) Main runs the app.
func OnCall ¶
OnCall sets the handler for synchronous calls from the host. It runs on the host's calling thread — usually the UI thread — so keep it fast.
func OnMessage ¶
func OnMessage(fn func(msg []byte))
OnMessage sets the handler for asynchronous messages from the host. Messages arrive in order, one at a time, on a runtime goroutine.
Types ¶
type Handle ¶
type Handle uint32
Handle is how a host refers to a Go value — a callback, a view's event handler — across the boundary. Hosts never see Go pointers, so the garbage collector never has to reason about native code.
type Handles ¶
type Handles[T any] struct { // contains filtered or unexported fields }
Handles maps handles to Go values. The zero value is ready to use; it is safe from any goroutine. Handle 0 is never issued, so hosts can use it for "none".
func (*Handles[T]) Get ¶
Get returns the value for id, or false if it was never issued or has been released — a host acting on a stale handle gets a miss, not a crash.
type HostError ¶
type HostError struct{ Code int }
HostError is a failed CallHost: Code is an NN_ERR_* value from nn.h.
type Stats ¶
type Stats struct {
Sent int64 // messages queued by Send
Wakes int64 // times the host was woken
Drains int64 // non-empty batches the host took
Received int64 // messages from nn_send
Calls int64 // nn_call invocations
Panics int64 // panics recovered at the boundary
HostCalls int64 // CallHost invocations
Goroutines int
HeapAlloc uint64 // bytes of live Go heap
Sys uint64 // bytes the Go runtime holds from the OS
}
Stats is a snapshot of bridge traffic and Go memory, for soak tests and (later) the DevTools inspector.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
abitest/app
command
The Go side of the ABI test: host.c drives it through nn.h exactly as an iOS or Android host would.
|
The Go side of the ABI test: host.c drives it through nn.h exactly as an iOS or Android host would. |