diff --git a/Cargo.toml b/Cargo.toml index 97a46133..47a6670d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,11 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[[test]] +name = "generated" +path = "sample_codegen.rs" +bench = false + [dev-dependencies] proptest = "1.1.0" diff --git a/sample_codegen.rs b/sample_codegen.rs index 20800514..c3cf4b06 100644 --- a/sample_codegen.rs +++ b/sample_codegen.rs @@ -1,3372 +1,6767 @@ use doodle::prelude::*; -struct Type100 { -codes: Vec, -codes_values: Vec +struct Type0 { + signature: (u8, u8, u8), + version: Vec, } -struct Type103 { -separator: u8, -label: u8, -block_size: u8, -identifier: Vec, -authentication_code: Vec, -application_data: Vec, -terminator: u8 +struct Type1 { + screen_width: u16, + screen_height: u16, + flags: u8, + bg_color_index: u8, + pixel_aspect_ratio: u8, } -struct Type104 { -separator: u8, -label: u8, -comment_data: Vec, -terminator: u8 +struct Type2 { + r: u8, + g: u8, + b: u8, } -struct Type107 { -separator: u8, -label: u8, -block_size: u8, -text_grid_left_position: u16, -text_grid_top_position: u16, -text_grid_width: u16, -text_grid_height: u16, -character_cell_width: u8, -character_cell_height: u8, -text_foreground_color_index: u8, -text_background_color_index: u8, -plain_text_data: Vec, -terminator: u8 +enum Type3 { + no, + yes(Vec), } -struct Type84 { -length: u32, -tag: (u8, u8, u8, u8), -data: Vec, -crc: u32 +struct Type4 { + descriptor: Type1, + global_color_table: Type3, } -struct Type2 { -r: u8, -g: u8, -b: u8 +struct Type5 { + len_bytes: u8, + data: Vec, } -enum Type22 { literal(u8) } - struct Type6 { -separator: u8, -image_left_position: u16, -image_top_position: u16, -image_width: u16, -image_height: u16, -flags: u8 + separator: u8, + label: u8, + comment_data: Vec, + terminator: u8, } -struct Type41 { -class_table_id: u8, -value: u8 +struct Type7 { + separator: u8, + label: u8, + block_size: u8, + identifier: Vec, + authentication_code: Vec, + application_data: Vec, + terminator: u8, +} + +enum Type8 { + comment_extension(Type6), + application_extension(Type7), +} + +struct Type9 { + separator: u8, + label: u8, + block_size: u8, + flags: u8, + delay_time: u16, + transparent_color_index: u8, + terminator: u8, +} + +enum Type10 { + none, + some(Type9), +} + +struct Type11 { + separator: u8, + label: u8, + block_size: u8, + text_grid_left_position: u16, + text_grid_top_position: u16, + text_grid_width: u16, + text_grid_height: u16, + character_cell_width: u8, + character_cell_height: u8, + text_foreground_color_index: u8, + text_background_color_index: u8, + plain_text_data: Vec, + terminator: u8, } -struct Type61 { -palette_index: u8 -} - -enum Type23 { dynamic_huffman { -hlit: u8, -hdist: u8, -hclen: u8, -code_length_alphabet_code_lengths: Vec, -literal_length_distance_alphabet_code_lengths: Vec, -literal_length_distance_alphabet_code_lengths_value: Vec, -literal_length_alphabet_code_lengths_value: Vec, -distance_alphabet_code_lengths_value: Vec, -codes: Vec, -codes_values: Vec -}, fixed_huffman { -codes: Vec, -codes_values: Vec -}, uncompressed { -align: (), -len: u16, -nlen: u16, -bytes: Vec, -codes_values: Vec -} } - -enum Type63 { bKGD { -length: u32, -tag: (u8, u8, u8, u8), -data: Type58, -crc: u32 -}, pHYs { -length: u32, -tag: (u8, u8, u8, u8), -data: Type59, -crc: u32 -}, PLTE { -length: u32, -tag: (u8, u8, u8, u8), -data: Vec, -crc: u32 -}, tIME { -length: u32, -tag: (u8, u8, u8, u8), -data: Type60, -crc: u32 -}, tRNS { -length: u32, -tag: (u8, u8, u8, u8), -data: Type62, -crc: u32 -} } +struct Type12 { + separator: u8, + image_left_position: u16, + image_top_position: u16, + image_width: u16, + image_height: u16, + flags: u8, +} -struct Type85 { -length: u32, -tag: (u8, u8, u8, u8), -data: Type60, -crc: u32 +struct Type13 { + lzw_min_code_size: u8, + image_data: Vec, + terminator: u8, } -struct Type93 { -marker: Type28, -length: u16, -data: Type41 +struct Type14 { + descriptor: Type12, + local_color_table: Type3, + data: Type13, } -struct Type26 { -crc: u32, -length: u32 +enum Type15 { + plain_text_extension(Type11), + table_based_image(Type14), } -struct Type92 { -marker: Type28, -length: u16, -data: Type40 +struct Type16 { + graphic_control_extension: Type10, + graphic_rendering_block: Type15, } -struct Type29 { -string: Vec, -null: u8 +enum Type17 { + special_purpose_block(Type8), + graphic_block(Type16), } -struct Type69 { -string: Vec, -__padding: Vec +struct Type18 { + separator: u8, +} + +struct Type19 { + header: Type0, + logical_screen: Type4, + blocks: Vec, + trailer: Type18, +} + +struct Type20 { + magic: (u8, u8), + method: u8, + file_flags: u8, + timestamp: u32, + compression_flags: u8, + os_id: u8, +} + +struct Type21 { + string: Vec, + null: u8, +} + +enum Type22 { + no, + yes(Type21), +} + +struct Type23 { + code: u16, + extra: u8, } struct Type24 { -r#final: u8, -r#type: u8, -data: Type23 + distance_extra_bits: u16, + distance: u16, } -struct Type34 { -num_fields: u16, -fields: Vec, -next_ifd_offset: u32, -next_ifd: Vec +struct Type25 { + length_extra_bits: u8, + length: u16, + distance_code: u16, + distance_record: Type24, } -struct Type95 { -marker: Type28, -length: u16, -data: Vec +enum Type26 { + none, + some(Type25), } -enum Type5 { some { -separator: u8, -label: u8, -block_size: u8, -flags: u8, -delay_time: u16, -transparent_color_index: u8, -terminator: u8 -}, none() } +struct Type27 { + code: u16, + extra: Type26, +} -struct Type99 { -align: (), -len: u16, -nlen: u16, -bytes: Vec, -codes_values: Vec +struct Type28 { + length: u16, + distance: u16, } -struct Type101 { -hlit: u8, -hdist: u8, -hclen: u8, -code_length_alphabet_code_lengths: Vec, -literal_length_distance_alphabet_code_lengths: Vec, -literal_length_distance_alphabet_code_lengths_value: Vec, -literal_length_alphabet_code_lengths_value: Vec, -distance_alphabet_code_lengths_value: Vec, -codes: Vec, -codes_values: Vec +enum Type29 { + literal(u8), + reference(Type28), } -struct Type13 { -magic: (u8, u8), -method: u8, -file_flags: u8, -timestamp: u32, -compression_flags: u8, -os_id: u8 -} - -struct Type37 { -identifier: Type29, -data: Type36 -} - -enum Type43 { dqt { -marker: Type28, -length: u16, -data: Type39 -}, dht { -marker: Type28, -length: u16, -data: Type40 -}, dac { -marker: Type28, -length: u16, -data: Type41 -}, dri { -marker: Type28, -length: u16, -data: Type42 -}, app0 { -marker: Type28, -length: u16, -data: Type31 -}, app1 { -marker: Type28, -length: u16, -data: Type37 -}, app2 { -marker: Type28, -length: u16, -data: Vec -}, app3 { -marker: Type28, -length: u16, -data: Vec -}, app4 { -marker: Type28, -length: u16, -data: Vec -}, app5 { -marker: Type28, -length: u16, -data: Vec -}, app6 { -marker: Type28, -length: u16, -data: Vec -}, app7 { -marker: Type28, -length: u16, -data: Vec -}, app8 { -marker: Type28, -length: u16, -data: Vec -}, app9 { -marker: Type28, -length: u16, -data: Vec -}, app10 { -marker: Type28, -length: u16, -data: Vec -}, app11 { -marker: Type28, -length: u16, -data: Vec -}, app12 { -marker: Type28, -length: u16, -data: Vec -}, app13 { -marker: Type28, -length: u16, -data: Vec -}, app14 { -marker: Type28, -length: u16, -data: Vec -}, app15 { -marker: Type28, -length: u16, -data: Vec -}, com { -marker: Type28, -length: u16, -data: Vec -} } - -enum Type20 { none(), some { -length_extra_bits: u8, -length: u16, -distance_code: u8, -distance_record: Type16 -} } - -enum Type62 { color_type_(Vec), color_type_ { -red: u16, -green: u16, -blue: u16 -}, color_type_ { -greyscale: u16 -} } +struct Type30 { + hlit: u8, + hdist: u8, + hclen: u8, + code_length_alphabet_code_lengths: Vec, + literal_length_distance_alphabet_code_lengths: Vec, + literal_length_distance_alphabet_code_lengths_value: Vec, + literal_length_alphabet_code_lengths_value: Vec, + distance_alphabet_code_lengths_value: Vec, + codes: Vec, + codes_values: Vec, +} -struct Type78 { -soi: Type28, -frame: Type55, -eoi: Type28 +struct Type31 { + length_extra_bits: u8, + length: u16, + distance_code: u8, + distance_record: Type24, } -struct Type86 { -length: u32, -tag: (u8, u8, u8, u8), -data: Type62, -crc: u32 +enum Type32 { + none, + some(Type31), } struct Type33 { -tag: u16, -r#type: u16, -length: u32, -offset_or_data: u32 -} - -enum Type38 { app0 { -marker: Type28, -length: u16, -data: Type31 -}, app1 { -marker: Type28, -length: u16, -data: Type37 -} } + code: u16, + extra: Type32, +} -struct Type45 { -sample_precision: u8, -num_lines: u16, -num_samples_per_line: u16, -num_image_components: u8, -image_components: Vec +struct Type34 { + codes: Vec, + codes_values: Vec, +} + +enum Type35 { + literal(u8), +} + +struct Type36 { + align: (), + len: u16, + nlen: u16, + bytes: Vec, + codes_values: Vec, +} + +enum Type37 { + dynamic_huffman(Type30), + fixed_huffman(Type34), + uncompressed(Type36), +} + +struct Type38 { + r#final: u8, + r#type: u8, + data: Type37, } struct Type39 { -precision_table_id: u8, -elements: Vec + blocks: Vec, + codes: Vec, + inflate: Vec, } -struct Type51 { -scan_data: Vec, -scan_data_stream: Vec +struct Type40 { + crc: u32, + length: u32, } -enum Type36 { other(Vec), xmp { -xmp: Vec -}, exif { -padding: u8, -exif: Type35 -} } +struct Type41 { + header: Type20, + fname: Type22, + data: Type39, + footer: Type40, +} -struct Type55 { -initial_segment: Type38, -segments: Vec, -header: Type46, -scan: Type52, -dnl: Type54, -scans: Vec +struct Type42 { + ff: u8, + marker: u8, } -struct Type67 { -tag: (u8, u8, u8, u8), -length: u32, -data: Vec, -pad: Type66 +struct Type43 { + xmp: Vec, } -struct Type91 { -marker: Type28, -length: u16, -data: Type39 +enum Type44 { + be(u8, u8), + le(u8, u8), } -enum Type74 { ascii(Vec), utf8(Vec) } +struct Type45 { + tag: u16, + r#type: u16, + length: u32, + offset_or_data: u32, +} -struct Type80 { -tag: (u8, u8, u8, u8), -length: u32, -data: Type68, -pad: Type66 +struct Type46 { + num_fields: u16, + fields: Vec, + next_ifd_offset: u32, + next_ifd: Vec, +} + +struct Type47 { + byte_order: Type44, + magic: u16, + offset: u32, + ifd: Type46, +} + +struct Type48 { + padding: u8, + exif: Type47, +} + +enum Type49 { + other(Vec), + xmp(Type43), + exif(Type48), +} + +struct Type50 { + identifier: Type21, + data: Type49, } -struct Type44 { -id: u8, -sampling_factor: u8, -quantization_table_id: u8 +struct Type51 { + marker: Type42, + length: u16, + data: Type50, } struct Type52 { -segments: Vec, -sos: Type49, -data: Type51 + version_major: u8, + version_minor: u8, + density_units: u8, + density_x: u16, + density_y: u16, + thumbnail_width: u8, + thumbnail_height: u8, + thumbnail_pixels: Vec>, } -struct Type12 { -separator: u8 +enum Type53 { + other(Vec), + jfif(Type52), } -enum Type17 { none(), some { -length_extra_bits: u8, -length: u16, -distance_code: u16, -distance_record: Type16 -} } +struct Type54 { + identifier: Type21, + data: Type53, +} -enum Type32 { le(u8, u8), be(u8, u8) } +struct Type55 { + marker: Type42, + length: u16, + data: Type54, +} -struct Type81 { -contents: Vec, -__padding: Vec, -__trailing: Vec +enum Type56 { + app1(Type51), + app0(Type55), } -struct Type88 { -marker: Type28, -length: u16, -data: Type37 +struct Type57 { + marker: Type42, + length: u16, + data: Vec, } -struct Type1 { -screen_width: u16, -screen_height: u16, -flags: u8, -bg_color_index: u8, -pixel_aspect_ratio: u8 +struct Type58 { + restart_interval: u16, } struct Type59 { -pixels_per_unit_x: u32, -pixels_per_unit_y: u32, -unit_specifier: u8 -} - -enum Type58 { color_type_ { -palette_index: u8 -}, color_type_ { -red: u16, -green: u16, -blue: u16 -}, color_type_ { -red: u16, -green: u16, -blue: u16 -}, color_type_ { -greyscale: u16 -}, color_type_ { -greyscale: u16 -} } - -struct Type94 { -marker: Type28, -length: u16, -data: Type42 -} - -struct Type49 { -marker: Type28, -length: u16, -data: Type48 + marker: Type42, + length: u16, + data: Type58, } -struct Type57 { -length: u32, -tag: (u8, u8, u8, u8), -data: Type56, -crc: u32 +struct Type60 { + class_table_id: u8, + value: u8, } -enum Type54 { some { -marker: Type28, -length: u16, -data: Type53 -}, none() } +struct Type61 { + marker: Type42, + length: u16, + data: Type60, +} -enum Type66 { no(u8), yes() } +struct Type62 { + class_table_id: u8, + num_codes: Vec, + values: Vec, +} -struct Type68 { -tag: (u8, u8, u8, u8), -chunks: Vec +struct Type63 { + marker: Type42, + length: u16, + data: Type62, } -enum Type3 { no(), yes(Vec) } +struct Type64 { + precision_table_id: u8, + elements: Vec, +} -struct Type40 { -class_table_id: u8, -num_codes: Vec, -values: Vec +struct Type65 { + marker: Type42, + length: u16, + data: Type64, +} + +enum Type66 { + com(Type57), + app15(Type57), + app14(Type57), + app13(Type57), + app12(Type57), + app11(Type57), + app10(Type57), + app9(Type57), + app8(Type57), + app7(Type57), + app6(Type57), + app5(Type57), + app4(Type57), + app3(Type57), + app2(Type57), + app1(Type51), + app0(Type55), + dri(Type59), + dac(Type61), + dht(Type63), + dqt(Type65), } -struct Type77 { -header: Type0, -logical_screen: Type4, -blocks: Vec, -trailer: Type12 +struct Type67 { + id: u8, + sampling_factor: u8, + quantization_table_id: u8, } -struct Type105 { -separator: u8, -label: u8, -block_size: u8, -flags: u8, -delay_time: u16, -transparent_color_index: u8, -terminator: u8 +struct Type68 { + sample_precision: u8, + num_lines: u16, + num_samples_per_line: u16, + num_image_components: u8, + image_components: Vec, } -struct Type106 { -descriptor: Type6, -local_color_table: Type3, -data: Type8 +struct Type69 { + marker: Type42, + length: u16, + data: Type68, +} + +enum Type70 { + sof15(Type69), + sof14(Type69), + sof13(Type69), + sof11(Type69), + sof10(Type69), + sof9(Type69), + sof7(Type69), + sof6(Type69), + sof5(Type69), + sof3(Type69), + sof2(Type69), + sof1(Type69), + sof0(Type69), +} + +struct Type71 { + component_selector: u8, + entropy_coding_table_ids: u8, +} + +struct Type72 { + num_image_components: u8, + image_components: Vec, + start_spectral_selection: u8, + end_spectral_selection: u8, + approximation_bit_position: u8, } struct Type73 { -header: Type72, -file: Vec, -__padding: () + marker: Type42, + length: u16, + data: Type72, } -struct Type28 { -ff: u8, -marker: u8 +enum Type74 { + rst7(Type42), + rst6(Type42), + rst5(Type42), + rst4(Type42), + rst3(Type42), + rst2(Type42), + rst1(Type42), + rst0(Type42), + mcu(u8), } -enum Type11 { graphic_block { -graphic_control_extension: Type5, -graphic_rendering_block: Type9 -}, special_purpose_block(Type10) } +struct Type75 { + scan_data: Vec, + scan_data_stream: Vec, +} -enum Type14 { no(), yes { -string: Vec, -null: u8 -} } +struct Type76 { + segments: Vec, + sos: Type73, + data: Type75, +} -struct Type25 { -blocks: Vec, -codes: Vec, -inflate: Vec +struct Type77 { + num_lines: u16, } -struct Type48 { -num_image_components: u8, -image_components: Vec, -start_spectral_selection: u8, -end_spectral_selection: u8, -approximation_bit_position: u8 -} - -enum Type9 { table_based_image { -descriptor: Type6, -local_color_table: Type3, -data: Type8 -}, plain_text_extension { -separator: u8, -label: u8, -block_size: u8, -text_grid_left_position: u16, -text_grid_top_position: u16, -text_grid_width: u16, -text_grid_height: u16, -character_cell_width: u8, -character_cell_height: u8, -text_foreground_color_index: u8, -text_background_color_index: u8, -plain_text_data: Vec, -terminator: u8 -} } - -struct Type15 { -code: u16, -extra: u8 +struct Type78 { + marker: Type42, + length: u16, + data: Type77, } -struct Type60 { -year: u16, -month: u8, -day: u8, -hour: u8, -minute: u8, -second: u8 +enum Type79 { + none, + some(Type78), } -struct Type72 { -name: Type69, -mode: Type70, -uid: Type70, -gid: Type70, -size: u32, -mtime: Type70, -chksum: Type70, -typeflag: u8, -linkname: Type69, -magic: (u8, u8, u8, u8, u8, u8), -version: (u8, u8), -uname: Type71, -gname: Type71, -devmajor: Type70, -devminor: Type70, -prefix: Type69, -pad: Vec -} - -struct Type96 { -padding: u8, -exif: Type35 +struct Type80 { + initial_segment: Type56, + segments: Vec, + header: Type70, + scan: Type76, + dnl: Type79, + scans: Vec, } -struct Type90 { -marker: Type28, -length: u16, -data: Type45 +struct Type81 { + soi: Type42, + frame: Type80, + eoi: Type42, } -struct Type97 { -xmp: Vec +struct Type82 { + width: u32, + height: u32, + bit_depth: u8, + color_type: u8, + compression_method: u8, + filter_method: u8, + interlace_method: u8, } -struct Type21 { -code: u16, -extra: Type20 +struct Type83 { + length: u32, + tag: (u8, u8, u8, u8), + data: Type82, + crc: u32, } -struct Type4 { -descriptor: Type1, -global_color_table: Type3 +struct Type84 { + palette_index: u8, } -struct Type89 { -marker: Type28, -length: u16, -data: Type53 +struct Type85 { + red: u16, + green: u16, + blue: u16, } -struct Type98 { -version_major: u8, -version_minor: u8, -density_units: u8, -density_x: u16, -density_y: u16, -thumbnail_width: u8, -thumbnail_height: u8, -thumbnail_pixels: Vec> +struct Type86 { + greyscale: u16, } -struct Type0 { -signature: (u8, u8, u8), -version: Vec +enum Type87 { + color_type_3(Vec), + color_type_2(Type85), + color_type_0(Type86), } -struct Type16 { -distance_extra_bits: u16, -distance: u16 +struct Type88 { + length: u32, + tag: (u8, u8, u8, u8), + data: Type87, + crc: u32, } -enum Type19 { literal(u8), reference { -length: u16, -distance: u16 -} } +struct Type89 { + year: u16, + month: u8, + day: u8, + hour: u8, + minute: u8, + second: u8, +} -struct Type79 { -signature: (u8, u8, u8, u8, u8, u8, u8, u8), -ihdr: Type57, -chunks: Vec, -idat: Vec, -more_chunks: Vec, -iend: Type65 +struct Type90 { + length: u32, + tag: (u8, u8, u8, u8), + data: Type89, + crc: u32, } -struct Type65 { -length: u32, -tag: (u8, u8, u8, u8), -data: (), -crc: u32 -} - -enum Type75 { gif { -header: Type0, -logical_screen: Type4, -blocks: Vec, -trailer: Type12 -}, gzip(Vec), jpeg { -soi: Type28, -frame: Type55, -eoi: Type28 -}, png { -signature: (u8, u8, u8, u8, u8, u8, u8, u8), -ihdr: Type57, -chunks: Vec, -idat: Vec, -more_chunks: Vec, -iend: Type65 -}, riff { -tag: (u8, u8, u8, u8), -length: u32, -data: Type68, -pad: Type66 -}, tar { -contents: Vec, -__padding: Vec, -__trailing: Vec -}, text(Type74) } +struct Type91 { + length: u32, + tag: (u8, u8, u8, u8), + data: Vec, + crc: u32, +} -struct Type102 { -graphic_control_extension: Type5, -graphic_rendering_block: Type9 +struct Type92 { + pixels_per_unit_x: u32, + pixels_per_unit_y: u32, + unit_specifier: u8, } -struct Type76 { -data: Type75, -end: () +struct Type93 { + length: u32, + tag: (u8, u8, u8, u8), + data: Type92, + crc: u32, } -struct Type8 { -lzw_min_code_size: u8, -image_data: Vec, -terminator: u8 +enum Type94 { + color_type_3(Type84), + color_type_6(Type85), + color_type_2(Type85), + color_type_4(Type86), + color_type_0(Type86), } -struct Type18 { -code: u16, -extra: Type17 +struct Type95 { + length: u32, + tag: (u8, u8, u8, u8), + data: Type94, + crc: u32, } -struct Type70 { -string: Vec, -__nul_or_wsp: u8, -__padding: Vec +enum Type96 { + tRNS(Type88), + tIME(Type90), + PLTE(Type91), + pHYs(Type93), + bKGD(Type95), } -struct Type71 { -string: Vec, -padding: Vec +struct Type97 { + length: u32, + tag: (u8, u8, u8, u8), + data: Vec, + crc: u32, } -struct Type7 { -len_bytes: u8, -data: Vec +struct Type98 { + length: u32, + tag: (u8, u8, u8, u8), + data: (), + crc: u32, } -enum Type10 { application_extension { -separator: u8, -label: u8, -block_size: u8, -identifier: Vec, -authentication_code: Vec, -application_data: Vec, -terminator: u8 -}, comment_extension { -separator: u8, -label: u8, -comment_data: Vec, -terminator: u8 -} } +struct Type99 { + signature: (u8, u8, u8, u8, u8, u8, u8, u8), + ihdr: Type83, + chunks: Vec, + idat: Vec, + more_chunks: Vec, + iend: Type98, +} -struct Type87 { -marker: Type28, -length: u16, -data: Type31 +enum Type100 { + no(u8), + yes, } -struct Type53 { -num_lines: u16 +struct Type101 { + tag: (u8, u8, u8, u8), + length: u32, + data: Vec, + pad: Type100, } -struct Type27 { -header: Type13, -fname: Type14, -data: Type25, -footer: Type26 -} - -enum Type30 { other(Vec), jfif { -version_major: u8, -version_minor: u8, -density_units: u8, -density_x: u16, -density_y: u16, -thumbnail_width: u8, -thumbnail_height: u8, -thumbnail_pixels: Vec> -} } +struct Type102 { + tag: (u8, u8, u8, u8), + chunks: Vec, +} -struct Type31 { -identifier: Type29, -data: Type30 -} - -struct Type56 { -width: u32, -height: u32, -bit_depth: u8, -color_type: u8, -compression_method: u8, -filter_method: u8, -interlace_method: u8 -} - -enum Type46 { sof0 { -marker: Type28, -length: u16, -data: Type45 -}, sof1 { -marker: Type28, -length: u16, -data: Type45 -}, sof2 { -marker: Type28, -length: u16, -data: Type45 -}, sof3 { -marker: Type28, -length: u16, -data: Type45 -}, sof5 { -marker: Type28, -length: u16, -data: Type45 -}, sof6 { -marker: Type28, -length: u16, -data: Type45 -}, sof7 { -marker: Type28, -length: u16, -data: Type45 -}, sof9 { -marker: Type28, -length: u16, -data: Type45 -}, sof10 { -marker: Type28, -length: u16, -data: Type45 -}, sof11 { -marker: Type28, -length: u16, -data: Type45 -}, sof13 { -marker: Type28, -length: u16, -data: Type45 -}, sof14 { -marker: Type28, -length: u16, -data: Type45 -}, sof15 { -marker: Type28, -length: u16, -data: Type45 -} } +struct Type103 { + tag: (u8, u8, u8, u8), + length: u32, + data: Type102, + pad: Type100, +} -struct Type64 { -length: u32, -tag: (u8, u8, u8, u8), -data: Vec, -crc: u32 +struct Type104 { + string: Vec, + __padding: Vec, } -struct Type47 { -component_selector: u8, -entropy_coding_table_ids: u8 -} - -struct Type35 { -byte_order: Type32, -magic: u16, -offset: u32, -ifd: Type34 -} - -enum Type50 { mcu(u8), rst0 { -ff: u8, -marker: u8 -}, rst1 { -ff: u8, -marker: u8 -}, rst2 { -ff: u8, -marker: u8 -}, rst3 { -ff: u8, -marker: u8 -}, rst4 { -ff: u8, -marker: u8 -}, rst5 { -ff: u8, -marker: u8 -}, rst6 { -ff: u8, -marker: u8 -}, rst7 { -ff: u8, -marker: u8 -} } +struct Type105 { + string: Vec, + __nul_or_wsp: u8, + __padding: Vec, +} -struct Type42 { -restart_interval: u16 +struct Type106 { + string: Vec, + padding: Vec, } -struct Type82 { -length: u32, -tag: (u8, u8, u8, u8), -data: Type58, -crc: u32 +struct Type107 { + name: Type104, + mode: Type105, + uid: Type105, + gid: Type105, + size: u32, + mtime: Type105, + chksum: Type105, + typeflag: u8, + linkname: Type104, + magic: (u8, u8, u8, u8, u8, u8), + version: (u8, u8), + uname: Type106, + gname: Type106, + devmajor: Type105, + devminor: Type105, + prefix: Type104, + pad: Vec, +} + +struct Type108 { + header: Type107, + file: Vec, + __padding: (), +} + +struct Type109 { + contents: Vec, + __padding: Vec, + __trailing: Vec, +} + +enum Type110 { + ascii(Vec), + utf8(Vec), +} + +enum Type111 { + gif(Type19), + gzip(Vec), + jpeg(Type81), + png(Type99), + riff(Type103), + tar(Type109), + text(Type110), +} + +struct Type112 { + data: Type111, + end: (), +} + +fn Decoder0<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + (Some((Decoder1(scope, input))?)) +} + +fn Decoder1<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let data = { (unimplemented!(r#"ParallelLogic::Alts.to_ast(..)"#)) }; + let end = { + if ((input.read_byte()).is_none()) { + () + } else { + return None; + } + }; + (Some(Type112 { data, end })) +} + +fn Decoder2<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let header = { (Decoder128(scope, input))? }; + let logical_screen = { (Decoder129(scope, input))? }; + let blocks = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 33 => 0, + + 44 => 0, + + 59 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder130(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let trailer = { (Decoder131(scope, input))? }; + (Some(Type19 { + header, + logical_screen, + blocks, + trailer, + })) +} + +fn Decoder3<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option> { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 31) { + 1 + } else { + 0 + } + }; + if (matching_ix == 0) { + break; + } else { + let next_elem = { + let header = { (Decoder118(scope, input))? }; + let fname = { + match (header.file_flags & 8 != 0) { + true => { + let inner = (Decoder119(scope, input))?; + (Type22::yes(inner)) + } + + false => { + let _ = (); + Type22::no + } + } + }; + let data = { (unimplemented!(r#"translate @ Decoder::Bits"#)) }; + let footer = { (Decoder121(scope, input))? }; + Type41 { + header, + fname, + data, + footer, + } + }; + (accum.push(next_elem)); + } + } + (Some(accum)) +} + +fn Decoder4<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let soi = { (Decoder45(scope, input))? }; + let frame = { (Decoder46(scope, input))? }; + let eoi = { (Decoder47(scope, input))? }; + (Some(Type81 { soi, frame, eoi })) +} + +fn Decoder5<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let signature = { (Decoder27(scope, input))? }; + let ihdr = { (Decoder28(scope, input))? }; + let chunks = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 98 => 0, + + 112 => 0, + + 80 => 0, + + 116 => 0, + + 73 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder29(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let idat = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 73 => { + let b = (lookahead.read_byte())?; + match b { + 69 => 0, + + 68 => 1, + } + } + + 98 => 0, + + 112 => 0, + + 80 => 0, + + 116 => 0, + } + }; + if (matching_ix == 0) { + break; + } else { + let next_elem = (Decoder30(scope, input))?; + (accum.push(next_elem)); + } + } + accum + }; + let more_chunks = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 98 => 0, + + 112 => 0, + + 80 => 0, + + 116 => 0, + + 73 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder29(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let iend = { (Decoder31(scope, input))? }; + (Some(Type99 { + signature, + ihdr, + chunks, + idat, + more_chunks, + iend, + })) +} + +fn Decoder6<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tag = { + let field0 = { + let b = (input.read_byte())?; + if (b == 82) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 70) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 70) { + b + } else { + return None; + } + }; + (field0, field1, field2, field3) + }; + let length = { (Decoder23(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let pad = { + match (length % 2 == 0) { + true => { + let _ = (); + Type100::yes + } + + false => { + let inner = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (Type100::no(inner)) + } + } + }; + (Some(Type103 { + tag, + length, + data, + pad, + })) +} + +fn Decoder7<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let contents = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 0 => 0, + + tmp if (tmp != 0) => 1, + } + }; + if (matching_ix == 0) { + break; + } else { + let next_elem = (Decoder14(scope, input))?; + (accum.push(next_elem)); + } + } + accum + }; + let __padding = { + let mut accum = (Vec::new()); + for _ in 0..1024 { + (accum.push({ + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + })); + } + accum + }; + let __trailing = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 0) { + 0 + } else { + 1 + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type109 { + contents, + __padding, + __trailing, + })) +} + +fn Decoder8<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + (Some((unimplemented!(r#"ParallelLogic::Alts.to_ast(..)"#)))) +} + +fn Decoder9<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option> { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if ((ByteSet::from_bits([18446744069414594048, 18446744073709551615, 0, 0])) + .contains(b)) + { + 1 + } else { + 0 + } + }; + if (matching_ix == 0) { + break; + } else { + let next_elem = (Decoder13(scope, input))?; + (accum.push(next_elem)); + } + } + (Some(accum)) +} + +fn Decoder10<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option> { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if ((ByteSet::from_bits([ + 18446744073709551615, + 18446744073709551615, + 0, + 0, + ])) + .contains(tmp)) => + { + 0 + } + + tmp if ((ByteSet::from_bits([0, 0, 0, 4294967292])).contains(tmp)) => 0, + + 224 => 0, + + tmp if ((ByteSet::from_bits([0, 0, 0, 35175782154240])).contains(tmp)) => 0, + + 237 => 0, + + tmp if ((ByteSet::from_bits([0, 0, 0, 211106232532992])).contains(tmp)) => 0, + + 240 => 0, + + tmp if ((ByteSet::from_bits([0, 0, 0, 3940649673949184])).contains(tmp)) => 0, + + 244 => 0, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder11(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + (Some(accum)) +} + +fn Decoder11<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let inner = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if ((ByteSet::from_bits([ + 18446744073709551615, + 18446744073709551615, + 0, + 0, + ])) + .contains(tmp)) => + { + 0 + } + + tmp if ((ByteSet::from_bits([0, 0, 0, 4294967292])).contains(tmp)) => 1, + + 224 => 2, + + tmp if ((ByteSet::from_bits([0, 0, 0, 35175782154240])).contains(tmp)) => 2, + + 237 => 2, + + tmp if ((ByteSet::from_bits([0, 0, 0, 211106232532992])).contains(tmp)) => 2, + + 240 => 3, + + tmp if ((ByteSet::from_bits([0, 0, 0, 3940649673949184])).contains(tmp)) => 3, + + 244 => 3, + } + }; + match tree_index { + 0 => { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([18446744073709551615, 18446744073709551615, 0, 0])) + .contains(b)) + { + b + } else { + return None; + } + }; + ((|byte| byte as u32)(inner)) + } + + 1 => { + let inner = { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 0, 4294967292])).contains(b)) { + b + } else { + return None; + } + }; + ((|raw| raw & 31)(inner)) + }; + let field1 = { (Decoder12(scope, input))? }; + (field0, field1) + }; + ((|bytes| match bytes { + (x1, x0) => ((x1 as u32) << 6 | (x0 as u32)), + })(inner)) + } + + 2 => { + let inner = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 224 => 0, + + tmp if ((ByteSet::from_bits([0, 0, 0, 35175782154240])) + .contains(tmp)) => + { + 1 + } + + 237 => 2, + + tmp if ((ByteSet::from_bits([0, 0, 0, 211106232532992])) + .contains(tmp)) => + { + 3 + } + } + }; + match tree_index { + 0 => { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if (b == 224) { + b + } else { + return None; + } + }; + ((|raw| raw & 15)(inner)) + }; + let field1 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 18446744069414584320, 0])) + .contains(b)) + { + b + } else { + return None; + } + }; + ((|raw| raw & 63)(inner)) + }; + let field2 = { (Decoder12(scope, input))? }; + (field0, field1, field2) + } + + 1 => { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 0, 35175782154240])).contains(b)) + { + b + } else { + return None; + } + }; + ((|raw| raw & 15)(inner)) + }; + let field1 = { (Decoder12(scope, input))? }; + let field2 = { (Decoder12(scope, input))? }; + (field0, field1, field2) + } + + 2 => { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if (b == 237) { + b + } else { + return None; + } + }; + ((|raw| raw & 15)(inner)) + }; + let field1 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 4294967295, 0])).contains(b)) { + b + } else { + return None; + } + }; + ((|raw| raw & 63)(inner)) + }; + let field2 = { (Decoder12(scope, input))? }; + (field0, field1, field2) + } + + 3 => { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 0, 211106232532992])) + .contains(b)) + { + b + } else { + return None; + } + }; + ((|raw| raw & 15)(inner)) + }; + let field1 = { (Decoder12(scope, input))? }; + let field2 = { (Decoder12(scope, input))? }; + (field0, field1, field2) + } + } + }; + ((|bytes| match bytes { + (x2, x1, x0) => ((x2 as u32) << 12 | (x1 as u32) << 6 | (x0 as u32)), + })(inner)) + } + + 3 => { + let inner = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 240 => 0, + + tmp if ((ByteSet::from_bits([0, 0, 0, 3940649673949184])) + .contains(tmp)) => + { + 1 + } + + 244 => 2, + } + }; + match tree_index { + 0 => { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if (b == 240) { + b + } else { + return None; + } + }; + ((|raw| raw & 7)(inner)) + }; + let field1 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 18446744073709486080, 0])) + .contains(b)) + { + b + } else { + return None; + } + }; + ((|raw| raw & 63)(inner)) + }; + let field2 = { (Decoder12(scope, input))? }; + let field3 = { (Decoder12(scope, input))? }; + (field0, field1, field2, field3) + } + + 1 => { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 0, 3940649673949184])) + .contains(b)) + { + b + } else { + return None; + } + }; + ((|raw| raw & 7)(inner)) + }; + let field1 = { (Decoder12(scope, input))? }; + let field2 = { (Decoder12(scope, input))? }; + let field3 = { (Decoder12(scope, input))? }; + (field0, field1, field2, field3) + } + + 2 => { + let field0 = { + let inner = { + let b = (input.read_byte())?; + if (b == 244) { + b + } else { + return None; + } + }; + ((|raw| raw & 7)(inner)) + }; + let field1 = { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 65535, 0])).contains(b)) { + b + } else { + return None; + } + }; + ((|raw| raw & 63)(inner)) + }; + let field2 = { (Decoder12(scope, input))? }; + let field3 = { (Decoder12(scope, input))? }; + (field0, field1, field2, field3) + } + } + }; + ((|bytes| match bytes { + (x3, x2, x1, x0) => { + ((x3 as u32) << 18 | (x2 as u32) << 12 | (x1 as u32) << 6 | (x0 as u32)) + } + })(inner)) + } + } + }; + (Some(((|codepoint| (char::from_u32(codepoint)).unwrap())(inner)))) +} + +fn Decoder12<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let inner = { + let b = (input.read_byte())?; + if ((ByteSet::from_bits([0, 0, 18446744073709551615, 0])).contains(b)) { + b + } else { + return None; + } + }; + (Some(((|raw| raw & 63)(inner)))) +} + +fn Decoder13<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let b = (input.read_byte())?; + (Some( + if ((ByteSet::from_bits([18446744069414594048, 18446744073709551615, 0, 0])).contains(b)) { + b + } else { + return None; + }, + )) +} + +fn Decoder14<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let header = { (Decoder15(scope, input))? }; + let file = { + let mut accum = (Vec::new()); + for _ in 0..header.size { + (accum.push((Decoder16(scope, input))?)); + } + accum + }; + let __padding = { + while (input.offset() % 512 != 0) { + let _ = (input.read_byte())?; + } + () + }; + (Some(Type108 { + header, + file, + __padding, + })) +} + +fn Decoder15<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + (Some((unimplemented!(r#"translate @ Decoder::Slice"#)))) +} + +fn Decoder16<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let b = (input.read_byte())?; + (Some(b)) +} + +fn Decoder17<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let string = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 0 => 0, + + tmp if (tmp != 0) => 1, + } + }; + if (matching_ix == 0) { + break; + } else { + let next_elem = { + let b = (input.read_byte())?; + if (b != 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } + } + accum + }; + let __padding = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 0) { + 0 + } else { + 1 + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type104 { string, __padding })) +} + +fn Decoder18<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let b = (input.read_byte())?; + (Some( + if ((ByteSet::from_bits([71776119061217280, 0, 0, 0])).contains(b)) { + b + } else { + return None; + }, + )) +} + +fn Decoder19<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let b = (input.read_byte())?; + (Some( + if ((ByteSet::from_bits([4294967297, 0, 0, 0])).contains(b)) { + b + } else { + return None; + }, + )) +} + +fn Decoder20<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let b = (input.read_byte())?; + (Some(b)) +} + +fn Decoder21<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let string = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b != 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let __padding = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 0) { + 0 + } else { + 1 + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type104 { string, __padding })) +} + +fn Decoder22<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let string = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b != 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let padding = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 0) { + 1 + } else { + 0 + } + }; + if (matching_ix == 0) { + break; + } else { + let next_elem = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } + } + accum + }; + (Some(Type106 { string, padding })) +} + +fn Decoder23<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let inner = { + let field0 = { (Decoder16(scope, input))? }; + let field1 = { (Decoder16(scope, input))? }; + let field2 = { (Decoder16(scope, input))? }; + let field3 = { (Decoder16(scope, input))? }; + (field0, field1, field2, field3) + }; + (Some(((|x| u32le(x))(inner)))) +} + +fn Decoder24<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tag = { (Decoder25(scope, input))? }; + let chunks = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + 0 + }; + if (matching_ix == 0) { + let next_elem = (Decoder26(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type102 { tag, chunks })) +} + +fn Decoder25<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option<(u8, u8, u8, u8)> { + let field0 = { (Decoder20(scope, input))? }; + let field1 = { (Decoder20(scope, input))? }; + let field2 = { (Decoder20(scope, input))? }; + let field3 = { (Decoder20(scope, input))? }; + (Some((field0, field1, field2, field3))) +} + +fn Decoder26<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tag = { (Decoder25(scope, input))? }; + let length = { (Decoder23(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let pad = { + match (length % 2 == 0) { + true => { + let _ = (); + Type100::yes + } + + false => { + let inner = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (Type100::no(inner)) + } + } + }; + (Some(Type101 { + tag, + length, + data, + pad, + })) +} + +fn Decoder27<'input>( + scope: &mut Scope, + input: &mut ParseCtxt<'input>, +) -> Option<(u8, u8, u8, u8, u8, u8, u8, u8)> { + let field0 = { + let b = (input.read_byte())?; + if (b == 137) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 80) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 78) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 71) { + b + } else { + return None; + } + }; + let field4 = { + let b = (input.read_byte())?; + if (b == 13) { + b + } else { + return None; + } + }; + let field5 = { + let b = (input.read_byte())?; + if (b == 10) { + b + } else { + return None; + } + }; + let field6 = { + let b = (input.read_byte())?; + if (b == 26) { + b + } else { + return None; + } + }; + let field7 = { + let b = (input.read_byte())?; + if (b == 10) { + b + } else { + return None; + } + }; + (Some(( + field0, field1, field2, field3, field4, field5, field6, field7, + ))) +} + +fn Decoder28<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { (Decoder43(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type83 { + length, + tag, + data, + crc, + })) +} + +fn Decoder29<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 98 => 0, + + 112 => 1, + + 80 => 2, + + 116 => { + let b = (lookahead.read_byte())?; + match b { + 73 => 3, + + 82 => 4, + } + } + } + }; + (Some(match tree_index { + 0 => { + let inner = (Decoder37(scope, input))?; + (Type96::bKGD(inner)) + } + + 1 => { + let inner = (Decoder38(scope, input))?; + (Type96::pHYs(inner)) + } + + 2 => { + let inner = (Decoder39(scope, input))?; + (Type96::PLTE(inner)) + } + + 3 => { + let inner = (Decoder40(scope, input))?; + (Type96::tIME(inner)) + } + + 4 => { + let inner = (Decoder41(scope, input))?; + (Type96::tRNS(inner)) + } + })) +} + +fn Decoder30<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { (Decoder35(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type97 { + length, + tag, + data, + crc, + })) +} + +fn Decoder31<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { (Decoder33(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type98 { + length, + tag, + data, + crc, + })) +} + +fn Decoder32<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let inner = { + let field0 = { (Decoder16(scope, input))? }; + let field1 = { (Decoder16(scope, input))? }; + let field2 = { (Decoder16(scope, input))? }; + let field3 = { (Decoder16(scope, input))? }; + (field0, field1, field2, field3) + }; + (Some(((|x| u32be(x))(inner)))) +} + +fn Decoder33<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option<(u8, u8, u8, u8)> { + let field0 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 69) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 78) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 68) { + b + } else { + return None; + } + }; + (Some((field0, field1, field2, field3))) +} + +fn Decoder34<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option<()> { + (Some(())) +} + +fn Decoder35<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option<(u8, u8, u8, u8)> { + let field0 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 68) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 65) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 84) { + b + } else { + return None; + } + }; + (Some((field0, field1, field2, field3))) +} + +fn Decoder36<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option> { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + 0 + }; + if (matching_ix == 0) { + let next_elem = (Decoder16(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + (Some(accum)) +} + +fn Decoder37<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { + let field0 = { + let b = (input.read_byte())?; + if (b == 98) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 75) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 71) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 68) { + b + } else { + return None; + } + }; + (field0, field1, field2, field3) + }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type95 { + length, + tag, + data, + crc, + })) +} + +fn Decoder38<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { + let field0 = { + let b = (input.read_byte())?; + if (b == 112) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 72) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 89) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 115) { + b + } else { + return None; + } + }; + (field0, field1, field2, field3) + }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type93 { + length, + tag, + data, + crc, + })) +} + +fn Decoder39<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { + let field0 = { + let b = (input.read_byte())?; + if (b == 80) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 76) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 84) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 69) { + b + } else { + return None; + } + }; + (field0, field1, field2, field3) + }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type91 { + length, + tag, + data, + crc, + })) +} + +fn Decoder40<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { + let field0 = { + let b = (input.read_byte())?; + if (b == 116) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 77) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 69) { + b + } else { + return None; + } + }; + (field0, field1, field2, field3) + }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type90 { + length, + tag, + data, + crc, + })) +} + +fn Decoder41<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let length = { (Decoder32(scope, input))? }; + let tag = { + let field0 = { + let b = (input.read_byte())?; + if (b == 116) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 82) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 78) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 83) { + b + } else { + return None; + } + }; + (field0, field1, field2, field3) + }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + let crc = { (Decoder32(scope, input))? }; + (Some(Type88 { + length, + tag, + data, + crc, + })) +} + +fn Decoder42<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let inner = { + let field0 = { (Decoder16(scope, input))? }; + let field1 = { (Decoder16(scope, input))? }; + (field0, field1) + }; + (Some(((|x| u16be(x))(inner)))) +} + +fn Decoder43<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option<(u8, u8, u8, u8)> { + let field0 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 72) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 68) { + b + } else { + return None; + } + }; + let field3 = { + let b = (input.read_byte())?; + if (b == 82) { + b + } else { + return None; + } + }; + (Some((field0, field1, field2, field3))) +} + +fn Decoder44<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let width = { (Decoder32(scope, input))? }; + let height = { (Decoder32(scope, input))? }; + let bit_depth = { (Decoder16(scope, input))? }; + let color_type = { (Decoder16(scope, input))? }; + let compression_method = { (Decoder16(scope, input))? }; + let filter_method = { (Decoder16(scope, input))? }; + let interlace_method = { (Decoder16(scope, input))? }; + (Some(Type82 { + width, + height, + bit_depth, + color_type, + compression_method, + filter_method, + interlace_method, + })) +} + +fn Decoder45<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 216) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder46<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let initial_segment = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 224 => 0, + + 225 => 1, + } + } else { + return None; + } + }; + match tree_index { + 0 => { + let inner = (Decoder48(scope, input))?; + (Type56::app0(inner)) + } + + 1 => { + let inner = (Decoder49(scope, input))?; + (Type56::app1(inner)) + } + } + }; + let segments = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 219 => 0, + + 196 => 0, + + 204 => 0, + + 221 => 0, + + 224 => 0, + + 225 => 0, + + 226 => 0, + + 227 => 0, + + 228 => 0, + + 229 => 0, + + 230 => 0, + + 231 => 0, + + 232 => 0, + + 233 => 0, + + 234 => 0, + + 235 => 0, + + 236 => 0, + + 237 => 0, + + 238 => 0, + + 239 => 0, + + 254 => 0, + + 192 => 1, + + 193 => 1, + + 194 => 1, + + 195 => 1, + + 197 => 1, + + 198 => 1, + + 199 => 1, + + 201 => 1, + + 202 => 1, + + 203 => 1, + + 205 => 1, + + 206 => 1, + + 207 => 1, + } + } else { + return None; + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder50(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let header = { (Decoder51(scope, input))? }; + let scan = { (Decoder52(scope, input))? }; + let dnl = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 220 => 0, + + 217 => 1, + + 218 => 1, + + 219 => 1, + + 196 => 1, + + 204 => 1, + + 221 => 1, + + 224 => 1, + + 225 => 1, + + 226 => 1, + + 227 => 1, + + 228 => 1, + + 229 => 1, + + 230 => 1, + + 231 => 1, + + 232 => 1, + + 233 => 1, + + 234 => 1, + + 235 => 1, + + 236 => 1, + + 237 => 1, + + 238 => 1, + + 239 => 1, + + 254 => 1, + } + } else { + return None; + } + }; + match tree_index { + 0 => { + let inner = (Decoder53(scope, input))?; + (Type79::some(inner)) + } + + 1 => { + let _ = (); + Type79::none + } + } + }; + let scans = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 218 => 0, + + 219 => 0, + + 196 => 0, + + 204 => 0, + + 221 => 0, + + 224 => 0, + + 225 => 0, + + 226 => 0, + + 227 => 0, + + 228 => 0, + + 229 => 0, + + 230 => 0, + + 231 => 0, + + 232 => 0, + + 233 => 0, + + 234 => 0, + + 235 => 0, + + 236 => 0, + + 237 => 0, + + 238 => 0, + + 239 => 0, + + 254 => 0, + + 217 => 1, + } + } else { + return None; + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder54(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type80 { + initial_segment, + segments, + header, + scan, + dnl, + scans, + })) +} + +fn Decoder47<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 217) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder48<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 224) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type55 { + marker, + length, + data, + })) +} + +fn Decoder49<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 225) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type51 { + marker, + length, + data, + })) +} + +fn Decoder50<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 219 => 0, + + 196 => 1, + + 204 => 2, + + 221 => 3, + + 224 => 4, + + 225 => 5, + + 226 => 6, + + 227 => 7, + + 228 => 8, + + 229 => 9, + + 230 => 10, + + 231 => 11, + + 232 => 12, + + 233 => 13, + + 234 => 14, + + 235 => 15, + + 236 => 16, + + 237 => 17, + + 238 => 18, + + 239 => 19, + + 254 => 20, + } + } else { + return None; + } + }; + (Some(match tree_index { + 0 => { + let inner = (Decoder85(scope, input))?; + (Type66::dqt(inner)) + } + + 1 => { + let inner = (Decoder86(scope, input))?; + (Type66::dht(inner)) + } + + 2 => { + let inner = (Decoder87(scope, input))?; + (Type66::dac(inner)) + } + + 3 => { + let inner = (Decoder88(scope, input))?; + (Type66::dri(inner)) + } + + 4 => { + let inner = (Decoder48(scope, input))?; + (Type66::app0(inner)) + } + + 5 => { + let inner = (Decoder49(scope, input))?; + (Type66::app1(inner)) + } + + 6 => { + let inner = (Decoder89(scope, input))?; + (Type66::app2(inner)) + } + + 7 => { + let inner = (Decoder90(scope, input))?; + (Type66::app3(inner)) + } + + 8 => { + let inner = (Decoder91(scope, input))?; + (Type66::app4(inner)) + } + + 9 => { + let inner = (Decoder92(scope, input))?; + (Type66::app5(inner)) + } + + 10 => { + let inner = (Decoder93(scope, input))?; + (Type66::app6(inner)) + } + + 11 => { + let inner = (Decoder94(scope, input))?; + (Type66::app7(inner)) + } + + 12 => { + let inner = (Decoder95(scope, input))?; + (Type66::app8(inner)) + } + + 13 => { + let inner = (Decoder96(scope, input))?; + (Type66::app9(inner)) + } + + 14 => { + let inner = (Decoder97(scope, input))?; + (Type66::app10(inner)) + } + + 15 => { + let inner = (Decoder98(scope, input))?; + (Type66::app11(inner)) + } + + 16 => { + let inner = (Decoder99(scope, input))?; + (Type66::app12(inner)) + } + + 17 => { + let inner = (Decoder100(scope, input))?; + (Type66::app13(inner)) + } + + 18 => { + let inner = (Decoder101(scope, input))?; + (Type66::app14(inner)) + } + + 19 => { + let inner = (Decoder102(scope, input))?; + (Type66::app15(inner)) + } + + 20 => { + let inner = (Decoder103(scope, input))?; + (Type66::com(inner)) + } + })) +} + +fn Decoder51<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 192 => 0, + + 193 => 1, + + 194 => 2, + + 195 => 3, + + 197 => 4, + + 198 => 5, + + 199 => 6, + + 201 => 7, + + 202 => 8, + + 203 => 9, + + 205 => 10, + + 206 => 11, + + 207 => 12, + } + } else { + return None; + } + }; + (Some(match tree_index { + 0 => { + let inner = (Decoder70(scope, input))?; + (Type70::sof0(inner)) + } + + 1 => { + let inner = (Decoder71(scope, input))?; + (Type70::sof1(inner)) + } + + 2 => { + let inner = (Decoder72(scope, input))?; + (Type70::sof2(inner)) + } + + 3 => { + let inner = (Decoder73(scope, input))?; + (Type70::sof3(inner)) + } + + 4 => { + let inner = (Decoder74(scope, input))?; + (Type70::sof5(inner)) + } + + 5 => { + let inner = (Decoder75(scope, input))?; + (Type70::sof6(inner)) + } + + 6 => { + let inner = (Decoder76(scope, input))?; + (Type70::sof7(inner)) + } + + 7 => { + let inner = (Decoder77(scope, input))?; + (Type70::sof9(inner)) + } + + 8 => { + let inner = (Decoder78(scope, input))?; + (Type70::sof10(inner)) + } + + 9 => { + let inner = (Decoder79(scope, input))?; + (Type70::sof11(inner)) + } + + 10 => { + let inner = (Decoder80(scope, input))?; + (Type70::sof13(inner)) + } + + 11 => { + let inner = (Decoder81(scope, input))?; + (Type70::sof14(inner)) + } + + 12 => { + let inner = (Decoder82(scope, input))?; + (Type70::sof15(inner)) + } + })) +} + +fn Decoder52<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let segments = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 219 => 0, + + 196 => 0, + + 204 => 0, + + 221 => 0, + + 224 => 0, + + 225 => 0, + + 226 => 0, + + 227 => 0, + + 228 => 0, + + 229 => 0, + + 230 => 0, + + 231 => 0, + + 232 => 0, + + 233 => 0, + + 234 => 0, + + 235 => 0, + + 236 => 0, + + 237 => 0, + + 238 => 0, + + 239 => 0, + + 254 => 0, + + 218 => 1, + } + } else { + return None; + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder50(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let sos = { (Decoder55(scope, input))? }; + let data = { (Decoder69(scope, input))? }; + (Some(Type76 { + segments, + sos, + data, + })) } -struct Type83 { -length: u32, -tag: (u8, u8, u8, u8), -data: Type59, -crc: u32 -} - -fn Decoder0<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let tmp = Decoder1(scope, inp)?; -inp = tmp.1; -tmp.0 -}); -} - -fn Decoder1<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let data = unimplemented!("invoke_decoder"); -let end = { -let tmp = inp.read_byte(); -if tmp.is_none() { -inp = tmp.1; -() -} else { -return None; -} -}; -return Some(Type76 { data, end }); -} - -fn Decoder2<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let header = { -let tmp = Decoder128(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let logical_screen = { -let tmp = Decoder129(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let blocks = unimplemented!("invoke_decoder"); -let trailer = { -let tmp = Decoder131(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type77 { header, logical_screen, blocks, trailer }); -} - -fn Decoder3<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option> { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder4<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let soi = { -let tmp = Decoder45(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let frame = { -let tmp = Decoder46(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let eoi = { -let tmp = Decoder47(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type78 { soi, frame, eoi }); -} - -fn Decoder5<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let signature = { -let tmp = Decoder27(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let ihdr = { -let tmp = Decoder28(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let chunks = unimplemented!("invoke_decoder"); -let idat = unimplemented!("invoke_decoder"); -let more_chunks = unimplemented!("invoke_decoder"); -let iend = { -let tmp = Decoder31(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type79 { signature, ihdr, chunks, idat, more_chunks, iend }); -} - -fn Decoder6<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let tag = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder23(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -let pad = unimplemented!("invoke_decoder"); -return Some(Type80 { tag, length, data, pad }); -} - -fn Decoder7<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let contents = unimplemented!("invoke_decoder"); -let __padding = unimplemented!("invoke_decoder"); -let __trailing = unimplemented!("invoke_decoder"); -return Some(Type81 { contents, __padding, __trailing }); -} - -fn Decoder8<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder9<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option> { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder10<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option> { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder11<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder12<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder13<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let bs = ByteSet::from_bits([18446744069414594048, 18446744073709551615, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}); -} - -fn Decoder14<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let header = { -let tmp = Decoder15(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let file = unimplemented!("invoke_decoder"); -let __padding = { -while input.offset % 512 != 0 { -let tmp = inp.read_byte()?; -inp = tmp.1; -} -() -}; -return Some(Type73 { header, file, __padding }); -} - -fn Decoder15<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder16<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let bs = ByteSet::from_bits([18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}); -} - -fn Decoder17<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let string = unimplemented!("invoke_decoder"); -let __padding = unimplemented!("invoke_decoder"); -return Some(Type69 { string, __padding }); -} - -fn Decoder18<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let bs = ByteSet::from_bits([71776119061217280, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}); -} - -fn Decoder19<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let bs = ByteSet::from_bits([4294967297, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}); -} - -fn Decoder20<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let bs = ByteSet::from_bits([18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}); -} - -fn Decoder21<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let string = unimplemented!("invoke_decoder"); -let __padding = unimplemented!("invoke_decoder"); -return Some(Type69 { string, __padding }); -} - -fn Decoder22<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let string = unimplemented!("invoke_decoder"); -let padding = unimplemented!("invoke_decoder"); -return Some(Type71 { string, padding }); -} - -fn Decoder23<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder24<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let tag = { -let tmp = Decoder25(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let chunks = unimplemented!("invoke_decoder"); -return Some(Type68 { tag, chunks }); -} - -fn Decoder25<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option<(u8, u8, u8, u8)> { -let mut inp = input; -let field0 = { -let tmp = Decoder20(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let field1 = { -let tmp = Decoder20(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let field2 = { -let tmp = Decoder20(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let field3 = { -let tmp = Decoder20(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some((field0, field1, field2, field3)); -} - -fn Decoder26<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let tag = { -let tmp = Decoder25(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let length = { -let tmp = Decoder23(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -let pad = unimplemented!("invoke_decoder"); -return Some(Type67 { tag, length, data, pad }); -} - -fn Decoder27<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option<(u8, u8, u8, u8, u8, u8, u8, u8)> { -let mut inp = input; -let field0 = { -let bs = ByteSet::from_bits([0, 0, 512, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field1 = { -let bs = ByteSet::from_bits([0, 65536, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field2 = { -let bs = ByteSet::from_bits([0, 16384, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field3 = { -let bs = ByteSet::from_bits([0, 128, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field4 = { -let bs = ByteSet::from_bits([8192, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field5 = { -let bs = ByteSet::from_bits([1024, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field6 = { -let bs = ByteSet::from_bits([67108864, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field7 = { -let bs = ByteSet::from_bits([1024, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some((field0, field1, field2, field3, field4, field5, field6, field7)); -} - -fn Decoder28<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = { -let tmp = Decoder43(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type57 { length, tag, data, crc }); -} - -fn Decoder29<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder30<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = { -let tmp = Decoder35(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type64 { length, tag, data, crc }); -} - -fn Decoder31<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = { -let tmp = Decoder33(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type65 { length, tag, data, crc }); -} - -fn Decoder32<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder33<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option<(u8, u8, u8, u8)> { -let mut inp = input; -let field0 = { -let bs = ByteSet::from_bits([0, 512, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field1 = { -let bs = ByteSet::from_bits([0, 32, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field2 = { -let bs = ByteSet::from_bits([0, 16384, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field3 = { -let bs = ByteSet::from_bits([0, 16, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some((field0, field1, field2, field3)); -} - -fn Decoder34<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option<()> { -Some(()) -} - -fn Decoder35<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option<(u8, u8, u8, u8)> { -let mut inp = input; -let field0 = { -let bs = ByteSet::from_bits([0, 512, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field1 = { -let bs = ByteSet::from_bits([0, 16, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field2 = { -let bs = ByteSet::from_bits([0, 2, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field3 = { -let bs = ByteSet::from_bits([0, 1048576, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some((field0, field1, field2, field3)); -} - -fn Decoder36<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option> { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder37<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = unimplemented!("invoke_decoder"); -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type82 { length, tag, data, crc }); -} - -fn Decoder38<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = unimplemented!("invoke_decoder"); -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type83 { length, tag, data, crc }); -} - -fn Decoder39<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = unimplemented!("invoke_decoder"); -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type84 { length, tag, data, crc }); -} - -fn Decoder40<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = unimplemented!("invoke_decoder"); -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type85 { length, tag, data, crc }); -} - -fn Decoder41<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let length = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let tag = unimplemented!("invoke_decoder"); -let data = unimplemented!("invoke_decoder"); -let crc = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type86 { length, tag, data, crc }); -} - -fn Decoder42<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder43<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option<(u8, u8, u8, u8)> { -let mut inp = input; -let field0 = { -let bs = ByteSet::from_bits([0, 512, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field1 = { -let bs = ByteSet::from_bits([0, 256, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field2 = { -let bs = ByteSet::from_bits([0, 16, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let field3 = { -let bs = ByteSet::from_bits([0, 262144, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some((field0, field1, field2, field3)); -} - -fn Decoder44<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let width = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let height = { -let tmp = Decoder32(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let bit_depth = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let color_type = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let compression_method = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let filter_method = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let interlace_method = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type56 { width, height, bit_depth, color_type, compression_method, filter_method, interlace_method }); -} - -fn Decoder45<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 16777216]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder46<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let initial_segment = unimplemented!("invoke_decoder"); -let segments = unimplemented!("invoke_decoder"); -let header = { -let tmp = Decoder51(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let scan = { -let tmp = Decoder52(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let dnl = unimplemented!("invoke_decoder"); -let scans = unimplemented!("invoke_decoder"); -return Some(Type55 { initial_segment, segments, header, scan, dnl, scans }); -} - -fn Decoder47<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 33554432]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder48<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type87 { marker, length, data }); -} - -fn Decoder49<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type88 { marker, length, data }); -} - -fn Decoder50<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder51<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder52<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let segments = unimplemented!("invoke_decoder"); -let sos = { -let tmp = Decoder55(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = { -let tmp = Decoder69(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type52 { segments, sos, data }); -} - -fn Decoder53<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type89 { marker, length, data }); -} - -fn Decoder54<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let segments = unimplemented!("invoke_decoder"); -let sos = { -let tmp = Decoder55(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = { -let tmp = Decoder56(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type52 { segments, sos, data }); -} - -fn Decoder55<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type49 { marker, length, data }); -} - -fn Decoder56<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let scan_data = unimplemented!("invoke_decoder"); -let scan_data_stream = unimplemented!("invoke_decoder"); -return Some(Type51 { scan_data, scan_data_stream }); -} - -fn Decoder57<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder58<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 65536]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder59<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 131072]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder60<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 262144]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder61<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 524288]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder62<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 1048576]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder63<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 2097152]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder64<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 4194304]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder65<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let ff = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let marker = { -let bs = ByteSet::from_bits([0, 0, 0, 8388608]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type28 { ff, marker }); -} - -fn Decoder66<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let num_image_components = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let image_components = unimplemented!("invoke_decoder"); -let start_spectral_selection = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let end_spectral_selection = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let approximation_bit_position = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type48 { num_image_components, image_components, start_spectral_selection, end_spectral_selection, approximation_bit_position }); -} - -fn Decoder67<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let component_selector = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let entropy_coding_table_ids = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type47 { component_selector, entropy_coding_table_ids }); -} - -fn Decoder68<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let num_lines = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type53 { num_lines }); -} - -fn Decoder69<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let scan_data = unimplemented!("invoke_decoder"); -let scan_data_stream = unimplemented!("invoke_decoder"); -return Some(Type51 { scan_data, scan_data_stream }); -} - -fn Decoder70<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder71<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder72<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder73<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder74<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder75<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder76<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder77<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder78<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder79<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder80<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder81<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder82<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type90 { marker, length, data }); -} - -fn Decoder83<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let sample_precision = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let num_lines = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let num_samples_per_line = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let num_image_components = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let image_components = unimplemented!("invoke_decoder"); -return Some(Type45 { sample_precision, num_lines, num_samples_per_line, num_image_components, image_components }); -} - -fn Decoder84<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let id = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let sampling_factor = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let quantization_table_id = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type44 { id, sampling_factor, quantization_table_id }); -} - -fn Decoder85<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type91 { marker, length, data }); -} - -fn Decoder86<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type92 { marker, length, data }); -} - -fn Decoder87<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type93 { marker, length, data }); -} - -fn Decoder88<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type94 { marker, length, data }); -} - -fn Decoder89<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder90<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder91<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder92<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder93<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder94<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder95<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder96<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder97<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder98<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder99<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder100<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder101<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder102<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder103<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let marker = unimplemented!("invoke_decoder"); -let length = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type95 { marker, length, data }); -} - -fn Decoder104<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let restart_interval = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type42 { restart_interval }); -} - -fn Decoder105<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let class_table_id = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let value = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type41 { class_table_id, value }); -} - -fn Decoder106<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let class_table_id = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let num_codes = unimplemented!("invoke_decoder"); -let values = unimplemented!("invoke_decoder"); -return Some(Type40 { class_table_id, num_codes, values }); -} - -fn Decoder107<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let precision_table_id = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let elements = unimplemented!("invoke_decoder"); -return Some(Type39 { precision_table_id, elements }); -} - -fn Decoder108<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let identifier = { -let tmp = Decoder109(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type37 { identifier, data }); -} - -fn Decoder109<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let string = unimplemented!("invoke_decoder"); -let null = { -let bs = ByteSet::from_bits([1, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type29 { string, null }); -} - -fn Decoder110<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let padding = { -let bs = ByteSet::from_bits([1, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let exif = { -let tmp = Decoder112(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type96 { padding, exif }); -} - -fn Decoder111<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let xmp = unimplemented!("invoke_decoder"); -return Some(Type97 { xmp }); -} - -fn Decoder112<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let byte_order = unimplemented!("invoke_decoder"); -let magic = unimplemented!("invoke_decoder"); -let offset = unimplemented!("invoke_decoder"); -let ifd = unimplemented!("invoke_decoder"); -return Some(Type35 { byte_order, magic, offset, ifd }); -} - -fn Decoder113<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder114<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let identifier = { -let tmp = Decoder115(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type31 { identifier, data }); -} - -fn Decoder115<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let string = unimplemented!("invoke_decoder"); -let null = { -let bs = ByteSet::from_bits([1, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type29 { string, null }); -} - -fn Decoder116<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let version_major = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let version_minor = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let density_units = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let density_x = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let density_y = { -let tmp = Decoder42(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let thumbnail_width = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let thumbnail_height = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let thumbnail_pixels = unimplemented!("invoke_decoder"); -return Some(Type98 { version_major, version_minor, density_units, density_x, density_y, thumbnail_width, thumbnail_height, thumbnail_pixels }); -} - -fn Decoder117<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let r = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let g = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let b = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type2 { r, g, b }); -} - -fn Decoder118<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let magic = unimplemented!("invoke_decoder"); -let method = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let file_flags = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let timestamp = { -let tmp = Decoder23(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let compression_flags = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let os_id = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type13 { magic, method, file_flags, timestamp, compression_flags, os_id }); -} - -fn Decoder119<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let tmp = Decoder127(scope, inp)?; -inp = tmp.1; -tmp.0 -}); -} - -fn Decoder120<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let blocks = unimplemented!("invoke_decoder"); -let codes = unimplemented!("invoke_decoder"); -let inflate = unimplemented!("invoke_decoder"); -return Some(Type25 { blocks, codes, inflate }); -} - -fn Decoder121<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let crc = { -let tmp = Decoder23(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let length = { -let tmp = Decoder23(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type26 { crc, length }); -} - -fn Decoder122<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let r#final = { -let tmp = Decoder123(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let r#type = unimplemented!("invoke_decoder"); -let data = unimplemented!("invoke_decoder"); -return Some(Type24 { r#final, r#type, data }); -} - -fn Decoder123<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let bs = ByteSet::from_bits([18446744073709551615, 18446744073709551615, 18446744073709551615, 18446744073709551615]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}); -} - -fn Decoder124<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let align = { -while input.offset % 8 != 0 { -let tmp = inp.read_byte()?; -inp = tmp.1; -} -() -}; -let len = unimplemented!("invoke_decoder"); -let nlen = unimplemented!("invoke_decoder"); -let bytes = unimplemented!("invoke_decoder"); -let codes_values = unimplemented!("invoke_decoder"); -return Some(Type99 { align, len, nlen, bytes, codes_values }); -} - -fn Decoder125<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let codes = unimplemented!("invoke_decoder"); -let codes_values = unimplemented!("invoke_decoder"); -return Some(Type100 { codes, codes_values }); -} - -fn Decoder126<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let hlit = unimplemented!("invoke_decoder"); -let hdist = unimplemented!("invoke_decoder"); -let hclen = unimplemented!("invoke_decoder"); -let code_length_alphabet_code_lengths = unimplemented!("invoke_decoder"); -let literal_length_distance_alphabet_code_lengths = unimplemented!("invoke_decoder"); -let literal_length_distance_alphabet_code_lengths_value = unimplemented!("invoke_decoder"); -let literal_length_alphabet_code_lengths_value = unimplemented!("invoke_decoder"); -let distance_alphabet_code_lengths_value = unimplemented!("invoke_decoder"); -let codes = unimplemented!("invoke_decoder"); -let codes_values = unimplemented!("invoke_decoder"); -return Some(Type101 { hlit, hdist, hclen, code_length_alphabet_code_lengths, literal_length_distance_alphabet_code_lengths, literal_length_distance_alphabet_code_lengths_value, literal_length_alphabet_code_lengths_value, distance_alphabet_code_lengths_value, codes, codes_values }); -} - -fn Decoder127<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let string = unimplemented!("invoke_decoder"); -let null = { -let bs = ByteSet::from_bits([1, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type29 { string, null }); -} - -fn Decoder128<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let signature = unimplemented!("invoke_decoder"); -let version = unimplemented!("invoke_decoder"); -return Some(Type0 { signature, version }); -} - -fn Decoder129<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let descriptor = { -let tmp = Decoder145(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let global_color_table = unimplemented!("invoke_decoder"); -return Some(Type4 { descriptor, global_color_table }); -} - -fn Decoder130<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder131<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let separator = { -let bs = ByteSet::from_bits([576460752303423488, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -return Some(Type12 { separator }); -} - -fn Decoder132<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let graphic_control_extension = unimplemented!("invoke_decoder"); -let graphic_rendering_block = { -let tmp = Decoder139(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type102 { graphic_control_extension, graphic_rendering_block }); -} - -fn Decoder133<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder134<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let separator = { -let bs = ByteSet::from_bits([8589934592, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let label = { -let bs = ByteSet::from_bits([0, 0, 0, 9223372036854775808]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let block_size = { -let bs = ByteSet::from_bits([2048, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let identifier = unimplemented!("invoke_decoder"); -let authentication_code = unimplemented!("invoke_decoder"); -let application_data = unimplemented!("invoke_decoder"); -let terminator = { -let tmp = Decoder137(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type103 { separator, label, block_size, identifier, authentication_code, application_data, terminator }); -} - -fn Decoder135<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let separator = { -let bs = ByteSet::from_bits([8589934592, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let label = { -let bs = ByteSet::from_bits([0, 0, 0, 4611686018427387904]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let comment_data = unimplemented!("invoke_decoder"); -let terminator = { -let tmp = Decoder137(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type104 { separator, label, comment_data, terminator }); -} - -fn Decoder136<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let len_bytes = { -let bs = ByteSet::from_bits([18446744073709551614, 18446744073709551615, 18446744073709551615, 18446744073709551615]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let data = unimplemented!("invoke_decoder"); -return Some(Type7 { len_bytes, data }); -} - -fn Decoder137<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some({ -let bs = ByteSet::from_bits([1, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}); -} - -fn Decoder138<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let separator = { -let bs = ByteSet::from_bits([8589934592, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let label = { -let bs = ByteSet::from_bits([0, 0, 0, 144115188075855872]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let block_size = { -let bs = ByteSet::from_bits([16, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let flags = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let delay_time = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let transparent_color_index = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let terminator = { -let tmp = Decoder137(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type105 { separator, label, block_size, flags, delay_time, transparent_color_index, terminator }); -} - -fn Decoder139<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -return Some(unimplemented!("invoke_decoder")); -} - -fn Decoder140<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let descriptor = { -let tmp = Decoder142(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let local_color_table = unimplemented!("invoke_decoder"); -let data = { -let tmp = Decoder144(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type106 { descriptor, local_color_table, data }); -} - -fn Decoder141<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let separator = { -let bs = ByteSet::from_bits([8589934592, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let label = { -let bs = ByteSet::from_bits([2, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let block_size = { -let bs = ByteSet::from_bits([4096, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let text_grid_left_position = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let text_grid_top_position = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let text_grid_width = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let text_grid_height = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let character_cell_width = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let character_cell_height = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let text_foreground_color_index = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let text_background_color_index = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let plain_text_data = unimplemented!("invoke_decoder"); -let terminator = { -let tmp = Decoder137(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type107 { separator, label, block_size, text_grid_left_position, text_grid_top_position, text_grid_width, text_grid_height, character_cell_width, character_cell_height, text_foreground_color_index, text_background_color_index, plain_text_data, terminator }); -} - -fn Decoder142<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let separator = { -let bs = ByteSet::from_bits([17592186044416, 0, 0, 0]); -let tmp = input.read_byte()?; -let b = tmp.0; -if bs.contains(b) { -inp = tmp.1; -b -} else { -return None; -} -}; -let image_left_position = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let image_top_position = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let image_width = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let image_height = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let flags = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type6 { separator, image_left_position, image_top_position, image_width, image_height, flags }); -} - -fn Decoder143<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let r = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let g = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let b = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type2 { r, g, b }); -} - -fn Decoder144<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let lzw_min_code_size = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let image_data = unimplemented!("invoke_decoder"); -let terminator = { -let tmp = Decoder137(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type8 { lzw_min_code_size, image_data, terminator }); -} - -fn Decoder145<'input>(scope: &mut Scope, input: ReadCtxt<'input>) -> Option { -let mut inp = input; -let screen_width = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let screen_height = { -let tmp = Decoder113(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let flags = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let bg_color_index = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -let pixel_aspect_ratio = { -let tmp = Decoder16(scope, inp)?; -inp = tmp.1; -tmp.0 -}; -return Some(Type1 { screen_width, screen_height, flags, bg_color_index, pixel_aspect_ratio }); +fn Decoder53<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 220) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type78 { + marker, + length, + data, + })) +} + +fn Decoder54<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let segments = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 255) { + let b = (lookahead.read_byte())?; + match b { + 219 => 0, + + 196 => 0, + + 204 => 0, + + 221 => 0, + + 224 => 0, + + 225 => 0, + + 226 => 0, + + 227 => 0, + + 228 => 0, + + 229 => 0, + + 230 => 0, + + 231 => 0, + + 232 => 0, + + 233 => 0, + + 234 => 0, + + 235 => 0, + + 236 => 0, + + 237 => 0, + + 238 => 0, + + 239 => 0, + + 254 => 0, + + 218 => 1, + } + } else { + return None; + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder50(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let sos = { (Decoder55(scope, input))? }; + let data = { (Decoder56(scope, input))? }; + (Some(Type76 { + segments, + sos, + data, + })) } +fn Decoder55<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 218) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type73 { + marker, + length, + data, + })) +} + +fn Decoder56<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let scan_data = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 255) => 0, + + 255 => { + let b = (lookahead.read_byte())?; + match b { + 0 => 0, + + 208 => 0, + + 209 => 0, + + 210 => 0, + + 211 => 0, + + 212 => 0, + + 213 => 0, + + 214 => 0, + + 215 => 0, + + 217 => 1, + + 218 => 1, + + 219 => 1, + + 196 => 1, + + 204 => 1, + + 221 => 1, + + 224 => 1, + + 225 => 1, + + 226 => 1, + + 227 => 1, + + 228 => 1, + + 229 => 1, + + 230 => 1, + + 231 => 1, + + 232 => 1, + + 233 => 1, + + 234 => 1, + + 235 => 1, + + 236 => 1, + + 237 => 1, + + 238 => 1, + + 239 => 1, + + 254 => 1, + } + } + } + }; + if (matching_ix == 0) { + let next_elem = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 255) => 0, + + 255 => { + let b = (lookahead.read_byte())?; + match b { + 0 => 0, + + 208 => 1, + + 209 => 2, + + 210 => 3, + + 211 => 4, + + 212 => 5, + + 213 => 6, + + 214 => 7, + + 215 => 8, + } + } + } + }; + match tree_index { + 0 => { + let inner = (Decoder57(scope, input))?; + (Type74::mcu(inner)) + } + + 1 => { + let inner = (Decoder58(scope, input))?; + (Type74::rst0(inner)) + } + + 2 => { + let inner = (Decoder59(scope, input))?; + (Type74::rst1(inner)) + } + + 3 => { + let inner = (Decoder60(scope, input))?; + (Type74::rst2(inner)) + } + + 4 => { + let inner = (Decoder61(scope, input))?; + (Type74::rst3(inner)) + } + + 5 => { + let inner = (Decoder62(scope, input))?; + (Type74::rst4(inner)) + } + + 6 => { + let inner = (Decoder63(scope, input))?; + (Type74::rst5(inner)) + } + + 7 => { + let inner = (Decoder64(scope, input))?; + (Type74::rst6(inner)) + } + + 8 => { + let inner = (Decoder65(scope, input))?; + (Type74::rst7(inner)) + } + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let scan_data_stream = { + (((scan_data.into_iter()).flat_map( + (|x| match x { + mcu(v) => ([v].to_vec()), + + rst0(_) => ([].to_vec()), + + rst1(_) => ([].to_vec()), + + rst2(_) => ([].to_vec()), + + rst3(_) => ([].to_vec()), + + rst4(_) => ([].to_vec()), + + rst5(_) => ([].to_vec()), + + rst6(_) => ([].to_vec()), + + rst7(_) => ([].to_vec()), + }), + )) + .collect()) + }; + (Some(Type75 { + scan_data, + scan_data_stream, + })) +} + +fn Decoder57<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 255) => 0, + + 255 => 1, + } + }; + (Some(match tree_index { + 0 => { + let b = (input.read_byte())?; + if (b != 255) { + b + } else { + return None; + } + } + + 1 => { + let inner = { + let field0 = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (field0, field1) + }; + ((|_| 255)(inner)) + } + })) +} + +fn Decoder58<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 208) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder59<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 209) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder60<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 210) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder61<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 211) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder62<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 212) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder63<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 213) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder64<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 214) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder65<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 215) { + b + } else { + return None; + } + }; + (Some(Type42 { ff, marker })) +} + +fn Decoder66<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let num_image_components = { (Decoder16(scope, input))? }; + let image_components = { + let mut accum = (Vec::new()); + for _ in 0..num_image_components { + (accum.push((Decoder67(scope, input))?)); + } + accum + }; + let start_spectral_selection = { (Decoder16(scope, input))? }; + let end_spectral_selection = { (Decoder16(scope, input))? }; + let approximation_bit_position = { (Decoder16(scope, input))? }; + (Some(Type72 { + num_image_components, + image_components, + start_spectral_selection, + end_spectral_selection, + approximation_bit_position, + })) +} + +fn Decoder67<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let component_selector = { (Decoder16(scope, input))? }; + let entropy_coding_table_ids = { (Decoder16(scope, input))? }; + (Some(Type71 { + component_selector, + entropy_coding_table_ids, + })) +} + +fn Decoder68<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let num_lines = { (Decoder42(scope, input))? }; + (Some(Type77 { num_lines })) +} + +fn Decoder69<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let scan_data = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 255) => 0, + + 255 => { + let b = (lookahead.read_byte())?; + match b { + 0 => 0, + + 208 => 0, + + 209 => 0, + + 210 => 0, + + 211 => 0, + + 212 => 0, + + 213 => 0, + + 214 => 0, + + 215 => 0, + + 220 => 1, + + 217 => 1, + + 218 => 1, + + 219 => 1, + + 196 => 1, + + 204 => 1, + + 221 => 1, + + 224 => 1, + + 225 => 1, + + 226 => 1, + + 227 => 1, + + 228 => 1, + + 229 => 1, + + 230 => 1, + + 231 => 1, + + 232 => 1, + + 233 => 1, + + 234 => 1, + + 235 => 1, + + 236 => 1, + + 237 => 1, + + 238 => 1, + + 239 => 1, + + 254 => 1, + } + } + } + }; + if (matching_ix == 0) { + let next_elem = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 255) => 0, + + 255 => { + let b = (lookahead.read_byte())?; + match b { + 0 => 0, + + 208 => 1, + + 209 => 2, + + 210 => 3, + + 211 => 4, + + 212 => 5, + + 213 => 6, + + 214 => 7, + + 215 => 8, + } + } + } + }; + match tree_index { + 0 => { + let inner = (Decoder57(scope, input))?; + (Type74::mcu(inner)) + } + + 1 => { + let inner = (Decoder58(scope, input))?; + (Type74::rst0(inner)) + } + + 2 => { + let inner = (Decoder59(scope, input))?; + (Type74::rst1(inner)) + } + + 3 => { + let inner = (Decoder60(scope, input))?; + (Type74::rst2(inner)) + } + + 4 => { + let inner = (Decoder61(scope, input))?; + (Type74::rst3(inner)) + } + + 5 => { + let inner = (Decoder62(scope, input))?; + (Type74::rst4(inner)) + } + + 6 => { + let inner = (Decoder63(scope, input))?; + (Type74::rst5(inner)) + } + + 7 => { + let inner = (Decoder64(scope, input))?; + (Type74::rst6(inner)) + } + + 8 => { + let inner = (Decoder65(scope, input))?; + (Type74::rst7(inner)) + } + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let scan_data_stream = { + (((scan_data.into_iter()).flat_map( + (|x| match x { + mcu(v) => ([v].to_vec()), + + rst0(_) => ([].to_vec()), + + rst1(_) => ([].to_vec()), + + rst2(_) => ([].to_vec()), + + rst3(_) => ([].to_vec()), + + rst4(_) => ([].to_vec()), + + rst5(_) => ([].to_vec()), + + rst6(_) => ([].to_vec()), + + rst7(_) => ([].to_vec()), + }), + )) + .collect()) + }; + (Some(Type75 { + scan_data, + scan_data_stream, + })) +} + +fn Decoder70<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 192) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder71<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 193) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder72<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 194) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder73<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 195) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder74<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 197) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder75<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 198) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder76<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 199) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder77<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 201) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder78<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 202) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder79<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 203) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder80<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 205) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder81<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 206) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder82<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 207) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type69 { + marker, + length, + data, + })) +} + +fn Decoder83<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let sample_precision = { (Decoder16(scope, input))? }; + let num_lines = { (Decoder42(scope, input))? }; + let num_samples_per_line = { (Decoder42(scope, input))? }; + let num_image_components = { (Decoder16(scope, input))? }; + let image_components = { + let mut accum = (Vec::new()); + for _ in 0..num_image_components { + (accum.push((Decoder84(scope, input))?)); + } + accum + }; + (Some(Type68 { + sample_precision, + num_lines, + num_samples_per_line, + num_image_components, + image_components, + })) +} + +fn Decoder84<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let id = { (Decoder16(scope, input))? }; + let sampling_factor = { (Decoder16(scope, input))? }; + let quantization_table_id = { (Decoder16(scope, input))? }; + (Some(Type67 { + id, + sampling_factor, + quantization_table_id, + })) +} + +fn Decoder85<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 219) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type65 { + marker, + length, + data, + })) +} + +fn Decoder86<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 196) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type63 { + marker, + length, + data, + })) +} + +fn Decoder87<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 204) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type61 { + marker, + length, + data, + })) +} + +fn Decoder88<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 221) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type59 { + marker, + length, + data, + })) +} + +fn Decoder89<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 226) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder90<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 227) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder91<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 228) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder92<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 229) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder93<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 230) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder94<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 231) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder95<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 232) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder96<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 233) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder97<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 234) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder98<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 235) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder99<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 236) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder100<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 237) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder101<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 238) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder102<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 239) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder103<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let marker = { + let ff = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let marker = { + let b = (input.read_byte())?; + if (b == 254) { + b + } else { + return None; + } + }; + Type42 { ff, marker } + }; + let length = { (Decoder42(scope, input))? }; + let data = { (unimplemented!(r#"translate @ Decoder::Slice"#)) }; + (Some(Type57 { + marker, + length, + data, + })) +} + +fn Decoder104<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let restart_interval = { (Decoder42(scope, input))? }; + (Some(Type58 { restart_interval })) +} + +fn Decoder105<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let class_table_id = { (Decoder16(scope, input))? }; + let value = { (Decoder16(scope, input))? }; + (Some(Type60 { + class_table_id, + value, + })) +} + +fn Decoder106<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let class_table_id = { (Decoder16(scope, input))? }; + let num_codes = { + let mut accum = (Vec::new()); + for _ in 0..16 { + (accum.push((Decoder16(scope, input))?)); + } + accum + }; + let values = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + 0 + }; + if (matching_ix == 0) { + let next_elem = (Decoder16(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type62 { + class_table_id, + num_codes, + values, + })) +} + +fn Decoder107<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let precision_table_id = { (Decoder16(scope, input))? }; + let elements = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + 0 + }; + if (matching_ix == 0) { + let next_elem = (Decoder16(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type64 { + precision_table_id, + elements, + })) +} + +fn Decoder108<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let identifier = { (Decoder109(scope, input))? }; + let data = { + match identifier.string { + [69, 120, 105, 102] => { + let inner = (Decoder110(scope, input))?; + (Type49::exif(inner)) + } + + [104, 116, 116, 112, 58, 47, 47, 110, 115, 46, 97, 100, 111, 98, 101, 46, 99, 111, 109, 47, 120, 97, 112, 47, 49, 46, 48, 47] => + { + let inner = (Decoder111(scope, input))?; + (Type49::xmp(inner)) + } + + _ => { + let inner = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + 0 + }; + if (matching_ix == 0) { + let next_elem = (Decoder16(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Type49::other(inner)) + } + } + }; + (Some(Type50 { identifier, data })) +} + +fn Decoder109<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let string = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b != 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let null = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (Some(Type21 { string, null })) +} + +fn Decoder110<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let padding = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + let exif = { (Decoder112(scope, input))? }; + (Some(Type48 { padding, exif })) +} + +fn Decoder111<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let xmp = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + 0 + }; + if (matching_ix == 0) { + let next_elem = (Decoder16(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Some(Type43 { xmp })) +} + +fn Decoder112<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let byte_order = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 73 => 0, + + 77 => 1, + } + }; + match tree_index { + 0 => { + let field0 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + (Type44::le(field0, field1)) + } + + 1 => { + let field0 = { + let b = (input.read_byte())?; + if (b == 77) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 77) { + b + } else { + return None; + } + }; + (Type44::be(field0, field1)) + } + } + }; + let magic = { + match byte_order { + le(_) => (Decoder113(scope, input))?, + + be(_) => (Decoder42(scope, input))?, + } + }; + let offset = { + match byte_order { + le(_) => (Decoder23(scope, input))?, + + be(_) => (Decoder32(scope, input))?, + } + }; + let ifd = { (unimplemented!(r#"translate @ Decoder::WithRelativeOffset"#)) }; + (Some(Type47 { + byte_order, + magic, + offset, + ifd, + })) +} + +fn Decoder113<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let inner = { + let field0 = { (Decoder16(scope, input))? }; + let field1 = { (Decoder16(scope, input))? }; + (field0, field1) + }; + (Some(((|x| u16le(x))(inner)))) +} + +fn Decoder114<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let identifier = { (Decoder115(scope, input))? }; + let data = { + match identifier.string { + [74, 70, 73, 70] => { + let inner = (Decoder116(scope, input))?; + (Type53::jfif(inner)) + } + + _ => { + let inner = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + 0 + }; + if (matching_ix == 0) { + let next_elem = (Decoder16(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + (Type53::other(inner)) + } + } + }; + (Some(Type54 { identifier, data })) +} + +fn Decoder115<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let string = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b != 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let null = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (Some(Type21 { string, null })) +} + +fn Decoder116<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let version_major = { (Decoder16(scope, input))? }; + let version_minor = { (Decoder16(scope, input))? }; + let density_units = { (Decoder16(scope, input))? }; + let density_x = { (Decoder42(scope, input))? }; + let density_y = { (Decoder42(scope, input))? }; + let thumbnail_width = { (Decoder16(scope, input))? }; + let thumbnail_height = { (Decoder16(scope, input))? }; + let thumbnail_pixels = { + let mut accum = (Vec::new()); + for _ in 0..thumbnail_height { + (accum.push({ + let mut accum = (Vec::new()); + for _ in 0..thumbnail_width { + (accum.push((Decoder117(scope, input))?)); + } + accum + })); + } + accum + }; + (Some(Type52 { + version_major, + version_minor, + density_units, + density_x, + density_y, + thumbnail_width, + thumbnail_height, + thumbnail_pixels, + })) +} + +fn Decoder117<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let r = { (Decoder16(scope, input))? }; + let g = { (Decoder16(scope, input))? }; + let b = { (Decoder16(scope, input))? }; + (Some(Type2 { r, g, b })) +} + +fn Decoder118<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let magic = { + let field0 = { + let b = (input.read_byte())?; + if (b == 31) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 139) { + b + } else { + return None; + } + }; + (field0, field1) + }; + let method = { (Decoder16(scope, input))? }; + let file_flags = { (Decoder16(scope, input))? }; + let timestamp = { (Decoder23(scope, input))? }; + let compression_flags = { (Decoder16(scope, input))? }; + let os_id = { (Decoder16(scope, input))? }; + (Some(Type20 { + magic, + method, + file_flags, + timestamp, + compression_flags, + os_id, + })) +} + +fn Decoder119<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + (Some((Decoder127(scope, input))?)) +} + +fn Decoder120<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let blocks = { + let mut accum = (Vec::new()); + while true { + let elem = (Decoder122(scope, input))?; + if (((|x| x.r#final == 1)())(&elem)) { + (accum.push(elem)); + break; + } else { + (accum.push(elem)); + } + } + accum + }; + let codes = { + (((blocks.into_iter()).flat_map( + (|x| match x.data { + uncompressed(y) => y.codes_values, + + fixed_huffman(y) => y.codes_values, + + dynamic_huffman(y) => y.codes_values, + }), + )) + .collect()) + }; + let inflate = { (unimplemented!(r#"embed_expr is not implemented for Expr::Inflate"#)) }; + (Some(Type39 { + blocks, + codes, + inflate, + })) +} + +fn Decoder121<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let crc = { (Decoder23(scope, input))? }; + let length = { (Decoder23(scope, input))? }; + (Some(Type40 { crc, length })) +} + +fn Decoder122<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let r#final = { (Decoder123(scope, input))? }; + let r#type = { + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + (field0, field1) + }; + ((|bits| bits.1 << 1 | bits.0)(inner)) + }; + let data = { + match r#type { + 0 => { + let inner = (Decoder124(scope, input))?; + (Type37::uncompressed(inner)) + } + + 1 => { + let inner = (Decoder125(scope, input))?; + (Type37::fixed_huffman(inner)) + } + + 2 => { + let inner = (Decoder126(scope, input))?; + (Type37::dynamic_huffman(inner)) + } + } + }; + (Some(Type38 { + r#final, + r#type, + data, + })) +} + +fn Decoder123<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let b = (input.read_byte())?; + (Some(b)) +} + +fn Decoder124<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let align = { + while (input.offset() % 8 != 0) { + let _ = (input.read_byte())?; + } + () + }; + let len = { + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + let field2 = { (Decoder123(scope, input))? }; + let field3 = { (Decoder123(scope, input))? }; + let field4 = { (Decoder123(scope, input))? }; + let field5 = { (Decoder123(scope, input))? }; + let field6 = { (Decoder123(scope, input))? }; + let field7 = { (Decoder123(scope, input))? }; + let field8 = { (Decoder123(scope, input))? }; + let field9 = { (Decoder123(scope, input))? }; + let field10 = { (Decoder123(scope, input))? }; + let field11 = { (Decoder123(scope, input))? }; + let field12 = { (Decoder123(scope, input))? }; + let field13 = { (Decoder123(scope, input))? }; + let field14 = { (Decoder123(scope, input))? }; + let field15 = { (Decoder123(scope, input))? }; + ( + field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, + field10, field11, field12, field13, field14, field15, + ) + }; + ((|bits| { + (bits.15 as u16) << 15 + | (bits.14 as u16) << 14 + | (bits.13 as u16) << 13 + | (bits.12 as u16) << 12 + | (bits.11 as u16) << 11 + | (bits.10 as u16) << 10 + | (bits.9 as u16) << 9 + | (bits.8 as u16) << 8 + | (bits.7 as u16) << 7 + | (bits.6 as u16) << 6 + | (bits.5 as u16) << 5 + | (bits.4 as u16) << 4 + | (bits.3 as u16) << 3 + | (bits.2 as u16) << 2 + | (bits.1 as u16) << 1 + | (bits.0 as u16) + })(inner)) + }; + let nlen = { + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + let field2 = { (Decoder123(scope, input))? }; + let field3 = { (Decoder123(scope, input))? }; + let field4 = { (Decoder123(scope, input))? }; + let field5 = { (Decoder123(scope, input))? }; + let field6 = { (Decoder123(scope, input))? }; + let field7 = { (Decoder123(scope, input))? }; + let field8 = { (Decoder123(scope, input))? }; + let field9 = { (Decoder123(scope, input))? }; + let field10 = { (Decoder123(scope, input))? }; + let field11 = { (Decoder123(scope, input))? }; + let field12 = { (Decoder123(scope, input))? }; + let field13 = { (Decoder123(scope, input))? }; + let field14 = { (Decoder123(scope, input))? }; + let field15 = { (Decoder123(scope, input))? }; + ( + field0, field1, field2, field3, field4, field5, field6, field7, field8, field9, + field10, field11, field12, field13, field14, field15, + ) + }; + ((|bits| { + (bits.15 as u16) << 15 + | (bits.14 as u16) << 14 + | (bits.13 as u16) << 13 + | (bits.12 as u16) << 12 + | (bits.11 as u16) << 11 + | (bits.10 as u16) << 10 + | (bits.9 as u16) << 9 + | (bits.8 as u16) << 8 + | (bits.7 as u16) << 7 + | (bits.6 as u16) << 6 + | (bits.5 as u16) << 5 + | (bits.4 as u16) << 4 + | (bits.3 as u16) << 3 + | (bits.2 as u16) << 2 + | (bits.1 as u16) << 1 + | (bits.0 as u16) + })(inner)) + }; + let bytes = { + let mut accum = (Vec::new()); + for _ in 0..len { + (accum.push({ + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + let field2 = { (Decoder123(scope, input))? }; + let field3 = { (Decoder123(scope, input))? }; + let field4 = { (Decoder123(scope, input))? }; + let field5 = { (Decoder123(scope, input))? }; + let field6 = { (Decoder123(scope, input))? }; + let field7 = { (Decoder123(scope, input))? }; + ( + field0, field1, field2, field3, field4, field5, field6, field7, + ) + }; + ((|bits| { + bits.7 << 7 + | bits.6 << 6 + | bits.5 << 5 + | bits.4 << 4 + | bits.3 << 3 + | bits.2 << 2 + | bits.1 << 1 + | bits.0 + })(inner)) + })); + } + accum + }; + let codes_values = + { (((bytes.into_iter()).flat_map((|x| [(literal(x))].to_vec()))).collect()) }; + (Some(Type36 { + align, + len, + nlen, + bytes, + codes_values, + })) +} + +fn Decoder125<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let codes = { (unimplemented!(r#"translate @ Decoder::Dynamic"#)) }; + let codes_values = { + (((codes.into_iter()).flat_map( + (|x| match x.code { + 256 => ([].to_vec()), + + 257 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 258 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 259 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 260 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 261 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 262 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 263 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 264 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 265 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 266 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 267 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 268 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 269 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 270 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 271 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 272 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 273 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 274 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 275 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 276 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 277 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 278 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 279 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 280 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 281 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 282 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 283 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 284 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 285 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + _ => ([(literal((x.code as u8)))].to_vec()), + }), + )) + .collect()) + }; + (Some(Type34 { + codes, + codes_values, + })) +} + +fn Decoder126<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let hlit = { + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + let field2 = { (Decoder123(scope, input))? }; + let field3 = { (Decoder123(scope, input))? }; + let field4 = { (Decoder123(scope, input))? }; + (field0, field1, field2, field3, field4) + }; + ((|bits| bits.4 << 4 | bits.3 << 3 | bits.2 << 2 | bits.1 << 1 | bits.0)(inner)) + }; + let hdist = { + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + let field2 = { (Decoder123(scope, input))? }; + let field3 = { (Decoder123(scope, input))? }; + let field4 = { (Decoder123(scope, input))? }; + (field0, field1, field2, field3, field4) + }; + ((|bits| bits.4 << 4 | bits.3 << 3 | bits.2 << 2 | bits.1 << 1 | bits.0)(inner)) + }; + let hclen = { + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + let field2 = { (Decoder123(scope, input))? }; + let field3 = { (Decoder123(scope, input))? }; + (field0, field1, field2, field3) + }; + ((|bits| bits.3 << 3 | bits.2 << 2 | bits.1 << 1 | bits.0)(inner)) + }; + let code_length_alphabet_code_lengths = { + let mut accum = (Vec::new()); + for _ in 0..(hclen + 4) { + (accum.push({ + let inner = { + let field0 = { (Decoder123(scope, input))? }; + let field1 = { (Decoder123(scope, input))? }; + let field2 = { (Decoder123(scope, input))? }; + (field0, field1, field2) + }; + ((|bits| bits.2 << 2 | bits.1 << 1 | bits.0)(inner)) + })); + } + accum + }; + let literal_length_distance_alphabet_code_lengths = + { (unimplemented!(r#"translate @ Decoder::Dynamic"#)) }; + let literal_length_distance_alphabet_code_lengths_value = { + (((literal_length_distance_alphabet_code_lengths.into_iter()).fold( + (none(())), + (|x| match (x.1.code as u8) { + 16 => ( + x.0, + (Vec::from_iter( + ((std::iter::repeat(match x.0 { + some(y) => y, + })) + .take((x.1.extra + 3))), + )), + ), + + 17 => ( + x.0, + (Vec::from_iter(((std::iter::repeat(0)).take((x.1.extra + 3))))), + ), + + 18 => ( + x.0, + (Vec::from_iter(((std::iter::repeat(0)).take((x.1.extra + 11))))), + ), + + v => ((some(v)), ([v].to_vec())), + }), + )) + .collect()) + }; + let literal_length_alphabet_code_lengths_value = { + { + let ix = 0; + literal_length_distance_alphabet_code_lengths_value[ix..(ix + (hlit as u16) + 257)] + } + }; + let distance_alphabet_code_lengths_value = { + { + let ix = ((hlit as u16) + 257); + literal_length_distance_alphabet_code_lengths_value[ix..(ix + (hdist as u16) + 1)] + } + }; + let codes = { (unimplemented!(r#"translate @ Decoder::Dynamic"#)) }; + let codes_values = { + (((codes.into_iter()).flat_map( + (|x| match x.code { + 256 => ([].to_vec()), + + 257 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 258 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 259 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 260 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 261 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 262 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 263 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 264 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 265 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 266 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 267 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 268 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 269 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 270 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 271 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 272 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 273 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 274 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 275 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 276 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 277 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 278 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 279 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 280 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 281 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 282 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 283 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 284 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + 285 => match x.extra { + some(rec) => { + ([reference { + length: rec.length, + distance: rec.distance_record.distance, + }] + .to_vec()) + } + }, + + _ => ([(literal((x.code as u8)))].to_vec()), + }), + )) + .collect()) + }; + (Some(Type30 { + hlit, + hdist, + hclen, + code_length_alphabet_code_lengths, + literal_length_distance_alphabet_code_lengths, + literal_length_distance_alphabet_code_lengths_value, + literal_length_alphabet_code_lengths_value, + distance_alphabet_code_lengths_value, + codes, + codes_values, + })) +} + +fn Decoder127<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let string = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = { + let b = (input.read_byte())?; + if (b != 0) { + b + } else { + return None; + } + }; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let null = { + let b = (input.read_byte())?; + if (b == 0) { + b + } else { + return None; + } + }; + (Some(Type21 { string, null })) +} + +fn Decoder128<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let signature = { + let field0 = { + let b = (input.read_byte())?; + if (b == 71) { + b + } else { + return None; + } + }; + let field1 = { + let b = (input.read_byte())?; + if (b == 73) { + b + } else { + return None; + } + }; + let field2 = { + let b = (input.read_byte())?; + if (b == 70) { + b + } else { + return None; + } + }; + (field0, field1, field2) + }; + let version = { + let mut accum = (Vec::new()); + for _ in 0..3 { + (accum.push((Decoder20(scope, input))?)); + } + accum + }; + (Some(Type0 { signature, version })) +} + +fn Decoder129<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let descriptor = { (Decoder145(scope, input))? }; + let global_color_table = { + match (descriptor.flags & 128 != 0) { + true => { + let inner = { + let mut accum = (Vec::new()); + for _ in 0..(2 << (descriptor.flags & 7)) { + (accum.push((Decoder143(scope, input))?)); + } + accum + }; + (Type3::yes(inner)) + } + + false => { + let _ = (); + Type3::no + } + } + }; + (Some(Type4 { + descriptor, + global_color_table, + })) +} + +fn Decoder130<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 33 => { + let b = (lookahead.read_byte())?; + match b { + 249 => 0, + + 1 => 0, + + 255 => 1, + + 254 => 1, + } + } + + 44 => 0, + } + }; + (Some(match tree_index { + 0 => { + let inner = (Decoder132(scope, input))?; + (Type17::graphic_block(inner)) + } + + 1 => { + let inner = (Decoder133(scope, input))?; + (Type17::special_purpose_block(inner)) + } + })) +} + +fn Decoder131<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let separator = { + let b = (input.read_byte())?; + if (b == 59) { + b + } else { + return None; + } + }; + (Some(Type18 { separator })) +} + +fn Decoder132<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let graphic_control_extension = { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 33 => { + let b = (lookahead.read_byte())?; + match b { + 249 => 0, + + 1 => 1, + } + } + + 44 => 1, + } + }; + match tree_index { + 0 => { + let inner = (Decoder138(scope, input))?; + (Type10::some(inner)) + } + + 1 => { + let _ = (); + Type10::none + } + } + }; + let graphic_rendering_block = { (Decoder139(scope, input))? }; + (Some(Type16 { + graphic_control_extension, + graphic_rendering_block, + })) +} + +fn Decoder133<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + if (b == 33) { + let b = (lookahead.read_byte())?; + match b { + 255 => 0, + + 254 => 1, + } + } else { + return None; + } + }; + (Some(match tree_index { + 0 => { + let inner = (Decoder134(scope, input))?; + (Type8::application_extension(inner)) + } + + 1 => { + let inner = (Decoder135(scope, input))?; + (Type8::comment_extension(inner)) + } + })) +} + +fn Decoder134<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let separator = { + let b = (input.read_byte())?; + if (b == 33) { + b + } else { + return None; + } + }; + let label = { + let b = (input.read_byte())?; + if (b == 255) { + b + } else { + return None; + } + }; + let block_size = { + let b = (input.read_byte())?; + if (b == 11) { + b + } else { + return None; + } + }; + let identifier = { + let mut accum = (Vec::new()); + for _ in 0..8 { + (accum.push((Decoder16(scope, input))?)); + } + accum + }; + let authentication_code = { + let mut accum = (Vec::new()); + for _ in 0..3 { + (accum.push((Decoder16(scope, input))?)); + } + accum + }; + let application_data = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder136(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let terminator = { (Decoder137(scope, input))? }; + (Some(Type7 { + separator, + label, + block_size, + identifier, + authentication_code, + application_data, + terminator, + })) +} + +fn Decoder135<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let separator = { + let b = (input.read_byte())?; + if (b == 33) { + b + } else { + return None; + } + }; + let label = { + let b = (input.read_byte())?; + if (b == 254) { + b + } else { + return None; + } + }; + let comment_data = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder136(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let terminator = { (Decoder137(scope, input))? }; + (Some(Type6 { + separator, + label, + comment_data, + terminator, + })) +} + +fn Decoder136<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let len_bytes = { + let b = (input.read_byte())?; + if (b != 0) { + b + } else { + return None; + } + }; + let data = { + let mut accum = (Vec::new()); + for _ in 0..len_bytes { + (accum.push((Decoder16(scope, input))?)); + } + accum + }; + (Some(Type5 { len_bytes, data })) +} + +fn Decoder137<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let b = (input.read_byte())?; + (Some(if (b == 0) { + b + } else { + return None; + })) +} + +fn Decoder138<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let separator = { + let b = (input.read_byte())?; + if (b == 33) { + b + } else { + return None; + } + }; + let label = { + let b = (input.read_byte())?; + if (b == 249) { + b + } else { + return None; + } + }; + let block_size = { + let b = (input.read_byte())?; + if (b == 4) { + b + } else { + return None; + } + }; + let flags = { (Decoder16(scope, input))? }; + let delay_time = { (Decoder113(scope, input))? }; + let transparent_color_index = { (Decoder16(scope, input))? }; + let terminator = { (Decoder137(scope, input))? }; + (Some(Type9 { + separator, + label, + block_size, + flags, + delay_time, + transparent_color_index, + terminator, + })) +} + +fn Decoder139<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let tree_index = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + 44 => 0, + + 33 => 1, + } + }; + (Some(match tree_index { + 0 => { + let inner = (Decoder140(scope, input))?; + (Type15::table_based_image(inner)) + } + + 1 => { + let inner = (Decoder141(scope, input))?; + (Type15::plain_text_extension(inner)) + } + })) +} + +fn Decoder140<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let descriptor = { (Decoder142(scope, input))? }; + let local_color_table = { + match (descriptor.flags & 128 != 0) { + true => { + let inner = { + let mut accum = (Vec::new()); + for _ in 0..(2 << (descriptor.flags & 7)) { + (accum.push((Decoder143(scope, input))?)); + } + accum + }; + (Type3::yes(inner)) + } + + false => { + let _ = (); + Type3::no + } + } + }; + let data = { (Decoder144(scope, input))? }; + (Some(Type14 { + descriptor, + local_color_table, + data, + })) +} + +fn Decoder141<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let separator = { + let b = (input.read_byte())?; + if (b == 33) { + b + } else { + return None; + } + }; + let label = { + let b = (input.read_byte())?; + if (b == 1) { + b + } else { + return None; + } + }; + let block_size = { + let b = (input.read_byte())?; + if (b == 12) { + b + } else { + return None; + } + }; + let text_grid_left_position = { (Decoder113(scope, input))? }; + let text_grid_top_position = { (Decoder113(scope, input))? }; + let text_grid_width = { (Decoder113(scope, input))? }; + let text_grid_height = { (Decoder113(scope, input))? }; + let character_cell_width = { (Decoder16(scope, input))? }; + let character_cell_height = { (Decoder16(scope, input))? }; + let text_foreground_color_index = { (Decoder16(scope, input))? }; + let text_background_color_index = { (Decoder16(scope, input))? }; + let plain_text_data = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder136(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let terminator = { (Decoder137(scope, input))? }; + (Some(Type11 { + separator, + label, + block_size, + text_grid_left_position, + text_grid_top_position, + text_grid_width, + text_grid_height, + character_cell_width, + character_cell_height, + text_foreground_color_index, + text_background_color_index, + plain_text_data, + terminator, + })) +} + +fn Decoder142<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let separator = { + let b = (input.read_byte())?; + if (b == 44) { + b + } else { + return None; + } + }; + let image_left_position = { (Decoder113(scope, input))? }; + let image_top_position = { (Decoder113(scope, input))? }; + let image_width = { (Decoder113(scope, input))? }; + let image_height = { (Decoder113(scope, input))? }; + let flags = { (Decoder16(scope, input))? }; + (Some(Type12 { + separator, + image_left_position, + image_top_position, + image_width, + image_height, + flags, + })) +} + +fn Decoder143<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let r = { (Decoder16(scope, input))? }; + let g = { (Decoder16(scope, input))? }; + let b = { (Decoder16(scope, input))? }; + (Some(Type2 { r, g, b })) +} + +fn Decoder144<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let lzw_min_code_size = { (Decoder16(scope, input))? }; + let image_data = { + let mut accum = (Vec::new()); + while true { + let matching_ix = { + let lookahead = &mut (input.clone()); + let b = (lookahead.read_byte())?; + match b { + tmp if (tmp != 0) => 0, + + 0 => 1, + } + }; + if (matching_ix == 0) { + let next_elem = (Decoder136(scope, input))?; + (accum.push(next_elem)); + } else { + break; + } + } + accum + }; + let terminator = { (Decoder137(scope, input))? }; + (Some(Type13 { + lzw_min_code_size, + image_data, + terminator, + })) +} + +fn Decoder145<'input>(scope: &mut Scope, input: &mut ParseCtxt<'input>) -> Option { + let screen_width = { (Decoder113(scope, input))? }; + let screen_height = { (Decoder113(scope, input))? }; + let flags = { (Decoder16(scope, input))? }; + let bg_color_index = { (Decoder16(scope, input))? }; + let pixel_aspect_ratio = { (Decoder16(scope, input))? }; + (Some(Type1 { + screen_width, + screen_height, + flags, + bg_color_index, + pixel_aspect_ratio, + })) +} + +#[test] +fn test_decoder_27() { + // PNG signature + let input = b"\x89PNG\r\n\x1A\n"; + let mut parse_ctxt = ParseCtxt::new(input); + let mut scope = Scope::Empty; + let ret = Decoder27(&mut scope, &mut parse_ctxt); + assert!(ret.is_some()); +} diff --git a/src/byte_set.rs b/src/byte_set.rs index c53be63d..0e3dd07b 100644 --- a/src/byte_set.rs +++ b/src/byte_set.rs @@ -10,6 +10,24 @@ pub struct ByteSet { bits: [u64; 4], } +const fn min_set_bit(x: u64) -> Option { + match x.trailing_zeros() { + 64 => None, + i => Some(i as u8), + } +} + +const fn bit_to_quad(bit: u8, offset: u8) -> u64 { + if offset > bit { + 0 + } else { + match 1u64.overflowing_shl((bit - offset) as u32) { + (n, false) => n, + (_, true) => 0, + } + } +} + impl ByteSet { pub const fn new() -> ByteSet { ByteSet::empty() @@ -29,6 +47,16 @@ impl ByteSet { ByteSet::from_bits([0; 4]) } + pub const fn singleton(bit: u8) -> ByteSet { + let bits = [ + bit_to_quad(bit, 0), + bit_to_quad(bit, 0x40), + bit_to_quad(bit, 0x80), + bit_to_quad(bit, 0xc0), + ]; + ByteSet { bits } + } + pub const fn full() -> ByteSet { ByteSet::from_bits([u64::MAX; 4]) } @@ -37,6 +65,22 @@ impl ByteSet { (0..=255).filter(|b| self.contains(*b)) } + pub const fn min_elem(&self) -> Option { + if let Some(i) = min_set_bit(self.bits[0]) { + return Some(i); + } + if let Some(i) = min_set_bit(self.bits[1]) { + return Some(0x40 + i); + } + if let Some(i) = min_set_bit(self.bits[2]) { + return Some(0x80 + i); + } + if let Some(i) = min_set_bit(self.bits[3]) { + return Some(0xc0 + i); + } + None + } + fn get_bit_with(&self, b: u8, f: impl FnOnce(u64, u8) -> T) -> T { match b { 0..=63 => f(self.bits[0], b), diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 0d3b3948..a0480116 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2,18 +2,18 @@ mod rust_ast; use crate::byte_set::ByteSet; use crate::codegen::rust_ast::{ - LocalType, Mut, RustControl, RustDecl, RustImport, RustImportItems, RustItem, RustProgram, + LocalType, MatchCaseLHS, Mut, RustControl, RustDecl, RustImport, RustImportItems, RustItem, + RustOp, RustProgram, }; use crate::decoder::{Decoder, Program}; -use crate::{Expr, Label, MatchTree, ValueType}; +use crate::{Expr, Label, MatchTree, Pattern, ValueType}; use std::borrow::Cow; use std::collections::HashMap; -use rust_ast::{CompType, PrimType, RustType, RustTypeDef, ToFragment}; - -use self::rust_ast::{ - AtomType, DefParams, FnSig, RustExpr, RustFn, RustLt, RustParams, RustStmt, RustStruct, - RustVariant, +use rust_ast::{ + AtomType, CompType, Constructor, DefParams, FnSig, Operator, PrimType, RustEntity, RustExpr, + RustFn, RustLt, RustParams, RustPattern, RustPrimLit, RustStmt, RustStruct, RustType, + RustTypeDef, RustVariant, ToFragment, }; #[repr(transparent)] @@ -148,19 +148,23 @@ impl Codegen { let rt_var = match vdef { ValueType::Empty => RustVariant::Unit(vname.clone()), ValueType::Tuple(args) => { - let mut rt_args = Vec::new(); - for arg in args.iter() { - rt_args.push(self.lift_type(arg)); + if args.is_empty() { + RustVariant::Unit(vname.clone()) + } else { + let mut rt_args = Vec::new(); + for arg in args.iter() { + rt_args.push(self.lift_type(arg)); + } + RustVariant::Tuple(vname.clone(), rt_args) } - RustVariant::Tuple(vname.clone(), rt_args) } - ValueType::Record(fields) => { + /* ValueType::Record(fields) => { let mut rt_fields = Vec::new(); for (f_lab, f_ty) in fields.iter() { rt_fields.push((f_lab.clone(), self.lift_type(f_ty))); } RustVariant::Record(vname.clone(), rt_fields) - } + } */ other => { let inner = self.lift_type(other); RustVariant::Tuple(vname.clone(), vec![inner]) @@ -194,12 +198,86 @@ impl Codegen { Decoder::Align(n) => CaseLogic::Simple(SimpleLogic::SkipToNextMultiple(*n)), Decoder::Byte(bs) => CaseLogic::Simple(SimpleLogic::ByteIn(bs.clone())), Decoder::Variant(vname, inner) => { - // FIXME - not sure quite what logic to employ for unwrapping type-hints on variants - match type_hint { - _ => CaseLogic::Derived(DerivedLogic::VariantOf( - vname.clone(), - Box::new(self.translate(inner.as_ref(), type_hint.clone())), - )), + let (tname, tdef) = match type_hint { + Some(RustType::Atom(AtomType::TypeRef(LocalType::LocalDef(ix, lab)))) => { + (lab.clone(), &self.defined_types[*ix]) + } + Some(other) => panic!("unexpected type_hint for Decoder::Variant: {:?}", other), + _ => unreachable!("must have type_hint to translate Decoder::Variant"), + }; + + let constr = Constructor::Compound(tname.clone(), vname.clone()); + + match tdef { + RustTypeDef::Enum(vars) => { + let matching = vars + .iter() + .find(|var| var.get_label().as_ref() == vname.as_ref()); + // REVIEW - should we force an exact match? + match matching { + Some(RustVariant::Unit(_)) => { + // FIXME - this is not quite correct, as it calls `Var(inner)` where `inner = ()` instead of `Var` + let inner = self.translate(inner, Some(&RustType::UNIT)); + CaseLogic::Derived(DerivedLogic::UnitVariantOf(constr, Box::new(inner))) + } + Some(RustVariant::Tuple(_, typs)) => { + if typs.is_empty() { + unreachable!("unexpected Tuple-Variant with 0 positional arguments"); + } + match inner.as_ref() { + Decoder::Tuple(decs) => { + if decs.len() != typs.len() { + if typs.len() == 1 { + // REVIEW - allowance for 1-tuple variant whose argument type is itself an n-tuple + match &typs[0] { + tt @ RustType::AnonTuple(..) => { + let cl_mono_tuple = self.translate(inner, Some(tt)); + CaseLogic::Derived(DerivedLogic::VariantOf(constr, Box::new(cl_mono_tuple))) + } + other => panic!("unable to translate Decoder::Tuple with hint ({other:?}) implied by {tname}::{vname}"), + } + } else { + unreachable!("mismatched arity between decoder (== {}) and variant {tname}::{vname} (== {})", decs.len(), typs.len()); + } + } else { + let mut cl_args = Vec::new(); + for (dec, typ) in decs.iter().zip(typs.iter()) { + let cl_arg = self.translate(dec, Some(typ)); + cl_args.push(cl_arg); + } + CaseLogic::Sequential(SequentialLogic::AccumTuple { constructor: Some(constr), elements: cl_args }) + } + } + _ => { + if typs.len() == 1 { + let cl_mono = self.translate(inner, Some(&typs[0])); + CaseLogic::Derived(DerivedLogic::VariantOf(constr, Box::new(cl_mono))) + } else { + panic!("Variant {tname}::{vname}({typs:#?}) mismatches non-tuple Decoder {inner:?}"); + } + } + } + } + Some(RustVariant::Record(_, fields)) => { + match inner.as_ref() { + Decoder::Record(inner_fields) => { + let mut assocs = Vec::new(); + for (i, (l0, d)) in inner_fields.iter().enumerate() { + let (l1, t) = &fields[i]; + assert_eq!(l0.as_ref(), l1.as_ref(), "Decoder field `{l0}` != RustTypeDef field `{l1}` (at index {i} in {decoder:?} | {tdef:?})"); + assocs.push((l0.clone(), self.translate(d, Some(t)))); + } + CaseLogic::Sequential(SequentialLogic::AccumRecord { constructor: constr, fields: assocs }) + } + _ => unreachable!("Variant {tname}::{vname} expects record ({fields:#?}) but found {:?}", inner), + } + } + None => unreachable!("VariantOf called for nonexistent variant `{vname}` of enum-type `{tname}`"), + } + } + RustTypeDef::Struct(_) => { + unreachable!("Decoder::Variant incoherent against type defined as struct") + } } } Decoder::Parallel(alts) => CaseLogic::Parallel(ParallelLogic::Alts( @@ -228,6 +306,9 @@ impl Codegen { .collect(), }) } + Some(RustType::Atom(AtomType::Prim(PrimType::Unit))) if elts.is_empty() => { + CaseLogic::Simple(SimpleLogic::Eval(RustExpr::UNIT)) + } Some(other) => unreachable!( "Decoder::Tuple expected to have type RustType::AnonTuple(..), found {:?}", other @@ -248,34 +329,418 @@ impl Codegen { assert_eq!(l0.as_ref(), l1.as_ref(), "Decoder field `{l0}` != RustTypeDef field `{l1}` (at index {i} in {decoder:?} | {tdef:?})"); assocs.push((l0.clone(), self.translate(d, Some(t)))); } - CaseLogic::Sequential(SequentialLogic::AccumRecord { constructor: lab.clone(), fields: assocs }) + CaseLogic::Sequential(SequentialLogic::AccumRecord { constructor: Constructor::Simple(lab.clone()), fields: assocs }) } + None => unreachable!("Cannot generate CaseLogic for a Record without a definite type-name"), Some(other) => unreachable!("Decoder::Record expected to have type RustType::Atom(AtomType::TypeRef(..)), found {:?}", other), } } + Decoder::While(tree_continue, single) => match type_hint { + Some(RustType::Atom(AtomType::Comp(CompType::Vec(t)))) => { + let cl_single = self.translate(single, Some(t.as_ref())); + CaseLogic::Repeat(RepeatLogic::ContinueOnMatch( + tree_continue.clone(), + Box::new(cl_single), + )) + } + Some(other) => { + unreachable!("Hint for Decoder::While should be Vec<_>, found {other:?}") + } + None => { + let cl_single = self.translate(single, None); + CaseLogic::Repeat(RepeatLogic::ContinueOnMatch( + tree_continue.clone(), + Box::new(cl_single), + )) + } + }, + Decoder::Until(tree_break, single) => match type_hint { + Some(RustType::Atom(AtomType::Comp(CompType::Vec(t)))) => { + let cl_single = self.translate(single, Some(t.as_ref())); + CaseLogic::Repeat(RepeatLogic::BreakOnMatch( + tree_break.clone(), + Box::new(cl_single), + )) + } + Some(other) => { + unreachable!("Hint for Decoder::Until should be Vec<_>, found {other:?}") + } + None => { + let cl_single = self.translate(single, None); + CaseLogic::Repeat(RepeatLogic::BreakOnMatch( + tree_break.clone(), + Box::new(cl_single), + )) + } + }, + Decoder::RepeatCount(expr_count, single) => match type_hint { + Some(RustType::Atom(AtomType::Comp(CompType::Vec(t)))) => { + let cl_single = self.translate(single, Some(t.as_ref())); + CaseLogic::Repeat(RepeatLogic::ExactCount( + embed_expr(expr_count), + Box::new(cl_single), + )) + } + Some(other) => { + unreachable!("Hint for Decoder::RepeatCount should be Vec<_>, found {other:?}") + } + None => { + let cl_single = self.translate(single, None); + CaseLogic::Repeat(RepeatLogic::ExactCount( + embed_expr(expr_count), + Box::new(cl_single), + )) + } + }, + Decoder::RepeatUntilLast(pred_terminal, single) => match type_hint { + Some(RustType::Atom(AtomType::Comp(CompType::Vec(t)))) => { + let cl_single = self.translate(single, Some(t.as_ref())); + CaseLogic::Repeat(RepeatLogic::ConditionTerminal( + embed_expr(pred_terminal), + Box::new(cl_single), + )) + } + Some(other) => unreachable!( + "Hint for Decoder::RepeatUntilLast should be Vec<_>, found {other:?}" + ), + None => { + let cl_single = self.translate(single, None); + CaseLogic::Repeat(RepeatLogic::ConditionTerminal( + embed_expr(pred_terminal), + Box::new(cl_single), + )) + } + }, + Decoder::RepeatUntilSeq(pred_complete, single) => match type_hint { + Some(RustType::Atom(AtomType::Comp(CompType::Vec(t)))) => { + let cl_single = self.translate(single, Some(t.as_ref())); + CaseLogic::Repeat(RepeatLogic::ConditionComplete( + embed_expr(pred_complete), + Box::new(cl_single), + )) + } + Some(other) => unreachable!( + "Hint for Decoder::RepeatUntilSeq should be Vec<_>, found {other:?}" + ), + None => { + let cl_single = self.translate(single, None); + CaseLogic::Repeat(RepeatLogic::ConditionComplete( + embed_expr(pred_complete), + Box::new(cl_single), + )) + } + }, // FIXME - implement CaseLogic variants and translation rules for the remaining cases - Decoder::While(_, _) => todo!(), - Decoder::Until(_, _) => todo!(), - Decoder::RepeatCount(_, _) => todo!(), - Decoder::RepeatUntilLast(_, _) => todo!(), - Decoder::RepeatUntilSeq(_, _) => todo!(), - Decoder::Peek(_) => todo!(), - Decoder::PeekNot(_) => todo!(), - Decoder::Slice(_, _) => todo!(), - Decoder::Bits(_) => todo!(), - Decoder::WithRelativeOffset(_, _) => todo!(), - Decoder::Map(_, _) => todo!(), - Decoder::Compute(_) => todo!(), - Decoder::Let(_, _, _) => todo!(), - Decoder::Match(_, _) => todo!(), - Decoder::Dynamic(_, _, _) => todo!(), - Decoder::Apply(_) => todo!(), + Decoder::Map(inner, f) => { + // FIXME - we have no way of inferring a proper type-hint for inner + let cl_inner = self.translate(inner, None); + CaseLogic::Derived(DerivedLogic::MapOf(embed_expr(f), Box::new(cl_inner))) + } + Decoder::Compute(expr) => CaseLogic::Simple(SimpleLogic::Eval(embed_expr(expr))), + Decoder::Let(name, expr, inner) => { + let cl_inner = self.translate(inner, type_hint); + CaseLogic::Derived(DerivedLogic::Let( + name.clone(), + embed_expr(expr), + Box::new(cl_inner), + )) + } + Decoder::Match(scrutinee, cases) => { + let mut cl_cases = Vec::new(); + for (pat, dec) in cases.iter() { + cl_cases.push(( + // FIXME - add type_hint for scrutinee when possible + MatchCaseLHS::Pattern(embed_pattern(pat, None)), + self.translate(dec, type_hint), + )); + } + CaseLogic::Other(OtherLogic::ExprMatch(embed_expr(scrutinee), cl_cases)) + } + Decoder::Dynamic(_lab, _f_dyn, _inner) => { + CaseLogic::Unhandled("translate @ Decoder::Dynamic".into()) + } + Decoder::Apply(_lab) => CaseLogic::Unhandled("translate @ Decoder::Apply".into()), + Decoder::Peek(_inner) => CaseLogic::Unhandled("translate @ Decoder::Peek".into()), + Decoder::PeekNot(_inner) => CaseLogic::Unhandled("translate @ Decoder::PeekNot".into()), + Decoder::Slice(_width, _inner) => { + CaseLogic::Unhandled("translate @ Decoder::Slice".into()) + } + Decoder::Bits(_dec_bits) => CaseLogic::Unhandled("translate @ Decoder::Bits".into()), + Decoder::WithRelativeOffset(_offset, _inner) => { + CaseLogic::Unhandled("translate @ Decoder::WithRelativeOffset".into()) + } } } } -fn decoder_fn(ix: usize, t: &RustType, decoder: &Decoder) -> RustFn { +fn get_enum_name<'a>(typ: &'a RustType) -> &'a Label { + match typ { + RustType::Atom(AtomType::TypeRef(LocalType::LocalDef(_, name))) => name, + other => unreachable!("get_enum_name: non-LocalDef type {other:?}"), + } +} + +fn embed_pattern(pat: &Pattern, type_hint: Option<&RustType>) -> RustPattern { + match pat { + Pattern::Wildcard => RustPattern::CatchAll(None), + Pattern::Binding(name) => RustPattern::CatchAll(Some(name.clone())), + Pattern::Bool(b) => RustPattern::PrimLiteral(RustPrimLit::BooleanLit(*b)), + Pattern::U8(n) => RustPattern::PrimLiteral(RustPrimLit::NumericLit(*n as usize)), + Pattern::U16(n) => RustPattern::PrimLiteral(RustPrimLit::NumericLit(*n as usize)), + Pattern::U32(n) => RustPattern::PrimLiteral(RustPrimLit::NumericLit(*n as usize)), + Pattern::Char(c) => RustPattern::PrimLiteral(RustPrimLit::CharLit(*c)), + Pattern::Tuple(pats) => { + RustPattern::TupleLiteral(pats.iter().map(|x| embed_pattern(x, None)).collect()) + } + Pattern::Seq(pats) => { + RustPattern::ArrayLiteral(pats.iter().map(|x| embed_pattern(x, None)).collect()) + } + Pattern::Variant(vname, pat) => { + let constr = match type_hint { + Some(ty) => { + let tname = get_enum_name(ty).clone(); + Constructor::Compound(tname, vname.clone()) + } + // FIXME - figure out a way to get around this + None => Constructor::Simple(vname.clone()), + }; + let inner = embed_pattern(pat, None); + RustPattern::Variant(constr, Box::new(inner)) + } + } +} + +fn embed_expr(expr: &Expr) -> RustExpr { + match expr { + Expr::Var(vname) => { + // FIXME - as currently implemented, the scoping is almost certainly not implemented to reference local assignments properly + RustExpr::local(vname.clone()) + } + Expr::Bool(b) => RustExpr::PrimitiveLit(RustPrimLit::BooleanLit(*b)), + Expr::U8(n) => RustExpr::num_lit(*n as usize), + Expr::U16(n) => RustExpr::num_lit(*n as usize), + Expr::U32(n) => RustExpr::num_lit(*n as usize), + Expr::Tuple(tup) => RustExpr::Tuple(tup.iter().map(embed_expr).collect()), + Expr::TupleProj(expr_tup, ix) => embed_expr(expr_tup).nth(*ix), + Expr::Record(_fields) => unreachable!("Record not bound in Variant"), + Expr::RecordProj(expr_rec, fld) => embed_expr(expr_rec).field(fld.clone()), + Expr::Variant(vname, inner) => match inner.as_ref() { + Expr::Record(fields) => RustExpr::Struct( + RustEntity::Local(vname.clone()), + fields + .iter() + .map(|(fname, fval)| (fname.clone(), Some(Box::new(embed_expr(fval))))) + .collect(), + ), + _ => RustExpr::local(vname.clone()).call_with([embed_expr(inner)]), + }, + Expr::Seq(elts) => { + RustExpr::ArrayLit(elts.iter().map(embed_expr).collect()).call_method("to_vec") + } + Expr::Match(scrutinee, cases) => RustExpr::Control(Box::new(RustControl::Match( + embed_expr(scrutinee), + cases + .iter() + .map(|(pat, rhs)| { + ( + // FIXME - add actual type_hint when possible + MatchCaseLHS::Pattern(embed_pattern(pat, None)), + vec![RustStmt::Return(false, embed_expr(rhs))], + ) + }) + .collect(), + ))), + // FIXME - we probably need to apply precedence rules similar to tree-output, which will require a lot of refactoring in AST + Expr::BitAnd(lhs, rhs) => { + RustExpr::infix(embed_expr(lhs), Operator::BitAnd, embed_expr(rhs)) + } + Expr::BitOr(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::BitOr, embed_expr(rhs)), + Expr::Eq(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Eq, embed_expr(rhs)), + Expr::Ne(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Neq, embed_expr(rhs)), + Expr::Lt(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Lt, embed_expr(rhs)), + Expr::Gt(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Gt, embed_expr(rhs)), + Expr::Lte(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Lte, embed_expr(rhs)), + Expr::Gte(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Gte, embed_expr(rhs)), + Expr::Mul(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Mul, embed_expr(rhs)), + Expr::Div(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Div, embed_expr(rhs)), + Expr::Rem(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Rem, embed_expr(rhs)), + Expr::Shl(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Shl, embed_expr(rhs)), + Expr::Shr(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Shr, embed_expr(rhs)), + Expr::Add(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Add, embed_expr(rhs)), + Expr::Sub(lhs, rhs) => RustExpr::infix(embed_expr(lhs), Operator::Sub, embed_expr(rhs)), + Expr::AsU8(x) => { + RustExpr::Operation(RustOp::AsCast(Box::new(embed_expr(x)), PrimType::U8.into())) + } + Expr::AsU16(x) => RustExpr::Operation(RustOp::AsCast( + Box::new(embed_expr(x)), + PrimType::U16.into(), + )), + Expr::AsU32(x) => RustExpr::Operation(RustOp::AsCast( + Box::new(embed_expr(x)), + PrimType::U32.into(), + )), + Expr::U16Be(be_bytes) => RustExpr::local("u16be").call_with([embed_expr(be_bytes)]), + Expr::U16Le(le_bytes) => RustExpr::local("u16le").call_with([embed_expr(le_bytes)]), + Expr::U32Be(be_bytes) => RustExpr::local("u32be").call_with([embed_expr(be_bytes)]), + Expr::U32Le(le_bytes) => RustExpr::local("u32le").call_with([embed_expr(le_bytes)]), + Expr::AsChar(codepoint) => RustExpr::scoped(["char"], "from_u32") + .call_with([embed_expr(codepoint)]) + .call_method("unwrap"), + Expr::SeqLength(seq) => embed_expr(seq).call_method("len"), + Expr::SubSeq(seq, ix, len) => { + let start_expr = embed_expr(ix); + let bind_ix = RustStmt::assign("ix", start_expr); + let end_expr = RustExpr::infix(RustExpr::local("ix"), Operator::Add, embed_expr(len)); + RustExpr::BlockScope( + vec![bind_ix], + Box::new(RustExpr::Slice( + Box::new(embed_expr(seq)), + Box::new(RustExpr::local("ix")), + Box::new(end_expr), + )), + ) + } + Expr::FlatMap(f, seq) => embed_expr(seq) + .call_method("into_iter") + .call_method_with("flat_map", [embed_expr(f)]) + .call_method("collect"), + Expr::FlatMapAccum(f, acc_init, _acc_type, seq) => embed_expr(seq) + .call_method("into_iter") + .call_method_with("fold", [embed_expr(acc_init), embed_expr(f)]) + .call_method("collect"), + Expr::Dup(n, expr) => RustExpr::scoped(["Vec"], "from_iter").call_with([RustExpr::scoped( + ["std", "iter"], + "repeat", + ) + .call_with([embed_expr(expr)]) + .call_method_with("take", [embed_expr(n)])]), + Expr::Inflate(_) => { + // FIXME - not clear what the proper thing to do here is + RustExpr::local("unimplemented!").call_with([RustExpr::str_lit( + "embed_expr is not implemented for Expr::Inflate", + )]) + } + Expr::Lambda(head, body) => RustExpr::Paren(Box::new(RustExpr::Closure( + head.clone(), + None, + Box::new(embed_expr(body)), + ))), + } +} + +#[allow(dead_code)] +type RustBlock = (Vec, Option); + +#[derive(Clone, Copy)] +#[allow(dead_code)] +struct ProdCtxt<'a> { + input_varname: &'a Label, + scope_varname: &'a Label, +} + +impl CaseLogic { + /// Produces an RustExpr-valued AST for the given CaseLogic instance. + /// + /// The Expr should have the bare type of the value being parsed (i.e. not Option-wrapped), + /// but it is implicitly assumed to be contained in a block whose ultimate return value + /// is `Option<_>`, allowing `return None` and `?` expressions to be used anyway. + /// + /// Local bindings and control flow are allowed, as long as an explicit return + /// or a concrete, consistently-typed return value are used + #[allow(dead_code)] + fn to_ast(&self, ctxt: ProdCtxt<'_>) -> RustBlock { + match self { + CaseLogic::Simple(s) => s.to_ast(ctxt), + CaseLogic::Derived(d) => d.to_ast(ctxt), + CaseLogic::Sequential(sq) => sq.to_ast(ctxt), + CaseLogic::Repeat(r) => r.to_ast(ctxt), + CaseLogic::Parallel(p) => p.to_ast(ctxt), + CaseLogic::Other(o) => o.to_ast(ctxt), + CaseLogic::Unhandled(msg) => ( + Vec::new(), + Some(RustExpr::local("unimplemented!").call_with([RustExpr::str_lit(msg.clone())])), + ), + } + } +} + +impl SimpleLogic { + fn to_ast(&self, ctxt: ProdCtxt<'_>) -> RustBlock { + match self { + SimpleLogic::Fail => (vec![RustStmt::Return(true, RustExpr::NONE)], None), + SimpleLogic::ExpectEnd => { + let call = RustExpr::local(ctxt.input_varname.clone()).call_method("read_byte"); + let cond = call.call_method("is_none"); + let b_true = [RustStmt::Return(false, RustExpr::UNIT)]; + let b_false = [RustStmt::Return(true, RustExpr::NONE)]; + ( + Vec::new(), + Some(RustExpr::Control(Box::new(RustControl::If( + cond, + b_true.to_vec(), + Some(b_false.to_vec()), + )))), + ) + } + // FIXME - not sure what should be done with _args + SimpleLogic::Invoke(ix_dec, _args) => { + let fname = format!("Decoder{ix_dec}"); + let call = RustExpr::local(fname).call_with([ + RustExpr::local(ctxt.scope_varname.clone()), + RustExpr::local(ctxt.input_varname.clone()), + ]); + (Vec::new(), Some(call.wrap_try())) + } + SimpleLogic::SkipToNextMultiple(n) => { + // FIXME - this currently produces correct but inefficient code + // it is harder to write, but much more efficient, to cut the buffer at the right place + // in order to do so, we would need a more advanced Parser model or more complex inline logic + let cond = RustExpr::infix( + RustExpr::infix( + RustExpr::local("input").call_method("offset"), + Operator::Rem, + RustExpr::num_lit(*n), + ), + Operator::Neq, + RustExpr::num_lit(0usize), + ); + let body = { + let let_tmp = RustStmt::assign( + "_", + RustExpr::local(ctxt.input_varname.clone()) + .call_method("read_byte") + .wrap_try(), + ); + vec![let_tmp] + }; + ( + vec![RustStmt::Control(RustControl::While(cond, body))], + Some(RustExpr::UNIT), + ) + } + SimpleLogic::ByteIn(bs) => { + let call = RustExpr::local(ctxt.input_varname.clone()) + .call_method("read_byte") + .wrap_try(); + let b_let = RustStmt::assign("b", call); + let (cond, always_true) = + ByteCriterion::from(bs).as_predicate(RustExpr::local("b")); + let logic = if always_true { + RustExpr::local("b") + } else { + let b_true = vec![RustStmt::Return(false, RustExpr::local("b"))]; + let b_false = vec![RustStmt::Return(true, RustExpr::local("None"))]; + RustExpr::Control(Box::new(RustControl::If(cond, b_true, Some(b_false)))) + }; + ([b_let].to_vec(), Some(logic)) + } + SimpleLogic::Eval(expr) => (vec![], Some(expr.clone())), + } + } +} + +fn decoder_fn(ix: usize, t: &RustType, logic: CaseLogic) -> RustFn { let name = Label::from(format!("Decoder{ix}")); let params = { let mut tmp = DefParams::new(); @@ -286,11 +751,7 @@ fn decoder_fn(ix: usize, t: &RustType, decoder: &Decoder) -> RustFn { let args = { let arg0 = { let name = "scope".into(); - let ty = RustType::Atom(AtomType::Comp(CompType::Borrow( - None, - Mut::Mutable, - Box::new(RustType::imported("Scope")), - ))); + let ty = RustType::borrow_of(None, Mut::Mutable, RustType::imported("Scope")); (name, ty) }; let arg1 = { @@ -298,7 +759,11 @@ fn decoder_fn(ix: usize, t: &RustType, decoder: &Decoder) -> RustFn { let ty = { let mut params = RustParams::::new(); params.push_lifetime(RustLt::Parametric("'input".into())); - RustType::verbatim("ReadCtxt", Some(params)) + RustType::borrow_of( + None, + Mut::Mutable, + RustType::verbatim("ParseCtxt", Some(params)), + ) }; (name, ty) }; @@ -306,260 +771,658 @@ fn decoder_fn(ix: usize, t: &RustType, decoder: &Decoder) -> RustFn { }; FnSig::new(args, Some(RustType::option_of(t.clone()))) }; - let body = decoder_body(decoder, t); + let ctxt = ProdCtxt { + input_varname: &Label::from("input"), + scope_varname: &Label::from("scope"), + }; + let (stmts, ret) = logic.to_ast(ctxt); + let body = stmts + .into_iter() + .chain(std::iter::once(RustStmt::Return( + false, + RustExpr::some(ret.unwrap()), + ))) + .collect(); RustFn::new(name, Some(params), sig, body) } +#[derive(Clone, Copy, Eq, PartialEq, Debug)] +enum ByteCriterion { + Any, + MustBe(u8), // singleton + OtherThan(u8), // negated singleton + WithinSet(ByteSet), // use embed_byteset to bridge to RustExpr +} + +impl From<&ByteSet> for ByteCriterion { + fn from(value: &ByteSet) -> Self { + if value.is_full() { + ByteCriterion::Any + } else { + match value.len() { + 1 => { + let elt = value.min_elem().expect("len == 1 but no min_elem"); + ByteCriterion::MustBe(elt) + } + 255 => { + let elt = (!value) + .min_elem() + .expect("len == 255 but no min_elem (on negation)"); + ByteCriterion::OtherThan(elt) + } + 2..=254 => ByteCriterion::WithinSet(*value), + other => unreachable!("unexpected byteset len in catch-all: {other}"), + } + } + } +} + +impl ByteCriterion { + /// Returns a tuple consisting of a RustExpr that evaluates to `true` if the argument satisfies the criterion + /// that `self` represents, and whose second element is a flag indicating whether the expression + /// is unconditionally true (and therefore may be elided in 'else-if' or case guard contexts) + fn as_predicate(&self, arg: RustExpr) -> (RustExpr, bool) { + match self { + ByteCriterion::Any => (RustExpr::TRUE, true), + ByteCriterion::MustBe(byte) => ( + RustExpr::Operation(RustOp::op_eq(arg, RustExpr::num_lit(*byte))), + false, + ), + ByteCriterion::OtherThan(byte) => ( + RustExpr::Operation(RustOp::op_neq(arg, RustExpr::num_lit(*byte))), + false, + ), + ByteCriterion::WithinSet(bs) => { + (embed_byteset(bs).call_method_with("contains", [arg]), false) + } + } + } +} + fn embed_byteset(bs: &ByteSet) -> RustExpr { - let [q0, q1, q2, q3] = bs.to_bits(); - RustExpr::scoped(["ByteSet"], "from_bits").call_with([RustExpr::ArrayLit(vec![ - RustExpr::NumericLit(q0 as usize), - RustExpr::NumericLit(q1 as usize), - RustExpr::NumericLit(q2 as usize), - RustExpr::NumericLit(q3 as usize), - ])]) -} - -// FIXME - implement something that actually works -fn invoke_decoder(decoder: &Decoder, input_varname: &Label) -> RustExpr { - match decoder { - Decoder::Align(factor) => { - // FIXME - this currently produces correct but inefficient code - // it is harder to write, but much more efficient, to cut the buffer at the right place - let cond = RustExpr::infix( - RustExpr::infix( - RustExpr::local("input").field("offset"), - " % ", - RustExpr::NumericLit(*factor), - ), - " != ", - RustExpr::NumericLit(0), - ); - let body = { - let let_tmp = RustStmt::assign( - "tmp", - RustExpr::local(input_varname.clone()) - .call_method("read_byte") - .wrap_try(), - ); - let rebind = - RustStmt::Reassign(input_varname.clone(), RustExpr::local("tmp").nth(1)); - vec![let_tmp, rebind] - }; - RustExpr::BlockScope( - vec![RustStmt::Control(RustControl::While(cond, body))], - Box::new(RustExpr::UNIT), - ) + if bs.is_full() { + RustExpr::scoped(["ByteSet"], "full").call() + } else if bs.len() == 1 { + let Some(elt) = bs.min_elem() else { + unreachable!("len == 1 but no min_elem") + }; + RustExpr::scoped(["ByteSet"], "singleton").call_with([RustExpr::num_lit(elt)]) + } else { + let [q0, q1, q2, q3] = bs.to_bits(); + RustExpr::scoped(["ByteSet"], "from_bits").call_with([RustExpr::ArrayLit(vec![ + RustExpr::num_lit(q0 as usize), + RustExpr::num_lit(q1 as usize), + RustExpr::num_lit(q2 as usize), + RustExpr::num_lit(q3 as usize), + ])]) + } +} + +impl From for RustExpr { + fn from(value: RustBlock) -> Self { + let (stmts, o_expr) = value; + let expr = o_expr.unwrap_or(RustExpr::UNIT); + if stmts.is_empty() { + expr + } else { + RustExpr::BlockScope(stmts, Box::new(expr)) } - Decoder::Fail => RustExpr::BlockScope( - vec![RustStmt::Return(true, RustExpr::NONE)], - Box::new(RustExpr::UNIT), - ), - Decoder::EndOfInput => { - let call = RustExpr::local(input_varname.clone()).call_method("read_byte"); - let bind = RustStmt::assign("tmp", call); - let cond = RustExpr::local("tmp").call_method("is_none"); - let b_true = [ - RustStmt::Reassign(input_varname.clone(), RustExpr::local("tmp").nth(1)), - RustStmt::Return(false, RustExpr::UNIT), - ]; - let b_false = [RustStmt::Return(true, RustExpr::NONE)]; - RustExpr::BlockScope( - vec![bind], - Box::new(RustExpr::Control(Box::new(RustControl::If( - cond, - b_true.to_vec(), - Some(b_false.to_vec()), - )))), - ) + } +} + +fn implicate_return(value: RustBlock) -> Vec { + let (mut stmts, o_expr) = value; + if let Some(expr) = o_expr { + stmts.push(RustStmt::Return(false, expr)) + } + stmts +} + +// follows the same rules as CaseLogic::to_ast as far as the expression type of the generated code +fn embed_matchtree(tree: &MatchTree, ctxt: ProdCtxt<'_>) -> RustBlock { + fn expand_matchtree(tree: &MatchTree, ctxt: ProdCtxt<'_>) -> RustBlock { + if tree.branches.is_empty() { + if let Some(ix) = tree.accept { + return (Vec::new(), Some(RustExpr::num_lit(ix))); + } else { + return (vec![RustStmt::Return(true, RustExpr::NONE)], None); + } } - Decoder::Byte(bs) => { - // FIXME - we have multiple options to handle this, none of them simple - let bs_let = RustStmt::assign("bs", embed_byteset(bs)); - - let call = RustExpr::local("input").call_method("read_byte").wrap_try(); - - let bind = RustStmt::assign("tmp", call); - let b_let = RustStmt::assign("b", RustExpr::local("tmp").nth(0)); - - let logic = { - let cond = - RustExpr::local("bs").call_method_with("contains", [RustExpr::local("b")]); - let b_true = vec![ - RustStmt::Reassign(input_varname.clone(), RustExpr::local("tmp").nth(1)), - RustStmt::Return(false, RustExpr::local("b")), - ]; - let b_false = vec![RustStmt::Return(true, RustExpr::local("None"))]; - RustExpr::Control(Box::new(RustControl::If(cond, b_true, Some(b_false)))) - }; - RustExpr::BlockScope([bs_let, bind, b_let].to_vec(), Box::new(logic)) + let bind = RustStmt::assign( + "b", + RustExpr::local(ctxt.input_varname.clone()) + .call_method("read_byte") + .wrap_try(), + ); + + if tree.branches.len() == 1 { + let (bs, branch) = tree.branches.first().unwrap(); + let (guard, always_true) = ByteCriterion::from(bs).as_predicate(RustExpr::local("b")); + if always_true { + // we have one non-accepting branch but it is unconditional + return expand_matchtree(branch, ctxt); + } else { + let b_true: Vec = implicate_return(expand_matchtree(branch, ctxt)); + let b_false = { + if let Some(ix) = tree.accept { + vec![RustStmt::Return(false, RustExpr::num_lit(ix))] + } else { + vec![RustStmt::Return(true, RustExpr::NONE)] + } + }; + return ( + vec![bind], + Some(RustExpr::Control(Box::new(RustControl::If( + guard, + b_true, + Some(b_false), + )))), + ); + } } - // FIXME - not sure what to do with _args ... - Decoder::Call(ix_dec, _args) => { - let fname = format!("Decoder{ix_dec}"); - let call = RustExpr::local(fname).call_with([ - RustExpr::local("scope"), - RustExpr::local(input_varname.clone()), - ]); - let bind = RustStmt::assign("tmp", call.wrap_try()); - let replace = RustStmt::Reassign(input_varname.clone(), RustExpr::local("tmp").nth(1)); - let ret = RustExpr::local("tmp").nth(0); - RustExpr::BlockScope(vec![bind, replace], Box::new(ret)) + + let mut cases = Vec::new(); + + for (bs, branch) in tree.branches.iter() { + let crit = ByteCriterion::from(bs); + match crit { + ByteCriterion::Any => { + unreachable!("unconditional descent with more than one branch") + } + ByteCriterion::MustBe(b) => { + let lhs = MatchCaseLHS::Pattern(RustPattern::PrimLiteral( + RustPrimLit::NumericLit(b as usize), + )); + let rhs = implicate_return(expand_matchtree(branch, ctxt)); + cases.push((lhs, rhs)) + } + ByteCriterion::OtherThan(_) | ByteCriterion::WithinSet(_) => { + let (guard, _) = crit.as_predicate(RustExpr::local("tmp")); + let lhs = MatchCaseLHS::WithGuard( + RustPattern::CatchAll(Some(Label::from("tmp"))), + guard, + ); + let rhs = implicate_return(expand_matchtree(branch, ctxt)); + cases.push((lhs, rhs)) + } + } } - _ => RustExpr::local("unimplemented!").call_with([RustExpr::str_lit("invoke_decoder")]), + let matchblock = RustControl::Match(RustExpr::local("b"), cases); + (vec![bind], Some(RustExpr::Control(Box::new(matchblock)))) } + + let b_lookahead = RustStmt::assign( + "lookahead", + RustExpr::BorrowMut(Box::new( + RustExpr::local(ctxt.input_varname.clone()).call_method("clone"), + )), + ); + let ll_context = ProdCtxt { + input_varname: &Label::from("lookahead"), + scope_varname: ctxt.scope_varname, + }; + + let (stmts, expr) = expand_matchtree(tree, ll_context); + ( + std::iter::once(b_lookahead) + .chain(stmts.into_iter()) + .collect(), + expr, + ) } /// Abstraction type use to sub-categorize different Decoders and ensure that the codegen layer /// is more resilient to changes both upstream (in the Decoder model) /// and downstream (in the API made available for generated code to use) #[derive(Clone, Debug)] -pub enum CaseLogic { +enum CaseLogic { Simple(SimpleLogic), Derived(DerivedLogic), Sequential(SequentialLogic), Parallel(ParallelLogic), + Repeat(RepeatLogic), Other(OtherLogic), + Unhandled(Label), // for generating a panic expression rather than panicking in codegen +} + +/// Cases where a constant block of logic is repeated (0 or more times) +#[derive(Clone, Debug)] +enum RepeatLogic { + ContinueOnMatch(MatchTree, Box), // evaluates a matchtree and continues if it is matched + BreakOnMatch(MatchTree, Box), // evaluates a matchtree and breaks if it is matched + ExactCount(RustExpr, Box), // repeats a specific numnber of times + ConditionTerminal(RustExpr, Box), // stops when a predicate for 'terminal element' is satisfied + ConditionComplete(RustExpr, Box), // stops when a predicate for 'complete sequence' is satisfied +} + +impl RepeatLogic { + fn to_ast(&self, ctxt: ProdCtxt<'_>) -> RustBlock { + match self { + RepeatLogic::ContinueOnMatch(ctree, elt) => { + let mut stmts = Vec::new(); + + let elt_expr = elt.to_ast(ctxt).into(); + + stmts.push(RustStmt::Let( + Mut::Mutable, + Label::from("accum"), + None, + RustExpr::scoped(["Vec"], "new").call(), + )); + let ctrl = { + let tree_index_expr: RustExpr = embed_matchtree(ctree, ctxt).into(); + let bind_ix = RustStmt::assign("matching_ix", tree_index_expr); + let cond = RustExpr::infix( + RustExpr::local("matching_ix"), + Operator::Eq, + RustExpr::num_lit(0usize), + ); + let b_continue = [ + RustStmt::assign("next_elem", elt_expr), + RustStmt::Expr( + RustExpr::local("accum") + .call_method_with("push", [RustExpr::local("next_elem")]), + ), + ] + .to_vec(); + let b_stop = [RustStmt::Control(RustControl::Break)].to_vec(); + let escape_clause = RustControl::If(cond, b_continue, Some(b_stop)); + RustStmt::Control(RustControl::While( + RustExpr::TRUE, + vec![bind_ix, RustStmt::Control(escape_clause)], + )) + }; + stmts.push(ctrl); + (stmts, Some(RustExpr::local("accum"))) + } + RepeatLogic::BreakOnMatch(btree, elt) => { + let mut stmts = Vec::new(); + + let elt_expr = elt.to_ast(ctxt).into(); + + stmts.push(RustStmt::Let( + Mut::Mutable, + Label::from("accum"), + None, + RustExpr::scoped(["Vec"], "new").call(), + )); + let ctrl = { + let tree_index_expr: RustExpr = embed_matchtree(btree, ctxt).into(); + let bind_ix = RustStmt::assign("matching_ix", tree_index_expr); + let cond = RustExpr::infix( + RustExpr::local("matching_ix"), + Operator::Eq, + RustExpr::num_lit(0usize), + ); + let b_continue = [ + RustStmt::assign("next_elem", elt_expr), + RustStmt::Expr( + RustExpr::local("accum") + .call_method_with("push", [RustExpr::local("next_elem")]), + ), + ] + .to_vec(); + let b_stop = [RustStmt::Control(RustControl::Break)].to_vec(); + let escape_clause = RustControl::If(cond, b_stop, Some(b_continue)); + RustStmt::Control(RustControl::While( + RustExpr::TRUE, + vec![bind_ix, RustStmt::Control(escape_clause)], + )) + }; + stmts.push(ctrl); + (stmts, Some(RustExpr::local("accum"))) + } + RepeatLogic::ExactCount(expr_n, elt) => { + let mut stmts = Vec::new(); + + let elt_expr = elt.to_ast(ctxt).into(); + + stmts.push(RustStmt::Let( + Mut::Mutable, + Label::from("accum"), + None, + RustExpr::scoped(["Vec"], "new").call(), + )); + // N non-loop blocks rather than 1 block representing an N-iteration loop + let body = vec![RustStmt::Expr( + RustExpr::local("accum").call_method_with("push", [elt_expr]), + )]; + stmts.push(RustStmt::Control(RustControl::ForRange0( + Label::from("_"), + expr_n.clone(), + body, + ))); + + (stmts, Some(RustExpr::local("accum"))) + } + RepeatLogic::ConditionTerminal(tpred, elt) => { + let mut stmts = Vec::new(); + let elt_expr = elt.to_ast(ctxt).into(); + + stmts.push(RustStmt::Let( + Mut::Mutable, + Label::from("accum"), + None, + RustExpr::scoped(["Vec"], "new").call(), + )); + let ctrl = { + let elt_bind = RustStmt::assign("elem", elt_expr); + let cond = tpred + .clone() + .call() + .call_with([RustExpr::Borrow(Box::new(RustExpr::local("elem")))]); + let b_terminal = [ + RustStmt::Expr( + RustExpr::local("accum") + .call_method_with("push", [RustExpr::local("elem")]), + ), + RustStmt::Control(RustControl::Break), + ] + .to_vec(); + let b_else = [RustStmt::Expr( + RustExpr::local("accum") + .call_method_with("push", [RustExpr::local("elem")]), + )] + .to_vec(); + let escape_clause = RustControl::If(cond, b_terminal, Some(b_else)); + RustStmt::Control(RustControl::While( + RustExpr::TRUE, + vec![elt_bind, RustStmt::Control(escape_clause)], + )) + }; + stmts.push(ctrl); + (stmts, Some(RustExpr::local("accum"))) + } + RepeatLogic::ConditionComplete(cpred, elt) => { + let mut stmts = Vec::new(); + let elt_expr = elt.to_ast(ctxt).into(); + + stmts.push(RustStmt::Let( + Mut::Mutable, + Label::from("accum"), + None, + RustExpr::scoped(["Vec"], "new").call(), + )); + let ctrl = { + let elt_bind = RustStmt::assign("elem", elt_expr); + let elt_push = RustStmt::Expr( + RustExpr::local("accum") + .call_method_with("push", [RustExpr::local("elem")]), + ); + let cond = cpred + .clone() + .call() + .call_with([RustExpr::Borrow(Box::new(RustExpr::local("accum")))]); + let b_terminal = [RustStmt::Control(RustControl::Break)].to_vec(); + let escape_clause = RustControl::If(cond, b_terminal, None); + RustStmt::Control(RustControl::While( + RustExpr::TRUE, + vec![elt_bind, elt_push, RustStmt::Control(escape_clause)], + )) + }; + stmts.push(ctrl); + (stmts, Some(RustExpr::local("accum"))) + } + } + } } /// Cases that apply other case-logic in sequence to an incrementally updated input #[derive(Clone, Debug)] -pub enum SequentialLogic { +enum SequentialLogic { AccumTuple { - constructor: Option