gen

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gen turns a wire schema into code: Go (methods on the schema's own types), Swift (NimbusNativeKit hosts) and Kotlin (Android hosts). All three produce byte-identical encodings; conformance_test.go proves it.

Index

Constants

View Source
const GoFile = "wire_gen.go"

GoFile is the name of the generated file written into the schema package.

Variables

This section is empty.

Functions

func Go

func Go(s *schema.Schema) ([]byte, error)

Go generates methods on the schema's own types: AppendWire / ReadWire on every struct, Append<U> / Read<U> and variant markers for every union, and the Message union with Encode / Decode.

func Kotlin

func Kotlin(s *schema.Schema, kotlinPackage string) []byte

Kotlin generates the schema's types for Android hosts as one object named after the package (package proto → object Proto) in the given Kotlin package: data classes for structs, sealed interfaces for unions, constant objects for enums. It needs space.nimbusgo.nativekit's WireReader / WireWriter.

Integers keep their size and sign where Kotlin can (Byte, Short, Int, Long); unsigned ones widen: uint8/16 → Int, uint32 → Long, and uint64 is a Long holding the unsigned bit pattern.

func KotlinSchema

func KotlinSchema(kotlinPackage string, combined uint64) []byte

KotlinSchema generates the object holding the combined schema hash a host passes to Bridge.start.

func Namespace

func Namespace(s *schema.Schema) string

Namespace is the Swift enum / Kotlin object name for the schema.

func Swift

func Swift(s *schema.Schema) []byte

Swift generates the schema's types for iOS hosts, inside one namespace enum named after the package (package proto → enum Proto). It needs the NimbusNativeKit wire runtime (Wire.swift) in the same module.

func SwiftApp

func SwiftApp(s *schema.Schema) []byte

SwiftApp is Swift for an app's own schema: it imports NimbusNativeKit when the kit is a separate module (a Swift package in an Xcode project) and compiles as one module with it otherwise (the CLI build).

func SwiftSchema

func SwiftSchema(combined uint64) []byte

SwiftSchema generates the file that tells the host which combined schema hash to pass to nn_start.

Types

type Output

type Output struct {
	Schema *schema.Schema
	Go     []byte // write to <schema dir>/wire_gen.go
	Swift  []byte // compile into the iOS app (imports NimbusNativeKit when it is a package)
	Kotlin []byte // compile into the Android host, as <Namespace>.kt
}

Output is everything generated for one schema package.

func Generate

func Generate(dir, kotlinPackage string) (*Output, error)

Generate loads the schema in dir and generates all three languages; the Kotlin goes in kotlinPackage.

Jump to

Keyboard shortcuts

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