Skip to content

Commit

Permalink
Support generating reference for bitmaps in schema
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Strygin <dcnick3@users.noreply.github.com>
  • Loading branch information
DCNick3 committed May 14, 2024
1 parent 45f94c4 commit 6c49324
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
16 changes: 16 additions & 0 deletions etc/schema/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ function renderSegment(segment: Segment, segmentName: string): string {
),
)
.with(null, () => segmentType('Zero-Size Type (unit type, null type)'))
.with({ Bitmap: P.select() }, ({ repr, masks }) =>
joinDouble(
// .
segmentType('Bitmap'),
segmentProp('Repr', repr),
segmentPropNameOnly('Masks'),
table(
[
{ title: 'Field name', align: 'right' },
{ title: 'Field value', align: 'left' },
],
masks.map((x) => [code(x.name), code('0x' + x.mask.toString(16))]),
{ indent: ' ' },
),
),
)
.exhaustive()

return joinDouble(heading, body)
Expand Down
13 changes: 13 additions & 0 deletions etc/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export type SchemaTypeDefinition =
| IntDefinition
| FixedPointDefinition
| TupleDef
| BitmapDef

export interface MapDefinition {
Map: {
Expand Down Expand Up @@ -77,3 +78,15 @@ export interface FixedPointDefinition {
export type TypePath = string

export type UnitType = null

export interface BitmapMask {
name: string
mask: number
}

export interface BitmapDef {
Bitmap: {
repr: string
masks: Array<BitmapMask>
}
}

0 comments on commit 6c49324

Please sign in to comment.