Skip to content

Suggestion: Give students Kaitai Struct grammar for viewing binary page data as structured object trees #263

Open
@GavinRay97

Description

@GavinRay97

This is really useful for debugging, especially when you're trying to implement serialization/deserialization logic.

Kaitai Struct is a tool that allows you to write declarative grammars for binary formats.
One of the tools it provides is a hex-based visualizer available in browser:

I wrote a grammar for the page format based on the description in the doc comments.
You can try it by visiting the ide.kaitai.io link, pasting the below definition, and uploading a page file to the hex editor.

Hope other folks find this as useful as I have =)

msedge_DdHUpeoIFI.mp4
meta:
  id: bustub_page
  file-extension: db
  endian: le

seq:
  - id: header
    type: page_header
    
  - id: slots
    type: tuple_slot
    repeat: expr
    repeat-expr: 'header.tuple_count'
    
  - id: padding
    type: u2
    repeat: until
    repeat-until: _ != 0
    
  - id: tuples
    type: tuple
    repeat: eos
    
types:
  page_header:
    seq:
      - id: page_id
        type: u4
        
      - id: log_storage_number
        type: u4
        
      - id: previous_page_id
        type: u4
        
      - id: next_page_id
        type: u4
        
      - id: free_space_pointer
        type: u4
        
      - id: tuple_count
        type: u4
        
  tuple_slot:
    seq:
      - id: offset
        type: u4
        
      - id: size
        type: u4
        
  tuple:
    seq:
      - id: len
        type: u4
        
      - id: data
        size: len

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions