rt

package
v0.18.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package rt provides the hand-written runtime shared by the generated PHP cgo bindings: a handle registry for live *encxmobile.EncClient values and a JSON response envelope. Generated cgo wrappers call into this package; it contains no cgo itself.

Index

Constants

This section is empty.

Variables

View Source
var Default = NewRegistry()

Default is the global registry used by the generated wrappers.

View Source
var ErrNilClient = errors.New("rt: cannot register nil client")

ErrNilClient is returned by Add when asked to register a nil client. Registering nil is refused rather than silently accepted, since a nil client stored under a valid handle would panic on first use instead of failing at registration time.

Functions

func Fail

func Fail(err error) string

Fail serializes an error envelope from err. A nil err still produces a valid envelope, using a stable placeholder message.

func Failf

func Failf(format string, a ...any) string

Failf serializes an error envelope from a formatted message. The message is JSON-string-escaped normally, so quotes, newlines, and non-ASCII text (e.g. Cyrillic) round-trip intact.

func OK

func OK(v any) string

OK serializes a successful envelope carrying v as the "value" field. If v cannot be marshaled to JSON (e.g. it contains a NaN float), OK returns a well-formed error envelope instead of broken JSON.

func OKVoid

func OKVoid() string

OKVoid returns a successful envelope with no "value" field at all (as opposed to a "value" of null).

Types

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry stores live clients under integer handles suitable for passing across the C ABI (e.g. as an opaque int64 to PHP).

Handles are monotonically increasing and are never reused after Free, so a handle freed on the PHP side can never be silently reassigned to a different, unrelated client. Handle 0 is reserved and never issued; it always means "invalid handle".

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates an empty registry.

func (*Registry) Add

func (r *Registry) Add(c *encxmobile.EncClient) (int64, error)

Add registers c and returns a new, non-zero handle for it. It returns an error (and a zero handle) if c is nil; nil clients are never registered.

func (*Registry) Free

func (r *Registry) Free(h int64) bool

Free removes the client registered under h. It reports whether h existed. The handle is never reused for a future Add.

func (*Registry) Get

func (r *Registry) Get(h int64) (*encxmobile.EncClient, error)

Get returns the client registered under h. It returns an error naming the handle if h is 0, unknown, or has already been freed.

func (*Registry) Len

func (r *Registry) Len() int

Len returns the number of currently registered clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL