Skip to content

Byte Engine

Pt edited this page Jun 17, 2026 · 2 revisions

Byte Engine is the binary backend in Lc for opcode-style runtime execution.

It is suitable for:

  • compact VM loops,
  • binary protocol handlers,
  • instruction stream processing,
  • low-level execution runtimes.

Runtime flow

  1. Raw bytes in scope: INPUT []byte.
  2. Parser builds []ParsedBytes.
  3. Parsed data stored in PARSED []ParsedBytes.
  4. Opcode resolved from Switch bytes + configured endianness.
  5. Handler execution with auto/manual instruction pointer policy.

Parsed node model

ParsedBytes fields:

  • Switch []byte
  • Args [][]byte
  • Raw []byte
  • Metadata map[string]interface{}

Built-in parser format (Parser1)

Expected instruction format:

  1. command bytes (CommandBytelen)
  2. args count bytes (ArgscountBytelen)
  3. per argument:
    • arg length bytes (ArglenBytelen)
    • argument payload bytes

All integer decoding depends on configured endianness.

Command contract

Registration:

  • NewCommandByte(opcode, handler, name, autoBytecodeIdxShift)

Handler signature:

  • func(*engine.ByteEngine, byteParsing.ParsedBytes) error

Instruction pointer control

Auto mode:

  • set autoBytecodeIdxShift=true, runtime moves to next instruction automatically.

Manual mode:

  • set autoBytecodeIdxShift=false, handler controls flow via:
    • AddToBytecodeIdx(n)
    • SetBytecodeIdx(n)
    • GetBytecodeIdx()

Manual mode enables loops, branches, jump tables, and custom control-flow semantics.

Reserved scope keys

Default events use:

  • ENDIANESS int
  • BYECODE_IDX *int
  • INPUT []byte
  • PARSED []ParsedBytes

Keep these names reserved in extension code.

Binary output

Write:

  • Generator.AddBytes(...)

Read:

  • Generator.GetBytesRes()

Use pipeline stages when your runtime has pre/post execution phases.

Clone this wiki locally