Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Binary file description language

License

NotificationsYou must be signed in to change notification settings

Solant/rebel

Repository files navigation

CircleCI

Rebel

(RoughlyElaborateBinaryExpressionLanguage) is a binary file description language and a compiler inspired byKaitai Struct with some new key features:

  • Support of both read and write operations
  • Separate language for data description

It produces minimal output with no external dependencies, so you can use compiled sources with no hassle against build systems (I'm looking at you, CMake)

Online demo (fully-fledged browser version)

Supported languages

Core compiler is implemented with TypeScript, however, it can generate sources for any other language.

LanguagePackage
TypeScripttarget-ts
JavaTBD
C++TBD

Any new languages implementations are welcome :^]

Installation

Rebel is split into multiple packages, so you can select how you want it to be installed:

  1. CLI version
npm i @rebel-struct/core @rebel-struct/cli
  1. Programmatic
npm i @rebel-struct/core

By defaultcore won't have any language support, so you'll also need target package for your language, for example for TypeScript

npm i @rebel-struct/target-ts
  1. Nah, I just need some sources and thats it

Compile sources withonline version and copy it to your project

File structure description

Structures

File contains several structure declarations in next format:

  • simple
struct TwoNumbers {  num1: i32;  num2: i32;}
  • and default
default struct MainStructure {  numbers: TwoNumbers;}

exactly one default structure is required for a file, as it will be used to generate publicread andwrite functions.

Fields

Structures can define several fields in next format:<fieldName>: <type>;. All fields with the exception of dependant fields will be generated in output code, for example:

default struct MainStruct {  myField: i32;}

will generate this TypeScript code:

interface MainStruct {  myField: i32;}readMainStruct(...) {  let object = .....;  object.myField = <read 32 bit value>}

Simple Types

Rebel typeC++ type
i8int8_t
i16int16_t
i32int32_t
i64int64_t
u8uint8_t
u16uint16_t
u32uint32_t
u64uint64_t

Arrays

Some binary data might require dynamic arrays support, for this case typearray is available:

default struct ArrayStruct {    length: i32 = lengthof(data);    data: array<i32>(length);}

length: i32 = lengthof(data) is computed property. It allows description of dynamic data that has dependencies on different fields.This field won't be available for direct read/write operations, but will be properly handled during serialization/deserialization.

Witharray<i32>(length) you can define array with dynamic size of fieldlength. Field will be read during deserialization, and written during serialization stage automatically.

This can also be used if binary data store size instead of length, for example:

default struct ArrayWithSizeStruct {    size: i32 = lengthof(data)*4;    data: array<i32>(size/4);}

In this waysize field will store size (in bytes) of 32-bit integer arraydata while preserving correct binary contents for serialization process.


[8]ページ先頭

©2009-2025 Movatter.jp