msgcodec

package
v1.5.4 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package msgcodec runs project-scoped Starlark message codecs that decode (and optionally re-encode) application-layer request/response bodies for display and editing. Codecs never run on the proxy hot path — only on explicit UI/API/MCP decode requests — so failures cannot break forwarding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(dir, id string) error

Delete removes a codec.

func Exists

func Exists(dir, id string) bool

Exists reports whether <id>.star is present in dir.

func Read

func Read(dir, id string) (string, error)

Read returns one codec's source.

func Save

func Save(dir, id, src string) error

Save validates that src compiles, then writes <id>.star.

func ValidID

func ValidID(id string) bool

ValidID reports whether id is a safe codec identifier.

Types

type Codec

type Codec struct {
	Meta Meta
	Src  string
	// contains filtered or unexported fields
}

Codec is a compiled Starlark codec.

func Compile

func Compile(id, src string) (*Codec, error)

Compile parses a codec script. Requires match(flow, side) and decode(flow, side, raw). encode(flow, side, plaintext) is optional unless apply_on_send is true.

func LoadDir

func LoadDir(dir string) ([]*Codec, map[string]error)

LoadDir compiles every *.star codec in dir.

func (*Codec) Decode

func (c *Codec) Decode(flow Flow, side string) (Result, error)

Decode runs decode(flow, side, raw) where raw is the body for that side.

func (*Codec) Encode

func (c *Codec) Encode(flow Flow, side, plaintext string) (string, error)

Encode rebuilds a wire body from edited plaintext.

func (*Codec) Match

func (c *Codec) Match(flow Flow, side string) (bool, error)

Match reports whether this codec applies to the flow/side.

type Flow

type Flow struct {
	Method     string
	Scheme     string
	Host       string
	Port       int
	Path       string
	Status     int
	Mime       string
	ReqHeaders map[string][]string
	ResHeaders map[string][]string
	ReqBody    string
	ResBody    string
}

Flow is the read-only view handed to match/decode/encode.

type Meta

type Meta struct {
	ID          string `json:"id"`
	Title       string `json:"title"`
	ApplyOnSend bool   `json:"applyOnSend"`
	Enabled     bool   `json:"enabled"`
}

Meta is codec metadata from the script's `meta` dict (or defaults from id).

type Result

type Result struct {
	CodecID   string            `json:"codecId"`
	Title     string            `json:"title,omitempty"`
	Plaintext string            `json:"plaintext"`
	Fields    map[string]string `json:"fields,omitempty"`
	Note      string            `json:"note,omitempty"`
	Error     string            `json:"error,omitempty"`
}

Result is what Decode returns for a matching codec.

func TryDecode

func TryDecode(codecs []*Codec, flow Flow, side string) (Result, bool)

TryDecode returns the first matching enabled codec's decode result.

type Source

type Source struct {
	ID     string `json:"id"`
	Source string `json:"source"`
	Meta   Meta   `json:"meta"`
	Error  string `json:"error,omitempty"`
}

Source is a stored codec with metadata and optional compile error.

func List

func List(dir string) []Source

List returns every *.star codec in dir (sorted).

Jump to

Keyboard shortcuts

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