1
1
mirror of https://github.com/wader/fq.git synced 2024-12-23 05:13:30 +03:00

mp4,decode: Properly decode ilst items (both mdta and mdir)

Refactor mp4 decoder to be simpler and have fallback for unknown box type
Cleanup some old ilst hacks
Add generic string reader to decode API that takes an encoding parameters
This commit is contained in:
Mattias Wadman 2022-12-07 19:06:34 +01:00
parent d8560cc2c5
commit 83ccedc506
26 changed files with 1442 additions and 1254 deletions

File diff suppressed because it is too large Load Diff

View File

@ -263,5 +263,26 @@ var boxDescriptions = scalar.StrToDescription{
"xml ": "XML container",
"yrrc": "Year when media was recorded",
// from https://wiki.multimedia.cx/index.php/FFmpeg_Metadata
"©nam": "Title",
"©ART": "Author",
"aART": "Album_artist",
"©alb": "Album",
"©grp": "Grouping",
"©wrt": "Composer",
"©day": "Year",
"trkn": "Track",
"©cmt": "Comment",
"©gen": "Genre",
"©cpy": "Copyright",
"desc": "Description",
"ldes": "Synopsis",
"tvsh": "Show",
"tven": "Episode_id",
"tvnn": "Network",
"©lyr": "Lyrics",
"©too": "Encoder",
"\x00\x00\x00\x00": "Terminator Atom",
}

View File

