From 4f6333a4ec41846e397cb722b118651ab64694b1 Mon Sep 17 00:00:00 2001 From: Nikita Strygin Date: Tue, 14 May 2024 16:41:54 +0300 Subject: [PATCH] Support generating reference for bitmaps in schema --- etc/schema/render.ts | 16 ++++++++++++++++ etc/schema/types.ts | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/etc/schema/render.ts b/etc/schema/render.ts index fb63a7a8b..8cfb43d8c 100644 --- a/etc/schema/render.ts +++ b/etc/schema/render.ts @@ -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) diff --git a/etc/schema/types.ts b/etc/schema/types.ts index 8d8b5813f..583a4ddbe 100644 --- a/etc/schema/types.ts +++ b/etc/schema/types.ts @@ -17,6 +17,7 @@ export type SchemaTypeDefinition = | IntDefinition | FixedPointDefinition | TupleDef + | BitmapDef export interface MapDefinition { Map: { @@ -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 + } +}