Nested structure (Bytefield)

Nesting is where hand-drawn byte diagrams fall apart, and where Bytefield is genuinely worth the unusual syntax.


#What this example shows

  • An outer envelope containing an inner record.

  • Repeated records, drawn as a gap with a count.

  • Colour distinguishing the layers.


#A worked example

Open it, edit it, or copy the source below.

Nested structure (Bytefield)

The source, which you can paste into a new diagram and edit:

(defattrs :hdr {:fill "#e4b5f7"})
(defattrs :body {:fill "#a0fafa"})

(defn draw-group-label-header [span label]
  (draw-box (text label [:math {:font-size 12}]) {:span span :borders #{} :height 14}))

(draw-column-headers)
(draw-group-label-header 4 "Magic")
(draw-group-label-header 2 "Version")
(draw-group-label-header 2 "Type")
(draw-group-label-header 4 "Length")
(next-row 14)
(draw-box (hex-text 0xAAAAAE 4 :bold) [:hdr {:span 4}])
(draw-box (hex-text 1 2 :bold) [:hdr {:span 2}])
(draw-box (hex-text 0x0A 2 :bold) [:hdr {:span 2}])
(draw-box (hex-text 256 4 :bold) [:hdr {:span 4}])
(draw-gap "Payload" {:min-label-columns 4})
(draw-bottom)

#Making it your own

  • Colour the layers differently, or nesting is invisible.

  • Say how many times a repeated region occurs, and where that count comes from.

  • Draw one instance of a repeated record in full, then a gap for the rest.



The offsets are computed, not drawn.