# Library for declaratively parsing and serializing binary data
trait Schema {
# Description of binary data layout
}
class _Primitive(Schema) {
# Primitive <-> (Int, Float, ...)
[_name]
}
class Struct(Schema) {
# Struct <-> Record
# field_map:
# maps field names (symbols) to Schemas associated
# with each field.
# field_map is a Map (and not Table) to ensure
# fields are ordered
[_field_map]
}
class Array(Schema) {
# Array <-> List
# Arrays map to the native List type
# rather than a separate dedicated Data subclass
[_schema, _n]
}
class Enum(Schema) {
# Enum <-> Variant
# choice_map:
# maps choices (symbols) to Schemas associated
# with the choice
[_choice_map]
}
trait Data {
# Data that is dual with a Schema
}
class Record(Data) {
# Dat amatching a Struct
[_field_map]
}
class Variant(Data) {
# Data matching an Enum
[_choice, _data]
}