@ -197,6 +197,11 @@ func (ctx *decodeContext) currentMoofBox() *moofBox {
return t
}
func (ctx *decodeContext) currentMetaBox() *metaBox {
t, _ := ctx.findParent("meta").(*metaBox)
return t
}
func (ctx *decodeContext) currentTrack() *track {
if t := ctx.currentTrakBox(); t != nil {
return ctx.lookupTrack(t.trackID)

View File

@ -346,7 +346,7 @@ $ fq -d mp4 dv aac.mp4
| | | boxes[0:1]: 0x578-0x59c.7 (37)
| | | [0]{}: box 0x578-0x59c.7 (37)
0x570| 00 00 00 25 | ...% | size: 37 0x578-0x57b.7 (4)
0x570| a9 74 6f 6f| .too| type: "<EFBFBD>too" 0x57c-0x57f.7 (4)
0x570| a9 74 6f 6f| .too| type: "©too" (Encoder) 0x57c-0x57f.7 (4)
| | | boxes[0:1]: 0x580-0x59c.7 (29)
| | | [0]{}: box 0x580-0x59c.7 (29)
0x580|00 00 00 1d |.... | size: 29 0x580-0x583.7 (4)

View File

@ -295,7 +295,7 @@ $ fq -d mp4 dv av1.mp4
| | | [0]{}: box 0x148d-0x14b1.7 (37)
0x1480| 00 00 00| ...| size: 37 0x148d-0x1490.7 (4)
0x1490|25 |% |
0x1490| a9 74 6f 6f | .too | type: "<EFBFBD>too" 0x1491-0x1494.7 (4)
0x1490| a9 74 6f 6f | .too | type: "©too" (Encoder) 0x1491-0x1494.7 (4)
| | | boxes[0:1]: 0x1495-0x14b1.7 (29)
| | | [0]{}: box 0x1495-0x14b1.7 (29)
0x1490| 00 00 00 1d | .... | size: 29 0x1495-0x1498.7 (4)

View File

@ -439,7 +439,7 @@ $ fq -d mp4 dv avc.mp4
| | | boxes[0:1]: 0x10bb-0x10df.7 (37)
| | | [0]{}: box 0x10bb-0x10df.7 (37)
0x010b0| 00 00 00 25 | ...% | size: 37 0x10bb-0x10be.7 (4)
0x010b0| a9| .| type: "<EFBFBD>too" 0x10bf-0x10c2.7 (4)
0x010b0| a9| .| type: "©too" (Encoder) 0x10bf-0x10c2.7 (4)
0x010c0|74 6f 6f |too |
| | | boxes[0:1]: 0x10c3-0x10df.7 (29)
| | | [0]{}: box 0x10c3-0x10df.7 (29)

View File

@ -300,7 +300,7 @@ $ fq -d mp4 dv flac.mp4
| | | [0]{}: box 0x51e-0x542.7 (37)
0x510| 00 00| ..| size: 37 0x51e-0x521.7 (4)
0x520|00 25 |.% |
0x520| a9 74 6f 6f | .too | type: "<EFBFBD>too" 0x522-0x525.7 (4)
0x520| a9 74 6f 6f | .too | type: "©too" (Encoder) 0x522-0x525.7 (4)
| | | boxes[0:1]: 0x526-0x542.7 (29)
| | | [0]{}: box 0x526-0x542.7 (29)
0x520| 00 00 00 1d | .... | size: 29 0x526-0x529.7 (4)

View File

@ -574,7 +574,7 @@ $ fq -d mp4 dv fragmented.mp4
| | | boxes[0:1]: 0x4c8-0x4ec.7 (37)
| | | [0]{}: box 0x4c8-0x4ec.7 (37)
0x004c0| 00 00 00 25 | ...% | size: 37 0x4c8-0x4cb.7 (4)
0x004c0| a9 74 6f 6f| .too| type: "<EFBFBD>too" 0x4cc-0x4cf.7 (4)
0x004c0| a9 74 6f 6f| .too| type: "©too" (Encoder) 0x4cc-0x4cf.7 (4)
| | | boxes[0:1]: 0x4d0-0x4ec.7 (29)
| | | [0]{}: box 0x4d0-0x4ec.7 (29)
0x004d0|00 00 00 1d |.... | size: 29 0x4d0-0x4d3.7 (4)

View File

@ -610,7 +610,7 @@ $ fq -d mp4 dv hevc.mp4
| | | boxes[0:1]: 0x1476-0x149a.7 (37)
| | | [0]{}: box 0x1476-0x149a.7 (37)
0x1470| 00 00 00 25 | ...% | size: 37 0x1476-0x1479.7 (4)
0x1470| a9 74 6f 6f | .too | type: "<EFBFBD>too" 0x147a-0x147d.7 (4)
0x1470| a9 74 6f 6f | .too | type: "©too" (Encoder) 0x147a-0x147d.7 (4)
| | | boxes[0:1]: 0x147e-0x149a.7 (29)
| | | [0]{}: box 0x147e-0x149a.7 (29)
0x1470| 00 00| ..| size: 29 0x147e-0x1481.7 (4)

View File

@ -274,7 +274,7 @@ $ fq dv in24.mp4
| | | boxes[0:1]: 0x3d3-0x3eb.7 (25)
| | | [0]{}: box 0x3d3-0x3eb.7 (25)
0x3d0| 00 00 00 19 | .... | size: 25 0x3d3-0x3d6.7 (4)
0x3d0| a9 73 77 72 | .swr | type: "<EFBFBD>swr" 0x3d7-0x3da.7 (4)
0x3d0| a9 73 77 72 | .swr | type: "©swr" 0x3d7-0x3da.7 (4)
0x3d0| 00 0d 55 c4 4c| ..U.L| data: raw bits 0x3db-0x3eb.7 (17)
0x3e0|61 76 66 35 38 2e 37 36 2e 31 30 30| |avf58.76.100| |
| | | tracks[0:1]: 0x3ec-NA (0)

View File

@ -264,7 +264,7 @@ $ fq dv lpcm.mp4
| | | boxes[0:1]: 0x4f9-0x511.7 (25)
| | | [0]{}: box 0x4f9-0x511.7 (25)
0x4f0| 00 00 00 19 | .... | size: 25 0x4f9-0x4fc.7 (4)
0x4f0| a9 73 77| .sw| type: "<EFBFBD>swr" 0x4fd-0x500.7 (4)
0x4f0| a9 73 77| .sw| type: "©swr" 0x4fd-0x500.7 (4)
0x500|72 |r |
0x500| 00 0d 55 c4 4c 61 76 66 35 38 2e 37 36 2e 31| ..U.Lavf58.76.1| data: raw bits 0x501-0x511.7 (17)
0x510|30 30| |00| |

BIN
format/mp4/testdata/mdir_tags.mp4 vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,51 @@
# ffmpeg -y -f lavfi -i sine -metadata title=test -t 10ms mdir_tags.mp4
$ fq 'grep_by(.type=="meta") | dv' mdir_tags.mp4
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.boxes[3].boxes[2].boxes[0]{}: box 0x4c9-0x53e.7 (118)
0x4c0| 00 00 00 76 | ...v | size: 118 0x4c9-0x4cc.7 (4)
0x4c0| 6d 65 74| met| type: "meta" (Metadata container) 0x4cd-0x4d0.7 (4)
0x4d0|61 |a |
0x4d0| 00 00 00 00 | .... | maybe_flags: 0 0x4d1-0x4d4.7 (4)
| | | boxes[0:2]: 0x4d5-0x53e.7 (106)
| | | [0]{}: box 0x4d5-0x4f5.7 (33)
0x4d0| 00 00 00 21 | ...! | size: 33 0x4d5-0x4d8.7 (4)
0x4d0| 68 64 6c 72 | hdlr | type: "hdlr" (Handler, declares the media (handler) type) 0x4d9-0x4dc.7 (4)
0x4d0| 00 | . | version: 0 0x4dd-0x4dd.7 (1)
0x4d0| 00 00| ..| flags: 0 0x4de-0x4e0.7 (3)
0x4e0|00 |. |
0x4e0| 00 00 00 00 | .... | component_type: "" 0x4e1-0x4e4.7 (4)
0x4e0| 6d 64 69 72 | mdir | component_subtype: "mdir" (Metadata) 0x4e5-0x4e8.7 (4)
0x4e0| 61 70 70 6c | appl | component_manufacturer: "appl" 0x4e9-0x4ec.7 (4)
0x4e0| 00 00 00| ...| component_flags: 0 0x4ed-0x4f0.7 (4)
0x4f0|00 |. |
0x4f0| 00 00 00 00 | .... | component_flags_mask: 0 0x4f1-0x4f4.7 (4)
0x4f0| 00 | . | component_name: "" 0x4f5-0x4f5.7 (1)
| | | [1]{}: box 0x4f6-0x53e.7 (73)
0x4f0| 00 00 00 49 | ...I | size: 73 0x4f6-0x4f9.7 (4)
0x4f0| 69 6c 73 74 | ilst | type: "ilst" 0x4fa-0x4fd.7 (4)
| | | boxes[0:2]: 0x4fe-0x53e.7 (65)
| | | [0]{}: box 0x4fe-0x519.7 (28)
0x4f0| 00 00| ..| size: 28 0x4fe-0x501.7 (4)
0x500|00 1c |.. |
0x500| a9 6e 61 6d | .nam | type: "©nam" (Title) 0x502-0x505.7 (4)
| | | boxes[0:1]: 0x506-0x519.7 (20)
| | | [0]{}: box 0x506-0x519.7 (20)
0x500| 00 00 00 14 | .... | size: 20 0x506-0x509.7 (4)
0x500| 64 61 74 61 | data | type: "data" 0x50a-0x50d.7 (4)
0x500| 00 | . | version: 0 0x50e-0x50e.7 (1)
0x500| 00| .| flags: 1 0x50f-0x511.7 (3)
0x510|00 01 |.. |
0x510| 00 00 00 00 | .... | reserved: 0 0x512-0x515.7 (4)
0x510| 74 65 73 74 | test | data: "test" 0x516-0x519.7 (4)
| | | [1]{}: box 0x51a-0x53e.7 (37)
0x510| 00 00 00 25 | ...% | size: 37 0x51a-0x51d.7 (4)
0x510| a9 74| .t| type: "©too" (Encoder) 0x51e-0x521.7 (4)
0x520|6f 6f |oo |
| | | boxes[0:1]: 0x522-0x53e.7 (29)
| | | [0]{}: box 0x522-0x53e.7 (29)
0x520| 00 00 00 1d | .... | size: 29 0x522-0x525.7 (4)
0x520| 64 61 74 61 | data | type: "data" 0x526-0x529.7 (4)
0x520| 00 | . | version: 0 0x52a-0x52a.7 (1)
0x520| 00 00 01 | ... | flags: 1 0x52b-0x52d.7 (3)
0x520| 00 00| ..| reserved: 0 0x52e-0x531.7 (4)
0x530|00 00 |.. |
0x530| 4c 61 76 66 35 39 2e 32 37 2e 31 30 30| | Lavf59.27.100|| data: "Lavf59.27.100" 0x532-0x53e.7 (13)

BIN
format/mp4/testdata/mdta_tags.mp4 vendored Normal file

Binary file not shown.

View File

@ -0,0 +1,69 @@
# ffmpeg -y -f lavfi -i sine -movflags use_metadata_tags -metadata title=test -t 10ms mdta_tags.mp4
$ fq 'grep_by(.type=="meta") | dv' mdta_tags.mp4
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.boxes[3].boxes[2].boxes[0]{}: box 0x4c9-0x56a.7 (162)
0x4c0| 00 00 00 a2 | .... | size: 162 0x4c9-0x4cc.7 (4)
0x4c0| 6d 65 74| met| type: "meta" (Metadata container) 0x4cd-0x4d0.7 (4)
0x4d0|61 |a |
0x4d0| 00 00 00 00 | .... | maybe_flags: 0 0x4d1-0x4d4.7 (4)
| | | boxes[0:3]: 0x4d5-0x56a.7 (150)
| | | [0]{}: box 0x4d5-0x4f5.7 (33)
0x4d0| 00 00 00 21 | ...! | size: 33 0x4d5-0x4d8.7 (4)
0x4d0| 68 64 6c 72 | hdlr | type: "hdlr" (Handler, declares the media (handler) type) 0x4d9-0x4dc.7 (4)
0x4d0| 00 | . | version: 0 0x4dd-0x4dd.7 (1)
0x4d0| 00 00| ..| flags: 0 0x4de-0x4e0.7 (3)
0x4e0|00 |. |
0x4e0| 00 00 00 00 | .... | component_type: "" 0x4e1-0x4e4.7 (4)
0x4e0| 6d 64 74 61 | mdta | component_subtype: "mdta" (Metadata Tags) 0x4e5-0x4e8.7 (4)
0x4e0| 00 00 00 00 | .... | component_manufacturer: "" 0x4e9-0x4ec.7 (4)
0x4e0| 00 00 00| ...| component_flags: 0 0x4ed-0x4f0.7 (4)
0x4f0|00 |. |
0x4f0| 00 00 00 00 | .... | component_flags_mask: 0 0x4f1-0x4f4.7 (4)
0x4f0| 00 | . | component_name: "" 0x4f5-0x4f5.7 (1)
| | | [1]{}: box 0x4f6-0x521.7 (44)
0x4f0| 00 00 00 2c | ..., | size: 44 0x4f6-0x4f9.7 (4)
0x4f0| 6b 65 79 73 | keys | type: "keys" 0x4fa-0x4fd.7 (4)
0x4f0| 00 | . | version: 0 0x4fe-0x4fe.7 (1)
0x4f0| 00| .| flags: 0 0x4ff-0x501.7 (3)
0x500|00 00 |.. |
0x500| 00 00 00 02 | .... | entry_count: 2 0x502-0x505.7 (4)
| | | entries[0:2]: 0x506-0x521.7 (28)
| | | [0]{}: entry 0x506-0x512.7 (13)
0x500| 00 00 00 0d | .... | key_size: 13 0x506-0x509.7 (4)
0x500| 6d 64 74 61 | mdta | key_namespace: "mdta" 0x50a-0x50d.7 (4)
0x500| 74 69| ti| key_name: "title" 0x50e-0x512.7 (5)
0x510|74 6c 65 |tle |
| | | [1]{}: entry 0x513-0x521.7 (15)
0x510| 00 00 00 0f | .... | key_size: 15 0x513-0x516.7 (4)
0x510| 6d 64 74 61 | mdta | key_namespace: "mdta" 0x517-0x51a.7 (4)
0x510| 65 6e 63 6f 64| encod| key_name: "encoder" 0x51b-0x521.7 (7)
0x520|65 72 |er |
| | | [2]{}: box 0x522-0x56a.7 (73)
0x520| 00 00 00 49 | ...I | size: 73 0x522-0x525.7 (4)
0x520| 69 6c 73 74 | ilst | type: "ilst" 0x526-0x529.7 (4)
| | | boxes[0:2]: 0x52a-0x56a.7 (65)
| | | [0]{}: box 0x52a-0x545.7 (28)
0x520| 00 00 00 1c | .... | size: 28 0x52a-0x52d.7 (4)
0x520| 00 00| ..| type: "title" ("\x00\x00\x00\x01") 0x52e-0x531.7 (4)
0x530|00 01 |.. |
| | | boxes[0:1]: 0x532-0x545.7 (20)
| | | [0]{}: box 0x532-0x545.7 (20)
0x530| 00 00 00 14 | .... | size: 20 0x532-0x535.7 (4)
0x530| 64 61 74 61 | data | type: "data" 0x536-0x539.7 (4)
0x530| 00 | . | version: 0 0x53a-0x53a.7 (1)
0x530| 00 00 01 | ... | flags: 1 0x53b-0x53d.7 (3)
0x530| 00 00| ..| reserved: 0 0x53e-0x541.7 (4)
0x540|00 00 |.. |
0x540| 74 65 73 74 | test | data: "test" 0x542-0x545.7 (4)
| | | [1]{}: box 0x546-0x56a.7 (37)
0x540| 00 00 00 25 | ...% | size: 37 0x546-0x549.7 (4)
0x540| 00 00 00 02 | .... | type: "encoder" ("\x00\x00\x00\x02") 0x54a-0x54d.7 (4)
| | | boxes[0:1]: 0x54e-0x56a.7 (29)
| | | [0]{}: box 0x54e-0x56a.7 (29)
0x540| 00 00| ..| size: 29 0x54e-0x551.7 (4)
0x550|00 1d |.. |
0x550| 64 61 74 61 | data | type: "data" 0x552-0x555.7 (4)
0x550| 00 | . | version: 0 0x556-0x556.7 (1)
0x550| 00 00 01 | ... | flags: 1 0x557-0x559.7 (3)
0x550| 00 00 00 00 | .... | reserved: 0 0x55a-0x55d.7 (4)
0x550| 4c 61| La| data: "Lavf59.27.100" 0x55e-0x56a.7 (13)
0x560|76 66 35 39 2e 32 37 2e 31 30 30| |vf59.27.100| |

View File

@ -312,7 +312,7 @@ $ fq -d mp4 dv mp3.mp4
| | | boxes[0:1]: 0x540-0x564.7 (37)
| | | [0]{}: box 0x540-0x564.7 (37)
0x540|00 00 00 25 |...% | size: 37 0x540-0x543.7 (4)
0x540| a9 74 6f 6f | .too | type: "<EFBFBD>too" 0x544-0x547.7 (4)
0x540| a9 74 6f 6f | .too | type: "©too" (Encoder) 0x544-0x547.7 (4)
| | | boxes[0:1]: 0x548-0x564.7 (29)
| | | [0]{}: box 0x548-0x564.7 (29)
0x540| 00 00 00 1d | .... | size: 29 0x548-0x54b.7 (4)

View File

@ -326,7 +326,7 @@ $ fq -d mp4 dv mpeg2.mp4
| | | boxes[0:1]: 0x2284-0x22a8.7 (37)
| | | [0]{}: box 0x2284-0x22a8.7 (37)
0x2280| 00 00 00 25 | ...% | size: 37 0x2284-0x2287.7 (4)
0x2280| a9 74 6f 6f | .too | type: "<EFBFBD>too" 0x2288-0x228b.7 (4)
0x2280| a9 74 6f 6f | .too | type: "©too" (Encoder) 0x2288-0x228b.7 (4)
| | | boxes[0:1]: 0x228c-0x22a8.7 (29)
| | | [0]{}: box 0x228c-0x22a8.7 (29)
0x2280| 00 00 00 1d| ....| size: 29 0x228c-0x228f.7 (4)

View File

@ -291,7 +291,7 @@ $ fq -d mp4 dv opus.mp4
| | | boxes[0:1]: 0x414-0x438.7 (37)
| | | [0]{}: box 0x414-0x438.7 (37)
0x410| 00 00 00 25 | ...% | size: 37 0x414-0x417.7 (4)
0x410| a9 74 6f 6f | .too | type: "<EFBFBD>too" 0x418-0x41b.7 (4)
0x410| a9 74 6f 6f | .too | type: "©too" (Encoder) 0x418-0x41b.7 (4)
| | | boxes[0:1]: 0x41c-0x438.7 (29)
| | | [0]{}: box 0x41c-0x438.7 (29)
0x410| 00 00 00 1d| ....| size: 29 0x41c-0x41f.7 (4)

View File

@ -335,7 +335,7 @@ $ fq dv png.mp4
| | | boxes[0:1]: 0x37b-0x39f.7 (37)
| | | [0]{}: box 0x37b-0x39f.7 (37)
0x370| 00 00 00 25 | ...% | size: 37 0x37b-0x37e.7 (4)
0x370| a9| .| type: "<EFBFBD>too" 0x37f-0x382.7 (4)
0x370| a9| .| type: "©too" (Encoder) 0x37f-0x382.7 (4)
0x380|74 6f 6f |too |
| | | boxes[0:1]: 0x383-0x39f.7 (29)
| | | [0]{}: box 0x383-0x39f.7 (29)

View File

@ -281,7 +281,7 @@ $ fq dv png_no_hdlr.mp4
| | | boxes[0:1]: 0x2e9-0x30d.7 (37)
| | | [0]{}: box 0x2e9-0x30d.7 (37)
0x2e0| 00 00 00 25 | ...% | size: 37 0x2e9-0x2ec.7 (4)
0x2e0| a9 74 6f| .to| type: "<EFBFBD>too" 0x2ed-0x2f0.7 (4)
0x2e0| a9 74 6f| .to| type: "©too" (Encoder) 0x2ed-0x2f0.7 (4)
0x2f0|6f |o |
| | | boxes[0:1]: 0x2f1-0x30d.7 (29)
| | | [0]{}: box 0x2f1-0x30d.7 (29)

View File

@ -354,7 +354,7 @@ $ fq -d mp4 dv vorbis.mp4
| | | boxes[0:1]: 0x1164-0x1188.7 (37)
| | | [0]{}: box 0x1164-0x1188.7 (37)
0x1160| 00 00 00 25 | ...% | size: 37 0x1164-0x1167.7 (4)
0x1160| a9 74 6f 6f | .too | type: "<EFBFBD>too" 0x1168-0x116b.7 (4)
0x1160| a9 74 6f 6f | .too | type: "©too" (Encoder) 0x1168-0x116b.7 (4)
| | | boxes[0:1]: 0x116c-0x1188.7 (29)
| | | [0]{}: box 0x116c-0x1188.7 (29)
0x1160| 00 00 00 1d| ....| size: 29 0x116c-0x116f.7 (4)

View File

@ -298,7 +298,7 @@ $ fq -d mp4 dv vp9.mp4
| | | boxes[0:1]: 0x182a-0x184e.7 (37)
| | | [0]{}: box 0x182a-0x184e.7 (37)
0x1820| 00 00 00 25 | ...% | size: 37 0x182a-0x182d.7 (4)
0x1820| a9 74| .t| type: "<EFBFBD>too" 0x182e-0x1831.7 (4)
0x1820| a9 74| .t| type: "©too" (Encoder) 0x182e-0x1831.7 (4)
0x1830|6f 6f |oo |
| | | boxes[0:1]: 0x1832-0x184e.7 (29)
| | | [0]{}: box 0x1832-0x184e.7 (29)

View File

@ -289,7 +289,7 @@ $ fq -d mp4 dv prores_frame.mov
| | | boxes[0:1]: 0x6ee6-0x6efe.7 (25)
| | | [0]{}: box 0x6ee6-0x6efe.7 (25)
0x6ee0| 00 00 00 19 | .... | size: 25 0x6ee6-0x6ee9.7 (4)
0x6ee0| a9 73 77 72 | .swr | type: "<EFBFBD>swr" 0x6eea-0x6eed.7 (4)
0x6ee0| a9 73 77 72 | .swr | type: "©swr" 0x6eea-0x6eed.7 (4)
0x6ee0| 00 0d| ..| data: raw bits 0x6eee-0x6efe.7 (17)
0x6ef0|55 c4 4c 61 76 66 35 39 2e 31 36 2e 31 30 30| |U.Lavf59.16.100||
| | | tracks[0:1]: 0x24-0x6efe.7 (28379)

View File

@ -7,6 +7,7 @@ import (
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/scalar"
"golang.org/x/text/encoding"
)
// Type BigInt
@ -19860,3 +19861,50 @@ func (d *D) TryFieldUTF8NullFixedLen(name string, fixedBytes int, sms ...scalar.
func (d *D) FieldUTF8NullFixedLen(name string, fixedBytes int, sms ...scalar.Mapper) string {
return d.FieldScalarUTF8NullFixedLen(name, fixedBytes, sms...).ActualStr()
}
// Reader Str
// TryStr tries to read nBytes bytes using encoding e
func (d *D) TryStr(nBytes int, e encoding.Encoding) (string, error) { return d.tryText(nBytes, e) }
// Str reads nBytes bytes using encoding e
func (d *D) Str(nBytes int, e encoding.Encoding) string {
v, err := d.tryText(nBytes, e)
if err != nil {
panic(IOError{Err: err, Op: "Str", Pos: d.Pos()})
}
return v
}
// TryFieldScalarStr tries to add a field and read nBytes bytes using encoding e
func (d *D) TryFieldScalarStr(name string, nBytes int, e encoding.Encoding, sms ...scalar.Mapper) (*scalar.S, error) {
s, err := d.TryFieldScalarFn(name, func(s scalar.S) (scalar.S, error) {
v, err := d.tryText(nBytes, e)
s.Actual = v
return s, err
}, sms...)
if err != nil {
return nil, err
}
return s, err
}
// FieldScalarStr adds a field and reads nBytes bytes using encoding e
func (d *D) FieldScalarStr(name string, nBytes int, e encoding.Encoding, sms ...scalar.Mapper) *scalar.S {
s, err := d.TryFieldScalarStr(name, nBytes, e, sms...)
if err != nil {
panic(IOError{Err: err, Name: name, Op: "Str", Pos: d.Pos()})
}
return s
}
// TryFieldStr tries to add a field and read nBytes bytes using encoding e
func (d *D) TryFieldStr(name string, nBytes int, e encoding.Encoding, sms ...scalar.Mapper) (string, error) {
s, err := d.TryFieldScalarStr(name, nBytes, e, sms...)
return s.ActualStr(), err
}
// FieldStr adds a field and reads nBytes bytes using encoding e
func (d *D) FieldStr(name string, nBytes int, e encoding.Encoding, sms ...scalar.Mapper) string {
return d.FieldScalarStr(name, nBytes, e, sms...).ActualStr()
}

View File

@ -7,6 +7,7 @@ import (
"github.com/wader/fq/pkg/bitio"
"github.com/wader/fq/pkg/scalar"
"golang.org/x/text/encoding"
)
{{- range $name, $t := $.types }}

View File

@ -234,6 +234,13 @@
"doc": "fixedBytes bytes long null terminated UTF8 string"
}
]
},
{
"name": "Str",
"type": "Str",
"variants": [
{"name": "", "args": "nBytes, e", "params": "nBytes int, e encoding.Encoding", "call": "d.tryText(nBytes, e)", "doc": "nBytes bytes using encoding e"}
]
}
]
}