binary

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package binary decodes a WebAssembly component binary -- its imports, exports, types, embedded core modules and instantiation graph -- without a wazy.Runtime: decoding is pure and compiles nothing.

c, err := binary.Decode(wasmBytes) // e.g. from os.ReadFile("app.wasm")
if err != nil {
	return err
}
for _, imp := range c.Imports {
	fmt.Println("import", imp.Name)
}
for _, exp := range c.Exports {
	fmt.Println("export", exp.Name)
}

An import's or export's ExternType is the sort byte of the binary format: 0x00 core module, 0x01 func, 0x02 value, 0x03 type, 0x04 component, 0x05 instance. For a func, Component.ResolveType(ExternIndex) gives its component.FuncDesc; for an instance, its InstanceDesc.

Every name here is an alias of the decoder wazy itself instantiates from, so what this package reports is exactly what Instantiate sees. The value type descriptors (component.FuncDesc, component.RecordDesc, ...) live in package component.

A core wasm module is not a component: Decode rejects one with ErrInvalidVersion. Use package github.com/samyfodil/wazy/binary for those.

Example

Decode a component and list what it imports and exports.

package main

import (
	"fmt"

	"github.com/samyfodil/wazy/component/binary"
	"github.com/samyfodil/wazy/internal/component/testfixtures"
)

func main() {
	wasm := testfixtures.RealHello // the bytes of a .wasm component

	c, err := binary.Decode(wasm)
	if err != nil {
		panic(err)
	}
	for _, imp := range c.Imports {
		fmt.Println("import", imp.Name)
	}
	for _, exp := range c.Exports {
		fmt.Println("export", exp.Name)
	}
}
Output:
import wasi:cli/environment@0.2.3
import wasi:cli/exit@0.2.3
import wasi:io/error@0.2.3
import wasi:io/streams@0.2.3
import wasi:cli/stdin@0.2.3
import wasi:cli/stdout@0.2.3
import wasi:cli/stderr@0.2.3
import wasi:clocks/wall-clock@0.2.3
import wasi:filesystem/types@0.2.3
import wasi:filesystem/preopens@0.2.3
export wasi:cli/run@0.2.3

Index

Examples

Constants

View Source
const (
	TypeDeclCoreType = binary.TypeDeclCoreType
	TypeDeclType     = binary.TypeDeclType
	TypeDeclAlias    = binary.TypeDeclAlias
	TypeDeclImport   = binary.TypeDeclImport
	TypeDeclExport   = binary.TypeDeclExport
)

The declaration kinds, TypeDecl.Kind.

View Source
const (
	TypeSpaceDef    = binary.TypeSpaceDef
	TypeSpaceAlias  = binary.TypeSpaceAlias
	TypeSpaceImport = binary.TypeSpaceImport
	TypeSpaceExport = binary.TypeSpaceExport

	ComponentFuncFromImport    = binary.ComponentFuncFromImport
	ComponentFuncFromAlias     = binary.ComponentFuncFromAlias
	ComponentFuncFromCanonLift = binary.ComponentFuncFromCanonLift
	ComponentFuncFromExport    = binary.ComponentFuncFromExport

	ComponentInstanceFromImport     = binary.ComponentInstanceFromImport
	ComponentInstanceFromDefinition = binary.ComponentInstanceFromDefinition
	ComponentInstanceFromAlias      = binary.ComponentInstanceFromAlias
	ComponentInstanceFromExport     = binary.ComponentInstanceFromExport

	ComponentFromImport     = binary.ComponentFromImport
	ComponentFromDefinition = binary.ComponentFromDefinition
	ComponentFromAlias      = binary.ComponentFromAlias
	ComponentFromExport     = binary.ComponentFromExport

	CoreFuncFromAlias = binary.CoreFuncFromAlias
	CoreFuncFromCanon = binary.CoreFuncFromCanon

	CoreModuleFromDefinition = binary.CoreModuleFromDefinition
	CoreModuleFromAlias      = binary.CoreModuleFromAlias
)

The index-space entry kinds.

