Binary Markup Language (BML) is a XML scheme for describing structured binary data. The library contains a protocol parser, a binary data parser, as well as a c header emitter.
In its current iteration, BML is simply an Odin package. It does not currently support an FFI friendly interface.
import "bml/protocol"
...
foo :: proc()
{
prot, prot_ok := protocol.parse("foo.xml")
}
import "bml/protocol"
import "bml/parser"
...
foo :: proc()
{
// Either of these three are possible
// 1. parse from protocol and file path
prot, prot_ok := protocol.parse("foo.xml")
content, content_ok := parser.parse_from_protocol(&prot, "foo.bin")
// 2. parse from scheme and file path
content, content_ok := parser.parse_from_file("foo.xml", "foo.bin")
// 3. parse from protocol and binary data
prot, prot_ok := protocol.parse("foo.xml")
data := os.read_entire_file_from_filename("foo.bin")
content, content_ok := parser.parse_data(&prot, data)
}
import "bml/protocol"
import "bml/emitter"
...
foo :: proc()
{
prot, prot_ok := protocol.parse("foo.xml")
c_header := emitter.emit_c(&prot)
}
The overall structure of a BML protocol consists of a series of custom types, a series of IDs and a packet definition. The packet definition describes the actual payload.
For examples, look in the demos folder.
The packet definition consists of a marker, a header as well as a body.
marker
- [required] type: BaseType
- [optional] length: int
- [optional] size: int
Comma-separated list of values. May be provided in different bases using the following prefixes:
- Hexadecimal: 0x
- Binary: 0b
- Octal: 0o
header
None
List of fields in header
body
None
List of fields in body
Type | Size |
---|---|
u8 | 1 |
i8 | 1 |
u16 | 2 |
i16 | 2 |
u32 | 4 |
i32 | 4 |
u64 | 8 |
i64 | 8 |
f16 | 2 |
f32 | 4 |
f64 | 8 |
IDs correlate an integer value to set of fields. A field can be dependant on another field, the type of which should be an ID.
id
- [required] name: string
- [required] type: BaseType
List of entries
Custom Types come in two flavors: type aliases and field lists.
type
- [required] name: string
- [optional] type: BaseType
List of fields
entry
- [required] name: string
- [required] value: int
field
- [required] name: string
- [optional] type: BaseType | CustomType | ID
- [optional] dependsOn: Name of Field
- [optional] size: int
- [optional] length: int