Skip to content

Commit

Permalink
id3v2: Decode CTOC flags
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed May 2, 2023
1 parent b1b0891 commit f237db2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 15 additions & 1 deletion format/id3/id3v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,23 @@ func decodeFrame(d *decode.D, version int) uint64 {
d.FieldU32("end_offset")
decodeFrames(d, version, uint64(d.BitsLeft()/8))
},

// <ID3v2.3 or ID3v2.4 frame header, ID: "CTOC"> (10 bytes)
// Element ID <text string> $00
// Flags %000000ab
// Entry count $xx (8-bit unsigned int)
// <Child Element ID list>
// <Optional embedded sub-frames>
//
// flag a: Top-level bit
// flag b: Ordered bit
"CTOC": func(d *decode.D) {
d.FieldStrFn("element_id", textNullFn(encodingUTF8))
d.FieldU8("ctoc_flags")
d.FieldStruct("ctoc_flags", func(d *decode.D) {
d.FieldU6("unused0")
d.FieldBool("top_level")
d.FieldBool("order")
})
entryCount := d.FieldU8("entry_count")
d.FieldArray("entries", func(d *decode.D) {
for i := uint64(0); i < entryCount; i++ {
Expand Down
5 changes: 4 additions & 1 deletion format/id3/testdata/ctoc.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ $ fq -d id3v2 dv ctoc
0x10| 00 | . | grouping_identity: false 0x13.2-0x13.2 (0.1)
0x10| 00 | . | unused1: 0 0x13.3-0x13.7 (0.5)
0x10| 54 4f 43 4d 00 | TOCM. | element_id: "TOCM" 0x14-0x18.7 (5)
0x10| 03 | . | ctoc_flags: 3 0x19-0x19.7 (1)
| | | ctoc_flags{}: 0x19-0x19.7 (1)
0x10| 03 | . | unused0: 0 0x19-0x19.5 (0.6)
0x10| 03 | . | top_level: true 0x19.6-0x19.6 (0.1)
0x10| 03 | . | order: true 0x19.7-0x19.7 (0.1)
0x10| 13 | . | entry_count: 19 0x1a-0x1a.7 (1)
| | | entries[0:19]: 0x1b-0x6f.7 (85)
0x10| 63 68 30 00 | ch0. | [0]: "ch0" entry 0x1b-0x1e.7 (4)
Expand Down

0 comments on commit f237db2

Please sign in to comment.