View Source
const (
	CanonKindLift                     = binary.CanonKindLift
	CanonKindLower                    = binary.CanonKindLower
	CanonKindResourceNew              = binary.CanonKindResourceNew
	CanonKindResourceDrop             = binary.CanonKindResourceDrop
	CanonKindResourceRep              = binary.CanonKindResourceRep
	CanonKindTaskCancel               = binary.CanonKindTaskCancel
	CanonKindSubtaskCancel            = binary.CanonKindSubtaskCancel
	CanonKindTaskReturn               = binary.CanonKindTaskReturn
	CanonKindContextGet               = binary.CanonKindContextGet
	CanonKindContextSet               = binary.CanonKindContextSet
	CanonKindThreadYield              = binary.CanonKindThreadYield
	CanonKindSubtaskDrop              = binary.CanonKindSubtaskDrop
	CanonKindStreamNew                = binary.CanonKindStreamNew
	CanonKindStreamRead               = binary.CanonKindStreamRead
	CanonKindStreamWrite              = binary.CanonKindStreamWrite
	CanonKindStreamCancelRead         = binary.CanonKindStreamCancelRead
	CanonKindStreamCancelWrite        = binary.CanonKindStreamCancelWrite
	CanonKindStreamDropReadable       = binary.CanonKindStreamDropReadable
	CanonKindStreamDropWritable       = binary.CanonKindStreamDropWritable
	CanonKindFutureNew                = binary.CanonKindFutureNew
	CanonKindFutureRead               = binary.CanonKindFutureRead
	CanonKindFutureWrite              = binary.CanonKindFutureWrite
	CanonKindFutureCancelRead         = binary.CanonKindFutureCancelRead
	CanonKindFutureCancelWrite        = binary.CanonKindFutureCancelWrite
	CanonKindFutureDropReadable       = binary.CanonKindFutureDropReadable
	CanonKindFutureDropWritable       = binary.CanonKindFutureDropWritable
	CanonKindStreamForward            = binary.CanonKindStreamForward
	CanonKindFutureForward            = binary.CanonKindFutureForward
	CanonKindErrorContextNew          = binary.CanonKindErrorContextNew
	CanonKindErrorContextDebugMessage = binary.CanonKindErrorContextDebugMessage
	CanonKindErrorContextDrop         = binary.CanonKindErrorContextDrop
	CanonKindWaitableSetNew           = binary.CanonKindWaitableSetNew
	CanonKindWaitableSetWait          = binary.CanonKindWaitableSetWait
	CanonKindWaitableSetPoll          = binary.CanonKindWaitableSetPoll
	CanonKindWaitableSetDrop          = binary.CanonKindWaitableSetDrop
	CanonKindWaitableJoin             = binary.CanonKindWaitableJoin
	CanonKindBackpressureInc          = binary.CanonKindBackpressureInc
	CanonKindBackpressureDec          = binary.CanonKindBackpressureDec
	CanonKindThreadIndex              = binary.CanonKindThreadIndex
	CanonKindThreadNewIndirect        = binary.CanonKindThreadNewIndirect
	CanonKindThreadSuspend            = binary.CanonKindThreadSuspend
	CanonKindThreadYieldThenResume    = binary.CanonKindThreadYieldThenResume
	CanonKindThreadResumeLater        = binary.CanonKindThreadResumeLater
	CanonKindThreadSuspendThenResume  = binary.CanonKindThreadSuspendThenResume
	CanonKindThreadSuspendThenPromote = binary.CanonKindThreadSuspendThenPromote
	CanonKindThreadYieldThenPromote   = binary.CanonKindThreadYieldThenPromote

	CanonKindThreadSpawnRef             = binary.CanonKindThreadSpawnRef
	CanonKindThreadSpawnIndirect        = binary.CanonKindThreadSpawnIndirect
	CanonKindThreadAvailableParallelism = binary.CanonKindThreadAvailableParallelism
)

The canon definition kinds, Canon.Kind.

Variables

View Source
var (
	ErrInvalidMagicNumber = binary.ErrInvalidMagicNumber
	ErrInvalidVersion     = binary.ErrInvalidVersion
	ErrInvalidLayer       = binary.ErrInvalidLayer
	ErrInvalidSectionID   = binary.ErrInvalidSectionID
	ErrTruncatedBinary    = binary.ErrTruncatedBinary
)

The errors Decode returns for a malformed preamble or section.

Functions

This section is empty.

Types

type AliasDef

type AliasDef = binary.AliasDef

A decoded component and its parts.

type Canon

