rap

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 9 Imported by: 0

README

rap

Go library for decoding and encoding
Real Virtuality / DayZ RAP binary config format (.bin, binary .rvmat).

  • RAP decode to rvcfg AST.
  • RAP encode from rvcfg AST.
  • Scalar subtype handling (string / float / long) with float normalization.
  • Class-body offsets and nested array support.

Install

go get github.com/woozymasta/rap

Relationship with rvcfg

rap uses github.com/woozymasta/rvcfg as text frontend:

  • preprocess + parse source text into AST
  • encode AST to RAP binary
  • decode RAP binary back to AST/text

Usage

Parse source and encode RAP:

parsed, err := rap.ParseSourceFileWithDefaults("config.cpp")
if err != nil {
  // handle
}

// or pass explicit options:
parsed, err := rap.ParseSourceFile("config.cpp", rap.SourceParseOptions{
  Preprocess: rvcfg.PreprocessOptions{
    IncludeDirs: []string{"./include"},
  },
  Parse: rvcfg.ParseOptions{
    CaptureScalarRaw: true,
  },
})
if err != nil {
  // handle
}

bin, err := rap.EncodeAST(parsed.Processed.Parse.File, rap.EncodeOptions{})

Decode RAP to AST:

file, err := rap.DecodeToAST(data, rap.DecodeOptions{})
if err != nil {
  // handle
}

_ = file.Statements

Decode RAP to text:

text, err := rap.DecodeToText(data, rap.DecodeOptions{}, rap.RenderOptions{
  Format: rvcfg.FormatOptions{
    MaxLineWidth: 120,
  },
})

Decode options

rap.DecodeOptions{
  DisableFloatNormalization: false, // default: shortest stable float32 text
}

Format coverage

Implemented RAP entry types:

  • 0 class with body offset
  • 1 scalar assignment
  • 2 array assignment
  • 3 extern class
  • 4 delete
  • 5 array append (+=)

References

Documentation

Overview

Package rap implements RAP binary codec for DayZ/ArmA config-like data.

The package integrates with github.com/woozymasta/rvcfg for text source parsing (preprocess + parse) and owns binary encode/decode pipeline.

Typical flow:

  • parse source text with ParseSourceFile
  • encode parsed AST with EncodeAST
  • decode RAP payload with DecodeToAST or DecodeToText

Minimal flow example:

parsed, err := ParseSourceFileWithDefaults("config.cpp")
if err != nil {
	// handle
}

bin, err := EncodeAST(parsed.Processed.Parse.File, EncodeOptions{})
if err != nil {
	// handle
}

decoded, err := DecodeToAST(bin, DecodeOptions{})
if err != nil {
	// handle
}

_ = decoded

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotImplemented indicates codec path is declared but not implemented yet.
	ErrNotImplemented = errors.New("not implemented")

	// ErrInvalidRAP indicates malformed or unsupported RAP binary structure.
	ErrInvalidRAP = errors.New("invalid rap binary")

	// ErrUnsupportedScalar indicates scalar cannot be represented by v0 RAP scalar subtypes.
	ErrUnsupportedScalar = errors.New("unsupported scalar")
)

Functions

func DecodeToAST

func DecodeToAST(data []byte, opts DecodeOptions) (rvcfg.File, error)

DecodeToAST decodes RAP binary payload into config AST.

func DecodeToText

func DecodeToText(data []byte, decodeOpts DecodeOptions, renderOpts RenderOptions) ([]byte, error)

DecodeToText decodes RAP binary and renders canonical text.

func EncodeAST

func EncodeAST(file rvcfg.File, opts EncodeOptions) ([]byte, error)

EncodeAST encodes parsed config AST into RAP binary payload.

func RenderAST

func RenderAST(file rvcfg.File) ([]byte, error)

RenderAST renders AST into deterministic config-like text.

Types

type DecodeOptions

type DecodeOptions struct {
	// DisableFloatNormalization keeps decoded float scalars in verbose fixed form.
	// Default false normalizes to shortest round-trip float32 text.
	DisableFloatNormalization bool `json:"disable_float_normalization,omitempty" yaml:"disable_float_normalization,omitempty"`
}

DecodeOptions configures RAP binary decoder.

type EncodeOptions

type EncodeOptions struct {
	// Enums appends enum table entries after class bodies.
	Enums []EnumEntry `json:"enums,omitempty" yaml:"enums,omitempty"`
}

EncodeOptions configures RAP binary encoder.

type EnumEntry

type EnumEntry struct {
	// Name is enum symbol name.
	Name string `json:"name,omitempty" yaml:"name,omitempty"`
	// Value is signed integer payload.
	Value int32 `json:"value,omitempty" yaml:"value,omitempty"`
}

EnumEntry stores one RAP enum table item.

func DecodeToASTWithEnums

func DecodeToASTWithEnums(data []byte, opts DecodeOptions) (rvcfg.File, []EnumEntry, error)

DecodeToASTWithEnums decodes RAP payload and returns parsed enum table.

type RenderOptions

type RenderOptions struct {
	// Format configures final text normalization via rvcfg formatter.
	Format rvcfg.FormatOptions `json:"format,omitempty" yaml:"format,omitempty"`

	// EmitEnumBlock appends synthetic enum block reconstructed from RAP enum table.
	EmitEnumBlock bool `json:"emit_enum_block,omitempty" yaml:"emit_enum_block,omitempty"`
}

RenderOptions configures AST-to-text rendering bridge.

type SourceParseOptions

type SourceParseOptions struct {
	// Preprocess configures include/macro processing.
	Preprocess rvcfg.PreprocessOptions `json:"preprocess,omitempty" yaml:"preprocess,omitempty"`

	// Parse configures parser behavior for processed text.
	Parse rvcfg.ParseOptions `json:"parse,omitempty" yaml:"parse,omitempty"`
}

SourceParseOptions configures text source parse pipeline delegated to rvcfg.

func RecommendedSourceParseOptions

func RecommendedSourceParseOptions() SourceParseOptions

RecommendedSourceParseOptions returns RAP-oriented defaults for source parsing.

Defaults:

  • Parse.CaptureScalarRaw = true
  • Preprocess.EnableExecEvalIntrinsics = true

type SourceParseResult

type SourceParseResult struct {
	// Processed keeps preprocess+parse result from rvcfg.
	Processed rvcfg.ProcessAndParseResult `json:"processed,omitempty" yaml:"processed,omitempty"`
}

SourceParseResult stores source parse pipeline output.

func ParseSourceFile

func ParseSourceFile(path string, opts SourceParseOptions) (SourceParseResult, error)

ParseSourceFile runs rvcfg processed pipeline for config-like source input.

Recommended RAP-compatible options:

  • Parse.CaptureScalarRaw = true
  • Preprocess.EnableExecEvalIntrinsics = true

Recommended "full preprocess/macro" setup for game-like sources:

  • Preprocess.IncludeDirs with include roots
  • Preprocess.Defines for external symbols/flags
  • Preprocess.EnableDynamicIntrinsics = true (only if source relies on DATE/TIME/COUNTER/RAND intrinsics)

func ParseSourceFileWithDefaults

func ParseSourceFileWithDefaults(path string) (SourceParseResult, error)

ParseSourceFileWithDefaults runs ParseSourceFile with RecommendedSourceParseOptions.

Jump to

Keyboard shortcuts

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