Documentation
¶
Overview ¶
rxabi (ABI for Application Binary Interface, rx for our frontend package) generates a TypeScript interface to communicate with the WASM Go rx engine Given the name of a (signed or unsigned) integer type T that has constants defined, rxabi will create a new self-contained TS source file exposing a list of events
The file is created in the same package and directory as the package that defines T. It has helpful defaults designed for use with go generate.
rxabi works best with constants that are consecutive values such as created using iota, but creates good code regardless. In the future it might also provide custom support for constant sets that are bit patterns.
For example, given this snippet,
package painkiller type Pill int const ( Placebo Pill = iota Aspirin Ibuprofen Paracetamol Acetaminophen = Paracetamol )
running this command
rxabi -type=Pill
in the same directory will create the file pill-abi.ts, in package painkiller, containing a definition of
export const PillEventsCode = { Placebo: 1, /*..*/.}
That method will translate the value of a Pill constant to the string representation of the respective constant name, so that the call fmt.Print(painkiller.Aspirin) will print the string "Aspirin".
Typically this process would be run using go generate, like this:
//go:generate rxabi -type=Pill
If multiple constants have the same value, the lexically first matching name will be used (in the example, Acetaminophen will print as "Paracetamol").
With no arguments, it processes the package in the current directory. Otherwise, the arguments must name a single directory holding a Go package or a set of Go source files that represent a single Go package.
The -type flag accepts a comma-separated list of types so a single run can generate methods for multiple types. The default output file is t_abi.ts, where t is the lower-cased name of the first type listed. It can be overridden with the -output flag.
The -linecomment flag tells rxabi to generate the text of any line comment, trimmed of leading spaces, instead of the constant name. For instance, if the constants above had a Pill prefix, one could write
PillAspirin // Aspirin
to suppress it in the output.