type Canon = binary.Canon

A decoded component and its parts.

type CanonOpt

type CanonOpt = binary.CanonOpt

A decoded component and its parts.

type Component

type Component = binary.Component

A decoded component and its parts.

func Decode

func Decode(b []byte) (*Component, error)

Decode decodes a component binary.

type ComponentDesc

type ComponentDesc = binary.ComponentDesc

The type descriptors package component does not already name.

type ComponentFuncSpaceEntry

type ComponentFuncSpaceEntry = binary.ComponentFuncSpaceEntry

The index spaces: each entry says what produced the item at that index.

type ComponentFuncSpaceEntryKind

type ComponentFuncSpaceEntryKind = binary.ComponentFuncSpaceEntryKind

The index spaces: each entry says what produced the item at that index.

type ComponentInstanceSpaceEntry

type ComponentInstanceSpaceEntry = binary.ComponentInstanceSpaceEntry

The index spaces: each entry says what produced the item at that index.

type ComponentInstanceSpaceEntryKind

type ComponentInstanceSpaceEntryKind = binary.ComponentInstanceSpaceEntryKind

The index spaces: each entry says what produced the item at that index.

type ComponentSpaceEntry

type ComponentSpaceEntry = binary.ComponentSpaceEntry

The index spaces: each entry says what produced the item at that index.

type ComponentSpaceEntryKind

type ComponentSpaceEntryKind = binary.ComponentSpaceEntryKind

The index spaces: each entry says what produced the item at that index.

type CoreFuncSpaceEntry

type CoreFuncSpaceEntry = binary.CoreFuncSpaceEntry

The index spaces: each entry says what produced the item at that index.

type CoreFuncSpaceEntryKind

type CoreFuncSpaceEntryKind = binary.CoreFuncSpaceEntryKind

The index spaces: each entry says what produced the item at that index.

type CoreInlineExport

type CoreInlineExport = binary.CoreInlineExport

A decoded component and its parts.

type CoreInstance

type CoreInstance = binary.CoreInstance

A decoded component and its parts.

type CoreInstantiateArg

type CoreInstantiateArg = binary.CoreInstantiateArg

A decoded component and its parts.

type CoreModule

type CoreModule = binary.CoreModule

A decoded component and its parts.

type CoreModuleSpaceEntry

type CoreModuleSpaceEntry = binary.CoreModuleSpaceEntry

The index spaces: each entry says what produced the item at that index.

type CoreModuleSpaceEntryKind

type CoreModuleSpaceEntryKind = binary.CoreModuleSpaceEntryKind

The index spaces: each entry says what produced the item at that index.

type Export

type Export = binary.Export

A decoded component and its parts.

type ExternDesc

type ExternDesc = binary.ExternDesc

The declarations of an instance or component type, its Decls field, and what an import, an export's ascription, or a declaration says an item is.

type Import

type Import = binary.Import

A decoded component and its parts.

type InlineExport

type InlineExport = binary.InlineExport

A decoded component and its parts.

type Instance

type Instance = binary.Instance

A decoded component and its parts.

type InstanceDesc

type InstanceDesc = binary.InstanceDesc

The type descriptors package component does not already name.

type InstantiateArg

type InstantiateArg = binary.InstantiateArg

A decoded component and its parts.

type RawSection

type RawSection = binary.RawSection

A decoded component and its parts.

type ResourceDesc

type ResourceDesc = binary.ResourceDesc

The type descriptors package component does not already name.

type Start

type Start = binary.Start

A decoded component and its parts.

type Type

type Type = binary.Type

A decoded component and its parts.

type TypeDecl

type TypeDecl = binary.TypeDecl

The declarations of an instance or component type, its Decls field, and what an import, an export's ascription, or a declaration says an item is.

type TypeDeclKind

type TypeDeclKind = binary.TypeDeclKind

The declarations of an instance or component type, its Decls field, and what an import, an export's ascription, or a declaration says an item is.

type TypeSpaceEntry

type TypeSpaceEntry = binary.TypeSpaceEntry

The index spaces: each entry says what produced the item at that index.

type TypeSpaceEntryKind

type TypeSpaceEntryKind = binary.TypeSpaceEntryKind

The index spaces: each entry says what produced the item at that index.

Jump to

Keyboard shortcuts

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