From 7a43396cfb617d5355df999d2e4f19250bebf996 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Wed, 20 Jul 2022 00:01:38 +0200 Subject: [PATCH 001/198] redesign adn adapt rust's generation --- .../specgenerators/RustSG.scala | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 560f93c76..5cff6e73e 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -15,19 +15,27 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def fileName(name: String): String = s"test_$name.rs" override def header(): Unit = { - out.puts("extern crate kaitai_struct;") - out.puts(s"extern crate rust;") - out.puts - - out.puts("use kaitai_struct::KaitaiStruct;") - out.puts(s"use rust::$className;") - out.puts + val code = + s""" + |#[cfg(test)] + |mod tests { + | extern crate kaitai_struct; + | use std::fs; + | + | use kaitai_struct::*; + | use crate::rust::${spec.id}::*; + | + | #[test] + | fn test_${spec.id}() { + | let bytes = fs::read("src/${spec.data}").unwrap(); + | let mut reader = BytesReader::new(&bytes); + | let mut r = $className::default(); + | + | r.read(&mut reader, None, None).unwrap(); + |""".stripMargin - out.puts("#[test]") - out.puts(s"fn test_${spec.id}() {") + out.puts(code) out.inc - - out.puts("if let Ok(r) = " + className + "::from_file(\"src/" + spec.data + "\") {") out.inc } @@ -40,7 +48,10 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def simpleAssert(check: TestAssert): Unit = { val actStr = translateAct(check.actual) - val expStr = translator.translate(check.expected) + var expStr = translator.translate(check.expected) + if (expStr.toLowerCase.startsWith("enum")) { + expStr = s"Some($expStr)" + } out.puts(s"assert_eq!($actStr, $expStr);") } From 999209f1b0f69d2426530fa00010011a33516448 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Thu, 21 Jul 2022 21:23:15 +0200 Subject: [PATCH 002/198] compiled *.ksy from `formats\` --- spec/rust/formats/bcd_user_type_be.rs | 558 ++++++++++++++++++ spec/rust/formats/bcd_user_type_le.rs | 558 ++++++++++++++++++ spec/rust/formats/bits_byte_aligned.rs | 61 ++ spec/rust/formats/bits_enum.rs | 65 ++ spec/rust/formats/bits_seq_endian_combo.rs | 55 ++ spec/rust/formats/bits_shift_by_b32_le.rs | 43 ++ spec/rust/formats/bits_shift_by_b64_le.rs | 43 ++ spec/rust/formats/bits_signed_res_b32_be.rs | 41 ++ spec/rust/formats/bits_signed_res_b32_le.rs | 41 ++ spec/rust/formats/bits_signed_shift_b32_le.rs | 43 ++ spec/rust/formats/bits_signed_shift_b64_le.rs | 43 ++ spec/rust/formats/bits_simple.rs | 82 +++ spec/rust/formats/bits_simple_le.rs | 82 +++ spec/rust/formats/bits_unaligned_b32_be.rs | 45 ++ spec/rust/formats/bits_unaligned_b32_le.rs | 45 ++ spec/rust/formats/bits_unaligned_b64_be.rs | 45 ++ spec/rust/formats/bits_unaligned_b64_le.rs | 45 ++ spec/rust/formats/buffered_struct.rs | 88 +++ spec/rust/formats/bytes_pad_term.rs | 47 ++ spec/rust/formats/cast_nested.rs | 224 +++++++ spec/rust/formats/cast_to_imported.rs | 55 ++ spec/rust/formats/cast_to_top.rs | 69 +++ spec/rust/formats/combine_bool.rs | 67 +++ spec/rust/formats/combine_bytes.rs | 136 +++++ spec/rust/formats/combine_enum.rs | 72 +++ spec/rust/formats/combine_str.rs | 214 +++++++ spec/rust/formats/debug_0.rs | 49 ++ spec/rust/formats/default_big_endian.rs | 41 ++ spec/rust/formats/default_bit_endian_mod.rs | 147 +++++ .../formats/default_endian_expr_exception.rs | 119 ++++ .../formats/default_endian_expr_inherited.rs | 200 +++++++ .../rust/formats/default_endian_expr_is_be.rs | 182 ++++++ .../rust/formats/default_endian_expr_is_le.rs | 119 ++++ spec/rust/formats/default_endian_mod.rs | 144 +++++ spec/rust/formats/docstrings.rs | 105 ++++ spec/rust/formats/docstrings_docref.rs | 79 +++ spec/rust/formats/docstrings_docref_multi.rs | 40 ++ spec/rust/formats/enum_0.rs | 61 ++ spec/rust/formats/enum_1.rs | 127 ++++ spec/rust/formats/enum_deep.rs | 141 +++++ spec/rust/formats/enum_deep_literals.rs | 167 ++++++ spec/rust/formats/enum_fancy.rs | 63 ++ spec/rust/formats/enum_for_unknown_id.rs | 59 ++ spec/rust/formats/enum_if.rs | 174 ++++++ spec/rust/formats/enum_import.rs | 43 ++ spec/rust/formats/enum_int_range_s.rs | 63 ++ spec/rust/formats/enum_int_range_u.rs | 59 ++ spec/rust/formats/enum_invalid.rs | 59 ++ spec/rust/formats/enum_long_range_s.rs | 79 +++ spec/rust/formats/enum_long_range_u.rs | 67 +++ spec/rust/formats/enum_negative.rs | 59 ++ spec/rust/formats/enum_of_value_inst.rs | 87 +++ spec/rust/formats/enum_to_i.rs | 126 ++++ spec/rust/formats/enum_to_i_class_border_1.rs | 90 +++ spec/rust/formats/enum_to_i_class_border_2.rs | 54 ++ spec/rust/formats/eof_exception_bytes.rs | 41 ++ spec/rust/formats/eof_exception_u4.rs | 43 ++ spec/rust/formats/eos_exception_bytes.rs | 76 +++ spec/rust/formats/eos_exception_u4.rs | 78 +++ spec/rust/formats/expr_0.rs | 67 +++ spec/rust/formats/expr_1.rs | 69 +++ spec/rust/formats/expr_2.rs | 266 +++++++++ spec/rust/formats/expr_3.rs | 173 ++++++ spec/rust/formats/expr_array.rs | 252 ++++++++ spec/rust/formats/expr_bits.rs | 148 +++++ spec/rust/formats/expr_bytes_cmp.rs | 186 ++++++ spec/rust/formats/expr_bytes_non_literal.rs | 56 ++ spec/rust/formats/expr_bytes_ops.rs | 210 +++++++ spec/rust/formats/expr_enum.rs | 100 ++++ spec/rust/formats/expr_if_int_ops.rs | 77 +++ spec/rust/formats/expr_int_div.rs | 95 +++ spec/rust/formats/expr_io_eof.rs | 98 +++ spec/rust/formats/expr_io_pos.rs | 84 +++ spec/rust/formats/expr_mod.rs | 95 +++ spec/rust/formats/expr_ops_parens.rs | 234 ++++++++ spec/rust/formats/expr_sizeof_type_0.rs | 89 +++ spec/rust/formats/expr_sizeof_type_1.rs | 137 +++++ spec/rust/formats/expr_sizeof_value_0.rs | 145 +++++ spec/rust/formats/expr_sizeof_value_sized.rs | 147 +++++ spec/rust/formats/expr_str_encodings.rs | 146 +++++ spec/rust/formats/expr_str_ops.rs | 249 ++++++++ spec/rust/formats/fixed_contents.rs | 43 ++ spec/rust/formats/fixed_struct.rs | 139 +++++ spec/rust/formats/float_to_i.rs | 173 ++++++ spec/rust/formats/floating_points.rs | 88 +++ spec/rust/formats/hello_world.rs | 41 ++ spec/rust/formats/if_instances.rs | 57 ++ spec/rust/formats/if_struct.rs | 158 +++++ spec/rust/formats/if_values.rs | 94 +++ spec/rust/formats/imported_1.rs | 44 ++ spec/rust/formats/imported_2.rs | 41 ++ spec/rust/formats/imports0.rs | 57 ++ spec/rust/formats/imports_circular_a.rs | 44 ++ spec/rust/formats/imports_circular_b.rs | 47 ++ spec/rust/formats/imports_rel_1.rs | 44 ++ spec/rust/formats/index_sizes.rs | 53 ++ spec/rust/formats/index_to_param_eos.rs | 89 +++ spec/rust/formats/index_to_param_expr.rs | 87 +++ spec/rust/formats/index_to_param_until.rs | 88 +++ spec/rust/formats/instance_std.rs | 54 ++ spec/rust/formats/instance_std_array.rs | 65 ++ spec/rust/formats/instance_user_array.rs | 106 ++++ spec/rust/formats/integers.rs | 93 +++ spec/rust/formats/integers_double_overflow.rs | 115 ++++ spec/rust/formats/integers_min_max.rs | 137 +++++ spec/rust/formats/io_local_var.rs | 122 ++++ spec/rust/formats/js_signed_right_shift.rs | 65 ++ spec/rust/formats/meta_tags.rs | 39 ++ spec/rust/formats/meta_xref.rs | 39 ++ spec/rust/formats/multiple_use.rs | 155 +++++ spec/rust/formats/nav_parent.rs | 150 +++++ spec/rust/formats/nav_parent2.rs | 149 +++++ spec/rust/formats/nav_parent3.rs | 163 +++++ spec/rust/formats/nav_parent_false.rs | 151 +++++ spec/rust/formats/nav_parent_false2.rs | 74 +++ spec/rust/formats/nav_parent_override.rs | 111 ++++ spec/rust/formats/nav_parent_switch.rs | 129 ++++ spec/rust/formats/nav_parent_switch_cast.rs | 224 +++++++ spec/rust/formats/nav_parent_vs_value_inst.rs | 87 +++ spec/rust/formats/nav_root.rs | 150 +++++ spec/rust/formats/nested_same_name.rs | 173 ++++++ spec/rust/formats/nested_same_name2.rs | 181 ++++++ spec/rust/formats/nested_type_param.rs | 106 ++++ spec/rust/formats/nested_types.rs | 144 +++++ spec/rust/formats/nested_types2.rs | 218 +++++++ spec/rust/formats/nested_types3.rs | 210 +++++++ spec/rust/formats/non_standard.rs | 95 +++ spec/rust/formats/opaque_external_type.rs | 42 ++ .../formats/opaque_external_type_02_child.rs | 94 +++ .../formats/opaque_external_type_02_parent.rs | 75 +++ spec/rust/formats/opaque_with_param.rs | 42 ++ spec/rust/formats/optional_id.rs | 45 ++ spec/rust/formats/params_call_extra_parens.rs | 75 +++ spec/rust/formats/params_call_short.rs | 117 ++++ spec/rust/formats/params_def.rs | 48 ++ spec/rust/formats/params_enum.rs | 106 ++++ .../formats/params_pass_array_usertype.rs | 116 ++++ spec/rust/formats/params_pass_bool.rs | 150 +++++ spec/rust/formats/params_pass_usertype.rs | 110 ++++ spec/rust/formats/position_abs.rs | 89 +++ spec/rust/formats/position_in_seq.rs | 93 +++ spec/rust/formats/position_to_end.rs | 89 +++ spec/rust/formats/process_coerce_bytes.rs | 103 ++++ spec/rust/formats/process_coerce_usertype1.rs | 141 +++++ spec/rust/formats/process_coerce_usertype2.rs | 139 +++++ spec/rust/formats/process_custom.rs | 53 ++ spec/rust/formats/process_custom_no_args.rs | 43 ++ spec/rust/formats/process_repeat_bytes.rs | 48 ++ spec/rust/formats/process_repeat_usertype.rs | 86 +++ spec/rust/formats/process_rotate.rs | 53 ++ spec/rust/formats/process_to_user.rs | 79 +++ spec/rust/formats/process_xor4_const.rs | 45 ++ spec/rust/formats/process_xor4_value.rs | 45 ++ spec/rust/formats/process_xor_const.rs | 45 ++ spec/rust/formats/process_xor_value.rs | 45 ++ spec/rust/formats/recursive_one.rs | 106 ++++ spec/rust/formats/repeat_eos_bit.rs | 47 ++ spec/rust/formats/repeat_eos_struct.rs | 82 +++ spec/rust/formats/repeat_eos_u4.rs | 47 ++ spec/rust/formats/repeat_n_struct.rs | 82 +++ spec/rust/formats/repeat_n_strz.rs | 47 ++ spec/rust/formats/repeat_n_strz_double.rs | 53 ++ spec/rust/formats/repeat_until_complex.rs | 138 +++++ spec/rust/formats/repeat_until_s4.rs | 48 ++ spec/rust/formats/repeat_until_sized.rs | 84 +++ spec/rust/formats/str_encodings.rs | 55 ++ spec/rust/formats/str_encodings_default.rs | 88 +++ spec/rust/formats/str_encodings_utf16.rs | 121 ++++ spec/rust/formats/str_eos.rs | 41 ++ spec/rust/formats/str_literals.rs | 104 ++++ spec/rust/formats/str_literals2.rs | 91 +++ spec/rust/formats/str_pad_term.rs | 47 ++ spec/rust/formats/str_pad_term_empty.rs | 47 ++ spec/rust/formats/switch_bytearray.rs | 172 ++++++ spec/rust/formats/switch_cast.rs | 211 +++++++ spec/rust/formats/switch_else_only.rs | 100 ++++ spec/rust/formats/switch_integers.rs | 124 ++++ spec/rust/formats/switch_integers2.rs | 105 ++++ spec/rust/formats/switch_manual_enum.rs | 188 ++++++ .../formats/switch_manual_enum_invalid.rs | 188 ++++++ .../switch_manual_enum_invalid_else.rs | 241 ++++++++ spec/rust/formats/switch_manual_int.rs | 172 ++++++ spec/rust/formats/switch_manual_int_else.rs | 214 +++++++ spec/rust/formats/switch_manual_int_size.rs | 194 ++++++ .../formats/switch_manual_int_size_else.rs | 228 +++++++ spec/rust/formats/switch_manual_str.rs | 172 ++++++ spec/rust/formats/switch_manual_str_else.rs | 214 +++++++ spec/rust/formats/switch_multi_bool_ops.rs | 124 ++++ spec/rust/formats/switch_repeat_expr.rs | 153 +++++ .../formats/switch_repeat_expr_invalid.rs | 153 +++++ spec/rust/formats/term_bytes.rs | 45 ++ spec/rust/formats/term_strz.rs | 45 ++ spec/rust/formats/term_u1_val.rs | 43 ++ spec/rust/formats/to_string_custom.rs | 43 ++ spec/rust/formats/ts_packet_header.rs | 79 +++ spec/rust/formats/type_int_unary_op.rs | 69 +++ spec/rust/formats/type_ternary.rs | 125 ++++ spec/rust/formats/type_ternary_opaque.rs | 83 +++ spec/rust/formats/user_type.rs | 76 +++ spec/rust/formats/valid_eq_str_encodings.rs | 55 ++ spec/rust/formats/valid_fail_anyof_int.rs | 41 ++ spec/rust/formats/valid_fail_contents.rs | 41 ++ spec/rust/formats/valid_fail_eq_bytes.rs | 41 ++ spec/rust/formats/valid_fail_eq_int.rs | 41 ++ spec/rust/formats/valid_fail_eq_str.rs | 41 ++ spec/rust/formats/valid_fail_expr.rs | 45 ++ spec/rust/formats/valid_fail_inst.rs | 59 ++ spec/rust/formats/valid_fail_max_int.rs | 41 ++ spec/rust/formats/valid_fail_min_int.rs | 41 ++ spec/rust/formats/valid_fail_range_bytes.rs | 41 ++ spec/rust/formats/valid_fail_range_float.rs | 41 ++ spec/rust/formats/valid_fail_range_int.rs | 41 ++ spec/rust/formats/valid_fail_range_str.rs | 41 ++ spec/rust/formats/valid_long.rs | 61 ++ spec/rust/formats/valid_not_parsed_if.rs | 49 ++ spec/rust/formats/valid_optional_id.rs | 46 ++ spec/rust/formats/valid_short.rs | 61 ++ spec/rust/formats/valid_switch.rs | 67 +++ spec/rust/formats/yaml_ints.rs | 91 +++ spec/rust/formats/zlib_surrounded.rs | 83 +++ spec/rust/formats/zlib_with_header_78.rs | 43 ++ 221 files changed, 22139 insertions(+) create mode 100644 spec/rust/formats/bcd_user_type_be.rs create mode 100644 spec/rust/formats/bcd_user_type_le.rs create mode 100644 spec/rust/formats/bits_byte_aligned.rs create mode 100644 spec/rust/formats/bits_enum.rs create mode 100644 spec/rust/formats/bits_seq_endian_combo.rs create mode 100644 spec/rust/formats/bits_shift_by_b32_le.rs create mode 100644 spec/rust/formats/bits_shift_by_b64_le.rs create mode 100644 spec/rust/formats/bits_signed_res_b32_be.rs create mode 100644 spec/rust/formats/bits_signed_res_b32_le.rs create mode 100644 spec/rust/formats/bits_signed_shift_b32_le.rs create mode 100644 spec/rust/formats/bits_signed_shift_b64_le.rs create mode 100644 spec/rust/formats/bits_simple.rs create mode 100644 spec/rust/formats/bits_simple_le.rs create mode 100644 spec/rust/formats/bits_unaligned_b32_be.rs create mode 100644 spec/rust/formats/bits_unaligned_b32_le.rs create mode 100644 spec/rust/formats/bits_unaligned_b64_be.rs create mode 100644 spec/rust/formats/bits_unaligned_b64_le.rs create mode 100644 spec/rust/formats/buffered_struct.rs create mode 100644 spec/rust/formats/bytes_pad_term.rs create mode 100644 spec/rust/formats/cast_nested.rs create mode 100644 spec/rust/formats/cast_to_imported.rs create mode 100644 spec/rust/formats/cast_to_top.rs create mode 100644 spec/rust/formats/combine_bool.rs create mode 100644 spec/rust/formats/combine_bytes.rs create mode 100644 spec/rust/formats/combine_enum.rs create mode 100644 spec/rust/formats/combine_str.rs create mode 100644 spec/rust/formats/debug_0.rs create mode 100644 spec/rust/formats/default_big_endian.rs create mode 100644 spec/rust/formats/default_bit_endian_mod.rs create mode 100644 spec/rust/formats/default_endian_expr_exception.rs create mode 100644 spec/rust/formats/default_endian_expr_inherited.rs create mode 100644 spec/rust/formats/default_endian_expr_is_be.rs create mode 100644 spec/rust/formats/default_endian_expr_is_le.rs create mode 100644 spec/rust/formats/default_endian_mod.rs create mode 100644 spec/rust/formats/docstrings.rs create mode 100644 spec/rust/formats/docstrings_docref.rs create mode 100644 spec/rust/formats/docstrings_docref_multi.rs create mode 100644 spec/rust/formats/enum_0.rs create mode 100644 spec/rust/formats/enum_1.rs create mode 100644 spec/rust/formats/enum_deep.rs create mode 100644 spec/rust/formats/enum_deep_literals.rs create mode 100644 spec/rust/formats/enum_fancy.rs create mode 100644 spec/rust/formats/enum_for_unknown_id.rs create mode 100644 spec/rust/formats/enum_if.rs create mode 100644 spec/rust/formats/enum_import.rs create mode 100644 spec/rust/formats/enum_int_range_s.rs create mode 100644 spec/rust/formats/enum_int_range_u.rs create mode 100644 spec/rust/formats/enum_invalid.rs create mode 100644 spec/rust/formats/enum_long_range_s.rs create mode 100644 spec/rust/formats/enum_long_range_u.rs create mode 100644 spec/rust/formats/enum_negative.rs create mode 100644 spec/rust/formats/enum_of_value_inst.rs create mode 100644 spec/rust/formats/enum_to_i.rs create mode 100644 spec/rust/formats/enum_to_i_class_border_1.rs create mode 100644 spec/rust/formats/enum_to_i_class_border_2.rs create mode 100644 spec/rust/formats/eof_exception_bytes.rs create mode 100644 spec/rust/formats/eof_exception_u4.rs create mode 100644 spec/rust/formats/eos_exception_bytes.rs create mode 100644 spec/rust/formats/eos_exception_u4.rs create mode 100644 spec/rust/formats/expr_0.rs create mode 100644 spec/rust/formats/expr_1.rs create mode 100644 spec/rust/formats/expr_2.rs create mode 100644 spec/rust/formats/expr_3.rs create mode 100644 spec/rust/formats/expr_array.rs create mode 100644 spec/rust/formats/expr_bits.rs create mode 100644 spec/rust/formats/expr_bytes_cmp.rs create mode 100644 spec/rust/formats/expr_bytes_non_literal.rs create mode 100644 spec/rust/formats/expr_bytes_ops.rs create mode 100644 spec/rust/formats/expr_enum.rs create mode 100644 spec/rust/formats/expr_if_int_ops.rs create mode 100644 spec/rust/formats/expr_int_div.rs create mode 100644 spec/rust/formats/expr_io_eof.rs create mode 100644 spec/rust/formats/expr_io_pos.rs create mode 100644 spec/rust/formats/expr_mod.rs create mode 100644 spec/rust/formats/expr_ops_parens.rs create mode 100644 spec/rust/formats/expr_sizeof_type_0.rs create mode 100644 spec/rust/formats/expr_sizeof_type_1.rs create mode 100644 spec/rust/formats/expr_sizeof_value_0.rs create mode 100644 spec/rust/formats/expr_sizeof_value_sized.rs create mode 100644 spec/rust/formats/expr_str_encodings.rs create mode 100644 spec/rust/formats/expr_str_ops.rs create mode 100644 spec/rust/formats/fixed_contents.rs create mode 100644 spec/rust/formats/fixed_struct.rs create mode 100644 spec/rust/formats/float_to_i.rs create mode 100644 spec/rust/formats/floating_points.rs create mode 100644 spec/rust/formats/hello_world.rs create mode 100644 spec/rust/formats/if_instances.rs create mode 100644 spec/rust/formats/if_struct.rs create mode 100644 spec/rust/formats/if_values.rs create mode 100644 spec/rust/formats/imported_1.rs create mode 100644 spec/rust/formats/imported_2.rs create mode 100644 spec/rust/formats/imports0.rs create mode 100644 spec/rust/formats/imports_circular_a.rs create mode 100644 spec/rust/formats/imports_circular_b.rs create mode 100644 spec/rust/formats/imports_rel_1.rs create mode 100644 spec/rust/formats/index_sizes.rs create mode 100644 spec/rust/formats/index_to_param_eos.rs create mode 100644 spec/rust/formats/index_to_param_expr.rs create mode 100644 spec/rust/formats/index_to_param_until.rs create mode 100644 spec/rust/formats/instance_std.rs create mode 100644 spec/rust/formats/instance_std_array.rs create mode 100644 spec/rust/formats/instance_user_array.rs create mode 100644 spec/rust/formats/integers.rs create mode 100644 spec/rust/formats/integers_double_overflow.rs create mode 100644 spec/rust/formats/integers_min_max.rs create mode 100644 spec/rust/formats/io_local_var.rs create mode 100644 spec/rust/formats/js_signed_right_shift.rs create mode 100644 spec/rust/formats/meta_tags.rs create mode 100644 spec/rust/formats/meta_xref.rs create mode 100644 spec/rust/formats/multiple_use.rs create mode 100644 spec/rust/formats/nav_parent.rs create mode 100644 spec/rust/formats/nav_parent2.rs create mode 100644 spec/rust/formats/nav_parent3.rs create mode 100644 spec/rust/formats/nav_parent_false.rs create mode 100644 spec/rust/formats/nav_parent_false2.rs create mode 100644 spec/rust/formats/nav_parent_override.rs create mode 100644 spec/rust/formats/nav_parent_switch.rs create mode 100644 spec/rust/formats/nav_parent_switch_cast.rs create mode 100644 spec/rust/formats/nav_parent_vs_value_inst.rs create mode 100644 spec/rust/formats/nav_root.rs create mode 100644 spec/rust/formats/nested_same_name.rs create mode 100644 spec/rust/formats/nested_same_name2.rs create mode 100644 spec/rust/formats/nested_type_param.rs create mode 100644 spec/rust/formats/nested_types.rs create mode 100644 spec/rust/formats/nested_types2.rs create mode 100644 spec/rust/formats/nested_types3.rs create mode 100644 spec/rust/formats/non_standard.rs create mode 100644 spec/rust/formats/opaque_external_type.rs create mode 100644 spec/rust/formats/opaque_external_type_02_child.rs create mode 100644 spec/rust/formats/opaque_external_type_02_parent.rs create mode 100644 spec/rust/formats/opaque_with_param.rs create mode 100644 spec/rust/formats/optional_id.rs create mode 100644 spec/rust/formats/params_call_extra_parens.rs create mode 100644 spec/rust/formats/params_call_short.rs create mode 100644 spec/rust/formats/params_def.rs create mode 100644 spec/rust/formats/params_enum.rs create mode 100644 spec/rust/formats/params_pass_array_usertype.rs create mode 100644 spec/rust/formats/params_pass_bool.rs create mode 100644 spec/rust/formats/params_pass_usertype.rs create mode 100644 spec/rust/formats/position_abs.rs create mode 100644 spec/rust/formats/position_in_seq.rs create mode 100644 spec/rust/formats/position_to_end.rs create mode 100644 spec/rust/formats/process_coerce_bytes.rs create mode 100644 spec/rust/formats/process_coerce_usertype1.rs create mode 100644 spec/rust/formats/process_coerce_usertype2.rs create mode 100644 spec/rust/formats/process_custom.rs create mode 100644 spec/rust/formats/process_custom_no_args.rs create mode 100644 spec/rust/formats/process_repeat_bytes.rs create mode 100644 spec/rust/formats/process_repeat_usertype.rs create mode 100644 spec/rust/formats/process_rotate.rs create mode 100644 spec/rust/formats/process_to_user.rs create mode 100644 spec/rust/formats/process_xor4_const.rs create mode 100644 spec/rust/formats/process_xor4_value.rs create mode 100644 spec/rust/formats/process_xor_const.rs create mode 100644 spec/rust/formats/process_xor_value.rs create mode 100644 spec/rust/formats/recursive_one.rs create mode 100644 spec/rust/formats/repeat_eos_bit.rs create mode 100644 spec/rust/formats/repeat_eos_struct.rs create mode 100644 spec/rust/formats/repeat_eos_u4.rs create mode 100644 spec/rust/formats/repeat_n_struct.rs create mode 100644 spec/rust/formats/repeat_n_strz.rs create mode 100644 spec/rust/formats/repeat_n_strz_double.rs create mode 100644 spec/rust/formats/repeat_until_complex.rs create mode 100644 spec/rust/formats/repeat_until_s4.rs create mode 100644 spec/rust/formats/repeat_until_sized.rs create mode 100644 spec/rust/formats/str_encodings.rs create mode 100644 spec/rust/formats/str_encodings_default.rs create mode 100644 spec/rust/formats/str_encodings_utf16.rs create mode 100644 spec/rust/formats/str_eos.rs create mode 100644 spec/rust/formats/str_literals.rs create mode 100644 spec/rust/formats/str_literals2.rs create mode 100644 spec/rust/formats/str_pad_term.rs create mode 100644 spec/rust/formats/str_pad_term_empty.rs create mode 100644 spec/rust/formats/switch_bytearray.rs create mode 100644 spec/rust/formats/switch_cast.rs create mode 100644 spec/rust/formats/switch_else_only.rs create mode 100644 spec/rust/formats/switch_integers.rs create mode 100644 spec/rust/formats/switch_integers2.rs create mode 100644 spec/rust/formats/switch_manual_enum.rs create mode 100644 spec/rust/formats/switch_manual_enum_invalid.rs create mode 100644 spec/rust/formats/switch_manual_enum_invalid_else.rs create mode 100644 spec/rust/formats/switch_manual_int.rs create mode 100644 spec/rust/formats/switch_manual_int_else.rs create mode 100644 spec/rust/formats/switch_manual_int_size.rs create mode 100644 spec/rust/formats/switch_manual_int_size_else.rs create mode 100644 spec/rust/formats/switch_manual_str.rs create mode 100644 spec/rust/formats/switch_manual_str_else.rs create mode 100644 spec/rust/formats/switch_multi_bool_ops.rs create mode 100644 spec/rust/formats/switch_repeat_expr.rs create mode 100644 spec/rust/formats/switch_repeat_expr_invalid.rs create mode 100644 spec/rust/formats/term_bytes.rs create mode 100644 spec/rust/formats/term_strz.rs create mode 100644 spec/rust/formats/term_u1_val.rs create mode 100644 spec/rust/formats/to_string_custom.rs create mode 100644 spec/rust/formats/ts_packet_header.rs create mode 100644 spec/rust/formats/type_int_unary_op.rs create mode 100644 spec/rust/formats/type_ternary.rs create mode 100644 spec/rust/formats/type_ternary_opaque.rs create mode 100644 spec/rust/formats/user_type.rs create mode 100644 spec/rust/formats/valid_eq_str_encodings.rs create mode 100644 spec/rust/formats/valid_fail_anyof_int.rs create mode 100644 spec/rust/formats/valid_fail_contents.rs create mode 100644 spec/rust/formats/valid_fail_eq_bytes.rs create mode 100644 spec/rust/formats/valid_fail_eq_int.rs create mode 100644 spec/rust/formats/valid_fail_eq_str.rs create mode 100644 spec/rust/formats/valid_fail_expr.rs create mode 100644 spec/rust/formats/valid_fail_inst.rs create mode 100644 spec/rust/formats/valid_fail_max_int.rs create mode 100644 spec/rust/formats/valid_fail_min_int.rs create mode 100644 spec/rust/formats/valid_fail_range_bytes.rs create mode 100644 spec/rust/formats/valid_fail_range_float.rs create mode 100644 spec/rust/formats/valid_fail_range_int.rs create mode 100644 spec/rust/formats/valid_fail_range_str.rs create mode 100644 spec/rust/formats/valid_long.rs create mode 100644 spec/rust/formats/valid_not_parsed_if.rs create mode 100644 spec/rust/formats/valid_optional_id.rs create mode 100644 spec/rust/formats/valid_short.rs create mode 100644 spec/rust/formats/valid_switch.rs create mode 100644 spec/rust/formats/yaml_ints.rs create mode 100644 spec/rust/formats/zlib_surrounded.rs create mode 100644 spec/rust/formats/zlib_with_header_78.rs diff --git a/spec/rust/formats/bcd_user_type_be.rs b/spec/rust/formats/bcd_user_type_be.rs new file mode 100644 index 000000000..76e680b1b --- /dev/null +++ b/spec/rust/formats/bcd_user_type_be.rs @@ -0,0 +1,558 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(ltr)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(rtl)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(leading_zero_ltr)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeBe { + pub ltr: Option, + pub rtl: Option, + pub leading_zero_ltr: Option, + pub raw_ltr: Vec, + pub raw_rtl: Vec, + pub raw_leading_zero_ltr: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + self.rtl = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + self.leading_zero_ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeBe { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeBe::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeBe_LtrObj { + pub b1: u8, + pub b2: u8, + pub b3: u8, + pub b4: u8, + pub as_int: Option, + pub digit2: Option, + pub digit4: Option, + pub digit3: Option, + pub digit5: Option, + pub digit8: Option, + pub digit6: Option, + pub as_str: Option, + pub digit1: Option, + pub digit7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe_LtrObj { + type Root = BcdUserTypeBe; + type ParentStack = (&'r BcdUserTypeBe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.b1 = _io.read_u1()?; + self.b2 = _io.read_u1()?; + self.b3 = _io.read_u1()?; + self.b4 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeBe_LtrObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeBe_LtrObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn as_int( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.as_int.is_some() { + return Ok(self.as_int.as_ref().unwrap()); + } + self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); + return Ok(self.as_int.as_ref().unwrap()); + } + fn digit2( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit2.is_some() { + return Ok(self.digit2.as_ref().unwrap()); + } + self.digit2 = Some((self.b1 & 15) as i32); + return Ok(self.digit2.as_ref().unwrap()); + } + fn digit4( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit4.is_some() { + return Ok(self.digit4.as_ref().unwrap()); + } + self.digit4 = Some((self.b2 & 15) as i32); + return Ok(self.digit4.as_ref().unwrap()); + } + fn digit3( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit3.is_some() { + return Ok(self.digit3.as_ref().unwrap()); + } + self.digit3 = Some(((self.b2 & 240) >> 4) as i32); + return Ok(self.digit3.as_ref().unwrap()); + } + fn digit5( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit5.is_some() { + return Ok(self.digit5.as_ref().unwrap()); + } + self.digit5 = Some(((self.b3 & 240) >> 4) as i32); + return Ok(self.digit5.as_ref().unwrap()); + } + fn digit8( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit8.is_some() { + return Ok(self.digit8.as_ref().unwrap()); + } + self.digit8 = Some((self.b4 & 15) as i32); + return Ok(self.digit8.as_ref().unwrap()); + } + fn digit6( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit6.is_some() { + return Ok(self.digit6.as_ref().unwrap()); + } + self.digit6 = Some((self.b3 & 15) as i32); + return Ok(self.digit6.as_ref().unwrap()); + } + fn as_str( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&String> { + if self.as_str.is_some() { + return Ok(self.as_str.as_ref().unwrap()); + } + self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); + return Ok(self.as_str.as_ref().unwrap()); + } + fn digit1( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit1.is_some() { + return Ok(self.digit1.as_ref().unwrap()); + } + self.digit1 = Some(((self.b1 & 240) >> 4) as i32); + return Ok(self.digit1.as_ref().unwrap()); + } + fn digit7( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit7.is_some() { + return Ok(self.digit7.as_ref().unwrap()); + } + self.digit7 = Some(((self.b4 & 240) >> 4) as i32); + return Ok(self.digit7.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeBe_RtlObj { + pub b1: u8, + pub b2: u8, + pub b3: u8, + pub b4: u8, + pub as_int: Option, + pub digit2: Option, + pub digit4: Option, + pub digit3: Option, + pub digit5: Option, + pub digit8: Option, + pub digit6: Option, + pub as_str: Option, + pub digit1: Option, + pub digit7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe_RtlObj { + type Root = BcdUserTypeBe; + type ParentStack = (&'r BcdUserTypeBe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.b1 = _io.read_u1()?; + self.b2 = _io.read_u1()?; + self.b3 = _io.read_u1()?; + self.b4 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeBe_RtlObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeBe_RtlObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn as_int( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.as_int.is_some() { + return Ok(self.as_int.as_ref().unwrap()); + } + self.as_int = Some(((((((((self.digit1(_io, _root, _parent)? * 1) + (self.digit2(_io, _root, _parent)? * 10)) + (self.digit3(_io, _root, _parent)? * 100)) + (self.digit4(_io, _root, _parent)? * 1000)) + (self.digit5(_io, _root, _parent)? * 10000)) + (self.digit6(_io, _root, _parent)? * 100000)) + (self.digit7(_io, _root, _parent)? * 1000000)) + (self.digit8(_io, _root, _parent)? * 10000000)) as i32); + return Ok(self.as_int.as_ref().unwrap()); + } + fn digit2( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit2.is_some() { + return Ok(self.digit2.as_ref().unwrap()); + } + self.digit2 = Some((self.b1 & 15) as i32); + return Ok(self.digit2.as_ref().unwrap()); + } + fn digit4( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit4.is_some() { + return Ok(self.digit4.as_ref().unwrap()); + } + self.digit4 = Some((self.b2 & 15) as i32); + return Ok(self.digit4.as_ref().unwrap()); + } + fn digit3( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit3.is_some() { + return Ok(self.digit3.as_ref().unwrap()); + } + self.digit3 = Some(((self.b2 & 240) >> 4) as i32); + return Ok(self.digit3.as_ref().unwrap()); + } + fn digit5( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit5.is_some() { + return Ok(self.digit5.as_ref().unwrap()); + } + self.digit5 = Some(((self.b3 & 240) >> 4) as i32); + return Ok(self.digit5.as_ref().unwrap()); + } + fn digit8( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit8.is_some() { + return Ok(self.digit8.as_ref().unwrap()); + } + self.digit8 = Some((self.b4 & 15) as i32); + return Ok(self.digit8.as_ref().unwrap()); + } + fn digit6( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit6.is_some() { + return Ok(self.digit6.as_ref().unwrap()); + } + self.digit6 = Some((self.b3 & 15) as i32); + return Ok(self.digit6.as_ref().unwrap()); + } + fn as_str( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&String> { + if self.as_str.is_some() { + return Ok(self.as_str.as_ref().unwrap()); + } + self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit8(_io, _root, _parent)?.to_string(), self.digit7(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit2(_io, _root, _parent)?.to_string()), self.digit1(_io, _root, _parent)?.to_string()).to_string()); + return Ok(self.as_str.as_ref().unwrap()); + } + fn digit1( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit1.is_some() { + return Ok(self.digit1.as_ref().unwrap()); + } + self.digit1 = Some(((self.b1 & 240) >> 4) as i32); + return Ok(self.digit1.as_ref().unwrap()); + } + fn digit7( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit7.is_some() { + return Ok(self.digit7.as_ref().unwrap()); + } + self.digit7 = Some(((self.b4 & 240) >> 4) as i32); + return Ok(self.digit7.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeBe_LeadingZeroLtrObj { + pub b1: u8, + pub b2: u8, + pub b3: u8, + pub b4: u8, + pub as_int: Option, + pub digit2: Option, + pub digit4: Option, + pub digit3: Option, + pub digit5: Option, + pub digit8: Option, + pub digit6: Option, + pub as_str: Option, + pub digit1: Option, + pub digit7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe_LeadingZeroLtrObj { + type Root = BcdUserTypeBe; + type ParentStack = (&'r BcdUserTypeBe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.b1 = _io.read_u1()?; + self.b2 = _io.read_u1()?; + self.b3 = _io.read_u1()?; + self.b4 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeBe_LeadingZeroLtrObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeBe_LeadingZeroLtrObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn as_int( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.as_int.is_some() { + return Ok(self.as_int.as_ref().unwrap()); + } + self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); + return Ok(self.as_int.as_ref().unwrap()); + } + fn digit2( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit2.is_some() { + return Ok(self.digit2.as_ref().unwrap()); + } + self.digit2 = Some((self.b1 & 15) as i32); + return Ok(self.digit2.as_ref().unwrap()); + } + fn digit4( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit4.is_some() { + return Ok(self.digit4.as_ref().unwrap()); + } + self.digit4 = Some((self.b2 & 15) as i32); + return Ok(self.digit4.as_ref().unwrap()); + } + fn digit3( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit3.is_some() { + return Ok(self.digit3.as_ref().unwrap()); + } + self.digit3 = Some(((self.b2 & 240) >> 4) as i32); + return Ok(self.digit3.as_ref().unwrap()); + } + fn digit5( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit5.is_some() { + return Ok(self.digit5.as_ref().unwrap()); + } + self.digit5 = Some(((self.b3 & 240) >> 4) as i32); + return Ok(self.digit5.as_ref().unwrap()); + } + fn digit8( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit8.is_some() { + return Ok(self.digit8.as_ref().unwrap()); + } + self.digit8 = Some((self.b4 & 15) as i32); + return Ok(self.digit8.as_ref().unwrap()); + } + fn digit6( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit6.is_some() { + return Ok(self.digit6.as_ref().unwrap()); + } + self.digit6 = Some((self.b3 & 15) as i32); + return Ok(self.digit6.as_ref().unwrap()); + } + fn as_str( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&String> { + if self.as_str.is_some() { + return Ok(self.as_str.as_ref().unwrap()); + } + self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); + return Ok(self.as_str.as_ref().unwrap()); + } + fn digit1( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit1.is_some() { + return Ok(self.digit1.as_ref().unwrap()); + } + self.digit1 = Some(((self.b1 & 240) >> 4) as i32); + return Ok(self.digit1.as_ref().unwrap()); + } + fn digit7( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit7.is_some() { + return Ok(self.digit7.as_ref().unwrap()); + } + self.digit7 = Some(((self.b4 & 240) >> 4) as i32); + return Ok(self.digit7.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/bcd_user_type_le.rs b/spec/rust/formats/bcd_user_type_le.rs new file mode 100644 index 000000000..4d09ade52 --- /dev/null +++ b/spec/rust/formats/bcd_user_type_le.rs @@ -0,0 +1,558 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(ltr)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(rtl)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(leading_zero_ltr)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeLe { + pub ltr: Option, + pub rtl: Option, + pub leading_zero_ltr: Option, + pub raw_ltr: Vec, + pub raw_rtl: Vec, + pub raw_leading_zero_ltr: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + self.rtl = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + self.leading_zero_ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeLe { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeLe::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeLe_LtrObj { + pub b1: u8, + pub b2: u8, + pub b3: u8, + pub b4: u8, + pub as_int: Option, + pub digit2: Option, + pub digit4: Option, + pub digit3: Option, + pub digit5: Option, + pub digit8: Option, + pub digit6: Option, + pub as_str: Option, + pub digit1: Option, + pub digit7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe_LtrObj { + type Root = BcdUserTypeLe; + type ParentStack = (&'r BcdUserTypeLe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.b1 = _io.read_u1()?; + self.b2 = _io.read_u1()?; + self.b3 = _io.read_u1()?; + self.b4 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeLe_LtrObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeLe_LtrObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn as_int( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.as_int.is_some() { + return Ok(self.as_int.as_ref().unwrap()); + } + self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); + return Ok(self.as_int.as_ref().unwrap()); + } + fn digit2( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit2.is_some() { + return Ok(self.digit2.as_ref().unwrap()); + } + self.digit2 = Some((self.b4 & 15) as i32); + return Ok(self.digit2.as_ref().unwrap()); + } + fn digit4( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit4.is_some() { + return Ok(self.digit4.as_ref().unwrap()); + } + self.digit4 = Some((self.b3 & 15) as i32); + return Ok(self.digit4.as_ref().unwrap()); + } + fn digit3( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit3.is_some() { + return Ok(self.digit3.as_ref().unwrap()); + } + self.digit3 = Some(((self.b3 & 240) >> 4) as i32); + return Ok(self.digit3.as_ref().unwrap()); + } + fn digit5( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit5.is_some() { + return Ok(self.digit5.as_ref().unwrap()); + } + self.digit5 = Some(((self.b2 & 240) >> 4) as i32); + return Ok(self.digit5.as_ref().unwrap()); + } + fn digit8( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit8.is_some() { + return Ok(self.digit8.as_ref().unwrap()); + } + self.digit8 = Some((self.b1 & 15) as i32); + return Ok(self.digit8.as_ref().unwrap()); + } + fn digit6( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit6.is_some() { + return Ok(self.digit6.as_ref().unwrap()); + } + self.digit6 = Some((self.b2 & 15) as i32); + return Ok(self.digit6.as_ref().unwrap()); + } + fn as_str( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&String> { + if self.as_str.is_some() { + return Ok(self.as_str.as_ref().unwrap()); + } + self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); + return Ok(self.as_str.as_ref().unwrap()); + } + fn digit1( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit1.is_some() { + return Ok(self.digit1.as_ref().unwrap()); + } + self.digit1 = Some(((self.b4 & 240) >> 4) as i32); + return Ok(self.digit1.as_ref().unwrap()); + } + fn digit7( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit7.is_some() { + return Ok(self.digit7.as_ref().unwrap()); + } + self.digit7 = Some(((self.b1 & 240) >> 4) as i32); + return Ok(self.digit7.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeLe_RtlObj { + pub b1: u8, + pub b2: u8, + pub b3: u8, + pub b4: u8, + pub as_int: Option, + pub digit2: Option, + pub digit4: Option, + pub digit3: Option, + pub digit5: Option, + pub digit8: Option, + pub digit6: Option, + pub as_str: Option, + pub digit1: Option, + pub digit7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe_RtlObj { + type Root = BcdUserTypeLe; + type ParentStack = (&'r BcdUserTypeLe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.b1 = _io.read_u1()?; + self.b2 = _io.read_u1()?; + self.b3 = _io.read_u1()?; + self.b4 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeLe_RtlObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeLe_RtlObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn as_int( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.as_int.is_some() { + return Ok(self.as_int.as_ref().unwrap()); + } + self.as_int = Some(((((((((self.digit1(_io, _root, _parent)? * 1) + (self.digit2(_io, _root, _parent)? * 10)) + (self.digit3(_io, _root, _parent)? * 100)) + (self.digit4(_io, _root, _parent)? * 1000)) + (self.digit5(_io, _root, _parent)? * 10000)) + (self.digit6(_io, _root, _parent)? * 100000)) + (self.digit7(_io, _root, _parent)? * 1000000)) + (self.digit8(_io, _root, _parent)? * 10000000)) as i32); + return Ok(self.as_int.as_ref().unwrap()); + } + fn digit2( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit2.is_some() { + return Ok(self.digit2.as_ref().unwrap()); + } + self.digit2 = Some((self.b4 & 15) as i32); + return Ok(self.digit2.as_ref().unwrap()); + } + fn digit4( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit4.is_some() { + return Ok(self.digit4.as_ref().unwrap()); + } + self.digit4 = Some((self.b3 & 15) as i32); + return Ok(self.digit4.as_ref().unwrap()); + } + fn digit3( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit3.is_some() { + return Ok(self.digit3.as_ref().unwrap()); + } + self.digit3 = Some(((self.b3 & 240) >> 4) as i32); + return Ok(self.digit3.as_ref().unwrap()); + } + fn digit5( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit5.is_some() { + return Ok(self.digit5.as_ref().unwrap()); + } + self.digit5 = Some(((self.b2 & 240) >> 4) as i32); + return Ok(self.digit5.as_ref().unwrap()); + } + fn digit8( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit8.is_some() { + return Ok(self.digit8.as_ref().unwrap()); + } + self.digit8 = Some((self.b1 & 15) as i32); + return Ok(self.digit8.as_ref().unwrap()); + } + fn digit6( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit6.is_some() { + return Ok(self.digit6.as_ref().unwrap()); + } + self.digit6 = Some((self.b2 & 15) as i32); + return Ok(self.digit6.as_ref().unwrap()); + } + fn as_str( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&String> { + if self.as_str.is_some() { + return Ok(self.as_str.as_ref().unwrap()); + } + self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit8(_io, _root, _parent)?.to_string(), self.digit7(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit2(_io, _root, _parent)?.to_string()), self.digit1(_io, _root, _parent)?.to_string()).to_string()); + return Ok(self.as_str.as_ref().unwrap()); + } + fn digit1( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit1.is_some() { + return Ok(self.digit1.as_ref().unwrap()); + } + self.digit1 = Some(((self.b4 & 240) >> 4) as i32); + return Ok(self.digit1.as_ref().unwrap()); + } + fn digit7( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit7.is_some() { + return Ok(self.digit7.as_ref().unwrap()); + } + self.digit7 = Some(((self.b1 & 240) >> 4) as i32); + return Ok(self.digit7.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct BcdUserTypeLe_LeadingZeroLtrObj { + pub b1: u8, + pub b2: u8, + pub b3: u8, + pub b4: u8, + pub as_int: Option, + pub digit2: Option, + pub digit4: Option, + pub digit3: Option, + pub digit5: Option, + pub digit8: Option, + pub digit6: Option, + pub as_str: Option, + pub digit1: Option, + pub digit7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe_LeadingZeroLtrObj { + type Root = BcdUserTypeLe; + type ParentStack = (&'r BcdUserTypeLe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.b1 = _io.read_u1()?; + self.b2 = _io.read_u1()?; + self.b3 = _io.read_u1()?; + self.b4 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> BcdUserTypeLe_LeadingZeroLtrObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BcdUserTypeLe_LeadingZeroLtrObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn as_int( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.as_int.is_some() { + return Ok(self.as_int.as_ref().unwrap()); + } + self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); + return Ok(self.as_int.as_ref().unwrap()); + } + fn digit2( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit2.is_some() { + return Ok(self.digit2.as_ref().unwrap()); + } + self.digit2 = Some((self.b4 & 15) as i32); + return Ok(self.digit2.as_ref().unwrap()); + } + fn digit4( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit4.is_some() { + return Ok(self.digit4.as_ref().unwrap()); + } + self.digit4 = Some((self.b3 & 15) as i32); + return Ok(self.digit4.as_ref().unwrap()); + } + fn digit3( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit3.is_some() { + return Ok(self.digit3.as_ref().unwrap()); + } + self.digit3 = Some(((self.b3 & 240) >> 4) as i32); + return Ok(self.digit3.as_ref().unwrap()); + } + fn digit5( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit5.is_some() { + return Ok(self.digit5.as_ref().unwrap()); + } + self.digit5 = Some(((self.b2 & 240) >> 4) as i32); + return Ok(self.digit5.as_ref().unwrap()); + } + fn digit8( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit8.is_some() { + return Ok(self.digit8.as_ref().unwrap()); + } + self.digit8 = Some((self.b1 & 15) as i32); + return Ok(self.digit8.as_ref().unwrap()); + } + fn digit6( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit6.is_some() { + return Ok(self.digit6.as_ref().unwrap()); + } + self.digit6 = Some((self.b2 & 15) as i32); + return Ok(self.digit6.as_ref().unwrap()); + } + fn as_str( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&String> { + if self.as_str.is_some() { + return Ok(self.as_str.as_ref().unwrap()); + } + self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); + return Ok(self.as_str.as_ref().unwrap()); + } + fn digit1( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit1.is_some() { + return Ok(self.digit1.as_ref().unwrap()); + } + self.digit1 = Some(((self.b4 & 240) >> 4) as i32); + return Ok(self.digit1.as_ref().unwrap()); + } + fn digit7( + &mut self, + _io: &'s S, + _root: Option<&'r BcdUserTypeLe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.digit7.is_some() { + return Ok(self.digit7.as_ref().unwrap()); + } + self.digit7 = Some(((self.b1 & 240) >> 4) as i32); + return Ok(self.digit7.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/bits_byte_aligned.rs b/spec/rust/formats/bits_byte_aligned.rs new file mode 100644 index 000000000..b8c09b521 --- /dev/null +++ b/spec/rust/formats/bits_byte_aligned.rs @@ -0,0 +1,61 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsByteAligned { + pub one: u64, + pub byte_1: u8, + pub two: u64, + pub three: bool, + pub byte_2: u8, + pub four: u64, + pub byte_3: Vec, + pub full_byte: u64, + pub byte_4: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsByteAligned { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_bits_int(6)?; + _io.align_to_byte()?; + self.byte_1 = _io.read_u1()?; + self.two = _io.read_bits_int(3)?; + self.three = _io.read_bits_int(1)? != 0; + _io.align_to_byte()?; + self.byte_2 = _io.read_u1()?; + self.four = _io.read_bits_int(14)?; + _io.align_to_byte()?; + self.byte_3 = _io.read_bytes(1 as usize)?.to_vec(); + self.full_byte = _io.read_bits_int(8)?; + _io.align_to_byte()?; + self.byte_4 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsByteAligned { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsByteAligned::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_enum.rs b/spec/rust/formats/bits_enum.rs new file mode 100644 index 000000000..6c9d6249e --- /dev/null +++ b/spec/rust/formats/bits_enum.rs @@ -0,0 +1,65 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsEnum { + pub one: Option, + pub two: Option, + pub three: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsEnum { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some((_io.read_bits_int(4)? as i64).try_into()?); + self.two = Some((_io.read_bits_int(8)? as i64).try_into()?); + self.three = Some((_io.read_bits_int(1)? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> BitsEnum { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsEnum::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum BitsEnum_Animal { + Cat, + Dog, + Horse, + Platypus, +} +impl TryFrom for BitsEnum_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 0 => Ok(BitsEnum_Animal::Cat), + 1 => Ok(BitsEnum_Animal::Dog), + 4 => Ok(BitsEnum_Animal::Horse), + 5 => Ok(BitsEnum_Animal::Platypus), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/bits_seq_endian_combo.rs b/spec/rust/formats/bits_seq_endian_combo.rs new file mode 100644 index 000000000..b558a4e85 --- /dev/null +++ b/spec/rust/formats/bits_seq_endian_combo.rs @@ -0,0 +1,55 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsSeqEndianCombo { + pub be1: u64, + pub be2: u64, + pub le3: u64, + pub be4: u64, + pub le5: u64, + pub le6: u64, + pub le7: u64, + pub be8: bool, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsSeqEndianCombo { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.be1 = _io.read_bits_int(6)?; + self.be2 = _io.read_bits_int(10)?; + self.le3 = _io.read_bits_int(8)?; + self.be4 = _io.read_bits_int(8)?; + self.le5 = _io.read_bits_int(5)?; + self.le6 = _io.read_bits_int(6)?; + self.le7 = _io.read_bits_int(5)?; + self.be8 = _io.read_bits_int(1)? != 0; + Ok(()) + } +} +impl<'r, 's: 'r> BitsSeqEndianCombo { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsSeqEndianCombo::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_shift_by_b32_le.rs b/spec/rust/formats/bits_shift_by_b32_le.rs new file mode 100644 index 000000000..51bc1c064 --- /dev/null +++ b/spec/rust/formats/bits_shift_by_b32_le.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsShiftByB32Le { + pub a: u64, + pub b: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsShiftByB32Le { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(32)?; + self.b = _io.read_bits_int(8)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsShiftByB32Le { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsShiftByB32Le::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_shift_by_b64_le.rs b/spec/rust/formats/bits_shift_by_b64_le.rs new file mode 100644 index 000000000..55679664f --- /dev/null +++ b/spec/rust/formats/bits_shift_by_b64_le.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsShiftByB64Le { + pub a: u64, + pub b: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsShiftByB64Le { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(64)?; + self.b = _io.read_bits_int(8)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsShiftByB64Le { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsShiftByB64Le::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_signed_res_b32_be.rs b/spec/rust/formats/bits_signed_res_b32_be.rs new file mode 100644 index 000000000..78dc78f26 --- /dev/null +++ b/spec/rust/formats/bits_signed_res_b32_be.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsSignedResB32Be { + pub a: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedResB32Be { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(32)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsSignedResB32Be { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsSignedResB32Be::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_signed_res_b32_le.rs b/spec/rust/formats/bits_signed_res_b32_le.rs new file mode 100644 index 000000000..44e6772a2 --- /dev/null +++ b/spec/rust/formats/bits_signed_res_b32_le.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsSignedResB32Le { + pub a: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedResB32Le { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(32)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsSignedResB32Le { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsSignedResB32Le::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_signed_shift_b32_le.rs b/spec/rust/formats/bits_signed_shift_b32_le.rs new file mode 100644 index 000000000..177b8e710 --- /dev/null +++ b/spec/rust/formats/bits_signed_shift_b32_le.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsSignedShiftB32Le { + pub a: u64, + pub b: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedShiftB32Le { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(31)?; + self.b = _io.read_bits_int(9)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsSignedShiftB32Le { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsSignedShiftB32Le::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_signed_shift_b64_le.rs b/spec/rust/formats/bits_signed_shift_b64_le.rs new file mode 100644 index 000000000..fc04f649e --- /dev/null +++ b/spec/rust/formats/bits_signed_shift_b64_le.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsSignedShiftB64Le { + pub a: u64, + pub b: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedShiftB64Le { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(63)?; + self.b = _io.read_bits_int(9)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsSignedShiftB64Le { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsSignedShiftB64Le::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_simple.rs b/spec/rust/formats/bits_simple.rs new file mode 100644 index 000000000..f3aa512e6 --- /dev/null +++ b/spec/rust/formats/bits_simple.rs @@ -0,0 +1,82 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsSimple { + pub byte_1: u64, + pub byte_2: u64, + pub bits_a: bool, + pub bits_b: u64, + pub bits_c: u64, + pub large_bits_1: u64, + pub spacer: u64, + pub large_bits_2: u64, + pub normal_s2: i16, + pub byte_8_9_10: u64, + pub byte_11_to_14: u64, + pub byte_15_to_19: u64, + pub byte_20_to_27: u64, + pub test_if_b1: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsSimple { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.byte_1 = _io.read_bits_int(8)?; + self.byte_2 = _io.read_bits_int(8)?; + self.bits_a = _io.read_bits_int(1)? != 0; + self.bits_b = _io.read_bits_int(3)?; + self.bits_c = _io.read_bits_int(4)?; + self.large_bits_1 = _io.read_bits_int(10)?; + self.spacer = _io.read_bits_int(3)?; + self.large_bits_2 = _io.read_bits_int(11)?; + _io.align_to_byte()?; + self.normal_s2 = _io.read_s2be()?; + self.byte_8_9_10 = _io.read_bits_int(24)?; + self.byte_11_to_14 = _io.read_bits_int(32)?; + self.byte_15_to_19 = _io.read_bits_int(40)?; + self.byte_20_to_27 = _io.read_bits_int(64)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsSimple { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsSimple::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn test_if_b1( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i8> { + if self.test_if_b1.is_some() { + return Ok(self.test_if_b1.as_ref().unwrap()); + } + { + // condIfHeader(Compare(Name(identifier(bits_a)),Eq,Bool(false))) + self.test_if_b1 = Some(123 as i8); + } + return Ok(self.test_if_b1.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/bits_simple_le.rs b/spec/rust/formats/bits_simple_le.rs new file mode 100644 index 000000000..5df58495f --- /dev/null +++ b/spec/rust/formats/bits_simple_le.rs @@ -0,0 +1,82 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsSimpleLe { + pub byte_1: u64, + pub byte_2: u64, + pub bits_a: bool, + pub bits_b: u64, + pub bits_c: u64, + pub large_bits_1: u64, + pub spacer: u64, + pub large_bits_2: u64, + pub normal_s2: i16, + pub byte_8_9_10: u64, + pub byte_11_to_14: u64, + pub byte_15_to_19: u64, + pub byte_20_to_27: u64, + pub test_if_b1: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsSimpleLe { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.byte_1 = _io.read_bits_int(8)?; + self.byte_2 = _io.read_bits_int(8)?; + self.bits_a = _io.read_bits_int(1)? != 0; + self.bits_b = _io.read_bits_int(3)?; + self.bits_c = _io.read_bits_int(4)?; + self.large_bits_1 = _io.read_bits_int(10)?; + self.spacer = _io.read_bits_int(3)?; + self.large_bits_2 = _io.read_bits_int(11)?; + _io.align_to_byte()?; + self.normal_s2 = _io.read_s2be()?; + self.byte_8_9_10 = _io.read_bits_int(24)?; + self.byte_11_to_14 = _io.read_bits_int(32)?; + self.byte_15_to_19 = _io.read_bits_int(40)?; + self.byte_20_to_27 = _io.read_bits_int(64)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsSimpleLe { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsSimpleLe::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn test_if_b1( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i8> { + if self.test_if_b1.is_some() { + return Ok(self.test_if_b1.as_ref().unwrap()); + } + { + // condIfHeader(Compare(Name(identifier(bits_a)),Eq,Bool(true))) + self.test_if_b1 = Some(123 as i8); + } + return Ok(self.test_if_b1.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/bits_unaligned_b32_be.rs b/spec/rust/formats/bits_unaligned_b32_be.rs new file mode 100644 index 000000000..1cf858584 --- /dev/null +++ b/spec/rust/formats/bits_unaligned_b32_be.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsUnalignedB32Be { + pub a: bool, + pub b: u64, + pub c: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB32Be { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(1)? != 0; + self.b = _io.read_bits_int(32)?; + self.c = _io.read_bits_int(7)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsUnalignedB32Be { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsUnalignedB32Be::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_unaligned_b32_le.rs b/spec/rust/formats/bits_unaligned_b32_le.rs new file mode 100644 index 000000000..b6ea72e5a --- /dev/null +++ b/spec/rust/formats/bits_unaligned_b32_le.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsUnalignedB32Le { + pub a: bool, + pub b: u64, + pub c: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB32Le { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(1)? != 0; + self.b = _io.read_bits_int(32)?; + self.c = _io.read_bits_int(7)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsUnalignedB32Le { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsUnalignedB32Le::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_unaligned_b64_be.rs b/spec/rust/formats/bits_unaligned_b64_be.rs new file mode 100644 index 000000000..40c82f01d --- /dev/null +++ b/spec/rust/formats/bits_unaligned_b64_be.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsUnalignedB64Be { + pub a: bool, + pub b: u64, + pub c: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB64Be { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(1)? != 0; + self.b = _io.read_bits_int(64)?; + self.c = _io.read_bits_int(7)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsUnalignedB64Be { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsUnalignedB64Be::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bits_unaligned_b64_le.rs b/spec/rust/formats/bits_unaligned_b64_le.rs new file mode 100644 index 000000000..760332cb2 --- /dev/null +++ b/spec/rust/formats/bits_unaligned_b64_le.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BitsUnalignedB64Le { + pub a: bool, + pub b: u64, + pub c: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB64Le { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bits_int(1)? != 0; + self.b = _io.read_bits_int(64)?; + self.c = _io.read_bits_int(7)?; + Ok(()) + } +} +impl<'r, 's: 'r> BitsUnalignedB64Le { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BitsUnalignedB64Le::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/buffered_struct.rs b/spec/rust/formats/buffered_struct.rs new file mode 100644 index 000000000..fcc3fff4c --- /dev/null +++ b/spec/rust/formats/buffered_struct.rs @@ -0,0 +1,88 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(block1)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(block2)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct BufferedStruct { + pub len1: u32, + pub block1: Option, + pub len2: u32, + pub block2: Option, + pub finisher: u32, + pub raw_block1: Vec, + pub raw_block2: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BufferedStruct { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len1 = _io.read_u4le()?; + self.block1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len1 as usize)?), Some(self), _parent.push(self))?); + self.len2 = _io.read_u4le()?; + self.block2 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len2 as usize)?), Some(self), _parent.push(self))?); + self.finisher = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> BufferedStruct { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BufferedStruct::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct BufferedStruct_Block { + pub number1: u32, + pub number2: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BufferedStruct_Block { + type Root = BufferedStruct; + type ParentStack = (&'r BufferedStruct, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.number1 = _io.read_u4le()?; + self.number2 = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> BufferedStruct_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BufferedStruct_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/bytes_pad_term.rs b/spec/rust/formats/bytes_pad_term.rs new file mode 100644 index 000000000..2a63e5a53 --- /dev/null +++ b/spec/rust/formats/bytes_pad_term.rs @@ -0,0 +1,47 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct BytesPadTerm { + pub str_pad: Vec, + pub str_term: Vec, + pub str_term_and_pad: Vec, + pub str_term_include: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for BytesPadTerm { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.str_pad = _io.bytes_strip_right(_io.read_bytes(20 as usize)?, 64).to_vec(); + self.str_term = _io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, false).to_vec(); + self.str_term_and_pad = _io.bytes_terminate(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 43), 64, false).to_vec(); + self.str_term_include = _io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, true).to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> BytesPadTerm { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = BytesPadTerm::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/cast_nested.rs b/spec/rust/formats/cast_nested.rs new file mode 100644 index 000000000..157cd94e0 --- /dev/null +++ b/spec/rust/formats/cast_nested.rs @@ -0,0 +1,224 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct CastNested { + pub opcodes: Vec, + pub opcodes_0_str: Option, + pub opcodes_0_str_value: Option, + pub opcodes_1_int: Option, + pub opcodes_1_int_value: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CastNested { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = CastNested_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> CastNested { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CastNested::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn opcodes_0_str( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&CastNested_Opcode_Strval> { + if self.opcodes_0_str.is_some() { + return Ok(self.opcodes_0_str.as_ref().unwrap()); + } + self.opcodes_0_str = Some(self.opcodes[0 as usize].body as CastNested_Opcode_Strval); + return Ok(self.opcodes_0_str.as_ref().unwrap()); + } + fn opcodes_0_str_value( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.opcodes_0_str_value.is_some() { + return Ok(self.opcodes_0_str_value.as_ref().unwrap()); + } + self.opcodes_0_str_value = Some(self.opcodes[0 as usize].body.value.to_string()); + return Ok(self.opcodes_0_str_value.as_ref().unwrap()); + } + fn opcodes_1_int( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&CastNested_Opcode_Intval> { + if self.opcodes_1_int.is_some() { + return Ok(self.opcodes_1_int.as_ref().unwrap()); + } + self.opcodes_1_int = Some(self.opcodes[1 as usize].body as CastNested_Opcode_Intval); + return Ok(self.opcodes_1_int.as_ref().unwrap()); + } + fn opcodes_1_int_value( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.opcodes_1_int_value.is_some() { + return Ok(self.opcodes_1_int_value.as_ref().unwrap()); + } + self.opcodes_1_int_value = Some(self.opcodes[1 as usize].body.value as u8); + return Ok(self.opcodes_1_int_value.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct CastNested_Opcode { + pub code: u8, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum CastNested_Opcode_Body { + CastNested_Opcode_Intval(CastNested_Opcode_Intval), + CastNested_Opcode_Strval(CastNested_Opcode_Strval), +} +impl From for CastNested_Opcode_Body { + fn from(v: CastNested_Opcode_Intval) -> Self { + Self::CastNested_Opcode_Intval(v) + } +} +impl From for CastNested_Opcode_Body { + fn from(v: CastNested_Opcode_Strval) -> Self { + Self::CastNested_Opcode_Strval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for CastNested_Opcode { + type Root = CastNested; + type ParentStack = (&'r CastNested, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + match self.code { + 73 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + 83 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> CastNested_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CastNested_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct CastNested_Opcode_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CastNested_Opcode_Intval { + type Root = CastNested; + type ParentStack = (&'r CastNested_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> CastNested_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CastNested_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct CastNested_Opcode_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CastNested_Opcode_Strval { + type Root = CastNested; + type ParentStack = (&'r CastNested_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> CastNested_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CastNested_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/cast_to_imported.rs b/spec/rust/formats/cast_to_imported.rs new file mode 100644 index 000000000..d7822ed2e --- /dev/null +++ b/spec/rust/formats/cast_to_imported.rs @@ -0,0 +1,55 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::hello_world::HelloWorld; + +#[derive(Default, Debug, PartialEq)] +pub struct CastToImported { + pub one: Option>, + pub one_casted: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CastToImported { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> CastToImported { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CastToImported::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn one_casted( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Box> { + if self.one_casted.is_some() { + return Ok(self.one_casted.as_ref().unwrap()); + } + self.one_casted = Some(self.one as HelloWorld); + return Ok(self.one_casted.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/cast_to_top.rs b/spec/rust/formats/cast_to_top.rs new file mode 100644 index 000000000..6dc4d5aed --- /dev/null +++ b/spec/rust/formats/cast_to_top.rs @@ -0,0 +1,69 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct CastToTop { + pub code: u8, + pub header: Option>, + pub header_casted: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CastToTop { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> CastToTop { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CastToTop::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn header( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Box> { + if self.header.is_some() { + return Ok(self.header.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(1)) + // popPos(_io) + return Ok(self.header.as_ref().unwrap()); + } + fn header_casted( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Box> { + if self.header_casted.is_some() { + return Ok(self.header_casted.as_ref().unwrap()); + } + self.header_casted = Some(self.header(_io, _root, _parent)? as CastToTop); + return Ok(self.header_casted.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/combine_bool.rs b/spec/rust/formats/combine_bool.rs new file mode 100644 index 000000000..1db57046f --- /dev/null +++ b/spec/rust/formats/combine_bool.rs @@ -0,0 +1,67 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct CombineBool { + pub bool_bit: bool, + pub bool_calc: Option, + pub bool_calc_bit: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CombineBool { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.bool_bit = _io.read_bits_int(1)? != 0; + Ok(()) + } +} +impl<'r, 's: 'r> CombineBool { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CombineBool::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn bool_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.bool_calc.is_some() { + return Ok(self.bool_calc.as_ref().unwrap()); + } + self.bool_calc = Some(false as bool); + return Ok(self.bool_calc.as_ref().unwrap()); + } + fn bool_calc_bit( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.bool_calc_bit.is_some() { + return Ok(self.bool_calc_bit.as_ref().unwrap()); + } + self.bool_calc_bit = Some(if true { self.bool_calc(_io, _root, _parent)? } else { self.bool_bit} as bool); + return Ok(self.bool_calc_bit.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/combine_bytes.rs b/spec/rust/formats/combine_bytes.rs new file mode 100644 index 000000000..dd1a6b2c6 --- /dev/null +++ b/spec/rust/formats/combine_bytes.rs @@ -0,0 +1,136 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct CombineBytes { + pub bytes_term: Vec, + pub bytes_limit: Vec, + pub bytes_eos: Vec, + pub limit_or_calc: Option>, + pub term_or_limit: Option>, + pub limit_or_eos: Option>, + pub eos_or_calc: Option>, + pub term_or_calc: Option>, + pub bytes_calc: Option>, + pub term_or_eos: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CombineBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.bytes_term = _io.read_bytes_term(124, false, true, true)?; + self.bytes_limit = _io.read_bytes(4 as usize)?.to_vec(); + self.bytes_eos = _io.read_bytes_full()?; + Ok(()) + } +} +impl<'r, 's: 'r> CombineBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CombineBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn limit_or_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.limit_or_calc.is_some() { + return Ok(self.limit_or_calc.as_ref().unwrap()); + } + self.limit_or_calc = Some(if false { self.bytes_limit } else { self.bytes_calc(_io, _root, _parent)?} as Vec); + return Ok(self.limit_or_calc.as_ref().unwrap()); + } + fn term_or_limit( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.term_or_limit.is_some() { + return Ok(self.term_or_limit.as_ref().unwrap()); + } + self.term_or_limit = Some(if true { self.bytes_term } else { self.bytes_limit} as Vec); + return Ok(self.term_or_limit.as_ref().unwrap()); + } + fn limit_or_eos( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.limit_or_eos.is_some() { + return Ok(self.limit_or_eos.as_ref().unwrap()); + } + self.limit_or_eos = Some(if true { self.bytes_limit } else { self.bytes_eos} as Vec); + return Ok(self.limit_or_eos.as_ref().unwrap()); + } + fn eos_or_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.eos_or_calc.is_some() { + return Ok(self.eos_or_calc.as_ref().unwrap()); + } + self.eos_or_calc = Some(if true { self.bytes_eos } else { self.bytes_calc(_io, _root, _parent)?} as Vec); + return Ok(self.eos_or_calc.as_ref().unwrap()); + } + fn term_or_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.term_or_calc.is_some() { + return Ok(self.term_or_calc.as_ref().unwrap()); + } + self.term_or_calc = Some(if true { self.bytes_term } else { self.bytes_calc(_io, _root, _parent)?} as Vec); + return Ok(self.term_or_calc.as_ref().unwrap()); + } + fn bytes_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.bytes_calc.is_some() { + return Ok(self.bytes_calc.as_ref().unwrap()); + } + self.bytes_calc = Some(&[0x52, 0x6e, 0x44] as Vec); + return Ok(self.bytes_calc.as_ref().unwrap()); + } + fn term_or_eos( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.term_or_eos.is_some() { + return Ok(self.term_or_eos.as_ref().unwrap()); + } + self.term_or_eos = Some(if false { self.bytes_term } else { self.bytes_eos} as Vec); + return Ok(self.term_or_eos.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/combine_enum.rs b/spec/rust/formats/combine_enum.rs new file mode 100644 index 000000000..eace6ec19 --- /dev/null +++ b/spec/rust/formats/combine_enum.rs @@ -0,0 +1,72 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct CombineEnum { + pub enum_u4: Option, + pub enum_u2: Option, + pub enum_u4_u2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CombineEnum { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.enum_u4 = Some((_io.read_u4le()? as i64).try_into()?); + self.enum_u2 = Some((_io.read_u2le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> CombineEnum { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CombineEnum::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn enum_u4_u2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&CombineEnum_Animal> { + if self.enum_u4_u2.is_some() { + return Ok(self.enum_u4_u2.as_ref().unwrap()); + } + self.enum_u4_u2 = Some(if false { self.enum_u4 } else { self.enum_u2} as i32); + return Ok(self.enum_u4_u2.as_ref().unwrap()); + } +} +#[derive(Debug, PartialEq)] +pub enum CombineEnum_Animal { + Pig, + Horse, +} +impl TryFrom for CombineEnum_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 7 => Ok(CombineEnum_Animal::Pig), + 12 => Ok(CombineEnum_Animal::Horse), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/combine_str.rs b/spec/rust/formats/combine_str.rs new file mode 100644 index 000000000..6adb3ee36 --- /dev/null +++ b/spec/rust/formats/combine_str.rs @@ -0,0 +1,214 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct CombineStr { + pub str_term: String, + pub str_limit: String, + pub str_eos: String, + pub limit_or_calc_bytes: Option, + pub limit_or_calc: Option, + pub term_or_limit: Option, + pub limit_or_eos: Option, + pub calc_or_calc_bytes: Option, + pub str_calc_bytes: Option, + pub eos_or_calc: Option, + pub term_or_calc: Option, + pub term_or_calc_bytes: Option, + pub term_or_eos: Option, + pub str_calc: Option, + pub eos_or_calc_bytes: Option, + pub calc_bytes: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for CombineStr { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.str_term = decode_string(_io.read_bytes_term(124, false, true, true)?, "ASCII")?; + self.str_limit = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; + self.str_eos = decode_string(_io.read_bytes_full()?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> CombineStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = CombineStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn limit_or_calc_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.limit_or_calc_bytes.is_some() { + return Ok(self.limit_or_calc_bytes.as_ref().unwrap()); + } + self.limit_or_calc_bytes = Some(if true { self.str_limit } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); + return Ok(self.limit_or_calc_bytes.as_ref().unwrap()); + } + fn limit_or_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.limit_or_calc.is_some() { + return Ok(self.limit_or_calc.as_ref().unwrap()); + } + self.limit_or_calc = Some(if false { self.str_limit } else { self.str_calc(_io, _root, _parent)?}.to_string()); + return Ok(self.limit_or_calc.as_ref().unwrap()); + } + fn term_or_limit( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.term_or_limit.is_some() { + return Ok(self.term_or_limit.as_ref().unwrap()); + } + self.term_or_limit = Some(if true { self.str_term } else { self.str_limit}.to_string()); + return Ok(self.term_or_limit.as_ref().unwrap()); + } + fn limit_or_eos( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.limit_or_eos.is_some() { + return Ok(self.limit_or_eos.as_ref().unwrap()); + } + self.limit_or_eos = Some(if true { self.str_limit } else { self.str_eos}.to_string()); + return Ok(self.limit_or_eos.as_ref().unwrap()); + } + fn calc_or_calc_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.calc_or_calc_bytes.is_some() { + return Ok(self.calc_or_calc_bytes.as_ref().unwrap()); + } + self.calc_or_calc_bytes = Some(if false { self.str_calc(_io, _root, _parent)? } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); + return Ok(self.calc_or_calc_bytes.as_ref().unwrap()); + } + fn str_calc_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.str_calc_bytes.is_some() { + return Ok(self.str_calc_bytes.as_ref().unwrap()); + } + self.str_calc_bytes = Some(decode_string(self.calc_bytes(_io, _root, _parent)?, "ASCII")?.to_string()); + return Ok(self.str_calc_bytes.as_ref().unwrap()); + } + fn eos_or_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.eos_or_calc.is_some() { + return Ok(self.eos_or_calc.as_ref().unwrap()); + } + self.eos_or_calc = Some(if false { self.str_eos } else { self.str_calc(_io, _root, _parent)?}.to_string()); + return Ok(self.eos_or_calc.as_ref().unwrap()); + } + fn term_or_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.term_or_calc.is_some() { + return Ok(self.term_or_calc.as_ref().unwrap()); + } + self.term_or_calc = Some(if true { self.str_term } else { self.str_calc(_io, _root, _parent)?}.to_string()); + return Ok(self.term_or_calc.as_ref().unwrap()); + } + fn term_or_calc_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.term_or_calc_bytes.is_some() { + return Ok(self.term_or_calc_bytes.as_ref().unwrap()); + } + self.term_or_calc_bytes = Some(if false { self.str_term } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); + return Ok(self.term_or_calc_bytes.as_ref().unwrap()); + } + fn term_or_eos( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.term_or_eos.is_some() { + return Ok(self.term_or_eos.as_ref().unwrap()); + } + self.term_or_eos = Some(if false { self.str_term } else { self.str_eos}.to_string()); + return Ok(self.term_or_eos.as_ref().unwrap()); + } + fn str_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.str_calc.is_some() { + return Ok(self.str_calc.as_ref().unwrap()); + } + self.str_calc = Some("bar".to_string()); + return Ok(self.str_calc.as_ref().unwrap()); + } + fn eos_or_calc_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.eos_or_calc_bytes.is_some() { + return Ok(self.eos_or_calc_bytes.as_ref().unwrap()); + } + self.eos_or_calc_bytes = Some(if true { self.str_eos } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); + return Ok(self.eos_or_calc_bytes.as_ref().unwrap()); + } + fn calc_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.calc_bytes.is_some() { + return Ok(self.calc_bytes.as_ref().unwrap()); + } + self.calc_bytes = Some(&[0x62, 0x61, 0x7a] as Vec); + return Ok(self.calc_bytes.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/debug_0.rs b/spec/rust/formats/debug_0.rs new file mode 100644 index 000000000..ef53c2b95 --- /dev/null +++ b/spec/rust/formats/debug_0.rs @@ -0,0 +1,49 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Debug0 { + pub one: u8, + pub array_of_ints: Vec, + pub _unnamed2: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Debug0 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + self.array_of_ints = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(array_of_ints), _io, Int1Type(false), IntNum(3)) + // handleAssignmentRepeatExpr(NamedIdentifier(array_of_ints), _io.read_u1()?) + } + self._unnamed2 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> Debug0 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Debug0::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/default_big_endian.rs b/spec/rust/formats/default_big_endian.rs new file mode 100644 index 000000000..8b71d7775 --- /dev/null +++ b/spec/rust/formats/default_big_endian.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultBigEndian { + pub one: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBigEndian { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u4be()?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultBigEndian { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultBigEndian::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/default_bit_endian_mod.rs b/spec/rust/formats/default_bit_endian_mod.rs new file mode 100644 index 000000000..b278a5b9e --- /dev/null +++ b/spec/rust/formats/default_bit_endian_mod.rs @@ -0,0 +1,147 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultBitEndianMod { + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultBitEndianMod { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultBitEndianMod::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultBitEndianMod_MainObj { + pub one: u64, + pub two: u64, + pub nest: Option, + pub nest_be: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod_MainObj { + type Root = DefaultBitEndianMod; + type ParentStack = (&'r DefaultBitEndianMod, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_bits_int(9)?; + self.two = _io.read_bits_int(15)?; + _io.align_to_byte()?; + self.nest = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.nest_be = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultBitEndianMod_MainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultBitEndianMod_MainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultBitEndianMod_MainObj_Subnest { + pub two: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod_MainObj_Subnest { + type Root = DefaultBitEndianMod; + type ParentStack = (&'r DefaultBitEndianMod_MainObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.two = _io.read_bits_int(16)?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultBitEndianMod_MainObj_Subnest { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultBitEndianMod_MainObj_Subnest::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultBitEndianMod_MainObj_SubnestBe { + pub two: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod_MainObj_SubnestBe { + type Root = DefaultBitEndianMod; + type ParentStack = (&'r DefaultBitEndianMod_MainObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.two = _io.read_bits_int(16)?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultBitEndianMod_MainObj_SubnestBe { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultBitEndianMod_MainObj_SubnestBe::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/default_endian_expr_exception.rs b/spec/rust/formats/default_endian_expr_exception.rs new file mode 100644 index 000000000..40d7819d2 --- /dev/null +++ b/spec/rust/formats/default_endian_expr_exception.rs @@ -0,0 +1,119 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprException { + pub docs: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprException { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.docs = Vec::new(); + { + type ArrayElement = DefaultEndianExprException_Doc; + while !_io.is_eof() { + self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprException { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprException::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprException_Doc { + pub indicator: Vec, + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprException_Doc { + type Root = DefaultEndianExprException; + type ParentStack = (&'r DefaultEndianExprException, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.indicator = _io.read_bytes(2 as usize)?.to_vec(); + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprException_Doc { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprException_Doc::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprException_Doc_MainObj { + pub some_int: u32, + pub some_int_be: u16, + pub some_int_le: u16, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprException_Doc_MainObj { + type Root = DefaultEndianExprException; + type ParentStack = (&'r DefaultEndianExprException_Doc, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.some_int = panic!("Unable to parse unknown-endian integers"); + self.some_int_be = _io.read_u2be()?; + self.some_int_le = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprException_Doc_MainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprException_Doc_MainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/default_endian_expr_inherited.rs b/spec/rust/formats/default_endian_expr_inherited.rs new file mode 100644 index 000000000..39b59d9b4 --- /dev/null +++ b/spec/rust/formats/default_endian_expr_inherited.rs @@ -0,0 +1,200 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprInherited { + pub docs: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.docs = Vec::new(); + { + type ArrayElement = DefaultEndianExprInherited_Doc; + while !_io.is_eof() { + self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprInherited { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprInherited::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprInherited_Doc { + pub indicator: Vec, + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc { + type Root = DefaultEndianExprInherited; + type ParentStack = (&'r DefaultEndianExprInherited, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.indicator = _io.read_bytes(2 as usize)?.to_vec(); + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprInherited_Doc { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprInherited_Doc::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprInherited_Doc_MainObj { + pub insides: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc_MainObj { + type Root = DefaultEndianExprInherited; + type ParentStack = (&'r DefaultEndianExprInherited_Doc, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.insides = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self), self._is_le)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprInherited_Doc_MainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprInherited_Doc_MainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprInherited_Doc_MainObj_SubObj { + pub some_int: u32, + pub more: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc_MainObj_SubObj { + type Root = DefaultEndianExprInherited; + type ParentStack = (&'r DefaultEndianExprInherited_Doc_MainObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.some_int = panic!("Unable to parse unknown-endian integers"); + self.more = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self), self._is_le)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprInherited_Doc_MainObj_SubObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprInherited_Doc_MainObj_SubObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj { + pub some_int1: u16, + pub some_int2: u16, + pub some_inst: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj { + type Root = DefaultEndianExprInherited; + type ParentStack = (&'r DefaultEndianExprInherited_Doc_MainObj_SubObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.some_int1 = panic!("Unable to parse unknown-endian integers"); + self.some_int2 = panic!("Unable to parse unknown-endian integers"); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn some_inst( + &mut self, + _io: &'s S, + _root: Option<&'r DefaultEndianExprInherited>, + _parent: Option>::ParentStack)>> + ) -> KResult<&u32> { + if self.some_inst.is_some() { + return Ok(self.some_inst.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(2)) + // popPos(_io) + return Ok(self.some_inst.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/default_endian_expr_is_be.rs b/spec/rust/formats/default_endian_expr_is_be.rs new file mode 100644 index 000000000..1d38ef23d --- /dev/null +++ b/spec/rust/formats/default_endian_expr_is_be.rs @@ -0,0 +1,182 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprIsBe { + pub docs: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.docs = Vec::new(); + { + type ArrayElement = DefaultEndianExprIsBe_Doc; + while !_io.is_eof() { + self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprIsBe { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprIsBe::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprIsBe_Doc { + pub indicator: Vec, + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe_Doc { + type Root = DefaultEndianExprIsBe; + type ParentStack = (&'r DefaultEndianExprIsBe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.indicator = _io.read_bytes(2 as usize)?.to_vec(); + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprIsBe_Doc { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprIsBe_Doc::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprIsBe_Doc_MainObj { + pub some_int: u32, + pub some_int_be: u16, + pub some_int_le: u16, + pub inst_int: Option, + pub inst_sub: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe_Doc_MainObj { + type Root = DefaultEndianExprIsBe; + type ParentStack = (&'r DefaultEndianExprIsBe_Doc, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.some_int = panic!("Unable to parse unknown-endian integers"); + self.some_int_be = _io.read_u2be()?; + self.some_int_le = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprIsBe_Doc_MainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprIsBe_Doc_MainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn inst_int( + &mut self, + _io: &'s S, + _root: Option<&'r DefaultEndianExprIsBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&u32> { + if self.inst_int.is_some() { + return Ok(self.inst_int.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(2)) + // popPos(_io) + return Ok(self.inst_int.as_ref().unwrap()); + } + fn inst_sub( + &mut self, + _io: &'s S, + _root: Option<&'r DefaultEndianExprIsBe>, + _parent: Option>::ParentStack)>> + ) -> KResult<&DefaultEndianExprIsBe_Doc_MainObj_SubMainObj> { + if self.inst_sub.is_some() { + return Ok(self.inst_sub.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(2)) + // popPos(_io) + return Ok(self.inst_sub.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprIsBe_Doc_MainObj_SubMainObj { + pub foo: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe_Doc_MainObj_SubMainObj { + type Root = DefaultEndianExprIsBe; + type ParentStack = (&'r DefaultEndianExprIsBe_Doc_MainObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = panic!("Unable to parse unknown-endian integers"); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprIsBe_Doc_MainObj_SubMainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprIsBe_Doc_MainObj_SubMainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/default_endian_expr_is_le.rs b/spec/rust/formats/default_endian_expr_is_le.rs new file mode 100644 index 000000000..ad1ccb6ef --- /dev/null +++ b/spec/rust/formats/default_endian_expr_is_le.rs @@ -0,0 +1,119 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprIsLe { + pub docs: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsLe { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.docs = Vec::new(); + { + type ArrayElement = DefaultEndianExprIsLe_Doc; + while !_io.is_eof() { + self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprIsLe { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprIsLe::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprIsLe_Doc { + pub indicator: Vec, + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsLe_Doc { + type Root = DefaultEndianExprIsLe; + type ParentStack = (&'r DefaultEndianExprIsLe, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.indicator = _io.read_bytes(2 as usize)?.to_vec(); + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprIsLe_Doc { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprIsLe_Doc::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianExprIsLe_Doc_MainObj { + pub some_int: u32, + pub some_int_be: u16, + pub some_int_le: u16, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsLe_Doc_MainObj { + type Root = DefaultEndianExprIsLe; + type ParentStack = (&'r DefaultEndianExprIsLe_Doc, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.some_int = panic!("Unable to parse unknown-endian integers"); + self.some_int_be = _io.read_u2be()?; + self.some_int_le = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianExprIsLe_Doc_MainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianExprIsLe_Doc_MainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/default_endian_mod.rs b/spec/rust/formats/default_endian_mod.rs new file mode 100644 index 000000000..c59c93fa7 --- /dev/null +++ b/spec/rust/formats/default_endian_mod.rs @@ -0,0 +1,144 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianMod { + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianMod { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianMod::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianMod_MainObj { + pub one: i32, + pub nest: Option, + pub nest_be: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod_MainObj { + type Root = DefaultEndianMod; + type ParentStack = (&'r DefaultEndianMod, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_s4le()?; + self.nest = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.nest_be = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianMod_MainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianMod_MainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianMod_MainObj_Subnest { + pub two: i32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod_MainObj_Subnest { + type Root = DefaultEndianMod; + type ParentStack = (&'r DefaultEndianMod_MainObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.two = _io.read_s4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianMod_MainObj_Subnest { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianMod_MainObj_Subnest::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct DefaultEndianMod_MainObj_SubnestBe { + pub two: i32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod_MainObj_SubnestBe { + type Root = DefaultEndianMod; + type ParentStack = (&'r DefaultEndianMod_MainObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.two = _io.read_s4be()?; + Ok(()) + } +} +impl<'r, 's: 'r> DefaultEndianMod_MainObj_SubnestBe { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DefaultEndianMod_MainObj_SubnestBe::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/docstrings.rs b/spec/rust/formats/docstrings.rs new file mode 100644 index 000000000..95c887ab8 --- /dev/null +++ b/spec/rust/formats/docstrings.rs @@ -0,0 +1,105 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// universalDoc() + +#[derive(Default, Debug, PartialEq)] +pub struct Docstrings { + pub one: u8, + pub two: Option, + pub three: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Docstrings { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> Docstrings { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Docstrings::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + // universalDoc() + fn two( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.two.is_some() { + return Ok(self.two.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(0)) + // popPos(_io) + return Ok(self.two.as_ref().unwrap()); + } + // universalDoc() + fn three( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i8> { + if self.three.is_some() { + return Ok(self.three.as_ref().unwrap()); + } + self.three = Some(66 as i8); + return Ok(self.three.as_ref().unwrap()); + } +} +// universalDoc() +// universalDoc() + +#[derive(Default, Debug, PartialEq)] +pub struct Docstrings_ComplexSubtype { +} +impl<'r, 's: 'r> KStruct<'r, 's> for Docstrings_ComplexSubtype { + type Root = Docstrings; + type ParentStack = (&'r Docstrings, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> Docstrings_ComplexSubtype { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Docstrings_ComplexSubtype::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/docstrings_docref.rs b/spec/rust/formats/docstrings_docref.rs new file mode 100644 index 000000000..c100671d8 --- /dev/null +++ b/spec/rust/formats/docstrings_docref.rs @@ -0,0 +1,79 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// universalDoc() + +#[derive(Default, Debug, PartialEq)] +pub struct DocstringsDocref { + pub one: u8, + pub two: u8, + pub three: u8, + pub foo: Option, + pub parse_inst: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for DocstringsDocref { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + self.two = _io.read_u1()?; + self.three = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> DocstringsDocref { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DocstringsDocref::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + // universalDoc() + fn foo( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.foo.is_some() { + return Ok(self.foo.as_ref().unwrap()); + } + self.foo = Some(true as bool); + return Ok(self.foo.as_ref().unwrap()); + } + // universalDoc() + fn parse_inst( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.parse_inst.is_some() { + return Ok(self.parse_inst.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(0)) + // popPos(_io) + return Ok(self.parse_inst.as_ref().unwrap()); + } +} +// universalDoc() +// universalDoc() +// universalDoc() diff --git a/spec/rust/formats/docstrings_docref_multi.rs b/spec/rust/formats/docstrings_docref_multi.rs new file mode 100644 index 000000000..51bf5bdf7 --- /dev/null +++ b/spec/rust/formats/docstrings_docref_multi.rs @@ -0,0 +1,40 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// universalDoc() + +#[derive(Default, Debug, PartialEq)] +pub struct DocstringsDocrefMulti { +} +impl<'r, 's: 'r> KStruct<'r, 's> for DocstringsDocrefMulti { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> DocstringsDocrefMulti { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = DocstringsDocrefMulti::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/enum_0.rs b/spec/rust/formats/enum_0.rs new file mode 100644 index 000000000..5bf2db999 --- /dev/null +++ b/spec/rust/formats/enum_0.rs @@ -0,0 +1,61 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Enum0 { + pub pet_1: Option, + pub pet_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Enum0 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> Enum0 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Enum0::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum Enum0_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for Enum0_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(Enum0_Animal::Dog), + 7 => Ok(Enum0_Animal::Cat), + 12 => Ok(Enum0_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_1.rs b/spec/rust/formats/enum_1.rs new file mode 100644 index 000000000..84f126017 --- /dev/null +++ b/spec/rust/formats/enum_1.rs @@ -0,0 +1,127 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Enum1 { + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Enum1 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> Enum1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Enum1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct Enum1_MainObj { + pub submain: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Enum1_MainObj { + type Root = Enum1; + type ParentStack = (&'r Enum1, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.submain = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> Enum1_MainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Enum1_MainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum Enum1_MainObj_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for Enum1_MainObj_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(Enum1_MainObj_Animal::Dog), + 7 => Ok(Enum1_MainObj_Animal::Cat), + 12 => Ok(Enum1_MainObj_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct Enum1_MainObj_SubmainObj { + pub pet_1: Option, + pub pet_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Enum1_MainObj_SubmainObj { + type Root = Enum1; + type ParentStack = (&'r Enum1_MainObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> Enum1_MainObj_SubmainObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Enum1_MainObj_SubmainObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/enum_deep.rs b/spec/rust/formats/enum_deep.rs new file mode 100644 index 000000000..f0288281b --- /dev/null +++ b/spec/rust/formats/enum_deep.rs @@ -0,0 +1,141 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumDeep { + pub pet_1: Option, + pub pet_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeep { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumDeep { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumDeep::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct EnumDeep_Container1 { +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeep_Container1 { + type Root = EnumDeep; + type ParentStack = (&'r EnumDeep, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> EnumDeep_Container1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumDeep_Container1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumDeep_Container1_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for EnumDeep_Container1_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumDeep_Container1_Animal::Dog), + 7 => Ok(EnumDeep_Container1_Animal::Cat), + 12 => Ok(EnumDeep_Container1_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct EnumDeep_Container1_Container2 { +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeep_Container1_Container2 { + type Root = EnumDeep; + type ParentStack = (&'r EnumDeep_Container1, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> EnumDeep_Container1_Container2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumDeep_Container1_Container2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumDeep_Container1_Container2_Animal { + Canary, + Turtle, + Hare, +} +impl TryFrom for EnumDeep_Container1_Container2_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumDeep_Container1_Container2_Animal::Canary), + 7 => Ok(EnumDeep_Container1_Container2_Animal::Turtle), + 12 => Ok(EnumDeep_Container1_Container2_Animal::Hare), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_deep_literals.rs b/spec/rust/formats/enum_deep_literals.rs new file mode 100644 index 000000000..64d7002c8 --- /dev/null +++ b/spec/rust/formats/enum_deep_literals.rs @@ -0,0 +1,167 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumDeepLiterals { + pub pet_1: Option, + pub pet_2: Option, + pub is_pet_1_ok: Option, + pub is_pet_2_ok: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeepLiterals { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumDeepLiterals { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumDeepLiterals::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn is_pet_1_ok( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_pet_1_ok.is_some() { + return Ok(self.is_pet_1_ok.as_ref().unwrap()); + } + self.is_pet_1_ok = Some(self.pet_1 == EnumDeepLiterals_Container1_Animal::Cat as bool); + return Ok(self.is_pet_1_ok.as_ref().unwrap()); + } + fn is_pet_2_ok( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_pet_2_ok.is_some() { + return Ok(self.is_pet_2_ok.as_ref().unwrap()); + } + self.is_pet_2_ok = Some(self.pet_2 == EnumDeepLiterals_Container1_Container2_Animal::Hare as bool); + return Ok(self.is_pet_2_ok.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct EnumDeepLiterals_Container1 { +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeepLiterals_Container1 { + type Root = EnumDeepLiterals; + type ParentStack = (&'r EnumDeepLiterals, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> EnumDeepLiterals_Container1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumDeepLiterals_Container1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumDeepLiterals_Container1_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for EnumDeepLiterals_Container1_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumDeepLiterals_Container1_Animal::Dog), + 7 => Ok(EnumDeepLiterals_Container1_Animal::Cat), + 12 => Ok(EnumDeepLiterals_Container1_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct EnumDeepLiterals_Container1_Container2 { +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeepLiterals_Container1_Container2 { + type Root = EnumDeepLiterals; + type ParentStack = (&'r EnumDeepLiterals_Container1, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> EnumDeepLiterals_Container1_Container2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumDeepLiterals_Container1_Container2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumDeepLiterals_Container1_Container2_Animal { + Canary, + Turtle, + Hare, +} +impl TryFrom for EnumDeepLiterals_Container1_Container2_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumDeepLiterals_Container1_Container2_Animal::Canary), + 7 => Ok(EnumDeepLiterals_Container1_Container2_Animal::Turtle), + 12 => Ok(EnumDeepLiterals_Container1_Container2_Animal::Hare), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_fancy.rs b/spec/rust/formats/enum_fancy.rs new file mode 100644 index 000000000..243aafa9a --- /dev/null +++ b/spec/rust/formats/enum_fancy.rs @@ -0,0 +1,63 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumFancy { + pub pet_1: Option, + pub pet_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumFancy { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumFancy { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumFancy::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumFancy_Animal { + // universalDoc() + Dog, + // universalDoc() + Cat, + Chicken, +} +impl TryFrom for EnumFancy_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumFancy_Animal::Dog), + 7 => Ok(EnumFancy_Animal::Cat), + 12 => Ok(EnumFancy_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_for_unknown_id.rs b/spec/rust/formats/enum_for_unknown_id.rs new file mode 100644 index 000000000..a37a82fb5 --- /dev/null +++ b/spec/rust/formats/enum_for_unknown_id.rs @@ -0,0 +1,59 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumForUnknownId { + pub one: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumForUnknownId { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some((_io.read_u1()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumForUnknownId { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumForUnknownId::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumForUnknownId_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for EnumForUnknownId_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumForUnknownId_Animal::Dog), + 7 => Ok(EnumForUnknownId_Animal::Cat), + 12 => Ok(EnumForUnknownId_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_if.rs b/spec/rust/formats/enum_if.rs new file mode 100644 index 000000000..dfe1b8df0 --- /dev/null +++ b/spec/rust/formats/enum_if.rs @@ -0,0 +1,174 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumIf { + pub op1: Option, + pub op2: Option, + pub op3: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.op1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.op2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.op3 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumIf { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumIf::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumIf_Opcodes { + AString, + ATuple, +} +impl TryFrom for EnumIf_Opcodes { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 83 => Ok(EnumIf_Opcodes::AString), + 84 => Ok(EnumIf_Opcodes::ATuple), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct EnumIf_Operation { + pub opcode: Option, + pub arg_tuple: Option, + pub arg_str: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf_Operation { + type Root = EnumIf; + type ParentStack = (&'r EnumIf, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcode = Some((_io.read_u1()? as i64).try_into()?); + { + // condIfHeader(Compare(Name(identifier(opcode)),Eq,EnumByLabel(identifier(opcodes),identifier(a_tuple),typeId(false,List(),false)))) + self.arg_tuple = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + } + { + // condIfHeader(Compare(Name(identifier(opcode)),Eq,EnumByLabel(identifier(opcodes),identifier(a_string),typeId(false,List(),false)))) + self.arg_str = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + } + Ok(()) + } +} +impl<'r, 's: 'r> EnumIf_Operation { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumIf_Operation::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct EnumIf_ArgTuple { + pub num1: u8, + pub num2: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf_ArgTuple { + type Root = EnumIf; + type ParentStack = (&'r EnumIf, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.num1 = _io.read_u1()?; + self.num2 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> EnumIf_ArgTuple { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumIf_ArgTuple::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct EnumIf_ArgStr { + pub len: u8, + pub str: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf_ArgStr { + type Root = EnumIf; + type ParentStack = (&'r EnumIf, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len = _io.read_u1()?; + self.str = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> EnumIf_ArgStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumIf_ArgStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/enum_import.rs b/spec/rust/formats/enum_import.rs new file mode 100644 index 000000000..ca0535be0 --- /dev/null +++ b/spec/rust/formats/enum_import.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumImport { + pub pet_1: Option, + pub pet_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumImport { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumImport { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumImport::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/enum_int_range_s.rs b/spec/rust/formats/enum_int_range_s.rs new file mode 100644 index 000000000..3e04b147f --- /dev/null +++ b/spec/rust/formats/enum_int_range_s.rs @@ -0,0 +1,63 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumIntRangeS { + pub f1: Option, + pub f2: Option, + pub f3: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumIntRangeS { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.f1 = Some((_io.read_s4be()? as i64).try_into()?); + self.f2 = Some((_io.read_s4be()? as i64).try_into()?); + self.f3 = Some((_io.read_s4be()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumIntRangeS { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumIntRangeS::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumIntRangeS_Constants { + IntMin, + Zero, + IntMax, +} +impl TryFrom for EnumIntRangeS_Constants { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + -2147483648 => Ok(EnumIntRangeS_Constants::IntMin), + 0 => Ok(EnumIntRangeS_Constants::Zero), + 2147483647 => Ok(EnumIntRangeS_Constants::IntMax), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_int_range_u.rs b/spec/rust/formats/enum_int_range_u.rs new file mode 100644 index 000000000..05543f4cd --- /dev/null +++ b/spec/rust/formats/enum_int_range_u.rs @@ -0,0 +1,59 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumIntRangeU { + pub f1: Option, + pub f2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumIntRangeU { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.f1 = Some((_io.read_u4be()? as i64).try_into()?); + self.f2 = Some((_io.read_u4be()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumIntRangeU { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumIntRangeU::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumIntRangeU_Constants { + Zero, + IntMax, +} +impl TryFrom for EnumIntRangeU_Constants { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 0 => Ok(EnumIntRangeU_Constants::Zero), + 4294967295 => Ok(EnumIntRangeU_Constants::IntMax), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_invalid.rs b/spec/rust/formats/enum_invalid.rs new file mode 100644 index 000000000..11a6d0671 --- /dev/null +++ b/spec/rust/formats/enum_invalid.rs @@ -0,0 +1,59 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumInvalid { + pub pet_1: Option, + pub pet_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumInvalid { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u1()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u1()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumInvalid { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumInvalid::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumInvalid_Animal { + Dog, + Cat, +} +impl TryFrom for EnumInvalid_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 102 => Ok(EnumInvalid_Animal::Dog), + 124 => Ok(EnumInvalid_Animal::Cat), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_long_range_s.rs b/spec/rust/formats/enum_long_range_s.rs new file mode 100644 index 000000000..b80a9dff3 --- /dev/null +++ b/spec/rust/formats/enum_long_range_s.rs @@ -0,0 +1,79 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumLongRangeS { + pub f1: Option, + pub f2: Option, + pub f3: Option, + pub f4: Option, + pub f5: Option, + pub f6: Option, + pub f7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumLongRangeS { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.f1 = Some((_io.read_s8be()? as i64).try_into()?); + self.f2 = Some((_io.read_s8be()? as i64).try_into()?); + self.f3 = Some((_io.read_s8be()? as i64).try_into()?); + self.f4 = Some((_io.read_s8be()? as i64).try_into()?); + self.f5 = Some((_io.read_s8be()? as i64).try_into()?); + self.f6 = Some((_io.read_s8be()? as i64).try_into()?); + self.f7 = Some((_io.read_s8be()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumLongRangeS { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumLongRangeS::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumLongRangeS_Constants { + LongMin, + IntBelowMin, + IntMin, + Zero, + IntMax, + IntOverMax, + LongMax, +} +impl TryFrom for EnumLongRangeS_Constants { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + -9223372036854775808 => Ok(EnumLongRangeS_Constants::LongMin), + -2147483649 => Ok(EnumLongRangeS_Constants::IntBelowMin), + -2147483648 => Ok(EnumLongRangeS_Constants::IntMin), + 0 => Ok(EnumLongRangeS_Constants::Zero), + 2147483647 => Ok(EnumLongRangeS_Constants::IntMax), + 2147483648 => Ok(EnumLongRangeS_Constants::IntOverMax), + 9223372036854775807 => Ok(EnumLongRangeS_Constants::LongMax), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_long_range_u.rs b/spec/rust/formats/enum_long_range_u.rs new file mode 100644 index 000000000..fb974ee89 --- /dev/null +++ b/spec/rust/formats/enum_long_range_u.rs @@ -0,0 +1,67 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumLongRangeU { + pub f1: Option, + pub f2: Option, + pub f3: Option, + pub f4: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumLongRangeU { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.f1 = Some((_io.read_u8be()? as i64).try_into()?); + self.f2 = Some((_io.read_u8be()? as i64).try_into()?); + self.f3 = Some((_io.read_u8be()? as i64).try_into()?); + self.f4 = Some((_io.read_u8be()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumLongRangeU { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumLongRangeU::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumLongRangeU_Constants { + Zero, + IntMax, + IntOverMax, + LongMax, +} +impl TryFrom for EnumLongRangeU_Constants { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 0 => Ok(EnumLongRangeU_Constants::Zero), + 4294967295 => Ok(EnumLongRangeU_Constants::IntMax), + 4294967296 => Ok(EnumLongRangeU_Constants::IntOverMax), + 9223372036854775807 => Ok(EnumLongRangeU_Constants::LongMax), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_negative.rs b/spec/rust/formats/enum_negative.rs new file mode 100644 index 000000000..59ceb25f9 --- /dev/null +++ b/spec/rust/formats/enum_negative.rs @@ -0,0 +1,59 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumNegative { + pub f1: Option, + pub f2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumNegative { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.f1 = Some((_io.read_s1()? as i64).try_into()?); + self.f2 = Some((_io.read_s1()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumNegative { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumNegative::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum EnumNegative_Constants { + NegativeOne, + PositiveOne, +} +impl TryFrom for EnumNegative_Constants { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + -1 => Ok(EnumNegative_Constants::NegativeOne), + 1 => Ok(EnumNegative_Constants::PositiveOne), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_of_value_inst.rs b/spec/rust/formats/enum_of_value_inst.rs new file mode 100644 index 000000000..db6bb488b --- /dev/null +++ b/spec/rust/formats/enum_of_value_inst.rs @@ -0,0 +1,87 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumOfValueInst { + pub pet_1: Option, + pub pet_2: Option, + pub pet_3: Option, + pub pet_4: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumOfValueInst { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumOfValueInst { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumOfValueInst::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn pet_3( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&EnumOfValueInst_Animal> { + if self.pet_3.is_some() { + return Ok(self.pet_3.as_ref().unwrap()); + } + self.pet_3 = Some(if self.pet_1 == EnumOfValueInst_Animal::Cat { 4 } else { 12} as i32); + return Ok(self.pet_3.as_ref().unwrap()); + } + fn pet_4( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&EnumOfValueInst_Animal> { + if self.pet_4.is_some() { + return Ok(self.pet_4.as_ref().unwrap()); + } + self.pet_4 = Some(if self.pet_1 == EnumOfValueInst_Animal::Cat { EnumOfValueInst_Animal::Dog } else { EnumOfValueInst_Animal::Chicken} as i32); + return Ok(self.pet_4.as_ref().unwrap()); + } +} +#[derive(Debug, PartialEq)] +pub enum EnumOfValueInst_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for EnumOfValueInst_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumOfValueInst_Animal::Dog), + 7 => Ok(EnumOfValueInst_Animal::Cat), + 12 => Ok(EnumOfValueInst_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_to_i.rs b/spec/rust/formats/enum_to_i.rs new file mode 100644 index 000000000..3ef671262 --- /dev/null +++ b/spec/rust/formats/enum_to_i.rs @@ -0,0 +1,126 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumToI { + pub pet_1: Option, + pub pet_2: Option, + pub pet_1_i: Option, + pub pet_1_eq_int: Option, + pub one_lt_two: Option, + pub pet_1_mod: Option, + pub pet_2_eq_int: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumToI { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumToI { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumToI::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn pet_1_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.pet_1_i.is_some() { + return Ok(self.pet_1_i.as_ref().unwrap()); + } + self.pet_1_i = Some(self.pet_1 as i32); + return Ok(self.pet_1_i.as_ref().unwrap()); + } + fn pet_1_eq_int( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.pet_1_eq_int.is_some() { + return Ok(self.pet_1_eq_int.as_ref().unwrap()); + } + self.pet_1_eq_int = Some(self.pet_1 == 7 as bool); + return Ok(self.pet_1_eq_int.as_ref().unwrap()); + } + fn one_lt_two( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.one_lt_two.is_some() { + return Ok(self.one_lt_two.as_ref().unwrap()); + } + self.one_lt_two = Some(self.pet_1 < self.pet_2 as bool); + return Ok(self.one_lt_two.as_ref().unwrap()); + } + fn pet_1_mod( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.pet_1_mod.is_some() { + return Ok(self.pet_1_mod.as_ref().unwrap()); + } + self.pet_1_mod = Some((self.pet_1 + 32768) as i32); + return Ok(self.pet_1_mod.as_ref().unwrap()); + } + fn pet_2_eq_int( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.pet_2_eq_int.is_some() { + return Ok(self.pet_2_eq_int.as_ref().unwrap()); + } + self.pet_2_eq_int = Some(self.pet_2 == 5 as bool); + return Ok(self.pet_2_eq_int.as_ref().unwrap()); + } +} +#[derive(Debug, PartialEq)] +pub enum EnumToI_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for EnumToI_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumToI_Animal::Dog), + 7 => Ok(EnumToI_Animal::Cat), + 12 => Ok(EnumToI_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_to_i_class_border_1.rs b/spec/rust/formats/enum_to_i_class_border_1.rs new file mode 100644 index 000000000..1b58aa590 --- /dev/null +++ b/spec/rust/formats/enum_to_i_class_border_1.rs @@ -0,0 +1,90 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::enum_to_i_class_border_2::EnumToIClassBorder2; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumToIClassBorder1 { + pub pet_1: Option, + pub pet_2: Option, + pub some_dog: Option, + pub checker: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumToIClassBorder1 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); + self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); + Ok(()) + } +} +impl<'r, 's: 'r> EnumToIClassBorder1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumToIClassBorder1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn some_dog( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&EnumToIClassBorder1_Animal> { + if self.some_dog.is_some() { + return Ok(self.some_dog.as_ref().unwrap()); + } + self.some_dog = Some(4 as i32); + return Ok(self.some_dog.as_ref().unwrap()); + } + fn checker( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Box> { + if self.checker.is_some() { + return Ok(self.checker.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(0)) + // popPos(_io) + return Ok(self.checker.as_ref().unwrap()); + } +} +#[derive(Debug, PartialEq)] +pub enum EnumToIClassBorder1_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for EnumToIClassBorder1_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(EnumToIClassBorder1_Animal::Dog), + 7 => Ok(EnumToIClassBorder1_Animal::Cat), + 12 => Ok(EnumToIClassBorder1_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/enum_to_i_class_border_2.rs b/spec/rust/formats/enum_to_i_class_border_2.rs new file mode 100644 index 000000000..e387c1062 --- /dev/null +++ b/spec/rust/formats/enum_to_i_class_border_2.rs @@ -0,0 +1,54 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::enum_to_i_class_border_1::EnumToIClassBorder1; + +#[derive(Default, Debug, PartialEq)] +pub struct EnumToIClassBorder2 { + pub parent: Option>, + pub is_dog: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EnumToIClassBorder2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> EnumToIClassBorder2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EnumToIClassBorder2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn is_dog( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_dog.is_some() { + return Ok(self.is_dog.as_ref().unwrap()); + } + self.is_dog = Some(self.parent.some_dog == 4 as bool); + return Ok(self.is_dog.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/eof_exception_bytes.rs b/spec/rust/formats/eof_exception_bytes.rs new file mode 100644 index 000000000..5ee1eb47f --- /dev/null +++ b/spec/rust/formats/eof_exception_bytes.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EofExceptionBytes { + pub buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EofExceptionBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf = _io.read_bytes(13 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> EofExceptionBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EofExceptionBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/eof_exception_u4.rs b/spec/rust/formats/eof_exception_u4.rs new file mode 100644 index 000000000..9187e9fcb --- /dev/null +++ b/spec/rust/formats/eof_exception_u4.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct EofExceptionU4 { + pub prebuf: Vec, + pub fail_int: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EofExceptionU4 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.prebuf = _io.read_bytes(9 as usize)?.to_vec(); + self.fail_int = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> EofExceptionU4 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EofExceptionU4::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/eos_exception_bytes.rs b/spec/rust/formats/eos_exception_bytes.rs new file mode 100644 index 000000000..8a3327ee8 --- /dev/null +++ b/spec/rust/formats/eos_exception_bytes.rs @@ -0,0 +1,76 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(envelope)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct EosExceptionBytes { + pub envelope: Option, + pub raw_envelope: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.envelope = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(6 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> EosExceptionBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EosExceptionBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct EosExceptionBytes_Data { + pub buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionBytes_Data { + type Root = EosExceptionBytes; + type ParentStack = (&'r EosExceptionBytes, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf = _io.read_bytes(7 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> EosExceptionBytes_Data { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EosExceptionBytes_Data::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/eos_exception_u4.rs b/spec/rust/formats/eos_exception_u4.rs new file mode 100644 index 000000000..6c4ad0bb8 --- /dev/null +++ b/spec/rust/formats/eos_exception_u4.rs @@ -0,0 +1,78 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(envelope)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct EosExceptionU4 { + pub envelope: Option, + pub raw_envelope: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionU4 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.envelope = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(6 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> EosExceptionU4 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EosExceptionU4::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct EosExceptionU4_Data { + pub prebuf: Vec, + pub fail_int: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionU4_Data { + type Root = EosExceptionU4; + type ParentStack = (&'r EosExceptionU4, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.prebuf = _io.read_bytes(3 as usize)?.to_vec(); + self.fail_int = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> EosExceptionU4_Data { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = EosExceptionU4_Data::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/expr_0.rs b/spec/rust/formats/expr_0.rs new file mode 100644 index 000000000..67be5b38e --- /dev/null +++ b/spec/rust/formats/expr_0.rs @@ -0,0 +1,67 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Expr0 { + pub len_of_1: u16, + pub must_be_f7: Option, + pub must_be_abc123: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Expr0 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_of_1 = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> Expr0 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Expr0::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn must_be_f7( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.must_be_f7.is_some() { + return Ok(self.must_be_f7.as_ref().unwrap()); + } + self.must_be_f7 = Some((7 + 240) as i32); + return Ok(self.must_be_f7.as_ref().unwrap()); + } + fn must_be_abc123( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.must_be_abc123.is_some() { + return Ok(self.must_be_abc123.as_ref().unwrap()); + } + self.must_be_abc123 = Some(format!("{}{}", "abc", "123").to_string()); + return Ok(self.must_be_abc123.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_1.rs b/spec/rust/formats/expr_1.rs new file mode 100644 index 000000000..e677a7851 --- /dev/null +++ b/spec/rust/formats/expr_1.rs @@ -0,0 +1,69 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Expr1 { + pub len_of_1: u16, + pub str1: String, + pub len_of_1_mod: Option, + pub str1_len: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Expr1 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_of_1 = _io.read_u2le()?; + self.str1 = decode_string(_io.read_bytes(self.len_of_1_mod(_io, _root, _parent)? as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> Expr1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Expr1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn len_of_1_mod( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.len_of_1_mod.is_some() { + return Ok(self.len_of_1_mod.as_ref().unwrap()); + } + self.len_of_1_mod = Some((self.len_of_1 - 2) as i32); + return Ok(self.len_of_1_mod.as_ref().unwrap()); + } + fn str1_len( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.str1_len.is_some() { + return Ok(self.str1_len.as_ref().unwrap()); + } + self.str1_len = Some(self.str1.len() as i32); + return Ok(self.str1_len.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_2.rs b/spec/rust/formats/expr_2.rs new file mode 100644 index 000000000..4db30fe40 --- /dev/null +++ b/spec/rust/formats/expr_2.rs @@ -0,0 +1,266 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Expr2 { + pub str1: Option, + pub str2: Option, + pub str1_len_mod: Option, + pub str1_len: Option, + pub str1_tuple5: Option, + pub str2_tuple5: Option, + pub str1_avg: Option, + pub str1_byte1: Option, + pub str1_char5: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Expr2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.str1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.str2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> Expr2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Expr2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn str1_len_mod( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.str1_len_mod.is_some() { + return Ok(self.str1_len_mod.as_ref().unwrap()); + } + self.str1_len_mod = Some(self.str1.len_mod as i32); + return Ok(self.str1_len_mod.as_ref().unwrap()); + } + fn str1_len( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.str1_len.is_some() { + return Ok(self.str1_len.as_ref().unwrap()); + } + self.str1_len = Some(self.str1.str.len() as i32); + return Ok(self.str1_len.as_ref().unwrap()); + } + fn str1_tuple5( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Expr2_Tuple> { + if self.str1_tuple5.is_some() { + return Ok(self.str1_tuple5.as_ref().unwrap()); + } + self.str1_tuple5 = Some(self.str1.tuple5 as Tuple); + return Ok(self.str1_tuple5.as_ref().unwrap()); + } + fn str2_tuple5( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Expr2_Tuple> { + if self.str2_tuple5.is_some() { + return Ok(self.str2_tuple5.as_ref().unwrap()); + } + self.str2_tuple5 = Some(self.str2.tuple5 as Tuple); + return Ok(self.str2_tuple5.as_ref().unwrap()); + } + fn str1_avg( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.str1_avg.is_some() { + return Ok(self.str1_avg.as_ref().unwrap()); + } + self.str1_avg = Some(self.str1.rest.avg as i32); + return Ok(self.str1_avg.as_ref().unwrap()); + } + fn str1_byte1( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.str1_byte1.is_some() { + return Ok(self.str1_byte1.as_ref().unwrap()); + } + self.str1_byte1 = Some(self.str1.rest.byte1 as u8); + return Ok(self.str1_byte1.as_ref().unwrap()); + } + fn str1_char5( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.str1_char5.is_some() { + return Ok(self.str1_char5.as_ref().unwrap()); + } + self.str1_char5 = Some(self.str1.char5.to_string()); + return Ok(self.str1_char5.as_ref().unwrap()); + } +} +// extraAttrForIO(RawIdentifier(NamedIdentifier(rest)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct Expr2_ModStr { + pub len_orig: u16, + pub str: String, + pub rest: Option, + pub raw_rest: Vec, + pub len_mod: Option, + pub char5: Option, + pub tuple5: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Expr2_ModStr { + type Root = Expr2; + type ParentStack = (&'r Expr2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_orig = _io.read_u2le()?; + self.str = decode_string(_io.read_bytes(self.len_mod(_io, _root, _parent)? as usize)?, "UTF-8")?; + self.rest = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(3 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> Expr2_ModStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Expr2_ModStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn len_mod( + &mut self, + _io: &'s S, + _root: Option<&'r Expr2>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.len_mod.is_some() { + return Ok(self.len_mod.as_ref().unwrap()); + } + self.len_mod = Some((self.len_orig - 3) as i32); + return Ok(self.len_mod.as_ref().unwrap()); + } + fn char5( + &mut self, + _io: &'s S, + _root: Option<&'r Expr2>, + _parent: Option>::ParentStack)>> + ) -> KResult<&String> { + if self.char5.is_some() { + return Ok(self.char5.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(5)) + // popPos(_io) + return Ok(self.char5.as_ref().unwrap()); + } + fn tuple5( + &mut self, + _io: &'s S, + _root: Option<&'r Expr2>, + _parent: Option>::ParentStack)>> + ) -> KResult<&Expr2_Tuple> { + if self.tuple5.is_some() { + return Ok(self.tuple5.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(5)) + // popPos(_io) + return Ok(self.tuple5.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct Expr2_Tuple { + pub byte0: u8, + pub byte1: u8, + pub byte2: u8, + pub avg: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Expr2_Tuple { + type Root = Expr2; + type ParentStack = (&'r Expr2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.byte0 = _io.read_u1()?; + self.byte1 = _io.read_u1()?; + self.byte2 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> Expr2_Tuple { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Expr2_Tuple::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn avg( + &mut self, + _io: &'s S, + _root: Option<&'r Expr2>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.avg.is_some() { + return Ok(self.avg.as_ref().unwrap()); + } + self.avg = Some((self.byte1 + self.byte2) / 2 as i32); + return Ok(self.avg.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_3.rs b/spec/rust/formats/expr_3.rs new file mode 100644 index 000000000..3d7ca8235 --- /dev/null +++ b/spec/rust/formats/expr_3.rs @@ -0,0 +1,173 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Expr3 { + pub one: u8, + pub two: String, + pub three: Option, + pub is_str_ge: Option, + pub is_str_ne: Option, + pub is_str_gt: Option, + pub is_str_le: Option, + pub is_str_lt2: Option, + pub test_not: Option, + pub is_str_lt: Option, + pub four: Option, + pub is_str_eq: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Expr3 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + self.two = decode_string(_io.read_bytes(3 as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> Expr3 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Expr3::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn three( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.three.is_some() { + return Ok(self.three.as_ref().unwrap()); + } + self.three = Some(format!("{}{}", "@", self.two).to_string()); + return Ok(self.three.as_ref().unwrap()); + } + fn is_str_ge( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_str_ge.is_some() { + return Ok(self.is_str_ge.as_ref().unwrap()); + } + self.is_str_ge = Some(self.two >= "ACK2" as bool); + return Ok(self.is_str_ge.as_ref().unwrap()); + } + fn is_str_ne( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_str_ne.is_some() { + return Ok(self.is_str_ne.as_ref().unwrap()); + } + self.is_str_ne = Some(self.two != "ACK" as bool); + return Ok(self.is_str_ne.as_ref().unwrap()); + } + fn is_str_gt( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_str_gt.is_some() { + return Ok(self.is_str_gt.as_ref().unwrap()); + } + self.is_str_gt = Some(self.two > "ACK2" as bool); + return Ok(self.is_str_gt.as_ref().unwrap()); + } + fn is_str_le( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_str_le.is_some() { + return Ok(self.is_str_le.as_ref().unwrap()); + } + self.is_str_le = Some(self.two <= "ACK2" as bool); + return Ok(self.is_str_le.as_ref().unwrap()); + } + fn is_str_lt2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_str_lt2.is_some() { + return Ok(self.is_str_lt2.as_ref().unwrap()); + } + self.is_str_lt2 = Some(self.three(_io, _root, _parent)? < self.two as bool); + return Ok(self.is_str_lt2.as_ref().unwrap()); + } + fn test_not( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.test_not.is_some() { + return Ok(self.test_not.as_ref().unwrap()); + } + self.test_not = Some(!(false) as bool); + return Ok(self.test_not.as_ref().unwrap()); + } + fn is_str_lt( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_str_lt.is_some() { + return Ok(self.is_str_lt.as_ref().unwrap()); + } + self.is_str_lt = Some(self.two < "ACK2" as bool); + return Ok(self.is_str_lt.as_ref().unwrap()); + } + fn four( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.four.is_some() { + return Ok(self.four.as_ref().unwrap()); + } + self.four = Some(format!("{}{}", format!("{}{}", "_", self.two), "_").to_string()); + return Ok(self.four.as_ref().unwrap()); + } + fn is_str_eq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_str_eq.is_some() { + return Ok(self.is_str_eq.as_ref().unwrap()); + } + self.is_str_eq = Some(self.two == "ACK" as bool); + return Ok(self.is_str_eq.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_array.rs b/spec/rust/formats/expr_array.rs new file mode 100644 index 000000000..7adc4b643 --- /dev/null +++ b/spec/rust/formats/expr_array.rs @@ -0,0 +1,252 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprArray { + pub aint: Vec, + pub afloat: Vec, + pub astr: Vec, + pub aint_first: Option, + pub afloat_size: Option, + pub astr_size: Option, + pub aint_min: Option, + pub afloat_min: Option, + pub aint_size: Option, + pub aint_last: Option, + pub afloat_last: Option, + pub astr_first: Option, + pub astr_last: Option, + pub aint_max: Option, + pub afloat_first: Option, + pub astr_min: Option, + pub astr_max: Option, + pub afloat_max: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprArray { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.aint = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(aint), _io, IntMultiType(false,Width4,Some(LittleEndian)), IntNum(4)) + // handleAssignmentRepeatExpr(NamedIdentifier(aint), _io.read_u4le()?) + } + self.afloat = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(afloat), _io, FloatMultiType(Width8,Some(LittleEndian)), IntNum(3)) + // handleAssignmentRepeatExpr(NamedIdentifier(afloat), _io.read_f8le()?) + } + self.astr = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(astr), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), IntNum(3)) + // handleAssignmentRepeatExpr(NamedIdentifier(astr), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) + } + Ok(()) + } +} +impl<'r, 's: 'r> ExprArray { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprArray::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn aint_first( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u32> { + if self.aint_first.is_some() { + return Ok(self.aint_first.as_ref().unwrap()); + } + self.aint_first = Some(self.aint.first() as u32); + return Ok(self.aint_first.as_ref().unwrap()); + } + fn afloat_size( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.afloat_size.is_some() { + return Ok(self.afloat_size.as_ref().unwrap()); + } + self.afloat_size = Some(self.afloat.len() as i32); + return Ok(self.afloat_size.as_ref().unwrap()); + } + fn astr_size( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.astr_size.is_some() { + return Ok(self.astr_size.as_ref().unwrap()); + } + self.astr_size = Some(self.astr.len() as i32); + return Ok(self.astr_size.as_ref().unwrap()); + } + fn aint_min( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u32> { + if self.aint_min.is_some() { + return Ok(self.aint_min.as_ref().unwrap()); + } + self.aint_min = Some(self.aint.iter().min() as u32); + return Ok(self.aint_min.as_ref().unwrap()); + } + fn afloat_min( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.afloat_min.is_some() { + return Ok(self.afloat_min.as_ref().unwrap()); + } + self.afloat_min = Some(self.afloat.iter().min() as f64); + return Ok(self.afloat_min.as_ref().unwrap()); + } + fn aint_size( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.aint_size.is_some() { + return Ok(self.aint_size.as_ref().unwrap()); + } + self.aint_size = Some(self.aint.len() as i32); + return Ok(self.aint_size.as_ref().unwrap()); + } + fn aint_last( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u32> { + if self.aint_last.is_some() { + return Ok(self.aint_last.as_ref().unwrap()); + } + self.aint_last = Some(self.aint.last() as u32); + return Ok(self.aint_last.as_ref().unwrap()); + } + fn afloat_last( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.afloat_last.is_some() { + return Ok(self.afloat_last.as_ref().unwrap()); + } + self.afloat_last = Some(self.afloat.last() as f64); + return Ok(self.afloat_last.as_ref().unwrap()); + } + fn astr_first( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.astr_first.is_some() { + return Ok(self.astr_first.as_ref().unwrap()); + } + self.astr_first = Some(self.astr.first().to_string()); + return Ok(self.astr_first.as_ref().unwrap()); + } + fn astr_last( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.astr_last.is_some() { + return Ok(self.astr_last.as_ref().unwrap()); + } + self.astr_last = Some(self.astr.last().to_string()); + return Ok(self.astr_last.as_ref().unwrap()); + } + fn aint_max( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u32> { + if self.aint_max.is_some() { + return Ok(self.aint_max.as_ref().unwrap()); + } + self.aint_max = Some(self.aint.iter().max() as u32); + return Ok(self.aint_max.as_ref().unwrap()); + } + fn afloat_first( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.afloat_first.is_some() { + return Ok(self.afloat_first.as_ref().unwrap()); + } + self.afloat_first = Some(self.afloat.first() as f64); + return Ok(self.afloat_first.as_ref().unwrap()); + } + fn astr_min( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.astr_min.is_some() { + return Ok(self.astr_min.as_ref().unwrap()); + } + self.astr_min = Some(self.astr.iter().min().to_string()); + return Ok(self.astr_min.as_ref().unwrap()); + } + fn astr_max( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.astr_max.is_some() { + return Ok(self.astr_max.as_ref().unwrap()); + } + self.astr_max = Some(self.astr.iter().max().to_string()); + return Ok(self.astr_max.as_ref().unwrap()); + } + fn afloat_max( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.afloat_max.is_some() { + return Ok(self.afloat_max.as_ref().unwrap()); + } + self.afloat_max = Some(self.afloat.iter().max() as f64); + return Ok(self.afloat_max.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_bits.rs b/spec/rust/formats/expr_bits.rs new file mode 100644 index 000000000..cd20bd91e --- /dev/null +++ b/spec/rust/formats/expr_bits.rs @@ -0,0 +1,148 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprBits { + pub enum_seq: Option, + pub a: u64, + pub byte_size: Vec, + pub repeat_expr: Vec, + pub switch_on_type: Option, + pub switch_on_endian: Option, + pub enum_inst: Option, + pub inst_pos: Option, +} +#[derive(Debug, PartialEq)] +pub enum ExprBits_SwitchOnType { + S1(i8), +} +impl From for ExprBits_SwitchOnType { + fn from(v: i8) -> Self { + Self::S1(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for ExprBits { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.enum_seq = Some((_io.read_bits_int(2)? as i64).try_into()?); + self.a = _io.read_bits_int(3)?; + _io.align_to_byte()?; + self.byte_size = _io.read_bytes(self.a as usize)?.to_vec(); + self.repeat_expr = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(repeat_expr), _io, Int1Type(true), Name(identifier(a))) + // handleAssignmentRepeatExpr(NamedIdentifier(repeat_expr), _io.read_s1()?) + } + match self.a { + 2 => { + self.switch_on_type = Some(_io.read_s1()?); + } + _ => panic!("unhandled value") + } + self.switch_on_endian = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ExprBits { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprBits::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn enum_inst( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&ExprBits_Items> { + if self.enum_inst.is_some() { + return Ok(self.enum_inst.as_ref().unwrap()); + } + self.enum_inst = Some(self.a as i32); + return Ok(self.enum_inst.as_ref().unwrap()); + } + fn inst_pos( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i8> { + if self.inst_pos.is_some() { + return Ok(self.inst_pos.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, Name(identifier(a))) + // popPos(_io) + return Ok(self.inst_pos.as_ref().unwrap()); + } +} +#[derive(Debug, PartialEq)] +pub enum ExprBits_Items { + Foo, + Bar, +} +impl TryFrom for ExprBits_Items { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 1 => Ok(ExprBits_Items::Foo), + 2 => Ok(ExprBits_Items::Bar), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct ExprBits_EndianSwitch { + pub foo: i16, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprBits_EndianSwitch { + type Root = ExprBits; + type ParentStack = (&'r ExprBits, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = panic!("Unable to parse unknown-endian integers"); + Ok(()) + } +} +impl<'r, 's: 'r> ExprBits_EndianSwitch { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprBits_EndianSwitch::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/expr_bytes_cmp.rs b/spec/rust/formats/expr_bytes_cmp.rs new file mode 100644 index 000000000..aa4ba5590 --- /dev/null +++ b/spec/rust/formats/expr_bytes_cmp.rs @@ -0,0 +1,186 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprBytesCmp { + pub one: Vec, + pub two: Vec, + pub is_le: Option, + pub ack: Option>, + pub is_gt2: Option, + pub is_gt: Option, + pub ack2: Option>, + pub is_eq: Option, + pub is_lt2: Option, + pub is_ge: Option, + pub hi_val: Option>, + pub is_ne: Option, + pub is_lt: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprBytesCmp { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_bytes(1 as usize)?.to_vec(); + self.two = _io.read_bytes(3 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ExprBytesCmp { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprBytesCmp::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn is_le( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_le.is_some() { + return Ok(self.is_le.as_ref().unwrap()); + } + self.is_le = Some(self.two <= self.ack2(_io, _root, _parent)? as bool); + return Ok(self.is_le.as_ref().unwrap()); + } + fn ack( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.ack.is_some() { + return Ok(self.ack.as_ref().unwrap()); + } + self.ack = Some(&[0x41, 0x43, 0x4b] as Vec); + return Ok(self.ack.as_ref().unwrap()); + } + fn is_gt2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_gt2.is_some() { + return Ok(self.is_gt2.as_ref().unwrap()); + } + self.is_gt2 = Some(self.hi_val(_io, _root, _parent)? > self.two as bool); + return Ok(self.is_gt2.as_ref().unwrap()); + } + fn is_gt( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_gt.is_some() { + return Ok(self.is_gt.as_ref().unwrap()); + } + self.is_gt = Some(self.two > self.ack2(_io, _root, _parent)? as bool); + return Ok(self.is_gt.as_ref().unwrap()); + } + fn ack2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.ack2.is_some() { + return Ok(self.ack2.as_ref().unwrap()); + } + self.ack2 = Some(&[0x41, 0x43, 0x4b, 0x32] as Vec); + return Ok(self.ack2.as_ref().unwrap()); + } + fn is_eq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_eq.is_some() { + return Ok(self.is_eq.as_ref().unwrap()); + } + self.is_eq = Some(self.two == self.ack(_io, _root, _parent)? as bool); + return Ok(self.is_eq.as_ref().unwrap()); + } + fn is_lt2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_lt2.is_some() { + return Ok(self.is_lt2.as_ref().unwrap()); + } + self.is_lt2 = Some(self.one < self.two as bool); + return Ok(self.is_lt2.as_ref().unwrap()); + } + fn is_ge( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_ge.is_some() { + return Ok(self.is_ge.as_ref().unwrap()); + } + self.is_ge = Some(self.two >= self.ack2(_io, _root, _parent)? as bool); + return Ok(self.is_ge.as_ref().unwrap()); + } + fn hi_val( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.hi_val.is_some() { + return Ok(self.hi_val.as_ref().unwrap()); + } + self.hi_val = Some(&[0x90, 0x43] as Vec); + return Ok(self.hi_val.as_ref().unwrap()); + } + fn is_ne( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_ne.is_some() { + return Ok(self.is_ne.as_ref().unwrap()); + } + self.is_ne = Some(self.two != self.ack(_io, _root, _parent)? as bool); + return Ok(self.is_ne.as_ref().unwrap()); + } + fn is_lt( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_lt.is_some() { + return Ok(self.is_lt.as_ref().unwrap()); + } + self.is_lt = Some(self.two < self.ack2(_io, _root, _parent)? as bool); + return Ok(self.is_lt.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_bytes_non_literal.rs b/spec/rust/formats/expr_bytes_non_literal.rs new file mode 100644 index 000000000..55d1a1c27 --- /dev/null +++ b/spec/rust/formats/expr_bytes_non_literal.rs @@ -0,0 +1,56 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprBytesNonLiteral { + pub one: u8, + pub two: u8, + pub calc_bytes: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprBytesNonLiteral { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + self.two = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprBytesNonLiteral { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprBytesNonLiteral::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn calc_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.calc_bytes.is_some() { + return Ok(self.calc_bytes.as_ref().unwrap()); + } + self.calc_bytes = Some(pack('C*', self.one, self.two) as Vec); + return Ok(self.calc_bytes.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_bytes_ops.rs b/spec/rust/formats/expr_bytes_ops.rs new file mode 100644 index 000000000..2c9097a81 --- /dev/null +++ b/spec/rust/formats/expr_bytes_ops.rs @@ -0,0 +1,210 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprBytesOps { + pub one: Vec, + pub two_last: Option, + pub two_max: Option, + pub one_min: Option, + pub one_first: Option, + pub one_mid: Option, + pub two: Option>, + pub two_min: Option, + pub two_mid: Option, + pub one_size: Option, + pub one_last: Option, + pub two_size: Option, + pub one_max: Option, + pub two_first: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprBytesOps { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_bytes(3 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ExprBytesOps { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprBytesOps::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn two_last( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.two_last.is_some() { + return Ok(self.two_last.as_ref().unwrap()); + } + self.two_last = Some(self.two(_io, _root, _parent)?.last() as u8); + return Ok(self.two_last.as_ref().unwrap()); + } + fn two_max( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.two_max.is_some() { + return Ok(self.two_max.as_ref().unwrap()); + } + self.two_max = Some(self.two(_io, _root, _parent)?.iter().max() as u8); + return Ok(self.two_max.as_ref().unwrap()); + } + fn one_min( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.one_min.is_some() { + return Ok(self.one_min.as_ref().unwrap()); + } + self.one_min = Some(self.one.iter().min() as u8); + return Ok(self.one_min.as_ref().unwrap()); + } + fn one_first( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.one_first.is_some() { + return Ok(self.one_first.as_ref().unwrap()); + } + self.one_first = Some(self.one.first() as u8); + return Ok(self.one_first.as_ref().unwrap()); + } + fn one_mid( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.one_mid.is_some() { + return Ok(self.one_mid.as_ref().unwrap()); + } + self.one_mid = Some(self.one[1 as usize] as u8); + return Ok(self.one_mid.as_ref().unwrap()); + } + fn two( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.two.is_some() { + return Ok(self.two.as_ref().unwrap()); + } + self.two = Some(&[0x41, 0xff, 0x4b] as Vec); + return Ok(self.two.as_ref().unwrap()); + } + fn two_min( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.two_min.is_some() { + return Ok(self.two_min.as_ref().unwrap()); + } + self.two_min = Some(self.two(_io, _root, _parent)?.iter().min() as u8); + return Ok(self.two_min.as_ref().unwrap()); + } + fn two_mid( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.two_mid.is_some() { + return Ok(self.two_mid.as_ref().unwrap()); + } + self.two_mid = Some(self.two(_io, _root, _parent)?[1 as usize] as u8); + return Ok(self.two_mid.as_ref().unwrap()); + } + fn one_size( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.one_size.is_some() { + return Ok(self.one_size.as_ref().unwrap()); + } + self.one_size = Some(self.one.len() as i32); + return Ok(self.one_size.as_ref().unwrap()); + } + fn one_last( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.one_last.is_some() { + return Ok(self.one_last.as_ref().unwrap()); + } + self.one_last = Some(self.one.last() as u8); + return Ok(self.one_last.as_ref().unwrap()); + } + fn two_size( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.two_size.is_some() { + return Ok(self.two_size.as_ref().unwrap()); + } + self.two_size = Some(self.two(_io, _root, _parent)?.len() as i32); + return Ok(self.two_size.as_ref().unwrap()); + } + fn one_max( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.one_max.is_some() { + return Ok(self.one_max.as_ref().unwrap()); + } + self.one_max = Some(self.one.iter().max() as u8); + return Ok(self.one_max.as_ref().unwrap()); + } + fn two_first( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.two_first.is_some() { + return Ok(self.two_first.as_ref().unwrap()); + } + self.two_first = Some(self.two(_io, _root, _parent)?.first() as u8); + return Ok(self.two_first.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_enum.rs b/spec/rust/formats/expr_enum.rs new file mode 100644 index 000000000..af01c066b --- /dev/null +++ b/spec/rust/formats/expr_enum.rs @@ -0,0 +1,100 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprEnum { + pub one: u8, + pub const_dog: Option, + pub derived_boom: Option, + pub derived_dog: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprEnum { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprEnum { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprEnum::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn const_dog( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&ExprEnum_Animal> { + if self.const_dog.is_some() { + return Ok(self.const_dog.as_ref().unwrap()); + } + self.const_dog = Some(4 as i32); + return Ok(self.const_dog.as_ref().unwrap()); + } + fn derived_boom( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&ExprEnum_Animal> { + if self.derived_boom.is_some() { + return Ok(self.derived_boom.as_ref().unwrap()); + } + self.derived_boom = Some(self.one as i32); + return Ok(self.derived_boom.as_ref().unwrap()); + } + fn derived_dog( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&ExprEnum_Animal> { + if self.derived_dog.is_some() { + return Ok(self.derived_dog.as_ref().unwrap()); + } + self.derived_dog = Some((self.one - 98) as i32); + return Ok(self.derived_dog.as_ref().unwrap()); + } +} +#[derive(Debug, PartialEq)] +pub enum ExprEnum_Animal { + Dog, + Cat, + Chicken, + Boom, +} +impl TryFrom for ExprEnum_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(ExprEnum_Animal::Dog), + 7 => Ok(ExprEnum_Animal::Cat), + 12 => Ok(ExprEnum_Animal::Chicken), + 102 => Ok(ExprEnum_Animal::Boom), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/expr_if_int_ops.rs b/spec/rust/formats/expr_if_int_ops.rs new file mode 100644 index 000000000..5ba1dbb37 --- /dev/null +++ b/spec/rust/formats/expr_if_int_ops.rs @@ -0,0 +1,77 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprIfIntOps { + pub skip: Vec, + pub it: i16, + pub boxed: i16, + pub is_eq_prim: Option, + pub is_eq_boxed: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprIfIntOps { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.skip = _io.read_bytes(2 as usize)?.to_vec(); + { + // condIfHeader(Bool(true)) + self.it = _io.read_s2le()?; + } + { + // condIfHeader(Bool(true)) + self.boxed = _io.read_s2le()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> ExprIfIntOps { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprIfIntOps::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn is_eq_prim( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_eq_prim.is_some() { + return Ok(self.is_eq_prim.as_ref().unwrap()); + } + self.is_eq_prim = Some(self.it == 16705 as bool); + return Ok(self.is_eq_prim.as_ref().unwrap()); + } + fn is_eq_boxed( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_eq_boxed.is_some() { + return Ok(self.is_eq_boxed.as_ref().unwrap()); + } + self.is_eq_boxed = Some(self.it == self.boxed as bool); + return Ok(self.is_eq_boxed.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_int_div.rs b/spec/rust/formats/expr_int_div.rs new file mode 100644 index 000000000..d9b02226d --- /dev/null +++ b/spec/rust/formats/expr_int_div.rs @@ -0,0 +1,95 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprIntDiv { + pub int_u: u32, + pub int_s: i32, + pub div_pos_const: Option, + pub div_neg_const: Option, + pub div_pos_seq: Option, + pub div_neg_seq: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprIntDiv { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.int_u = _io.read_u4le()?; + self.int_s = _io.read_s4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprIntDiv { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprIntDiv::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn div_pos_const( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.div_pos_const.is_some() { + return Ok(self.div_pos_const.as_ref().unwrap()); + } + self.div_pos_const = Some(9837 / 13 as i32); + return Ok(self.div_pos_const.as_ref().unwrap()); + } + fn div_neg_const( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.div_neg_const.is_some() { + return Ok(self.div_neg_const.as_ref().unwrap()); + } + self.div_neg_const = Some(-9837 / 13 as i32); + return Ok(self.div_neg_const.as_ref().unwrap()); + } + fn div_pos_seq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.div_pos_seq.is_some() { + return Ok(self.div_pos_seq.as_ref().unwrap()); + } + self.div_pos_seq = Some(self.int_u / 13 as i32); + return Ok(self.div_pos_seq.as_ref().unwrap()); + } + fn div_neg_seq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.div_neg_seq.is_some() { + return Ok(self.div_neg_seq.as_ref().unwrap()); + } + self.div_neg_seq = Some(self.int_s / 13 as i32); + return Ok(self.div_neg_seq.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_io_eof.rs b/spec/rust/formats/expr_io_eof.rs new file mode 100644 index 000000000..53d6865b5 --- /dev/null +++ b/spec/rust/formats/expr_io_eof.rs @@ -0,0 +1,98 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(substream1)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(substream2)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ExprIoEof { + pub substream1: Option, + pub substream2: Option, + pub raw_substream1: Vec, + pub raw_substream2: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoEof { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.substream1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + self.substream2 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(8 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ExprIoEof { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprIoEof::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ExprIoEof_OneOrTwo { + pub one: u32, + pub two: u32, + pub reflect_eof: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoEof_OneOrTwo { + type Root = ExprIoEof; + type ParentStack = (&'r ExprIoEof, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u4le()?; + { + // condIfHeader(UnaryOp(Not,Attribute(Name(identifier(_io)),identifier(eof)))) + self.two = _io.read_u4le()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> ExprIoEof_OneOrTwo { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprIoEof_OneOrTwo::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn reflect_eof( + &mut self, + _io: &'s S, + _root: Option<&'r ExprIoEof>, + _parent: Option>::ParentStack)>> + ) -> KResult<&bool> { + if self.reflect_eof.is_some() { + return Ok(self.reflect_eof.as_ref().unwrap()); + } + self.reflect_eof = Some(_io.is_eof as bool); + return Ok(self.reflect_eof.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_io_pos.rs b/spec/rust/formats/expr_io_pos.rs new file mode 100644 index 000000000..a84957b58 --- /dev/null +++ b/spec/rust/formats/expr_io_pos.rs @@ -0,0 +1,84 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(substream1)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(substream2)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ExprIoPos { + pub substream1: Option, + pub substream2: Option, + pub raw_substream1: Vec, + pub raw_substream2: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoPos { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.substream1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(16 as usize)?), Some(self), _parent.push(self))?); + self.substream2 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(14 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ExprIoPos { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprIoPos::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ExprIoPos_AllPlusNumber { + pub my_str: String, + pub body: Vec, + pub number: u16, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoPos_AllPlusNumber { + type Root = ExprIoPos; + type ParentStack = (&'r ExprIoPos, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.my_str = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; + self.body = _io.read_bytes(((_io.size - _io.pos) - 2) as usize)?.to_vec(); + self.number = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprIoPos_AllPlusNumber { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprIoPos_AllPlusNumber::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/expr_mod.rs b/spec/rust/formats/expr_mod.rs new file mode 100644 index 000000000..74139b6c5 --- /dev/null +++ b/spec/rust/formats/expr_mod.rs @@ -0,0 +1,95 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprMod { + pub int_u: u32, + pub int_s: i32, + pub mod_pos_const: Option, + pub mod_neg_const: Option, + pub mod_pos_seq: Option, + pub mod_neg_seq: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprMod { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.int_u = _io.read_u4le()?; + self.int_s = _io.read_s4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprMod { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprMod::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn mod_pos_const( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.mod_pos_const.is_some() { + return Ok(self.mod_pos_const.as_ref().unwrap()); + } + self.mod_pos_const = Some(9837 % 13 as i32); + return Ok(self.mod_pos_const.as_ref().unwrap()); + } + fn mod_neg_const( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.mod_neg_const.is_some() { + return Ok(self.mod_neg_const.as_ref().unwrap()); + } + self.mod_neg_const = Some(-9837 % 13 as i32); + return Ok(self.mod_neg_const.as_ref().unwrap()); + } + fn mod_pos_seq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.mod_pos_seq.is_some() { + return Ok(self.mod_pos_seq.as_ref().unwrap()); + } + self.mod_pos_seq = Some(self.int_u % 13 as i32); + return Ok(self.mod_pos_seq.as_ref().unwrap()); + } + fn mod_neg_seq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.mod_neg_seq.is_some() { + return Ok(self.mod_neg_seq.as_ref().unwrap()); + } + self.mod_neg_seq = Some(self.int_s % 13 as i32); + return Ok(self.mod_neg_seq.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_ops_parens.rs b/spec/rust/formats/expr_ops_parens.rs new file mode 100644 index 000000000..51b0af591 --- /dev/null +++ b/spec/rust/formats/expr_ops_parens.rs @@ -0,0 +1,234 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprOpsParens { + pub bool_and: Option, + pub str_0_to_4: Option, + pub bool_or: Option, + pub f_e: Option, + pub f_sum_to_int: Option, + pub f_2pi: Option, + pub str_concat_rev: Option, + pub i_m13: Option, + pub str_concat_len: Option, + pub str_concat_to_i: Option, + pub i_42: Option, + pub i_sum_to_str: Option, + pub bool_eq: Option, + pub str_5_to_9: Option, + pub str_concat_substr_2_to_7: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprOpsParens { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> ExprOpsParens { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprOpsParens::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn bool_and( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.bool_and.is_some() { + return Ok(self.bool_and.as_ref().unwrap()); + } + self.bool_and = Some( ((false) && (true)) as i32 as i32); + return Ok(self.bool_and.as_ref().unwrap()); + } + fn str_0_to_4( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.str_0_to_4.is_some() { + return Ok(self.str_0_to_4.as_ref().unwrap()); + } + self.str_0_to_4 = Some("01234".to_string()); + return Ok(self.str_0_to_4.as_ref().unwrap()); + } + fn bool_or( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.bool_or.is_some() { + return Ok(self.bool_or.as_ref().unwrap()); + } + self.bool_or = Some( ((!(false)) || (false)) as i32 as i32); + return Ok(self.bool_or.as_ref().unwrap()); + } + fn f_e( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.f_e.is_some() { + return Ok(self.f_e.as_ref().unwrap()); + } + self.f_e = Some(2.72 as f64); + return Ok(self.f_e.as_ref().unwrap()); + } + fn f_sum_to_int( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.f_sum_to_int.is_some() { + return Ok(self.f_sum_to_int.as_ref().unwrap()); + } + self.f_sum_to_int = Some((self.f_2pi(_io, _root, _parent)? + self.f_e(_io, _root, _parent)?) as i32 as i32); + return Ok(self.f_sum_to_int.as_ref().unwrap()); + } + fn f_2pi( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.f_2pi.is_some() { + return Ok(self.f_2pi.as_ref().unwrap()); + } + self.f_2pi = Some(6.28 as f64); + return Ok(self.f_2pi.as_ref().unwrap()); + } + fn str_concat_rev( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.str_concat_rev.is_some() { + return Ok(self.str_concat_rev.as_ref().unwrap()); + } + self.str_concat_rev = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).graphemes(true).rev().flat_map(|g| g.chars()).collect().to_string()); + return Ok(self.str_concat_rev.as_ref().unwrap()); + } + fn i_m13( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.i_m13.is_some() { + return Ok(self.i_m13.as_ref().unwrap()); + } + self.i_m13 = Some(-13 as i32); + return Ok(self.i_m13.as_ref().unwrap()); + } + fn str_concat_len( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.str_concat_len.is_some() { + return Ok(self.str_concat_len.as_ref().unwrap()); + } + self.str_concat_len = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).len() as i32); + return Ok(self.str_concat_len.as_ref().unwrap()); + } + fn str_concat_to_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.str_concat_to_i.is_some() { + return Ok(self.str_concat_to_i.as_ref().unwrap()); + } + self.str_concat_to_i = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).parse().unwrap() as i32); + return Ok(self.str_concat_to_i.as_ref().unwrap()); + } + fn i_42( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i8> { + if self.i_42.is_some() { + return Ok(self.i_42.as_ref().unwrap()); + } + self.i_42 = Some(42 as i8); + return Ok(self.i_42.as_ref().unwrap()); + } + fn i_sum_to_str( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.i_sum_to_str.is_some() { + return Ok(self.i_sum_to_str.as_ref().unwrap()); + } + self.i_sum_to_str = Some((self.i_42(_io, _root, _parent)? + self.i_m13(_io, _root, _parent)?).to_string().to_string()); + return Ok(self.i_sum_to_str.as_ref().unwrap()); + } + fn bool_eq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.bool_eq.is_some() { + return Ok(self.bool_eq.as_ref().unwrap()); + } + self.bool_eq = Some(false == true as i32 as i32); + return Ok(self.bool_eq.as_ref().unwrap()); + } + fn str_5_to_9( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.str_5_to_9.is_some() { + return Ok(self.str_5_to_9.as_ref().unwrap()); + } + self.str_5_to_9 = Some("56789".to_string()); + return Ok(self.str_5_to_9.as_ref().unwrap()); + } + fn str_concat_substr_2_to_7( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.str_concat_substr_2_to_7.is_some() { + return Ok(self.str_concat_substr_2_to_7.as_ref().unwrap()); + } + self.str_concat_substr_2_to_7 = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).substring(2, 7).to_string()); + return Ok(self.str_concat_substr_2_to_7.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_sizeof_type_0.rs b/spec/rust/formats/expr_sizeof_type_0.rs new file mode 100644 index 000000000..d1ca3785c --- /dev/null +++ b/spec/rust/formats/expr_sizeof_type_0.rs @@ -0,0 +1,89 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofType0 { + pub sizeof_block: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType0 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofType0 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofType0::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn sizeof_block( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block.is_some() { + return Ok(self.sizeof_block.as_ref().unwrap()); + } + self.sizeof_block = Some(7 as i32); + return Ok(self.sizeof_block.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofType0_Block { + pub a: u8, + pub b: u32, + pub c: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType0_Block { + type Root = ExprSizeofType0; + type ParentStack = (&'r ExprSizeofType0, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_u1()?; + self.b = _io.read_u4le()?; + self.c = _io.read_bytes(2 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofType0_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofType0_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/expr_sizeof_type_1.rs b/spec/rust/formats/expr_sizeof_type_1.rs new file mode 100644 index 000000000..27c60cd66 --- /dev/null +++ b/spec/rust/formats/expr_sizeof_type_1.rs @@ -0,0 +1,137 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofType1 { + pub sizeof_block: Option, + pub sizeof_subblock: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType1 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofType1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofType1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn sizeof_block( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block.is_some() { + return Ok(self.sizeof_block.as_ref().unwrap()); + } + self.sizeof_block = Some(11 as i32); + return Ok(self.sizeof_block.as_ref().unwrap()); + } + fn sizeof_subblock( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_subblock.is_some() { + return Ok(self.sizeof_subblock.as_ref().unwrap()); + } + self.sizeof_subblock = Some(4 as i32); + return Ok(self.sizeof_subblock.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofType1_Block { + pub a: u8, + pub b: u32, + pub c: Vec, + pub d: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType1_Block { + type Root = ExprSizeofType1; + type ParentStack = (&'r ExprSizeofType1, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_u1()?; + self.b = _io.read_u4le()?; + self.c = _io.read_bytes(2 as usize)?.to_vec(); + self.d = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofType1_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofType1_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofType1_Block_Subblock { + pub a: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType1_Block_Subblock { + type Root = ExprSizeofType1; + type ParentStack = (&'r ExprSizeofType1_Block, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_bytes(4 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofType1_Block_Subblock { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofType1_Block_Subblock::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/expr_sizeof_value_0.rs b/spec/rust/formats/expr_sizeof_value_0.rs new file mode 100644 index 000000000..72b743a8e --- /dev/null +++ b/spec/rust/formats/expr_sizeof_value_0.rs @@ -0,0 +1,145 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofValue0 { + pub block1: Option, + pub more: u16, + pub self_sizeof: Option, + pub sizeof_block: Option, + pub sizeof_block_b: Option, + pub sizeof_block_a: Option, + pub sizeof_block_c: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValue0 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.block1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.more = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofValue0 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofValue0::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn self_sizeof( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.self_sizeof.is_some() { + return Ok(self.self_sizeof.as_ref().unwrap()); + } + self.self_sizeof = Some(9 as i32); + return Ok(self.self_sizeof.as_ref().unwrap()); + } + fn sizeof_block( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block.is_some() { + return Ok(self.sizeof_block.as_ref().unwrap()); + } + self.sizeof_block = Some(7 as i32); + return Ok(self.sizeof_block.as_ref().unwrap()); + } + fn sizeof_block_b( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block_b.is_some() { + return Ok(self.sizeof_block_b.as_ref().unwrap()); + } + self.sizeof_block_b = Some(4 as i32); + return Ok(self.sizeof_block_b.as_ref().unwrap()); + } + fn sizeof_block_a( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block_a.is_some() { + return Ok(self.sizeof_block_a.as_ref().unwrap()); + } + self.sizeof_block_a = Some(1 as i32); + return Ok(self.sizeof_block_a.as_ref().unwrap()); + } + fn sizeof_block_c( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block_c.is_some() { + return Ok(self.sizeof_block_c.as_ref().unwrap()); + } + self.sizeof_block_c = Some(2 as i32); + return Ok(self.sizeof_block_c.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofValue0_Block { + pub a: u8, + pub b: u32, + pub c: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValue0_Block { + type Root = ExprSizeofValue0; + type ParentStack = (&'r ExprSizeofValue0, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_u1()?; + self.b = _io.read_u4le()?; + self.c = _io.read_bytes(2 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofValue0_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofValue0_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/expr_sizeof_value_sized.rs b/spec/rust/formats/expr_sizeof_value_sized.rs new file mode 100644 index 000000000..a837264eb --- /dev/null +++ b/spec/rust/formats/expr_sizeof_value_sized.rs @@ -0,0 +1,147 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(block1)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofValueSized { + pub block1: Option, + pub more: u16, + pub raw_block1: Vec, + pub self_sizeof: Option, + pub sizeof_block: Option, + pub sizeof_block_b: Option, + pub sizeof_block_a: Option, + pub sizeof_block_c: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValueSized { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.block1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); + self.more = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofValueSized { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofValueSized::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn self_sizeof( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.self_sizeof.is_some() { + return Ok(self.self_sizeof.as_ref().unwrap()); + } + self.self_sizeof = Some(14 as i32); + return Ok(self.self_sizeof.as_ref().unwrap()); + } + fn sizeof_block( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block.is_some() { + return Ok(self.sizeof_block.as_ref().unwrap()); + } + self.sizeof_block = Some(12 as i32); + return Ok(self.sizeof_block.as_ref().unwrap()); + } + fn sizeof_block_b( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block_b.is_some() { + return Ok(self.sizeof_block_b.as_ref().unwrap()); + } + self.sizeof_block_b = Some(4 as i32); + return Ok(self.sizeof_block_b.as_ref().unwrap()); + } + fn sizeof_block_a( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block_a.is_some() { + return Ok(self.sizeof_block_a.as_ref().unwrap()); + } + self.sizeof_block_a = Some(1 as i32); + return Ok(self.sizeof_block_a.as_ref().unwrap()); + } + fn sizeof_block_c( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.sizeof_block_c.is_some() { + return Ok(self.sizeof_block_c.as_ref().unwrap()); + } + self.sizeof_block_c = Some(2 as i32); + return Ok(self.sizeof_block_c.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct ExprSizeofValueSized_Block { + pub a: u8, + pub b: u32, + pub c: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValueSized_Block { + type Root = ExprSizeofValueSized; + type ParentStack = (&'r ExprSizeofValueSized, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_u1()?; + self.b = _io.read_u4le()?; + self.c = _io.read_bytes(2 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ExprSizeofValueSized_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprSizeofValueSized_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/expr_str_encodings.rs b/spec/rust/formats/expr_str_encodings.rs new file mode 100644 index 000000000..92bd46c84 --- /dev/null +++ b/spec/rust/formats/expr_str_encodings.rs @@ -0,0 +1,146 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprStrEncodings { + pub len_of_1: u16, + pub str1: String, + pub len_of_2: u16, + pub str2: String, + pub len_of_3: u16, + pub str3: String, + pub len_of_4: u16, + pub str4: String, + pub str4_gt_str_from_bytes: Option, + pub str1_eq: Option, + pub str4_eq: Option, + pub str3_eq_str2: Option, + pub str4_gt_str_calc: Option, + pub str2_eq: Option, + pub str3_eq: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprStrEncodings { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_of_1 = _io.read_u2le()?; + self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "ASCII")?; + self.len_of_2 = _io.read_u2le()?; + self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; + self.len_of_3 = _io.read_u2le()?; + self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; + self.len_of_4 = _io.read_u2le()?; + self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprStrEncodings { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprStrEncodings::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn str4_gt_str_from_bytes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.str4_gt_str_from_bytes.is_some() { + return Ok(self.str4_gt_str_from_bytes.as_ref().unwrap()); + } + self.str4_gt_str_from_bytes = Some(self.str4 > decode_string(&[0xb4], "CP437")? as bool); + return Ok(self.str4_gt_str_from_bytes.as_ref().unwrap()); + } + fn str1_eq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.str1_eq.is_some() { + return Ok(self.str1_eq.as_ref().unwrap()); + } + self.str1_eq = Some(self.str1 == "Some ASCII" as bool); + return Ok(self.str1_eq.as_ref().unwrap()); + } + fn str4_eq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.str4_eq.is_some() { + return Ok(self.str4_eq.as_ref().unwrap()); + } + self.str4_eq = Some(self.str4 == "\u{2591}\u{2592}\u{2593}" as bool); + return Ok(self.str4_eq.as_ref().unwrap()); + } + fn str3_eq_str2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.str3_eq_str2.is_some() { + return Ok(self.str3_eq_str2.as_ref().unwrap()); + } + self.str3_eq_str2 = Some(self.str3 == self.str2 as bool); + return Ok(self.str3_eq_str2.as_ref().unwrap()); + } + fn str4_gt_str_calc( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.str4_gt_str_calc.is_some() { + return Ok(self.str4_gt_str_calc.as_ref().unwrap()); + } + self.str4_gt_str_calc = Some(self.str4 > "\u{2524}" as bool); + return Ok(self.str4_gt_str_calc.as_ref().unwrap()); + } + fn str2_eq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.str2_eq.is_some() { + return Ok(self.str2_eq.as_ref().unwrap()); + } + self.str2_eq = Some(self.str2 == "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}" as bool); + return Ok(self.str2_eq.as_ref().unwrap()); + } + fn str3_eq( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.str3_eq.is_some() { + return Ok(self.str3_eq.as_ref().unwrap()); + } + self.str3_eq = Some(self.str3 == "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}" as bool); + return Ok(self.str3_eq.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/expr_str_ops.rs b/spec/rust/formats/expr_str_ops.rs new file mode 100644 index 000000000..f79f6bfe4 --- /dev/null +++ b/spec/rust/formats/expr_str_ops.rs @@ -0,0 +1,249 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ExprStrOps { + pub one: String, + pub one_substr_3_to_3: Option, + pub to_i_r8: Option, + pub to_i_r16: Option, + pub two_substr_0_to_10: Option, + pub one_len: Option, + pub two_len: Option, + pub one_substr_2_to_5: Option, + pub to_i_r2: Option, + pub two_rev: Option, + pub two: Option, + pub two_substr_4_to_10: Option, + pub to_i_r10: Option, + pub two_substr_0_to_7: Option, + pub to_i_attr: Option, + pub one_substr_0_to_3: Option, + pub one_rev: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ExprStrOps { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = decode_string(_io.read_bytes(5 as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> ExprStrOps { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ExprStrOps::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn one_substr_3_to_3( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.one_substr_3_to_3.is_some() { + return Ok(self.one_substr_3_to_3.as_ref().unwrap()); + } + self.one_substr_3_to_3 = Some(self.one.substring(3, 3).to_string()); + return Ok(self.one_substr_3_to_3.as_ref().unwrap()); + } + fn to_i_r8( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.to_i_r8.is_some() { + return Ok(self.to_i_r8.as_ref().unwrap()); + } + self.to_i_r8 = Some(panic!("Converting from string to int in base {} is unimplemented"8) as i32); + return Ok(self.to_i_r8.as_ref().unwrap()); + } + fn to_i_r16( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.to_i_r16.is_some() { + return Ok(self.to_i_r16.as_ref().unwrap()); + } + self.to_i_r16 = Some(panic!("Converting from string to int in base {} is unimplemented"16) as i32); + return Ok(self.to_i_r16.as_ref().unwrap()); + } + fn two_substr_0_to_10( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.two_substr_0_to_10.is_some() { + return Ok(self.two_substr_0_to_10.as_ref().unwrap()); + } + self.two_substr_0_to_10 = Some(self.two(_io, _root, _parent)?.substring(0, 10).to_string()); + return Ok(self.two_substr_0_to_10.as_ref().unwrap()); + } + fn one_len( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.one_len.is_some() { + return Ok(self.one_len.as_ref().unwrap()); + } + self.one_len = Some(self.one.len() as i32); + return Ok(self.one_len.as_ref().unwrap()); + } + fn two_len( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.two_len.is_some() { + return Ok(self.two_len.as_ref().unwrap()); + } + self.two_len = Some(self.two(_io, _root, _parent)?.len() as i32); + return Ok(self.two_len.as_ref().unwrap()); + } + fn one_substr_2_to_5( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.one_substr_2_to_5.is_some() { + return Ok(self.one_substr_2_to_5.as_ref().unwrap()); + } + self.one_substr_2_to_5 = Some(self.one.substring(2, 5).to_string()); + return Ok(self.one_substr_2_to_5.as_ref().unwrap()); + } + fn to_i_r2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.to_i_r2.is_some() { + return Ok(self.to_i_r2.as_ref().unwrap()); + } + self.to_i_r2 = Some(panic!("Converting from string to int in base {} is unimplemented"2) as i32); + return Ok(self.to_i_r2.as_ref().unwrap()); + } + fn two_rev( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.two_rev.is_some() { + return Ok(self.two_rev.as_ref().unwrap()); + } + self.two_rev = Some(self.two(_io, _root, _parent)?.graphemes(true).rev().flat_map(|g| g.chars()).collect().to_string()); + return Ok(self.two_rev.as_ref().unwrap()); + } + fn two( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.two.is_some() { + return Ok(self.two.as_ref().unwrap()); + } + self.two = Some("0123456789".to_string()); + return Ok(self.two.as_ref().unwrap()); + } + fn two_substr_4_to_10( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.two_substr_4_to_10.is_some() { + return Ok(self.two_substr_4_to_10.as_ref().unwrap()); + } + self.two_substr_4_to_10 = Some(self.two(_io, _root, _parent)?.substring(4, 10).to_string()); + return Ok(self.two_substr_4_to_10.as_ref().unwrap()); + } + fn to_i_r10( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.to_i_r10.is_some() { + return Ok(self.to_i_r10.as_ref().unwrap()); + } + self.to_i_r10 = Some("-072".parse().unwrap() as i32); + return Ok(self.to_i_r10.as_ref().unwrap()); + } + fn two_substr_0_to_7( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.two_substr_0_to_7.is_some() { + return Ok(self.two_substr_0_to_7.as_ref().unwrap()); + } + self.two_substr_0_to_7 = Some(self.two(_io, _root, _parent)?.substring(0, 7).to_string()); + return Ok(self.two_substr_0_to_7.as_ref().unwrap()); + } + fn to_i_attr( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.to_i_attr.is_some() { + return Ok(self.to_i_attr.as_ref().unwrap()); + } + self.to_i_attr = Some("9173".parse().unwrap() as i32); + return Ok(self.to_i_attr.as_ref().unwrap()); + } + fn one_substr_0_to_3( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.one_substr_0_to_3.is_some() { + return Ok(self.one_substr_0_to_3.as_ref().unwrap()); + } + self.one_substr_0_to_3 = Some(self.one.substring(0, 3).to_string()); + return Ok(self.one_substr_0_to_3.as_ref().unwrap()); + } + fn one_rev( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.one_rev.is_some() { + return Ok(self.one_rev.as_ref().unwrap()); + } + self.one_rev = Some(self.one.graphemes(true).rev().flat_map(|g| g.chars()).collect().to_string()); + return Ok(self.one_rev.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/fixed_contents.rs b/spec/rust/formats/fixed_contents.rs new file mode 100644 index 000000000..5a427f7b3 --- /dev/null +++ b/spec/rust/formats/fixed_contents.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct FixedContents { + pub normal: Vec, + pub high_bit_8: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for FixedContents { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.normal = _io.read_bytes(6 as usize)?.to_vec(); + self.high_bit_8 = _io.read_bytes(2 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> FixedContents { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = FixedContents::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/fixed_struct.rs b/spec/rust/formats/fixed_struct.rs new file mode 100644 index 000000000..4c6a5068a --- /dev/null +++ b/spec/rust/formats/fixed_struct.rs @@ -0,0 +1,139 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct FixedStruct { + pub hdr: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for FixedStruct { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> FixedStruct { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = FixedStruct::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn hdr( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&FixedStruct_Header> { + if self.hdr.is_some() { + return Ok(self.hdr.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(0)) + // popPos(_io) + return Ok(self.hdr.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct FixedStruct_Header { + pub magic1: Vec, + pub uint8: u8, + pub sint8: i8, + pub magic_uint: Vec, + pub uint16: u16, + pub uint32: u32, + pub uint64: u64, + pub magic_sint: Vec, + pub sint16: i16, + pub sint32: i32, + pub sint64: i64, + pub magic_uint_le: Vec, + pub uint16le: u16, + pub uint32le: u32, + pub uint64le: u64, + pub magic_sint_le: Vec, + pub sint16le: i16, + pub sint32le: i32, + pub sint64le: i64, + pub magic_uint_be: Vec, + pub uint16be: u16, + pub uint32be: u32, + pub uint64be: u64, + pub magic_sint_be: Vec, + pub sint16be: i16, + pub sint32be: i32, + pub sint64be: i64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for FixedStruct_Header { + type Root = FixedStruct; + type ParentStack = (&'r FixedStruct, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); + self.uint8 = _io.read_u1()?; + self.sint8 = _io.read_s1()?; + self.magic_uint = _io.read_bytes(10 as usize)?.to_vec(); + self.uint16 = _io.read_u2le()?; + self.uint32 = _io.read_u4le()?; + self.uint64 = _io.read_u8le()?; + self.magic_sint = _io.read_bytes(10 as usize)?.to_vec(); + self.sint16 = _io.read_s2le()?; + self.sint32 = _io.read_s4le()?; + self.sint64 = _io.read_s8le()?; + self.magic_uint_le = _io.read_bytes(9 as usize)?.to_vec(); + self.uint16le = _io.read_u2le()?; + self.uint32le = _io.read_u4le()?; + self.uint64le = _io.read_u8le()?; + self.magic_sint_le = _io.read_bytes(9 as usize)?.to_vec(); + self.sint16le = _io.read_s2le()?; + self.sint32le = _io.read_s4le()?; + self.sint64le = _io.read_s8le()?; + self.magic_uint_be = _io.read_bytes(9 as usize)?.to_vec(); + self.uint16be = _io.read_u2be()?; + self.uint32be = _io.read_u4be()?; + self.uint64be = _io.read_u8be()?; + self.magic_sint_be = _io.read_bytes(9 as usize)?.to_vec(); + self.sint16be = _io.read_s2be()?; + self.sint32be = _io.read_s4be()?; + self.sint64be = _io.read_s8be()?; + Ok(()) + } +} +impl<'r, 's: 'r> FixedStruct_Header { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = FixedStruct_Header::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/float_to_i.rs b/spec/rust/formats/float_to_i.rs new file mode 100644 index 000000000..d1764bab6 --- /dev/null +++ b/spec/rust/formats/float_to_i.rs @@ -0,0 +1,173 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct FloatToI { + pub single_value: f32, + pub double_value: f64, + pub float2_i: Option, + pub calc_float1: Option, + pub float4_i: Option, + pub calc_float3: Option, + pub calc_float2: Option, + pub float1_i: Option, + pub double_i: Option, + pub float3_i: Option, + pub single_i: Option, + pub calc_float4: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for FloatToI { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.single_value = _io.read_f4le()?; + self.double_value = _io.read_f8le()?; + Ok(()) + } +} +impl<'r, 's: 'r> FloatToI { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = FloatToI::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn float2_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.float2_i.is_some() { + return Ok(self.float2_i.as_ref().unwrap()); + } + self.float2_i = Some(self.calc_float2(_io, _root, _parent)? as i32 as i32); + return Ok(self.float2_i.as_ref().unwrap()); + } + fn calc_float1( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.calc_float1.is_some() { + return Ok(self.calc_float1.as_ref().unwrap()); + } + self.calc_float1 = Some(1.234 as f64); + return Ok(self.calc_float1.as_ref().unwrap()); + } + fn float4_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.float4_i.is_some() { + return Ok(self.float4_i.as_ref().unwrap()); + } + self.float4_i = Some(self.calc_float4(_io, _root, _parent)? as i32 as i32); + return Ok(self.float4_i.as_ref().unwrap()); + } + fn calc_float3( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.calc_float3.is_some() { + return Ok(self.calc_float3.as_ref().unwrap()); + } + self.calc_float3 = Some(1.9 as f64); + return Ok(self.calc_float3.as_ref().unwrap()); + } + fn calc_float2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.calc_float2.is_some() { + return Ok(self.calc_float2.as_ref().unwrap()); + } + self.calc_float2 = Some(1.5 as f64); + return Ok(self.calc_float2.as_ref().unwrap()); + } + fn float1_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.float1_i.is_some() { + return Ok(self.float1_i.as_ref().unwrap()); + } + self.float1_i = Some(self.calc_float1(_io, _root, _parent)? as i32 as i32); + return Ok(self.float1_i.as_ref().unwrap()); + } + fn double_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.double_i.is_some() { + return Ok(self.double_i.as_ref().unwrap()); + } + self.double_i = Some(self.double_value as i32 as i32); + return Ok(self.double_i.as_ref().unwrap()); + } + fn float3_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.float3_i.is_some() { + return Ok(self.float3_i.as_ref().unwrap()); + } + self.float3_i = Some(self.calc_float3(_io, _root, _parent)? as i32 as i32); + return Ok(self.float3_i.as_ref().unwrap()); + } + fn single_i( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.single_i.is_some() { + return Ok(self.single_i.as_ref().unwrap()); + } + self.single_i = Some(self.single_value as i32 as i32); + return Ok(self.single_i.as_ref().unwrap()); + } + fn calc_float4( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.calc_float4.is_some() { + return Ok(self.calc_float4.as_ref().unwrap()); + } + self.calc_float4 = Some(-2.7 as f64); + return Ok(self.calc_float4.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/floating_points.rs b/spec/rust/formats/floating_points.rs new file mode 100644 index 000000000..7c41dbf26 --- /dev/null +++ b/spec/rust/formats/floating_points.rs @@ -0,0 +1,88 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct FloatingPoints { + pub single_value: f32, + pub double_value: f64, + pub single_value_be: f32, + pub double_value_be: f64, + pub approximate_value: f32, + pub single_value_plus_int: Option, + pub single_value_plus_float: Option, + pub double_value_plus_float: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for FloatingPoints { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.single_value = _io.read_f4le()?; + self.double_value = _io.read_f8le()?; + self.single_value_be = _io.read_f4be()?; + self.double_value_be = _io.read_f8be()?; + self.approximate_value = _io.read_f4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> FloatingPoints { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = FloatingPoints::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn single_value_plus_int( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.single_value_plus_int.is_some() { + return Ok(self.single_value_plus_int.as_ref().unwrap()); + } + self.single_value_plus_int = Some((self.single_value + 1) as f64); + return Ok(self.single_value_plus_int.as_ref().unwrap()); + } + fn single_value_plus_float( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.single_value_plus_float.is_some() { + return Ok(self.single_value_plus_float.as_ref().unwrap()); + } + self.single_value_plus_float = Some((self.single_value + 0.5) as f64); + return Ok(self.single_value_plus_float.as_ref().unwrap()); + } + fn double_value_plus_float( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&f64> { + if self.double_value_plus_float.is_some() { + return Ok(self.double_value_plus_float.as_ref().unwrap()); + } + self.double_value_plus_float = Some((self.double_value + 0.05) as f64); + return Ok(self.double_value_plus_float.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/hello_world.rs b/spec/rust/formats/hello_world.rs new file mode 100644 index 000000000..8377b0c8a --- /dev/null +++ b/spec/rust/formats/hello_world.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct HelloWorld { + pub one: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for HelloWorld { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> HelloWorld { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = HelloWorld::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/if_instances.rs b/spec/rust/formats/if_instances.rs new file mode 100644 index 000000000..fc569cd8b --- /dev/null +++ b/spec/rust/formats/if_instances.rs @@ -0,0 +1,57 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IfInstances { + pub never_happens: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IfInstances { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> IfInstances { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IfInstances::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn never_happens( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.never_happens.is_some() { + return Ok(self.never_happens.as_ref().unwrap()); + } + { + // condIfHeader(Bool(false)) + // pushPos(_io) + // seek(_io, IntNum(100500)) + // popPos(_io) + } + return Ok(self.never_happens.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/if_struct.rs b/spec/rust/formats/if_struct.rs new file mode 100644 index 000000000..11e861e33 --- /dev/null +++ b/spec/rust/formats/if_struct.rs @@ -0,0 +1,158 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IfStruct { + pub op1: Option, + pub op2: Option, + pub op3: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.op1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.op2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.op3 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> IfStruct { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IfStruct::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IfStruct_Operation { + pub opcode: u8, + pub arg_tuple: Option, + pub arg_str: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct_Operation { + type Root = IfStruct; + type ParentStack = (&'r IfStruct, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcode = _io.read_u1()?; + { + // condIfHeader(Compare(Name(identifier(opcode)),Eq,IntNum(84))) + self.arg_tuple = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + } + { + // condIfHeader(Compare(Name(identifier(opcode)),Eq,IntNum(83))) + self.arg_str = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + } + Ok(()) + } +} +impl<'r, 's: 'r> IfStruct_Operation { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IfStruct_Operation::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IfStruct_ArgTuple { + pub num1: u8, + pub num2: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct_ArgTuple { + type Root = IfStruct; + type ParentStack = (&'r IfStruct, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.num1 = _io.read_u1()?; + self.num2 = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> IfStruct_ArgTuple { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IfStruct_ArgTuple::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IfStruct_ArgStr { + pub len: u8, + pub str: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct_ArgStr { + type Root = IfStruct; + type ParentStack = (&'r IfStruct, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len = _io.read_u1()?; + self.str = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> IfStruct_ArgStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IfStruct_ArgStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/if_values.rs b/spec/rust/formats/if_values.rs new file mode 100644 index 000000000..23ea2e47e --- /dev/null +++ b/spec/rust/formats/if_values.rs @@ -0,0 +1,94 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IfValues { + pub codes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IfValues { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.codes = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(codes), _io, UserTypeInstream(List(code),None,List()), IntNum(3)) + // handleAssignmentRepeatExpr(NamedIdentifier(codes), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> IfValues { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IfValues::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IfValues_Code { + pub opcode: u8, + pub half_opcode: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IfValues_Code { + type Root = IfValues; + type ParentStack = (&'r IfValues, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcode = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> IfValues_Code { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IfValues_Code::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn half_opcode( + &mut self, + _io: &'s S, + _root: Option<&'r IfValues>, + _parent: Option>::ParentStack)>> + ) -> KResult<&i32> { + if self.half_opcode.is_some() { + return Ok(self.half_opcode.as_ref().unwrap()); + } + { + // condIfHeader(Compare(BinOp(Name(identifier(opcode)),Mod,IntNum(2)),Eq,IntNum(0))) + self.half_opcode = Some(self.opcode / 2 as i32); + } + return Ok(self.half_opcode.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/imported_1.rs b/spec/rust/formats/imported_1.rs new file mode 100644 index 000000000..d2e38ba2e --- /dev/null +++ b/spec/rust/formats/imported_1.rs @@ -0,0 +1,44 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::imported_2::Imported2; + +#[derive(Default, Debug, PartialEq)] +pub struct Imported1 { + pub one: u8, + pub two: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Imported1 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + self.two = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> Imported1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Imported1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/imported_2.rs b/spec/rust/formats/imported_2.rs new file mode 100644 index 000000000..4914e8e70 --- /dev/null +++ b/spec/rust/formats/imported_2.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Imported2 { + pub one: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Imported2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> Imported2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Imported2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/imports0.rs b/spec/rust/formats/imports0.rs new file mode 100644 index 000000000..13113f591 --- /dev/null +++ b/spec/rust/formats/imports0.rs @@ -0,0 +1,57 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::hello_world::HelloWorld; + +#[derive(Default, Debug, PartialEq)] +pub struct Imports0 { + pub two: u8, + pub hw: Option>, + pub hw_one: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Imports0 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.two = _io.read_u1()?; + self.hw = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> Imports0 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Imports0::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn hw_one( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.hw_one.is_some() { + return Ok(self.hw_one.as_ref().unwrap()); + } + self.hw_one = Some(self.hw.one as u8); + return Ok(self.hw_one.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/imports_circular_a.rs b/spec/rust/formats/imports_circular_a.rs new file mode 100644 index 000000000..e1b4bb44d --- /dev/null +++ b/spec/rust/formats/imports_circular_a.rs @@ -0,0 +1,44 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::imports_circular_b::ImportsCircularB; + +#[derive(Default, Debug, PartialEq)] +pub struct ImportsCircularA { + pub code: u8, + pub two: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ImportsCircularA { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + self.two = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ImportsCircularA { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ImportsCircularA::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/imports_circular_b.rs b/spec/rust/formats/imports_circular_b.rs new file mode 100644 index 000000000..13d8a0c42 --- /dev/null +++ b/spec/rust/formats/imports_circular_b.rs @@ -0,0 +1,47 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::imports_circular_a::ImportsCircularA; + +#[derive(Default, Debug, PartialEq)] +pub struct ImportsCircularB { + pub initial: u8, + pub back_ref: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ImportsCircularB { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.initial = _io.read_u1()?; + { + // condIfHeader(Compare(Name(identifier(initial)),Eq,IntNum(65))) + self.back_ref = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + } + Ok(()) + } +} +impl<'r, 's: 'r> ImportsCircularB { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ImportsCircularB::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/imports_rel_1.rs b/spec/rust/formats/imports_rel_1.rs new file mode 100644 index 000000000..dd01ba44d --- /dev/null +++ b/spec/rust/formats/imports_rel_1.rs @@ -0,0 +1,44 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::imported_1::Imported1; + +#[derive(Default, Debug, PartialEq)] +pub struct ImportsRel1 { + pub one: u8, + pub two: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ImportsRel1 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + self.two = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ImportsRel1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ImportsRel1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/index_sizes.rs b/spec/rust/formats/index_sizes.rs new file mode 100644 index 000000000..3677def6c --- /dev/null +++ b/spec/rust/formats/index_sizes.rs @@ -0,0 +1,53 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IndexSizes { + pub qty: u32, + pub sizes: Vec, + pub bufs: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IndexSizes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty = _io.read_u4le()?; + self.sizes = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) + } + self.bufs = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(bufs), _io, StrFromBytesType(BytesLimitType(Subscript(Name(identifier(sizes)),Name(identifier(_index))),None,false,None,None),ASCII), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(bufs), decode_string(_io.read_bytes(self.sizes[i as usize] as usize)?, "ASCII")?) + } + Ok(()) + } +} +impl<'r, 's: 'r> IndexSizes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IndexSizes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/index_to_param_eos.rs b/spec/rust/formats/index_to_param_eos.rs new file mode 100644 index 000000000..431fdb310 --- /dev/null +++ b/spec/rust/formats/index_to_param_eos.rs @@ -0,0 +1,89 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IndexToParamEos { + pub qty: u32, + pub sizes: Vec, + pub blocks: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamEos { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty = _io.read_u4le()?; + self.sizes = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) + } + self.blocks = Vec::new(); + { + type ArrayElement = IndexToParamEos_Block; + while !_io.is_eof() { + self.blocks.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> IndexToParamEos { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IndexToParamEos::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IndexToParamEos_Block { + pub idx: i32, + pub buf: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamEos_Block { + type Root = IndexToParamEos; + type ParentStack = (&'r IndexToParamEos, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.sizes[self.idx as usize] as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> IndexToParamEos_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IndexToParamEos_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/index_to_param_expr.rs b/spec/rust/formats/index_to_param_expr.rs new file mode 100644 index 000000000..2fe489870 --- /dev/null +++ b/spec/rust/formats/index_to_param_expr.rs @@ -0,0 +1,87 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IndexToParamExpr { + pub qty: u32, + pub sizes: Vec, + pub blocks: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamExpr { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty = _io.read_u4le()?; + self.sizes = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) + } + self.blocks = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,ArrayBuffer(Name(identifier(_index)))), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(blocks), Self::read_into::(i, _io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> IndexToParamExpr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IndexToParamExpr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IndexToParamExpr_Block { + pub idx: i32, + pub buf: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamExpr_Block { + type Root = IndexToParamExpr; + type ParentStack = (&'r IndexToParamExpr, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.sizes[self.idx as usize] as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> IndexToParamExpr_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IndexToParamExpr_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/index_to_param_until.rs b/spec/rust/formats/index_to_param_until.rs new file mode 100644 index 000000000..c056ccf57 --- /dev/null +++ b/spec/rust/formats/index_to_param_until.rs @@ -0,0 +1,88 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IndexToParamUntil { + pub qty: u32, + pub sizes: Vec, + pub blocks: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamUntil { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty = _io.read_u4le()?; + self.sizes = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) + } + self.blocks = Vec::new(); + { + // condRepeatUntilHeader(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,ArrayBuffer(Name(identifier(_index)))), Attribute(Name(identifier(_io)),identifier(eof))) + // handleAssignmentRepeatUntil(NamedIdentifier(blocks), Self::read_into::(i, _io, _root, _parent.push(self))?.into(), false) + // condRepeatUntilFooter(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,ArrayBuffer(Name(identifier(_index)))), Attribute(Name(identifier(_io)),identifier(eof))) + } {} + Ok(()) + } +} +impl<'r, 's: 'r> IndexToParamUntil { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IndexToParamUntil::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IndexToParamUntil_Block { + pub idx: i32, + pub buf: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamUntil_Block { + type Root = IndexToParamUntil; + type ParentStack = (&'r IndexToParamUntil, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.sizes[self.idx as usize] as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> IndexToParamUntil_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IndexToParamUntil_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/instance_std.rs b/spec/rust/formats/instance_std.rs new file mode 100644 index 000000000..de3ad728c --- /dev/null +++ b/spec/rust/formats/instance_std.rs @@ -0,0 +1,54 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct InstanceStd { + pub header: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for InstanceStd { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> InstanceStd { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = InstanceStd::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn header( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.header.is_some() { + return Ok(self.header.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(2)) + // popPos(_io) + return Ok(self.header.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/instance_std_array.rs b/spec/rust/formats/instance_std_array.rs new file mode 100644 index 000000000..dfb0f98a4 --- /dev/null +++ b/spec/rust/formats/instance_std_array.rs @@ -0,0 +1,65 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct InstanceStdArray { + pub ofs: u32, + pub entry_size: u32, + pub qty_entries: u32, + pub entries: Vec>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for InstanceStdArray { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.ofs = _io.read_u4le()?; + self.entry_size = _io.read_u4le()?; + self.qty_entries = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> InstanceStdArray { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = InstanceStdArray::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn entries( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec>> { + if self.entries.is_some() { + return Ok(self.entries.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, Name(identifier(ofs))) + self.entries = Vec::new(); + { + // condRepeatExprHeader(InstanceIdentifier(entries), _io, BytesLimitType(Name(identifier(entry_size)),None,false,None,None), Name(identifier(qty_entries))) + // handleAssignmentRepeatExpr(InstanceIdentifier(entries), _io.read_bytes(self.entry_size as usize)?) + } + // popPos(_io) + return Ok(self.entries.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/instance_user_array.rs b/spec/rust/formats/instance_user_array.rs new file mode 100644 index 000000000..56fed5b10 --- /dev/null +++ b/spec/rust/formats/instance_user_array.rs @@ -0,0 +1,106 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(InstanceIdentifier(user_entries)), RepeatExpr(Name(identifier(qty_entries)))) + +#[derive(Default, Debug, PartialEq)] +pub struct InstanceUserArray { + pub ofs: u32, + pub entry_size: u32, + pub qty_entries: u32, + pub raw_user_entries: Vec>, + pub user_entries: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for InstanceUserArray { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.ofs = _io.read_u4le()?; + self.entry_size = _io.read_u4le()?; + self.qty_entries = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> InstanceUserArray { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = InstanceUserArray::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn user_entries( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.user_entries.is_some() { + return Ok(self.user_entries.as_ref().unwrap()); + } + { + // condIfHeader(Compare(Name(identifier(ofs)),Gt,IntNum(0))) + // pushPos(_io) + // seek(_io, Name(identifier(ofs))) + self.user_entries = Vec::new(); + { + // condRepeatExprHeader(InstanceIdentifier(user_entries), _io, UserTypeFromBytes(List(entry),None,List(),BytesLimitType(Name(identifier(entry_size)),None,false,None,None),None), Name(identifier(qty_entries))) + // handleAssignmentRepeatExpr(RawIdentifier(InstanceIdentifier(user_entries)), _io.read_bytes(self.entry_size as usize)?) + // handleAssignmentRepeatExpr(InstanceIdentifier(user_entries), &BytesReader::new(_io.read_bytes(self.entry_size as usize)?)) + } + // popPos(_io) + } + return Ok(self.user_entries.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct InstanceUserArray_Entry { + pub word1: u16, + pub word2: u16, +} +impl<'r, 's: 'r> KStruct<'r, 's> for InstanceUserArray_Entry { + type Root = InstanceUserArray; + type ParentStack = (&'r InstanceUserArray, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.word1 = _io.read_u2le()?; + self.word2 = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> InstanceUserArray_Entry { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = InstanceUserArray_Entry::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/integers.rs b/spec/rust/formats/integers.rs new file mode 100644 index 000000000..29e4813fd --- /dev/null +++ b/spec/rust/formats/integers.rs @@ -0,0 +1,93 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct Integers { + pub magic1: Vec, + pub uint8: u8, + pub sint8: i8, + pub magic_uint: Vec, + pub uint16: u16, + pub uint32: u32, + pub uint64: u64, + pub magic_sint: Vec, + pub sint16: i16, + pub sint32: i32, + pub sint64: i64, + pub magic_uint_le: Vec, + pub uint16le: u16, + pub uint32le: u32, + pub uint64le: u64, + pub magic_sint_le: Vec, + pub sint16le: i16, + pub sint32le: i32, + pub sint64le: i64, + pub magic_uint_be: Vec, + pub uint16be: u16, + pub uint32be: u32, + pub uint64be: u64, + pub magic_sint_be: Vec, + pub sint16be: i16, + pub sint32be: i32, + pub sint64be: i64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for Integers { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); + self.uint8 = _io.read_u1()?; + self.sint8 = _io.read_s1()?; + self.magic_uint = _io.read_bytes(10 as usize)?.to_vec(); + self.uint16 = _io.read_u2le()?; + self.uint32 = _io.read_u4le()?; + self.uint64 = _io.read_u8le()?; + self.magic_sint = _io.read_bytes(10 as usize)?.to_vec(); + self.sint16 = _io.read_s2le()?; + self.sint32 = _io.read_s4le()?; + self.sint64 = _io.read_s8le()?; + self.magic_uint_le = _io.read_bytes(9 as usize)?.to_vec(); + self.uint16le = _io.read_u2le()?; + self.uint32le = _io.read_u4le()?; + self.uint64le = _io.read_u8le()?; + self.magic_sint_le = _io.read_bytes(9 as usize)?.to_vec(); + self.sint16le = _io.read_s2le()?; + self.sint32le = _io.read_s4le()?; + self.sint64le = _io.read_s8le()?; + self.magic_uint_be = _io.read_bytes(9 as usize)?.to_vec(); + self.uint16be = _io.read_u2be()?; + self.uint32be = _io.read_u4be()?; + self.uint64be = _io.read_u8be()?; + self.magic_sint_be = _io.read_bytes(9 as usize)?.to_vec(); + self.sint16be = _io.read_s2be()?; + self.sint32be = _io.read_s4be()?; + self.sint64be = _io.read_s8be()?; + Ok(()) + } +} +impl<'r, 's: 'r> Integers { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = Integers::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/integers_double_overflow.rs b/spec/rust/formats/integers_double_overflow.rs new file mode 100644 index 000000000..3faa0c24e --- /dev/null +++ b/spec/rust/formats/integers_double_overflow.rs @@ -0,0 +1,115 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IntegersDoubleOverflow { + pub signed_safe_min_be: i64, + pub signed_safe_min_le: i64, + pub signed_safe_max_be: i64, + pub signed_safe_max_le: i64, + pub signed_unsafe_neg_be: i64, + pub signed_unsafe_neg_le: i64, + pub signed_unsafe_pos_be: i64, + pub signed_unsafe_pos_le: i64, + pub unsigned_safe_max_be: Option, + pub unsigned_safe_max_le: Option, + pub unsigned_unsafe_pos_be: Option, + pub unsigned_unsafe_pos_le: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IntegersDoubleOverflow { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.signed_safe_min_be = _io.read_s8be()?; + self.signed_safe_min_le = _io.read_s8le()?; + self.signed_safe_max_be = _io.read_s8be()?; + self.signed_safe_max_le = _io.read_s8le()?; + self.signed_unsafe_neg_be = _io.read_s8be()?; + self.signed_unsafe_neg_le = _io.read_s8le()?; + self.signed_unsafe_pos_be = _io.read_s8be()?; + self.signed_unsafe_pos_le = _io.read_s8le()?; + Ok(()) + } +} +impl<'r, 's: 'r> IntegersDoubleOverflow { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IntegersDoubleOverflow::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn unsigned_safe_max_be( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u64> { + if self.unsigned_safe_max_be.is_some() { + return Ok(self.unsigned_safe_max_be.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(16)) + // popPos(_io) + return Ok(self.unsigned_safe_max_be.as_ref().unwrap()); + } + fn unsigned_safe_max_le( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u64> { + if self.unsigned_safe_max_le.is_some() { + return Ok(self.unsigned_safe_max_le.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(24)) + // popPos(_io) + return Ok(self.unsigned_safe_max_le.as_ref().unwrap()); + } + fn unsigned_unsafe_pos_be( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u64> { + if self.unsigned_unsafe_pos_be.is_some() { + return Ok(self.unsigned_unsafe_pos_be.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(48)) + // popPos(_io) + return Ok(self.unsigned_unsafe_pos_be.as_ref().unwrap()); + } + fn unsigned_unsafe_pos_le( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u64> { + if self.unsigned_unsafe_pos_le.is_some() { + return Ok(self.unsigned_unsafe_pos_le.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(56)) + // popPos(_io) + return Ok(self.unsigned_unsafe_pos_le.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/integers_min_max.rs b/spec/rust/formats/integers_min_max.rs new file mode 100644 index 000000000..1a0ece3a0 --- /dev/null +++ b/spec/rust/formats/integers_min_max.rs @@ -0,0 +1,137 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct IntegersMinMax { + pub unsigned_min: Option, + pub unsigned_max: Option, + pub signed_min: Option, + pub signed_max: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IntegersMinMax { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.unsigned_min = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.unsigned_max = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.signed_min = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.signed_max = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> IntegersMinMax { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IntegersMinMax::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IntegersMinMax_Unsigned { + pub u1: u8, + pub u2le: u16, + pub u4le: u32, + pub u8le: u64, + pub u2be: u16, + pub u4be: u32, + pub u8be: u64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IntegersMinMax_Unsigned { + type Root = IntegersMinMax; + type ParentStack = (&'r IntegersMinMax, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.u1 = _io.read_u1()?; + self.u2le = _io.read_u2le()?; + self.u4le = _io.read_u4le()?; + self.u8le = _io.read_u8le()?; + self.u2be = _io.read_u2be()?; + self.u4be = _io.read_u4be()?; + self.u8be = _io.read_u8be()?; + Ok(()) + } +} +impl<'r, 's: 'r> IntegersMinMax_Unsigned { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IntegersMinMax_Unsigned::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct IntegersMinMax_Signed { + pub s1: i8, + pub s2le: i16, + pub s4le: i32, + pub s8le: i64, + pub s2be: i16, + pub s4be: i32, + pub s8be: i64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for IntegersMinMax_Signed { + type Root = IntegersMinMax; + type ParentStack = (&'r IntegersMinMax, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.s1 = _io.read_s1()?; + self.s2le = _io.read_s2le()?; + self.s4le = _io.read_s4le()?; + self.s8le = _io.read_s8le()?; + self.s2be = _io.read_s2be()?; + self.s4be = _io.read_s4be()?; + self.s8be = _io.read_s8be()?; + Ok(()) + } +} +impl<'r, 's: 'r> IntegersMinMax_Signed { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IntegersMinMax_Signed::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/io_local_var.rs b/spec/rust/formats/io_local_var.rs new file mode 100644 index 000000000..ab8803eb0 --- /dev/null +++ b/spec/rust/formats/io_local_var.rs @@ -0,0 +1,122 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(InstanceIdentifier(mess_up)), NoRepeat) +// extraAttrForIO(RawIdentifier(InstanceIdentifier(mess_up)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct IoLocalVar { + pub skip: Vec, + pub always_null: u8, + pub followup: u8, + pub raw_mess_up: Vec, + pub mess_up: Option, +} +#[derive(Debug, PartialEq)] +pub enum IoLocalVar_MessUp { + IoLocalVar_Dummy(IoLocalVar_Dummy), + Bytes(Vec), +} +impl From for IoLocalVar_MessUp { + fn from(v: IoLocalVar_Dummy) -> Self { + Self::IoLocalVar_Dummy(v) + } +} +impl From> for IoLocalVar_MessUp { + fn from(v: Vec) -> Self { + Self::Bytes(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for IoLocalVar { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.skip = _io.read_bytes(20 as usize)?.to_vec(); + { + // condIfHeader(Compare(Attribute(Attribute(CastToType(Name(identifier(mess_up)),typeId(false,ArrayBuffer(dummy),false)),identifier(_io)),identifier(pos)),Lt,IntNum(0))) + self.always_null = _io.read_u1()?; + } + self.followup = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> IoLocalVar { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IoLocalVar::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn mess_up( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&IoLocalVar_MessUp> { + if self.mess_up.is_some() { + return Ok(self.mess_up.as_ref().unwrap()); + } + // pushPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) + // seek(// useIO(Attribute(Name(identifier(_root)),identifier(_io))), IntNum(8)) + match 2 { + 1 => { + } + 2 => { + } + // switchElseStart() + } + _ => panic!("unhandled value") + } + // popPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) + return Ok(self.mess_up.as_ref().unwrap()); +} +} + +#[derive(Default, Debug, PartialEq)] +pub struct IoLocalVar_Dummy { +} +impl<'r, 's: 'r> KStruct<'r, 's> for IoLocalVar_Dummy { +type Root = IoLocalVar; +type ParentStack = (&'r IoLocalVar, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + Ok(()) +} +} +impl<'r, 's: 'r> IoLocalVar_Dummy { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = IoLocalVar_Dummy::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/js_signed_right_shift.rs b/spec/rust/formats/js_signed_right_shift.rs new file mode 100644 index 000000000..39cb2c32d --- /dev/null +++ b/spec/rust/formats/js_signed_right_shift.rs @@ -0,0 +1,65 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct JsSignedRightShift { + pub should_be_40000000: Option, + pub should_be_a00000: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for JsSignedRightShift { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> JsSignedRightShift { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = JsSignedRightShift::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn should_be_40000000( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.should_be_40000000.is_some() { + return Ok(self.should_be_40000000.as_ref().unwrap()); + } + self.should_be_40000000 = Some((2147483648 >> 1) as i32); + return Ok(self.should_be_40000000.as_ref().unwrap()); + } + fn should_be_a00000( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.should_be_a00000.is_some() { + return Ok(self.should_be_a00000.as_ref().unwrap()); + } + self.should_be_a00000 = Some((2684354560 >> 8) as i32); + return Ok(self.should_be_a00000.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/meta_tags.rs b/spec/rust/formats/meta_tags.rs new file mode 100644 index 000000000..ef3524957 --- /dev/null +++ b/spec/rust/formats/meta_tags.rs @@ -0,0 +1,39 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct MetaTags { +} +impl<'r, 's: 'r> KStruct<'r, 's> for MetaTags { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> MetaTags { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = MetaTags::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/meta_xref.rs b/spec/rust/formats/meta_xref.rs new file mode 100644 index 000000000..2ec4359db --- /dev/null +++ b/spec/rust/formats/meta_xref.rs @@ -0,0 +1,39 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct MetaXref { +} +impl<'r, 's: 'r> KStruct<'r, 's> for MetaXref { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> MetaXref { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = MetaXref::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/multiple_use.rs b/spec/rust/formats/multiple_use.rs new file mode 100644 index 000000000..d18dc868e --- /dev/null +++ b/spec/rust/formats/multiple_use.rs @@ -0,0 +1,155 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct MultipleUse { + pub t1: Option, + pub t2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.t1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.t2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> MultipleUse { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = MultipleUse::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct MultipleUse_Multi { + pub value: i32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse_Multi { + type Root = MultipleUse; + type ParentStack = (&'r MultipleUse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_s4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> MultipleUse_Multi { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = MultipleUse_Multi::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct MultipleUse_Type1 { + pub first_use: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse_Type1 { + type Root = MultipleUse; + type ParentStack = (&'r MultipleUse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.first_use = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> MultipleUse_Type1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = MultipleUse_Type1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct MultipleUse_Type2 { + pub second_use: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse_Type2 { + type Root = MultipleUse; + type ParentStack = (&'r MultipleUse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> MultipleUse_Type2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = MultipleUse_Type2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn second_use( + &mut self, + _io: &'s S, + _root: Option<&'r MultipleUse>, + _parent: Option>::ParentStack)>> + ) -> KResult<&MultipleUse_Multi> { + if self.second_use.is_some() { + return Ok(self.second_use.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(0)) + // popPos(_io) + return Ok(self.second_use.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/nav_parent.rs b/spec/rust/formats/nav_parent.rs new file mode 100644 index 000000000..883f5c022 --- /dev/null +++ b/spec/rust/formats/nav_parent.rs @@ -0,0 +1,150 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent { + pub header: Option, + pub index: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.header = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.index = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParent { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent_HeaderObj { + pub qty_entries: u32, + pub filename_len: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent_HeaderObj { + type Root = NavParent; + type ParentStack = (&'r NavParent, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty_entries = _io.read_u4le()?; + self.filename_len = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParent_HeaderObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent_HeaderObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent_IndexObj { + pub magic: Vec, + pub entries: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent_IndexObj { + type Root = NavParent; + type ParentStack = (&'r NavParent, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.magic = _io.read_bytes(4 as usize)?.to_vec(); + self.entries = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(entries), _io, UserTypeInstream(List(entry),None,List()), Attribute(Attribute(Name(identifier(_parent)),identifier(header)),identifier(qty_entries))) + // handleAssignmentRepeatExpr(NamedIdentifier(entries), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> NavParent_IndexObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent_IndexObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent_Entry { + pub filename: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent_Entry { + type Root = NavParent; + type ParentStack = (&'r NavParent, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.filename = decode_string(_io.read_bytes(_parent.peek()._parent.header.filename_len as usize)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParent_Entry { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent_Entry::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nav_parent2.rs b/spec/rust/formats/nav_parent2.rs new file mode 100644 index 000000000..d779ac41d --- /dev/null +++ b/spec/rust/formats/nav_parent2.rs @@ -0,0 +1,149 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent2 { + pub ofs_tags: u32, + pub num_tags: u32, + pub tags: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.ofs_tags = _io.read_u4le()?; + self.num_tags = _io.read_u4le()?; + self.tags = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(tags), _io, UserTypeInstream(List(tag),None,List()), Name(identifier(num_tags))) + // handleAssignmentRepeatExpr(NamedIdentifier(tags), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> NavParent2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent2_Tag { + pub name: String, + pub ofs: u32, + pub num_items: u32, + pub tag_content: Option, +} +#[derive(Debug, PartialEq)] +pub enum NavParent2_Tag_TagContent { + NavParent2_Tag_TagChar(NavParent2_Tag_TagChar), +} +impl From for NavParent2_Tag_TagContent { + fn from(v: NavParent2_Tag_TagChar) -> Self { + Self::NavParent2_Tag_TagChar(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent2_Tag { + type Root = NavParent2; + type ParentStack = (&'r NavParent2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.name = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; + self.ofs = _io.read_u4le()?; + self.num_items = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParent2_Tag { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent2_Tag::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn tag_content( + &mut self, + _io: &'s S, + _root: Option<&'r NavParent2>, + _parent: Option>::ParentStack)>> + ) -> KResult<&NavParent2_Tag_TagContent> { + if self.tag_content.is_some() { + return Ok(self.tag_content.as_ref().unwrap()); + } + // pushPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) + // seek(// useIO(Attribute(Name(identifier(_root)),identifier(_io))), Name(identifier(ofs))) + { + let on = &self.name; + if on == "RAHC" { + } + } + // popPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) + return Ok(self.tag_content.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent2_Tag_TagChar { + pub content: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent2_Tag_TagChar { + type Root = NavParent2; + type ParentStack = (&'r NavParent2_Tag, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.content = decode_string(_io.read_bytes(_parent.peek().num_items as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParent2_Tag_TagChar { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent2_Tag_TagChar::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nav_parent3.rs b/spec/rust/formats/nav_parent3.rs new file mode 100644 index 000000000..8690b9370 --- /dev/null +++ b/spec/rust/formats/nav_parent3.rs @@ -0,0 +1,163 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent3 { + pub ofs_tags: u32, + pub num_tags: u32, + pub tags: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent3 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.ofs_tags = _io.read_u4le()?; + self.num_tags = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParent3 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent3::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn tags( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Vec> { + if self.tags.is_some() { + return Ok(self.tags.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, Name(identifier(ofs_tags))) + self.tags = Vec::new(); + { + // condRepeatExprHeader(InstanceIdentifier(tags), _io, UserTypeInstream(List(tag),None,List()), Name(identifier(num_tags))) + // handleAssignmentRepeatExpr(InstanceIdentifier(tags), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + // popPos(_io) + return Ok(self.tags.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent3_Tag { + pub name: String, + pub ofs: u32, + pub num_items: u32, + pub tag_content: Option, +} +#[derive(Debug, PartialEq)] +pub enum NavParent3_Tag_TagContent { + NavParent3_Tag_TagChar(NavParent3_Tag_TagChar), +} +impl From for NavParent3_Tag_TagContent { + fn from(v: NavParent3_Tag_TagChar) -> Self { + Self::NavParent3_Tag_TagChar(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent3_Tag { + type Root = NavParent3; + type ParentStack = (&'r NavParent3, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.name = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; + self.ofs = _io.read_u4le()?; + self.num_items = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParent3_Tag { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent3_Tag::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn tag_content( + &mut self, + _io: &'s S, + _root: Option<&'r NavParent3>, + _parent: Option>::ParentStack)>> + ) -> KResult<&NavParent3_Tag_TagContent> { + if self.tag_content.is_some() { + return Ok(self.tag_content.as_ref().unwrap()); + } + // pushPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) + // seek(// useIO(Attribute(Name(identifier(_root)),identifier(_io))), Name(identifier(ofs))) + { + let on = &self.name; + if on == "RAHC" { + } + } + // popPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) + return Ok(self.tag_content.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParent3_Tag_TagChar { + pub content: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParent3_Tag_TagChar { + type Root = NavParent3; + type ParentStack = (&'r NavParent3_Tag, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.content = decode_string(_io.read_bytes(_parent.peek().num_items as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParent3_Tag_TagChar { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParent3_Tag_TagChar::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nav_parent_false.rs b/spec/rust/formats/nav_parent_false.rs new file mode 100644 index 000000000..ea114a4df --- /dev/null +++ b/spec/rust/formats/nav_parent_false.rs @@ -0,0 +1,151 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentFalse { + pub child_size: u8, + pub element_a: Option, + pub element_b: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.child_size = _io.read_u1()?; + self.element_a = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.element_b = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentFalse { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentFalse::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentFalse_ParentA { + pub foo: Option, + pub bar: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse_ParentA { + type Root = NavParentFalse; + type ParentStack = (&'r NavParentFalse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.bar = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentFalse_ParentA { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentFalse_ParentA::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentFalse_ParentB { + pub foo: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse_ParentB { + type Root = NavParentFalse; + type ParentStack = (&'r NavParentFalse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, KStructUnit::parent_stack())?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentFalse_ParentB { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentFalse_ParentB::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentFalse_Child { + pub code: u8, + pub more: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse_Child { + type Root = NavParentFalse; + type ParentStack = (&'r NavParentFalse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + { + // condIfHeader(Compare(Name(identifier(code)),Eq,IntNum(73))) + self.more = _io.read_bytes(_parent.peek()._parent.child_size as usize)?.to_vec(); + } + Ok(()) + } +} +impl<'r, 's: 'r> NavParentFalse_Child { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentFalse_Child::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nav_parent_false2.rs b/spec/rust/formats/nav_parent_false2.rs new file mode 100644 index 000000000..1acd02ad8 --- /dev/null +++ b/spec/rust/formats/nav_parent_false2.rs @@ -0,0 +1,74 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentFalse2 { + pub parentless: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.parentless = Some(Self::read_into::(Self::read_into::(_io, _root, KStructUnit::parent_stack())?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentFalse2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentFalse2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentFalse2_Child { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse2_Child { + type Root = NavParentFalse2; + type ParentStack = (&'r NavParentFalse2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NavParentFalse2_Child { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentFalse2_Child::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nav_parent_override.rs b/spec/rust/formats/nav_parent_override.rs new file mode 100644 index 000000000..9ad2ff630 --- /dev/null +++ b/spec/rust/formats/nav_parent_override.rs @@ -0,0 +1,111 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentOverride { + pub child_size: u8, + pub child_1: Option, + pub mediator_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentOverride { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.child_size = _io.read_u1()?; + self.child_1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.mediator_2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentOverride { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentOverride::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentOverride_Mediator { + pub child_2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentOverride_Mediator { + type Root = NavParentOverride; + type ParentStack = (&'r NavParentOverride, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.child_2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.peek())?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentOverride_Mediator { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentOverride_Mediator::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentOverride_Child { + pub data: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentOverride_Child { + type Root = NavParentOverride; + type ParentStack = (&'r NavParentOverride, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.data = _io.read_bytes(_parent.peek().child_size as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentOverride_Child { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentOverride_Child::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nav_parent_switch.rs b/spec/rust/formats/nav_parent_switch.rs new file mode 100644 index 000000000..daa2f07da --- /dev/null +++ b/spec/rust/formats/nav_parent_switch.rs @@ -0,0 +1,129 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitch { + pub category: u8, + pub content: Option, +} +#[derive(Debug, PartialEq)] +pub enum NavParentSwitch_Content { + NavParentSwitch_Element1(NavParentSwitch_Element1), +} +impl From for NavParentSwitch_Content { + fn from(v: NavParentSwitch_Element1) -> Self { + Self::NavParentSwitch_Element1(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitch { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.category = _io.read_u1()?; + match self.category { + 1 => { + self.content = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> NavParentSwitch { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitch::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitch_Element1 { + pub foo: u8, + pub subelement: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitch_Element1 { + type Root = NavParentSwitch; + type ParentStack = (&'r NavParentSwitch, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + self.subelement = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentSwitch_Element1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitch_Element1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitch_Subelement1 { + pub bar: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitch_Subelement1 { + type Root = NavParentSwitch; + type ParentStack = (&'r NavParentSwitch, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + { + // condIfHeader(Compare(Attribute(Name(identifier(_parent)),identifier(foo)),Eq,IntNum(66))) + self.bar = _io.read_u1()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> NavParentSwitch_Subelement1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitch_Subelement1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nav_parent_switch_cast.rs b/spec/rust/formats/nav_parent_switch_cast.rs new file mode 100644 index 000000000..c9799c28f --- /dev/null +++ b/spec/rust/formats/nav_parent_switch_cast.rs @@ -0,0 +1,224 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitchCast { + pub main: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentSwitchCast { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitchCast::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitchCast_Foo { + pub buf_type: u8, + pub flag: u8, + pub buf: Option, + pub raw_buf: Vec, +} +#[derive(Debug, PartialEq)] +pub enum NavParentSwitchCast_Foo_Buf { + NavParentSwitchCast_Foo_Zero(NavParentSwitchCast_Foo_Zero), + NavParentSwitchCast_Foo_One(NavParentSwitchCast_Foo_One), + Bytes(Vec), +} +impl From for NavParentSwitchCast_Foo_Buf { + fn from(v: NavParentSwitchCast_Foo_Zero) -> Self { + Self::NavParentSwitchCast_Foo_Zero(v) + } +} +impl From for NavParentSwitchCast_Foo_Buf { + fn from(v: NavParentSwitchCast_Foo_One) -> Self { + Self::NavParentSwitchCast_Foo_One(v) + } +} +impl From> for NavParentSwitchCast_Foo_Buf { + fn from(v: Vec) -> Self { + Self::Bytes(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo { + type Root = NavParentSwitchCast; + type ParentStack = (&'r NavParentSwitchCast, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf_type = _io.read_u1()?; + self.flag = _io.read_u1()?; + match self.buf_type { + 0 => { + self.buf = Some(&BytesReader::new(_io.read_bytes(4 as usize)?)); + } + 1 => { + self.buf = Some(&BytesReader::new(_io.read_bytes(4 as usize)?)); + } + // switchElseStart() + self.buf = Some(_io.read_bytes(4 as usize)?); + } + _ => panic!("unhandled value") + } + Ok(()) +} +} +impl<'r, 's: 'r> NavParentSwitchCast_Foo { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitchCast_Foo::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitchCast_Foo_Zero { +pub branch: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo_Zero { +type Root = NavParentSwitchCast; +type ParentStack = (&'r NavParentSwitchCast_Foo, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.branch = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) +} +} +impl<'r, 's: 'r> NavParentSwitchCast_Foo_Zero { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitchCast_Foo_Zero::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitchCast_Foo_One { +pub branch: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo_One { +type Root = NavParentSwitchCast; +type ParentStack = (&'r NavParentSwitchCast_Foo, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.branch = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) +} +} +impl<'r, 's: 'r> NavParentSwitchCast_Foo_One { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitchCast_Foo_One::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentSwitchCast_Foo_Common { +pub flag: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo_Common { +type Root = NavParentSwitchCast; +type ParentStack = (&'r NavParentSwitchCast_Foo, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + Ok(()) +} +} +impl<'r, 's: 'r> NavParentSwitchCast_Foo_Common { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentSwitchCast_Foo_Common::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +fn flag( + &mut self, + _io: &'s S, + _root: Option<&'r NavParentSwitchCast>, + _parent: Option>::ParentStack)>> +) -> KResult<&u8> { + if self.flag.is_some() { + return Ok(self.flag.as_ref().unwrap()); + } + self.flag = Some(_parent.peek()._parent.flag as u8); + return Ok(self.flag.as_ref().unwrap()); +} +} diff --git a/spec/rust/formats/nav_parent_vs_value_inst.rs b/spec/rust/formats/nav_parent_vs_value_inst.rs new file mode 100644 index 000000000..f31ea31e1 --- /dev/null +++ b/spec/rust/formats/nav_parent_vs_value_inst.rs @@ -0,0 +1,87 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentVsValueInst { + pub s1: String, + pub child: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentVsValueInst { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; + self.child = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavParentVsValueInst { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentVsValueInst::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavParentVsValueInst_ChildObj { + pub do_something: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavParentVsValueInst_ChildObj { + type Root = NavParentVsValueInst; + type ParentStack = (&'r NavParentVsValueInst, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> NavParentVsValueInst_ChildObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavParentVsValueInst_ChildObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn do_something( + &mut self, + _io: &'s S, + _root: Option<&'r NavParentVsValueInst>, + _parent: Option>::ParentStack)>> + ) -> KResult<&bool> { + if self.do_something.is_some() { + return Ok(self.do_something.as_ref().unwrap()); + } + self.do_something = Some(if _parent.peek().s1 == "foo" { true } else { false} as bool); + return Ok(self.do_something.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/nav_root.rs b/spec/rust/formats/nav_root.rs new file mode 100644 index 000000000..435a8b6e9 --- /dev/null +++ b/spec/rust/formats/nav_root.rs @@ -0,0 +1,150 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NavRoot { + pub header: Option, + pub index: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.header = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.index = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NavRoot { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavRoot::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavRoot_HeaderObj { + pub qty_entries: u32, + pub filename_len: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot_HeaderObj { + type Root = NavRoot; + type ParentStack = (&'r NavRoot, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty_entries = _io.read_u4le()?; + self.filename_len = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> NavRoot_HeaderObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavRoot_HeaderObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavRoot_IndexObj { + pub magic: Vec, + pub entries: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot_IndexObj { + type Root = NavRoot; + type ParentStack = (&'r NavRoot, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.magic = _io.read_bytes(4 as usize)?.to_vec(); + self.entries = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(entries), _io, UserTypeInstream(List(entry),None,List()), Attribute(Attribute(Name(identifier(_root)),identifier(header)),identifier(qty_entries))) + // handleAssignmentRepeatExpr(NamedIdentifier(entries), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> NavRoot_IndexObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavRoot_IndexObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NavRoot_Entry { + pub filename: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot_Entry { + type Root = NavRoot; + type ParentStack = (&'r NavRoot, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.filename = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.header.filename_len as usize)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> NavRoot_Entry { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NavRoot_Entry::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nested_same_name.rs b/spec/rust/formats/nested_same_name.rs new file mode 100644 index 000000000..c0d682109 --- /dev/null +++ b/spec/rust/formats/nested_same_name.rs @@ -0,0 +1,173 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName { + pub main_data: Option, + pub dummy: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main_data = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.dummy = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName_Main { + pub main_size: i32, + pub foo: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_Main { + type Root = NestedSameName; + type ParentStack = (&'r NestedSameName, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main_size = _io.read_s4le()?; + self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName_Main { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName_Main::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName_Main_FooObj { + pub data: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_Main_FooObj { + type Root = NestedSameName; + type ParentStack = (&'r NestedSameName_Main, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.data = _io.read_bytes((_parent.peek().main_size * 2) as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName_Main_FooObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName_Main_FooObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName_DummyObj { +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_DummyObj { + type Root = NestedSameName; + type ParentStack = (&'r NestedSameName, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName_DummyObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName_DummyObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName_DummyObj_Foo { +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_DummyObj_Foo { + type Root = NestedSameName; + type ParentStack = (&'r NestedSameName_DummyObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName_DummyObj_Foo { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName_DummyObj_Foo::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nested_same_name2.rs b/spec/rust/formats/nested_same_name2.rs new file mode 100644 index 000000000..a191e08fc --- /dev/null +++ b/spec/rust/formats/nested_same_name2.rs @@ -0,0 +1,181 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName2 { + pub version: u32, + pub main_data: Option, + pub dummy: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.version = _io.read_u4le()?; + self.main_data = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.dummy = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName2_Main { + pub main_size: i32, + pub foo: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_Main { + type Root = NestedSameName2; + type ParentStack = (&'r NestedSameName2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main_size = _io.read_s4le()?; + self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName2_Main { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName2_Main::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName2_Main_FooObj { + pub data1: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_Main_FooObj { + type Root = NestedSameName2; + type ParentStack = (&'r NestedSameName2_Main, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.data1 = _io.read_bytes((_parent.peek().main_size * 2) as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName2_Main_FooObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName2_Main_FooObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName2_DummyObj { + pub dummy_size: i32, + pub foo: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_DummyObj { + type Root = NestedSameName2; + type ParentStack = (&'r NestedSameName2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.dummy_size = _io.read_s4le()?; + self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName2_DummyObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName2_DummyObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedSameName2_DummyObj_FooObj { + pub data2: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_DummyObj_FooObj { + type Root = NestedSameName2; + type ParentStack = (&'r NestedSameName2_DummyObj, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.data2 = _io.read_bytes((_parent.peek().dummy_size * 2) as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> NestedSameName2_DummyObj_FooObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedSameName2_DummyObj_FooObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nested_type_param.rs b/spec/rust/formats/nested_type_param.rs new file mode 100644 index 000000000..cb226dbe1 --- /dev/null +++ b/spec/rust/formats/nested_type_param.rs @@ -0,0 +1,106 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypeParam { + pub main_seq: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypeParam { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.main_seq = Some(Self::read_into::(Self::read_into::(5, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypeParam { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypeParam::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypeParam_Nested { +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypeParam_Nested { + type Root = NestedTypeParam; + type ParentStack = (&'r NestedTypeParam, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypeParam_Nested { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypeParam_Nested::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypeParam_Nested_MyType { + pub my_len: u32, + pub body: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypeParam_Nested_MyType { + type Root = NestedTypeParam; + type ParentStack = (&'r NestedTypeParam_Nested, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.body = decode_string(_io.read_bytes(self.my_len as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypeParam_Nested_MyType { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypeParam_Nested_MyType::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nested_types.rs b/spec/rust/formats/nested_types.rs new file mode 100644 index 000000000..23c79304b --- /dev/null +++ b/spec/rust/formats/nested_types.rs @@ -0,0 +1,144 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes { + pub one: Option, + pub two: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.two = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes_SubtypeA { + pub typed_at_root: Option, + pub typed_here: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes_SubtypeA { + type Root = NestedTypes; + type ParentStack = (&'r NestedTypes, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.typed_at_root = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.typed_here = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes_SubtypeA { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes_SubtypeA::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes_SubtypeA_SubtypeC { + pub value_c: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes_SubtypeA_SubtypeC { + type Root = NestedTypes; + type ParentStack = (&'r NestedTypes_SubtypeA, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_c = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes_SubtypeA_SubtypeC { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes_SubtypeA_SubtypeC::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes_SubtypeB { + pub value_b: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes_SubtypeB { + type Root = NestedTypes; + type ParentStack = (&'r NestedTypes, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_b = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes_SubtypeB { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes_SubtypeB::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nested_types2.rs b/spec/rust/formats/nested_types2.rs new file mode 100644 index 000000000..e9d9cd97e --- /dev/null +++ b/spec/rust/formats/nested_types2.rs @@ -0,0 +1,218 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes2 { + pub one: Option, + pub two: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.two = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes2_SubtypeA { + pub typed_at_root: Option, + pub typed_here1: Option, + pub typed_here2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA { + type Root = NestedTypes2; + type ParentStack = (&'r NestedTypes2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.typed_at_root = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.typed_here1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.typed_here2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes2_SubtypeA { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes2_SubtypeA::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes2_SubtypeA_SubtypeC { + pub value_c: i8, + pub typed_here: Option, + pub typed_parent: Option, + pub typed_root: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA_SubtypeC { + type Root = NestedTypes2; + type ParentStack = (&'r NestedTypes2_SubtypeA, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_c = _io.read_s1()?; + self.typed_here = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.typed_parent = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.typed_root = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes2_SubtypeA_SubtypeC { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes2_SubtypeA_SubtypeC::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes2_SubtypeA_SubtypeC_SubtypeD { + pub value_d: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA_SubtypeC_SubtypeD { + type Root = NestedTypes2; + type ParentStack = (&'r NestedTypes2_SubtypeA_SubtypeC, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_d = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes2_SubtypeA_SubtypeC_SubtypeD { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes2_SubtypeA_SubtypeC_SubtypeD::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes2_SubtypeA_SubtypeCc { + pub value_cc: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA_SubtypeCc { + type Root = NestedTypes2; + type ParentStack = (&'r NestedTypes2_SubtypeA, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_cc = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes2_SubtypeA_SubtypeCc { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes2_SubtypeA_SubtypeCc::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes2_SubtypeB { + pub value_b: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeB { + type Root = NestedTypes2; + type ParentStack = (&'r NestedTypes2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_b = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes2_SubtypeB { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes2_SubtypeB::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/nested_types3.rs b/spec/rust/formats/nested_types3.rs new file mode 100644 index 000000000..d64b89447 --- /dev/null +++ b/spec/rust/formats/nested_types3.rs @@ -0,0 +1,210 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes3 { + pub a_cc: Option, + pub a_c_d: Option, + pub b: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a_cc = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.a_c_d = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.b = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes3 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes3::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes3_SubtypeA { +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA { + type Root = NestedTypes3; + type ParentStack = (&'r NestedTypes3, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes3_SubtypeA { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes3_SubtypeA::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes3_SubtypeA_SubtypeC { +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA_SubtypeC { + type Root = NestedTypes3; + type ParentStack = (&'r NestedTypes3_SubtypeA, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes3_SubtypeA_SubtypeC { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes3_SubtypeA_SubtypeC::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes3_SubtypeA_SubtypeC_SubtypeD { + pub value_d: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA_SubtypeC_SubtypeD { + type Root = NestedTypes3; + type ParentStack = (&'r NestedTypes3_SubtypeA_SubtypeC, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_d = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes3_SubtypeA_SubtypeC_SubtypeD { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes3_SubtypeA_SubtypeC_SubtypeD::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes3_SubtypeA_SubtypeCc { + pub value_cc: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA_SubtypeCc { + type Root = NestedTypes3; + type ParentStack = (&'r NestedTypes3_SubtypeA, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_cc = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes3_SubtypeA_SubtypeCc { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes3_SubtypeA_SubtypeCc::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct NestedTypes3_SubtypeB { + pub value_b: i8, + pub a_cc: Option, + pub a_c_d: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeB { + type Root = NestedTypes3; + type ParentStack = (&'r NestedTypes3, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_b = _io.read_s1()?; + self.a_cc = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.a_c_d = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> NestedTypes3_SubtypeB { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NestedTypes3_SubtypeB::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/non_standard.rs b/spec/rust/formats/non_standard.rs new file mode 100644 index 000000000..8e21e7de6 --- /dev/null +++ b/spec/rust/formats/non_standard.rs @@ -0,0 +1,95 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct NonStandard { + pub foo: u8, + pub bar: Option, + pub vi: Option, + pub pi: Option, +} +#[derive(Debug, PartialEq)] +pub enum NonStandard_Bar { + U2(u16), + U4(u32), +} +impl From for NonStandard_Bar { + fn from(v: u16) -> Self { + Self::U2(v) + } +} +impl From for NonStandard_Bar { + fn from(v: u32) -> Self { + Self::U4(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for NonStandard { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + match self.foo { + 42 => { + self.bar = Some(_io.read_u2le()?); + } + 43 => { + self.bar = Some(_io.read_u4le()?); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> NonStandard { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = NonStandard::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn vi( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.vi.is_some() { + return Ok(self.vi.as_ref().unwrap()); + } + self.vi = Some(self.foo as u8); + return Ok(self.vi.as_ref().unwrap()); + } + fn pi( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.pi.is_some() { + return Ok(self.pi.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(0)) + // popPos(_io) + return Ok(self.pi.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/opaque_external_type.rs b/spec/rust/formats/opaque_external_type.rs new file mode 100644 index 000000000..515918256 --- /dev/null +++ b/spec/rust/formats/opaque_external_type.rs @@ -0,0 +1,42 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::term_strz::TermStrz; + +#[derive(Default, Debug, PartialEq)] +pub struct OpaqueExternalType { + pub one: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> OpaqueExternalType { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = OpaqueExternalType::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/opaque_external_type_02_child.rs b/spec/rust/formats/opaque_external_type_02_child.rs new file mode 100644 index 000000000..e4375ac3e --- /dev/null +++ b/spec/rust/formats/opaque_external_type_02_child.rs @@ -0,0 +1,94 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct OpaqueExternalType02Child { + pub s1: String, + pub s2: String, + pub s3: Option, + pub some_method: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Child { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; + self.s2 = decode_string(_io.read_bytes_term(124, false, false, true)?, "UTF-8")?; + self.s3 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> OpaqueExternalType02Child { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = OpaqueExternalType02Child::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn some_method( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.some_method.is_some() { + return Ok(self.some_method.as_ref().unwrap()); + } + self.some_method = Some(true as bool); + return Ok(self.some_method.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct OpaqueExternalType02Child_OpaqueExternalType02ChildChild { + pub s3: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Child_OpaqueExternalType02ChildChild { + type Root = OpaqueExternalType02Child; + type ParentStack = (&'r OpaqueExternalType02Child, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + { + // condIfHeader(Attribute(Name(identifier(_root)),identifier(some_method))) + self.s3 = decode_string(_io.read_bytes_term(64, true, true, true)?, "UTF-8")?; + } + Ok(()) + } +} +impl<'r, 's: 'r> OpaqueExternalType02Child_OpaqueExternalType02ChildChild { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = OpaqueExternalType02Child_OpaqueExternalType02ChildChild::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/opaque_external_type_02_parent.rs b/spec/rust/formats/opaque_external_type_02_parent.rs new file mode 100644 index 000000000..141c7eba3 --- /dev/null +++ b/spec/rust/formats/opaque_external_type_02_parent.rs @@ -0,0 +1,75 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::opaque_external_type_02_child::OpaqueExternalType02Child; + +#[derive(Default, Debug, PartialEq)] +pub struct OpaqueExternalType02Parent { + pub parent: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Parent { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.parent = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> OpaqueExternalType02Parent { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = OpaqueExternalType02Parent::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct OpaqueExternalType02Parent_ParentObj { + pub child: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Parent_ParentObj { + type Root = OpaqueExternalType02Parent; + type ParentStack = (&'r OpaqueExternalType02Parent, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.child = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> OpaqueExternalType02Parent_ParentObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = OpaqueExternalType02Parent_ParentObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/opaque_with_param.rs b/spec/rust/formats/opaque_with_param.rs new file mode 100644 index 000000000..95124fe68 --- /dev/null +++ b/spec/rust/formats/opaque_with_param.rs @@ -0,0 +1,42 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::params_def::ParamsDef; + +#[derive(Default, Debug, PartialEq)] +pub struct OpaqueWithParam { + pub one: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueWithParam { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some(Self::read_into::>(Self::read_into::(5, true, _io)?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> OpaqueWithParam { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = OpaqueWithParam::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/optional_id.rs b/spec/rust/formats/optional_id.rs new file mode 100644 index 000000000..7b054fd16 --- /dev/null +++ b/spec/rust/formats/optional_id.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct OptionalId { + pub _unnamed0: u8, + pub _unnamed1: u8, + pub _unnamed2: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for OptionalId { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self._unnamed0 = _io.read_u1()?; + self._unnamed1 = _io.read_u1()?; + self._unnamed2 = _io.read_bytes(5 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> OptionalId { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = OptionalId::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/params_call_extra_parens.rs b/spec/rust/formats/params_call_extra_parens.rs new file mode 100644 index 000000000..3fbded590 --- /dev/null +++ b/spec/rust/formats/params_call_extra_parens.rs @@ -0,0 +1,75 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsCallExtraParens { + pub buf1: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallExtraParens { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf1 = Some(Self::read_into::(Self::read_into::(5, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsCallExtraParens { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsCallExtraParens::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsCallExtraParens_MyStr1 { + pub len: u32, + pub body: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallExtraParens_MyStr1 { + type Root = ParamsCallExtraParens; + type ParentStack = (&'r ParamsCallExtraParens, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.body = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> ParamsCallExtraParens_MyStr1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsCallExtraParens_MyStr1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/params_call_short.rs b/spec/rust/formats/params_call_short.rs new file mode 100644 index 000000000..885c85b83 --- /dev/null +++ b/spec/rust/formats/params_call_short.rs @@ -0,0 +1,117 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsCallShort { + pub buf1: Option, + pub buf2: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallShort { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf1 = Some(Self::read_into::(Self::read_into::(5, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.buf2 = Some(Self::read_into::(Self::read_into::((2 + 3), true, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsCallShort { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsCallShort::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsCallShort_MyStr1 { + pub len: u32, + pub body: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallShort_MyStr1 { + type Root = ParamsCallShort; + type ParentStack = (&'r ParamsCallShort, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.body = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> ParamsCallShort_MyStr1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsCallShort_MyStr1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsCallShort_MyStr2 { + pub len: u32, + pub has_trailer: bool, + pub body: String, + pub trailer: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallShort_MyStr2 { + type Root = ParamsCallShort; + type ParentStack = (&'r ParamsCallShort, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.body = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; + { + // condIfHeader(Name(identifier(has_trailer))) + self.trailer = _io.read_u1()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> ParamsCallShort_MyStr2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsCallShort_MyStr2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/params_def.rs b/spec/rust/formats/params_def.rs new file mode 100644 index 000000000..e7427bf49 --- /dev/null +++ b/spec/rust/formats/params_def.rs @@ -0,0 +1,48 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsDef { + pub len: u32, + pub has_trailer: bool, + pub buf: String, + pub trailer: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsDef { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; + { + // condIfHeader(Name(identifier(has_trailer))) + self.trailer = _io.read_u1()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> ParamsDef { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsDef::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/params_enum.rs b/spec/rust/formats/params_enum.rs new file mode 100644 index 000000000..08b9e1e67 --- /dev/null +++ b/spec/rust/formats/params_enum.rs @@ -0,0 +1,106 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsEnum { + pub one: Option, + pub invoke_with_param: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsEnum { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some((_io.read_u1()? as i64).try_into()?); + self.invoke_with_param = Some(Self::read_into::(Self::read_into::(self.one, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsEnum { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsEnum::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum ParamsEnum_Animal { + Dog, + Cat, + Chicken, +} +impl TryFrom for ParamsEnum_Animal { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 4 => Ok(ParamsEnum_Animal::Dog), + 7 => Ok(ParamsEnum_Animal::Cat), + 12 => Ok(ParamsEnum_Animal::Chicken), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsEnum_WithParam { + pub enumerated_one: Option, + pub is_cat: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsEnum_WithParam { + type Root = ParamsEnum; + type ParentStack = (&'r ParamsEnum, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> ParamsEnum_WithParam { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsEnum_WithParam::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn is_cat( + &mut self, + _io: &'s S, + _root: Option<&'r ParamsEnum>, + _parent: Option>::ParentStack)>> + ) -> KResult<&bool> { + if self.is_cat.is_some() { + return Ok(self.is_cat.as_ref().unwrap()); + } + self.is_cat = Some(self.enumerated_one == ParamsEnum_Animal::Cat as bool); + return Ok(self.is_cat.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/params_pass_array_usertype.rs b/spec/rust/formats/params_pass_array_usertype.rs new file mode 100644 index 000000000..a465a1db4 --- /dev/null +++ b/spec/rust/formats/params_pass_array_usertype.rs @@ -0,0 +1,116 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassArrayUsertype { + pub blocks: Vec, + pub pass_blocks: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassArrayUsertype { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.blocks = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,List()), IntNum(2)) + // handleAssignmentRepeatExpr(NamedIdentifier(blocks), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + self.pass_blocks = Some(Self::read_into::(Self::read_into::(self.blocks, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassArrayUsertype { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassArrayUsertype::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassArrayUsertype_Block { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassArrayUsertype_Block { + type Root = ParamsPassArrayUsertype; + type ParentStack = (&'r ParamsPassArrayUsertype, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassArrayUsertype_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassArrayUsertype_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassArrayUsertype_ParamType { + pub bar: Vec, + pub one: Vec, + pub two: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassArrayUsertype_ParamType { + type Root = ParamsPassArrayUsertype; + type ParentStack = (&'r ParamsPassArrayUsertype, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_bytes(self.bar[0 as usize].foo as usize)?.to_vec(); + self.two = _io.read_bytes(self.bar[1 as usize].foo as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassArrayUsertype_ParamType { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassArrayUsertype_ParamType::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/params_pass_bool.rs b/spec/rust/formats/params_pass_bool.rs new file mode 100644 index 000000000..e05e81f53 --- /dev/null +++ b/spec/rust/formats/params_pass_bool.rs @@ -0,0 +1,150 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassBool { + pub s_false: bool, + pub s_true: bool, + pub seq_b1: Option, + pub seq_bool: Option, + pub literal_b1: Option, + pub literal_bool: Option, + pub inst_b1: Option, + pub inst_bool: Option, + pub v_false: Option, + pub v_true: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassBool { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.s_false = _io.read_bits_int(1)? != 0; + self.s_true = _io.read_bits_int(1)? != 0; + _io.align_to_byte()?; + self.seq_b1 = Some(Self::read_into::(Self::read_into::(self.s_true, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.seq_bool = Some(Self::read_into::(Self::read_into::(self.s_false, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.literal_b1 = Some(Self::read_into::(Self::read_into::(false, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.literal_bool = Some(Self::read_into::(Self::read_into::(true, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.inst_b1 = Some(Self::read_into::(Self::read_into::(self.v_true(_io, _root, _parent)?, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.inst_bool = Some(Self::read_into::(Self::read_into::(self.v_false(_io, _root, _parent)?, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassBool { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassBool::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn v_false( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.v_false.is_some() { + return Ok(self.v_false.as_ref().unwrap()); + } + self.v_false = Some(false as bool); + return Ok(self.v_false.as_ref().unwrap()); + } + fn v_true( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.v_true.is_some() { + return Ok(self.v_true.as_ref().unwrap()); + } + self.v_true = Some(true as bool); + return Ok(self.v_true.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassBool_ParamTypeB1 { + pub arg: bool, + pub foo: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassBool_ParamTypeB1 { + type Root = ParamsPassBool; + type ParentStack = (&'r ParamsPassBool, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_bytes(if self.arg { 1 } else { 2} as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassBool_ParamTypeB1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassBool_ParamTypeB1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassBool_ParamTypeBool { + pub arg: bool, + pub foo: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassBool_ParamTypeBool { + type Root = ParamsPassBool; + type ParentStack = (&'r ParamsPassBool, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_bytes(if self.arg { 1 } else { 2} as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassBool_ParamTypeBool { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassBool_ParamTypeBool::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/params_pass_usertype.rs b/spec/rust/formats/params_pass_usertype.rs new file mode 100644 index 000000000..909391db5 --- /dev/null +++ b/spec/rust/formats/params_pass_usertype.rs @@ -0,0 +1,110 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassUsertype { + pub first: Option, + pub one: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassUsertype { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.first = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + self.one = Some(Self::read_into::(Self::read_into::(self.first, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassUsertype { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassUsertype::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassUsertype_Block { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassUsertype_Block { + type Root = ParamsPassUsertype; + type ParentStack = (&'r ParamsPassUsertype, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassUsertype_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassUsertype_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ParamsPassUsertype_ParamType { + pub foo: Option, + pub buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassUsertype_ParamType { + type Root = ParamsPassUsertype; + type ParentStack = (&'r ParamsPassUsertype, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.buf = _io.read_bytes(self.foo.foo as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ParamsPassUsertype_ParamType { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ParamsPassUsertype_ParamType::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/position_abs.rs b/spec/rust/formats/position_abs.rs new file mode 100644 index 000000000..2cc648e8f --- /dev/null +++ b/spec/rust/formats/position_abs.rs @@ -0,0 +1,89 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct PositionAbs { + pub index_offset: u32, + pub index: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for PositionAbs { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.index_offset = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> PositionAbs { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = PositionAbs::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn index( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&PositionAbs_IndexObj> { + if self.index.is_some() { + return Ok(self.index.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, Name(identifier(index_offset))) + // popPos(_io) + return Ok(self.index.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct PositionAbs_IndexObj { + pub entry: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for PositionAbs_IndexObj { + type Root = PositionAbs; + type ParentStack = (&'r PositionAbs, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.entry = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> PositionAbs_IndexObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = PositionAbs_IndexObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/position_in_seq.rs b/spec/rust/formats/position_in_seq.rs new file mode 100644 index 000000000..546c0dc58 --- /dev/null +++ b/spec/rust/formats/position_in_seq.rs @@ -0,0 +1,93 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct PositionInSeq { + pub numbers: Vec, + pub header: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for PositionInSeq { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.numbers = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(numbers), _io, Int1Type(false), Attribute(Name(identifier(header)),identifier(qty_numbers))) + // handleAssignmentRepeatExpr(NamedIdentifier(numbers), _io.read_u1()?) + } + Ok(()) + } +} +impl<'r, 's: 'r> PositionInSeq { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = PositionInSeq::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn header( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&PositionInSeq_HeaderObj> { + if self.header.is_some() { + return Ok(self.header.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(16)) + // popPos(_io) + return Ok(self.header.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct PositionInSeq_HeaderObj { + pub qty_numbers: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for PositionInSeq_HeaderObj { + type Root = PositionInSeq; + type ParentStack = (&'r PositionInSeq, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty_numbers = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> PositionInSeq_HeaderObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = PositionInSeq_HeaderObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/position_to_end.rs b/spec/rust/formats/position_to_end.rs new file mode 100644 index 000000000..2a2f62191 --- /dev/null +++ b/spec/rust/formats/position_to_end.rs @@ -0,0 +1,89 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct PositionToEnd { + pub index: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for PositionToEnd { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> PositionToEnd { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = PositionToEnd::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn index( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&PositionToEnd_IndexObj> { + if self.index.is_some() { + return Ok(self.index.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, BinOp(Attribute(Name(identifier(_io)),identifier(size)),Sub,IntNum(8))) + // popPos(_io) + return Ok(self.index.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct PositionToEnd_IndexObj { + pub foo: u32, + pub bar: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for PositionToEnd_IndexObj { + type Root = PositionToEnd; + type ParentStack = (&'r PositionToEnd, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u4le()?; + self.bar = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> PositionToEnd_IndexObj { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = PositionToEnd_IndexObj::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_coerce_bytes.rs b/spec/rust/formats/process_coerce_bytes.rs new file mode 100644 index 000000000..26c30992c --- /dev/null +++ b/spec/rust/formats/process_coerce_bytes.rs @@ -0,0 +1,103 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceBytes { + pub records: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.records = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(records), _io, UserTypeInstream(List(record),None,List()), IntNum(2)) + // handleAssignmentRepeatExpr(NamedIdentifier(records), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +// extraAttrForIO(NamedIdentifier(buf_proc), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceBytes_Record { + pub flag: u8, + pub buf_unproc: Vec, + pub buf_proc: Vec, + pub raw_buf_proc: Vec, + pub buf: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceBytes_Record { + type Root = ProcessCoerceBytes; + type ParentStack = (&'r ProcessCoerceBytes, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.flag = _io.read_u1()?; + { + // condIfHeader(Compare(Name(identifier(flag)),Eq,IntNum(0))) + self.buf_unproc = _io.read_bytes(4 as usize)?.to_vec(); + } + { + // condIfHeader(Compare(Name(identifier(flag)),NotEq,IntNum(0))) + // attrProcess(ProcessXor(IntNum(170)), RawIdentifier(NamedIdentifier(buf_proc)), NamedIdentifier(buf_proc), NoRepeat) + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceBytes_Record { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceBytes_Record::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn buf( + &mut self, + _io: &'s S, + _root: Option<&'r ProcessCoerceBytes>, + _parent: Option>::ParentStack)>> + ) -> KResult<&Vec> { + if self.buf.is_some() { + return Ok(self.buf.as_ref().unwrap()); + } + self.buf = Some(if self.flag == 0 { self.buf_unproc } else { self.buf_proc} as Vec); + return Ok(self.buf.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/process_coerce_usertype1.rs b/spec/rust/formats/process_coerce_usertype1.rs new file mode 100644 index 000000000..c9e4d0050 --- /dev/null +++ b/spec/rust/formats/process_coerce_usertype1.rs @@ -0,0 +1,141 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceUsertype1 { + pub records: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype1 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.records = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(records), _io, UserTypeInstream(List(record),None,List()), IntNum(2)) + // handleAssignmentRepeatExpr(NamedIdentifier(records), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceUsertype1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceUsertype1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_unproc)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceUsertype1_Record { + pub flag: u8, + pub buf_unproc: Option, + pub buf_proc: Option, + pub raw_buf_unproc: Vec, + pub raw_buf_proc: Vec, + pub raw_raw_buf_proc: Vec, + pub buf: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype1_Record { + type Root = ProcessCoerceUsertype1; + type ParentStack = (&'r ProcessCoerceUsertype1, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.flag = _io.read_u1()?; + { + // condIfHeader(Compare(Name(identifier(flag)),Eq,IntNum(0))) + self.buf_unproc = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + } + { + // condIfHeader(Compare(Name(identifier(flag)),NotEq,IntNum(0))) + // attrProcess(ProcessXor(IntNum(170)), RawIdentifier(RawIdentifier(NamedIdentifier(buf_proc))), RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) + self.buf_proc = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceUsertype1_Record { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceUsertype1_Record::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn buf( + &mut self, + _io: &'s S, + _root: Option<&'r ProcessCoerceUsertype1>, + _parent: Option>::ParentStack)>> + ) -> KResult<&ProcessCoerceUsertype1_Foo> { + if self.buf.is_some() { + return Ok(self.buf.as_ref().unwrap()); + } + self.buf = Some(if self.flag == 0 { self.buf_unproc } else { self.buf_proc} as Foo); + return Ok(self.buf.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceUsertype1_Foo { + pub value: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype1_Foo { + type Root = ProcessCoerceUsertype1; + type ParentStack = (&'r ProcessCoerceUsertype1, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceUsertype1_Foo { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceUsertype1_Foo::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_coerce_usertype2.rs b/spec/rust/formats/process_coerce_usertype2.rs new file mode 100644 index 000000000..49bed3f23 --- /dev/null +++ b/spec/rust/formats/process_coerce_usertype2.rs @@ -0,0 +1,139 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceUsertype2 { + pub records: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.records = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(records), _io, UserTypeInstream(List(record),None,List()), IntNum(2)) + // handleAssignmentRepeatExpr(NamedIdentifier(records), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceUsertype2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceUsertype2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceUsertype2_Record { + pub flag: u8, + pub buf_unproc: Option, + pub buf_proc: Option, + pub raw_buf_proc: Vec, + pub raw_raw_buf_proc: Vec, + pub buf: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype2_Record { + type Root = ProcessCoerceUsertype2; + type ParentStack = (&'r ProcessCoerceUsertype2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.flag = _io.read_u1()?; + { + // condIfHeader(Compare(Name(identifier(flag)),Eq,IntNum(0))) + self.buf_unproc = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + } + { + // condIfHeader(Compare(Name(identifier(flag)),NotEq,IntNum(0))) + // attrProcess(ProcessXor(IntNum(170)), RawIdentifier(RawIdentifier(NamedIdentifier(buf_proc))), RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) + self.buf_proc = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceUsertype2_Record { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceUsertype2_Record::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn buf( + &mut self, + _io: &'s S, + _root: Option<&'r ProcessCoerceUsertype2>, + _parent: Option>::ParentStack)>> + ) -> KResult<&ProcessCoerceUsertype2_Foo> { + if self.buf.is_some() { + return Ok(self.buf.as_ref().unwrap()); + } + self.buf = Some(if self.flag == 0 { self.buf_unproc } else { self.buf_proc} as Foo); + return Ok(self.buf.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCoerceUsertype2_Foo { + pub value: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype2_Foo { + type Root = ProcessCoerceUsertype2; + type ParentStack = (&'r ProcessCoerceUsertype2, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCoerceUsertype2_Foo { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCoerceUsertype2_Foo::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_custom.rs b/spec/rust/formats/process_custom.rs new file mode 100644 index 000000000..844a8b4ad --- /dev/null +++ b/spec/rust/formats/process_custom.rs @@ -0,0 +1,53 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(buf1), NoRepeat) +// extraAttrForIO(NamedIdentifier(buf2), NoRepeat) +// extraAttrForIO(NamedIdentifier(buf3), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCustom { + pub buf1: Vec, + pub buf2: Vec, + pub key: u8, + pub buf3: Vec, + pub raw_buf1: Vec, + pub raw_buf2: Vec, + pub raw_buf3: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCustom { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + // attrProcess(ProcessCustom(List(my_custom_fx),ArrayBuffer(IntNum(7), Bool(true), List(ArrayBuffer(IntNum(32), IntNum(48), IntNum(64))))), RawIdentifier(NamedIdentifier(buf1)), NamedIdentifier(buf1), NoRepeat) + // attrProcess(ProcessCustom(List(nested, deeply, custom_fx),ArrayBuffer(IntNum(7))), RawIdentifier(NamedIdentifier(buf2)), NamedIdentifier(buf2), NoRepeat) + self.key = _io.read_u1()?; + // attrProcess(ProcessCustom(List(my_custom_fx),ArrayBuffer(Name(identifier(key)), Bool(false), List(ArrayBuffer(IntNum(0))))), RawIdentifier(NamedIdentifier(buf3)), NamedIdentifier(buf3), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCustom { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCustom::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_custom_no_args.rs b/spec/rust/formats/process_custom_no_args.rs new file mode 100644 index 000000000..415825d80 --- /dev/null +++ b/spec/rust/formats/process_custom_no_args.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(buf), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessCustomNoArgs { + pub buf: Vec, + pub raw_buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCustomNoArgs { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + // attrProcess(ProcessCustom(List(custom_fx_no_args),List()), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ProcessCustomNoArgs { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessCustomNoArgs::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_repeat_bytes.rs b/spec/rust/formats/process_repeat_bytes.rs new file mode 100644 index 000000000..8dc31fec0 --- /dev/null +++ b/spec/rust/formats/process_repeat_bytes.rs @@ -0,0 +1,48 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(bufs), RepeatExpr(IntNum(2))) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessRepeatBytes { + pub bufs: Vec>, + pub raw_bufs: Vec>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRepeatBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.bufs = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(bufs), _io, BytesLimitType(IntNum(5),None,false,None,Some(ProcessXor(IntNum(158)))), IntNum(2)) + // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(bufs)), _io.read_bytes(5 as usize)?) + // attrProcess(ProcessXor(IntNum(158)), RawIdentifier(NamedIdentifier(bufs)), NamedIdentifier(bufs), RepeatExpr(IntNum(2))) + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessRepeatBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessRepeatBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_repeat_usertype.rs b/spec/rust/formats/process_repeat_usertype.rs new file mode 100644 index 000000000..7256f775a --- /dev/null +++ b/spec/rust/formats/process_repeat_usertype.rs @@ -0,0 +1,86 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(blocks)), RepeatExpr(IntNum(2))) +// extraAttrForIO(RawIdentifier(NamedIdentifier(blocks)), RepeatExpr(IntNum(2))) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessRepeatUsertype { + pub blocks: Vec, + pub raw_blocks: Vec>, + pub raw_raw_blocks: Vec>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRepeatUsertype { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.blocks = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(blocks), _io, UserTypeFromBytes(List(block),None,List(),BytesLimitType(IntNum(5),None,false,None,Some(ProcessXor(IntNum(158)))),Some(ProcessXor(IntNum(158)))), IntNum(2)) + // handleAssignmentRepeatExpr(RawIdentifier(RawIdentifier(NamedIdentifier(blocks))), _io.read_bytes(5 as usize)?) + // attrProcess(ProcessXor(IntNum(158)), RawIdentifier(RawIdentifier(NamedIdentifier(blocks))), RawIdentifier(NamedIdentifier(blocks)), RepeatExpr(IntNum(2))) + // handleAssignmentRepeatExpr(NamedIdentifier(blocks), &BytesReader::new(_io.read_bytes(5 as usize)?)) + } + Ok(()) + } +} +impl<'r, 's: 'r> ProcessRepeatUsertype { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessRepeatUsertype::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessRepeatUsertype_Block { + pub a: i32, + pub b: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRepeatUsertype_Block { + type Root = ProcessRepeatUsertype; + type ParentStack = (&'r ProcessRepeatUsertype, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_s4le()?; + self.b = _io.read_s1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ProcessRepeatUsertype_Block { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessRepeatUsertype_Block::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_rotate.rs b/spec/rust/formats/process_rotate.rs new file mode 100644 index 000000000..d17b69b80 --- /dev/null +++ b/spec/rust/formats/process_rotate.rs @@ -0,0 +1,53 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(buf1), NoRepeat) +// extraAttrForIO(NamedIdentifier(buf2), NoRepeat) +// extraAttrForIO(NamedIdentifier(buf3), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessRotate { + pub buf1: Vec, + pub buf2: Vec, + pub key: u8, + pub buf3: Vec, + pub raw_buf1: Vec, + pub raw_buf2: Vec, + pub raw_buf3: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRotate { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + // attrProcess(ProcessRotate(true,IntNum(3)), RawIdentifier(NamedIdentifier(buf1)), NamedIdentifier(buf1), NoRepeat) + // attrProcess(ProcessRotate(false,IntNum(3)), RawIdentifier(NamedIdentifier(buf2)), NamedIdentifier(buf2), NoRepeat) + self.key = _io.read_u1()?; + // attrProcess(ProcessRotate(true,Name(identifier(key))), RawIdentifier(NamedIdentifier(buf3)), NamedIdentifier(buf3), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ProcessRotate { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessRotate::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_to_user.rs b/spec/rust/formats/process_to_user.rs new file mode 100644 index 000000000..45aa800bd --- /dev/null +++ b/spec/rust/formats/process_to_user.rs @@ -0,0 +1,79 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf1)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(buf1)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessToUser { + pub buf1: Option, + pub raw_buf1: Vec, + pub raw_raw_buf1: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessToUser { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + // attrProcess(ProcessRotate(true,IntNum(3)), RawIdentifier(RawIdentifier(NamedIdentifier(buf1))), RawIdentifier(NamedIdentifier(buf1)), NoRepeat) + self.buf1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(5 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> ProcessToUser { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessToUser::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessToUser_JustStr { + pub str: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessToUser_JustStr { + type Root = ProcessToUser; + type ParentStack = (&'r ProcessToUser, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.str = decode_string(_io.read_bytes_full()?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> ProcessToUser_JustStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessToUser_JustStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_xor4_const.rs b/spec/rust/formats/process_xor4_const.rs new file mode 100644 index 000000000..60f0a651e --- /dev/null +++ b/spec/rust/formats/process_xor4_const.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(buf), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessXor4Const { + pub key: Vec, + pub buf: Vec, + pub raw_buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXor4Const { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.key = _io.read_bytes(4 as usize)?.to_vec(); + // attrProcess(ProcessXor(List(ArrayBuffer(IntNum(236), IntNum(187), IntNum(163), IntNum(20)))), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ProcessXor4Const { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessXor4Const::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_xor4_value.rs b/spec/rust/formats/process_xor4_value.rs new file mode 100644 index 000000000..858cd36e1 --- /dev/null +++ b/spec/rust/formats/process_xor4_value.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(buf), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessXor4Value { + pub key: Vec, + pub buf: Vec, + pub raw_buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXor4Value { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.key = _io.read_bytes(4 as usize)?.to_vec(); + // attrProcess(ProcessXor(Name(identifier(key))), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ProcessXor4Value { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessXor4Value::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_xor_const.rs b/spec/rust/formats/process_xor_const.rs new file mode 100644 index 000000000..51ea1a7d7 --- /dev/null +++ b/spec/rust/formats/process_xor_const.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(buf), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessXorConst { + pub key: u8, + pub buf: Vec, + pub raw_buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXorConst { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.key = _io.read_u1()?; + // attrProcess(ProcessXor(IntNum(255)), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ProcessXorConst { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessXorConst::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/process_xor_value.rs b/spec/rust/formats/process_xor_value.rs new file mode 100644 index 000000000..535908a4d --- /dev/null +++ b/spec/rust/formats/process_xor_value.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(buf), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ProcessXorValue { + pub key: u8, + pub buf: Vec, + pub raw_buf: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXorValue { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.key = _io.read_u1()?; + // attrProcess(ProcessXor(Name(identifier(key))), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ProcessXorValue { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ProcessXorValue::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/recursive_one.rs b/spec/rust/formats/recursive_one.rs new file mode 100644 index 000000000..152188b6f --- /dev/null +++ b/spec/rust/formats/recursive_one.rs @@ -0,0 +1,106 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RecursiveOne { + pub one: u8, + pub next: Option, +} +#[derive(Debug, PartialEq)] +pub enum RecursiveOne_Next { + RecursiveOne(Box), + RecursiveOne_Fini(RecursiveOne_Fini), +} +impl From> for RecursiveOne_Next { + fn from(v: Box) -> Self { + Self::RecursiveOne(v) + } +} +impl From for RecursiveOne_Next { + fn from(v: RecursiveOne_Fini) -> Self { + Self::RecursiveOne_Fini(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for RecursiveOne { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = _io.read_u1()?; + match (self.one & 3) { + 0 => { + self.next = Some(Self::read_into::(_io)?.into()); + } + 1 => { + self.next = Some(Self::read_into::(_io)?.into()); + } + 2 => { + self.next = Some(Self::read_into::(_io)?.into()); + } + 3 => { + self.next = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> RecursiveOne { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RecursiveOne::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct RecursiveOne_Fini { + pub finisher: u16, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RecursiveOne_Fini { + type Root = RecursiveOne; + type ParentStack = (&'r RecursiveOne, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.finisher = _io.read_u2le()?; + Ok(()) + } +} +impl<'r, 's: 'r> RecursiveOne_Fini { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RecursiveOne_Fini::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_eos_bit.rs b/spec/rust/formats/repeat_eos_bit.rs new file mode 100644 index 000000000..538e3a47b --- /dev/null +++ b/spec/rust/formats/repeat_eos_bit.rs @@ -0,0 +1,47 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatEosBit { + pub nibbles: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosBit { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.nibbles = Vec::new(); + { + type ArrayElement = u64; + while !_io.is_eof() { + self.nibbles.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatEosBit { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatEosBit::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_eos_struct.rs b/spec/rust/formats/repeat_eos_struct.rs new file mode 100644 index 000000000..01fe73f0a --- /dev/null +++ b/spec/rust/formats/repeat_eos_struct.rs @@ -0,0 +1,82 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatEosStruct { + pub chunks: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosStruct { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.chunks = Vec::new(); + { + type ArrayElement = RepeatEosStruct_Chunk; + while !_io.is_eof() { + self.chunks.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatEosStruct { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatEosStruct::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatEosStruct_Chunk { + pub offset: u32, + pub len: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosStruct_Chunk { + type Root = RepeatEosStruct; + type ParentStack = (&'r RepeatEosStruct, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.offset = _io.read_u4le()?; + self.len = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> RepeatEosStruct_Chunk { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatEosStruct_Chunk::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_eos_u4.rs b/spec/rust/formats/repeat_eos_u4.rs new file mode 100644 index 000000000..7e14baaf2 --- /dev/null +++ b/spec/rust/formats/repeat_eos_u4.rs @@ -0,0 +1,47 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatEosU4 { + pub numbers: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosU4 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.numbers = Vec::new(); + { + type ArrayElement = u32; + while !_io.is_eof() { + self.numbers.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatEosU4 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatEosU4::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_n_struct.rs b/spec/rust/formats/repeat_n_struct.rs new file mode 100644 index 000000000..5420796b3 --- /dev/null +++ b/spec/rust/formats/repeat_n_struct.rs @@ -0,0 +1,82 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatNStruct { + pub qty: u32, + pub chunks: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStruct { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty = _io.read_u4le()?; + self.chunks = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(chunks), _io, UserTypeInstream(List(chunk),None,List()), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(chunks), Self::read_into::(_io, _root, _parent.push(self))?.into()) + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatNStruct { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatNStruct::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatNStruct_Chunk { + pub offset: u32, + pub len: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStruct_Chunk { + type Root = RepeatNStruct; + type ParentStack = (&'r RepeatNStruct, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.offset = _io.read_u4le()?; + self.len = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> RepeatNStruct_Chunk { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatNStruct_Chunk::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_n_strz.rs b/spec/rust/formats/repeat_n_strz.rs new file mode 100644 index 000000000..85969ae76 --- /dev/null +++ b/spec/rust/formats/repeat_n_strz.rs @@ -0,0 +1,47 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatNStrz { + pub qty: u32, + pub lines: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStrz { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty = _io.read_u4le()?; + self.lines = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(lines), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), Name(identifier(qty))) + // handleAssignmentRepeatExpr(NamedIdentifier(lines), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatNStrz { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatNStrz::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_n_strz_double.rs b/spec/rust/formats/repeat_n_strz_double.rs new file mode 100644 index 000000000..ef1a1a346 --- /dev/null +++ b/spec/rust/formats/repeat_n_strz_double.rs @@ -0,0 +1,53 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatNStrzDouble { + pub qty: u32, + pub lines1: Vec, + pub lines2: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStrzDouble { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.qty = _io.read_u4le()?; + self.lines1 = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(lines1), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), BinOp(Name(identifier(qty)),Div,IntNum(2))) + // handleAssignmentRepeatExpr(NamedIdentifier(lines1), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) + } + self.lines2 = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(lines2), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), BinOp(Name(identifier(qty)),Div,IntNum(2))) + // handleAssignmentRepeatExpr(NamedIdentifier(lines2), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatNStrzDouble { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatNStrzDouble::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_until_complex.rs b/spec/rust/formats/repeat_until_complex.rs new file mode 100644 index 000000000..2917034a9 --- /dev/null +++ b/spec/rust/formats/repeat_until_complex.rs @@ -0,0 +1,138 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatUntilComplex { + pub first: Vec, + pub second: Vec, + pub third: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilComplex { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.first = Vec::new(); + { + // condRepeatUntilHeader(NamedIdentifier(first), _io, UserTypeInstream(List(type_u1),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) + // handleAssignmentRepeatUntil(NamedIdentifier(first), Self::read_into::(_io, _root, _parent.push(self))?.into(), false) + // condRepeatUntilFooter(NamedIdentifier(first), _io, UserTypeInstream(List(type_u1),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) + } {} + self.second = Vec::new(); + { + // condRepeatUntilHeader(NamedIdentifier(second), _io, UserTypeInstream(List(type_u2),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) + // handleAssignmentRepeatUntil(NamedIdentifier(second), Self::read_into::(_io, _root, _parent.push(self))?.into(), false) + // condRepeatUntilFooter(NamedIdentifier(second), _io, UserTypeInstream(List(type_u2),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) + } {} + self.third = Vec::new(); + { + // condRepeatUntilHeader(NamedIdentifier(third), _io, Int1Type(false), Compare(Name(identifier(_)),Eq,IntNum(0))) + // handleAssignmentRepeatUntil(NamedIdentifier(third), _io.read_u1()?, false) + // condRepeatUntilFooter(NamedIdentifier(third), _io, Int1Type(false), Compare(Name(identifier(_)),Eq,IntNum(0))) + } {} + Ok(()) + } +} +impl<'r, 's: 'r> RepeatUntilComplex { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatUntilComplex::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatUntilComplex_TypeU1 { + pub count: u8, + pub values: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilComplex_TypeU1 { + type Root = RepeatUntilComplex; + type ParentStack = (&'r RepeatUntilComplex, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.count = _io.read_u1()?; + self.values = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(values), _io, Int1Type(false), Name(identifier(count))) + // handleAssignmentRepeatExpr(NamedIdentifier(values), _io.read_u1()?) + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatUntilComplex_TypeU1 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatUntilComplex_TypeU1::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatUntilComplex_TypeU2 { + pub count: u16, + pub values: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilComplex_TypeU2 { + type Root = RepeatUntilComplex; + type ParentStack = (&'r RepeatUntilComplex, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.count = _io.read_u2le()?; + self.values = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(values), _io, IntMultiType(false,Width2,Some(LittleEndian)), Name(identifier(count))) + // handleAssignmentRepeatExpr(NamedIdentifier(values), _io.read_u2le()?) + } + Ok(()) + } +} +impl<'r, 's: 'r> RepeatUntilComplex_TypeU2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatUntilComplex_TypeU2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_until_s4.rs b/spec/rust/formats/repeat_until_s4.rs new file mode 100644 index 000000000..e5b5cc99a --- /dev/null +++ b/spec/rust/formats/repeat_until_s4.rs @@ -0,0 +1,48 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatUntilS4 { + pub entries: Vec, + pub afterall: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilS4 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.entries = Vec::new(); + { + // condRepeatUntilHeader(NamedIdentifier(entries), _io, IntMultiType(true,Width4,Some(LittleEndian)), Compare(Name(identifier(_)),Eq,UnaryOp(Minus,IntNum(1)))) + // handleAssignmentRepeatUntil(NamedIdentifier(entries), _io.read_s4le()?, false) + // condRepeatUntilFooter(NamedIdentifier(entries), _io, IntMultiType(true,Width4,Some(LittleEndian)), Compare(Name(identifier(_)),Eq,UnaryOp(Minus,IntNum(1)))) + } {} + self.afterall = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> RepeatUntilS4 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatUntilS4::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/repeat_until_sized.rs b/spec/rust/formats/repeat_until_sized.rs new file mode 100644 index 000000000..5c830a964 --- /dev/null +++ b/spec/rust/formats/repeat_until_sized.rs @@ -0,0 +1,84 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(records)), RepeatUntil(Compare(Attribute(Name(identifier(_)),identifier(marker)),Eq,IntNum(170)))) + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatUntilSized { + pub records: Vec, + pub raw_records: Vec>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilSized { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.records = Vec::new(); + { + // condRepeatUntilHeader(NamedIdentifier(records), _io, UserTypeFromBytes(List(record),None,List(),BytesLimitType(IntNum(5),None,false,None,None),None), Compare(Attribute(Name(identifier(_)),identifier(marker)),Eq,IntNum(170))) + // handleAssignmentRepeatUntil(RawIdentifier(NamedIdentifier(records)), _io.read_bytes(5 as usize)?, true) + // handleAssignmentRepeatUntil(NamedIdentifier(records), &BytesReader::new(_io.read_bytes(5 as usize)?), false) + // condRepeatUntilFooter(NamedIdentifier(records), _io, UserTypeFromBytes(List(record),None,List(),BytesLimitType(IntNum(5),None,false,None,None),None), Compare(Attribute(Name(identifier(_)),identifier(marker)),Eq,IntNum(170))) + } {} + Ok(()) + } +} +impl<'r, 's: 'r> RepeatUntilSized { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatUntilSized::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct RepeatUntilSized_Record { + pub marker: u8, + pub body: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilSized_Record { + type Root = RepeatUntilSized; + type ParentStack = (&'r RepeatUntilSized, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.marker = _io.read_u1()?; + self.body = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> RepeatUntilSized_Record { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = RepeatUntilSized_Record::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/str_encodings.rs b/spec/rust/formats/str_encodings.rs new file mode 100644 index 000000000..a0b5c91bb --- /dev/null +++ b/spec/rust/formats/str_encodings.rs @@ -0,0 +1,55 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct StrEncodings { + pub len_of_1: u16, + pub str1: String, + pub len_of_2: u16, + pub str2: String, + pub len_of_3: u16, + pub str3: String, + pub len_of_4: u16, + pub str4: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodings { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_of_1 = _io.read_u2le()?; + self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "ASCII")?; + self.len_of_2 = _io.read_u2le()?; + self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; + self.len_of_3 = _io.read_u2le()?; + self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; + self.len_of_4 = _io.read_u2le()?; + self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; + Ok(()) + } +} +impl<'r, 's: 'r> StrEncodings { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrEncodings::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/str_encodings_default.rs b/spec/rust/formats/str_encodings_default.rs new file mode 100644 index 000000000..5258a526c --- /dev/null +++ b/spec/rust/formats/str_encodings_default.rs @@ -0,0 +1,88 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct StrEncodingsDefault { + pub len_of_1: u16, + pub str1: String, + pub rest: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsDefault { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_of_1 = _io.read_u2le()?; + self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "UTF-8")?; + self.rest = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> StrEncodingsDefault { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrEncodingsDefault::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct StrEncodingsDefault_Subtype { + pub len_of_2: u16, + pub str2: String, + pub len_of_3: u16, + pub str3: String, + pub len_of_4: u16, + pub str4: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsDefault_Subtype { + type Root = StrEncodingsDefault; + type ParentStack = (&'r StrEncodingsDefault, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_of_2 = _io.read_u2le()?; + self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; + self.len_of_3 = _io.read_u2le()?; + self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; + self.len_of_4 = _io.read_u2le()?; + self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; + Ok(()) + } +} +impl<'r, 's: 'r> StrEncodingsDefault_Subtype { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrEncodingsDefault_Subtype::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/str_encodings_utf16.rs b/spec/rust/formats/str_encodings_utf16.rs new file mode 100644 index 000000000..6b1c7def4 --- /dev/null +++ b/spec/rust/formats/str_encodings_utf16.rs @@ -0,0 +1,121 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(be_bom_removed)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(le_bom_removed)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct StrEncodingsUtf16 { + pub len_be: u32, + pub be_bom_removed: Option, + pub len_le: u32, + pub le_bom_removed: Option, + pub raw_be_bom_removed: Vec, + pub raw_le_bom_removed: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsUtf16 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_be = _io.read_u4le()?; + self.be_bom_removed = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len_be as usize)?), Some(self), _parent.push(self))?); + self.len_le = _io.read_u4le()?; + self.le_bom_removed = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len_le as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> StrEncodingsUtf16 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrEncodingsUtf16::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct StrEncodingsUtf16_StrBeBomRemoved { + pub bom: u16, + pub str: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsUtf16_StrBeBomRemoved { + type Root = StrEncodingsUtf16; + type ParentStack = (&'r StrEncodingsUtf16, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.bom = _io.read_u2be()?; + self.str = decode_string(_io.read_bytes_full()?, "UTF-16BE")?; + Ok(()) + } +} +impl<'r, 's: 'r> StrEncodingsUtf16_StrBeBomRemoved { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrEncodingsUtf16_StrBeBomRemoved::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct StrEncodingsUtf16_StrLeBomRemoved { + pub bom: u16, + pub str: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsUtf16_StrLeBomRemoved { + type Root = StrEncodingsUtf16; + type ParentStack = (&'r StrEncodingsUtf16, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.bom = _io.read_u2le()?; + self.str = decode_string(_io.read_bytes_full()?, "UTF-16LE")?; + Ok(()) + } +} +impl<'r, 's: 'r> StrEncodingsUtf16_StrLeBomRemoved { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrEncodingsUtf16_StrLeBomRemoved::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/str_eos.rs b/spec/rust/formats/str_eos.rs new file mode 100644 index 000000000..8eb6f220b --- /dev/null +++ b/spec/rust/formats/str_eos.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct StrEos { + pub str: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrEos { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.str = decode_string(_io.read_bytes_full()?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> StrEos { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrEos::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/str_literals.rs b/spec/rust/formats/str_literals.rs new file mode 100644 index 000000000..71e2e76fa --- /dev/null +++ b/spec/rust/formats/str_literals.rs @@ -0,0 +1,104 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct StrLiterals { + pub octal_eatup2: Option, + pub backslashes: Option, + pub octal_eatup: Option, + pub double_quotes: Option, + pub complex_str: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrLiterals { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> StrLiterals { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrLiterals::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn octal_eatup2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.octal_eatup2.is_some() { + return Ok(self.octal_eatup2.as_ref().unwrap()); + } + self.octal_eatup2 = Some("\u{2}2".to_string()); + return Ok(self.octal_eatup2.as_ref().unwrap()); + } + fn backslashes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.backslashes.is_some() { + return Ok(self.backslashes.as_ref().unwrap()); + } + self.backslashes = Some("\\\\\\".to_string()); + return Ok(self.backslashes.as_ref().unwrap()); + } + fn octal_eatup( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.octal_eatup.is_some() { + return Ok(self.octal_eatup.as_ref().unwrap()); + } + self.octal_eatup = Some("\u{0}22".to_string()); + return Ok(self.octal_eatup.as_ref().unwrap()); + } + fn double_quotes( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.double_quotes.is_some() { + return Ok(self.double_quotes.as_ref().unwrap()); + } + self.double_quotes = Some("\"\"\"".to_string()); + return Ok(self.double_quotes.as_ref().unwrap()); + } + fn complex_str( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.complex_str.is_some() { + return Ok(self.complex_str.as_ref().unwrap()); + } + self.complex_str = Some("\u{0}\u{1}\u{2}\u{7}\u{8}\n\r\t\u{b}\u{c}\u{1b}=\u{7}\n$\u{263b}".to_string()); + return Ok(self.complex_str.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/str_literals2.rs b/spec/rust/formats/str_literals2.rs new file mode 100644 index 000000000..338e684b1 --- /dev/null +++ b/spec/rust/formats/str_literals2.rs @@ -0,0 +1,91 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct StrLiterals2 { + pub dollar1: Option, + pub dollar2: Option, + pub hash: Option, + pub at_sign: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrLiterals2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> StrLiterals2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrLiterals2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn dollar1( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.dollar1.is_some() { + return Ok(self.dollar1.as_ref().unwrap()); + } + self.dollar1 = Some("$foo".to_string()); + return Ok(self.dollar1.as_ref().unwrap()); + } + fn dollar2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.dollar2.is_some() { + return Ok(self.dollar2.as_ref().unwrap()); + } + self.dollar2 = Some("${foo}".to_string()); + return Ok(self.dollar2.as_ref().unwrap()); + } + fn hash( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.hash.is_some() { + return Ok(self.hash.as_ref().unwrap()); + } + self.hash = Some("#{foo}".to_string()); + return Ok(self.hash.as_ref().unwrap()); + } + fn at_sign( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.at_sign.is_some() { + return Ok(self.at_sign.as_ref().unwrap()); + } + self.at_sign = Some("@foo".to_string()); + return Ok(self.at_sign.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/str_pad_term.rs b/spec/rust/formats/str_pad_term.rs new file mode 100644 index 000000000..c033ba432 --- /dev/null +++ b/spec/rust/formats/str_pad_term.rs @@ -0,0 +1,47 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct StrPadTerm { + pub str_pad: String, + pub str_term: String, + pub str_term_and_pad: String, + pub str_term_include: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrPadTerm { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.str_pad = decode_string(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 64), "UTF-8")?; + self.str_term = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, false), "UTF-8")?; + self.str_term_and_pad = decode_string(_io.bytes_terminate(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 43), 64, false), "UTF-8")?; + self.str_term_include = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, true), "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> StrPadTerm { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrPadTerm::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/str_pad_term_empty.rs b/spec/rust/formats/str_pad_term_empty.rs new file mode 100644 index 000000000..e241a4117 --- /dev/null +++ b/spec/rust/formats/str_pad_term_empty.rs @@ -0,0 +1,47 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct StrPadTermEmpty { + pub str_pad: String, + pub str_term: String, + pub str_term_and_pad: String, + pub str_term_include: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for StrPadTermEmpty { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.str_pad = decode_string(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 64), "UTF-8")?; + self.str_term = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, false), "UTF-8")?; + self.str_term_and_pad = decode_string(_io.bytes_terminate(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 43), 64, false), "UTF-8")?; + self.str_term_include = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, true), "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> StrPadTermEmpty { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = StrPadTermEmpty::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_bytearray.rs b/spec/rust/formats/switch_bytearray.rs new file mode 100644 index 000000000..7a2403b4a --- /dev/null +++ b/spec/rust/formats/switch_bytearray.rs @@ -0,0 +1,172 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchBytearray { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchBytearray_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchBytearray { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchBytearray::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchBytearray_Opcode { + pub code: Vec, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchBytearray_Opcode_Body { + SwitchBytearray_Opcode_Intval(SwitchBytearray_Opcode_Intval), + SwitchBytearray_Opcode_Strval(SwitchBytearray_Opcode_Strval), +} +impl From for SwitchBytearray_Opcode_Body { + fn from(v: SwitchBytearray_Opcode_Intval) -> Self { + Self::SwitchBytearray_Opcode_Intval(v) + } +} +impl From for SwitchBytearray_Opcode_Body { + fn from(v: SwitchBytearray_Opcode_Strval) -> Self { + Self::SwitchBytearray_Opcode_Strval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray_Opcode { + type Root = SwitchBytearray; + type ParentStack = (&'r SwitchBytearray, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_bytes(1 as usize)?.to_vec(); + { + let on = &self.code; + if on == &[0x49] { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + else if on == &[0x53] { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchBytearray_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchBytearray_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchBytearray_Opcode_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray_Opcode_Intval { + type Root = SwitchBytearray; + type ParentStack = (&'r SwitchBytearray_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchBytearray_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchBytearray_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchBytearray_Opcode_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray_Opcode_Strval { + type Root = SwitchBytearray; + type ParentStack = (&'r SwitchBytearray_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchBytearray_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchBytearray_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_cast.rs b/spec/rust/formats/switch_cast.rs new file mode 100644 index 000000000..366d238af --- /dev/null +++ b/spec/rust/formats/switch_cast.rs @@ -0,0 +1,211 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchCast { + pub opcodes: Vec, + pub first_obj: Option, + pub second_val: Option, + pub err_cast: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchCast_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchCast { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchCast::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn first_obj( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&SwitchCast_Strval> { + if self.first_obj.is_some() { + return Ok(self.first_obj.as_ref().unwrap()); + } + self.first_obj = Some(self.opcodes[0 as usize].body as SwitchCast_Strval); + return Ok(self.first_obj.as_ref().unwrap()); + } + fn second_val( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.second_val.is_some() { + return Ok(self.second_val.as_ref().unwrap()); + } + self.second_val = Some(self.opcodes[1 as usize].body.value as u8); + return Ok(self.second_val.as_ref().unwrap()); + } + fn err_cast( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&SwitchCast_Strval> { + if self.err_cast.is_some() { + return Ok(self.err_cast.as_ref().unwrap()); + } + self.err_cast = Some(self.opcodes[2 as usize].body as SwitchCast_Strval); + return Ok(self.err_cast.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchCast_Opcode { + pub code: u8, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchCast_Opcode_Body { + SwitchCast_Intval(SwitchCast_Intval), + SwitchCast_Strval(SwitchCast_Strval), +} +impl From for SwitchCast_Opcode_Body { + fn from(v: SwitchCast_Intval) -> Self { + Self::SwitchCast_Intval(v) + } +} +impl From for SwitchCast_Opcode_Body { + fn from(v: SwitchCast_Strval) -> Self { + Self::SwitchCast_Strval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast_Opcode { + type Root = SwitchCast; + type ParentStack = (&'r SwitchCast, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + match self.code { + 73 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + 83 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchCast_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchCast_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchCast_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast_Intval { + type Root = SwitchCast; + type ParentStack = (&'r SwitchCast, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchCast_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchCast_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchCast_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast_Strval { + type Root = SwitchCast; + type ParentStack = (&'r SwitchCast, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchCast_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchCast_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_else_only.rs b/spec/rust/formats/switch_else_only.rs new file mode 100644 index 000000000..3ebcc4b83 --- /dev/null +++ b/spec/rust/formats/switch_else_only.rs @@ -0,0 +1,100 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchElseOnly { + pub opcode: i8, + pub prim_byte: Option, + pub indicator: Vec, + pub ut: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchElseOnly_PrimByte { + S1(i8), +} +impl From for SwitchElseOnly_PrimByte { + fn from(v: i8) -> Self { + Self::S1(v) + } +} + +#[derive(Debug, PartialEq)] +pub enum SwitchElseOnly_Ut { + SwitchElseOnly_Data(SwitchElseOnly_Data), +} +impl From for SwitchElseOnly_Ut { + fn from(v: SwitchElseOnly_Data) -> Self { + Self::SwitchElseOnly_Data(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchElseOnly { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcode = _io.read_s1()?; + self.prim_byte = Some(_io.read_s1()?); + self.indicator = _io.read_bytes(4 as usize)?.to_vec(); + self.ut = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + Ok(()) + } +} +impl<'r, 's: 'r> SwitchElseOnly { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchElseOnly::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchElseOnly_Data { + pub value: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchElseOnly_Data { + type Root = SwitchElseOnly; + type ParentStack = (&'r SwitchElseOnly, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_bytes(4 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> SwitchElseOnly_Data { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchElseOnly_Data::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_integers.rs b/spec/rust/formats/switch_integers.rs new file mode 100644 index 000000000..26c040c4f --- /dev/null +++ b/spec/rust/formats/switch_integers.rs @@ -0,0 +1,124 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchIntegers { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchIntegers { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchIntegers_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchIntegers { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchIntegers::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchIntegers_Opcode { + pub code: u8, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchIntegers_Opcode_Body { + U1(u8), + U2(u16), + U4(u32), + U8(u64), +} +impl From for SwitchIntegers_Opcode_Body { + fn from(v: u8) -> Self { + Self::U1(v) + } +} +impl From for SwitchIntegers_Opcode_Body { + fn from(v: u16) -> Self { + Self::U2(v) + } +} +impl From for SwitchIntegers_Opcode_Body { + fn from(v: u32) -> Self { + Self::U4(v) + } +} +impl From for SwitchIntegers_Opcode_Body { + fn from(v: u64) -> Self { + Self::U8(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchIntegers_Opcode { + type Root = SwitchIntegers; + type ParentStack = (&'r SwitchIntegers, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + match self.code { + 1 => { + self.body = Some(_io.read_u1()?); + } + 2 => { + self.body = Some(_io.read_u2le()?); + } + 4 => { + self.body = Some(_io.read_u4le()?); + } + 8 => { + self.body = Some(_io.read_u8le()?); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchIntegers_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchIntegers_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_integers2.rs b/spec/rust/formats/switch_integers2.rs new file mode 100644 index 000000000..64aff3d30 --- /dev/null +++ b/spec/rust/formats/switch_integers2.rs @@ -0,0 +1,105 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchIntegers2 { + pub code: u8, + pub len: Option, + pub ham: Vec, + pub padding: u8, + pub len_mod_str: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchIntegers2_Len { + U1(u8), + U2(u16), + U4(u32), + U8(u64), +} +impl From for SwitchIntegers2_Len { + fn from(v: u8) -> Self { + Self::U1(v) + } +} +impl From for SwitchIntegers2_Len { + fn from(v: u16) -> Self { + Self::U2(v) + } +} +impl From for SwitchIntegers2_Len { + fn from(v: u32) -> Self { + Self::U4(v) + } +} +impl From for SwitchIntegers2_Len { + fn from(v: u64) -> Self { + Self::U8(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchIntegers2 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + match self.code { + 1 => { + self.len = Some(_io.read_u1()?); + } + 2 => { + self.len = Some(_io.read_u2le()?); + } + 4 => { + self.len = Some(_io.read_u4le()?); + } + 8 => { + self.len = Some(_io.read_u8le()?); + } + _ => panic!("unhandled value") + } + self.ham = _io.read_bytes(self.len as usize)?.to_vec(); + { + // condIfHeader(Compare(Name(identifier(len)),Gt,IntNum(3))) + self.padding = _io.read_u1()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchIntegers2 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchIntegers2::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn len_mod_str( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&String> { + if self.len_mod_str.is_some() { + return Ok(self.len_mod_str.as_ref().unwrap()); + } + self.len_mod_str = Some(((self.len * 2) - 1).to_string().to_string()); + return Ok(self.len_mod_str.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/switch_manual_enum.rs b/spec/rust/formats/switch_manual_enum.rs new file mode 100644 index 000000000..d36b58fc6 --- /dev/null +++ b/spec/rust/formats/switch_manual_enum.rs @@ -0,0 +1,188 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnum { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchManualEnum_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnum { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnum::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnum_Opcode { + pub code: Option, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualEnum_Opcode_Body { + SwitchManualEnum_Opcode_Intval(SwitchManualEnum_Opcode_Intval), + SwitchManualEnum_Opcode_Strval(SwitchManualEnum_Opcode_Strval), +} +impl From for SwitchManualEnum_Opcode_Body { + fn from(v: SwitchManualEnum_Opcode_Intval) -> Self { + Self::SwitchManualEnum_Opcode_Intval(v) + } +} +impl From for SwitchManualEnum_Opcode_Body { + fn from(v: SwitchManualEnum_Opcode_Strval) -> Self { + Self::SwitchManualEnum_Opcode_Strval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum_Opcode { + type Root = SwitchManualEnum; + type ParentStack = (&'r SwitchManualEnum, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = Some((_io.read_u1()? as i64).try_into()?); + match self.code { + SwitchManualEnum_Opcode_CodeEnum::Intval => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + SwitchManualEnum_Opcode_CodeEnum::Strval => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnum_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnum_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualEnum_Opcode_CodeEnum { + Intval, + Strval, +} +impl TryFrom for SwitchManualEnum_Opcode_CodeEnum { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 73 => Ok(SwitchManualEnum_Opcode_CodeEnum::Intval), + 83 => Ok(SwitchManualEnum_Opcode_CodeEnum::Strval), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnum_Opcode_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum_Opcode_Intval { + type Root = SwitchManualEnum; + type ParentStack = (&'r SwitchManualEnum_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnum_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnum_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnum_Opcode_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum_Opcode_Strval { + type Root = SwitchManualEnum; + type ParentStack = (&'r SwitchManualEnum_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnum_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnum_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_manual_enum_invalid.rs b/spec/rust/formats/switch_manual_enum_invalid.rs new file mode 100644 index 000000000..2d419998e --- /dev/null +++ b/spec/rust/formats/switch_manual_enum_invalid.rs @@ -0,0 +1,188 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalid { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchManualEnumInvalid_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnumInvalid { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalid::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalid_Opcode { + pub code: Option, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualEnumInvalid_Opcode_Body { + SwitchManualEnumInvalid_Opcode_Intval(SwitchManualEnumInvalid_Opcode_Intval), + SwitchManualEnumInvalid_Opcode_Strval(SwitchManualEnumInvalid_Opcode_Strval), +} +impl From for SwitchManualEnumInvalid_Opcode_Body { + fn from(v: SwitchManualEnumInvalid_Opcode_Intval) -> Self { + Self::SwitchManualEnumInvalid_Opcode_Intval(v) + } +} +impl From for SwitchManualEnumInvalid_Opcode_Body { + fn from(v: SwitchManualEnumInvalid_Opcode_Strval) -> Self { + Self::SwitchManualEnumInvalid_Opcode_Strval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid_Opcode { + type Root = SwitchManualEnumInvalid; + type ParentStack = (&'r SwitchManualEnumInvalid, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = Some((_io.read_u1()? as i64).try_into()?); + match self.code { + SwitchManualEnumInvalid_Opcode_CodeEnum::Intval => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + SwitchManualEnumInvalid_Opcode_CodeEnum::Strval => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnumInvalid_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalid_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualEnumInvalid_Opcode_CodeEnum { + Intval, + Strval, +} +impl TryFrom for SwitchManualEnumInvalid_Opcode_CodeEnum { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 73 => Ok(SwitchManualEnumInvalid_Opcode_CodeEnum::Intval), + 83 => Ok(SwitchManualEnumInvalid_Opcode_CodeEnum::Strval), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalid_Opcode_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid_Opcode_Intval { + type Root = SwitchManualEnumInvalid; + type ParentStack = (&'r SwitchManualEnumInvalid_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnumInvalid_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalid_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalid_Opcode_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid_Opcode_Strval { + type Root = SwitchManualEnumInvalid; + type ParentStack = (&'r SwitchManualEnumInvalid_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnumInvalid_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalid_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_manual_enum_invalid_else.rs b/spec/rust/formats/switch_manual_enum_invalid_else.rs new file mode 100644 index 000000000..aef7b2440 --- /dev/null +++ b/spec/rust/formats/switch_manual_enum_invalid_else.rs @@ -0,0 +1,241 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalidElse { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchManualEnumInvalidElse_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualEnumInvalidElse { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalidElse::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalidElse_Opcode { + pub code: Option, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualEnumInvalidElse_Opcode_Body { + SwitchManualEnumInvalidElse_Opcode_Intval(SwitchManualEnumInvalidElse_Opcode_Intval), + SwitchManualEnumInvalidElse_Opcode_Strval(SwitchManualEnumInvalidElse_Opcode_Strval), + SwitchManualEnumInvalidElse_Opcode_Defval(SwitchManualEnumInvalidElse_Opcode_Defval), +} +impl From for SwitchManualEnumInvalidElse_Opcode_Body { + fn from(v: SwitchManualEnumInvalidElse_Opcode_Intval) -> Self { + Self::SwitchManualEnumInvalidElse_Opcode_Intval(v) + } +} +impl From for SwitchManualEnumInvalidElse_Opcode_Body { + fn from(v: SwitchManualEnumInvalidElse_Opcode_Strval) -> Self { + Self::SwitchManualEnumInvalidElse_Opcode_Strval(v) + } +} +impl From for SwitchManualEnumInvalidElse_Opcode_Body { + fn from(v: SwitchManualEnumInvalidElse_Opcode_Defval) -> Self { + Self::SwitchManualEnumInvalidElse_Opcode_Defval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode { + type Root = SwitchManualEnumInvalidElse; + type ParentStack = (&'r SwitchManualEnumInvalidElse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = Some((_io.read_u1()? as i64).try_into()?); + match self.code { + SwitchManualEnumInvalidElse_Opcode_CodeEnum::Intval => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + SwitchManualEnumInvalidElse_Opcode_CodeEnum::Strval => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + // switchElseStart() + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalidElse_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualEnumInvalidElse_Opcode_CodeEnum { +Intval, +Strval, +} +impl TryFrom for SwitchManualEnumInvalidElse_Opcode_CodeEnum { +type Error = KError; +fn try_from(flag: i64) -> KResult { + match flag { + 73 => Ok(SwitchManualEnumInvalidElse_Opcode_CodeEnum::Intval), + 83 => Ok(SwitchManualEnumInvalidElse_Opcode_CodeEnum::Strval), + _ => Err(KError::UnknownVariant(flag)), + } +} +} + + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalidElse_Opcode_Intval { +pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode_Intval { +type Root = SwitchManualEnumInvalidElse; +type ParentStack = (&'r SwitchManualEnumInvalidElse_Opcode, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalidElse_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalidElse_Opcode_Strval { +pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode_Strval { +type Root = SwitchManualEnumInvalidElse; +type ParentStack = (&'r SwitchManualEnumInvalidElse_Opcode, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalidElse_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualEnumInvalidElse_Opcode_Defval { +pub value: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode_Defval { +type Root = SwitchManualEnumInvalidElse; +type ParentStack = (&'r SwitchManualEnumInvalidElse_Opcode, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode_Defval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualEnumInvalidElse_Opcode_Defval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +fn value( + &mut self, + _io: &'s S, + _root: Option<&'r SwitchManualEnumInvalidElse>, + _parent: Option>::ParentStack)>> +) -> KResult<&i8> { + if self.value.is_some() { + return Ok(self.value.as_ref().unwrap()); + } + self.value = Some(123 as i8); + return Ok(self.value.as_ref().unwrap()); +} +} diff --git a/spec/rust/formats/switch_manual_int.rs b/spec/rust/formats/switch_manual_int.rs new file mode 100644 index 000000000..3bba746ac --- /dev/null +++ b/spec/rust/formats/switch_manual_int.rs @@ -0,0 +1,172 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualInt { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchManualInt_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualInt { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualInt::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualInt_Opcode { + pub code: u8, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualInt_Opcode_Body { + SwitchManualInt_Opcode_Intval(SwitchManualInt_Opcode_Intval), + SwitchManualInt_Opcode_Strval(SwitchManualInt_Opcode_Strval), +} +impl From for SwitchManualInt_Opcode_Body { + fn from(v: SwitchManualInt_Opcode_Intval) -> Self { + Self::SwitchManualInt_Opcode_Intval(v) + } +} +impl From for SwitchManualInt_Opcode_Body { + fn from(v: SwitchManualInt_Opcode_Strval) -> Self { + Self::SwitchManualInt_Opcode_Strval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt_Opcode { + type Root = SwitchManualInt; + type ParentStack = (&'r SwitchManualInt, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + match self.code { + 73 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + 83 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualInt_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualInt_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualInt_Opcode_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt_Opcode_Intval { + type Root = SwitchManualInt; + type ParentStack = (&'r SwitchManualInt_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualInt_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualInt_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualInt_Opcode_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt_Opcode_Strval { + type Root = SwitchManualInt; + type ParentStack = (&'r SwitchManualInt_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualInt_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualInt_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_manual_int_else.rs b/spec/rust/formats/switch_manual_int_else.rs new file mode 100644 index 000000000..65e2b4b0e --- /dev/null +++ b/spec/rust/formats/switch_manual_int_else.rs @@ -0,0 +1,214 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntElse { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchManualIntElse_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualIntElse { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntElse::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntElse_Opcode { + pub code: u8, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualIntElse_Opcode_Body { + SwitchManualIntElse_Opcode_Intval(SwitchManualIntElse_Opcode_Intval), + SwitchManualIntElse_Opcode_Strval(SwitchManualIntElse_Opcode_Strval), + SwitchManualIntElse_Opcode_Noneval(SwitchManualIntElse_Opcode_Noneval), +} +impl From for SwitchManualIntElse_Opcode_Body { + fn from(v: SwitchManualIntElse_Opcode_Intval) -> Self { + Self::SwitchManualIntElse_Opcode_Intval(v) + } +} +impl From for SwitchManualIntElse_Opcode_Body { + fn from(v: SwitchManualIntElse_Opcode_Strval) -> Self { + Self::SwitchManualIntElse_Opcode_Strval(v) + } +} +impl From for SwitchManualIntElse_Opcode_Body { + fn from(v: SwitchManualIntElse_Opcode_Noneval) -> Self { + Self::SwitchManualIntElse_Opcode_Noneval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode { + type Root = SwitchManualIntElse; + type ParentStack = (&'r SwitchManualIntElse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + match self.code { + 73 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + 83 => { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + // switchElseStart() + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + _ => panic!("unhandled value") + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntElse_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntElse_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntElse_Opcode_Intval { +pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode_Intval { +type Root = SwitchManualIntElse; +type ParentStack = (&'r SwitchManualIntElse_Opcode, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntElse_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntElse_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntElse_Opcode_Strval { +pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode_Strval { +type Root = SwitchManualIntElse; +type ParentStack = (&'r SwitchManualIntElse_Opcode, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntElse_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntElse_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntElse_Opcode_Noneval { +pub filler: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode_Noneval { +type Root = SwitchManualIntElse; +type ParentStack = (&'r SwitchManualIntElse_Opcode, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.filler = _io.read_u4le()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntElse_Opcode_Noneval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntElse_Opcode_Noneval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_manual_int_size.rs b/spec/rust/formats/switch_manual_int_size.rs new file mode 100644 index 000000000..1a5b425de --- /dev/null +++ b/spec/rust/formats/switch_manual_int_size.rs @@ -0,0 +1,194 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSize { + pub chunks: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.chunks = Vec::new(); + { + type ArrayElement = SwitchManualIntSize_Chunk; + while !_io.is_eof() { + self.chunks.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualIntSize { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSize::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSize_Chunk { + pub code: u8, + pub size: u32, + pub body: Option, + pub raw_body: Vec, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualIntSize_Chunk_Body { + SwitchManualIntSize_Chunk_ChunkMeta(SwitchManualIntSize_Chunk_ChunkMeta), + SwitchManualIntSize_Chunk_ChunkDir(SwitchManualIntSize_Chunk_ChunkDir), + Bytes(Vec), +} +impl From for SwitchManualIntSize_Chunk_Body { + fn from(v: SwitchManualIntSize_Chunk_ChunkMeta) -> Self { + Self::SwitchManualIntSize_Chunk_ChunkMeta(v) + } +} +impl From for SwitchManualIntSize_Chunk_Body { + fn from(v: SwitchManualIntSize_Chunk_ChunkDir) -> Self { + Self::SwitchManualIntSize_Chunk_ChunkDir(v) + } +} +impl From> for SwitchManualIntSize_Chunk_Body { + fn from(v: Vec) -> Self { + Self::Bytes(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize_Chunk { + type Root = SwitchManualIntSize; + type ParentStack = (&'r SwitchManualIntSize, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + self.size = _io.read_u4le()?; + match self.code { + 17 => { + self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); + } + 34 => { + self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); + } + // switchElseStart() + self.body = Some(_io.read_bytes(self.size as usize)?); + } + _ => panic!("unhandled value") + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntSize_Chunk { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSize_Chunk::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSize_Chunk_ChunkMeta { +pub title: String, +pub author: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize_Chunk_ChunkMeta { +type Root = SwitchManualIntSize; +type ParentStack = (&'r SwitchManualIntSize_Chunk, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.title = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; + self.author = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntSize_Chunk_ChunkMeta { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSize_Chunk_ChunkMeta::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSize_Chunk_ChunkDir { +pub entries: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize_Chunk_ChunkDir { +type Root = SwitchManualIntSize; +type ParentStack = (&'r SwitchManualIntSize_Chunk, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.entries = Vec::new(); + { + type ArrayElement = String; + while !_io.is_eof() { + self.entries.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntSize_Chunk_ChunkDir { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSize_Chunk_ChunkDir::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_manual_int_size_else.rs b/spec/rust/formats/switch_manual_int_size_else.rs new file mode 100644 index 000000000..ee2b6b45d --- /dev/null +++ b/spec/rust/formats/switch_manual_int_size_else.rs @@ -0,0 +1,228 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSizeElse { + pub chunks: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.chunks = Vec::new(); + { + type ArrayElement = SwitchManualIntSizeElse_Chunk; + while !_io.is_eof() { + self.chunks.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualIntSizeElse { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSizeElse::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSizeElse_Chunk { + pub code: u8, + pub size: u32, + pub body: Option, + pub raw_body: Vec, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualIntSizeElse_Chunk_Body { + SwitchManualIntSizeElse_Chunk_ChunkMeta(SwitchManualIntSizeElse_Chunk_ChunkMeta), + SwitchManualIntSizeElse_Chunk_ChunkDir(SwitchManualIntSizeElse_Chunk_ChunkDir), + SwitchManualIntSizeElse_Chunk_Dummy(SwitchManualIntSizeElse_Chunk_Dummy), +} +impl From for SwitchManualIntSizeElse_Chunk_Body { + fn from(v: SwitchManualIntSizeElse_Chunk_ChunkMeta) -> Self { + Self::SwitchManualIntSizeElse_Chunk_ChunkMeta(v) + } +} +impl From for SwitchManualIntSizeElse_Chunk_Body { + fn from(v: SwitchManualIntSizeElse_Chunk_ChunkDir) -> Self { + Self::SwitchManualIntSizeElse_Chunk_ChunkDir(v) + } +} +impl From for SwitchManualIntSizeElse_Chunk_Body { + fn from(v: SwitchManualIntSizeElse_Chunk_Dummy) -> Self { + Self::SwitchManualIntSizeElse_Chunk_Dummy(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk { + type Root = SwitchManualIntSizeElse; + type ParentStack = (&'r SwitchManualIntSizeElse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + self.size = _io.read_u4le()?; + match self.code { + 17 => { + self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); + } + 34 => { + self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); + } + // switchElseStart() + self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); + } + _ => panic!("unhandled value") + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSizeElse_Chunk::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSizeElse_Chunk_ChunkMeta { +pub title: String, +pub author: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk_ChunkMeta { +type Root = SwitchManualIntSizeElse; +type ParentStack = (&'r SwitchManualIntSizeElse_Chunk, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.title = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; + self.author = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk_ChunkMeta { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSizeElse_Chunk_ChunkMeta::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSizeElse_Chunk_ChunkDir { +pub entries: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk_ChunkDir { +type Root = SwitchManualIntSizeElse; +type ParentStack = (&'r SwitchManualIntSizeElse_Chunk, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.entries = Vec::new(); + { + type ArrayElement = String; + while !_io.is_eof() { + self.entries.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk_ChunkDir { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSizeElse_Chunk_ChunkDir::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualIntSizeElse_Chunk_Dummy { +pub rest: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk_Dummy { +type Root = SwitchManualIntSizeElse; +type ParentStack = (&'r SwitchManualIntSizeElse_Chunk, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.rest = _io.read_bytes_full()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk_Dummy { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualIntSizeElse_Chunk_Dummy::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_manual_str.rs b/spec/rust/formats/switch_manual_str.rs new file mode 100644 index 000000000..45bba2750 --- /dev/null +++ b/spec/rust/formats/switch_manual_str.rs @@ -0,0 +1,172 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStr { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchManualStr_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStr_Opcode { + pub code: String, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualStr_Opcode_Body { + SwitchManualStr_Opcode_Intval(SwitchManualStr_Opcode_Intval), + SwitchManualStr_Opcode_Strval(SwitchManualStr_Opcode_Strval), +} +impl From for SwitchManualStr_Opcode_Body { + fn from(v: SwitchManualStr_Opcode_Intval) -> Self { + Self::SwitchManualStr_Opcode_Intval(v) + } +} +impl From for SwitchManualStr_Opcode_Body { + fn from(v: SwitchManualStr_Opcode_Strval) -> Self { + Self::SwitchManualStr_Opcode_Strval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr_Opcode { + type Root = SwitchManualStr; + type ParentStack = (&'r SwitchManualStr, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = decode_string(_io.read_bytes(1 as usize)?, "ASCII")?; + { + let on = &self.code; + if on == "I" { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + else if on == "S" { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStr_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStr_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStr_Opcode_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr_Opcode_Intval { + type Root = SwitchManualStr; + type ParentStack = (&'r SwitchManualStr_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStr_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStr_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStr_Opcode_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr_Opcode_Strval { + type Root = SwitchManualStr; + type ParentStack = (&'r SwitchManualStr_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStr_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStr_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_manual_str_else.rs b/spec/rust/formats/switch_manual_str_else.rs new file mode 100644 index 000000000..0a2763e0b --- /dev/null +++ b/spec/rust/formats/switch_manual_str_else.rs @@ -0,0 +1,214 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStrElse { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchManualStrElse_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStrElse { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStrElse::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStrElse_Opcode { + pub code: String, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchManualStrElse_Opcode_Body { + SwitchManualStrElse_Opcode_Intval(SwitchManualStrElse_Opcode_Intval), + SwitchManualStrElse_Opcode_Strval(SwitchManualStrElse_Opcode_Strval), + SwitchManualStrElse_Opcode_Noneval(SwitchManualStrElse_Opcode_Noneval), +} +impl From for SwitchManualStrElse_Opcode_Body { + fn from(v: SwitchManualStrElse_Opcode_Intval) -> Self { + Self::SwitchManualStrElse_Opcode_Intval(v) + } +} +impl From for SwitchManualStrElse_Opcode_Body { + fn from(v: SwitchManualStrElse_Opcode_Strval) -> Self { + Self::SwitchManualStrElse_Opcode_Strval(v) + } +} +impl From for SwitchManualStrElse_Opcode_Body { + fn from(v: SwitchManualStrElse_Opcode_Noneval) -> Self { + Self::SwitchManualStrElse_Opcode_Noneval(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode { + type Root = SwitchManualStrElse; + type ParentStack = (&'r SwitchManualStrElse, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = decode_string(_io.read_bytes(1 as usize)?, "ASCII")?; + { + let on = &self.code; + if on == "I" { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + else if on == "S" { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + else { + self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStrElse_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStrElse_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStrElse_Opcode_Intval { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode_Intval { + type Root = SwitchManualStrElse; + type ParentStack = (&'r SwitchManualStrElse_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStrElse_Opcode_Intval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStrElse_Opcode_Intval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStrElse_Opcode_Strval { + pub value: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode_Strval { + type Root = SwitchManualStrElse; + type ParentStack = (&'r SwitchManualStrElse_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStrElse_Opcode_Strval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStrElse_Opcode_Strval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchManualStrElse_Opcode_Noneval { + pub filler: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode_Noneval { + type Root = SwitchManualStrElse; + type ParentStack = (&'r SwitchManualStrElse_Opcode, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.filler = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> SwitchManualStrElse_Opcode_Noneval { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchManualStrElse_Opcode_Noneval::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_multi_bool_ops.rs b/spec/rust/formats/switch_multi_bool_ops.rs new file mode 100644 index 000000000..275402c8e --- /dev/null +++ b/spec/rust/formats/switch_multi_bool_ops.rs @@ -0,0 +1,124 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchMultiBoolOps { + pub opcodes: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchMultiBoolOps { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.opcodes = Vec::new(); + { + type ArrayElement = SwitchMultiBoolOps_Opcode; + while !_io.is_eof() { + self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); + } + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchMultiBoolOps { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchMultiBoolOps::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchMultiBoolOps_Opcode { + pub code: u8, + pub body: Option, +} +#[derive(Debug, PartialEq)] +pub enum SwitchMultiBoolOps_Opcode_Body { + U1(u8), + U2(u16), + U4(u32), + U8(u64), +} +impl From for SwitchMultiBoolOps_Opcode_Body { + fn from(v: u8) -> Self { + Self::U1(v) + } +} +impl From for SwitchMultiBoolOps_Opcode_Body { + fn from(v: u16) -> Self { + Self::U2(v) + } +} +impl From for SwitchMultiBoolOps_Opcode_Body { + fn from(v: u32) -> Self { + Self::U4(v) + } +} +impl From for SwitchMultiBoolOps_Opcode_Body { + fn from(v: u64) -> Self { + Self::U8(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchMultiBoolOps_Opcode { + type Root = SwitchMultiBoolOps; + type ParentStack = (&'r SwitchMultiBoolOps, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + match if ((self.code > 0) && (self.code <= 8) && (if self.code != 10 { true } else { false})) { self.code } else { 0} { + 1 => { + self.body = Some(_io.read_u1()?); + } + 2 => { + self.body = Some(_io.read_u2le()?); + } + 4 => { + self.body = Some(_io.read_u4le()?); + } + 8 => { + self.body = Some(_io.read_u8le()?); + } + _ => panic!("unhandled value") + } + Ok(()) + } +} +impl<'r, 's: 'r> SwitchMultiBoolOps_Opcode { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchMultiBoolOps_Opcode::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_repeat_expr.rs b/spec/rust/formats/switch_repeat_expr.rs new file mode 100644 index 000000000..2a389aefc --- /dev/null +++ b/spec/rust/formats/switch_repeat_expr.rs @@ -0,0 +1,153 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchRepeatExpr { + pub code: u8, + pub size: u32, + pub body: Vec, + pub raw_body: Vec>, +} +#[derive(Debug, PartialEq)] +pub enum SwitchRepeatExpr_Body { + SwitchRepeatExpr_One(SwitchRepeatExpr_One), + SwitchRepeatExpr_Two(SwitchRepeatExpr_Two), + Bytes(Vec), +} +impl From for SwitchRepeatExpr_Body { + fn from(v: SwitchRepeatExpr_One) -> Self { + Self::SwitchRepeatExpr_One(v) + } +} +impl From for SwitchRepeatExpr_Body { + fn from(v: SwitchRepeatExpr_Two) -> Self { + Self::SwitchRepeatExpr_Two(v) + } +} +impl From> for SwitchRepeatExpr_Body { + fn from(v: Vec) -> Self { + Self::Bytes(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExpr { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + self.size = _io.read_u4le()?; + self.body = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(body), _io, SwitchType(Name(identifier(code)),Map(IntNum(17) -> UserTypeFromBytes(List(one),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), IntNum(34) -> UserTypeFromBytes(List(two),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), Name(identifier(_)) -> BytesLimitType(Name(identifier(size)),None,false,None,None)),true), IntNum(1)) + match self.code { + 17 => { + // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) + // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) + } + 34 => { + // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) + // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) + } + // switchElseStart() + // handleAssignmentRepeatExpr(NamedIdentifier(body), _io.read_bytes(self.size as usize)?) + } + _ => panic!("unhandled value") + } + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchRepeatExpr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchRepeatExpr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchRepeatExpr_One { +pub first: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExpr_One { +type Root = SwitchRepeatExpr; +type ParentStack = (&'r SwitchRepeatExpr, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.first = _io.read_bytes_full()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchRepeatExpr_One { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchRepeatExpr_One::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchRepeatExpr_Two { +pub second: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExpr_Two { +type Root = SwitchRepeatExpr; +type ParentStack = (&'r SwitchRepeatExpr, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.second = _io.read_bytes_full()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchRepeatExpr_Two { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchRepeatExpr_Two::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/switch_repeat_expr_invalid.rs b/spec/rust/formats/switch_repeat_expr_invalid.rs new file mode 100644 index 000000000..fcd70b5e3 --- /dev/null +++ b/spec/rust/formats/switch_repeat_expr_invalid.rs @@ -0,0 +1,153 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) +// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchRepeatExprInvalid { + pub code: u8, + pub size: u32, + pub body: Vec, + pub raw_body: Vec>, +} +#[derive(Debug, PartialEq)] +pub enum SwitchRepeatExprInvalid_Body { + SwitchRepeatExprInvalid_One(SwitchRepeatExprInvalid_One), + SwitchRepeatExprInvalid_Two(SwitchRepeatExprInvalid_Two), + Bytes(Vec), +} +impl From for SwitchRepeatExprInvalid_Body { + fn from(v: SwitchRepeatExprInvalid_One) -> Self { + Self::SwitchRepeatExprInvalid_One(v) + } +} +impl From for SwitchRepeatExprInvalid_Body { + fn from(v: SwitchRepeatExprInvalid_Two) -> Self { + Self::SwitchRepeatExprInvalid_Two(v) + } +} +impl From> for SwitchRepeatExprInvalid_Body { + fn from(v: Vec) -> Self { + Self::Bytes(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExprInvalid { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.code = _io.read_u1()?; + self.size = _io.read_u4le()?; + self.body = Vec::new(); + { + // condRepeatExprHeader(NamedIdentifier(body), _io, SwitchType(Name(identifier(code)),Map(IntNum(255) -> UserTypeFromBytes(List(one),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), IntNum(34) -> UserTypeFromBytes(List(two),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), Name(identifier(_)) -> BytesLimitType(Name(identifier(size)),None,false,None,None)),true), IntNum(1)) + match self.code { + 255 => { + // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) + // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) + } + 34 => { + // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) + // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) + } + // switchElseStart() + // handleAssignmentRepeatExpr(NamedIdentifier(body), _io.read_bytes(self.size as usize)?) + } + _ => panic!("unhandled value") + } + } + Ok(()) +} +} +impl<'r, 's: 'r> SwitchRepeatExprInvalid { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchRepeatExprInvalid::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchRepeatExprInvalid_One { +pub first: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExprInvalid_One { +type Root = SwitchRepeatExprInvalid; +type ParentStack = (&'r SwitchRepeatExprInvalid, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.first = _io.read_bytes_full()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchRepeatExprInvalid_One { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchRepeatExprInvalid_One::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct SwitchRepeatExprInvalid_Two { +pub second: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExprInvalid_Two { +type Root = SwitchRepeatExprInvalid; +type ParentStack = (&'r SwitchRepeatExprInvalid, >::ParentStack); + +fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> +) -> KResult<()> { + self.second = _io.read_bytes_full()?; + Ok(()) +} +} +impl<'r, 's: 'r> SwitchRepeatExprInvalid_Two { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = SwitchRepeatExprInvalid_Two::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/term_bytes.rs b/spec/rust/formats/term_bytes.rs new file mode 100644 index 000000000..c567a6eaf --- /dev/null +++ b/spec/rust/formats/term_bytes.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct TermBytes { + pub s1: Vec, + pub s2: Vec, + pub s3: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TermBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.s1 = _io.read_bytes_term(124, false, true, true)?; + self.s2 = _io.read_bytes_term(124, false, false, true)?; + self.s3 = _io.read_bytes_term(64, true, true, true)?; + Ok(()) + } +} +impl<'r, 's: 'r> TermBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TermBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/term_strz.rs b/spec/rust/formats/term_strz.rs new file mode 100644 index 000000000..d1526e2f3 --- /dev/null +++ b/spec/rust/formats/term_strz.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct TermStrz { + pub s1: String, + pub s2: String, + pub s3: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TermStrz { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; + self.s2 = decode_string(_io.read_bytes_term(124, false, false, true)?, "UTF-8")?; + self.s3 = decode_string(_io.read_bytes_term(64, true, true, true)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> TermStrz { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TermStrz::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/term_u1_val.rs b/spec/rust/formats/term_u1_val.rs new file mode 100644 index 000000000..c8222135e --- /dev/null +++ b/spec/rust/formats/term_u1_val.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct TermU1Val { + pub foo: Vec, + pub bar: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TermU1Val { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_bytes_term(227, false, false, true)?; + self.bar = decode_string(_io.read_bytes_term(171, true, true, true)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> TermU1Val { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TermU1Val::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/to_string_custom.rs b/spec/rust/formats/to_string_custom.rs new file mode 100644 index 000000000..e70fe052b --- /dev/null +++ b/spec/rust/formats/to_string_custom.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ToStringCustom { + pub s1: String, + pub s2: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ToStringCustom { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; + self.s2 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; + Ok(()) + } +} +impl<'r, 's: 'r> ToStringCustom { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ToStringCustom::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/ts_packet_header.rs b/spec/rust/formats/ts_packet_header.rs new file mode 100644 index 000000000..a679ba5f8 --- /dev/null +++ b/spec/rust/formats/ts_packet_header.rs @@ -0,0 +1,79 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// universalDoc() + +#[derive(Default, Debug, PartialEq)] +pub struct TsPacketHeader { + pub sync_byte: u8, + pub transport_error_indicator: bool, + pub payload_unit_start_indicator: bool, + pub transport_priority: bool, + pub pid: u64, + pub transport_scrambling_control: u64, + pub adaptation_field_control: Option, + pub continuity_counter: u64, + pub ts_packet_remain: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TsPacketHeader { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.sync_byte = _io.read_u1()?; + self.transport_error_indicator = _io.read_bits_int(1)? != 0; + self.payload_unit_start_indicator = _io.read_bits_int(1)? != 0; + self.transport_priority = _io.read_bits_int(1)? != 0; + self.pid = _io.read_bits_int(13)?; + self.transport_scrambling_control = _io.read_bits_int(2)?; + self.adaptation_field_control = Some((_io.read_bits_int(2)? as i64).try_into()?); + self.continuity_counter = _io.read_bits_int(4)?; + _io.align_to_byte()?; + self.ts_packet_remain = _io.read_bytes(184 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> TsPacketHeader { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TsPacketHeader::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} +#[derive(Debug, PartialEq)] +pub enum TsPacketHeader_AdaptationFieldControlEnum { + Reserved, + PayloadOnly, + AdaptationFieldOnly, + AdaptationFieldAndPayload, +} +impl TryFrom for TsPacketHeader_AdaptationFieldControlEnum { + type Error = KError; + fn try_from(flag: i64) -> KResult { + match flag { + 0 => Ok(TsPacketHeader_AdaptationFieldControlEnum::Reserved), + 1 => Ok(TsPacketHeader_AdaptationFieldControlEnum::PayloadOnly), + 2 => Ok(TsPacketHeader_AdaptationFieldControlEnum::AdaptationFieldOnly), + 3 => Ok(TsPacketHeader_AdaptationFieldControlEnum::AdaptationFieldAndPayload), + _ => Err(KError::UnknownVariant(flag)), + } + } +} + diff --git a/spec/rust/formats/type_int_unary_op.rs b/spec/rust/formats/type_int_unary_op.rs new file mode 100644 index 000000000..30b542525 --- /dev/null +++ b/spec/rust/formats/type_int_unary_op.rs @@ -0,0 +1,69 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct TypeIntUnaryOp { + pub value_s2: i16, + pub value_s8: i64, + pub unary_s2: Option, + pub unary_s8: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TypeIntUnaryOp { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value_s2 = _io.read_s2le()?; + self.value_s8 = _io.read_s8le()?; + Ok(()) + } +} +impl<'r, 's: 'r> TypeIntUnaryOp { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TypeIntUnaryOp::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn unary_s2( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.unary_s2.is_some() { + return Ok(self.unary_s2.as_ref().unwrap()); + } + self.unary_s2 = Some(-(self.value_s2) as i32); + return Ok(self.unary_s2.as_ref().unwrap()); + } + fn unary_s8( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i64> { + if self.unary_s8.is_some() { + return Ok(self.unary_s8.as_ref().unwrap()); + } + self.unary_s8 = Some(-(self.value_s8) as i64); + return Ok(self.unary_s8.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/type_ternary.rs b/spec/rust/formats/type_ternary.rs new file mode 100644 index 000000000..7968f844a --- /dev/null +++ b/spec/rust/formats/type_ternary.rs @@ -0,0 +1,125 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_wo_hack)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct TypeTernary { + pub dif_wo_hack: Option, + pub dif_with_hack: Option, + pub raw_dif_wo_hack: Vec, + pub raw_dif_with_hack: Vec, + pub raw_raw_dif_with_hack: Vec, + pub is_hack: Option, + pub dif: Option, + pub dif_value: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TypeTernary { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + { + // condIfHeader(UnaryOp(Not,Name(identifier(is_hack)))) + self.dif_wo_hack = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(1 as usize)?), Some(self), _parent.push(self))?); + } + // attrProcess(ProcessXor(IntNum(3)), RawIdentifier(RawIdentifier(NamedIdentifier(dif_with_hack))), RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) + self.dif_with_hack = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(1 as usize)?), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> TypeTernary { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TypeTernary::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn is_hack( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_hack.is_some() { + return Ok(self.is_hack.as_ref().unwrap()); + } + self.is_hack = Some(true as bool); + return Ok(self.is_hack.as_ref().unwrap()); + } + fn dif( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&TypeTernary_Dummy> { + if self.dif.is_some() { + return Ok(self.dif.as_ref().unwrap()); + } + self.dif = Some(if !(self.is_hack(_io, _root, _parent)?) { self.dif_wo_hack } else { self.dif_with_hack} as Dummy); + return Ok(self.dif.as_ref().unwrap()); + } + fn dif_value( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.dif_value.is_some() { + return Ok(self.dif_value.as_ref().unwrap()); + } + self.dif_value = Some(self.dif(_io, _root, _parent)?.value as u8); + return Ok(self.dif_value.as_ref().unwrap()); + } +} + +#[derive(Default, Debug, PartialEq)] +pub struct TypeTernary_Dummy { + pub value: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TypeTernary_Dummy { + type Root = TypeTernary; + type ParentStack = (&'r TypeTernary, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.value = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> TypeTernary_Dummy { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TypeTernary_Dummy::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/type_ternary_opaque.rs b/spec/rust/formats/type_ternary_opaque.rs new file mode 100644 index 000000000..b134dd440 --- /dev/null +++ b/spec/rust/formats/type_ternary_opaque.rs @@ -0,0 +1,83 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +use crate::term_strz::TermStrz; +// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_wo_hack)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct TypeTernaryOpaque { + pub dif_wo_hack: Option>, + pub dif_with_hack: Option>, + pub raw_dif_wo_hack: Vec, + pub raw_dif_with_hack: Vec, + pub raw_raw_dif_with_hack: Vec, + pub is_hack: Option, + pub dif: Option>, +} +impl<'r, 's: 'r> KStruct<'r, 's> for TypeTernaryOpaque { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + { + // condIfHeader(UnaryOp(Not,Name(identifier(is_hack)))) + self.dif_wo_hack = Some(Self::read_into::>(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); + } + { + // condIfHeader(Name(identifier(is_hack))) + // attrProcess(ProcessXor(IntNum(3)), RawIdentifier(RawIdentifier(NamedIdentifier(dif_with_hack))), RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) + self.dif_with_hack = Some(Self::read_into::>(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); + } + Ok(()) + } +} +impl<'r, 's: 'r> TypeTernaryOpaque { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = TypeTernaryOpaque::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn is_hack( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&bool> { + if self.is_hack.is_some() { + return Ok(self.is_hack.as_ref().unwrap()); + } + self.is_hack = Some(false as bool); + return Ok(self.is_hack.as_ref().unwrap()); + } + fn dif( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&Box> { + if self.dif.is_some() { + return Ok(self.dif.as_ref().unwrap()); + } + self.dif = Some(if !(self.is_hack(_io, _root, _parent)?) { self.dif_wo_hack } else { self.dif_with_hack} as TermStrz); + return Ok(self.dif.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/user_type.rs b/spec/rust/formats/user_type.rs new file mode 100644 index 000000000..44b64cc42 --- /dev/null +++ b/spec/rust/formats/user_type.rs @@ -0,0 +1,76 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct UserType { + pub one: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for UserType { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.one = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); + Ok(()) + } +} +impl<'r, 's: 'r> UserType { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = UserType::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct UserType_Header { + pub width: u32, + pub height: u32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for UserType_Header { + type Root = UserType; + type ParentStack = (&'r UserType, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.width = _io.read_u4le()?; + self.height = _io.read_u4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> UserType_Header { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = UserType_Header::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_eq_str_encodings.rs b/spec/rust/formats/valid_eq_str_encodings.rs new file mode 100644 index 000000000..f908fc4d3 --- /dev/null +++ b/spec/rust/formats/valid_eq_str_encodings.rs @@ -0,0 +1,55 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidEqStrEncodings { + pub len_of_1: u16, + pub str1: String, + pub len_of_2: u16, + pub str2: String, + pub len_of_3: u16, + pub str3: String, + pub len_of_4: u16, + pub str4: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidEqStrEncodings { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.len_of_1 = _io.read_u2le()?; + self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "ASCII")?; + self.len_of_2 = _io.read_u2le()?; + self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; + self.len_of_3 = _io.read_u2le()?; + self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; + self.len_of_4 = _io.read_u2le()?; + self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidEqStrEncodings { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidEqStrEncodings::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_anyof_int.rs b/spec/rust/formats/valid_fail_anyof_int.rs new file mode 100644 index 000000000..d306a99db --- /dev/null +++ b/spec/rust/formats/valid_fail_anyof_int.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailAnyofInt { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailAnyofInt { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailAnyofInt { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailAnyofInt::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_contents.rs b/spec/rust/formats/valid_fail_contents.rs new file mode 100644 index 000000000..9a5ec2f8d --- /dev/null +++ b/spec/rust/formats/valid_fail_contents.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailContents { + pub foo: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailContents { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_bytes(2 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailContents { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailContents::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_eq_bytes.rs b/spec/rust/formats/valid_fail_eq_bytes.rs new file mode 100644 index 000000000..b03f9a0c5 --- /dev/null +++ b/spec/rust/formats/valid_fail_eq_bytes.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailEqBytes { + pub foo: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailEqBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_bytes(2 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailEqBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailEqBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_eq_int.rs b/spec/rust/formats/valid_fail_eq_int.rs new file mode 100644 index 000000000..6e6026394 --- /dev/null +++ b/spec/rust/formats/valid_fail_eq_int.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailEqInt { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailEqInt { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailEqInt { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailEqInt::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_eq_str.rs b/spec/rust/formats/valid_fail_eq_str.rs new file mode 100644 index 000000000..ea4d91eac --- /dev/null +++ b/spec/rust/formats/valid_fail_eq_str.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailEqStr { + pub foo: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailEqStr { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailEqStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailEqStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_expr.rs b/spec/rust/formats/valid_fail_expr.rs new file mode 100644 index 000000000..78c34b34b --- /dev/null +++ b/spec/rust/formats/valid_fail_expr.rs @@ -0,0 +1,45 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailExpr { + pub foo: u8, + pub bar: i16, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailExpr { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + u8 tmpa = foo(); + self.bar = _io.read_s2le()?; + i16 tmpa = bar(); + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailExpr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailExpr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_inst.rs b/spec/rust/formats/valid_fail_inst.rs new file mode 100644 index 000000000..1179bcf37 --- /dev/null +++ b/spec/rust/formats/valid_fail_inst.rs @@ -0,0 +1,59 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailInst { + pub a: u8, + pub inst: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailInst { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + { + // condIfHeader(Compare(Name(identifier(inst)),GtE,IntNum(0))) + self.a = _io.read_u1()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailInst { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailInst::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn inst( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&u8> { + if self.inst.is_some() { + return Ok(self.inst.as_ref().unwrap()); + } + // pushPos(_io) + // seek(_io, IntNum(5)) + // popPos(_io) + return Ok(self.inst.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/valid_fail_max_int.rs b/spec/rust/formats/valid_fail_max_int.rs new file mode 100644 index 000000000..c15405b57 --- /dev/null +++ b/spec/rust/formats/valid_fail_max_int.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailMaxInt { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailMaxInt { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailMaxInt { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailMaxInt::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_min_int.rs b/spec/rust/formats/valid_fail_min_int.rs new file mode 100644 index 000000000..8c2f00308 --- /dev/null +++ b/spec/rust/formats/valid_fail_min_int.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailMinInt { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailMinInt { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailMinInt { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailMinInt::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_range_bytes.rs b/spec/rust/formats/valid_fail_range_bytes.rs new file mode 100644 index 000000000..9124ee3cb --- /dev/null +++ b/spec/rust/formats/valid_fail_range_bytes.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailRangeBytes { + pub foo: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeBytes { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_bytes(2 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailRangeBytes { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailRangeBytes::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_range_float.rs b/spec/rust/formats/valid_fail_range_float.rs new file mode 100644 index 000000000..26e1a161e --- /dev/null +++ b/spec/rust/formats/valid_fail_range_float.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailRangeFloat { + pub foo: f32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeFloat { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_f4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailRangeFloat { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailRangeFloat::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_range_int.rs b/spec/rust/formats/valid_fail_range_int.rs new file mode 100644 index 000000000..84eb7daf5 --- /dev/null +++ b/spec/rust/formats/valid_fail_range_int.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailRangeInt { + pub foo: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeInt { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = _io.read_u1()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailRangeInt { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailRangeInt::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_fail_range_str.rs b/spec/rust/formats/valid_fail_range_str.rs new file mode 100644 index 000000000..44185d6e5 --- /dev/null +++ b/spec/rust/formats/valid_fail_range_str.rs @@ -0,0 +1,41 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidFailRangeStr { + pub foo: String, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeStr { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.foo = decode_string(_io.read_bytes(2 as usize)?, "ASCII")?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidFailRangeStr { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidFailRangeStr::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_long.rs b/spec/rust/formats/valid_long.rs new file mode 100644 index 000000000..5a8f88554 --- /dev/null +++ b/spec/rust/formats/valid_long.rs @@ -0,0 +1,61 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidLong { + pub magic1: Vec, + pub uint8: u8, + pub sint8: i8, + pub magic_uint: String, + pub uint16: u16, + pub uint32: u32, + pub uint64: u64, + pub magic_sint: String, + pub sint16: i16, + pub sint32: i32, + pub sint64: i64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidLong { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); + self.uint8 = _io.read_u1()?; + self.sint8 = _io.read_s1()?; + self.magic_uint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; + self.uint16 = _io.read_u2le()?; + self.uint32 = _io.read_u4le()?; + self.uint64 = _io.read_u8le()?; + self.magic_sint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; + self.sint16 = _io.read_s2le()?; + self.sint32 = _io.read_s4le()?; + self.sint64 = _io.read_s8le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidLong { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidLong::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_not_parsed_if.rs b/spec/rust/formats/valid_not_parsed_if.rs new file mode 100644 index 000000000..8d36ef739 --- /dev/null +++ b/spec/rust/formats/valid_not_parsed_if.rs @@ -0,0 +1,49 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidNotParsedIf { + pub not_parsed: u8, + pub parsed: u8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidNotParsedIf { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + { + // condIfHeader(Bool(false)) + self.not_parsed = _io.read_u1()?; + } + { + // condIfHeader(Bool(true)) + self.parsed = _io.read_u1()?; + } + Ok(()) + } +} +impl<'r, 's: 'r> ValidNotParsedIf { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidNotParsedIf::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_optional_id.rs b/spec/rust/formats/valid_optional_id.rs new file mode 100644 index 000000000..4feab7cad --- /dev/null +++ b/spec/rust/formats/valid_optional_id.rs @@ -0,0 +1,46 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidOptionalId { + pub _unnamed0: Vec, + pub _unnamed1: u8, + pub _unnamed2: i8, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidOptionalId { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self._unnamed0 = _io.read_bytes(6 as usize)?.to_vec(); + self._unnamed1 = _io.read_u1()?; + self._unnamed2 = _io.read_s1()?; + i8 tmpa = _unnamed2(); + Ok(()) + } +} +impl<'r, 's: 'r> ValidOptionalId { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidOptionalId::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_short.rs b/spec/rust/formats/valid_short.rs new file mode 100644 index 000000000..7a26e0f8a --- /dev/null +++ b/spec/rust/formats/valid_short.rs @@ -0,0 +1,61 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidShort { + pub magic1: Vec, + pub uint8: u8, + pub sint8: i8, + pub magic_uint: String, + pub uint16: u16, + pub uint32: u32, + pub uint64: u64, + pub magic_sint: String, + pub sint16: i16, + pub sint32: i32, + pub sint64: i64, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ValidShort { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); + self.uint8 = _io.read_u1()?; + self.sint8 = _io.read_s1()?; + self.magic_uint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; + self.uint16 = _io.read_u2le()?; + self.uint32 = _io.read_u4le()?; + self.uint64 = _io.read_u8le()?; + self.magic_sint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; + self.sint16 = _io.read_s2le()?; + self.sint32 = _io.read_s4le()?; + self.sint64 = _io.read_s8le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ValidShort { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidShort::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/valid_switch.rs b/spec/rust/formats/valid_switch.rs new file mode 100644 index 000000000..17c5528c3 --- /dev/null +++ b/spec/rust/formats/valid_switch.rs @@ -0,0 +1,67 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct ValidSwitch { + pub a: u8, + pub b: Option, +} +#[derive(Debug, PartialEq)] +pub enum ValidSwitch_B { + U2(u16), + U2(u16), +} +impl From for ValidSwitch_B { + fn from(v: u16) -> Self { + Self::U2(v) + } +} +impl From for ValidSwitch_B { + fn from(v: u16) -> Self { + Self::U2(v) + } +} + +impl<'r, 's: 'r> KStruct<'r, 's> for ValidSwitch { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.a = _io.read_u1()?; + match self.a { + 80 => { + self.b = Some(_io.read_u2le()?); + } + // switchElseStart() + self.b = Some(_io.read_u2be()?); + } + _ => panic!("unhandled value") + } + Ok(()) +} +} +impl<'r, 's: 'r> ValidSwitch { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ValidSwitch::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/yaml_ints.rs b/spec/rust/formats/yaml_ints.rs new file mode 100644 index 000000000..eafdb6777 --- /dev/null +++ b/spec/rust/formats/yaml_ints.rs @@ -0,0 +1,91 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; + +#[derive(Default, Debug, PartialEq)] +pub struct YamlInts { + pub test_u4_dec: Option, + pub test_u4_hex: Option, + pub test_u8_dec: Option, + pub test_u8_hex: Option, +} +impl<'r, 's: 'r> KStruct<'r, 's> for YamlInts { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + Ok(()) + } +} +impl<'r, 's: 'r> YamlInts { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = YamlInts::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + + fn test_u4_dec( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.test_u4_dec.is_some() { + return Ok(self.test_u4_dec.as_ref().unwrap()); + } + self.test_u4_dec = Some(4294967295 as i32); + return Ok(self.test_u4_dec.as_ref().unwrap()); + } + fn test_u4_hex( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.test_u4_hex.is_some() { + return Ok(self.test_u4_hex.as_ref().unwrap()); + } + self.test_u4_hex = Some(4294967295 as i32); + return Ok(self.test_u4_hex.as_ref().unwrap()); + } + fn test_u8_dec( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.test_u8_dec.is_some() { + return Ok(self.test_u8_dec.as_ref().unwrap()); + } + self.test_u8_dec = Some(18446744073709551615 as i32); + return Ok(self.test_u8_dec.as_ref().unwrap()); + } + fn test_u8_hex( + &mut self, + _io: &'s S, + _root: Option<&'r Self>, + _parent: Option> + ) -> KResult<&i32> { + if self.test_u8_hex.is_some() { + return Ok(self.test_u8_hex.as_ref().unwrap()); + } + self.test_u8_hex = Some(18446744073709551615 as i32); + return Ok(self.test_u8_hex.as_ref().unwrap()); + } +} diff --git a/spec/rust/formats/zlib_surrounded.rs b/spec/rust/formats/zlib_surrounded.rs new file mode 100644 index 000000000..7591b1032 --- /dev/null +++ b/spec/rust/formats/zlib_surrounded.rs @@ -0,0 +1,83 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(RawIdentifier(NamedIdentifier(zlib)), NoRepeat) +// extraAttrForIO(RawIdentifier(NamedIdentifier(zlib)), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ZlibSurrounded { + pub pre: Vec, + pub zlib: Option, + pub post: Vec, + pub raw_zlib: Vec, + pub raw_raw_zlib: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ZlibSurrounded { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.pre = _io.read_bytes(4 as usize)?.to_vec(); + // attrProcess(ProcessZlib, RawIdentifier(RawIdentifier(NamedIdentifier(zlib))), RawIdentifier(NamedIdentifier(zlib)), NoRepeat) + self.zlib = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); + self.post = _io.read_bytes(4 as usize)?.to_vec(); + Ok(()) + } +} +impl<'r, 's: 'r> ZlibSurrounded { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ZlibSurrounded::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} + +#[derive(Default, Debug, PartialEq)] +pub struct ZlibSurrounded_Inflated { + pub num: i32, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ZlibSurrounded_Inflated { + type Root = ZlibSurrounded; + type ParentStack = (&'r ZlibSurrounded, >::ParentStack); + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + self.num = _io.read_s4le()?; + Ok(()) + } +} +impl<'r, 's: 'r> ZlibSurrounded_Inflated { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ZlibSurrounded_Inflated::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} diff --git a/spec/rust/formats/zlib_with_header_78.rs b/spec/rust/formats/zlib_with_header_78.rs new file mode 100644 index 000000000..803fea25c --- /dev/null +++ b/spec/rust/formats/zlib_with_header_78.rs @@ -0,0 +1,43 @@ +// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild + +#![allow(unused_imports)] +#![allow(non_snake_case)] +#![allow(non_camel_case_types)] + +use kaitai::*; +use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; +// extraAttrForIO(NamedIdentifier(data), NoRepeat) + +#[derive(Default, Debug, PartialEq)] +pub struct ZlibWithHeader78 { + pub data: Vec, + pub raw_data: Vec, +} +impl<'r, 's: 'r> KStruct<'r, 's> for ZlibWithHeader78 { + type Root = Self; + type ParentStack = KStructUnit; + + fn read( + &mut self, + _io: &'s S, + _root: Option<&'r Self::Root>, + _parent: Option> + ) -> KResult<()> { + // attrProcess(ProcessZlib, RawIdentifier(NamedIdentifier(data)), NamedIdentifier(data), NoRepeat) + Ok(()) + } +} +impl<'r, 's: 'r> ZlibWithHeader78 { + pub fn from_file(path: &str) -> Self { + let bytes = fs::read(path).unwrap(); + let reader = BytesReader::new(&bytes); + let mut obj = ZlibWithHeader78::default(); + + if let Err(err) = obj.read(&reader, None, None) { + panic!("error '{:?}' reading from file '{}'", err, path); + } + + obj + } + +} From 8d92a837962c379bb8ab910c2da6e9449dd703d7 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Thu, 21 Jul 2022 21:51:20 +0200 Subject: [PATCH 003/198] runParseExpectError, finish_panic --- .../specgenerators/RustSG.scala | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 5cff6e73e..7a0f635af 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -1,7 +1,7 @@ package io.kaitai.struct.testtranslator.specgenerators import _root_.io.kaitai.struct.{ClassTypeProvider, RuntimeConfig} -import _root_.io.kaitai.struct.datatype.DataType +import _root_.io.kaitai.struct.datatype.{DataType, KSError} import _root_.io.kaitai.struct.datatype.DataType._ import _root_.io.kaitai.struct.exprlang.Ast import _root_.io.kaitai.struct.languages.RustCompiler @@ -11,6 +11,7 @@ import _root_.io.kaitai.struct.translators.RustTranslator class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(spec) { val className = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) + var do_panic = true; override def fileName(name: String): String = s"test_$name.rs" @@ -19,10 +20,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( s""" |#[cfg(test)] |mod tests { - | extern crate kaitai_struct; | use std::fs; | - | use kaitai_struct::*; + | use kaitai::*; | use crate::rust::${spec.id}::*; | | #[test] @@ -31,14 +31,46 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( | let mut reader = BytesReader::new(&bytes); | let mut r = $className::default(); | - | r.read(&mut reader, None, None).unwrap(); - |""".stripMargin + | if let Err(err) = r.read(&mut reader, None, None) {""".stripMargin out.puts(code) out.inc out.inc } + override def runParseExpectError(exception: KSError): Unit = { + val code = + s""" println!("err: {:?}, exception: ${exception}", err); + | } else { + | panic!("no expected exception: ${exception}"); + | } + | + |""".stripMargin + + out.puts(code) + do_panic = false + // out.puts("err = r.Read(s, &r, &r)") +// out.puts("switch v := err.(type) {") +// out.puts(s"case ${errorName}:") +// out.inc +// out.puts("break") +// out.dec +// out.puts("default:") +// out.inc +// out.puts("t.Fatalf(\"expected " + errorName + ", got %T\", v)") +// out.dec +// out.puts("}") + } + + def finish_panic(): Unit = { + if (do_panic) { + out.inc + out.puts("panic!(\"{:?}\", err);") + out.dec + out.puts("}") + do_panic = false + } + } override def footer(): Unit = { out.dec out.puts("}") @@ -52,11 +84,13 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( if (expStr.toLowerCase.startsWith("enum")) { expStr = s"Some($expStr)" } + finish_panic() out.puts(s"assert_eq!($actStr, $expStr);") } override def nullAssert(actual: Ast.expr): Unit = { val actStr = translateAct(actual) + finish_panic() out.puts(s"assertNull($actStr);") // TODO: Figure out what's meant to happen here } From ed9d309a04ddb0b35fab3f62c13f2cb9b8695604 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Thu, 21 Jul 2022 21:52:17 +0200 Subject: [PATCH 004/198] genereated from .kst --- spec/rust/test_bcd_user_type_be.rs | 20 +++++++++++ spec/rust/test_bcd_user_type_le.rs | 20 +++++++++++ spec/rust/test_bits_byte_aligned.rs | 23 +++++++++++++ spec/rust/test_bits_enum.rs | 17 ++++++++++ spec/rust/test_bits_seq_endian_combo.rs | 22 ++++++++++++ spec/rust/test_bits_simple.rs | 28 +++++++++++++++ spec/rust/test_bits_simple_le.rs | 28 +++++++++++++++ spec/rust/test_buffered_struct.rs | 21 ++++++++++++ spec/rust/test_bytes_pad_term.rs | 18 ++++++++++ spec/rust/test_cast_nested.rs | 18 ++++++++++ spec/rust/test_cast_to_imported.rs | 16 +++++++++ spec/rust/test_cast_to_top.rs | 17 ++++++++++ spec/rust/test_default_big_endian.rs | 15 ++++++++ spec/rust/test_default_bit_endian_mod.rs | 18 ++++++++++ .../test_default_endian_expr_inherited.rs | 29 ++++++++++++++++ spec/rust/test_default_endian_expr_is_be.rs | 32 +++++++++++++++++ spec/rust/test_default_endian_expr_is_le.rs | 26 ++++++++++++++ spec/rust/test_default_endian_mod.rs | 17 ++++++++++ spec/rust/test_docstrings.rs | 14 ++++++++ spec/rust/test_docstrings_docref.rs | 14 ++++++++ spec/rust/test_docstrings_docref_multi.rs | 14 ++++++++ spec/rust/test_enum_0.rs | 16 +++++++++ spec/rust/test_enum_1.rs | 16 +++++++++ spec/rust/test_enum_deep.rs | 16 +++++++++ spec/rust/test_enum_deep_literals.rs | 16 +++++++++ spec/rust/test_enum_fancy.rs | 16 +++++++++ spec/rust/test_enum_if.rs | 21 ++++++++++++ spec/rust/test_enum_negative.rs | 16 +++++++++ spec/rust/test_enum_of_value_inst.rs | 18 ++++++++++ spec/rust/test_expr_0.rs | 16 +++++++++ spec/rust/test_expr_1.rs | 18 ++++++++++ spec/rust/test_expr_2.rs | 31 +++++++++++++++++ spec/rust/test_expr_3.rs | 26 ++++++++++++++ spec/rust/test_expr_array.rs | 29 ++++++++++++++++ spec/rust/test_expr_bytes_cmp.rs | 24 +++++++++++++ spec/rust/test_expr_enum.rs | 17 ++++++++++ spec/rust/test_expr_io_pos.rs | 20 +++++++++++ spec/rust/test_expr_mod.rs | 20 +++++++++++ spec/rust/test_fixed_contents.rs | 14 ++++++++ spec/rust/test_fixed_struct.rs | 34 +++++++++++++++++++ spec/rust/test_float_to_i.rs | 22 ++++++++++++ spec/rust/test_floating_points.rs | 22 ++++++++++++ spec/rust/test_hello_world.rs | 15 ++++++++ spec/rust/test_if_instances.rs | 15 ++++++++ spec/rust/test_if_struct.rs | 21 ++++++++++++ spec/rust/test_if_values.rs | 20 +++++++++++ spec/rust/test_imports0.rs | 17 ++++++++++ spec/rust/test_str_eos.rs | 15 ++++++++ 48 files changed, 958 insertions(+) create mode 100644 spec/rust/test_bcd_user_type_be.rs create mode 100644 spec/rust/test_bcd_user_type_le.rs create mode 100644 spec/rust/test_bits_byte_aligned.rs create mode 100644 spec/rust/test_bits_enum.rs create mode 100644 spec/rust/test_bits_seq_endian_combo.rs create mode 100644 spec/rust/test_bits_simple.rs create mode 100644 spec/rust/test_bits_simple_le.rs create mode 100644 spec/rust/test_buffered_struct.rs create mode 100644 spec/rust/test_bytes_pad_term.rs create mode 100644 spec/rust/test_cast_nested.rs create mode 100644 spec/rust/test_cast_to_imported.rs create mode 100644 spec/rust/test_cast_to_top.rs create mode 100644 spec/rust/test_default_big_endian.rs create mode 100644 spec/rust/test_default_bit_endian_mod.rs create mode 100644 spec/rust/test_default_endian_expr_inherited.rs create mode 100644 spec/rust/test_default_endian_expr_is_be.rs create mode 100644 spec/rust/test_default_endian_expr_is_le.rs create mode 100644 spec/rust/test_default_endian_mod.rs create mode 100644 spec/rust/test_docstrings.rs create mode 100644 spec/rust/test_docstrings_docref.rs create mode 100644 spec/rust/test_docstrings_docref_multi.rs create mode 100644 spec/rust/test_enum_0.rs create mode 100644 spec/rust/test_enum_1.rs create mode 100644 spec/rust/test_enum_deep.rs create mode 100644 spec/rust/test_enum_deep_literals.rs create mode 100644 spec/rust/test_enum_fancy.rs create mode 100644 spec/rust/test_enum_if.rs create mode 100644 spec/rust/test_enum_negative.rs create mode 100644 spec/rust/test_enum_of_value_inst.rs create mode 100644 spec/rust/test_expr_0.rs create mode 100644 spec/rust/test_expr_1.rs create mode 100644 spec/rust/test_expr_2.rs create mode 100644 spec/rust/test_expr_3.rs create mode 100644 spec/rust/test_expr_array.rs create mode 100644 spec/rust/test_expr_bytes_cmp.rs create mode 100644 spec/rust/test_expr_enum.rs create mode 100644 spec/rust/test_expr_io_pos.rs create mode 100644 spec/rust/test_expr_mod.rs create mode 100644 spec/rust/test_fixed_contents.rs create mode 100644 spec/rust/test_fixed_struct.rs create mode 100644 spec/rust/test_float_to_i.rs create mode 100644 spec/rust/test_floating_points.rs create mode 100644 spec/rust/test_hello_world.rs create mode 100644 spec/rust/test_if_instances.rs create mode 100644 spec/rust/test_if_struct.rs create mode 100644 spec/rust/test_if_values.rs create mode 100644 spec/rust/test_imports0.rs create mode 100644 spec/rust/test_str_eos.rs diff --git a/spec/rust/test_bcd_user_type_be.rs b/spec/rust/test_bcd_user_type_be.rs new file mode 100644 index 000000000..9577c7cb0 --- /dev/null +++ b/spec/rust/test_bcd_user_type_be.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BcdUserTypeBe; + +#[test] +fn test_bcd_user_type_be() { + if let Ok(r) = BcdUserTypeBe::from_file("src/bcd_user_type_be.bin") { + + assert_eq!(r.ltr.as_int, 12345678); + assert_eq!(r.ltr.as_str, "12345678"); + assert_eq!(r.rtl.as_int, 87654321); + assert_eq!(r.rtl.as_str, "87654321"); + assert_eq!(r.leading_zero_ltr.as_int, 123456); + assert_eq!(r.leading_zero_ltr.as_str, "00123456"); + } +} diff --git a/spec/rust/test_bcd_user_type_le.rs b/spec/rust/test_bcd_user_type_le.rs new file mode 100644 index 000000000..ec7eee864 --- /dev/null +++ b/spec/rust/test_bcd_user_type_le.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BcdUserTypeLe; + +#[test] +fn test_bcd_user_type_le() { + if let Ok(r) = BcdUserTypeLe::from_file("src/bcd_user_type_le.bin") { + + assert_eq!(r.ltr.as_int, 12345678); + assert_eq!(r.ltr.as_str, "12345678"); + assert_eq!(r.rtl.as_int, 87654321); + assert_eq!(r.rtl.as_str, "87654321"); + assert_eq!(r.leading_zero_ltr.as_int, 123456); + assert_eq!(r.leading_zero_ltr.as_str, "00123456"); + } +} diff --git a/spec/rust/test_bits_byte_aligned.rs b/spec/rust/test_bits_byte_aligned.rs new file mode 100644 index 000000000..e45589006 --- /dev/null +++ b/spec/rust/test_bits_byte_aligned.rs @@ -0,0 +1,23 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BitsByteAligned; + +#[test] +fn test_bits_byte_aligned() { + if let Ok(r) = BitsByteAligned::from_file("src/fixed_struct.bin") { + + assert_eq!(r.one, 20); + assert_eq!(r.byte_1, 65); + assert_eq!(r.two, 2); + assert_eq!(r.three, false); + assert_eq!(r.byte_2, 75); + assert_eq!(r.four, 2892); + assert_eq!(r.byte_3, &[0xff]); + assert_eq!(r.full_byte, 255); + assert_eq!(r.byte_4, 80); + } +} diff --git a/spec/rust/test_bits_enum.rs b/spec/rust/test_bits_enum.rs new file mode 100644 index 000000000..433004059 --- /dev/null +++ b/spec/rust/test_bits_enum.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BitsEnum; + +#[test] +fn test_bits_enum() { + if let Ok(r) = BitsEnum::from_file("src/fixed_struct.bin") { + + assert_eq!(r.one, BitsEnum_Animal::Platypus); + assert_eq!(r.two, BitsEnum_Animal::Horse); + assert_eq!(r.three, BitsEnum_Animal::Cat); + } +} diff --git a/spec/rust/test_bits_seq_endian_combo.rs b/spec/rust/test_bits_seq_endian_combo.rs new file mode 100644 index 000000000..042023f58 --- /dev/null +++ b/spec/rust/test_bits_seq_endian_combo.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BitsSeqEndianCombo; + +#[test] +fn test_bits_seq_endian_combo() { + if let Ok(r) = BitsSeqEndianCombo::from_file("src/process_xor_4.bin") { + + assert_eq!(r.be1, 59); + assert_eq!(r.be2, 187); + assert_eq!(r.le3, 163); + assert_eq!(r.be4, 20); + assert_eq!(r.le5, 10); + assert_eq!(r.le6, 36); + assert_eq!(r.le7, 26); + assert_eq!(r.be8, true); + } +} diff --git a/spec/rust/test_bits_simple.rs b/spec/rust/test_bits_simple.rs new file mode 100644 index 000000000..c074a740a --- /dev/null +++ b/spec/rust/test_bits_simple.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BitsSimple; + +#[test] +fn test_bits_simple() { + if let Ok(r) = BitsSimple::from_file("src/fixed_struct.bin") { + + assert_eq!(r.byte_1, 80); + assert_eq!(r.byte_2, 65); + assert_eq!(r.bits_a, false); + assert_eq!(r.bits_b, 4); + assert_eq!(r.bits_c, 3); + assert_eq!(r.large_bits_1, 300); + assert_eq!(r.spacer, 5); + assert_eq!(r.large_bits_2, 1329); + assert_eq!(r.normal_s2, -1); + assert_eq!(r.byte_8_9_10, 5259587); + assert_eq!(r.byte_11_to_14, 1261262125); + assert_eq!(r.byte_15_to_19, 293220057087); + assert_eq!(r.byte_20_to_27, 18446744073709551615); + assert_eq!(r.test_if_b1, 123); + } +} diff --git a/spec/rust/test_bits_simple_le.rs b/spec/rust/test_bits_simple_le.rs new file mode 100644 index 000000000..be32e114d --- /dev/null +++ b/spec/rust/test_bits_simple_le.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BitsSimpleLe; + +#[test] +fn test_bits_simple_le() { + if let Ok(r) = BitsSimpleLe::from_file("src/fixed_struct.bin") { + + assert_eq!(r.byte_1, 80); + assert_eq!(r.byte_2, 65); + assert_eq!(r.bits_a, true); + assert_eq!(r.bits_b, 1); + assert_eq!(r.bits_c, 4); + assert_eq!(r.large_bits_1, 331); + assert_eq!(r.spacer, 3); + assert_eq!(r.large_bits_2, 393); + assert_eq!(r.normal_s2, -1); + assert_eq!(r.byte_8_9_10, 4407632); + assert_eq!(r.byte_11_to_14, 760556875); + assert_eq!(r.byte_15_to_19, 1099499455812); + assert_eq!(r.byte_20_to_27, 18446744073709551615); + assert_eq!(r.test_if_b1, 123); + } +} diff --git a/spec/rust/test_buffered_struct.rs b/spec/rust/test_buffered_struct.rs new file mode 100644 index 000000000..ef2a828dc --- /dev/null +++ b/spec/rust/test_buffered_struct.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BufferedStruct; + +#[test] +fn test_buffered_struct() { + if let Ok(r) = BufferedStruct::from_file("src/buffered_struct.bin") { + + assert_eq!(r.len1, 16); + assert_eq!(r.block1.number1, 66); + assert_eq!(r.block1.number2, 67); + assert_eq!(r.len2, 8); + assert_eq!(r.block2.number1, 68); + assert_eq!(r.block2.number2, 69); + assert_eq!(r.finisher, 238); + } +} diff --git a/spec/rust/test_bytes_pad_term.rs b/spec/rust/test_bytes_pad_term.rs new file mode 100644 index 000000000..14706cc4f --- /dev/null +++ b/spec/rust/test_bytes_pad_term.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::BytesPadTerm; + +#[test] +fn test_bytes_pad_term() { + if let Ok(r) = BytesPadTerm::from_file("src/str_pad_term.bin") { + + assert_eq!(r.str_pad, &[0x73, 0x74, 0x72, 0x31]); + assert_eq!(r.str_term, &[0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f]); + assert_eq!(r.str_term_and_pad, &[0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b]); + assert_eq!(r.str_term_include, &[0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40]); + } +} diff --git a/spec/rust/test_cast_nested.rs b/spec/rust/test_cast_nested.rs new file mode 100644 index 000000000..120413e35 --- /dev/null +++ b/spec/rust/test_cast_nested.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::CastNested; + +#[test] +fn test_cast_nested() { + if let Ok(r) = CastNested::from_file("src/switch_opcodes.bin") { + + assert_eq!(r.opcodes_0_str.value, "foobar"); + assert_eq!(r.opcodes_0_str_value, "foobar"); + assert_eq!(r.opcodes_1_int.value, 66); + assert_eq!(r.opcodes_1_int_value, 66); + } +} diff --git a/spec/rust/test_cast_to_imported.rs b/spec/rust/test_cast_to_imported.rs new file mode 100644 index 000000000..656c4c6dd --- /dev/null +++ b/spec/rust/test_cast_to_imported.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::CastToImported; + +#[test] +fn test_cast_to_imported() { + if let Ok(r) = CastToImported::from_file("src/fixed_struct.bin") { + + assert_eq!(r.one.one, 80); + assert_eq!(r.one_casted.one, 80); + } +} diff --git a/spec/rust/test_cast_to_top.rs b/spec/rust/test_cast_to_top.rs new file mode 100644 index 000000000..22abe6450 --- /dev/null +++ b/spec/rust/test_cast_to_top.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::CastToTop; + +#[test] +fn test_cast_to_top() { + if let Ok(r) = CastToTop::from_file("src/fixed_struct.bin") { + + assert_eq!(r.code, 80); + assert_eq!(r.header.code, 65); + assert_eq!(r.header_casted.code, 65); + } +} diff --git a/spec/rust/test_default_big_endian.rs b/spec/rust/test_default_big_endian.rs new file mode 100644 index 000000000..3d85db5d1 --- /dev/null +++ b/spec/rust/test_default_big_endian.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DefaultBigEndian; + +#[test] +fn test_default_big_endian() { + if let Ok(r) = DefaultBigEndian::from_file("src/enum_0.bin") { + + assert_eq!(r.one, 117440512); + } +} diff --git a/spec/rust/test_default_bit_endian_mod.rs b/spec/rust/test_default_bit_endian_mod.rs new file mode 100644 index 000000000..82725b2ee --- /dev/null +++ b/spec/rust/test_default_bit_endian_mod.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DefaultBitEndianMod; + +#[test] +fn test_default_bit_endian_mod() { + if let Ok(r) = DefaultBitEndianMod::from_file("src/fixed_struct.bin") { + + assert_eq!(r.main.one, 336); + assert_eq!(r.main.two, 8608); + assert_eq!(r.main.nest.two, 11595); + assert_eq!(r.main.nest_be.two, 12799); + } +} diff --git a/spec/rust/test_default_endian_expr_inherited.rs b/spec/rust/test_default_endian_expr_inherited.rs new file mode 100644 index 000000000..bc30542b9 --- /dev/null +++ b/spec/rust/test_default_endian_expr_inherited.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DefaultEndianExprInherited; + +#[test] +fn test_default_endian_expr_inherited() { + if let Ok(r) = DefaultEndianExprInherited::from_file("src/endian_expr.bin") { + + assert_eq!(r.docs[0 as usize].indicator, &[0x49, 0x49]); + assert_eq!(r.docs[0 as usize].main.insides.some_int, 66); + assert_eq!(r.docs[0 as usize].main.insides.more.some_int1, 16896); + assert_eq!(r.docs[0 as usize].main.insides.more.some_int2, 66); + assert_eq!(r.docs[0 as usize].main.insides.more.some_inst, 66); + assert_eq!(r.docs[1 as usize].indicator, &[0x4d, 0x4d]); + assert_eq!(r.docs[1 as usize].main.insides.some_int, 66); + assert_eq!(r.docs[1 as usize].main.insides.more.some_int1, 66); + assert_eq!(r.docs[1 as usize].main.insides.more.some_int2, 16896); + assert_eq!(r.docs[1 as usize].main.insides.more.some_inst, 1107296256); + assert_eq!(r.docs[2 as usize].indicator, &[0x58, 0x58]); + assert_eq!(r.docs[2 as usize].main.insides.some_int, 66); + assert_eq!(r.docs[2 as usize].main.insides.more.some_int1, 66); + assert_eq!(r.docs[2 as usize].main.insides.more.some_int2, 16896); + assert_eq!(r.docs[2 as usize].main.insides.more.some_inst, 1107296256); + } +} diff --git a/spec/rust/test_default_endian_expr_is_be.rs b/spec/rust/test_default_endian_expr_is_be.rs new file mode 100644 index 000000000..26a034410 --- /dev/null +++ b/spec/rust/test_default_endian_expr_is_be.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DefaultEndianExprIsBe; + +#[test] +fn test_default_endian_expr_is_be() { + if let Ok(r) = DefaultEndianExprIsBe::from_file("src/endian_expr.bin") { + + assert_eq!(r.docs[0 as usize].indicator, &[0x49, 0x49]); + assert_eq!(r.docs[0 as usize].main.some_int, 66); + assert_eq!(r.docs[0 as usize].main.some_int_be, 66); + assert_eq!(r.docs[0 as usize].main.some_int_le, 66); + assert_eq!(r.docs[0 as usize].main.inst_int, 66); + assert_eq!(r.docs[0 as usize].main.inst_sub.foo, 66); + assert_eq!(r.docs[1 as usize].indicator, &[0x4d, 0x4d]); + assert_eq!(r.docs[1 as usize].main.some_int, 66); + assert_eq!(r.docs[1 as usize].main.some_int_be, 66); + assert_eq!(r.docs[1 as usize].main.some_int_le, 66); + assert_eq!(r.docs[1 as usize].main.inst_int, 1107296256); + assert_eq!(r.docs[1 as usize].main.inst_sub.foo, 1107296256); + assert_eq!(r.docs[2 as usize].indicator, &[0x58, 0x58]); + assert_eq!(r.docs[2 as usize].main.some_int, 1107296256); + assert_eq!(r.docs[2 as usize].main.some_int_be, 66); + assert_eq!(r.docs[2 as usize].main.some_int_le, 66); + assert_eq!(r.docs[2 as usize].main.inst_int, 66); + assert_eq!(r.docs[2 as usize].main.inst_sub.foo, 66); + } +} diff --git a/spec/rust/test_default_endian_expr_is_le.rs b/spec/rust/test_default_endian_expr_is_le.rs new file mode 100644 index 000000000..c02ea05f3 --- /dev/null +++ b/spec/rust/test_default_endian_expr_is_le.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DefaultEndianExprIsLe; + +#[test] +fn test_default_endian_expr_is_le() { + if let Ok(r) = DefaultEndianExprIsLe::from_file("src/endian_expr.bin") { + + assert_eq!(r.docs[0 as usize].indicator, &[0x49, 0x49]); + assert_eq!(r.docs[0 as usize].main.some_int, 66); + assert_eq!(r.docs[0 as usize].main.some_int_be, 66); + assert_eq!(r.docs[0 as usize].main.some_int_le, 66); + assert_eq!(r.docs[1 as usize].indicator, &[0x4d, 0x4d]); + assert_eq!(r.docs[1 as usize].main.some_int, 66); + assert_eq!(r.docs[1 as usize].main.some_int_be, 66); + assert_eq!(r.docs[1 as usize].main.some_int_le, 66); + assert_eq!(r.docs[2 as usize].indicator, &[0x58, 0x58]); + assert_eq!(r.docs[2 as usize].main.some_int, 66); + assert_eq!(r.docs[2 as usize].main.some_int_be, 66); + assert_eq!(r.docs[2 as usize].main.some_int_le, 66); + } +} diff --git a/spec/rust/test_default_endian_mod.rs b/spec/rust/test_default_endian_mod.rs new file mode 100644 index 000000000..6823715ed --- /dev/null +++ b/spec/rust/test_default_endian_mod.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DefaultEndianMod; + +#[test] +fn test_default_endian_mod() { + if let Ok(r) = DefaultEndianMod::from_file("src/fixed_struct.bin") { + + assert_eq!(r.main.one, 1262698832); + assert_eq!(r.main.nest.two, -52947); + assert_eq!(r.main.nest_be.two, 1346454347); + } +} diff --git a/spec/rust/test_docstrings.rs b/spec/rust/test_docstrings.rs new file mode 100644 index 000000000..3ab726f38 --- /dev/null +++ b/spec/rust/test_docstrings.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Docstrings; + +#[test] +fn test_docstrings() { + if let Ok(r) = Docstrings::from_file("src/fixed_struct.bin") { + + } +} diff --git a/spec/rust/test_docstrings_docref.rs b/spec/rust/test_docstrings_docref.rs new file mode 100644 index 000000000..c2c1df62e --- /dev/null +++ b/spec/rust/test_docstrings_docref.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DocstringsDocref; + +#[test] +fn test_docstrings_docref() { + if let Ok(r) = DocstringsDocref::from_file("src/fixed_struct.bin") { + + } +} diff --git a/spec/rust/test_docstrings_docref_multi.rs b/spec/rust/test_docstrings_docref_multi.rs new file mode 100644 index 000000000..1bc4f5a53 --- /dev/null +++ b/spec/rust/test_docstrings_docref_multi.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::DocstringsDocrefMulti; + +#[test] +fn test_docstrings_docref_multi() { + if let Ok(r) = DocstringsDocrefMulti::from_file("src/fixed_struct.bin") { + + } +} diff --git a/spec/rust/test_enum_0.rs b/spec/rust/test_enum_0.rs new file mode 100644 index 000000000..bf3a99705 --- /dev/null +++ b/spec/rust/test_enum_0.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Enum0; + +#[test] +fn test_enum_0() { + if let Ok(r) = Enum0::from_file("src/enum_0.bin") { + + assert_eq!(r.pet_1, Enum0_Animal::Cat); + assert_eq!(r.pet_2, Enum0_Animal::Chicken); + } +} diff --git a/spec/rust/test_enum_1.rs b/spec/rust/test_enum_1.rs new file mode 100644 index 000000000..229012977 --- /dev/null +++ b/spec/rust/test_enum_1.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Enum1; + +#[test] +fn test_enum_1() { + if let Ok(r) = Enum1::from_file("src/enum_0.bin") { + + assert_eq!(r.main.submain.pet_1, Enum1_MainObj_Animal::Cat); + assert_eq!(r.main.submain.pet_2, Enum1_MainObj_Animal::Chicken); + } +} diff --git a/spec/rust/test_enum_deep.rs b/spec/rust/test_enum_deep.rs new file mode 100644 index 000000000..0f8b5178d --- /dev/null +++ b/spec/rust/test_enum_deep.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::EnumDeep; + +#[test] +fn test_enum_deep() { + if let Ok(r) = EnumDeep::from_file("src/enum_0.bin") { + + assert_eq!(r.pet_1, EnumDeep_Container1_Animal::Cat); + assert_eq!(r.pet_2, EnumDeep_Container1_Container2_Animal::Hare); + } +} diff --git a/spec/rust/test_enum_deep_literals.rs b/spec/rust/test_enum_deep_literals.rs new file mode 100644 index 000000000..4ad8ad1bc --- /dev/null +++ b/spec/rust/test_enum_deep_literals.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::EnumDeepLiterals; + +#[test] +fn test_enum_deep_literals() { + if let Ok(r) = EnumDeepLiterals::from_file("src/enum_0.bin") { + + assert_eq!(r.is_pet_1_ok, true); + assert_eq!(r.is_pet_2_ok, true); + } +} diff --git a/spec/rust/test_enum_fancy.rs b/spec/rust/test_enum_fancy.rs new file mode 100644 index 000000000..d999dfff3 --- /dev/null +++ b/spec/rust/test_enum_fancy.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::EnumFancy; + +#[test] +fn test_enum_fancy() { + if let Ok(r) = EnumFancy::from_file("src/enum_0.bin") { + + assert_eq!(r.pet_1, EnumFancy_Animal::Cat); + assert_eq!(r.pet_2, EnumFancy_Animal::Chicken); + } +} diff --git a/spec/rust/test_enum_if.rs b/spec/rust/test_enum_if.rs new file mode 100644 index 000000000..28e21df8d --- /dev/null +++ b/spec/rust/test_enum_if.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::EnumIf; + +#[test] +fn test_enum_if() { + if let Ok(r) = EnumIf::from_file("src/if_struct.bin") { + + assert_eq!(r.op1.opcode, EnumIf_Opcodes::AString); + assert_eq!(r.op1.arg_str.str, "foo"); + assert_eq!(r.op2.opcode, EnumIf_Opcodes::ATuple); + assert_eq!(r.op2.arg_tuple.num1, 66); + assert_eq!(r.op2.arg_tuple.num2, 67); + assert_eq!(r.op3.opcode, EnumIf_Opcodes::AString); + assert_eq!(r.op3.arg_str.str, "bar"); + } +} diff --git a/spec/rust/test_enum_negative.rs b/spec/rust/test_enum_negative.rs new file mode 100644 index 000000000..f473aaf7f --- /dev/null +++ b/spec/rust/test_enum_negative.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::EnumNegative; + +#[test] +fn test_enum_negative() { + if let Ok(r) = EnumNegative::from_file("src/enum_negative.bin") { + + assert_eq!(r.f1, EnumNegative_Constants::NegativeOne); + assert_eq!(r.f2, EnumNegative_Constants::PositiveOne); + } +} diff --git a/spec/rust/test_enum_of_value_inst.rs b/spec/rust/test_enum_of_value_inst.rs new file mode 100644 index 000000000..8005cf9cc --- /dev/null +++ b/spec/rust/test_enum_of_value_inst.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::EnumOfValueInst; + +#[test] +fn test_enum_of_value_inst() { + if let Ok(r) = EnumOfValueInst::from_file("src/enum_0.bin") { + + assert_eq!(r.pet_1, EnumOfValueInst_Animal::Cat); + assert_eq!(r.pet_2, EnumOfValueInst_Animal::Chicken); + assert_eq!(r.pet_3, EnumOfValueInst_Animal::Dog); + assert_eq!(r.pet_4, EnumOfValueInst_Animal::Dog); + } +} diff --git a/spec/rust/test_expr_0.rs b/spec/rust/test_expr_0.rs new file mode 100644 index 000000000..daccff261 --- /dev/null +++ b/spec/rust/test_expr_0.rs @@ -0,0 +1,16 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Expr0; + +#[test] +fn test_expr_0() { + if let Ok(r) = Expr0::from_file("src/str_encodings.bin") { + + assert_eq!(r.must_be_f7, 247); + assert_eq!(r.must_be_abc123, "abc123"); + } +} diff --git a/spec/rust/test_expr_1.rs b/spec/rust/test_expr_1.rs new file mode 100644 index 000000000..44573a63f --- /dev/null +++ b/spec/rust/test_expr_1.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Expr1; + +#[test] +fn test_expr_1() { + if let Ok(r) = Expr1::from_file("src/str_encodings.bin") { + + assert_eq!(r.len_of_1, 10); + assert_eq!(r.len_of_1_mod, 8); + assert_eq!(r.str1, "Some ASC"); + assert_eq!(r.str1_len, 8); + } +} diff --git a/spec/rust/test_expr_2.rs b/spec/rust/test_expr_2.rs new file mode 100644 index 000000000..736e9e4ba --- /dev/null +++ b/spec/rust/test_expr_2.rs @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Expr2; + +#[test] +fn test_expr_2() { + if let Ok(r) = Expr2::from_file("src/str_encodings.bin") { + + assert_eq!(r.str1.len_orig, 10); + assert_eq!(r.str1.len_mod, 7); + assert_eq!(r.str1.str, "Some AS"); + assert_eq!(r.str1_len, 7); + assert_eq!(r.str1_len_mod, 7); + assert_eq!(r.str1_byte1, 73); + assert_eq!(r.str1_avg, 73); + assert_eq!(r.str1_char5, "e"); + assert_eq!(r.str1_tuple5.byte0, 101); + assert_eq!(r.str1_tuple5.byte0, 101); + assert_eq!(r.str1_tuple5.byte1, 32); + assert_eq!(r.str1_tuple5.byte2, 65); + assert_eq!(r.str1_tuple5.avg, 48); + assert_eq!(r.str2_tuple5.byte0, 101); + assert_eq!(r.str2_tuple5.byte1, 32); + assert_eq!(r.str2_tuple5.byte2, 65); + assert_eq!(r.str2_tuple5.avg, 48); + } +} diff --git a/spec/rust/test_expr_3.rs b/spec/rust/test_expr_3.rs new file mode 100644 index 000000000..4bb03fe9f --- /dev/null +++ b/spec/rust/test_expr_3.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Expr3; + +#[test] +fn test_expr_3() { + if let Ok(r) = Expr3::from_file("src/fixed_struct.bin") { + + assert_eq!(r.one, 80); + assert_eq!(r.two, "ACK"); + assert_eq!(r.three, "@ACK"); + assert_eq!(r.four, "_ACK_"); + assert_eq!(r.is_str_eq, true); + assert_eq!(r.is_str_ne, false); + assert_eq!(r.is_str_lt, true); + assert_eq!(r.is_str_gt, false); + assert_eq!(r.is_str_le, true); + assert_eq!(r.is_str_ge, false); + assert_eq!(r.is_str_lt2, true); + assert_eq!(r.test_not, true); + } +} diff --git a/spec/rust/test_expr_array.rs b/spec/rust/test_expr_array.rs new file mode 100644 index 000000000..16e25538d --- /dev/null +++ b/spec/rust/test_expr_array.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::ExprArray; + +#[test] +fn test_expr_array() { + if let Ok(r) = ExprArray::from_file("src/expr_array.bin") { + + assert_eq!(r.aint_size, 4); + assert_eq!(r.aint_first, 7657765); + assert_eq!(r.aint_last, 16272640); + assert_eq!(r.aint_min, 49185); + assert_eq!(r.aint_max, 1123362332); + assert_eq!(r.afloat_size, 3); + assert_eq!(r.afloat_first, -2.6839530254859364E-121); + assert_eq!(r.afloat_last, -1.1103359815095273E-175); + assert_eq!(r.afloat_min, -8.754689149998834E+288); + assert_eq!(r.afloat_max, -1.1103359815095273E-175); + assert_eq!(r.astr_size, 3); + assert_eq!(r.astr_first, "foo"); + assert_eq!(r.astr_last, "baz"); + assert_eq!(r.astr_min, "bar"); + assert_eq!(r.astr_max, "foo"); + } +} diff --git a/spec/rust/test_expr_bytes_cmp.rs b/spec/rust/test_expr_bytes_cmp.rs new file mode 100644 index 000000000..c08306a64 --- /dev/null +++ b/spec/rust/test_expr_bytes_cmp.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::ExprBytesCmp; + +#[test] +fn test_expr_bytes_cmp() { + if let Ok(r) = ExprBytesCmp::from_file("src/fixed_struct.bin") { + + assert_eq!(r.one, &[0x50]); + assert_eq!(r.two, &[0x41, 0x43, 0x4b]); + assert_eq!(r.is_eq, true); + assert_eq!(r.is_ne, false); + assert_eq!(r.is_lt, true); + assert_eq!(r.is_gt, false); + assert_eq!(r.is_le, true); + assert_eq!(r.is_ge, false); + assert_eq!(r.is_lt2, false); + assert_eq!(r.is_gt2, true); + } +} diff --git a/spec/rust/test_expr_enum.rs b/spec/rust/test_expr_enum.rs new file mode 100644 index 000000000..91a086f1f --- /dev/null +++ b/spec/rust/test_expr_enum.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::ExprEnum; + +#[test] +fn test_expr_enum() { + if let Ok(r) = ExprEnum::from_file("src/term_strz.bin") { + + assert_eq!(r.const_dog, ExprEnum_Animal::Dog); + assert_eq!(r.derived_boom, ExprEnum_Animal::Boom); + assert_eq!(r.derived_dog, ExprEnum_Animal::Dog); + } +} diff --git a/spec/rust/test_expr_io_pos.rs b/spec/rust/test_expr_io_pos.rs new file mode 100644 index 000000000..486c0f03f --- /dev/null +++ b/spec/rust/test_expr_io_pos.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::ExprIoPos; + +#[test] +fn test_expr_io_pos() { + if let Ok(r) = ExprIoPos::from_file("src/expr_io_pos.bin") { + + assert_eq!(r.substream1.my_str, "CURIOSITY"); + assert_eq!(r.substream1.body, &[0x11, 0x22, 0x33, 0x44]); + assert_eq!(r.substream1.number, 66); + assert_eq!(r.substream2.my_str, "KILLED"); + assert_eq!(r.substream2.body, &[0x61, 0x20, 0x63, 0x61, 0x74]); + assert_eq!(r.substream2.number, 103); + } +} diff --git a/spec/rust/test_expr_mod.rs b/spec/rust/test_expr_mod.rs new file mode 100644 index 000000000..f9c63448e --- /dev/null +++ b/spec/rust/test_expr_mod.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::ExprMod; + +#[test] +fn test_expr_mod() { + if let Ok(r) = ExprMod::from_file("src/fixed_struct.bin") { + + assert_eq!(r.int_u, 1262698832); + assert_eq!(r.int_s, -52947); + assert_eq!(r.mod_pos_const, 9); + assert_eq!(r.mod_neg_const, 4); + assert_eq!(r.mod_pos_seq, 5); + assert_eq!(r.mod_neg_seq, 2); + } +} diff --git a/spec/rust/test_fixed_contents.rs b/spec/rust/test_fixed_contents.rs new file mode 100644 index 000000000..1a57a8c5c --- /dev/null +++ b/spec/rust/test_fixed_contents.rs @@ -0,0 +1,14 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::FixedContents; + +#[test] +fn test_fixed_contents() { + if let Ok(r) = FixedContents::from_file("src/fixed_struct.bin") { + + } +} diff --git a/spec/rust/test_fixed_struct.rs b/spec/rust/test_fixed_struct.rs new file mode 100644 index 000000000..b667f6ef1 --- /dev/null +++ b/spec/rust/test_fixed_struct.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::FixedStruct; + +#[test] +fn test_fixed_struct() { + if let Ok(r) = FixedStruct::from_file("src/fixed_struct.bin") { + + assert_eq!(r.hdr.uint8, 255); + assert_eq!(r.hdr.uint16, 65535); + assert_eq!(r.hdr.uint32, 4294967295); + assert_eq!(r.hdr.uint64, 18446744073709551615); + assert_eq!(r.hdr.sint8, -1); + assert_eq!(r.hdr.sint16, -1); + assert_eq!(r.hdr.sint32, -1); + assert_eq!(r.hdr.sint64, -1); + assert_eq!(r.hdr.uint16le, 66); + assert_eq!(r.hdr.uint32le, 66); + assert_eq!(r.hdr.uint64le, 66); + assert_eq!(r.hdr.sint16le, -66); + assert_eq!(r.hdr.sint32le, -66); + assert_eq!(r.hdr.sint64le, -66); + assert_eq!(r.hdr.uint16be, 66); + assert_eq!(r.hdr.uint32be, 66); + assert_eq!(r.hdr.uint64be, 66); + assert_eq!(r.hdr.sint16be, -66); + assert_eq!(r.hdr.sint32be, -66); + assert_eq!(r.hdr.sint64be, -66); + } +} diff --git a/spec/rust/test_float_to_i.rs b/spec/rust/test_float_to_i.rs new file mode 100644 index 000000000..ae0d2921f --- /dev/null +++ b/spec/rust/test_float_to_i.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::FloatToI; + +#[test] +fn test_float_to_i() { + if let Ok(r) = FloatToI::from_file("src/floating_points.bin") { + + assert_eq!(r.single_value, 0.5); + assert_eq!(r.double_value, 0.25); + assert_eq!(r.single_i, 0); + assert_eq!(r.double_i, 0); + assert_eq!(r.float1_i, 1); + assert_eq!(r.float2_i, 1); + assert_eq!(r.float3_i, 1); + assert_eq!(r.float4_i, -2); + } +} diff --git a/spec/rust/test_floating_points.rs b/spec/rust/test_floating_points.rs new file mode 100644 index 000000000..1d88cbb9f --- /dev/null +++ b/spec/rust/test_floating_points.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::FloatingPoints; + +#[test] +fn test_floating_points() { + if let Ok(r) = FloatingPoints::from_file("src/floating_points.bin") { + + assert_eq!(r.single_value, 0.5); + assert_eq!(r.single_value_be, 0.5); + assert_eq!(r.double_value, 0.25); + assert_eq!(r.double_value_be, 0.25); + assert_eq!(r.approximate_value, 1.2345); + assert_eq!(r.single_value_plus_int, 1.5); + assert_eq!(r.single_value_plus_float, 1.0); + assert_eq!(r.double_value_plus_float, 0.3); + } +} diff --git a/spec/rust/test_hello_world.rs b/spec/rust/test_hello_world.rs new file mode 100644 index 000000000..4f751ffb6 --- /dev/null +++ b/spec/rust/test_hello_world.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::HelloWorld; + +#[test] +fn test_hello_world() { + if let Ok(r) = HelloWorld::from_file("src/fixed_struct.bin") { + + assert_eq!(r.one, 80); + } +} diff --git a/spec/rust/test_if_instances.rs b/spec/rust/test_if_instances.rs new file mode 100644 index 000000000..ed8393b86 --- /dev/null +++ b/spec/rust/test_if_instances.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::IfInstances; + +#[test] +fn test_if_instances() { + if let Ok(r) = IfInstances::from_file("src/fixed_struct.bin") { + + assertNull(r.never_happens); + } +} diff --git a/spec/rust/test_if_struct.rs b/spec/rust/test_if_struct.rs new file mode 100644 index 000000000..65c23c1ea --- /dev/null +++ b/spec/rust/test_if_struct.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::IfStruct; + +#[test] +fn test_if_struct() { + if let Ok(r) = IfStruct::from_file("src/if_struct.bin") { + + assert_eq!(r.op1.opcode, 83); + assert_eq!(r.op1.arg_str.str, "foo"); + assert_eq!(r.op2.opcode, 84); + assert_eq!(r.op2.arg_tuple.num1, 66); + assert_eq!(r.op2.arg_tuple.num2, 67); + assert_eq!(r.op3.opcode, 83); + assert_eq!(r.op3.arg_str.str, "bar"); + } +} diff --git a/spec/rust/test_if_values.rs b/spec/rust/test_if_values.rs new file mode 100644 index 000000000..0b629bf8b --- /dev/null +++ b/spec/rust/test_if_values.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::IfValues; + +#[test] +fn test_if_values() { + if let Ok(r) = IfValues::from_file("src/fixed_struct.bin") { + + assert_eq!(r.codes[0 as usize].opcode, 80); + assert_eq!(r.codes[0 as usize].half_opcode, 40); + assert_eq!(r.codes[1 as usize].opcode, 65); + assertNull(r.codes[1 as usize].half_opcode); + assert_eq!(r.codes[2 as usize].opcode, 67); + assertNull(r.codes[2 as usize].half_opcode); + } +} diff --git a/spec/rust/test_imports0.rs b/spec/rust/test_imports0.rs new file mode 100644 index 000000000..1c5fecae4 --- /dev/null +++ b/spec/rust/test_imports0.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::Imports0; + +#[test] +fn test_imports0() { + if let Ok(r) = Imports0::from_file("src/fixed_struct.bin") { + + assert_eq!(r.two, 80); + assert_eq!(r.hw.one, 65); + assert_eq!(r.hw_one, 65); + } +} diff --git a/spec/rust/test_str_eos.rs b/spec/rust/test_str_eos.rs new file mode 100644 index 000000000..8c861443d --- /dev/null +++ b/spec/rust/test_str_eos.rs @@ -0,0 +1,15 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +extern crate kaitai_struct; +extern crate kaitai_rust; + +use kaitai_struct::KaitaiStruct; +use rust::StrEos; + +#[test] +fn test_str_eos() { + if let Ok(r) = StrEos::from_file("src/term_strz.bin") { + + assert_eq!(r.str, "foo|bar|baz@"); + } +} From 7152ca2028bad15fa938bbfe36f632948788e101 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Fri, 22 Jul 2022 15:50:11 +0200 Subject: [PATCH 005/198] standard rust structure --- spec/rust/{ => src}/test_bcd_user_type_be.rs | 0 spec/rust/{ => src}/test_bcd_user_type_le.rs | 0 spec/rust/{ => src}/test_bits_byte_aligned.rs | 0 spec/rust/{ => src}/test_bits_enum.rs | 0 spec/rust/{ => src}/test_bits_seq_endian_combo.rs | 0 spec/rust/{ => src}/test_bits_shift_by_b32_le.rs | 0 spec/rust/{ => src}/test_bits_shift_by_b64_le.rs | 0 spec/rust/{ => src}/test_bits_signed_res_b32_be.rs | 0 spec/rust/{ => src}/test_bits_signed_res_b32_le.rs | 0 spec/rust/{ => src}/test_bits_signed_shift_b32_le.rs | 0 spec/rust/{ => src}/test_bits_signed_shift_b64_le.rs | 0 spec/rust/{ => src}/test_bits_simple.rs | 0 spec/rust/{ => src}/test_bits_simple_le.rs | 0 spec/rust/{ => src}/test_bits_unaligned_b32_be.rs | 0 spec/rust/{ => src}/test_bits_unaligned_b32_le.rs | 0 spec/rust/{ => src}/test_bits_unaligned_b64_be.rs | 0 spec/rust/{ => src}/test_bits_unaligned_b64_le.rs | 0 spec/rust/{ => src}/test_buffered_struct.rs | 0 spec/rust/{ => src}/test_bytes_pad_term.rs | 0 spec/rust/{ => src}/test_cast_nested.rs | 0 spec/rust/{ => src}/test_cast_to_imported.rs | 0 spec/rust/{ => src}/test_cast_to_top.rs | 0 spec/rust/{ => src}/test_combine_bool.rs | 0 spec/rust/{ => src}/test_combine_bytes.rs | 0 spec/rust/{ => src}/test_combine_enum.rs | 0 spec/rust/{ => src}/test_combine_str.rs | 0 spec/rust/{ => src}/test_debug_switch_user.rs | 0 spec/rust/{ => src}/test_default_big_endian.rs | 0 spec/rust/{ => src}/test_default_bit_endian_mod.rs | 0 spec/rust/{ => src}/test_default_endian_expr_inherited.rs | 0 spec/rust/{ => src}/test_default_endian_expr_is_be.rs | 0 spec/rust/{ => src}/test_default_endian_expr_is_le.rs | 0 spec/rust/{ => src}/test_default_endian_mod.rs | 0 spec/rust/{ => src}/test_docstrings.rs | 0 spec/rust/{ => src}/test_docstrings_docref.rs | 0 spec/rust/{ => src}/test_docstrings_docref_multi.rs | 0 spec/rust/{ => src}/test_enum_0.rs | 0 spec/rust/{ => src}/test_enum_1.rs | 0 spec/rust/{ => src}/test_enum_deep.rs | 0 spec/rust/{ => src}/test_enum_deep_literals.rs | 0 spec/rust/{ => src}/test_enum_fancy.rs | 0 spec/rust/{ => src}/test_enum_for_unknown_id.rs | 0 spec/rust/{ => src}/test_enum_if.rs | 0 spec/rust/{ => src}/test_enum_import.rs | 0 spec/rust/{ => src}/test_enum_int_range_s.rs | 0 spec/rust/{ => src}/test_enum_int_range_u.rs | 0 spec/rust/{ => src}/test_enum_invalid.rs | 0 spec/rust/{ => src}/test_enum_long_range_s.rs | 0 spec/rust/{ => src}/test_enum_long_range_u.rs | 0 spec/rust/{ => src}/test_enum_negative.rs | 0 spec/rust/{ => src}/test_enum_of_value_inst.rs | 0 spec/rust/{ => src}/test_enum_to_i.rs | 0 spec/rust/{ => src}/test_enum_to_i_class_border_1.rs | 0 spec/rust/{ => src}/test_expr_0.rs | 0 spec/rust/{ => src}/test_expr_1.rs | 0 spec/rust/{ => src}/test_expr_2.rs | 0 spec/rust/{ => src}/test_expr_3.rs | 0 spec/rust/{ => src}/test_expr_array.rs | 0 spec/rust/{ => src}/test_expr_bits.rs | 0 spec/rust/{ => src}/test_expr_bytes_cmp.rs | 0 spec/rust/{ => src}/test_expr_bytes_non_literal.rs | 0 spec/rust/{ => src}/test_expr_bytes_ops.rs | 0 spec/rust/{ => src}/test_expr_calc_array_ops.rs | 0 spec/rust/{ => src}/test_expr_enum.rs | 0 spec/rust/{ => src}/test_expr_if_int_ops.rs | 0 spec/rust/{ => src}/test_expr_int_div.rs | 0 spec/rust/{ => src}/test_expr_io_eof.rs | 0 spec/rust/{ => src}/test_expr_io_pos.rs | 0 spec/rust/{ => src}/test_expr_mod.rs | 0 spec/rust/{ => src}/test_expr_ops_parens.rs | 0 spec/rust/{ => src}/test_expr_sizeof_type_0.rs | 0 spec/rust/{ => src}/test_expr_sizeof_type_1.rs | 0 spec/rust/{ => src}/test_expr_sizeof_value_0.rs | 0 spec/rust/{ => src}/test_expr_sizeof_value_sized.rs | 0 spec/rust/{ => src}/test_expr_str_encodings.rs | 0 spec/rust/{ => src}/test_expr_str_ops.rs | 0 spec/rust/{ => src}/test_fixed_contents.rs | 0 spec/rust/{ => src}/test_fixed_struct.rs | 0 spec/rust/{ => src}/test_float_to_i.rs | 0 spec/rust/{ => src}/test_floating_points.rs | 0 spec/rust/{ => src}/test_hello_world.rs | 0 spec/rust/{ => src}/test_if_instances.rs | 0 spec/rust/{ => src}/test_if_struct.rs | 0 spec/rust/{ => src}/test_if_values.rs | 0 spec/rust/{ => src}/test_imports0.rs | 0 spec/rust/{ => src}/test_imports_abs_abs.rs | 0 spec/rust/{ => src}/test_imports_abs_rel.rs | 0 spec/rust/{ => src}/test_imports_circular_a.rs | 0 spec/rust/{ => src}/test_imports_rel_1.rs | 0 spec/rust/{ => src}/test_integers_double_overflow.rs | 0 spec/rust/{ => src}/test_integers_min_max.rs | 0 spec/rust/{ => src}/test_io_local_var.rs | 0 spec/rust/{ => src}/test_meta_tags.rs | 0 spec/rust/{ => src}/test_meta_xref.rs | 0 spec/rust/{ => src}/test_nav_parent_switch_cast.rs | 0 spec/rust/{ => src}/test_nested_type_param.rs | 0 spec/rust/{ => src}/test_opaque_external_type_02_parent.rs | 0 spec/rust/{ => src}/test_optional_id.rs | 0 spec/rust/{ => src}/test_params_call_extra_parens.rs | 0 spec/rust/{ => src}/test_params_pass_array_int.rs | 0 spec/rust/{ => src}/test_params_pass_array_str.rs | 0 spec/rust/{ => src}/test_params_pass_array_struct.rs | 0 spec/rust/{ => src}/test_params_pass_array_usertype.rs | 0 spec/rust/{ => src}/test_params_pass_bool.rs | 0 spec/rust/{ => src}/test_params_pass_struct.rs | 0 spec/rust/{ => src}/test_process_custom_no_args.rs | 0 spec/rust/{ => src}/test_process_repeat_bytes.rs | 0 spec/rust/{ => src}/test_process_repeat_usertype.rs | 0 spec/rust/{ => src}/test_repeat_eos_bit.rs | 0 spec/rust/{ => src}/test_repeat_until_calc_array_type.rs | 0 spec/rust/{ => src}/test_str_encodings_utf16.rs | 0 spec/rust/{ => src}/test_str_eos.rs | 0 spec/rust/{ => src}/test_switch_else_only.rs | 0 spec/rust/{ => src}/test_switch_manual_enum_invalid.rs | 0 spec/rust/{ => src}/test_switch_manual_enum_invalid_else.rs | 0 spec/rust/{ => src}/test_switch_manual_int_size.rs | 0 spec/rust/{ => src}/test_switch_manual_int_size_eos.rs | 0 spec/rust/{ => src}/test_switch_multi_bool_ops.rs | 0 spec/rust/{ => src}/test_switch_repeat_expr.rs | 0 spec/rust/{ => src}/test_switch_repeat_expr_invalid.rs | 0 spec/rust/{ => src}/test_term_u1_val.rs | 0 spec/rust/{ => src}/test_type_ternary_2nd_falsy.rs | 0 spec/rust/{ => src}/test_valid_eq_str_encodings.rs | 0 spec/rust/{ => src}/test_valid_long.rs | 0 spec/rust/{ => src}/test_valid_not_parsed_if.rs | 0 spec/rust/{ => src}/test_valid_short.rs | 0 spec/rust/{ => src}/test_valid_switch.rs | 0 spec/rust/{ => src}/test_yaml_ints.rs | 0 spec/rust/{ => src}/test_zlib_surrounded.rs | 0 129 files changed, 0 insertions(+), 0 deletions(-) rename spec/rust/{ => src}/test_bcd_user_type_be.rs (100%) rename spec/rust/{ => src}/test_bcd_user_type_le.rs (100%) rename spec/rust/{ => src}/test_bits_byte_aligned.rs (100%) rename spec/rust/{ => src}/test_bits_enum.rs (100%) rename spec/rust/{ => src}/test_bits_seq_endian_combo.rs (100%) rename spec/rust/{ => src}/test_bits_shift_by_b32_le.rs (100%) rename spec/rust/{ => src}/test_bits_shift_by_b64_le.rs (100%) rename spec/rust/{ => src}/test_bits_signed_res_b32_be.rs (100%) rename spec/rust/{ => src}/test_bits_signed_res_b32_le.rs (100%) rename spec/rust/{ => src}/test_bits_signed_shift_b32_le.rs (100%) rename spec/rust/{ => src}/test_bits_signed_shift_b64_le.rs (100%) rename spec/rust/{ => src}/test_bits_simple.rs (100%) rename spec/rust/{ => src}/test_bits_simple_le.rs (100%) rename spec/rust/{ => src}/test_bits_unaligned_b32_be.rs (100%) rename spec/rust/{ => src}/test_bits_unaligned_b32_le.rs (100%) rename spec/rust/{ => src}/test_bits_unaligned_b64_be.rs (100%) rename spec/rust/{ => src}/test_bits_unaligned_b64_le.rs (100%) rename spec/rust/{ => src}/test_buffered_struct.rs (100%) rename spec/rust/{ => src}/test_bytes_pad_term.rs (100%) rename spec/rust/{ => src}/test_cast_nested.rs (100%) rename spec/rust/{ => src}/test_cast_to_imported.rs (100%) rename spec/rust/{ => src}/test_cast_to_top.rs (100%) rename spec/rust/{ => src}/test_combine_bool.rs (100%) rename spec/rust/{ => src}/test_combine_bytes.rs (100%) rename spec/rust/{ => src}/test_combine_enum.rs (100%) rename spec/rust/{ => src}/test_combine_str.rs (100%) rename spec/rust/{ => src}/test_debug_switch_user.rs (100%) rename spec/rust/{ => src}/test_default_big_endian.rs (100%) rename spec/rust/{ => src}/test_default_bit_endian_mod.rs (100%) rename spec/rust/{ => src}/test_default_endian_expr_inherited.rs (100%) rename spec/rust/{ => src}/test_default_endian_expr_is_be.rs (100%) rename spec/rust/{ => src}/test_default_endian_expr_is_le.rs (100%) rename spec/rust/{ => src}/test_default_endian_mod.rs (100%) rename spec/rust/{ => src}/test_docstrings.rs (100%) rename spec/rust/{ => src}/test_docstrings_docref.rs (100%) rename spec/rust/{ => src}/test_docstrings_docref_multi.rs (100%) rename spec/rust/{ => src}/test_enum_0.rs (100%) rename spec/rust/{ => src}/test_enum_1.rs (100%) rename spec/rust/{ => src}/test_enum_deep.rs (100%) rename spec/rust/{ => src}/test_enum_deep_literals.rs (100%) rename spec/rust/{ => src}/test_enum_fancy.rs (100%) rename spec/rust/{ => src}/test_enum_for_unknown_id.rs (100%) rename spec/rust/{ => src}/test_enum_if.rs (100%) rename spec/rust/{ => src}/test_enum_import.rs (100%) rename spec/rust/{ => src}/test_enum_int_range_s.rs (100%) rename spec/rust/{ => src}/test_enum_int_range_u.rs (100%) rename spec/rust/{ => src}/test_enum_invalid.rs (100%) rename spec/rust/{ => src}/test_enum_long_range_s.rs (100%) rename spec/rust/{ => src}/test_enum_long_range_u.rs (100%) rename spec/rust/{ => src}/test_enum_negative.rs (100%) rename spec/rust/{ => src}/test_enum_of_value_inst.rs (100%) rename spec/rust/{ => src}/test_enum_to_i.rs (100%) rename spec/rust/{ => src}/test_enum_to_i_class_border_1.rs (100%) rename spec/rust/{ => src}/test_expr_0.rs (100%) rename spec/rust/{ => src}/test_expr_1.rs (100%) rename spec/rust/{ => src}/test_expr_2.rs (100%) rename spec/rust/{ => src}/test_expr_3.rs (100%) rename spec/rust/{ => src}/test_expr_array.rs (100%) rename spec/rust/{ => src}/test_expr_bits.rs (100%) rename spec/rust/{ => src}/test_expr_bytes_cmp.rs (100%) rename spec/rust/{ => src}/test_expr_bytes_non_literal.rs (100%) rename spec/rust/{ => src}/test_expr_bytes_ops.rs (100%) rename spec/rust/{ => src}/test_expr_calc_array_ops.rs (100%) rename spec/rust/{ => src}/test_expr_enum.rs (100%) rename spec/rust/{ => src}/test_expr_if_int_ops.rs (100%) rename spec/rust/{ => src}/test_expr_int_div.rs (100%) rename spec/rust/{ => src}/test_expr_io_eof.rs (100%) rename spec/rust/{ => src}/test_expr_io_pos.rs (100%) rename spec/rust/{ => src}/test_expr_mod.rs (100%) rename spec/rust/{ => src}/test_expr_ops_parens.rs (100%) rename spec/rust/{ => src}/test_expr_sizeof_type_0.rs (100%) rename spec/rust/{ => src}/test_expr_sizeof_type_1.rs (100%) rename spec/rust/{ => src}/test_expr_sizeof_value_0.rs (100%) rename spec/rust/{ => src}/test_expr_sizeof_value_sized.rs (100%) rename spec/rust/{ => src}/test_expr_str_encodings.rs (100%) rename spec/rust/{ => src}/test_expr_str_ops.rs (100%) rename spec/rust/{ => src}/test_fixed_contents.rs (100%) rename spec/rust/{ => src}/test_fixed_struct.rs (100%) rename spec/rust/{ => src}/test_float_to_i.rs (100%) rename spec/rust/{ => src}/test_floating_points.rs (100%) rename spec/rust/{ => src}/test_hello_world.rs (100%) rename spec/rust/{ => src}/test_if_instances.rs (100%) rename spec/rust/{ => src}/test_if_struct.rs (100%) rename spec/rust/{ => src}/test_if_values.rs (100%) rename spec/rust/{ => src}/test_imports0.rs (100%) rename spec/rust/{ => src}/test_imports_abs_abs.rs (100%) rename spec/rust/{ => src}/test_imports_abs_rel.rs (100%) rename spec/rust/{ => src}/test_imports_circular_a.rs (100%) rename spec/rust/{ => src}/test_imports_rel_1.rs (100%) rename spec/rust/{ => src}/test_integers_double_overflow.rs (100%) rename spec/rust/{ => src}/test_integers_min_max.rs (100%) rename spec/rust/{ => src}/test_io_local_var.rs (100%) rename spec/rust/{ => src}/test_meta_tags.rs (100%) rename spec/rust/{ => src}/test_meta_xref.rs (100%) rename spec/rust/{ => src}/test_nav_parent_switch_cast.rs (100%) rename spec/rust/{ => src}/test_nested_type_param.rs (100%) rename spec/rust/{ => src}/test_opaque_external_type_02_parent.rs (100%) rename spec/rust/{ => src}/test_optional_id.rs (100%) rename spec/rust/{ => src}/test_params_call_extra_parens.rs (100%) rename spec/rust/{ => src}/test_params_pass_array_int.rs (100%) rename spec/rust/{ => src}/test_params_pass_array_str.rs (100%) rename spec/rust/{ => src}/test_params_pass_array_struct.rs (100%) rename spec/rust/{ => src}/test_params_pass_array_usertype.rs (100%) rename spec/rust/{ => src}/test_params_pass_bool.rs (100%) rename spec/rust/{ => src}/test_params_pass_struct.rs (100%) rename spec/rust/{ => src}/test_process_custom_no_args.rs (100%) rename spec/rust/{ => src}/test_process_repeat_bytes.rs (100%) rename spec/rust/{ => src}/test_process_repeat_usertype.rs (100%) rename spec/rust/{ => src}/test_repeat_eos_bit.rs (100%) rename spec/rust/{ => src}/test_repeat_until_calc_array_type.rs (100%) rename spec/rust/{ => src}/test_str_encodings_utf16.rs (100%) rename spec/rust/{ => src}/test_str_eos.rs (100%) rename spec/rust/{ => src}/test_switch_else_only.rs (100%) rename spec/rust/{ => src}/test_switch_manual_enum_invalid.rs (100%) rename spec/rust/{ => src}/test_switch_manual_enum_invalid_else.rs (100%) rename spec/rust/{ => src}/test_switch_manual_int_size.rs (100%) rename spec/rust/{ => src}/test_switch_manual_int_size_eos.rs (100%) rename spec/rust/{ => src}/test_switch_multi_bool_ops.rs (100%) rename spec/rust/{ => src}/test_switch_repeat_expr.rs (100%) rename spec/rust/{ => src}/test_switch_repeat_expr_invalid.rs (100%) rename spec/rust/{ => src}/test_term_u1_val.rs (100%) rename spec/rust/{ => src}/test_type_ternary_2nd_falsy.rs (100%) rename spec/rust/{ => src}/test_valid_eq_str_encodings.rs (100%) rename spec/rust/{ => src}/test_valid_long.rs (100%) rename spec/rust/{ => src}/test_valid_not_parsed_if.rs (100%) rename spec/rust/{ => src}/test_valid_short.rs (100%) rename spec/rust/{ => src}/test_valid_switch.rs (100%) rename spec/rust/{ => src}/test_yaml_ints.rs (100%) rename spec/rust/{ => src}/test_zlib_surrounded.rs (100%) diff --git a/spec/rust/test_bcd_user_type_be.rs b/spec/rust/src/test_bcd_user_type_be.rs similarity index 100% rename from spec/rust/test_bcd_user_type_be.rs rename to spec/rust/src/test_bcd_user_type_be.rs diff --git a/spec/rust/test_bcd_user_type_le.rs b/spec/rust/src/test_bcd_user_type_le.rs similarity index 100% rename from spec/rust/test_bcd_user_type_le.rs rename to spec/rust/src/test_bcd_user_type_le.rs diff --git a/spec/rust/test_bits_byte_aligned.rs b/spec/rust/src/test_bits_byte_aligned.rs similarity index 100% rename from spec/rust/test_bits_byte_aligned.rs rename to spec/rust/src/test_bits_byte_aligned.rs diff --git a/spec/rust/test_bits_enum.rs b/spec/rust/src/test_bits_enum.rs similarity index 100% rename from spec/rust/test_bits_enum.rs rename to spec/rust/src/test_bits_enum.rs diff --git a/spec/rust/test_bits_seq_endian_combo.rs b/spec/rust/src/test_bits_seq_endian_combo.rs similarity index 100% rename from spec/rust/test_bits_seq_endian_combo.rs rename to spec/rust/src/test_bits_seq_endian_combo.rs diff --git a/spec/rust/test_bits_shift_by_b32_le.rs b/spec/rust/src/test_bits_shift_by_b32_le.rs similarity index 100% rename from spec/rust/test_bits_shift_by_b32_le.rs rename to spec/rust/src/test_bits_shift_by_b32_le.rs diff --git a/spec/rust/test_bits_shift_by_b64_le.rs b/spec/rust/src/test_bits_shift_by_b64_le.rs similarity index 100% rename from spec/rust/test_bits_shift_by_b64_le.rs rename to spec/rust/src/test_bits_shift_by_b64_le.rs diff --git a/spec/rust/test_bits_signed_res_b32_be.rs b/spec/rust/src/test_bits_signed_res_b32_be.rs similarity index 100% rename from spec/rust/test_bits_signed_res_b32_be.rs rename to spec/rust/src/test_bits_signed_res_b32_be.rs diff --git a/spec/rust/test_bits_signed_res_b32_le.rs b/spec/rust/src/test_bits_signed_res_b32_le.rs similarity index 100% rename from spec/rust/test_bits_signed_res_b32_le.rs rename to spec/rust/src/test_bits_signed_res_b32_le.rs diff --git a/spec/rust/test_bits_signed_shift_b32_le.rs b/spec/rust/src/test_bits_signed_shift_b32_le.rs similarity index 100% rename from spec/rust/test_bits_signed_shift_b32_le.rs rename to spec/rust/src/test_bits_signed_shift_b32_le.rs diff --git a/spec/rust/test_bits_signed_shift_b64_le.rs b/spec/rust/src/test_bits_signed_shift_b64_le.rs similarity index 100% rename from spec/rust/test_bits_signed_shift_b64_le.rs rename to spec/rust/src/test_bits_signed_shift_b64_le.rs diff --git a/spec/rust/test_bits_simple.rs b/spec/rust/src/test_bits_simple.rs similarity index 100% rename from spec/rust/test_bits_simple.rs rename to spec/rust/src/test_bits_simple.rs diff --git a/spec/rust/test_bits_simple_le.rs b/spec/rust/src/test_bits_simple_le.rs similarity index 100% rename from spec/rust/test_bits_simple_le.rs rename to spec/rust/src/test_bits_simple_le.rs diff --git a/spec/rust/test_bits_unaligned_b32_be.rs b/spec/rust/src/test_bits_unaligned_b32_be.rs similarity index 100% rename from spec/rust/test_bits_unaligned_b32_be.rs rename to spec/rust/src/test_bits_unaligned_b32_be.rs diff --git a/spec/rust/test_bits_unaligned_b32_le.rs b/spec/rust/src/test_bits_unaligned_b32_le.rs similarity index 100% rename from spec/rust/test_bits_unaligned_b32_le.rs rename to spec/rust/src/test_bits_unaligned_b32_le.rs diff --git a/spec/rust/test_bits_unaligned_b64_be.rs b/spec/rust/src/test_bits_unaligned_b64_be.rs similarity index 100% rename from spec/rust/test_bits_unaligned_b64_be.rs rename to spec/rust/src/test_bits_unaligned_b64_be.rs diff --git a/spec/rust/test_bits_unaligned_b64_le.rs b/spec/rust/src/test_bits_unaligned_b64_le.rs similarity index 100% rename from spec/rust/test_bits_unaligned_b64_le.rs rename to spec/rust/src/test_bits_unaligned_b64_le.rs diff --git a/spec/rust/test_buffered_struct.rs b/spec/rust/src/test_buffered_struct.rs similarity index 100% rename from spec/rust/test_buffered_struct.rs rename to spec/rust/src/test_buffered_struct.rs diff --git a/spec/rust/test_bytes_pad_term.rs b/spec/rust/src/test_bytes_pad_term.rs similarity index 100% rename from spec/rust/test_bytes_pad_term.rs rename to spec/rust/src/test_bytes_pad_term.rs diff --git a/spec/rust/test_cast_nested.rs b/spec/rust/src/test_cast_nested.rs similarity index 100% rename from spec/rust/test_cast_nested.rs rename to spec/rust/src/test_cast_nested.rs diff --git a/spec/rust/test_cast_to_imported.rs b/spec/rust/src/test_cast_to_imported.rs similarity index 100% rename from spec/rust/test_cast_to_imported.rs rename to spec/rust/src/test_cast_to_imported.rs diff --git a/spec/rust/test_cast_to_top.rs b/spec/rust/src/test_cast_to_top.rs similarity index 100% rename from spec/rust/test_cast_to_top.rs rename to spec/rust/src/test_cast_to_top.rs diff --git a/spec/rust/test_combine_bool.rs b/spec/rust/src/test_combine_bool.rs similarity index 100% rename from spec/rust/test_combine_bool.rs rename to spec/rust/src/test_combine_bool.rs diff --git a/spec/rust/test_combine_bytes.rs b/spec/rust/src/test_combine_bytes.rs similarity index 100% rename from spec/rust/test_combine_bytes.rs rename to spec/rust/src/test_combine_bytes.rs diff --git a/spec/rust/test_combine_enum.rs b/spec/rust/src/test_combine_enum.rs similarity index 100% rename from spec/rust/test_combine_enum.rs rename to spec/rust/src/test_combine_enum.rs diff --git a/spec/rust/test_combine_str.rs b/spec/rust/src/test_combine_str.rs similarity index 100% rename from spec/rust/test_combine_str.rs rename to spec/rust/src/test_combine_str.rs diff --git a/spec/rust/test_debug_switch_user.rs b/spec/rust/src/test_debug_switch_user.rs similarity index 100% rename from spec/rust/test_debug_switch_user.rs rename to spec/rust/src/test_debug_switch_user.rs diff --git a/spec/rust/test_default_big_endian.rs b/spec/rust/src/test_default_big_endian.rs similarity index 100% rename from spec/rust/test_default_big_endian.rs rename to spec/rust/src/test_default_big_endian.rs diff --git a/spec/rust/test_default_bit_endian_mod.rs b/spec/rust/src/test_default_bit_endian_mod.rs similarity index 100% rename from spec/rust/test_default_bit_endian_mod.rs rename to spec/rust/src/test_default_bit_endian_mod.rs diff --git a/spec/rust/test_default_endian_expr_inherited.rs b/spec/rust/src/test_default_endian_expr_inherited.rs similarity index 100% rename from spec/rust/test_default_endian_expr_inherited.rs rename to spec/rust/src/test_default_endian_expr_inherited.rs diff --git a/spec/rust/test_default_endian_expr_is_be.rs b/spec/rust/src/test_default_endian_expr_is_be.rs similarity index 100% rename from spec/rust/test_default_endian_expr_is_be.rs rename to spec/rust/src/test_default_endian_expr_is_be.rs diff --git a/spec/rust/test_default_endian_expr_is_le.rs b/spec/rust/src/test_default_endian_expr_is_le.rs similarity index 100% rename from spec/rust/test_default_endian_expr_is_le.rs rename to spec/rust/src/test_default_endian_expr_is_le.rs diff --git a/spec/rust/test_default_endian_mod.rs b/spec/rust/src/test_default_endian_mod.rs similarity index 100% rename from spec/rust/test_default_endian_mod.rs rename to spec/rust/src/test_default_endian_mod.rs diff --git a/spec/rust/test_docstrings.rs b/spec/rust/src/test_docstrings.rs similarity index 100% rename from spec/rust/test_docstrings.rs rename to spec/rust/src/test_docstrings.rs diff --git a/spec/rust/test_docstrings_docref.rs b/spec/rust/src/test_docstrings_docref.rs similarity index 100% rename from spec/rust/test_docstrings_docref.rs rename to spec/rust/src/test_docstrings_docref.rs diff --git a/spec/rust/test_docstrings_docref_multi.rs b/spec/rust/src/test_docstrings_docref_multi.rs similarity index 100% rename from spec/rust/test_docstrings_docref_multi.rs rename to spec/rust/src/test_docstrings_docref_multi.rs diff --git a/spec/rust/test_enum_0.rs b/spec/rust/src/test_enum_0.rs similarity index 100% rename from spec/rust/test_enum_0.rs rename to spec/rust/src/test_enum_0.rs diff --git a/spec/rust/test_enum_1.rs b/spec/rust/src/test_enum_1.rs similarity index 100% rename from spec/rust/test_enum_1.rs rename to spec/rust/src/test_enum_1.rs diff --git a/spec/rust/test_enum_deep.rs b/spec/rust/src/test_enum_deep.rs similarity index 100% rename from spec/rust/test_enum_deep.rs rename to spec/rust/src/test_enum_deep.rs diff --git a/spec/rust/test_enum_deep_literals.rs b/spec/rust/src/test_enum_deep_literals.rs similarity index 100% rename from spec/rust/test_enum_deep_literals.rs rename to spec/rust/src/test_enum_deep_literals.rs diff --git a/spec/rust/test_enum_fancy.rs b/spec/rust/src/test_enum_fancy.rs similarity index 100% rename from spec/rust/test_enum_fancy.rs rename to spec/rust/src/test_enum_fancy.rs diff --git a/spec/rust/test_enum_for_unknown_id.rs b/spec/rust/src/test_enum_for_unknown_id.rs similarity index 100% rename from spec/rust/test_enum_for_unknown_id.rs rename to spec/rust/src/test_enum_for_unknown_id.rs diff --git a/spec/rust/test_enum_if.rs b/spec/rust/src/test_enum_if.rs similarity index 100% rename from spec/rust/test_enum_if.rs rename to spec/rust/src/test_enum_if.rs diff --git a/spec/rust/test_enum_import.rs b/spec/rust/src/test_enum_import.rs similarity index 100% rename from spec/rust/test_enum_import.rs rename to spec/rust/src/test_enum_import.rs diff --git a/spec/rust/test_enum_int_range_s.rs b/spec/rust/src/test_enum_int_range_s.rs similarity index 100% rename from spec/rust/test_enum_int_range_s.rs rename to spec/rust/src/test_enum_int_range_s.rs diff --git a/spec/rust/test_enum_int_range_u.rs b/spec/rust/src/test_enum_int_range_u.rs similarity index 100% rename from spec/rust/test_enum_int_range_u.rs rename to spec/rust/src/test_enum_int_range_u.rs diff --git a/spec/rust/test_enum_invalid.rs b/spec/rust/src/test_enum_invalid.rs similarity index 100% rename from spec/rust/test_enum_invalid.rs rename to spec/rust/src/test_enum_invalid.rs diff --git a/spec/rust/test_enum_long_range_s.rs b/spec/rust/src/test_enum_long_range_s.rs similarity index 100% rename from spec/rust/test_enum_long_range_s.rs rename to spec/rust/src/test_enum_long_range_s.rs diff --git a/spec/rust/test_enum_long_range_u.rs b/spec/rust/src/test_enum_long_range_u.rs similarity index 100% rename from spec/rust/test_enum_long_range_u.rs rename to spec/rust/src/test_enum_long_range_u.rs diff --git a/spec/rust/test_enum_negative.rs b/spec/rust/src/test_enum_negative.rs similarity index 100% rename from spec/rust/test_enum_negative.rs rename to spec/rust/src/test_enum_negative.rs diff --git a/spec/rust/test_enum_of_value_inst.rs b/spec/rust/src/test_enum_of_value_inst.rs similarity index 100% rename from spec/rust/test_enum_of_value_inst.rs rename to spec/rust/src/test_enum_of_value_inst.rs diff --git a/spec/rust/test_enum_to_i.rs b/spec/rust/src/test_enum_to_i.rs similarity index 100% rename from spec/rust/test_enum_to_i.rs rename to spec/rust/src/test_enum_to_i.rs diff --git a/spec/rust/test_enum_to_i_class_border_1.rs b/spec/rust/src/test_enum_to_i_class_border_1.rs similarity index 100% rename from spec/rust/test_enum_to_i_class_border_1.rs rename to spec/rust/src/test_enum_to_i_class_border_1.rs diff --git a/spec/rust/test_expr_0.rs b/spec/rust/src/test_expr_0.rs similarity index 100% rename from spec/rust/test_expr_0.rs rename to spec/rust/src/test_expr_0.rs diff --git a/spec/rust/test_expr_1.rs b/spec/rust/src/test_expr_1.rs similarity index 100% rename from spec/rust/test_expr_1.rs rename to spec/rust/src/test_expr_1.rs diff --git a/spec/rust/test_expr_2.rs b/spec/rust/src/test_expr_2.rs similarity index 100% rename from spec/rust/test_expr_2.rs rename to spec/rust/src/test_expr_2.rs diff --git a/spec/rust/test_expr_3.rs b/spec/rust/src/test_expr_3.rs similarity index 100% rename from spec/rust/test_expr_3.rs rename to spec/rust/src/test_expr_3.rs diff --git a/spec/rust/test_expr_array.rs b/spec/rust/src/test_expr_array.rs similarity index 100% rename from spec/rust/test_expr_array.rs rename to spec/rust/src/test_expr_array.rs diff --git a/spec/rust/test_expr_bits.rs b/spec/rust/src/test_expr_bits.rs similarity index 100% rename from spec/rust/test_expr_bits.rs rename to spec/rust/src/test_expr_bits.rs diff --git a/spec/rust/test_expr_bytes_cmp.rs b/spec/rust/src/test_expr_bytes_cmp.rs similarity index 100% rename from spec/rust/test_expr_bytes_cmp.rs rename to spec/rust/src/test_expr_bytes_cmp.rs diff --git a/spec/rust/test_expr_bytes_non_literal.rs b/spec/rust/src/test_expr_bytes_non_literal.rs similarity index 100% rename from spec/rust/test_expr_bytes_non_literal.rs rename to spec/rust/src/test_expr_bytes_non_literal.rs diff --git a/spec/rust/test_expr_bytes_ops.rs b/spec/rust/src/test_expr_bytes_ops.rs similarity index 100% rename from spec/rust/test_expr_bytes_ops.rs rename to spec/rust/src/test_expr_bytes_ops.rs diff --git a/spec/rust/test_expr_calc_array_ops.rs b/spec/rust/src/test_expr_calc_array_ops.rs similarity index 100% rename from spec/rust/test_expr_calc_array_ops.rs rename to spec/rust/src/test_expr_calc_array_ops.rs diff --git a/spec/rust/test_expr_enum.rs b/spec/rust/src/test_expr_enum.rs similarity index 100% rename from spec/rust/test_expr_enum.rs rename to spec/rust/src/test_expr_enum.rs diff --git a/spec/rust/test_expr_if_int_ops.rs b/spec/rust/src/test_expr_if_int_ops.rs similarity index 100% rename from spec/rust/test_expr_if_int_ops.rs rename to spec/rust/src/test_expr_if_int_ops.rs diff --git a/spec/rust/test_expr_int_div.rs b/spec/rust/src/test_expr_int_div.rs similarity index 100% rename from spec/rust/test_expr_int_div.rs rename to spec/rust/src/test_expr_int_div.rs diff --git a/spec/rust/test_expr_io_eof.rs b/spec/rust/src/test_expr_io_eof.rs similarity index 100% rename from spec/rust/test_expr_io_eof.rs rename to spec/rust/src/test_expr_io_eof.rs diff --git a/spec/rust/test_expr_io_pos.rs b/spec/rust/src/test_expr_io_pos.rs similarity index 100% rename from spec/rust/test_expr_io_pos.rs rename to spec/rust/src/test_expr_io_pos.rs diff --git a/spec/rust/test_expr_mod.rs b/spec/rust/src/test_expr_mod.rs similarity index 100% rename from spec/rust/test_expr_mod.rs rename to spec/rust/src/test_expr_mod.rs diff --git a/spec/rust/test_expr_ops_parens.rs b/spec/rust/src/test_expr_ops_parens.rs similarity index 100% rename from spec/rust/test_expr_ops_parens.rs rename to spec/rust/src/test_expr_ops_parens.rs diff --git a/spec/rust/test_expr_sizeof_type_0.rs b/spec/rust/src/test_expr_sizeof_type_0.rs similarity index 100% rename from spec/rust/test_expr_sizeof_type_0.rs rename to spec/rust/src/test_expr_sizeof_type_0.rs diff --git a/spec/rust/test_expr_sizeof_type_1.rs b/spec/rust/src/test_expr_sizeof_type_1.rs similarity index 100% rename from spec/rust/test_expr_sizeof_type_1.rs rename to spec/rust/src/test_expr_sizeof_type_1.rs diff --git a/spec/rust/test_expr_sizeof_value_0.rs b/spec/rust/src/test_expr_sizeof_value_0.rs similarity index 100% rename from spec/rust/test_expr_sizeof_value_0.rs rename to spec/rust/src/test_expr_sizeof_value_0.rs diff --git a/spec/rust/test_expr_sizeof_value_sized.rs b/spec/rust/src/test_expr_sizeof_value_sized.rs similarity index 100% rename from spec/rust/test_expr_sizeof_value_sized.rs rename to spec/rust/src/test_expr_sizeof_value_sized.rs diff --git a/spec/rust/test_expr_str_encodings.rs b/spec/rust/src/test_expr_str_encodings.rs similarity index 100% rename from spec/rust/test_expr_str_encodings.rs rename to spec/rust/src/test_expr_str_encodings.rs diff --git a/spec/rust/test_expr_str_ops.rs b/spec/rust/src/test_expr_str_ops.rs similarity index 100% rename from spec/rust/test_expr_str_ops.rs rename to spec/rust/src/test_expr_str_ops.rs diff --git a/spec/rust/test_fixed_contents.rs b/spec/rust/src/test_fixed_contents.rs similarity index 100% rename from spec/rust/test_fixed_contents.rs rename to spec/rust/src/test_fixed_contents.rs diff --git a/spec/rust/test_fixed_struct.rs b/spec/rust/src/test_fixed_struct.rs similarity index 100% rename from spec/rust/test_fixed_struct.rs rename to spec/rust/src/test_fixed_struct.rs diff --git a/spec/rust/test_float_to_i.rs b/spec/rust/src/test_float_to_i.rs similarity index 100% rename from spec/rust/test_float_to_i.rs rename to spec/rust/src/test_float_to_i.rs diff --git a/spec/rust/test_floating_points.rs b/spec/rust/src/test_floating_points.rs similarity index 100% rename from spec/rust/test_floating_points.rs rename to spec/rust/src/test_floating_points.rs diff --git a/spec/rust/test_hello_world.rs b/spec/rust/src/test_hello_world.rs similarity index 100% rename from spec/rust/test_hello_world.rs rename to spec/rust/src/test_hello_world.rs diff --git a/spec/rust/test_if_instances.rs b/spec/rust/src/test_if_instances.rs similarity index 100% rename from spec/rust/test_if_instances.rs rename to spec/rust/src/test_if_instances.rs diff --git a/spec/rust/test_if_struct.rs b/spec/rust/src/test_if_struct.rs similarity index 100% rename from spec/rust/test_if_struct.rs rename to spec/rust/src/test_if_struct.rs diff --git a/spec/rust/test_if_values.rs b/spec/rust/src/test_if_values.rs similarity index 100% rename from spec/rust/test_if_values.rs rename to spec/rust/src/test_if_values.rs diff --git a/spec/rust/test_imports0.rs b/spec/rust/src/test_imports0.rs similarity index 100% rename from spec/rust/test_imports0.rs rename to spec/rust/src/test_imports0.rs diff --git a/spec/rust/test_imports_abs_abs.rs b/spec/rust/src/test_imports_abs_abs.rs similarity index 100% rename from spec/rust/test_imports_abs_abs.rs rename to spec/rust/src/test_imports_abs_abs.rs diff --git a/spec/rust/test_imports_abs_rel.rs b/spec/rust/src/test_imports_abs_rel.rs similarity index 100% rename from spec/rust/test_imports_abs_rel.rs rename to spec/rust/src/test_imports_abs_rel.rs diff --git a/spec/rust/test_imports_circular_a.rs b/spec/rust/src/test_imports_circular_a.rs similarity index 100% rename from spec/rust/test_imports_circular_a.rs rename to spec/rust/src/test_imports_circular_a.rs diff --git a/spec/rust/test_imports_rel_1.rs b/spec/rust/src/test_imports_rel_1.rs similarity index 100% rename from spec/rust/test_imports_rel_1.rs rename to spec/rust/src/test_imports_rel_1.rs diff --git a/spec/rust/test_integers_double_overflow.rs b/spec/rust/src/test_integers_double_overflow.rs similarity index 100% rename from spec/rust/test_integers_double_overflow.rs rename to spec/rust/src/test_integers_double_overflow.rs diff --git a/spec/rust/test_integers_min_max.rs b/spec/rust/src/test_integers_min_max.rs similarity index 100% rename from spec/rust/test_integers_min_max.rs rename to spec/rust/src/test_integers_min_max.rs diff --git a/spec/rust/test_io_local_var.rs b/spec/rust/src/test_io_local_var.rs similarity index 100% rename from spec/rust/test_io_local_var.rs rename to spec/rust/src/test_io_local_var.rs diff --git a/spec/rust/test_meta_tags.rs b/spec/rust/src/test_meta_tags.rs similarity index 100% rename from spec/rust/test_meta_tags.rs rename to spec/rust/src/test_meta_tags.rs diff --git a/spec/rust/test_meta_xref.rs b/spec/rust/src/test_meta_xref.rs similarity index 100% rename from spec/rust/test_meta_xref.rs rename to spec/rust/src/test_meta_xref.rs diff --git a/spec/rust/test_nav_parent_switch_cast.rs b/spec/rust/src/test_nav_parent_switch_cast.rs similarity index 100% rename from spec/rust/test_nav_parent_switch_cast.rs rename to spec/rust/src/test_nav_parent_switch_cast.rs diff --git a/spec/rust/test_nested_type_param.rs b/spec/rust/src/test_nested_type_param.rs similarity index 100% rename from spec/rust/test_nested_type_param.rs rename to spec/rust/src/test_nested_type_param.rs diff --git a/spec/rust/test_opaque_external_type_02_parent.rs b/spec/rust/src/test_opaque_external_type_02_parent.rs similarity index 100% rename from spec/rust/test_opaque_external_type_02_parent.rs rename to spec/rust/src/test_opaque_external_type_02_parent.rs diff --git a/spec/rust/test_optional_id.rs b/spec/rust/src/test_optional_id.rs similarity index 100% rename from spec/rust/test_optional_id.rs rename to spec/rust/src/test_optional_id.rs diff --git a/spec/rust/test_params_call_extra_parens.rs b/spec/rust/src/test_params_call_extra_parens.rs similarity index 100% rename from spec/rust/test_params_call_extra_parens.rs rename to spec/rust/src/test_params_call_extra_parens.rs diff --git a/spec/rust/test_params_pass_array_int.rs b/spec/rust/src/test_params_pass_array_int.rs similarity index 100% rename from spec/rust/test_params_pass_array_int.rs rename to spec/rust/src/test_params_pass_array_int.rs diff --git a/spec/rust/test_params_pass_array_str.rs b/spec/rust/src/test_params_pass_array_str.rs similarity index 100% rename from spec/rust/test_params_pass_array_str.rs rename to spec/rust/src/test_params_pass_array_str.rs diff --git a/spec/rust/test_params_pass_array_struct.rs b/spec/rust/src/test_params_pass_array_struct.rs similarity index 100% rename from spec/rust/test_params_pass_array_struct.rs rename to spec/rust/src/test_params_pass_array_struct.rs diff --git a/spec/rust/test_params_pass_array_usertype.rs b/spec/rust/src/test_params_pass_array_usertype.rs similarity index 100% rename from spec/rust/test_params_pass_array_usertype.rs rename to spec/rust/src/test_params_pass_array_usertype.rs diff --git a/spec/rust/test_params_pass_bool.rs b/spec/rust/src/test_params_pass_bool.rs similarity index 100% rename from spec/rust/test_params_pass_bool.rs rename to spec/rust/src/test_params_pass_bool.rs diff --git a/spec/rust/test_params_pass_struct.rs b/spec/rust/src/test_params_pass_struct.rs similarity index 100% rename from spec/rust/test_params_pass_struct.rs rename to spec/rust/src/test_params_pass_struct.rs diff --git a/spec/rust/test_process_custom_no_args.rs b/spec/rust/src/test_process_custom_no_args.rs similarity index 100% rename from spec/rust/test_process_custom_no_args.rs rename to spec/rust/src/test_process_custom_no_args.rs diff --git a/spec/rust/test_process_repeat_bytes.rs b/spec/rust/src/test_process_repeat_bytes.rs similarity index 100% rename from spec/rust/test_process_repeat_bytes.rs rename to spec/rust/src/test_process_repeat_bytes.rs diff --git a/spec/rust/test_process_repeat_usertype.rs b/spec/rust/src/test_process_repeat_usertype.rs similarity index 100% rename from spec/rust/test_process_repeat_usertype.rs rename to spec/rust/src/test_process_repeat_usertype.rs diff --git a/spec/rust/test_repeat_eos_bit.rs b/spec/rust/src/test_repeat_eos_bit.rs similarity index 100% rename from spec/rust/test_repeat_eos_bit.rs rename to spec/rust/src/test_repeat_eos_bit.rs diff --git a/spec/rust/test_repeat_until_calc_array_type.rs b/spec/rust/src/test_repeat_until_calc_array_type.rs similarity index 100% rename from spec/rust/test_repeat_until_calc_array_type.rs rename to spec/rust/src/test_repeat_until_calc_array_type.rs diff --git a/spec/rust/test_str_encodings_utf16.rs b/spec/rust/src/test_str_encodings_utf16.rs similarity index 100% rename from spec/rust/test_str_encodings_utf16.rs rename to spec/rust/src/test_str_encodings_utf16.rs diff --git a/spec/rust/test_str_eos.rs b/spec/rust/src/test_str_eos.rs similarity index 100% rename from spec/rust/test_str_eos.rs rename to spec/rust/src/test_str_eos.rs diff --git a/spec/rust/test_switch_else_only.rs b/spec/rust/src/test_switch_else_only.rs similarity index 100% rename from spec/rust/test_switch_else_only.rs rename to spec/rust/src/test_switch_else_only.rs diff --git a/spec/rust/test_switch_manual_enum_invalid.rs b/spec/rust/src/test_switch_manual_enum_invalid.rs similarity index 100% rename from spec/rust/test_switch_manual_enum_invalid.rs rename to spec/rust/src/test_switch_manual_enum_invalid.rs diff --git a/spec/rust/test_switch_manual_enum_invalid_else.rs b/spec/rust/src/test_switch_manual_enum_invalid_else.rs similarity index 100% rename from spec/rust/test_switch_manual_enum_invalid_else.rs rename to spec/rust/src/test_switch_manual_enum_invalid_else.rs diff --git a/spec/rust/test_switch_manual_int_size.rs b/spec/rust/src/test_switch_manual_int_size.rs similarity index 100% rename from spec/rust/test_switch_manual_int_size.rs rename to spec/rust/src/test_switch_manual_int_size.rs diff --git a/spec/rust/test_switch_manual_int_size_eos.rs b/spec/rust/src/test_switch_manual_int_size_eos.rs similarity index 100% rename from spec/rust/test_switch_manual_int_size_eos.rs rename to spec/rust/src/test_switch_manual_int_size_eos.rs diff --git a/spec/rust/test_switch_multi_bool_ops.rs b/spec/rust/src/test_switch_multi_bool_ops.rs similarity index 100% rename from spec/rust/test_switch_multi_bool_ops.rs rename to spec/rust/src/test_switch_multi_bool_ops.rs diff --git a/spec/rust/test_switch_repeat_expr.rs b/spec/rust/src/test_switch_repeat_expr.rs similarity index 100% rename from spec/rust/test_switch_repeat_expr.rs rename to spec/rust/src/test_switch_repeat_expr.rs diff --git a/spec/rust/test_switch_repeat_expr_invalid.rs b/spec/rust/src/test_switch_repeat_expr_invalid.rs similarity index 100% rename from spec/rust/test_switch_repeat_expr_invalid.rs rename to spec/rust/src/test_switch_repeat_expr_invalid.rs diff --git a/spec/rust/test_term_u1_val.rs b/spec/rust/src/test_term_u1_val.rs similarity index 100% rename from spec/rust/test_term_u1_val.rs rename to spec/rust/src/test_term_u1_val.rs diff --git a/spec/rust/test_type_ternary_2nd_falsy.rs b/spec/rust/src/test_type_ternary_2nd_falsy.rs similarity index 100% rename from spec/rust/test_type_ternary_2nd_falsy.rs rename to spec/rust/src/test_type_ternary_2nd_falsy.rs diff --git a/spec/rust/test_valid_eq_str_encodings.rs b/spec/rust/src/test_valid_eq_str_encodings.rs similarity index 100% rename from spec/rust/test_valid_eq_str_encodings.rs rename to spec/rust/src/test_valid_eq_str_encodings.rs diff --git a/spec/rust/test_valid_long.rs b/spec/rust/src/test_valid_long.rs similarity index 100% rename from spec/rust/test_valid_long.rs rename to spec/rust/src/test_valid_long.rs diff --git a/spec/rust/test_valid_not_parsed_if.rs b/spec/rust/src/test_valid_not_parsed_if.rs similarity index 100% rename from spec/rust/test_valid_not_parsed_if.rs rename to spec/rust/src/test_valid_not_parsed_if.rs diff --git a/spec/rust/test_valid_short.rs b/spec/rust/src/test_valid_short.rs similarity index 100% rename from spec/rust/test_valid_short.rs rename to spec/rust/src/test_valid_short.rs diff --git a/spec/rust/test_valid_switch.rs b/spec/rust/src/test_valid_switch.rs similarity index 100% rename from spec/rust/test_valid_switch.rs rename to spec/rust/src/test_valid_switch.rs diff --git a/spec/rust/test_yaml_ints.rs b/spec/rust/src/test_yaml_ints.rs similarity index 100% rename from spec/rust/test_yaml_ints.rs rename to spec/rust/src/test_yaml_ints.rs diff --git a/spec/rust/test_zlib_surrounded.rs b/spec/rust/src/test_zlib_surrounded.rs similarity index 100% rename from spec/rust/test_zlib_surrounded.rs rename to spec/rust/src/test_zlib_surrounded.rs From 5bc4021da527c09721dc0071bc65e2e2fe46ed74 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Fri, 22 Jul 2022 15:53:53 +0200 Subject: [PATCH 006/198] standard rust structure --- spec/rust/{ => src}/formats/bcd_user_type_be.rs | 0 spec/rust/{ => src}/formats/bcd_user_type_le.rs | 0 spec/rust/{ => src}/formats/bits_byte_aligned.rs | 0 spec/rust/{ => src}/formats/bits_enum.rs | 0 spec/rust/{ => src}/formats/bits_seq_endian_combo.rs | 0 spec/rust/{ => src}/formats/bits_shift_by_b32_le.rs | 0 spec/rust/{ => src}/formats/bits_shift_by_b64_le.rs | 0 spec/rust/{ => src}/formats/bits_signed_res_b32_be.rs | 0 spec/rust/{ => src}/formats/bits_signed_res_b32_le.rs | 0 spec/rust/{ => src}/formats/bits_signed_shift_b32_le.rs | 0 spec/rust/{ => src}/formats/bits_signed_shift_b64_le.rs | 0 spec/rust/{ => src}/formats/bits_simple.rs | 0 spec/rust/{ => src}/formats/bits_simple_le.rs | 0 spec/rust/{ => src}/formats/bits_unaligned_b32_be.rs | 0 spec/rust/{ => src}/formats/bits_unaligned_b32_le.rs | 0 spec/rust/{ => src}/formats/bits_unaligned_b64_be.rs | 0 spec/rust/{ => src}/formats/bits_unaligned_b64_le.rs | 0 spec/rust/{ => src}/formats/buffered_struct.rs | 0 spec/rust/{ => src}/formats/bytes_pad_term.rs | 0 spec/rust/{ => src}/formats/cast_nested.rs | 0 spec/rust/{ => src}/formats/cast_to_imported.rs | 0 spec/rust/{ => src}/formats/cast_to_top.rs | 0 spec/rust/{ => src}/formats/combine_bool.rs | 0 spec/rust/{ => src}/formats/combine_bytes.rs | 0 spec/rust/{ => src}/formats/combine_enum.rs | 0 spec/rust/{ => src}/formats/combine_str.rs | 0 spec/rust/{ => src}/formats/debug_0.rs | 0 spec/rust/{ => src}/formats/default_big_endian.rs | 0 spec/rust/{ => src}/formats/default_bit_endian_mod.rs | 0 spec/rust/{ => src}/formats/default_endian_expr_exception.rs | 0 spec/rust/{ => src}/formats/default_endian_expr_inherited.rs | 0 spec/rust/{ => src}/formats/default_endian_expr_is_be.rs | 0 spec/rust/{ => src}/formats/default_endian_expr_is_le.rs | 0 spec/rust/{ => src}/formats/default_endian_mod.rs | 0 spec/rust/{ => src}/formats/docstrings.rs | 0 spec/rust/{ => src}/formats/docstrings_docref.rs | 0 spec/rust/{ => src}/formats/docstrings_docref_multi.rs | 0 spec/rust/{ => src}/formats/enum_0.rs | 0 spec/rust/{ => src}/formats/enum_1.rs | 0 spec/rust/{ => src}/formats/enum_deep.rs | 0 spec/rust/{ => src}/formats/enum_deep_literals.rs | 0 spec/rust/{ => src}/formats/enum_fancy.rs | 0 spec/rust/{ => src}/formats/enum_for_unknown_id.rs | 0 spec/rust/{ => src}/formats/enum_if.rs | 0 spec/rust/{ => src}/formats/enum_import.rs | 0 spec/rust/{ => src}/formats/enum_int_range_s.rs | 0 spec/rust/{ => src}/formats/enum_int_range_u.rs | 0 spec/rust/{ => src}/formats/enum_invalid.rs | 0 spec/rust/{ => src}/formats/enum_long_range_s.rs | 0 spec/rust/{ => src}/formats/enum_long_range_u.rs | 0 spec/rust/{ => src}/formats/enum_negative.rs | 0 spec/rust/{ => src}/formats/enum_of_value_inst.rs | 0 spec/rust/{ => src}/formats/enum_to_i.rs | 0 spec/rust/{ => src}/formats/enum_to_i_class_border_1.rs | 0 spec/rust/{ => src}/formats/enum_to_i_class_border_2.rs | 0 spec/rust/{ => src}/formats/eof_exception_bytes.rs | 0 spec/rust/{ => src}/formats/eof_exception_u4.rs | 0 spec/rust/{ => src}/formats/eos_exception_bytes.rs | 0 spec/rust/{ => src}/formats/eos_exception_u4.rs | 0 spec/rust/{ => src}/formats/expr_0.rs | 0 spec/rust/{ => src}/formats/expr_1.rs | 0 spec/rust/{ => src}/formats/expr_2.rs | 0 spec/rust/{ => src}/formats/expr_3.rs | 0 spec/rust/{ => src}/formats/expr_array.rs | 0 spec/rust/{ => src}/formats/expr_bits.rs | 0 spec/rust/{ => src}/formats/expr_bytes_cmp.rs | 0 spec/rust/{ => src}/formats/expr_bytes_non_literal.rs | 0 spec/rust/{ => src}/formats/expr_bytes_ops.rs | 0 spec/rust/{ => src}/formats/expr_enum.rs | 0 spec/rust/{ => src}/formats/expr_if_int_ops.rs | 0 spec/rust/{ => src}/formats/expr_int_div.rs | 0 spec/rust/{ => src}/formats/expr_io_eof.rs | 0 spec/rust/{ => src}/formats/expr_io_pos.rs | 0 spec/rust/{ => src}/formats/expr_mod.rs | 0 spec/rust/{ => src}/formats/expr_ops_parens.rs | 0 spec/rust/{ => src}/formats/expr_sizeof_type_0.rs | 0 spec/rust/{ => src}/formats/expr_sizeof_type_1.rs | 0 spec/rust/{ => src}/formats/expr_sizeof_value_0.rs | 0 spec/rust/{ => src}/formats/expr_sizeof_value_sized.rs | 0 spec/rust/{ => src}/formats/expr_str_encodings.rs | 0 spec/rust/{ => src}/formats/expr_str_ops.rs | 0 spec/rust/{ => src}/formats/fixed_contents.rs | 0 spec/rust/{ => src}/formats/fixed_struct.rs | 0 spec/rust/{ => src}/formats/float_to_i.rs | 0 spec/rust/{ => src}/formats/floating_points.rs | 0 spec/rust/{ => src}/formats/hello_world.rs | 0 spec/rust/{ => src}/formats/if_instances.rs | 0 spec/rust/{ => src}/formats/if_struct.rs | 0 spec/rust/{ => src}/formats/if_values.rs | 0 spec/rust/{ => src}/formats/imported_1.rs | 0 spec/rust/{ => src}/formats/imported_2.rs | 0 spec/rust/{ => src}/formats/imports0.rs | 0 spec/rust/{ => src}/formats/imports_circular_a.rs | 0 spec/rust/{ => src}/formats/imports_circular_b.rs | 0 spec/rust/{ => src}/formats/imports_rel_1.rs | 0 spec/rust/{ => src}/formats/index_sizes.rs | 0 spec/rust/{ => src}/formats/index_to_param_eos.rs | 0 spec/rust/{ => src}/formats/index_to_param_expr.rs | 0 spec/rust/{ => src}/formats/index_to_param_until.rs | 0 spec/rust/{ => src}/formats/instance_std.rs | 0 spec/rust/{ => src}/formats/instance_std_array.rs | 0 spec/rust/{ => src}/formats/instance_user_array.rs | 0 spec/rust/{ => src}/formats/integers.rs | 0 spec/rust/{ => src}/formats/integers_double_overflow.rs | 0 spec/rust/{ => src}/formats/integers_min_max.rs | 0 spec/rust/{ => src}/formats/io_local_var.rs | 0 spec/rust/{ => src}/formats/js_signed_right_shift.rs | 0 spec/rust/{ => src}/formats/meta_tags.rs | 0 spec/rust/{ => src}/formats/meta_xref.rs | 0 spec/rust/{ => src}/formats/multiple_use.rs | 0 spec/rust/{ => src}/formats/nav_parent.rs | 0 spec/rust/{ => src}/formats/nav_parent2.rs | 0 spec/rust/{ => src}/formats/nav_parent3.rs | 0 spec/rust/{ => src}/formats/nav_parent_false.rs | 0 spec/rust/{ => src}/formats/nav_parent_false2.rs | 0 spec/rust/{ => src}/formats/nav_parent_override.rs | 0 spec/rust/{ => src}/formats/nav_parent_switch.rs | 0 spec/rust/{ => src}/formats/nav_parent_switch_cast.rs | 0 spec/rust/{ => src}/formats/nav_parent_vs_value_inst.rs | 0 spec/rust/{ => src}/formats/nav_root.rs | 0 spec/rust/{ => src}/formats/nested_same_name.rs | 0 spec/rust/{ => src}/formats/nested_same_name2.rs | 0 spec/rust/{ => src}/formats/nested_type_param.rs | 0 spec/rust/{ => src}/formats/nested_types.rs | 0 spec/rust/{ => src}/formats/nested_types2.rs | 0 spec/rust/{ => src}/formats/nested_types3.rs | 0 spec/rust/{ => src}/formats/non_standard.rs | 0 spec/rust/{ => src}/formats/opaque_external_type.rs | 0 spec/rust/{ => src}/formats/opaque_external_type_02_child.rs | 0 spec/rust/{ => src}/formats/opaque_external_type_02_parent.rs | 0 spec/rust/{ => src}/formats/opaque_with_param.rs | 0 spec/rust/{ => src}/formats/optional_id.rs | 0 spec/rust/{ => src}/formats/params_call_extra_parens.rs | 0 spec/rust/{ => src}/formats/params_call_short.rs | 0 spec/rust/{ => src}/formats/params_def.rs | 0 spec/rust/{ => src}/formats/params_enum.rs | 0 spec/rust/{ => src}/formats/params_pass_array_usertype.rs | 0 spec/rust/{ => src}/formats/params_pass_bool.rs | 0 spec/rust/{ => src}/formats/params_pass_usertype.rs | 0 spec/rust/{ => src}/formats/position_abs.rs | 0 spec/rust/{ => src}/formats/position_in_seq.rs | 0 spec/rust/{ => src}/formats/position_to_end.rs | 0 spec/rust/{ => src}/formats/process_coerce_bytes.rs | 0 spec/rust/{ => src}/formats/process_coerce_usertype1.rs | 0 spec/rust/{ => src}/formats/process_coerce_usertype2.rs | 0 spec/rust/{ => src}/formats/process_custom.rs | 0 spec/rust/{ => src}/formats/process_custom_no_args.rs | 0 spec/rust/{ => src}/formats/process_repeat_bytes.rs | 0 spec/rust/{ => src}/formats/process_repeat_usertype.rs | 0 spec/rust/{ => src}/formats/process_rotate.rs | 0 spec/rust/{ => src}/formats/process_to_user.rs | 0 spec/rust/{ => src}/formats/process_xor4_const.rs | 0 spec/rust/{ => src}/formats/process_xor4_value.rs | 0 spec/rust/{ => src}/formats/process_xor_const.rs | 0 spec/rust/{ => src}/formats/process_xor_value.rs | 0 spec/rust/{ => src}/formats/recursive_one.rs | 0 spec/rust/{ => src}/formats/repeat_eos_bit.rs | 0 spec/rust/{ => src}/formats/repeat_eos_struct.rs | 0 spec/rust/{ => src}/formats/repeat_eos_u4.rs | 0 spec/rust/{ => src}/formats/repeat_n_struct.rs | 0 spec/rust/{ => src}/formats/repeat_n_strz.rs | 0 spec/rust/{ => src}/formats/repeat_n_strz_double.rs | 0 spec/rust/{ => src}/formats/repeat_until_complex.rs | 0 spec/rust/{ => src}/formats/repeat_until_s4.rs | 0 spec/rust/{ => src}/formats/repeat_until_sized.rs | 0 spec/rust/{ => src}/formats/str_encodings.rs | 0 spec/rust/{ => src}/formats/str_encodings_default.rs | 0 spec/rust/{ => src}/formats/str_encodings_utf16.rs | 0 spec/rust/{ => src}/formats/str_eos.rs | 0 spec/rust/{ => src}/formats/str_literals.rs | 0 spec/rust/{ => src}/formats/str_literals2.rs | 0 spec/rust/{ => src}/formats/str_pad_term.rs | 0 spec/rust/{ => src}/formats/str_pad_term_empty.rs | 0 spec/rust/{ => src}/formats/switch_bytearray.rs | 0 spec/rust/{ => src}/formats/switch_cast.rs | 0 spec/rust/{ => src}/formats/switch_else_only.rs | 0 spec/rust/{ => src}/formats/switch_integers.rs | 0 spec/rust/{ => src}/formats/switch_integers2.rs | 0 spec/rust/{ => src}/formats/switch_manual_enum.rs | 0 spec/rust/{ => src}/formats/switch_manual_enum_invalid.rs | 0 spec/rust/{ => src}/formats/switch_manual_enum_invalid_else.rs | 0 spec/rust/{ => src}/formats/switch_manual_int.rs | 0 spec/rust/{ => src}/formats/switch_manual_int_else.rs | 0 spec/rust/{ => src}/formats/switch_manual_int_size.rs | 0 spec/rust/{ => src}/formats/switch_manual_int_size_else.rs | 0 spec/rust/{ => src}/formats/switch_manual_str.rs | 0 spec/rust/{ => src}/formats/switch_manual_str_else.rs | 0 spec/rust/{ => src}/formats/switch_multi_bool_ops.rs | 0 spec/rust/{ => src}/formats/switch_repeat_expr.rs | 0 spec/rust/{ => src}/formats/switch_repeat_expr_invalid.rs | 0 spec/rust/{ => src}/formats/term_bytes.rs | 0 spec/rust/{ => src}/formats/term_strz.rs | 0 spec/rust/{ => src}/formats/term_u1_val.rs | 0 spec/rust/{ => src}/formats/to_string_custom.rs | 0 spec/rust/{ => src}/formats/ts_packet_header.rs | 0 spec/rust/{ => src}/formats/type_int_unary_op.rs | 0 spec/rust/{ => src}/formats/type_ternary.rs | 0 spec/rust/{ => src}/formats/type_ternary_opaque.rs | 0 spec/rust/{ => src}/formats/user_type.rs | 0 spec/rust/{ => src}/formats/valid_eq_str_encodings.rs | 0 spec/rust/{ => src}/formats/valid_fail_anyof_int.rs | 0 spec/rust/{ => src}/formats/valid_fail_contents.rs | 0 spec/rust/{ => src}/formats/valid_fail_eq_bytes.rs | 0 spec/rust/{ => src}/formats/valid_fail_eq_int.rs | 0 spec/rust/{ => src}/formats/valid_fail_eq_str.rs | 0 spec/rust/{ => src}/formats/valid_fail_expr.rs | 0 spec/rust/{ => src}/formats/valid_fail_inst.rs | 0 spec/rust/{ => src}/formats/valid_fail_max_int.rs | 0 spec/rust/{ => src}/formats/valid_fail_min_int.rs | 0 spec/rust/{ => src}/formats/valid_fail_range_bytes.rs | 0 spec/rust/{ => src}/formats/valid_fail_range_float.rs | 0 spec/rust/{ => src}/formats/valid_fail_range_int.rs | 0 spec/rust/{ => src}/formats/valid_fail_range_str.rs | 0 spec/rust/{ => src}/formats/valid_long.rs | 0 spec/rust/{ => src}/formats/valid_not_parsed_if.rs | 0 spec/rust/{ => src}/formats/valid_optional_id.rs | 0 spec/rust/{ => src}/formats/valid_short.rs | 0 spec/rust/{ => src}/formats/valid_switch.rs | 0 spec/rust/{ => src}/formats/yaml_ints.rs | 0 spec/rust/{ => src}/formats/zlib_surrounded.rs | 0 spec/rust/{ => src}/formats/zlib_with_header_78.rs | 0 221 files changed, 0 insertions(+), 0 deletions(-) rename spec/rust/{ => src}/formats/bcd_user_type_be.rs (100%) rename spec/rust/{ => src}/formats/bcd_user_type_le.rs (100%) rename spec/rust/{ => src}/formats/bits_byte_aligned.rs (100%) rename spec/rust/{ => src}/formats/bits_enum.rs (100%) rename spec/rust/{ => src}/formats/bits_seq_endian_combo.rs (100%) rename spec/rust/{ => src}/formats/bits_shift_by_b32_le.rs (100%) rename spec/rust/{ => src}/formats/bits_shift_by_b64_le.rs (100%) rename spec/rust/{ => src}/formats/bits_signed_res_b32_be.rs (100%) rename spec/rust/{ => src}/formats/bits_signed_res_b32_le.rs (100%) rename spec/rust/{ => src}/formats/bits_signed_shift_b32_le.rs (100%) rename spec/rust/{ => src}/formats/bits_signed_shift_b64_le.rs (100%) rename spec/rust/{ => src}/formats/bits_simple.rs (100%) rename spec/rust/{ => src}/formats/bits_simple_le.rs (100%) rename spec/rust/{ => src}/formats/bits_unaligned_b32_be.rs (100%) rename spec/rust/{ => src}/formats/bits_unaligned_b32_le.rs (100%) rename spec/rust/{ => src}/formats/bits_unaligned_b64_be.rs (100%) rename spec/rust/{ => src}/formats/bits_unaligned_b64_le.rs (100%) rename spec/rust/{ => src}/formats/buffered_struct.rs (100%) rename spec/rust/{ => src}/formats/bytes_pad_term.rs (100%) rename spec/rust/{ => src}/formats/cast_nested.rs (100%) rename spec/rust/{ => src}/formats/cast_to_imported.rs (100%) rename spec/rust/{ => src}/formats/cast_to_top.rs (100%) rename spec/rust/{ => src}/formats/combine_bool.rs (100%) rename spec/rust/{ => src}/formats/combine_bytes.rs (100%) rename spec/rust/{ => src}/formats/combine_enum.rs (100%) rename spec/rust/{ => src}/formats/combine_str.rs (100%) rename spec/rust/{ => src}/formats/debug_0.rs (100%) rename spec/rust/{ => src}/formats/default_big_endian.rs (100%) rename spec/rust/{ => src}/formats/default_bit_endian_mod.rs (100%) rename spec/rust/{ => src}/formats/default_endian_expr_exception.rs (100%) rename spec/rust/{ => src}/formats/default_endian_expr_inherited.rs (100%) rename spec/rust/{ => src}/formats/default_endian_expr_is_be.rs (100%) rename spec/rust/{ => src}/formats/default_endian_expr_is_le.rs (100%) rename spec/rust/{ => src}/formats/default_endian_mod.rs (100%) rename spec/rust/{ => src}/formats/docstrings.rs (100%) rename spec/rust/{ => src}/formats/docstrings_docref.rs (100%) rename spec/rust/{ => src}/formats/docstrings_docref_multi.rs (100%) rename spec/rust/{ => src}/formats/enum_0.rs (100%) rename spec/rust/{ => src}/formats/enum_1.rs (100%) rename spec/rust/{ => src}/formats/enum_deep.rs (100%) rename spec/rust/{ => src}/formats/enum_deep_literals.rs (100%) rename spec/rust/{ => src}/formats/enum_fancy.rs (100%) rename spec/rust/{ => src}/formats/enum_for_unknown_id.rs (100%) rename spec/rust/{ => src}/formats/enum_if.rs (100%) rename spec/rust/{ => src}/formats/enum_import.rs (100%) rename spec/rust/{ => src}/formats/enum_int_range_s.rs (100%) rename spec/rust/{ => src}/formats/enum_int_range_u.rs (100%) rename spec/rust/{ => src}/formats/enum_invalid.rs (100%) rename spec/rust/{ => src}/formats/enum_long_range_s.rs (100%) rename spec/rust/{ => src}/formats/enum_long_range_u.rs (100%) rename spec/rust/{ => src}/formats/enum_negative.rs (100%) rename spec/rust/{ => src}/formats/enum_of_value_inst.rs (100%) rename spec/rust/{ => src}/formats/enum_to_i.rs (100%) rename spec/rust/{ => src}/formats/enum_to_i_class_border_1.rs (100%) rename spec/rust/{ => src}/formats/enum_to_i_class_border_2.rs (100%) rename spec/rust/{ => src}/formats/eof_exception_bytes.rs (100%) rename spec/rust/{ => src}/formats/eof_exception_u4.rs (100%) rename spec/rust/{ => src}/formats/eos_exception_bytes.rs (100%) rename spec/rust/{ => src}/formats/eos_exception_u4.rs (100%) rename spec/rust/{ => src}/formats/expr_0.rs (100%) rename spec/rust/{ => src}/formats/expr_1.rs (100%) rename spec/rust/{ => src}/formats/expr_2.rs (100%) rename spec/rust/{ => src}/formats/expr_3.rs (100%) rename spec/rust/{ => src}/formats/expr_array.rs (100%) rename spec/rust/{ => src}/formats/expr_bits.rs (100%) rename spec/rust/{ => src}/formats/expr_bytes_cmp.rs (100%) rename spec/rust/{ => src}/formats/expr_bytes_non_literal.rs (100%) rename spec/rust/{ => src}/formats/expr_bytes_ops.rs (100%) rename spec/rust/{ => src}/formats/expr_enum.rs (100%) rename spec/rust/{ => src}/formats/expr_if_int_ops.rs (100%) rename spec/rust/{ => src}/formats/expr_int_div.rs (100%) rename spec/rust/{ => src}/formats/expr_io_eof.rs (100%) rename spec/rust/{ => src}/formats/expr_io_pos.rs (100%) rename spec/rust/{ => src}/formats/expr_mod.rs (100%) rename spec/rust/{ => src}/formats/expr_ops_parens.rs (100%) rename spec/rust/{ => src}/formats/expr_sizeof_type_0.rs (100%) rename spec/rust/{ => src}/formats/expr_sizeof_type_1.rs (100%) rename spec/rust/{ => src}/formats/expr_sizeof_value_0.rs (100%) rename spec/rust/{ => src}/formats/expr_sizeof_value_sized.rs (100%) rename spec/rust/{ => src}/formats/expr_str_encodings.rs (100%) rename spec/rust/{ => src}/formats/expr_str_ops.rs (100%) rename spec/rust/{ => src}/formats/fixed_contents.rs (100%) rename spec/rust/{ => src}/formats/fixed_struct.rs (100%) rename spec/rust/{ => src}/formats/float_to_i.rs (100%) rename spec/rust/{ => src}/formats/floating_points.rs (100%) rename spec/rust/{ => src}/formats/hello_world.rs (100%) rename spec/rust/{ => src}/formats/if_instances.rs (100%) rename spec/rust/{ => src}/formats/if_struct.rs (100%) rename spec/rust/{ => src}/formats/if_values.rs (100%) rename spec/rust/{ => src}/formats/imported_1.rs (100%) rename spec/rust/{ => src}/formats/imported_2.rs (100%) rename spec/rust/{ => src}/formats/imports0.rs (100%) rename spec/rust/{ => src}/formats/imports_circular_a.rs (100%) rename spec/rust/{ => src}/formats/imports_circular_b.rs (100%) rename spec/rust/{ => src}/formats/imports_rel_1.rs (100%) rename spec/rust/{ => src}/formats/index_sizes.rs (100%) rename spec/rust/{ => src}/formats/index_to_param_eos.rs (100%) rename spec/rust/{ => src}/formats/index_to_param_expr.rs (100%) rename spec/rust/{ => src}/formats/index_to_param_until.rs (100%) rename spec/rust/{ => src}/formats/instance_std.rs (100%) rename spec/rust/{ => src}/formats/instance_std_array.rs (100%) rename spec/rust/{ => src}/formats/instance_user_array.rs (100%) rename spec/rust/{ => src}/formats/integers.rs (100%) rename spec/rust/{ => src}/formats/integers_double_overflow.rs (100%) rename spec/rust/{ => src}/formats/integers_min_max.rs (100%) rename spec/rust/{ => src}/formats/io_local_var.rs (100%) rename spec/rust/{ => src}/formats/js_signed_right_shift.rs (100%) rename spec/rust/{ => src}/formats/meta_tags.rs (100%) rename spec/rust/{ => src}/formats/meta_xref.rs (100%) rename spec/rust/{ => src}/formats/multiple_use.rs (100%) rename spec/rust/{ => src}/formats/nav_parent.rs (100%) rename spec/rust/{ => src}/formats/nav_parent2.rs (100%) rename spec/rust/{ => src}/formats/nav_parent3.rs (100%) rename spec/rust/{ => src}/formats/nav_parent_false.rs (100%) rename spec/rust/{ => src}/formats/nav_parent_false2.rs (100%) rename spec/rust/{ => src}/formats/nav_parent_override.rs (100%) rename spec/rust/{ => src}/formats/nav_parent_switch.rs (100%) rename spec/rust/{ => src}/formats/nav_parent_switch_cast.rs (100%) rename spec/rust/{ => src}/formats/nav_parent_vs_value_inst.rs (100%) rename spec/rust/{ => src}/formats/nav_root.rs (100%) rename spec/rust/{ => src}/formats/nested_same_name.rs (100%) rename spec/rust/{ => src}/formats/nested_same_name2.rs (100%) rename spec/rust/{ => src}/formats/nested_type_param.rs (100%) rename spec/rust/{ => src}/formats/nested_types.rs (100%) rename spec/rust/{ => src}/formats/nested_types2.rs (100%) rename spec/rust/{ => src}/formats/nested_types3.rs (100%) rename spec/rust/{ => src}/formats/non_standard.rs (100%) rename spec/rust/{ => src}/formats/opaque_external_type.rs (100%) rename spec/rust/{ => src}/formats/opaque_external_type_02_child.rs (100%) rename spec/rust/{ => src}/formats/opaque_external_type_02_parent.rs (100%) rename spec/rust/{ => src}/formats/opaque_with_param.rs (100%) rename spec/rust/{ => src}/formats/optional_id.rs (100%) rename spec/rust/{ => src}/formats/params_call_extra_parens.rs (100%) rename spec/rust/{ => src}/formats/params_call_short.rs (100%) rename spec/rust/{ => src}/formats/params_def.rs (100%) rename spec/rust/{ => src}/formats/params_enum.rs (100%) rename spec/rust/{ => src}/formats/params_pass_array_usertype.rs (100%) rename spec/rust/{ => src}/formats/params_pass_bool.rs (100%) rename spec/rust/{ => src}/formats/params_pass_usertype.rs (100%) rename spec/rust/{ => src}/formats/position_abs.rs (100%) rename spec/rust/{ => src}/formats/position_in_seq.rs (100%) rename spec/rust/{ => src}/formats/position_to_end.rs (100%) rename spec/rust/{ => src}/formats/process_coerce_bytes.rs (100%) rename spec/rust/{ => src}/formats/process_coerce_usertype1.rs (100%) rename spec/rust/{ => src}/formats/process_coerce_usertype2.rs (100%) rename spec/rust/{ => src}/formats/process_custom.rs (100%) rename spec/rust/{ => src}/formats/process_custom_no_args.rs (100%) rename spec/rust/{ => src}/formats/process_repeat_bytes.rs (100%) rename spec/rust/{ => src}/formats/process_repeat_usertype.rs (100%) rename spec/rust/{ => src}/formats/process_rotate.rs (100%) rename spec/rust/{ => src}/formats/process_to_user.rs (100%) rename spec/rust/{ => src}/formats/process_xor4_const.rs (100%) rename spec/rust/{ => src}/formats/process_xor4_value.rs (100%) rename spec/rust/{ => src}/formats/process_xor_const.rs (100%) rename spec/rust/{ => src}/formats/process_xor_value.rs (100%) rename spec/rust/{ => src}/formats/recursive_one.rs (100%) rename spec/rust/{ => src}/formats/repeat_eos_bit.rs (100%) rename spec/rust/{ => src}/formats/repeat_eos_struct.rs (100%) rename spec/rust/{ => src}/formats/repeat_eos_u4.rs (100%) rename spec/rust/{ => src}/formats/repeat_n_struct.rs (100%) rename spec/rust/{ => src}/formats/repeat_n_strz.rs (100%) rename spec/rust/{ => src}/formats/repeat_n_strz_double.rs (100%) rename spec/rust/{ => src}/formats/repeat_until_complex.rs (100%) rename spec/rust/{ => src}/formats/repeat_until_s4.rs (100%) rename spec/rust/{ => src}/formats/repeat_until_sized.rs (100%) rename spec/rust/{ => src}/formats/str_encodings.rs (100%) rename spec/rust/{ => src}/formats/str_encodings_default.rs (100%) rename spec/rust/{ => src}/formats/str_encodings_utf16.rs (100%) rename spec/rust/{ => src}/formats/str_eos.rs (100%) rename spec/rust/{ => src}/formats/str_literals.rs (100%) rename spec/rust/{ => src}/formats/str_literals2.rs (100%) rename spec/rust/{ => src}/formats/str_pad_term.rs (100%) rename spec/rust/{ => src}/formats/str_pad_term_empty.rs (100%) rename spec/rust/{ => src}/formats/switch_bytearray.rs (100%) rename spec/rust/{ => src}/formats/switch_cast.rs (100%) rename spec/rust/{ => src}/formats/switch_else_only.rs (100%) rename spec/rust/{ => src}/formats/switch_integers.rs (100%) rename spec/rust/{ => src}/formats/switch_integers2.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_enum.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_enum_invalid.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_enum_invalid_else.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_int.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_int_else.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_int_size.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_int_size_else.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_str.rs (100%) rename spec/rust/{ => src}/formats/switch_manual_str_else.rs (100%) rename spec/rust/{ => src}/formats/switch_multi_bool_ops.rs (100%) rename spec/rust/{ => src}/formats/switch_repeat_expr.rs (100%) rename spec/rust/{ => src}/formats/switch_repeat_expr_invalid.rs (100%) rename spec/rust/{ => src}/formats/term_bytes.rs (100%) rename spec/rust/{ => src}/formats/term_strz.rs (100%) rename spec/rust/{ => src}/formats/term_u1_val.rs (100%) rename spec/rust/{ => src}/formats/to_string_custom.rs (100%) rename spec/rust/{ => src}/formats/ts_packet_header.rs (100%) rename spec/rust/{ => src}/formats/type_int_unary_op.rs (100%) rename spec/rust/{ => src}/formats/type_ternary.rs (100%) rename spec/rust/{ => src}/formats/type_ternary_opaque.rs (100%) rename spec/rust/{ => src}/formats/user_type.rs (100%) rename spec/rust/{ => src}/formats/valid_eq_str_encodings.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_anyof_int.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_contents.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_eq_bytes.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_eq_int.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_eq_str.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_expr.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_inst.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_max_int.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_min_int.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_range_bytes.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_range_float.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_range_int.rs (100%) rename spec/rust/{ => src}/formats/valid_fail_range_str.rs (100%) rename spec/rust/{ => src}/formats/valid_long.rs (100%) rename spec/rust/{ => src}/formats/valid_not_parsed_if.rs (100%) rename spec/rust/{ => src}/formats/valid_optional_id.rs (100%) rename spec/rust/{ => src}/formats/valid_short.rs (100%) rename spec/rust/{ => src}/formats/valid_switch.rs (100%) rename spec/rust/{ => src}/formats/yaml_ints.rs (100%) rename spec/rust/{ => src}/formats/zlib_surrounded.rs (100%) rename spec/rust/{ => src}/formats/zlib_with_header_78.rs (100%) diff --git a/spec/rust/formats/bcd_user_type_be.rs b/spec/rust/src/formats/bcd_user_type_be.rs similarity index 100% rename from spec/rust/formats/bcd_user_type_be.rs rename to spec/rust/src/formats/bcd_user_type_be.rs diff --git a/spec/rust/formats/bcd_user_type_le.rs b/spec/rust/src/formats/bcd_user_type_le.rs similarity index 100% rename from spec/rust/formats/bcd_user_type_le.rs rename to spec/rust/src/formats/bcd_user_type_le.rs diff --git a/spec/rust/formats/bits_byte_aligned.rs b/spec/rust/src/formats/bits_byte_aligned.rs similarity index 100% rename from spec/rust/formats/bits_byte_aligned.rs rename to spec/rust/src/formats/bits_byte_aligned.rs diff --git a/spec/rust/formats/bits_enum.rs b/spec/rust/src/formats/bits_enum.rs similarity index 100% rename from spec/rust/formats/bits_enum.rs rename to spec/rust/src/formats/bits_enum.rs diff --git a/spec/rust/formats/bits_seq_endian_combo.rs b/spec/rust/src/formats/bits_seq_endian_combo.rs similarity index 100% rename from spec/rust/formats/bits_seq_endian_combo.rs rename to spec/rust/src/formats/bits_seq_endian_combo.rs diff --git a/spec/rust/formats/bits_shift_by_b32_le.rs b/spec/rust/src/formats/bits_shift_by_b32_le.rs similarity index 100% rename from spec/rust/formats/bits_shift_by_b32_le.rs rename to spec/rust/src/formats/bits_shift_by_b32_le.rs diff --git a/spec/rust/formats/bits_shift_by_b64_le.rs b/spec/rust/src/formats/bits_shift_by_b64_le.rs similarity index 100% rename from spec/rust/formats/bits_shift_by_b64_le.rs rename to spec/rust/src/formats/bits_shift_by_b64_le.rs diff --git a/spec/rust/formats/bits_signed_res_b32_be.rs b/spec/rust/src/formats/bits_signed_res_b32_be.rs similarity index 100% rename from spec/rust/formats/bits_signed_res_b32_be.rs rename to spec/rust/src/formats/bits_signed_res_b32_be.rs diff --git a/spec/rust/formats/bits_signed_res_b32_le.rs b/spec/rust/src/formats/bits_signed_res_b32_le.rs similarity index 100% rename from spec/rust/formats/bits_signed_res_b32_le.rs rename to spec/rust/src/formats/bits_signed_res_b32_le.rs diff --git a/spec/rust/formats/bits_signed_shift_b32_le.rs b/spec/rust/src/formats/bits_signed_shift_b32_le.rs similarity index 100% rename from spec/rust/formats/bits_signed_shift_b32_le.rs rename to spec/rust/src/formats/bits_signed_shift_b32_le.rs diff --git a/spec/rust/formats/bits_signed_shift_b64_le.rs b/spec/rust/src/formats/bits_signed_shift_b64_le.rs similarity index 100% rename from spec/rust/formats/bits_signed_shift_b64_le.rs rename to spec/rust/src/formats/bits_signed_shift_b64_le.rs diff --git a/spec/rust/formats/bits_simple.rs b/spec/rust/src/formats/bits_simple.rs similarity index 100% rename from spec/rust/formats/bits_simple.rs rename to spec/rust/src/formats/bits_simple.rs diff --git a/spec/rust/formats/bits_simple_le.rs b/spec/rust/src/formats/bits_simple_le.rs similarity index 100% rename from spec/rust/formats/bits_simple_le.rs rename to spec/rust/src/formats/bits_simple_le.rs diff --git a/spec/rust/formats/bits_unaligned_b32_be.rs b/spec/rust/src/formats/bits_unaligned_b32_be.rs similarity index 100% rename from spec/rust/formats/bits_unaligned_b32_be.rs rename to spec/rust/src/formats/bits_unaligned_b32_be.rs diff --git a/spec/rust/formats/bits_unaligned_b32_le.rs b/spec/rust/src/formats/bits_unaligned_b32_le.rs similarity index 100% rename from spec/rust/formats/bits_unaligned_b32_le.rs rename to spec/rust/src/formats/bits_unaligned_b32_le.rs diff --git a/spec/rust/formats/bits_unaligned_b64_be.rs b/spec/rust/src/formats/bits_unaligned_b64_be.rs similarity index 100% rename from spec/rust/formats/bits_unaligned_b64_be.rs rename to spec/rust/src/formats/bits_unaligned_b64_be.rs diff --git a/spec/rust/formats/bits_unaligned_b64_le.rs b/spec/rust/src/formats/bits_unaligned_b64_le.rs similarity index 100% rename from spec/rust/formats/bits_unaligned_b64_le.rs rename to spec/rust/src/formats/bits_unaligned_b64_le.rs diff --git a/spec/rust/formats/buffered_struct.rs b/spec/rust/src/formats/buffered_struct.rs similarity index 100% rename from spec/rust/formats/buffered_struct.rs rename to spec/rust/src/formats/buffered_struct.rs diff --git a/spec/rust/formats/bytes_pad_term.rs b/spec/rust/src/formats/bytes_pad_term.rs similarity index 100% rename from spec/rust/formats/bytes_pad_term.rs rename to spec/rust/src/formats/bytes_pad_term.rs diff --git a/spec/rust/formats/cast_nested.rs b/spec/rust/src/formats/cast_nested.rs similarity index 100% rename from spec/rust/formats/cast_nested.rs rename to spec/rust/src/formats/cast_nested.rs diff --git a/spec/rust/formats/cast_to_imported.rs b/spec/rust/src/formats/cast_to_imported.rs similarity index 100% rename from spec/rust/formats/cast_to_imported.rs rename to spec/rust/src/formats/cast_to_imported.rs diff --git a/spec/rust/formats/cast_to_top.rs b/spec/rust/src/formats/cast_to_top.rs similarity index 100% rename from spec/rust/formats/cast_to_top.rs rename to spec/rust/src/formats/cast_to_top.rs diff --git a/spec/rust/formats/combine_bool.rs b/spec/rust/src/formats/combine_bool.rs similarity index 100% rename from spec/rust/formats/combine_bool.rs rename to spec/rust/src/formats/combine_bool.rs diff --git a/spec/rust/formats/combine_bytes.rs b/spec/rust/src/formats/combine_bytes.rs similarity index 100% rename from spec/rust/formats/combine_bytes.rs rename to spec/rust/src/formats/combine_bytes.rs diff --git a/spec/rust/formats/combine_enum.rs b/spec/rust/src/formats/combine_enum.rs similarity index 100% rename from spec/rust/formats/combine_enum.rs rename to spec/rust/src/formats/combine_enum.rs diff --git a/spec/rust/formats/combine_str.rs b/spec/rust/src/formats/combine_str.rs similarity index 100% rename from spec/rust/formats/combine_str.rs rename to spec/rust/src/formats/combine_str.rs diff --git a/spec/rust/formats/debug_0.rs b/spec/rust/src/formats/debug_0.rs similarity index 100% rename from spec/rust/formats/debug_0.rs rename to spec/rust/src/formats/debug_0.rs diff --git a/spec/rust/formats/default_big_endian.rs b/spec/rust/src/formats/default_big_endian.rs similarity index 100% rename from spec/rust/formats/default_big_endian.rs rename to spec/rust/src/formats/default_big_endian.rs diff --git a/spec/rust/formats/default_bit_endian_mod.rs b/spec/rust/src/formats/default_bit_endian_mod.rs similarity index 100% rename from spec/rust/formats/default_bit_endian_mod.rs rename to spec/rust/src/formats/default_bit_endian_mod.rs diff --git a/spec/rust/formats/default_endian_expr_exception.rs b/spec/rust/src/formats/default_endian_expr_exception.rs similarity index 100% rename from spec/rust/formats/default_endian_expr_exception.rs rename to spec/rust/src/formats/default_endian_expr_exception.rs diff --git a/spec/rust/formats/default_endian_expr_inherited.rs b/spec/rust/src/formats/default_endian_expr_inherited.rs similarity index 100% rename from spec/rust/formats/default_endian_expr_inherited.rs rename to spec/rust/src/formats/default_endian_expr_inherited.rs diff --git a/spec/rust/formats/default_endian_expr_is_be.rs b/spec/rust/src/formats/default_endian_expr_is_be.rs similarity index 100% rename from spec/rust/formats/default_endian_expr_is_be.rs rename to spec/rust/src/formats/default_endian_expr_is_be.rs diff --git a/spec/rust/formats/default_endian_expr_is_le.rs b/spec/rust/src/formats/default_endian_expr_is_le.rs similarity index 100% rename from spec/rust/formats/default_endian_expr_is_le.rs rename to spec/rust/src/formats/default_endian_expr_is_le.rs diff --git a/spec/rust/formats/default_endian_mod.rs b/spec/rust/src/formats/default_endian_mod.rs similarity index 100% rename from spec/rust/formats/default_endian_mod.rs rename to spec/rust/src/formats/default_endian_mod.rs diff --git a/spec/rust/formats/docstrings.rs b/spec/rust/src/formats/docstrings.rs similarity index 100% rename from spec/rust/formats/docstrings.rs rename to spec/rust/src/formats/docstrings.rs diff --git a/spec/rust/formats/docstrings_docref.rs b/spec/rust/src/formats/docstrings_docref.rs similarity index 100% rename from spec/rust/formats/docstrings_docref.rs rename to spec/rust/src/formats/docstrings_docref.rs diff --git a/spec/rust/formats/docstrings_docref_multi.rs b/spec/rust/src/formats/docstrings_docref_multi.rs similarity index 100% rename from spec/rust/formats/docstrings_docref_multi.rs rename to spec/rust/src/formats/docstrings_docref_multi.rs diff --git a/spec/rust/formats/enum_0.rs b/spec/rust/src/formats/enum_0.rs similarity index 100% rename from spec/rust/formats/enum_0.rs rename to spec/rust/src/formats/enum_0.rs diff --git a/spec/rust/formats/enum_1.rs b/spec/rust/src/formats/enum_1.rs similarity index 100% rename from spec/rust/formats/enum_1.rs rename to spec/rust/src/formats/enum_1.rs diff --git a/spec/rust/formats/enum_deep.rs b/spec/rust/src/formats/enum_deep.rs similarity index 100% rename from spec/rust/formats/enum_deep.rs rename to spec/rust/src/formats/enum_deep.rs diff --git a/spec/rust/formats/enum_deep_literals.rs b/spec/rust/src/formats/enum_deep_literals.rs similarity index 100% rename from spec/rust/formats/enum_deep_literals.rs rename to spec/rust/src/formats/enum_deep_literals.rs diff --git a/spec/rust/formats/enum_fancy.rs b/spec/rust/src/formats/enum_fancy.rs similarity index 100% rename from spec/rust/formats/enum_fancy.rs rename to spec/rust/src/formats/enum_fancy.rs diff --git a/spec/rust/formats/enum_for_unknown_id.rs b/spec/rust/src/formats/enum_for_unknown_id.rs similarity index 100% rename from spec/rust/formats/enum_for_unknown_id.rs rename to spec/rust/src/formats/enum_for_unknown_id.rs diff --git a/spec/rust/formats/enum_if.rs b/spec/rust/src/formats/enum_if.rs similarity index 100% rename from spec/rust/formats/enum_if.rs rename to spec/rust/src/formats/enum_if.rs diff --git a/spec/rust/formats/enum_import.rs b/spec/rust/src/formats/enum_import.rs similarity index 100% rename from spec/rust/formats/enum_import.rs rename to spec/rust/src/formats/enum_import.rs diff --git a/spec/rust/formats/enum_int_range_s.rs b/spec/rust/src/formats/enum_int_range_s.rs similarity index 100% rename from spec/rust/formats/enum_int_range_s.rs rename to spec/rust/src/formats/enum_int_range_s.rs diff --git a/spec/rust/formats/enum_int_range_u.rs b/spec/rust/src/formats/enum_int_range_u.rs similarity index 100% rename from spec/rust/formats/enum_int_range_u.rs rename to spec/rust/src/formats/enum_int_range_u.rs diff --git a/spec/rust/formats/enum_invalid.rs b/spec/rust/src/formats/enum_invalid.rs similarity index 100% rename from spec/rust/formats/enum_invalid.rs rename to spec/rust/src/formats/enum_invalid.rs diff --git a/spec/rust/formats/enum_long_range_s.rs b/spec/rust/src/formats/enum_long_range_s.rs similarity index 100% rename from spec/rust/formats/enum_long_range_s.rs rename to spec/rust/src/formats/enum_long_range_s.rs diff --git a/spec/rust/formats/enum_long_range_u.rs b/spec/rust/src/formats/enum_long_range_u.rs similarity index 100% rename from spec/rust/formats/enum_long_range_u.rs rename to spec/rust/src/formats/enum_long_range_u.rs diff --git a/spec/rust/formats/enum_negative.rs b/spec/rust/src/formats/enum_negative.rs similarity index 100% rename from spec/rust/formats/enum_negative.rs rename to spec/rust/src/formats/enum_negative.rs diff --git a/spec/rust/formats/enum_of_value_inst.rs b/spec/rust/src/formats/enum_of_value_inst.rs similarity index 100% rename from spec/rust/formats/enum_of_value_inst.rs rename to spec/rust/src/formats/enum_of_value_inst.rs diff --git a/spec/rust/formats/enum_to_i.rs b/spec/rust/src/formats/enum_to_i.rs similarity index 100% rename from spec/rust/formats/enum_to_i.rs rename to spec/rust/src/formats/enum_to_i.rs diff --git a/spec/rust/formats/enum_to_i_class_border_1.rs b/spec/rust/src/formats/enum_to_i_class_border_1.rs similarity index 100% rename from spec/rust/formats/enum_to_i_class_border_1.rs rename to spec/rust/src/formats/enum_to_i_class_border_1.rs diff --git a/spec/rust/formats/enum_to_i_class_border_2.rs b/spec/rust/src/formats/enum_to_i_class_border_2.rs similarity index 100% rename from spec/rust/formats/enum_to_i_class_border_2.rs rename to spec/rust/src/formats/enum_to_i_class_border_2.rs diff --git a/spec/rust/formats/eof_exception_bytes.rs b/spec/rust/src/formats/eof_exception_bytes.rs similarity index 100% rename from spec/rust/formats/eof_exception_bytes.rs rename to spec/rust/src/formats/eof_exception_bytes.rs diff --git a/spec/rust/formats/eof_exception_u4.rs b/spec/rust/src/formats/eof_exception_u4.rs similarity index 100% rename from spec/rust/formats/eof_exception_u4.rs rename to spec/rust/src/formats/eof_exception_u4.rs diff --git a/spec/rust/formats/eos_exception_bytes.rs b/spec/rust/src/formats/eos_exception_bytes.rs similarity index 100% rename from spec/rust/formats/eos_exception_bytes.rs rename to spec/rust/src/formats/eos_exception_bytes.rs diff --git a/spec/rust/formats/eos_exception_u4.rs b/spec/rust/src/formats/eos_exception_u4.rs similarity index 100% rename from spec/rust/formats/eos_exception_u4.rs rename to spec/rust/src/formats/eos_exception_u4.rs diff --git a/spec/rust/formats/expr_0.rs b/spec/rust/src/formats/expr_0.rs similarity index 100% rename from spec/rust/formats/expr_0.rs rename to spec/rust/src/formats/expr_0.rs diff --git a/spec/rust/formats/expr_1.rs b/spec/rust/src/formats/expr_1.rs similarity index 100% rename from spec/rust/formats/expr_1.rs rename to spec/rust/src/formats/expr_1.rs diff --git a/spec/rust/formats/expr_2.rs b/spec/rust/src/formats/expr_2.rs similarity index 100% rename from spec/rust/formats/expr_2.rs rename to spec/rust/src/formats/expr_2.rs diff --git a/spec/rust/formats/expr_3.rs b/spec/rust/src/formats/expr_3.rs similarity index 100% rename from spec/rust/formats/expr_3.rs rename to spec/rust/src/formats/expr_3.rs diff --git a/spec/rust/formats/expr_array.rs b/spec/rust/src/formats/expr_array.rs similarity index 100% rename from spec/rust/formats/expr_array.rs rename to spec/rust/src/formats/expr_array.rs diff --git a/spec/rust/formats/expr_bits.rs b/spec/rust/src/formats/expr_bits.rs similarity index 100% rename from spec/rust/formats/expr_bits.rs rename to spec/rust/src/formats/expr_bits.rs diff --git a/spec/rust/formats/expr_bytes_cmp.rs b/spec/rust/src/formats/expr_bytes_cmp.rs similarity index 100% rename from spec/rust/formats/expr_bytes_cmp.rs rename to spec/rust/src/formats/expr_bytes_cmp.rs diff --git a/spec/rust/formats/expr_bytes_non_literal.rs b/spec/rust/src/formats/expr_bytes_non_literal.rs similarity index 100% rename from spec/rust/formats/expr_bytes_non_literal.rs rename to spec/rust/src/formats/expr_bytes_non_literal.rs diff --git a/spec/rust/formats/expr_bytes_ops.rs b/spec/rust/src/formats/expr_bytes_ops.rs similarity index 100% rename from spec/rust/formats/expr_bytes_ops.rs rename to spec/rust/src/formats/expr_bytes_ops.rs diff --git a/spec/rust/formats/expr_enum.rs b/spec/rust/src/formats/expr_enum.rs similarity index 100% rename from spec/rust/formats/expr_enum.rs rename to spec/rust/src/formats/expr_enum.rs diff --git a/spec/rust/formats/expr_if_int_ops.rs b/spec/rust/src/formats/expr_if_int_ops.rs similarity index 100% rename from spec/rust/formats/expr_if_int_ops.rs rename to spec/rust/src/formats/expr_if_int_ops.rs diff --git a/spec/rust/formats/expr_int_div.rs b/spec/rust/src/formats/expr_int_div.rs similarity index 100% rename from spec/rust/formats/expr_int_div.rs rename to spec/rust/src/formats/expr_int_div.rs diff --git a/spec/rust/formats/expr_io_eof.rs b/spec/rust/src/formats/expr_io_eof.rs similarity index 100% rename from spec/rust/formats/expr_io_eof.rs rename to spec/rust/src/formats/expr_io_eof.rs diff --git a/spec/rust/formats/expr_io_pos.rs b/spec/rust/src/formats/expr_io_pos.rs similarity index 100% rename from spec/rust/formats/expr_io_pos.rs rename to spec/rust/src/formats/expr_io_pos.rs diff --git a/spec/rust/formats/expr_mod.rs b/spec/rust/src/formats/expr_mod.rs similarity index 100% rename from spec/rust/formats/expr_mod.rs rename to spec/rust/src/formats/expr_mod.rs diff --git a/spec/rust/formats/expr_ops_parens.rs b/spec/rust/src/formats/expr_ops_parens.rs similarity index 100% rename from spec/rust/formats/expr_ops_parens.rs rename to spec/rust/src/formats/expr_ops_parens.rs diff --git a/spec/rust/formats/expr_sizeof_type_0.rs b/spec/rust/src/formats/expr_sizeof_type_0.rs similarity index 100% rename from spec/rust/formats/expr_sizeof_type_0.rs rename to spec/rust/src/formats/expr_sizeof_type_0.rs diff --git a/spec/rust/formats/expr_sizeof_type_1.rs b/spec/rust/src/formats/expr_sizeof_type_1.rs similarity index 100% rename from spec/rust/formats/expr_sizeof_type_1.rs rename to spec/rust/src/formats/expr_sizeof_type_1.rs diff --git a/spec/rust/formats/expr_sizeof_value_0.rs b/spec/rust/src/formats/expr_sizeof_value_0.rs similarity index 100% rename from spec/rust/formats/expr_sizeof_value_0.rs rename to spec/rust/src/formats/expr_sizeof_value_0.rs diff --git a/spec/rust/formats/expr_sizeof_value_sized.rs b/spec/rust/src/formats/expr_sizeof_value_sized.rs similarity index 100% rename from spec/rust/formats/expr_sizeof_value_sized.rs rename to spec/rust/src/formats/expr_sizeof_value_sized.rs diff --git a/spec/rust/formats/expr_str_encodings.rs b/spec/rust/src/formats/expr_str_encodings.rs similarity index 100% rename from spec/rust/formats/expr_str_encodings.rs rename to spec/rust/src/formats/expr_str_encodings.rs diff --git a/spec/rust/formats/expr_str_ops.rs b/spec/rust/src/formats/expr_str_ops.rs similarity index 100% rename from spec/rust/formats/expr_str_ops.rs rename to spec/rust/src/formats/expr_str_ops.rs diff --git a/spec/rust/formats/fixed_contents.rs b/spec/rust/src/formats/fixed_contents.rs similarity index 100% rename from spec/rust/formats/fixed_contents.rs rename to spec/rust/src/formats/fixed_contents.rs diff --git a/spec/rust/formats/fixed_struct.rs b/spec/rust/src/formats/fixed_struct.rs similarity index 100% rename from spec/rust/formats/fixed_struct.rs rename to spec/rust/src/formats/fixed_struct.rs diff --git a/spec/rust/formats/float_to_i.rs b/spec/rust/src/formats/float_to_i.rs similarity index 100% rename from spec/rust/formats/float_to_i.rs rename to spec/rust/src/formats/float_to_i.rs diff --git a/spec/rust/formats/floating_points.rs b/spec/rust/src/formats/floating_points.rs similarity index 100% rename from spec/rust/formats/floating_points.rs rename to spec/rust/src/formats/floating_points.rs diff --git a/spec/rust/formats/hello_world.rs b/spec/rust/src/formats/hello_world.rs similarity index 100% rename from spec/rust/formats/hello_world.rs rename to spec/rust/src/formats/hello_world.rs diff --git a/spec/rust/formats/if_instances.rs b/spec/rust/src/formats/if_instances.rs similarity index 100% rename from spec/rust/formats/if_instances.rs rename to spec/rust/src/formats/if_instances.rs diff --git a/spec/rust/formats/if_struct.rs b/spec/rust/src/formats/if_struct.rs similarity index 100% rename from spec/rust/formats/if_struct.rs rename to spec/rust/src/formats/if_struct.rs diff --git a/spec/rust/formats/if_values.rs b/spec/rust/src/formats/if_values.rs similarity index 100% rename from spec/rust/formats/if_values.rs rename to spec/rust/src/formats/if_values.rs diff --git a/spec/rust/formats/imported_1.rs b/spec/rust/src/formats/imported_1.rs similarity index 100% rename from spec/rust/formats/imported_1.rs rename to spec/rust/src/formats/imported_1.rs diff --git a/spec/rust/formats/imported_2.rs b/spec/rust/src/formats/imported_2.rs similarity index 100% rename from spec/rust/formats/imported_2.rs rename to spec/rust/src/formats/imported_2.rs diff --git a/spec/rust/formats/imports0.rs b/spec/rust/src/formats/imports0.rs similarity index 100% rename from spec/rust/formats/imports0.rs rename to spec/rust/src/formats/imports0.rs diff --git a/spec/rust/formats/imports_circular_a.rs b/spec/rust/src/formats/imports_circular_a.rs similarity index 100% rename from spec/rust/formats/imports_circular_a.rs rename to spec/rust/src/formats/imports_circular_a.rs diff --git a/spec/rust/formats/imports_circular_b.rs b/spec/rust/src/formats/imports_circular_b.rs similarity index 100% rename from spec/rust/formats/imports_circular_b.rs rename to spec/rust/src/formats/imports_circular_b.rs diff --git a/spec/rust/formats/imports_rel_1.rs b/spec/rust/src/formats/imports_rel_1.rs similarity index 100% rename from spec/rust/formats/imports_rel_1.rs rename to spec/rust/src/formats/imports_rel_1.rs diff --git a/spec/rust/formats/index_sizes.rs b/spec/rust/src/formats/index_sizes.rs similarity index 100% rename from spec/rust/formats/index_sizes.rs rename to spec/rust/src/formats/index_sizes.rs diff --git a/spec/rust/formats/index_to_param_eos.rs b/spec/rust/src/formats/index_to_param_eos.rs similarity index 100% rename from spec/rust/formats/index_to_param_eos.rs rename to spec/rust/src/formats/index_to_param_eos.rs diff --git a/spec/rust/formats/index_to_param_expr.rs b/spec/rust/src/formats/index_to_param_expr.rs similarity index 100% rename from spec/rust/formats/index_to_param_expr.rs rename to spec/rust/src/formats/index_to_param_expr.rs diff --git a/spec/rust/formats/index_to_param_until.rs b/spec/rust/src/formats/index_to_param_until.rs similarity index 100% rename from spec/rust/formats/index_to_param_until.rs rename to spec/rust/src/formats/index_to_param_until.rs diff --git a/spec/rust/formats/instance_std.rs b/spec/rust/src/formats/instance_std.rs similarity index 100% rename from spec/rust/formats/instance_std.rs rename to spec/rust/src/formats/instance_std.rs diff --git a/spec/rust/formats/instance_std_array.rs b/spec/rust/src/formats/instance_std_array.rs similarity index 100% rename from spec/rust/formats/instance_std_array.rs rename to spec/rust/src/formats/instance_std_array.rs diff --git a/spec/rust/formats/instance_user_array.rs b/spec/rust/src/formats/instance_user_array.rs similarity index 100% rename from spec/rust/formats/instance_user_array.rs rename to spec/rust/src/formats/instance_user_array.rs diff --git a/spec/rust/formats/integers.rs b/spec/rust/src/formats/integers.rs similarity index 100% rename from spec/rust/formats/integers.rs rename to spec/rust/src/formats/integers.rs diff --git a/spec/rust/formats/integers_double_overflow.rs b/spec/rust/src/formats/integers_double_overflow.rs similarity index 100% rename from spec/rust/formats/integers_double_overflow.rs rename to spec/rust/src/formats/integers_double_overflow.rs diff --git a/spec/rust/formats/integers_min_max.rs b/spec/rust/src/formats/integers_min_max.rs similarity index 100% rename from spec/rust/formats/integers_min_max.rs rename to spec/rust/src/formats/integers_min_max.rs diff --git a/spec/rust/formats/io_local_var.rs b/spec/rust/src/formats/io_local_var.rs similarity index 100% rename from spec/rust/formats/io_local_var.rs rename to spec/rust/src/formats/io_local_var.rs diff --git a/spec/rust/formats/js_signed_right_shift.rs b/spec/rust/src/formats/js_signed_right_shift.rs similarity index 100% rename from spec/rust/formats/js_signed_right_shift.rs rename to spec/rust/src/formats/js_signed_right_shift.rs diff --git a/spec/rust/formats/meta_tags.rs b/spec/rust/src/formats/meta_tags.rs similarity index 100% rename from spec/rust/formats/meta_tags.rs rename to spec/rust/src/formats/meta_tags.rs diff --git a/spec/rust/formats/meta_xref.rs b/spec/rust/src/formats/meta_xref.rs similarity index 100% rename from spec/rust/formats/meta_xref.rs rename to spec/rust/src/formats/meta_xref.rs diff --git a/spec/rust/formats/multiple_use.rs b/spec/rust/src/formats/multiple_use.rs similarity index 100% rename from spec/rust/formats/multiple_use.rs rename to spec/rust/src/formats/multiple_use.rs diff --git a/spec/rust/formats/nav_parent.rs b/spec/rust/src/formats/nav_parent.rs similarity index 100% rename from spec/rust/formats/nav_parent.rs rename to spec/rust/src/formats/nav_parent.rs diff --git a/spec/rust/formats/nav_parent2.rs b/spec/rust/src/formats/nav_parent2.rs similarity index 100% rename from spec/rust/formats/nav_parent2.rs rename to spec/rust/src/formats/nav_parent2.rs diff --git a/spec/rust/formats/nav_parent3.rs b/spec/rust/src/formats/nav_parent3.rs similarity index 100% rename from spec/rust/formats/nav_parent3.rs rename to spec/rust/src/formats/nav_parent3.rs diff --git a/spec/rust/formats/nav_parent_false.rs b/spec/rust/src/formats/nav_parent_false.rs similarity index 100% rename from spec/rust/formats/nav_parent_false.rs rename to spec/rust/src/formats/nav_parent_false.rs diff --git a/spec/rust/formats/nav_parent_false2.rs b/spec/rust/src/formats/nav_parent_false2.rs similarity index 100% rename from spec/rust/formats/nav_parent_false2.rs rename to spec/rust/src/formats/nav_parent_false2.rs diff --git a/spec/rust/formats/nav_parent_override.rs b/spec/rust/src/formats/nav_parent_override.rs similarity index 100% rename from spec/rust/formats/nav_parent_override.rs rename to spec/rust/src/formats/nav_parent_override.rs diff --git a/spec/rust/formats/nav_parent_switch.rs b/spec/rust/src/formats/nav_parent_switch.rs similarity index 100% rename from spec/rust/formats/nav_parent_switch.rs rename to spec/rust/src/formats/nav_parent_switch.rs diff --git a/spec/rust/formats/nav_parent_switch_cast.rs b/spec/rust/src/formats/nav_parent_switch_cast.rs similarity index 100% rename from spec/rust/formats/nav_parent_switch_cast.rs rename to spec/rust/src/formats/nav_parent_switch_cast.rs diff --git a/spec/rust/formats/nav_parent_vs_value_inst.rs b/spec/rust/src/formats/nav_parent_vs_value_inst.rs similarity index 100% rename from spec/rust/formats/nav_parent_vs_value_inst.rs rename to spec/rust/src/formats/nav_parent_vs_value_inst.rs diff --git a/spec/rust/formats/nav_root.rs b/spec/rust/src/formats/nav_root.rs similarity index 100% rename from spec/rust/formats/nav_root.rs rename to spec/rust/src/formats/nav_root.rs diff --git a/spec/rust/formats/nested_same_name.rs b/spec/rust/src/formats/nested_same_name.rs similarity index 100% rename from spec/rust/formats/nested_same_name.rs rename to spec/rust/src/formats/nested_same_name.rs diff --git a/spec/rust/formats/nested_same_name2.rs b/spec/rust/src/formats/nested_same_name2.rs similarity index 100% rename from spec/rust/formats/nested_same_name2.rs rename to spec/rust/src/formats/nested_same_name2.rs diff --git a/spec/rust/formats/nested_type_param.rs b/spec/rust/src/formats/nested_type_param.rs similarity index 100% rename from spec/rust/formats/nested_type_param.rs rename to spec/rust/src/formats/nested_type_param.rs diff --git a/spec/rust/formats/nested_types.rs b/spec/rust/src/formats/nested_types.rs similarity index 100% rename from spec/rust/formats/nested_types.rs rename to spec/rust/src/formats/nested_types.rs diff --git a/spec/rust/formats/nested_types2.rs b/spec/rust/src/formats/nested_types2.rs similarity index 100% rename from spec/rust/formats/nested_types2.rs rename to spec/rust/src/formats/nested_types2.rs diff --git a/spec/rust/formats/nested_types3.rs b/spec/rust/src/formats/nested_types3.rs similarity index 100% rename from spec/rust/formats/nested_types3.rs rename to spec/rust/src/formats/nested_types3.rs diff --git a/spec/rust/formats/non_standard.rs b/spec/rust/src/formats/non_standard.rs similarity index 100% rename from spec/rust/formats/non_standard.rs rename to spec/rust/src/formats/non_standard.rs diff --git a/spec/rust/formats/opaque_external_type.rs b/spec/rust/src/formats/opaque_external_type.rs similarity index 100% rename from spec/rust/formats/opaque_external_type.rs rename to spec/rust/src/formats/opaque_external_type.rs diff --git a/spec/rust/formats/opaque_external_type_02_child.rs b/spec/rust/src/formats/opaque_external_type_02_child.rs similarity index 100% rename from spec/rust/formats/opaque_external_type_02_child.rs rename to spec/rust/src/formats/opaque_external_type_02_child.rs diff --git a/spec/rust/formats/opaque_external_type_02_parent.rs b/spec/rust/src/formats/opaque_external_type_02_parent.rs similarity index 100% rename from spec/rust/formats/opaque_external_type_02_parent.rs rename to spec/rust/src/formats/opaque_external_type_02_parent.rs diff --git a/spec/rust/formats/opaque_with_param.rs b/spec/rust/src/formats/opaque_with_param.rs similarity index 100% rename from spec/rust/formats/opaque_with_param.rs rename to spec/rust/src/formats/opaque_with_param.rs diff --git a/spec/rust/formats/optional_id.rs b/spec/rust/src/formats/optional_id.rs similarity index 100% rename from spec/rust/formats/optional_id.rs rename to spec/rust/src/formats/optional_id.rs diff --git a/spec/rust/formats/params_call_extra_parens.rs b/spec/rust/src/formats/params_call_extra_parens.rs similarity index 100% rename from spec/rust/formats/params_call_extra_parens.rs rename to spec/rust/src/formats/params_call_extra_parens.rs diff --git a/spec/rust/formats/params_call_short.rs b/spec/rust/src/formats/params_call_short.rs similarity index 100% rename from spec/rust/formats/params_call_short.rs rename to spec/rust/src/formats/params_call_short.rs diff --git a/spec/rust/formats/params_def.rs b/spec/rust/src/formats/params_def.rs similarity index 100% rename from spec/rust/formats/params_def.rs rename to spec/rust/src/formats/params_def.rs diff --git a/spec/rust/formats/params_enum.rs b/spec/rust/src/formats/params_enum.rs similarity index 100% rename from spec/rust/formats/params_enum.rs rename to spec/rust/src/formats/params_enum.rs diff --git a/spec/rust/formats/params_pass_array_usertype.rs b/spec/rust/src/formats/params_pass_array_usertype.rs similarity index 100% rename from spec/rust/formats/params_pass_array_usertype.rs rename to spec/rust/src/formats/params_pass_array_usertype.rs diff --git a/spec/rust/formats/params_pass_bool.rs b/spec/rust/src/formats/params_pass_bool.rs similarity index 100% rename from spec/rust/formats/params_pass_bool.rs rename to spec/rust/src/formats/params_pass_bool.rs diff --git a/spec/rust/formats/params_pass_usertype.rs b/spec/rust/src/formats/params_pass_usertype.rs similarity index 100% rename from spec/rust/formats/params_pass_usertype.rs rename to spec/rust/src/formats/params_pass_usertype.rs diff --git a/spec/rust/formats/position_abs.rs b/spec/rust/src/formats/position_abs.rs similarity index 100% rename from spec/rust/formats/position_abs.rs rename to spec/rust/src/formats/position_abs.rs diff --git a/spec/rust/formats/position_in_seq.rs b/spec/rust/src/formats/position_in_seq.rs similarity index 100% rename from spec/rust/formats/position_in_seq.rs rename to spec/rust/src/formats/position_in_seq.rs diff --git a/spec/rust/formats/position_to_end.rs b/spec/rust/src/formats/position_to_end.rs similarity index 100% rename from spec/rust/formats/position_to_end.rs rename to spec/rust/src/formats/position_to_end.rs diff --git a/spec/rust/formats/process_coerce_bytes.rs b/spec/rust/src/formats/process_coerce_bytes.rs similarity index 100% rename from spec/rust/formats/process_coerce_bytes.rs rename to spec/rust/src/formats/process_coerce_bytes.rs diff --git a/spec/rust/formats/process_coerce_usertype1.rs b/spec/rust/src/formats/process_coerce_usertype1.rs similarity index 100% rename from spec/rust/formats/process_coerce_usertype1.rs rename to spec/rust/src/formats/process_coerce_usertype1.rs diff --git a/spec/rust/formats/process_coerce_usertype2.rs b/spec/rust/src/formats/process_coerce_usertype2.rs similarity index 100% rename from spec/rust/formats/process_coerce_usertype2.rs rename to spec/rust/src/formats/process_coerce_usertype2.rs diff --git a/spec/rust/formats/process_custom.rs b/spec/rust/src/formats/process_custom.rs similarity index 100% rename from spec/rust/formats/process_custom.rs rename to spec/rust/src/formats/process_custom.rs diff --git a/spec/rust/formats/process_custom_no_args.rs b/spec/rust/src/formats/process_custom_no_args.rs similarity index 100% rename from spec/rust/formats/process_custom_no_args.rs rename to spec/rust/src/formats/process_custom_no_args.rs diff --git a/spec/rust/formats/process_repeat_bytes.rs b/spec/rust/src/formats/process_repeat_bytes.rs similarity index 100% rename from spec/rust/formats/process_repeat_bytes.rs rename to spec/rust/src/formats/process_repeat_bytes.rs diff --git a/spec/rust/formats/process_repeat_usertype.rs b/spec/rust/src/formats/process_repeat_usertype.rs similarity index 100% rename from spec/rust/formats/process_repeat_usertype.rs rename to spec/rust/src/formats/process_repeat_usertype.rs diff --git a/spec/rust/formats/process_rotate.rs b/spec/rust/src/formats/process_rotate.rs similarity index 100% rename from spec/rust/formats/process_rotate.rs rename to spec/rust/src/formats/process_rotate.rs diff --git a/spec/rust/formats/process_to_user.rs b/spec/rust/src/formats/process_to_user.rs similarity index 100% rename from spec/rust/formats/process_to_user.rs rename to spec/rust/src/formats/process_to_user.rs diff --git a/spec/rust/formats/process_xor4_const.rs b/spec/rust/src/formats/process_xor4_const.rs similarity index 100% rename from spec/rust/formats/process_xor4_const.rs rename to spec/rust/src/formats/process_xor4_const.rs diff --git a/spec/rust/formats/process_xor4_value.rs b/spec/rust/src/formats/process_xor4_value.rs similarity index 100% rename from spec/rust/formats/process_xor4_value.rs rename to spec/rust/src/formats/process_xor4_value.rs diff --git a/spec/rust/formats/process_xor_const.rs b/spec/rust/src/formats/process_xor_const.rs similarity index 100% rename from spec/rust/formats/process_xor_const.rs rename to spec/rust/src/formats/process_xor_const.rs diff --git a/spec/rust/formats/process_xor_value.rs b/spec/rust/src/formats/process_xor_value.rs similarity index 100% rename from spec/rust/formats/process_xor_value.rs rename to spec/rust/src/formats/process_xor_value.rs diff --git a/spec/rust/formats/recursive_one.rs b/spec/rust/src/formats/recursive_one.rs similarity index 100% rename from spec/rust/formats/recursive_one.rs rename to spec/rust/src/formats/recursive_one.rs diff --git a/spec/rust/formats/repeat_eos_bit.rs b/spec/rust/src/formats/repeat_eos_bit.rs similarity index 100% rename from spec/rust/formats/repeat_eos_bit.rs rename to spec/rust/src/formats/repeat_eos_bit.rs diff --git a/spec/rust/formats/repeat_eos_struct.rs b/spec/rust/src/formats/repeat_eos_struct.rs similarity index 100% rename from spec/rust/formats/repeat_eos_struct.rs rename to spec/rust/src/formats/repeat_eos_struct.rs diff --git a/spec/rust/formats/repeat_eos_u4.rs b/spec/rust/src/formats/repeat_eos_u4.rs similarity index 100% rename from spec/rust/formats/repeat_eos_u4.rs rename to spec/rust/src/formats/repeat_eos_u4.rs diff --git a/spec/rust/formats/repeat_n_struct.rs b/spec/rust/src/formats/repeat_n_struct.rs similarity index 100% rename from spec/rust/formats/repeat_n_struct.rs rename to spec/rust/src/formats/repeat_n_struct.rs diff --git a/spec/rust/formats/repeat_n_strz.rs b/spec/rust/src/formats/repeat_n_strz.rs similarity index 100% rename from spec/rust/formats/repeat_n_strz.rs rename to spec/rust/src/formats/repeat_n_strz.rs diff --git a/spec/rust/formats/repeat_n_strz_double.rs b/spec/rust/src/formats/repeat_n_strz_double.rs similarity index 100% rename from spec/rust/formats/repeat_n_strz_double.rs rename to spec/rust/src/formats/repeat_n_strz_double.rs diff --git a/spec/rust/formats/repeat_until_complex.rs b/spec/rust/src/formats/repeat_until_complex.rs similarity index 100% rename from spec/rust/formats/repeat_until_complex.rs rename to spec/rust/src/formats/repeat_until_complex.rs diff --git a/spec/rust/formats/repeat_until_s4.rs b/spec/rust/src/formats/repeat_until_s4.rs similarity index 100% rename from spec/rust/formats/repeat_until_s4.rs rename to spec/rust/src/formats/repeat_until_s4.rs diff --git a/spec/rust/formats/repeat_until_sized.rs b/spec/rust/src/formats/repeat_until_sized.rs similarity index 100% rename from spec/rust/formats/repeat_until_sized.rs rename to spec/rust/src/formats/repeat_until_sized.rs diff --git a/spec/rust/formats/str_encodings.rs b/spec/rust/src/formats/str_encodings.rs similarity index 100% rename from spec/rust/formats/str_encodings.rs rename to spec/rust/src/formats/str_encodings.rs diff --git a/spec/rust/formats/str_encodings_default.rs b/spec/rust/src/formats/str_encodings_default.rs similarity index 100% rename from spec/rust/formats/str_encodings_default.rs rename to spec/rust/src/formats/str_encodings_default.rs diff --git a/spec/rust/formats/str_encodings_utf16.rs b/spec/rust/src/formats/str_encodings_utf16.rs similarity index 100% rename from spec/rust/formats/str_encodings_utf16.rs rename to spec/rust/src/formats/str_encodings_utf16.rs diff --git a/spec/rust/formats/str_eos.rs b/spec/rust/src/formats/str_eos.rs similarity index 100% rename from spec/rust/formats/str_eos.rs rename to spec/rust/src/formats/str_eos.rs diff --git a/spec/rust/formats/str_literals.rs b/spec/rust/src/formats/str_literals.rs similarity index 100% rename from spec/rust/formats/str_literals.rs rename to spec/rust/src/formats/str_literals.rs diff --git a/spec/rust/formats/str_literals2.rs b/spec/rust/src/formats/str_literals2.rs similarity index 100% rename from spec/rust/formats/str_literals2.rs rename to spec/rust/src/formats/str_literals2.rs diff --git a/spec/rust/formats/str_pad_term.rs b/spec/rust/src/formats/str_pad_term.rs similarity index 100% rename from spec/rust/formats/str_pad_term.rs rename to spec/rust/src/formats/str_pad_term.rs diff --git a/spec/rust/formats/str_pad_term_empty.rs b/spec/rust/src/formats/str_pad_term_empty.rs similarity index 100% rename from spec/rust/formats/str_pad_term_empty.rs rename to spec/rust/src/formats/str_pad_term_empty.rs diff --git a/spec/rust/formats/switch_bytearray.rs b/spec/rust/src/formats/switch_bytearray.rs similarity index 100% rename from spec/rust/formats/switch_bytearray.rs rename to spec/rust/src/formats/switch_bytearray.rs diff --git a/spec/rust/formats/switch_cast.rs b/spec/rust/src/formats/switch_cast.rs similarity index 100% rename from spec/rust/formats/switch_cast.rs rename to spec/rust/src/formats/switch_cast.rs diff --git a/spec/rust/formats/switch_else_only.rs b/spec/rust/src/formats/switch_else_only.rs similarity index 100% rename from spec/rust/formats/switch_else_only.rs rename to spec/rust/src/formats/switch_else_only.rs diff --git a/spec/rust/formats/switch_integers.rs b/spec/rust/src/formats/switch_integers.rs similarity index 100% rename from spec/rust/formats/switch_integers.rs rename to spec/rust/src/formats/switch_integers.rs diff --git a/spec/rust/formats/switch_integers2.rs b/spec/rust/src/formats/switch_integers2.rs similarity index 100% rename from spec/rust/formats/switch_integers2.rs rename to spec/rust/src/formats/switch_integers2.rs diff --git a/spec/rust/formats/switch_manual_enum.rs b/spec/rust/src/formats/switch_manual_enum.rs similarity index 100% rename from spec/rust/formats/switch_manual_enum.rs rename to spec/rust/src/formats/switch_manual_enum.rs diff --git a/spec/rust/formats/switch_manual_enum_invalid.rs b/spec/rust/src/formats/switch_manual_enum_invalid.rs similarity index 100% rename from spec/rust/formats/switch_manual_enum_invalid.rs rename to spec/rust/src/formats/switch_manual_enum_invalid.rs diff --git a/spec/rust/formats/switch_manual_enum_invalid_else.rs b/spec/rust/src/formats/switch_manual_enum_invalid_else.rs similarity index 100% rename from spec/rust/formats/switch_manual_enum_invalid_else.rs rename to spec/rust/src/formats/switch_manual_enum_invalid_else.rs diff --git a/spec/rust/formats/switch_manual_int.rs b/spec/rust/src/formats/switch_manual_int.rs similarity index 100% rename from spec/rust/formats/switch_manual_int.rs rename to spec/rust/src/formats/switch_manual_int.rs diff --git a/spec/rust/formats/switch_manual_int_else.rs b/spec/rust/src/formats/switch_manual_int_else.rs similarity index 100% rename from spec/rust/formats/switch_manual_int_else.rs rename to spec/rust/src/formats/switch_manual_int_else.rs diff --git a/spec/rust/formats/switch_manual_int_size.rs b/spec/rust/src/formats/switch_manual_int_size.rs similarity index 100% rename from spec/rust/formats/switch_manual_int_size.rs rename to spec/rust/src/formats/switch_manual_int_size.rs diff --git a/spec/rust/formats/switch_manual_int_size_else.rs b/spec/rust/src/formats/switch_manual_int_size_else.rs similarity index 100% rename from spec/rust/formats/switch_manual_int_size_else.rs rename to spec/rust/src/formats/switch_manual_int_size_else.rs diff --git a/spec/rust/formats/switch_manual_str.rs b/spec/rust/src/formats/switch_manual_str.rs similarity index 100% rename from spec/rust/formats/switch_manual_str.rs rename to spec/rust/src/formats/switch_manual_str.rs diff --git a/spec/rust/formats/switch_manual_str_else.rs b/spec/rust/src/formats/switch_manual_str_else.rs similarity index 100% rename from spec/rust/formats/switch_manual_str_else.rs rename to spec/rust/src/formats/switch_manual_str_else.rs diff --git a/spec/rust/formats/switch_multi_bool_ops.rs b/spec/rust/src/formats/switch_multi_bool_ops.rs similarity index 100% rename from spec/rust/formats/switch_multi_bool_ops.rs rename to spec/rust/src/formats/switch_multi_bool_ops.rs diff --git a/spec/rust/formats/switch_repeat_expr.rs b/spec/rust/src/formats/switch_repeat_expr.rs similarity index 100% rename from spec/rust/formats/switch_repeat_expr.rs rename to spec/rust/src/formats/switch_repeat_expr.rs diff --git a/spec/rust/formats/switch_repeat_expr_invalid.rs b/spec/rust/src/formats/switch_repeat_expr_invalid.rs similarity index 100% rename from spec/rust/formats/switch_repeat_expr_invalid.rs rename to spec/rust/src/formats/switch_repeat_expr_invalid.rs diff --git a/spec/rust/formats/term_bytes.rs b/spec/rust/src/formats/term_bytes.rs similarity index 100% rename from spec/rust/formats/term_bytes.rs rename to spec/rust/src/formats/term_bytes.rs diff --git a/spec/rust/formats/term_strz.rs b/spec/rust/src/formats/term_strz.rs similarity index 100% rename from spec/rust/formats/term_strz.rs rename to spec/rust/src/formats/term_strz.rs diff --git a/spec/rust/formats/term_u1_val.rs b/spec/rust/src/formats/term_u1_val.rs similarity index 100% rename from spec/rust/formats/term_u1_val.rs rename to spec/rust/src/formats/term_u1_val.rs diff --git a/spec/rust/formats/to_string_custom.rs b/spec/rust/src/formats/to_string_custom.rs similarity index 100% rename from spec/rust/formats/to_string_custom.rs rename to spec/rust/src/formats/to_string_custom.rs diff --git a/spec/rust/formats/ts_packet_header.rs b/spec/rust/src/formats/ts_packet_header.rs similarity index 100% rename from spec/rust/formats/ts_packet_header.rs rename to spec/rust/src/formats/ts_packet_header.rs diff --git a/spec/rust/formats/type_int_unary_op.rs b/spec/rust/src/formats/type_int_unary_op.rs similarity index 100% rename from spec/rust/formats/type_int_unary_op.rs rename to spec/rust/src/formats/type_int_unary_op.rs diff --git a/spec/rust/formats/type_ternary.rs b/spec/rust/src/formats/type_ternary.rs similarity index 100% rename from spec/rust/formats/type_ternary.rs rename to spec/rust/src/formats/type_ternary.rs diff --git a/spec/rust/formats/type_ternary_opaque.rs b/spec/rust/src/formats/type_ternary_opaque.rs similarity index 100% rename from spec/rust/formats/type_ternary_opaque.rs rename to spec/rust/src/formats/type_ternary_opaque.rs diff --git a/spec/rust/formats/user_type.rs b/spec/rust/src/formats/user_type.rs similarity index 100% rename from spec/rust/formats/user_type.rs rename to spec/rust/src/formats/user_type.rs diff --git a/spec/rust/formats/valid_eq_str_encodings.rs b/spec/rust/src/formats/valid_eq_str_encodings.rs similarity index 100% rename from spec/rust/formats/valid_eq_str_encodings.rs rename to spec/rust/src/formats/valid_eq_str_encodings.rs diff --git a/spec/rust/formats/valid_fail_anyof_int.rs b/spec/rust/src/formats/valid_fail_anyof_int.rs similarity index 100% rename from spec/rust/formats/valid_fail_anyof_int.rs rename to spec/rust/src/formats/valid_fail_anyof_int.rs diff --git a/spec/rust/formats/valid_fail_contents.rs b/spec/rust/src/formats/valid_fail_contents.rs similarity index 100% rename from spec/rust/formats/valid_fail_contents.rs rename to spec/rust/src/formats/valid_fail_contents.rs diff --git a/spec/rust/formats/valid_fail_eq_bytes.rs b/spec/rust/src/formats/valid_fail_eq_bytes.rs similarity index 100% rename from spec/rust/formats/valid_fail_eq_bytes.rs rename to spec/rust/src/formats/valid_fail_eq_bytes.rs diff --git a/spec/rust/formats/valid_fail_eq_int.rs b/spec/rust/src/formats/valid_fail_eq_int.rs similarity index 100% rename from spec/rust/formats/valid_fail_eq_int.rs rename to spec/rust/src/formats/valid_fail_eq_int.rs diff --git a/spec/rust/formats/valid_fail_eq_str.rs b/spec/rust/src/formats/valid_fail_eq_str.rs similarity index 100% rename from spec/rust/formats/valid_fail_eq_str.rs rename to spec/rust/src/formats/valid_fail_eq_str.rs diff --git a/spec/rust/formats/valid_fail_expr.rs b/spec/rust/src/formats/valid_fail_expr.rs similarity index 100% rename from spec/rust/formats/valid_fail_expr.rs rename to spec/rust/src/formats/valid_fail_expr.rs diff --git a/spec/rust/formats/valid_fail_inst.rs b/spec/rust/src/formats/valid_fail_inst.rs similarity index 100% rename from spec/rust/formats/valid_fail_inst.rs rename to spec/rust/src/formats/valid_fail_inst.rs diff --git a/spec/rust/formats/valid_fail_max_int.rs b/spec/rust/src/formats/valid_fail_max_int.rs similarity index 100% rename from spec/rust/formats/valid_fail_max_int.rs rename to spec/rust/src/formats/valid_fail_max_int.rs diff --git a/spec/rust/formats/valid_fail_min_int.rs b/spec/rust/src/formats/valid_fail_min_int.rs similarity index 100% rename from spec/rust/formats/valid_fail_min_int.rs rename to spec/rust/src/formats/valid_fail_min_int.rs diff --git a/spec/rust/formats/valid_fail_range_bytes.rs b/spec/rust/src/formats/valid_fail_range_bytes.rs similarity index 100% rename from spec/rust/formats/valid_fail_range_bytes.rs rename to spec/rust/src/formats/valid_fail_range_bytes.rs diff --git a/spec/rust/formats/valid_fail_range_float.rs b/spec/rust/src/formats/valid_fail_range_float.rs similarity index 100% rename from spec/rust/formats/valid_fail_range_float.rs rename to spec/rust/src/formats/valid_fail_range_float.rs diff --git a/spec/rust/formats/valid_fail_range_int.rs b/spec/rust/src/formats/valid_fail_range_int.rs similarity index 100% rename from spec/rust/formats/valid_fail_range_int.rs rename to spec/rust/src/formats/valid_fail_range_int.rs diff --git a/spec/rust/formats/valid_fail_range_str.rs b/spec/rust/src/formats/valid_fail_range_str.rs similarity index 100% rename from spec/rust/formats/valid_fail_range_str.rs rename to spec/rust/src/formats/valid_fail_range_str.rs diff --git a/spec/rust/formats/valid_long.rs b/spec/rust/src/formats/valid_long.rs similarity index 100% rename from spec/rust/formats/valid_long.rs rename to spec/rust/src/formats/valid_long.rs diff --git a/spec/rust/formats/valid_not_parsed_if.rs b/spec/rust/src/formats/valid_not_parsed_if.rs similarity index 100% rename from spec/rust/formats/valid_not_parsed_if.rs rename to spec/rust/src/formats/valid_not_parsed_if.rs diff --git a/spec/rust/formats/valid_optional_id.rs b/spec/rust/src/formats/valid_optional_id.rs similarity index 100% rename from spec/rust/formats/valid_optional_id.rs rename to spec/rust/src/formats/valid_optional_id.rs diff --git a/spec/rust/formats/valid_short.rs b/spec/rust/src/formats/valid_short.rs similarity index 100% rename from spec/rust/formats/valid_short.rs rename to spec/rust/src/formats/valid_short.rs diff --git a/spec/rust/formats/valid_switch.rs b/spec/rust/src/formats/valid_switch.rs similarity index 100% rename from spec/rust/formats/valid_switch.rs rename to spec/rust/src/formats/valid_switch.rs diff --git a/spec/rust/formats/yaml_ints.rs b/spec/rust/src/formats/yaml_ints.rs similarity index 100% rename from spec/rust/formats/yaml_ints.rs rename to spec/rust/src/formats/yaml_ints.rs diff --git a/spec/rust/formats/zlib_surrounded.rs b/spec/rust/src/formats/zlib_surrounded.rs similarity index 100% rename from spec/rust/formats/zlib_surrounded.rs rename to spec/rust/src/formats/zlib_surrounded.rs diff --git a/spec/rust/formats/zlib_with_header_78.rs b/spec/rust/src/formats/zlib_with_header_78.rs similarity index 100% rename from spec/rust/formats/zlib_with_header_78.rs rename to spec/rust/src/formats/zlib_with_header_78.rs From 1377aafa1fc012e600c5b07d0c5d2f166ed66fea Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Sun, 24 Jul 2022 21:50:45 +0200 Subject: [PATCH 007/198] `--force` stores value in `config.outDir` --- .../src/main/scala/io/kaitai/struct/testtranslator/Main.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala index 6f0eccf8b..ef81bc384 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala @@ -81,8 +81,8 @@ object Main extends App { c.copy(srcFiles = list.toSeq) } text("process all KST files available") - opt[Unit]('f', "force") action { (x, c) => - c.copy(outDir = specDir) + opt[String]('f', "force") action { (x, c) => + c.copy(outDir = x) } text(s"force overwrite specs in production spec dirs (default: generate in $defaultOutDir)") } From e0ca664f438d8d2bdf4bb38a7788e53aa1b51bdb Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Sun, 24 Jul 2022 21:51:59 +0200 Subject: [PATCH 008/198] `crate::formats` instead of `crate::rust` --- .../io/kaitai/struct/testtranslator/specgenerators/RustSG.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 7a0f635af..a7a30a845 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -23,7 +23,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( | use std::fs; | | use kaitai::*; - | use crate::rust::${spec.id}::*; + | use crate::formats::${spec.id}::*; | | #[test] | fn test_${spec.id}() { From 80deccf926d2cd01062ec9fa0b63d5106360e755 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Sun, 24 Jul 2022 21:54:07 +0200 Subject: [PATCH 009/198] `doTestSpec(..., exactOutDir: Boolean)` --- .../io/kaitai/struct/testtranslator/TestTranslator.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index 19b99edc1..fcb8c5449 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -6,7 +6,7 @@ import io.kaitai.struct.datatype.DataType.UserTypeInstream import io.kaitai.struct.format._ import io.kaitai.struct.formats.JavaKSYParser import io.kaitai.struct.problems.ProblemSeverity -import io.kaitai.struct.testtranslator.Main.CLIOptions +import io.kaitai.struct.testtranslator.Main.{CLIOptions, defaultOutDir} import io.kaitai.struct.testtranslator.specgenerators._ import io.kaitai.struct.{ClassTypeProvider, CppRuntimeConfig} @@ -15,11 +15,11 @@ class TestTranslator(options: CLIOptions) { def run(): Unit = { options.srcFiles.foreach(testName => - doTestSpec(testName, options.targets, options.outDir) + doTestSpec(testName, options.targets, options.outDir, options.outDir != defaultOutDir) ) } - def doTestSpec(testName: String, langs: Seq[String], outDir: String): Unit = { + def doTestSpec(testName: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { Console.println(s"Translating: $testName") val testSpec = loadTestSpec(testName) @@ -31,7 +31,7 @@ class TestTranslator(options: CLIOptions) { val sg = getSG(langName, testSpec, provider) try { sg.run() - val outFile = s"$outDir/$langName/${sg.fileName(testName)}" + val outFile = if (exactOutDir) { s"$outDir/${sg.fileName(testName)}" } else { s"$outDir/$langName/${sg.fileName(testName)}" } Console.println(s"... generating $outFile") writeFile(outFile, sg.results) } catch { From a4fdb7ab2e7bdce9cbe65e6c957307855ca7e946 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 14:07:40 +0800 Subject: [PATCH 010/198] gen formats for rust lang only. --- build-rust-formats | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 build-rust-formats diff --git a/build-rust-formats b/build-rust-formats new file mode 100644 index 000000000..eda59a1b9 --- /dev/null +++ b/build-rust-formats @@ -0,0 +1,18 @@ +#!/bin/sh + +. ./config + +FORMATS_COMPILED_DIR=$FORMATS_COMPILED_DIR/rust + +rm -rf "$FORMATS_COMPILED_DIR" +mkdir -p "$FORMATS_COMPILED_DIR" +"$COMPILER_DIR/jvm/target/universal/stage/bin/kaitai-struct-compiler" -- \ + --verbose all -t rust -d "$FORMATS_COMPILED_DIR" \ + --import-path "$FORMATS_REPO_DIR" \ + --import-path "$FORMATS_KSY_DIR/ks_path" \ + --java-package io.kaitai.struct.testformats \ + --php-namespace 'Kaitai\Struct\Tests' \ + --go-package test_formats \ + --nim-module "kaitai_struct_nim_runtime" \ + --nim-opaque "../../tests/spec/nim/opaque/" \ + "$FORMATS_KSY_DIR"/*.ksy || : From 27cccd404da00c49a93153126171c15a2171fbef Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 14:09:06 +0800 Subject: [PATCH 011/198] gen tests for rust-only and more. --- build-rust-formats | 0 build-rust-tests | 74 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) mode change 100644 => 100755 build-rust-formats create mode 100755 build-rust-tests diff --git a/build-rust-formats b/build-rust-formats old mode 100644 new mode 100755 diff --git a/build-rust-tests b/build-rust-tests new file mode 100755 index 000000000..705142c5a --- /dev/null +++ b/build-rust-tests @@ -0,0 +1,74 @@ +#!/bin/bash -e + +. ./config + +LANG=rust +LANG_EXT=rs + +# existing tests +EXIST_TESTS_DIR="spec/$LANG/tests" + +# kst-file for test generation +KS_DIR="spec/ks" + +# formats dir +FORMATS_DIR=$FORMATS_KSY_DIR + +# build compiler +pushd $COMPILER_DIR +sbt publishLocal +popd + +# generate tests only for exist formats only +# ksy -> rs +# but also check if correspond kst-file exist +FORMATS= +FORMATS_ONLY_RUST= +KEEPING_TESTS= +for fn in $FORMATS_DIR/*; do + f=$(basename -- ${fn%%.*}) + + # regenerate tests only if there no such test exist + if [ ! -f "$EXIST_TESTS_DIR/test_$f.$LANG_EXT" ]; then + if [ -f "$KS_DIR/$f.kst" ]; then + FORMATS_FILES="${FORMATS_FILES} $f" + else + FORMATS_FILES_ONLY_RUST="${FORMATS_FILES_ONLY_RUST} $f" + fi + else + KEEPING_TESTS="${KEEPING_TESTS} test_$f.$LANG_EXT" + fi +done + +if [ ! -z "$KEEPING_TESTS" ]; then + echo "Keeping (edited) tests: $KEEPING_TESTS" +fi + +if [ -z "$FORMATS_FILES" ]; then + echo "No new tests were generated." + echo "Please delete selected (or all) tests (test_*.$LANG_EXT) from $EXIST_TESTS_DIR." + echo "And rerun this script to make a new." +else + echo generating tests for $LANG: + echo $FORMATS_FILES + + ./spec_kst_to_all -t $LANG $FORMATS_FILES + + mv "$KS_DIR/out/$LANG"/* "$EXIST_TESTS_DIR" + rm -rf spec/ks/out +fi + +# check for manual tests +if [ ! -z "$FORMATS_FILES_ONLY_RUST" ]; then + echo + echo "!!! This tests exist only for rust (manual tests):" + for f in ${FORMATS_FILES_ONLY_RUST[*]}; do + if ! [ -f "$EXIST_TESTS_DIR/manual_$f.$LANG_EXT" ]; then + echo "!!! $FORMATS_DIR/$f.ksy detected without correspond kst-file, please put manual test $EXIST_TESTS_DIR/manual_$f.$LANG_EXT" + else + echo "$EXIST_TESTS_DIR/manual_$f.$LANG_EXT" + fi + done + echo "!!! Please, update them manually !!!" + echo +fi From 970d47d16b8e75f7165a1e8529c1b9ee630b3511 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 14:10:15 +0800 Subject: [PATCH 012/198] run-rust added. --- run-rust | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 run-rust diff --git a/run-rust b/run-rust new file mode 100755 index 000000000..25d24bb74 --- /dev/null +++ b/run-rust @@ -0,0 +1,9 @@ +#!/bin/sh + +. ./config + +mkdir -p "$TEST_OUT_DIR/rust" + +cd spec/rust +cargo build +cargo test From f3e3c86c3ae05bf96c18934fbb12b63e6e2c9993 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 14:12:08 +0800 Subject: [PATCH 013/198] formats_rust/ dir added. --- config | 2 +- formats_rust/expr_0.ksy | 11 +++++ formats_rust/expr_1.ksy | 15 +++++++ formats_rust/fixed_contents.ksy | 7 +++ formats_rust/process_coerce_bytes.ksy | 23 ++++++++++ formats_rust/process_rotate.ksy | 15 +++++++ formats_rust/process_to_user.ksy | 14 ++++++ formats_rust/process_xor4_const.ksy | 8 ++++ formats_rust/process_xor4_value.ksy | 8 ++++ formats_rust/process_xor_const.ksy | 9 ++++ formats_rust/process_xor_value.ksy | 9 ++++ formats_rust/read_bytes.ksy | 9 ++++ formats_rust/str_encodings.ksy | 28 ++++++++++++ formats_rust/str_encodings_default.ksy | 32 +++++++++++++ formats_rust/str_encodings_utf16.ksy | 47 ++++++++++++++++++++ formats_rust/str_eos.ksy | 7 +++ formats_rust/str_literals.ksy | 13 ++++++ formats_rust/str_literals2.ksy | 18 ++++++++ formats_rust/str_pad_term.ksy | 24 ++++++++++ formats_rust/str_pad_term_empty.ksy | 25 +++++++++++ formats_rust/str_repeat.ksy | 8 ++++ formats_rust/switch_bytearray.ksy | 27 +++++++++++ formats_rust/switch_cast.ksy | 33 ++++++++++++++ formats_rust/switch_cast_parent.ksy | 28 ++++++++++++ formats_rust/switch_else_only.ksy | 22 +++++++++ formats_rust/switch_integers.ksy | 20 +++++++++ formats_rust/switch_integers2.ksy | 22 +++++++++ formats_rust/switch_manual_int.ksy | 27 +++++++++++ formats_rust/switch_manual_int_else.ksy | 33 ++++++++++++++ formats_rust/switch_manual_int_size.ksy | 37 +++++++++++++++ formats_rust/switch_manual_int_size_else.ksy | 42 +++++++++++++++++ formats_rust/switch_manual_int_size_eos.ksy | 43 ++++++++++++++++++ formats_rust/switch_manual_str.ksy | 29 ++++++++++++ formats_rust/switch_manual_str_else.ksy | 35 +++++++++++++++ formats_rust/term_bytes.ksy | 11 +++++ formats_rust/term_strz.ksy | 18 ++++++++ formats_rust/term_u1_val.ksy | 12 +++++ formats_rust/test_parent.ksy | 24 ++++++++++ formats_rust/ts_packet_header.ksy | 38 ++++++++++++++++ formats_rust/type_int_unary_op.ksy | 13 ++++++ formats_rust/type_ternary.ksy | 23 ++++++++++ formats_rust/valid_fail_inst.ksy | 11 +++++ formats_rust/valid_fail_range_bytes.ksy | 8 ++++ 43 files changed, 887 insertions(+), 1 deletion(-) create mode 100644 formats_rust/expr_0.ksy create mode 100644 formats_rust/expr_1.ksy create mode 100644 formats_rust/fixed_contents.ksy create mode 100644 formats_rust/process_coerce_bytes.ksy create mode 100644 formats_rust/process_rotate.ksy create mode 100644 formats_rust/process_to_user.ksy create mode 100644 formats_rust/process_xor4_const.ksy create mode 100644 formats_rust/process_xor4_value.ksy create mode 100644 formats_rust/process_xor_const.ksy create mode 100644 formats_rust/process_xor_value.ksy create mode 100644 formats_rust/read_bytes.ksy create mode 100644 formats_rust/str_encodings.ksy create mode 100644 formats_rust/str_encodings_default.ksy create mode 100644 formats_rust/str_encodings_utf16.ksy create mode 100644 formats_rust/str_eos.ksy create mode 100644 formats_rust/str_literals.ksy create mode 100644 formats_rust/str_literals2.ksy create mode 100644 formats_rust/str_pad_term.ksy create mode 100644 formats_rust/str_pad_term_empty.ksy create mode 100644 formats_rust/str_repeat.ksy create mode 100644 formats_rust/switch_bytearray.ksy create mode 100644 formats_rust/switch_cast.ksy create mode 100644 formats_rust/switch_cast_parent.ksy create mode 100644 formats_rust/switch_else_only.ksy create mode 100644 formats_rust/switch_integers.ksy create mode 100644 formats_rust/switch_integers2.ksy create mode 100644 formats_rust/switch_manual_int.ksy create mode 100644 formats_rust/switch_manual_int_else.ksy create mode 100644 formats_rust/switch_manual_int_size.ksy create mode 100644 formats_rust/switch_manual_int_size_else.ksy create mode 100644 formats_rust/switch_manual_int_size_eos.ksy create mode 100644 formats_rust/switch_manual_str.ksy create mode 100644 formats_rust/switch_manual_str_else.ksy create mode 100644 formats_rust/term_bytes.ksy create mode 100644 formats_rust/term_strz.ksy create mode 100644 formats_rust/term_u1_val.ksy create mode 100644 formats_rust/test_parent.ksy create mode 100644 formats_rust/ts_packet_header.ksy create mode 100644 formats_rust/type_int_unary_op.ksy create mode 100644 formats_rust/type_ternary.ksy create mode 100644 formats_rust/valid_fail_inst.ksy create mode 100644 formats_rust/valid_fail_range_bytes.ksy diff --git a/config b/config index 793344dd1..bc4f01596 100644 --- a/config +++ b/config @@ -1,5 +1,5 @@ COMPILER_DIR=../compiler -FORMATS_KSY_DIR=formats +FORMATS_KSY_DIR=formats_rust FORMATS_COMPILED_DIR=compiled FORMATS_REPO_DIR=../formats diff --git a/formats_rust/expr_0.ksy b/formats_rust/expr_0.ksy new file mode 100644 index 000000000..3fbd61e76 --- /dev/null +++ b/formats_rust/expr_0.ksy @@ -0,0 +1,11 @@ +meta: + id: expr_0 + endian: le +seq: + - id: len_of_1 + type: u2 +instances: + must_be_f7: + value: 7 + 0xf0 + must_be_abc123: + value: '"abc" + "123"' diff --git a/formats_rust/expr_1.ksy b/formats_rust/expr_1.ksy new file mode 100644 index 000000000..6b2921094 --- /dev/null +++ b/formats_rust/expr_1.ksy @@ -0,0 +1,15 @@ +meta: + id: expr_1 + endian: le +seq: + - id: len_of_1 + type: u2 + - id: str1 + type: str + size: len_of_1_mod + encoding: ASCII +instances: + len_of_1_mod: + value: len_of_1 - 2 + str1_len: + value: str1.length diff --git a/formats_rust/fixed_contents.ksy b/formats_rust/fixed_contents.ksy new file mode 100644 index 000000000..249a8eb29 --- /dev/null +++ b/formats_rust/fixed_contents.ksy @@ -0,0 +1,7 @@ +meta: + id: fixed_contents +seq: + - id: normal + contents: 'PACK-1' + - id: high_bit_8 + contents: [0xff, 0xff] diff --git a/formats_rust/process_coerce_bytes.ksy b/formats_rust/process_coerce_bytes.ksy new file mode 100644 index 000000000..05a100b49 --- /dev/null +++ b/formats_rust/process_coerce_bytes.ksy @@ -0,0 +1,23 @@ +# Checks coercion of two different byte arrays (with and without processing) +meta: + id: process_coerce_bytes +seq: + - id: records + type: record + repeat: expr + repeat-expr: 2 +types: + record: + seq: + - id: flag + type: u1 + - id: buf_unproc + size: 4 + if: flag == 0 + - id: buf_proc + size: 4 + process: xor(0xaa) + if: flag != 0 + instances: + buf: + value: 'flag == 0 ? buf_unproc : buf_proc' diff --git a/formats_rust/process_rotate.ksy b/formats_rust/process_rotate.ksy new file mode 100644 index 000000000..7afaebc3f --- /dev/null +++ b/formats_rust/process_rotate.ksy @@ -0,0 +1,15 @@ +meta: + id: process_rotate + endian: le +seq: + - id: buf1 + size: 5 + process: rol(3) + - id: buf2 + size: 5 + process: ror(3) + - id: key + type: u1 + - id: buf3 + size: 5 + process: rol(key) diff --git a/formats_rust/process_to_user.ksy b/formats_rust/process_to_user.ksy new file mode 100644 index 000000000..8cf658066 --- /dev/null +++ b/formats_rust/process_to_user.ksy @@ -0,0 +1,14 @@ +meta: + id: process_to_user +seq: + - id: buf1 + size: 5 + process: rol(3) + type: just_str +types: + just_str: + seq: + - id: str + type: str + encoding: UTF-8 + size-eos: true diff --git a/formats_rust/process_xor4_const.ksy b/formats_rust/process_xor4_const.ksy new file mode 100644 index 000000000..c090ee93d --- /dev/null +++ b/formats_rust/process_xor4_const.ksy @@ -0,0 +1,8 @@ +meta: + id: process_xor4_const +seq: + - id: key + size: 4 + - id: buf + size-eos: true + process: xor([0xec, 0xbb, 0xa3, 0x14]) diff --git a/formats_rust/process_xor4_value.ksy b/formats_rust/process_xor4_value.ksy new file mode 100644 index 000000000..19d812c0d --- /dev/null +++ b/formats_rust/process_xor4_value.ksy @@ -0,0 +1,8 @@ +meta: + id: process_xor4_value +seq: + - id: key + size: 4 + - id: buf + size-eos: true + process: xor(key) diff --git a/formats_rust/process_xor_const.ksy b/formats_rust/process_xor_const.ksy new file mode 100644 index 000000000..549ecd697 --- /dev/null +++ b/formats_rust/process_xor_const.ksy @@ -0,0 +1,9 @@ +meta: + id: process_xor_const + endian: le +seq: + - id: key + type: u1 + - id: buf + size-eos: true + process: xor(0xff) diff --git a/formats_rust/process_xor_value.ksy b/formats_rust/process_xor_value.ksy new file mode 100644 index 000000000..e27e48cc1 --- /dev/null +++ b/formats_rust/process_xor_value.ksy @@ -0,0 +1,9 @@ +meta: + id: process_xor_value + endian: le +seq: + - id: key + type: u1 + - id: buf + size-eos: true + process: xor(key) diff --git a/formats_rust/read_bytes.ksy b/formats_rust/read_bytes.ksy new file mode 100644 index 000000000..382fba24e --- /dev/null +++ b/formats_rust/read_bytes.ksy @@ -0,0 +1,9 @@ +meta: + id: read_bytes +seq: + - id: len + type: u1 + - id: val + size: len + - id: padding + size: 2 diff --git a/formats_rust/str_encodings.ksy b/formats_rust/str_encodings.ksy new file mode 100644 index 000000000..4bfa31e93 --- /dev/null +++ b/formats_rust/str_encodings.ksy @@ -0,0 +1,28 @@ +meta: + id: str_encodings + endian: le +seq: + - id: len_of_1 + type: u2 + - id: str1 + type: str + size: len_of_1 + encoding: ASCII + - id: len_of_2 + type: u2 + - id: str2 + type: str + size: len_of_2 + encoding: UTF-8 + - id: len_of_3 + type: u2 + - id: str3 + type: str + size: len_of_3 + encoding: SJIS + - id: len_of_4 + type: u2 + - id: str4 + type: str + size: len_of_4 + encoding: CP866 # CP437 diff --git a/formats_rust/str_encodings_default.ksy b/formats_rust/str_encodings_default.ksy new file mode 100644 index 000000000..be4e1ef03 --- /dev/null +++ b/formats_rust/str_encodings_default.ksy @@ -0,0 +1,32 @@ +meta: + id: str_encodings_default + endian: le + encoding: UTF-8 +seq: + - id: len_of_1 + type: u2 + - id: str1 + type: str + size: len_of_1 + - id: rest + type: subtype +types: + subtype: + seq: + - id: len_of_2 + type: u2 + - id: str2 + type: str + size: len_of_2 + - id: len_of_3 + type: u2 + - id: str3 + type: str + size: len_of_3 + encoding: SJIS + - id: len_of_4 + type: u2 + - id: str4 + type: str + size: len_of_4 + encoding: CP866 # CP437 diff --git a/formats_rust/str_encodings_utf16.ksy b/formats_rust/str_encodings_utf16.ksy new file mode 100644 index 000000000..3945951f0 --- /dev/null +++ b/formats_rust/str_encodings_utf16.ksy @@ -0,0 +1,47 @@ +meta: + id: str_encodings_utf16 + endian: le +seq: + - id: len_be + type: u4 + - id: be_bom_removed + size: len_be + type: str_be_bom_removed + + - id: len_le + type: u4 + - id: le_bom_removed + size: len_le + type: str_le_bom_removed + +# instances: +# be_with_bom: +# pos: 4 +# size: len_be +# type: str +# encoding: UTF-16 + +# le_with_bom: +# pos: 4 + len_be + 4 +# size: len_le +# type: str +# encoding: UTF-16 + +types: + str_be_bom_removed: + seq: + - id: bom + type: u2be + - id: str + size-eos: true + type: str + encoding: UTF-16BE + + str_le_bom_removed: + seq: + - id: bom + type: u2le + - id: str + size-eos: true + type: str + encoding: UTF-16LE diff --git a/formats_rust/str_eos.ksy b/formats_rust/str_eos.ksy new file mode 100644 index 000000000..cd192334e --- /dev/null +++ b/formats_rust/str_eos.ksy @@ -0,0 +1,7 @@ +meta: + id: str_eos +seq: + - id: str + type: str + size-eos: true + encoding: UTF-8 diff --git a/formats_rust/str_literals.ksy b/formats_rust/str_literals.ksy new file mode 100644 index 000000000..1901813a8 --- /dev/null +++ b/formats_rust/str_literals.ksy @@ -0,0 +1,13 @@ +meta: + id: str_literals +instances: + complex_str: + value: '"\0\1\2\a\b\n\r\t\v\f\e\75\7\u000a\u0024\u263b"' + double_quotes: + value: '"\"\u0022\42"' + backslashes: + value: '"\\\u005c\134"' + octal_eatup: + value: '"\0\62\62"' + octal_eatup2: + value: '"\2\62"' diff --git a/formats_rust/str_literals2.ksy b/formats_rust/str_literals2.ksy new file mode 100644 index 000000000..3cf6b0881 --- /dev/null +++ b/formats_rust/str_literals2.ksy @@ -0,0 +1,18 @@ +# Tests double-quoted interpolation variables used in various +# languages. None of this should be actually processed as interpolated +# variables, all should be escaped properly in relevant translators. +meta: + id: str_literals2 +instances: + # PHP, Perl + dollar1: + value: '"$foo"' + # PHP, Perl + dollar2: + value: '"${foo}"' + # Ruby + hash: + value: '"#{foo}"' + # Perl + at_sign: + value: '"@foo"' diff --git a/formats_rust/str_pad_term.ksy b/formats_rust/str_pad_term.ksy new file mode 100644 index 000000000..1996d359b --- /dev/null +++ b/formats_rust/str_pad_term.ksy @@ -0,0 +1,24 @@ +# Tests "pad-right" and "terminator" functionality in fixed-length strings ("str" with "size") +meta: + id: str_pad_term + encoding: UTF-8 +seq: + - id: str_pad + type: str + size: 20 + pad-right: 0x40 + - id: str_term + type: str + size: 20 + terminator: 0x40 + - id: str_term_and_pad + type: str + size: 20 + terminator: 0x40 + pad-right: 0x2b + - id: str_term_include + type: str + size: 20 + terminator: 0x40 + include: true + # "consume" is pointless to test: it will be always consumed anyway, as we have a fixed-length string diff --git a/formats_rust/str_pad_term_empty.ksy b/formats_rust/str_pad_term_empty.ksy new file mode 100644 index 000000000..12a2d194d --- /dev/null +++ b/formats_rust/str_pad_term_empty.ksy @@ -0,0 +1,25 @@ +# Same as "str_pad_term", but used with different input file that is +# meant to test fully empty strings +meta: + id: str_pad_term_empty + encoding: UTF-8 +seq: + - id: str_pad + type: str + size: 20 + pad-right: 0x40 + - id: str_term + type: str + size: 20 + terminator: 0x40 + - id: str_term_and_pad + type: str + size: 20 + terminator: 0x40 + pad-right: 0x2b + - id: str_term_include + type: str + size: 20 + terminator: 0x40 + include: true + # "consume" is pointless to test: it will be always consumed anyway, as we have a fixed-length string diff --git a/formats_rust/str_repeat.ksy b/formats_rust/str_repeat.ksy new file mode 100644 index 000000000..60d3681ba --- /dev/null +++ b/formats_rust/str_repeat.ksy @@ -0,0 +1,8 @@ +meta: + id: str_repeat +seq: + - id: entries + type: str + size: 4 + repeat: eos + encoding: UTF-8 diff --git a/formats_rust/switch_bytearray.ksy b/formats_rust/switch_bytearray.ksy new file mode 100644 index 000000000..a9db63a6b --- /dev/null +++ b/formats_rust/switch_bytearray.ksy @@ -0,0 +1,27 @@ +meta: + id: switch_bytearray +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + size: 1 + - id: body + type: + switch-on: code + cases: + '[73]': intval + '[83]': strval + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/formats_rust/switch_cast.ksy b/formats_rust/switch_cast.ksy new file mode 100644 index 000000000..ba4b883ee --- /dev/null +++ b/formats_rust/switch_cast.ksy @@ -0,0 +1,33 @@ +meta: + id: switch_cast +seq: + - id: opcodes + type: opcode + repeat: eos +#instances: +# first_obj: +# value: opcodes[0].body.as +# second_val: +# value: opcodes[1].body.as.value +# err_cast: +# value: opcodes[2].body.as +types: + opcode: + seq: + - id: code + type: u1 + - id: body + type: + switch-on: code + cases: + 73: intval + 83: strval + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/formats_rust/switch_cast_parent.ksy b/formats_rust/switch_cast_parent.ksy new file mode 100644 index 000000000..21565383a --- /dev/null +++ b/formats_rust/switch_cast_parent.ksy @@ -0,0 +1,28 @@ +meta: + id: switch_cast_parent +seq: + - id: opcodes + type: opcode + repeat: eos + +types: + opcode: + seq: + - id: code + type: u1 + - id: body + type: + switch-on: code + cases: + 73: intval + 83: strval + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/formats_rust/switch_else_only.ksy b/formats_rust/switch_else_only.ksy new file mode 100644 index 000000000..199ffd085 --- /dev/null +++ b/formats_rust/switch_else_only.ksy @@ -0,0 +1,22 @@ +meta: + id: switch_else_only +seq: + - id: opcode + type: s1 + - id: prim_byte + type: + switch-on: opcode + cases: + _: s1 + - id: indicator + size: 4 + - id: ut + type: + switch-on: indicator + cases: + _: data +types: + data: + seq: + - id: value + size: 4 diff --git a/formats_rust/switch_integers.ksy b/formats_rust/switch_integers.ksy new file mode 100644 index 000000000..647bdb640 --- /dev/null +++ b/formats_rust/switch_integers.ksy @@ -0,0 +1,20 @@ +meta: + id: switch_integers + endian: le +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: u1 + - id: body + type: + switch-on: code + cases: + 1: u1 + 2: u2 + 4: u4 + 8: u8 diff --git a/formats_rust/switch_integers2.ksy b/formats_rust/switch_integers2.ksy new file mode 100644 index 000000000..8f33f40f4 --- /dev/null +++ b/formats_rust/switch_integers2.ksy @@ -0,0 +1,22 @@ +meta: + id: switch_integers2 + endian: le +seq: + - id: code + type: u1 + - id: len + type: + switch-on: code + cases: + 1: u1 + 2: u2 + 4: u4 + 8: u8 + - id: ham + size: len + - id: padding + type: u1 + if: len > 3 +instances: + len_mod_str: + value: (len * 2 - 1).to_s diff --git a/formats_rust/switch_manual_int.ksy b/formats_rust/switch_manual_int.ksy new file mode 100644 index 000000000..a62208c0e --- /dev/null +++ b/formats_rust/switch_manual_int.ksy @@ -0,0 +1,27 @@ +meta: + id: switch_manual_int +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: u1 + - id: body + type: + switch-on: code + cases: + 73: intval + 83: strval + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/formats_rust/switch_manual_int_else.ksy b/formats_rust/switch_manual_int_else.ksy new file mode 100644 index 000000000..a1ffe3590 --- /dev/null +++ b/formats_rust/switch_manual_int_else.ksy @@ -0,0 +1,33 @@ +meta: + id: switch_manual_int_else + endian: le +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: u1 + - id: body + type: + switch-on: code + cases: + 73: intval + 83: strval + _: noneval + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII + noneval: + seq: + - id: filler + type: u4 diff --git a/formats_rust/switch_manual_int_size.ksy b/formats_rust/switch_manual_int_size.ksy new file mode 100644 index 000000000..535c73fbb --- /dev/null +++ b/formats_rust/switch_manual_int_size.ksy @@ -0,0 +1,37 @@ +meta: + id: switch_manual_int_size + endian: le +seq: + - id: chunks + type: chunk + repeat: eos +types: + chunk: + seq: + - id: code + type: u1 + - id: size + type: u4 + - id: body + size: size + type: + switch-on: code + cases: + 0x11: chunk_meta + 0x22: chunk_dir + types: + chunk_meta: + seq: + - id: title + type: strz + encoding: UTF-8 + - id: author + type: strz + encoding: UTF-8 + chunk_dir: + seq: + - id: entries + type: str + size: 4 + repeat: eos + encoding: UTF-8 diff --git a/formats_rust/switch_manual_int_size_else.ksy b/formats_rust/switch_manual_int_size_else.ksy new file mode 100644 index 000000000..9f108374f --- /dev/null +++ b/formats_rust/switch_manual_int_size_else.ksy @@ -0,0 +1,42 @@ +meta: + id: switch_manual_int_size_else + endian: le +seq: + - id: chunks + type: chunk + repeat: eos +types: + chunk: + seq: + - id: code + type: u1 + - id: size + type: u4 + - id: body + size: size + type: + switch-on: code + cases: + 0x11: chunk_meta + 0x22: chunk_dir + _: dummy + types: + chunk_meta: + seq: + - id: title + type: strz + encoding: UTF-8 + - id: author + type: strz + encoding: UTF-8 + chunk_dir: + seq: + - id: entries + type: str + size: 4 + repeat: eos + encoding: UTF-8 + dummy: + seq: + - id: rest + size-eos: true diff --git a/formats_rust/switch_manual_int_size_eos.ksy b/formats_rust/switch_manual_int_size_eos.ksy new file mode 100644 index 000000000..d5fb8ae29 --- /dev/null +++ b/formats_rust/switch_manual_int_size_eos.ksy @@ -0,0 +1,43 @@ +meta: + id: switch_manual_int_size_eos + endian: le +seq: + - id: chunks + type: chunk + repeat: eos +types: + chunk: + seq: + - id: code + type: u1 + - id: size + type: u4 + - id: body + size: size + type: chunk_body + types: + chunk_body: + seq: + - id: body + size-eos: true + type: + switch-on: _parent.code + cases: + 0x11: chunk_meta + 0x22: chunk_dir + types: + chunk_meta: + seq: + - id: title + type: strz + encoding: UTF-8 + - id: author + type: strz + encoding: UTF-8 + chunk_dir: + seq: + - id: entries + type: str + size: 4 + repeat: eos + encoding: UTF-8 diff --git a/formats_rust/switch_manual_str.ksy b/formats_rust/switch_manual_str.ksy new file mode 100644 index 000000000..5e244eeac --- /dev/null +++ b/formats_rust/switch_manual_str.ksy @@ -0,0 +1,29 @@ +meta: + id: switch_manual_str +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: str + size: 1 + encoding: ASCII + - id: body + type: + switch-on: code + cases: + '"I"': intval + '"S"': strval + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/formats_rust/switch_manual_str_else.ksy b/formats_rust/switch_manual_str_else.ksy new file mode 100644 index 000000000..24c409754 --- /dev/null +++ b/formats_rust/switch_manual_str_else.ksy @@ -0,0 +1,35 @@ +meta: + id: switch_manual_str_else + endian: le +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: str + size: 1 + encoding: ASCII + - id: body + type: + switch-on: code + cases: + '"I"': intval + '"S"': strval + _: noneval + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII + noneval: + seq: + - id: filler + type: u4 diff --git a/formats_rust/term_bytes.ksy b/formats_rust/term_bytes.ksy new file mode 100644 index 000000000..a5f4e3e3a --- /dev/null +++ b/formats_rust/term_bytes.ksy @@ -0,0 +1,11 @@ +meta: + id: term_bytes +seq: + - id: s1 + terminator: 0x7c + - id: s2 + terminator: 0x7c + consume: false + - id: s3 + terminator: 0x40 + include: true diff --git a/formats_rust/term_strz.ksy b/formats_rust/term_strz.ksy new file mode 100644 index 000000000..e434f5f9b --- /dev/null +++ b/formats_rust/term_strz.ksy @@ -0,0 +1,18 @@ +meta: + id: term_strz + endian: le +seq: + - id: s1 + type: str + encoding: UTF-8 + terminator: 0x7c + - id: s2 + type: str + encoding: UTF-8 + terminator: 0x7c + consume: false + - id: s3 + type: str + encoding: UTF-8 + terminator: 0x40 + include: true diff --git a/formats_rust/term_u1_val.ksy b/formats_rust/term_u1_val.ksy new file mode 100644 index 000000000..2f8d2f455 --- /dev/null +++ b/formats_rust/term_u1_val.ksy @@ -0,0 +1,12 @@ +# Test if unsigned values in `terminator` work +meta: + id: term_u1_val +seq: + - id: foo + terminator: 0xe3 + consume: false + - id: bar + type: str + encoding: UTF-8 + terminator: 0xab + include: true diff --git a/formats_rust/test_parent.ksy b/formats_rust/test_parent.ksy new file mode 100644 index 000000000..b1d777eab --- /dev/null +++ b/formats_rust/test_parent.ksy @@ -0,0 +1,24 @@ +meta: + id: test_parent +seq: + - id: root_byte + type: u1 + - id: child + type: child_struct +types: + child_struct: + seq: + - id: child_byte + type: u1 + - id: child2 + type: child2_struct + repeat: expr + repeat-expr: _root.root_byte + types: + child2_struct: + seq: + - id: child2_byte + type: u1 + repeat: expr + repeat-expr: _parent.child_byte + diff --git a/formats_rust/ts_packet_header.ksy b/formats_rust/ts_packet_header.ksy new file mode 100644 index 000000000..e5902b25c --- /dev/null +++ b/formats_rust/ts_packet_header.ksy @@ -0,0 +1,38 @@ +# Transport stream packet +# see H.222.0 F.1.1 + +# |7,6,5,4,2,1,0|7,6,5,4,3,2,1,0|7,6,5,4,3,2,1,0|7,6,5,4,3,2,1,0| +# | sync_byte | , , ,<-------pid------------->| ,afc,<-cc-->| + +meta: + id: ts_packet_header + endian: le +doc: > + describes the first 4 header bytes of a TS Packet header +seq: + - id: sync_byte + type: u1 + #contents: [0x47] + - id: transport_error_indicator + type: b1 + - id: payload_unit_start_indicator + type: b1 + - id: transport_priority + type: b1 + - id: pid + type: b13 + - id: transport_scrambling_control + type: b2 + - id: adaptation_field_control + type: b2 + enum: adaptation_field_control_enum + - id: continuity_counter + type: b4 + - id: ts_packet_remain + size: 184 +enums: + adaptation_field_control_enum: + 0x0: reserved + 0x1: payload_only + 0x2: adaptation_field_only + 0x3: adaptation_field_and_payload diff --git a/formats_rust/type_int_unary_op.ksy b/formats_rust/type_int_unary_op.ksy new file mode 100644 index 000000000..c9a3c7e74 --- /dev/null +++ b/formats_rust/type_int_unary_op.ksy @@ -0,0 +1,13 @@ +meta: + id: type_int_unary_op + endian: le +seq: + - id: value_s2 + type: s2 + - id: value_s8 + type: s8 +instances: + unary_s2: + value: -value_s2 + unary_s8: + value: -value_s8 diff --git a/formats_rust/type_ternary.ksy b/formats_rust/type_ternary.ksy new file mode 100644 index 000000000..e93637e8b --- /dev/null +++ b/formats_rust/type_ternary.ksy @@ -0,0 +1,23 @@ +meta: + id: type_ternary +seq: + - id: dif_wo_hack + size: 1 + type: dummy + if: not is_hack + - id: dif_with_hack + size: 1 + type: dummy + process: xor(0b00000011) +types: + dummy: + seq: + - id: value + type: u1 +instances: + is_hack: + value: "true" + dif: + value: "not is_hack ? dif_wo_hack : dif_with_hack" + dif_value: + value: dif.value diff --git a/formats_rust/valid_fail_inst.ksy b/formats_rust/valid_fail_inst.ksy new file mode 100644 index 000000000..c993514f4 --- /dev/null +++ b/formats_rust/valid_fail_inst.ksy @@ -0,0 +1,11 @@ +meta: + id: valid_fail_inst +seq: + - id: a + type: u1 + if: inst >= 0 # invoke instance +instances: + inst: + pos: 5 + type: u1 + valid: 0x50 # there is actually 0x31 in the file diff --git a/formats_rust/valid_fail_range_bytes.ksy b/formats_rust/valid_fail_range_bytes.ksy new file mode 100644 index 000000000..06025b4a1 --- /dev/null +++ b/formats_rust/valid_fail_range_bytes.ksy @@ -0,0 +1,8 @@ +meta: + id: valid_fail_range_bytes +seq: + - id: foo + size: 2 + valid: + min: '[80]' + max: '[80, 49]' # there is actually [80, 65] in the file From f13f0311bd5897ee4616853277271ddfbadca6be Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 14:33:33 +0800 Subject: [PATCH 014/198] rust updated. --- spec/rust/Cargo.lock | 121 ---- spec/rust/Cargo.toml | 2 +- spec/rust/build.rs | 22 +- spec/rust/src/formats/bcd_user_type_be.rs | 558 ------------------ spec/rust/src/formats/bcd_user_type_le.rs | 558 ------------------ spec/rust/src/formats/bits_byte_aligned.rs | 61 -- spec/rust/src/formats/bits_enum.rs | 65 -- .../rust/src/formats/bits_seq_endian_combo.rs | 55 -- spec/rust/src/formats/bits_shift_by_b32_le.rs | 43 -- spec/rust/src/formats/bits_shift_by_b64_le.rs | 43 -- .../src/formats/bits_signed_res_b32_be.rs | 41 -- .../src/formats/bits_signed_res_b32_le.rs | 41 -- .../src/formats/bits_signed_shift_b32_le.rs | 43 -- .../src/formats/bits_signed_shift_b64_le.rs | 43 -- spec/rust/src/formats/bits_simple.rs | 82 --- spec/rust/src/formats/bits_simple_le.rs | 82 --- .../rust/src/formats/bits_unaligned_b32_be.rs | 45 -- .../rust/src/formats/bits_unaligned_b32_le.rs | 45 -- .../rust/src/formats/bits_unaligned_b64_be.rs | 45 -- .../rust/src/formats/bits_unaligned_b64_le.rs | 45 -- spec/rust/src/formats/buffered_struct.rs | 88 --- spec/rust/src/formats/bytes_pad_term.rs | 47 -- spec/rust/src/formats/cast_nested.rs | 224 ------- spec/rust/src/formats/cast_to_imported.rs | 55 -- spec/rust/src/formats/cast_to_top.rs | 69 --- spec/rust/src/formats/combine_bool.rs | 67 --- spec/rust/src/formats/combine_bytes.rs | 136 ----- spec/rust/src/formats/combine_enum.rs | 72 --- spec/rust/src/formats/combine_str.rs | 214 ------- spec/rust/src/formats/debug_0.rs | 49 -- spec/rust/src/formats/default_big_endian.rs | 41 -- .../src/formats/default_bit_endian_mod.rs | 147 ----- .../formats/default_endian_expr_exception.rs | 119 ---- .../formats/default_endian_expr_inherited.rs | 200 ------- .../src/formats/default_endian_expr_is_be.rs | 182 ------ .../src/formats/default_endian_expr_is_le.rs | 119 ---- spec/rust/src/formats/default_endian_mod.rs | 144 ----- spec/rust/src/formats/docstrings.rs | 105 ---- spec/rust/src/formats/docstrings_docref.rs | 79 --- .../src/formats/docstrings_docref_multi.rs | 40 -- spec/rust/src/formats/enum_0.rs | 61 -- spec/rust/src/formats/enum_1.rs | 127 ---- spec/rust/src/formats/enum_deep.rs | 141 ----- spec/rust/src/formats/enum_deep_literals.rs | 167 ------ spec/rust/src/formats/enum_fancy.rs | 63 -- spec/rust/src/formats/enum_for_unknown_id.rs | 59 -- spec/rust/src/formats/enum_if.rs | 174 ------ spec/rust/src/formats/enum_import.rs | 43 -- spec/rust/src/formats/enum_int_range_s.rs | 63 -- spec/rust/src/formats/enum_int_range_u.rs | 59 -- spec/rust/src/formats/enum_invalid.rs | 59 -- spec/rust/src/formats/enum_long_range_s.rs | 79 --- spec/rust/src/formats/enum_long_range_u.rs | 67 --- spec/rust/src/formats/enum_negative.rs | 59 -- spec/rust/src/formats/enum_of_value_inst.rs | 87 --- spec/rust/src/formats/enum_to_i.rs | 126 ---- .../src/formats/enum_to_i_class_border_1.rs | 90 --- .../src/formats/enum_to_i_class_border_2.rs | 54 -- spec/rust/src/formats/eof_exception_bytes.rs | 41 -- spec/rust/src/formats/eof_exception_u4.rs | 43 -- spec/rust/src/formats/eos_exception_bytes.rs | 76 --- spec/rust/src/formats/eos_exception_u4.rs | 78 --- spec/rust/src/formats/expr_0.rs | 67 --- spec/rust/src/formats/expr_1.rs | 69 --- spec/rust/src/formats/expr_2.rs | 266 --------- spec/rust/src/formats/expr_3.rs | 173 ------ spec/rust/src/formats/expr_array.rs | 252 -------- spec/rust/src/formats/expr_bits.rs | 148 ----- spec/rust/src/formats/expr_bytes_cmp.rs | 186 ------ .../src/formats/expr_bytes_non_literal.rs | 56 -- spec/rust/src/formats/expr_bytes_ops.rs | 210 ------- spec/rust/src/formats/expr_enum.rs | 100 ---- spec/rust/src/formats/expr_if_int_ops.rs | 77 --- spec/rust/src/formats/expr_int_div.rs | 95 --- spec/rust/src/formats/expr_io_eof.rs | 98 --- spec/rust/src/formats/expr_io_pos.rs | 84 --- spec/rust/src/formats/expr_mod.rs | 95 --- spec/rust/src/formats/expr_ops_parens.rs | 234 -------- spec/rust/src/formats/expr_sizeof_type_0.rs | 89 --- spec/rust/src/formats/expr_sizeof_type_1.rs | 137 ----- spec/rust/src/formats/expr_sizeof_value_0.rs | 145 ----- .../src/formats/expr_sizeof_value_sized.rs | 147 ----- spec/rust/src/formats/expr_str_encodings.rs | 146 ----- spec/rust/src/formats/expr_str_ops.rs | 249 -------- spec/rust/src/formats/fixed_contents.rs | 43 -- spec/rust/src/formats/fixed_struct.rs | 139 ----- spec/rust/src/formats/float_to_i.rs | 173 ------ spec/rust/src/formats/floating_points.rs | 88 --- spec/rust/src/formats/hello_world.rs | 41 -- spec/rust/src/formats/if_instances.rs | 57 -- spec/rust/src/formats/if_struct.rs | 158 ----- spec/rust/src/formats/if_values.rs | 94 --- spec/rust/src/formats/imported_1.rs | 44 -- spec/rust/src/formats/imported_2.rs | 41 -- spec/rust/src/formats/imports0.rs | 57 -- spec/rust/src/formats/imports_circular_a.rs | 44 -- spec/rust/src/formats/imports_circular_b.rs | 47 -- spec/rust/src/formats/imports_rel_1.rs | 44 -- spec/rust/src/formats/index_sizes.rs | 53 -- spec/rust/src/formats/index_to_param_eos.rs | 89 --- spec/rust/src/formats/index_to_param_expr.rs | 87 --- spec/rust/src/formats/index_to_param_until.rs | 88 --- spec/rust/src/formats/instance_std.rs | 54 -- spec/rust/src/formats/instance_std_array.rs | 65 -- spec/rust/src/formats/instance_user_array.rs | 106 ---- spec/rust/src/formats/integers.rs | 93 --- .../src/formats/integers_double_overflow.rs | 115 ---- spec/rust/src/formats/integers_min_max.rs | 137 ----- spec/rust/src/formats/io_local_var.rs | 122 ---- .../rust/src/formats/js_signed_right_shift.rs | 65 -- spec/rust/src/formats/meta_tags.rs | 39 -- spec/rust/src/formats/meta_xref.rs | 39 -- spec/rust/src/formats/multiple_use.rs | 155 ----- spec/rust/src/formats/nav_parent.rs | 150 ----- spec/rust/src/formats/nav_parent2.rs | 149 ----- spec/rust/src/formats/nav_parent3.rs | 163 ----- spec/rust/src/formats/nav_parent_false.rs | 151 ----- spec/rust/src/formats/nav_parent_false2.rs | 74 --- spec/rust/src/formats/nav_parent_override.rs | 111 ---- spec/rust/src/formats/nav_parent_switch.rs | 129 ---- .../src/formats/nav_parent_switch_cast.rs | 224 ------- .../src/formats/nav_parent_vs_value_inst.rs | 87 --- spec/rust/src/formats/nav_root.rs | 150 ----- spec/rust/src/formats/nested_same_name.rs | 173 ------ spec/rust/src/formats/nested_same_name2.rs | 181 ------ spec/rust/src/formats/nested_type_param.rs | 106 ---- spec/rust/src/formats/nested_types.rs | 144 ----- spec/rust/src/formats/nested_types2.rs | 218 ------- spec/rust/src/formats/nested_types3.rs | 210 ------- spec/rust/src/formats/non_standard.rs | 95 --- spec/rust/src/formats/opaque_external_type.rs | 42 -- .../formats/opaque_external_type_02_child.rs | 94 --- .../formats/opaque_external_type_02_parent.rs | 75 --- spec/rust/src/formats/opaque_with_param.rs | 42 -- spec/rust/src/formats/optional_id.rs | 45 -- .../src/formats/params_call_extra_parens.rs | 75 --- spec/rust/src/formats/params_call_short.rs | 117 ---- spec/rust/src/formats/params_def.rs | 48 -- spec/rust/src/formats/params_enum.rs | 106 ---- .../src/formats/params_pass_array_usertype.rs | 116 ---- spec/rust/src/formats/params_pass_bool.rs | 150 ----- spec/rust/src/formats/params_pass_usertype.rs | 110 ---- spec/rust/src/formats/position_abs.rs | 89 --- spec/rust/src/formats/position_in_seq.rs | 93 --- spec/rust/src/formats/position_to_end.rs | 89 --- spec/rust/src/formats/process_coerce_bytes.rs | 103 ---- .../src/formats/process_coerce_usertype1.rs | 141 ----- .../src/formats/process_coerce_usertype2.rs | 139 ----- spec/rust/src/formats/process_custom.rs | 53 -- .../src/formats/process_custom_no_args.rs | 43 -- spec/rust/src/formats/process_repeat_bytes.rs | 48 -- .../src/formats/process_repeat_usertype.rs | 86 --- spec/rust/src/formats/process_rotate.rs | 53 -- spec/rust/src/formats/process_to_user.rs | 79 --- spec/rust/src/formats/process_xor4_const.rs | 45 -- spec/rust/src/formats/process_xor4_value.rs | 45 -- spec/rust/src/formats/process_xor_const.rs | 45 -- spec/rust/src/formats/process_xor_value.rs | 45 -- spec/rust/src/formats/recursive_one.rs | 106 ---- spec/rust/src/formats/repeat_eos_bit.rs | 47 -- spec/rust/src/formats/repeat_eos_struct.rs | 82 --- spec/rust/src/formats/repeat_eos_u4.rs | 47 -- spec/rust/src/formats/repeat_n_struct.rs | 82 --- spec/rust/src/formats/repeat_n_strz.rs | 47 -- spec/rust/src/formats/repeat_n_strz_double.rs | 53 -- spec/rust/src/formats/repeat_until_complex.rs | 138 ----- spec/rust/src/formats/repeat_until_s4.rs | 48 -- spec/rust/src/formats/repeat_until_sized.rs | 84 --- spec/rust/src/formats/str_encodings.rs | 55 -- .../rust/src/formats/str_encodings_default.rs | 88 --- spec/rust/src/formats/str_encodings_utf16.rs | 121 ---- spec/rust/src/formats/str_eos.rs | 41 -- spec/rust/src/formats/str_literals.rs | 104 ---- spec/rust/src/formats/str_literals2.rs | 91 --- spec/rust/src/formats/str_pad_term.rs | 47 -- spec/rust/src/formats/str_pad_term_empty.rs | 47 -- spec/rust/src/formats/switch_bytearray.rs | 172 ------ spec/rust/src/formats/switch_cast.rs | 211 ------- spec/rust/src/formats/switch_else_only.rs | 100 ---- spec/rust/src/formats/switch_integers.rs | 124 ---- spec/rust/src/formats/switch_integers2.rs | 105 ---- spec/rust/src/formats/switch_manual_enum.rs | 188 ------ .../src/formats/switch_manual_enum_invalid.rs | 188 ------ .../switch_manual_enum_invalid_else.rs | 241 -------- spec/rust/src/formats/switch_manual_int.rs | 172 ------ .../src/formats/switch_manual_int_else.rs | 214 ------- .../src/formats/switch_manual_int_size.rs | 194 ------ .../formats/switch_manual_int_size_else.rs | 228 ------- spec/rust/src/formats/switch_manual_str.rs | 172 ------ .../src/formats/switch_manual_str_else.rs | 214 ------- .../rust/src/formats/switch_multi_bool_ops.rs | 124 ---- spec/rust/src/formats/switch_repeat_expr.rs | 153 ----- .../src/formats/switch_repeat_expr_invalid.rs | 153 ----- spec/rust/src/formats/term_bytes.rs | 45 -- spec/rust/src/formats/term_strz.rs | 45 -- spec/rust/src/formats/term_u1_val.rs | 43 -- spec/rust/src/formats/to_string_custom.rs | 43 -- spec/rust/src/formats/ts_packet_header.rs | 79 --- spec/rust/src/formats/type_int_unary_op.rs | 69 --- spec/rust/src/formats/type_ternary.rs | 125 ---- spec/rust/src/formats/type_ternary_opaque.rs | 83 --- spec/rust/src/formats/user_type.rs | 76 --- .../src/formats/valid_eq_str_encodings.rs | 55 -- spec/rust/src/formats/valid_fail_anyof_int.rs | 41 -- spec/rust/src/formats/valid_fail_contents.rs | 41 -- spec/rust/src/formats/valid_fail_eq_bytes.rs | 41 -- spec/rust/src/formats/valid_fail_eq_int.rs | 41 -- spec/rust/src/formats/valid_fail_eq_str.rs | 41 -- spec/rust/src/formats/valid_fail_expr.rs | 45 -- spec/rust/src/formats/valid_fail_inst.rs | 59 -- spec/rust/src/formats/valid_fail_max_int.rs | 41 -- spec/rust/src/formats/valid_fail_min_int.rs | 41 -- .../src/formats/valid_fail_range_bytes.rs | 41 -- .../src/formats/valid_fail_range_float.rs | 41 -- spec/rust/src/formats/valid_fail_range_int.rs | 41 -- spec/rust/src/formats/valid_fail_range_str.rs | 41 -- spec/rust/src/formats/valid_long.rs | 61 -- spec/rust/src/formats/valid_not_parsed_if.rs | 49 -- spec/rust/src/formats/valid_optional_id.rs | 46 -- spec/rust/src/formats/valid_short.rs | 61 -- spec/rust/src/formats/valid_switch.rs | 67 --- spec/rust/src/formats/yaml_ints.rs | 91 --- spec/rust/src/formats/zlib_surrounded.rs | 83 --- spec/rust/src/formats/zlib_with_header_78.rs | 43 -- spec/rust/src/lib.rs | 1 + spec/rust/src/test_bcd_user_type_be.rs | 20 - spec/rust/src/test_bcd_user_type_le.rs | 20 - spec/rust/src/test_bits_byte_aligned.rs | 23 - spec/rust/src/test_bits_enum.rs | 17 - spec/rust/src/test_bits_seq_endian_combo.rs | 22 - spec/rust/src/test_bits_shift_by_b32_le.rs | 16 - spec/rust/src/test_bits_shift_by_b64_le.rs | 16 - spec/rust/src/test_bits_signed_res_b32_be.rs | 15 - spec/rust/src/test_bits_signed_res_b32_le.rs | 15 - .../rust/src/test_bits_signed_shift_b32_le.rs | 16 - .../rust/src/test_bits_signed_shift_b64_le.rs | 16 - spec/rust/src/test_bits_simple.rs | 28 - spec/rust/src/test_bits_simple_le.rs | 28 - spec/rust/src/test_bits_unaligned_b32_be.rs | 17 - spec/rust/src/test_bits_unaligned_b32_le.rs | 17 - spec/rust/src/test_bits_unaligned_b64_be.rs | 17 - spec/rust/src/test_bits_unaligned_b64_le.rs | 17 - spec/rust/src/test_buffered_struct.rs | 21 - spec/rust/src/test_bytes_pad_term.rs | 18 - spec/rust/src/test_cast_nested.rs | 18 - spec/rust/src/test_cast_to_imported.rs | 16 - spec/rust/src/test_cast_to_top.rs | 17 - spec/rust/src/test_combine_bool.rs | 16 - spec/rust/src/test_combine_bytes.rs | 24 - spec/rust/src/test_combine_enum.rs | 17 - spec/rust/src/test_combine_str.rs | 29 - spec/rust/src/test_debug_switch_user.rs | 16 - spec/rust/src/test_default_big_endian.rs | 15 - spec/rust/src/test_default_bit_endian_mod.rs | 18 - .../src/test_default_endian_expr_inherited.rs | 29 - .../src/test_default_endian_expr_is_be.rs | 32 - .../src/test_default_endian_expr_is_le.rs | 26 - spec/rust/src/test_default_endian_mod.rs | 17 - spec/rust/src/test_docstrings.rs | 14 - spec/rust/src/test_docstrings_docref.rs | 14 - spec/rust/src/test_docstrings_docref_multi.rs | 14 - spec/rust/src/test_enum_0.rs | 16 - spec/rust/src/test_enum_1.rs | 16 - spec/rust/src/test_enum_deep.rs | 16 - spec/rust/src/test_enum_deep_literals.rs | 16 - spec/rust/src/test_enum_fancy.rs | 16 - spec/rust/src/test_enum_for_unknown_id.rs | 15 - spec/rust/src/test_enum_if.rs | 21 - spec/rust/src/test_enum_import.rs | 16 - spec/rust/src/test_enum_int_range_s.rs | 17 - spec/rust/src/test_enum_int_range_u.rs | 16 - spec/rust/src/test_enum_invalid.rs | 16 - spec/rust/src/test_enum_long_range_s.rs | 21 - spec/rust/src/test_enum_long_range_u.rs | 18 - spec/rust/src/test_enum_negative.rs | 16 - spec/rust/src/test_enum_of_value_inst.rs | 18 - spec/rust/src/test_enum_to_i.rs | 21 - .../rust/src/test_enum_to_i_class_border_1.rs | 17 - spec/rust/src/test_expr_0.rs | 16 - spec/rust/src/test_expr_1.rs | 18 - spec/rust/src/test_expr_2.rs | 31 - spec/rust/src/test_expr_3.rs | 26 - spec/rust/src/test_expr_array.rs | 29 - spec/rust/src/test_expr_bits.rs | 24 - spec/rust/src/test_expr_bytes_cmp.rs | 24 - spec/rust/src/test_expr_bytes_non_literal.rs | 17 - spec/rust/src/test_expr_bytes_ops.rs | 30 - spec/rust/src/test_expr_calc_array_ops.rs | 32 - spec/rust/src/test_expr_enum.rs | 17 - spec/rust/src/test_expr_if_int_ops.rs | 16 - spec/rust/src/test_expr_int_div.rs | 20 - spec/rust/src/test_expr_io_eof.rs | 18 - spec/rust/src/test_expr_io_pos.rs | 20 - spec/rust/src/test_expr_mod.rs | 20 - spec/rust/src/test_expr_ops_parens.rs | 23 - spec/rust/src/test_expr_sizeof_type_0.rs | 14 - spec/rust/src/test_expr_sizeof_type_1.rs | 15 - spec/rust/src/test_expr_sizeof_value_0.rs | 18 - spec/rust/src/test_expr_sizeof_value_sized.rs | 18 - spec/rust/src/test_expr_str_encodings.rs | 21 - spec/rust/src/test_expr_str_ops.rs | 31 - spec/rust/src/test_fixed_contents.rs | 14 - spec/rust/src/test_fixed_struct.rs | 34 -- spec/rust/src/test_float_to_i.rs | 22 - spec/rust/src/test_floating_points.rs | 22 - spec/rust/src/test_hello_world.rs | 15 - spec/rust/src/test_if_instances.rs | 15 - spec/rust/src/test_if_struct.rs | 21 - spec/rust/src/test_if_values.rs | 20 - spec/rust/src/test_imports0.rs | 17 - spec/rust/src/test_imports_abs_abs.rs | 15 - spec/rust/src/test_imports_abs_rel.rs | 15 - spec/rust/src/test_imports_circular_a.rs | 19 - spec/rust/src/test_imports_rel_1.rs | 17 - .../rust/src/test_integers_double_overflow.rs | 22 - spec/rust/src/test_integers_min_max.rs | 42 -- spec/rust/src/test_io_local_var.rs | 15 - spec/rust/src/test_meta_tags.rs | 13 - spec/rust/src/test_meta_xref.rs | 13 - spec/rust/src/test_nav_parent_switch_cast.rs | 17 - spec/rust/src/test_nested_type_param.rs | 16 - .../test_opaque_external_type_02_parent.rs | 15 - spec/rust/src/test_optional_id.rs | 15 - .../rust/src/test_params_call_extra_parens.rs | 15 - spec/rust/src/test_params_pass_array_int.rs | 21 - spec/rust/src/test_params_pass_array_str.rs | 21 - .../rust/src/test_params_pass_array_struct.rs | 17 - .../src/test_params_pass_array_usertype.rs | 19 - spec/rust/src/test_params_pass_bool.rs | 28 - spec/rust/src/test_params_pass_struct.rs | 18 - spec/rust/src/test_process_custom_no_args.rs | 15 - spec/rust/src/test_process_repeat_bytes.rs | 16 - spec/rust/src/test_process_repeat_usertype.rs | 18 - spec/rust/src/test_repeat_eos_bit.rs | 14 - .../src/test_repeat_until_calc_array_type.rs | 21 - spec/rust/src/test_str_encodings_utf16.rs | 20 - spec/rust/src/test_str_eos.rs | 15 - spec/rust/src/test_switch_else_only.rs | 17 - .../src/test_switch_manual_enum_invalid.rs | 19 - .../test_switch_manual_enum_invalid_else.rs | 19 - spec/rust/src/test_switch_manual_int_size.rs | 24 - .../src/test_switch_manual_int_size_eos.rs | 24 - spec/rust/src/test_switch_multi_bool_ops.rs | 23 - spec/rust/src/test_switch_repeat_expr.rs | 17 - .../src/test_switch_repeat_expr_invalid.rs | 17 - spec/rust/src/test_term_u1_val.rs | 16 - spec/rust/src/test_type_ternary_2nd_falsy.rs | 27 - spec/rust/src/test_valid_eq_str_encodings.rs | 14 - spec/rust/src/test_valid_long.rs | 14 - spec/rust/src/test_valid_not_parsed_if.rs | 14 - spec/rust/src/test_valid_short.rs | 14 - spec/rust/src/test_valid_switch.rs | 14 - spec/rust/src/test_yaml_ints.rs | 18 - spec/rust/src/test_zlib_surrounded.rs | 15 - spec/rust/tests/manual_read_bytes.rs | 24 + spec/rust/tests/manual_str_literals.rs | 35 ++ spec/rust/tests/manual_str_repeat.rs | 23 + spec/rust/tests/manual_switch_cast.rs | 50 ++ spec/rust/tests/manual_switch_cast_parent.rs | 50 ++ spec/rust/tests/manual_test_parent.rs | 24 + spec/rust/tests/test_bcd_user_type_be.rs | 19 - spec/rust/tests/test_bcd_user_type_le.rs | 19 - spec/rust/tests/test_bits_byte_aligned.rs | 22 - spec/rust/tests/test_bits_simple.rs | 27 - spec/rust/tests/test_buffered_struct.rs | 20 - spec/rust/tests/test_bytes_pad_term.rs | 17 - spec/rust/tests/test_cast_nested.rs | 17 - spec/rust/tests/test_cast_to_imported.rs | 15 - spec/rust/tests/test_cast_to_top.rs | 16 - spec/rust/tests/test_default_big_endian.rs | 14 - .../test_default_endian_expr_inherited.rs | 28 - .../tests/test_default_endian_expr_is_be.rs | 31 - .../tests/test_default_endian_expr_is_le.rs | 25 - spec/rust/tests/test_default_endian_mod.rs | 16 - spec/rust/tests/test_docstrings.rs | 13 - spec/rust/tests/test_docstrings_docref.rs | 13 - spec/rust/tests/test_expr_0.rs | 24 +- spec/rust/tests/test_expr_1.rs | 33 +- spec/rust/tests/test_expr_2.rs | 30 - spec/rust/tests/test_expr_3.rs | 25 - spec/rust/tests/test_expr_array.rs | 28 - spec/rust/tests/test_expr_bytes_cmp.rs | 23 - spec/rust/tests/test_expr_io_pos.rs | 19 - spec/rust/tests/test_expr_mod.rs | 19 - spec/rust/tests/test_fixed_contents.rs | 20 +- spec/rust/tests/test_fixed_struct.rs | 33 -- spec/rust/tests/test_float_to_i.rs | 21 - spec/rust/tests/test_hello_world.rs | 14 - spec/rust/tests/test_if_struct.rs | 20 - spec/rust/tests/test_if_values.rs | 19 - spec/rust/tests/test_index_sizes.rs | 20 - spec/rust/tests/test_index_to_param_eos.rs | 20 - spec/rust/tests/test_index_to_param_expr.rs | 20 - spec/rust/tests/test_index_to_param_until.rs | 20 - spec/rust/tests/test_instance_io_user.rs | 17 - spec/rust/tests/test_instance_std.rs | 14 - spec/rust/tests/test_instance_std_array.rs | 20 - spec/rust/tests/test_instance_user_array.rs | 23 - spec/rust/tests/test_js_signed_right_shift.rs | 15 - spec/rust/tests/test_meta_xref.rs | 13 - spec/rust/tests/test_multiple_use.rs | 15 - spec/rust/tests/test_nav_parent.rs | 18 - spec/rust/tests/test_nav_parent2.rs | 23 - spec/rust/tests/test_nav_parent3.rs | 23 - spec/rust/tests/test_nav_parent_false.rs | 18 - spec/rust/tests/test_nav_parent_false2.rs | 14 - spec/rust/tests/test_nav_parent_override.rs | 16 - spec/rust/tests/test_nav_parent_switch.rs | 16 - .../tests/test_nav_parent_vs_value_inst.rs | 14 - spec/rust/tests/test_nav_root.rs | 18 - spec/rust/tests/test_nested_same_name.rs | 15 - spec/rust/tests/test_nested_same_name2.rs | 18 - spec/rust/tests/test_nested_types.rs | 16 - spec/rust/tests/test_nested_types2.rs | 20 - spec/rust/tests/test_nested_types3.rs | 18 - spec/rust/tests/test_non_standard.rs | 14 - spec/rust/tests/test_params_call_short.rs | 16 - spec/rust/tests/test_params_pass_usertype.rs | 15 - spec/rust/tests/test_position_abs.rs | 15 - spec/rust/tests/test_position_in_seq.rs | 14 - spec/rust/tests/test_position_to_end.rs | 15 - spec/rust/tests/test_process_coerce_bytes.rs | 35 +- spec/rust/tests/test_process_coerce_switch.rs | 16 - .../tests/test_process_coerce_usertype1.rs | 17 - .../tests/test_process_coerce_usertype2.rs | 17 - spec/rust/tests/test_process_custom.rs | 16 - spec/rust/tests/test_process_rotate.rs | 26 +- spec/rust/tests/test_process_to_user.rs | 22 +- spec/rust/tests/test_process_xor4_const.rs | 24 +- spec/rust/tests/test_process_xor4_value.rs | 24 +- spec/rust/tests/test_process_xor_const.rs | 24 +- spec/rust/tests/test_process_xor_value.rs | 24 +- spec/rust/tests/test_repeat_eos_struct.rs | 18 - spec/rust/tests/test_repeat_eos_u4.rs | 14 - spec/rust/tests/test_repeat_n_struct.rs | 18 - spec/rust/tests/test_repeat_n_strz.rs | 15 - spec/rust/tests/test_repeat_n_strz_double.rs | 16 - spec/rust/tests/test_repeat_until_complex.rs | 28 - spec/rust/tests/test_repeat_until_s4.rs | 15 - spec/rust/tests/test_repeat_until_sized.rs | 20 - spec/rust/tests/test_str_encodings.rs | 28 +- spec/rust/tests/test_str_encodings_default.rs | 28 +- spec/rust/tests/test_str_encodings_utf16.rs | 25 + spec/rust/tests/test_str_eos.rs | 22 +- spec/rust/tests/test_str_literals2.rs | 35 +- spec/rust/tests/test_str_pad_term.rs | 28 +- spec/rust/tests/test_str_pad_term_empty.rs | 26 +- spec/rust/tests/test_switch_bytearray.rs | 58 +- spec/rust/tests/test_switch_else_only.rs | 25 + spec/rust/tests/test_switch_integers.rs | 38 +- spec/rust/tests/test_switch_integers2.rs | 30 +- spec/rust/tests/test_switch_manual_int.rs | 56 +- .../rust/tests/test_switch_manual_int_else.rs | 58 +- .../rust/tests/test_switch_manual_int_size.rs | 52 ++ .../tests/test_switch_manual_int_size_else.rs | 63 +- .../tests/test_switch_manual_int_size_eos.rs | 52 ++ spec/rust/tests/test_switch_manual_str.rs | 58 +- .../rust/tests/test_switch_manual_str_else.rs | 58 +- spec/rust/tests/test_term_bytes.rs | 26 +- spec/rust/tests/test_term_strz.rs | 26 +- spec/rust/tests/test_term_u1_val.rs | 21 + spec/rust/tests/test_ts_packet_header.rs | 26 + spec/rust/tests/test_type_int_unary_op.rs | 28 +- spec/rust/tests/test_type_ternary.rs | 22 +- spec/rust/tests/test_user_type.rs | 15 - spec/rust/tests/test_valid_fail_inst.rs | 20 + .../rust/tests/test_valid_fail_range_bytes.rs | 20 + spec/rust/tests/test_zlib_with_header_78.rs | 14 - 468 files changed, 1093 insertions(+), 26377 deletions(-) delete mode 100644 spec/rust/Cargo.lock delete mode 100644 spec/rust/src/formats/bcd_user_type_be.rs delete mode 100644 spec/rust/src/formats/bcd_user_type_le.rs delete mode 100644 spec/rust/src/formats/bits_byte_aligned.rs delete mode 100644 spec/rust/src/formats/bits_enum.rs delete mode 100644 spec/rust/src/formats/bits_seq_endian_combo.rs delete mode 100644 spec/rust/src/formats/bits_shift_by_b32_le.rs delete mode 100644 spec/rust/src/formats/bits_shift_by_b64_le.rs delete mode 100644 spec/rust/src/formats/bits_signed_res_b32_be.rs delete mode 100644 spec/rust/src/formats/bits_signed_res_b32_le.rs delete mode 100644 spec/rust/src/formats/bits_signed_shift_b32_le.rs delete mode 100644 spec/rust/src/formats/bits_signed_shift_b64_le.rs delete mode 100644 spec/rust/src/formats/bits_simple.rs delete mode 100644 spec/rust/src/formats/bits_simple_le.rs delete mode 100644 spec/rust/src/formats/bits_unaligned_b32_be.rs delete mode 100644 spec/rust/src/formats/bits_unaligned_b32_le.rs delete mode 100644 spec/rust/src/formats/bits_unaligned_b64_be.rs delete mode 100644 spec/rust/src/formats/bits_unaligned_b64_le.rs delete mode 100644 spec/rust/src/formats/buffered_struct.rs delete mode 100644 spec/rust/src/formats/bytes_pad_term.rs delete mode 100644 spec/rust/src/formats/cast_nested.rs delete mode 100644 spec/rust/src/formats/cast_to_imported.rs delete mode 100644 spec/rust/src/formats/cast_to_top.rs delete mode 100644 spec/rust/src/formats/combine_bool.rs delete mode 100644 spec/rust/src/formats/combine_bytes.rs delete mode 100644 spec/rust/src/formats/combine_enum.rs delete mode 100644 spec/rust/src/formats/combine_str.rs delete mode 100644 spec/rust/src/formats/debug_0.rs delete mode 100644 spec/rust/src/formats/default_big_endian.rs delete mode 100644 spec/rust/src/formats/default_bit_endian_mod.rs delete mode 100644 spec/rust/src/formats/default_endian_expr_exception.rs delete mode 100644 spec/rust/src/formats/default_endian_expr_inherited.rs delete mode 100644 spec/rust/src/formats/default_endian_expr_is_be.rs delete mode 100644 spec/rust/src/formats/default_endian_expr_is_le.rs delete mode 100644 spec/rust/src/formats/default_endian_mod.rs delete mode 100644 spec/rust/src/formats/docstrings.rs delete mode 100644 spec/rust/src/formats/docstrings_docref.rs delete mode 100644 spec/rust/src/formats/docstrings_docref_multi.rs delete mode 100644 spec/rust/src/formats/enum_0.rs delete mode 100644 spec/rust/src/formats/enum_1.rs delete mode 100644 spec/rust/src/formats/enum_deep.rs delete mode 100644 spec/rust/src/formats/enum_deep_literals.rs delete mode 100644 spec/rust/src/formats/enum_fancy.rs delete mode 100644 spec/rust/src/formats/enum_for_unknown_id.rs delete mode 100644 spec/rust/src/formats/enum_if.rs delete mode 100644 spec/rust/src/formats/enum_import.rs delete mode 100644 spec/rust/src/formats/enum_int_range_s.rs delete mode 100644 spec/rust/src/formats/enum_int_range_u.rs delete mode 100644 spec/rust/src/formats/enum_invalid.rs delete mode 100644 spec/rust/src/formats/enum_long_range_s.rs delete mode 100644 spec/rust/src/formats/enum_long_range_u.rs delete mode 100644 spec/rust/src/formats/enum_negative.rs delete mode 100644 spec/rust/src/formats/enum_of_value_inst.rs delete mode 100644 spec/rust/src/formats/enum_to_i.rs delete mode 100644 spec/rust/src/formats/enum_to_i_class_border_1.rs delete mode 100644 spec/rust/src/formats/enum_to_i_class_border_2.rs delete mode 100644 spec/rust/src/formats/eof_exception_bytes.rs delete mode 100644 spec/rust/src/formats/eof_exception_u4.rs delete mode 100644 spec/rust/src/formats/eos_exception_bytes.rs delete mode 100644 spec/rust/src/formats/eos_exception_u4.rs delete mode 100644 spec/rust/src/formats/expr_0.rs delete mode 100644 spec/rust/src/formats/expr_1.rs delete mode 100644 spec/rust/src/formats/expr_2.rs delete mode 100644 spec/rust/src/formats/expr_3.rs delete mode 100644 spec/rust/src/formats/expr_array.rs delete mode 100644 spec/rust/src/formats/expr_bits.rs delete mode 100644 spec/rust/src/formats/expr_bytes_cmp.rs delete mode 100644 spec/rust/src/formats/expr_bytes_non_literal.rs delete mode 100644 spec/rust/src/formats/expr_bytes_ops.rs delete mode 100644 spec/rust/src/formats/expr_enum.rs delete mode 100644 spec/rust/src/formats/expr_if_int_ops.rs delete mode 100644 spec/rust/src/formats/expr_int_div.rs delete mode 100644 spec/rust/src/formats/expr_io_eof.rs delete mode 100644 spec/rust/src/formats/expr_io_pos.rs delete mode 100644 spec/rust/src/formats/expr_mod.rs delete mode 100644 spec/rust/src/formats/expr_ops_parens.rs delete mode 100644 spec/rust/src/formats/expr_sizeof_type_0.rs delete mode 100644 spec/rust/src/formats/expr_sizeof_type_1.rs delete mode 100644 spec/rust/src/formats/expr_sizeof_value_0.rs delete mode 100644 spec/rust/src/formats/expr_sizeof_value_sized.rs delete mode 100644 spec/rust/src/formats/expr_str_encodings.rs delete mode 100644 spec/rust/src/formats/expr_str_ops.rs delete mode 100644 spec/rust/src/formats/fixed_contents.rs delete mode 100644 spec/rust/src/formats/fixed_struct.rs delete mode 100644 spec/rust/src/formats/float_to_i.rs delete mode 100644 spec/rust/src/formats/floating_points.rs delete mode 100644 spec/rust/src/formats/hello_world.rs delete mode 100644 spec/rust/src/formats/if_instances.rs delete mode 100644 spec/rust/src/formats/if_struct.rs delete mode 100644 spec/rust/src/formats/if_values.rs delete mode 100644 spec/rust/src/formats/imported_1.rs delete mode 100644 spec/rust/src/formats/imported_2.rs delete mode 100644 spec/rust/src/formats/imports0.rs delete mode 100644 spec/rust/src/formats/imports_circular_a.rs delete mode 100644 spec/rust/src/formats/imports_circular_b.rs delete mode 100644 spec/rust/src/formats/imports_rel_1.rs delete mode 100644 spec/rust/src/formats/index_sizes.rs delete mode 100644 spec/rust/src/formats/index_to_param_eos.rs delete mode 100644 spec/rust/src/formats/index_to_param_expr.rs delete mode 100644 spec/rust/src/formats/index_to_param_until.rs delete mode 100644 spec/rust/src/formats/instance_std.rs delete mode 100644 spec/rust/src/formats/instance_std_array.rs delete mode 100644 spec/rust/src/formats/instance_user_array.rs delete mode 100644 spec/rust/src/formats/integers.rs delete mode 100644 spec/rust/src/formats/integers_double_overflow.rs delete mode 100644 spec/rust/src/formats/integers_min_max.rs delete mode 100644 spec/rust/src/formats/io_local_var.rs delete mode 100644 spec/rust/src/formats/js_signed_right_shift.rs delete mode 100644 spec/rust/src/formats/meta_tags.rs delete mode 100644 spec/rust/src/formats/meta_xref.rs delete mode 100644 spec/rust/src/formats/multiple_use.rs delete mode 100644 spec/rust/src/formats/nav_parent.rs delete mode 100644 spec/rust/src/formats/nav_parent2.rs delete mode 100644 spec/rust/src/formats/nav_parent3.rs delete mode 100644 spec/rust/src/formats/nav_parent_false.rs delete mode 100644 spec/rust/src/formats/nav_parent_false2.rs delete mode 100644 spec/rust/src/formats/nav_parent_override.rs delete mode 100644 spec/rust/src/formats/nav_parent_switch.rs delete mode 100644 spec/rust/src/formats/nav_parent_switch_cast.rs delete mode 100644 spec/rust/src/formats/nav_parent_vs_value_inst.rs delete mode 100644 spec/rust/src/formats/nav_root.rs delete mode 100644 spec/rust/src/formats/nested_same_name.rs delete mode 100644 spec/rust/src/formats/nested_same_name2.rs delete mode 100644 spec/rust/src/formats/nested_type_param.rs delete mode 100644 spec/rust/src/formats/nested_types.rs delete mode 100644 spec/rust/src/formats/nested_types2.rs delete mode 100644 spec/rust/src/formats/nested_types3.rs delete mode 100644 spec/rust/src/formats/non_standard.rs delete mode 100644 spec/rust/src/formats/opaque_external_type.rs delete mode 100644 spec/rust/src/formats/opaque_external_type_02_child.rs delete mode 100644 spec/rust/src/formats/opaque_external_type_02_parent.rs delete mode 100644 spec/rust/src/formats/opaque_with_param.rs delete mode 100644 spec/rust/src/formats/optional_id.rs delete mode 100644 spec/rust/src/formats/params_call_extra_parens.rs delete mode 100644 spec/rust/src/formats/params_call_short.rs delete mode 100644 spec/rust/src/formats/params_def.rs delete mode 100644 spec/rust/src/formats/params_enum.rs delete mode 100644 spec/rust/src/formats/params_pass_array_usertype.rs delete mode 100644 spec/rust/src/formats/params_pass_bool.rs delete mode 100644 spec/rust/src/formats/params_pass_usertype.rs delete mode 100644 spec/rust/src/formats/position_abs.rs delete mode 100644 spec/rust/src/formats/position_in_seq.rs delete mode 100644 spec/rust/src/formats/position_to_end.rs delete mode 100644 spec/rust/src/formats/process_coerce_bytes.rs delete mode 100644 spec/rust/src/formats/process_coerce_usertype1.rs delete mode 100644 spec/rust/src/formats/process_coerce_usertype2.rs delete mode 100644 spec/rust/src/formats/process_custom.rs delete mode 100644 spec/rust/src/formats/process_custom_no_args.rs delete mode 100644 spec/rust/src/formats/process_repeat_bytes.rs delete mode 100644 spec/rust/src/formats/process_repeat_usertype.rs delete mode 100644 spec/rust/src/formats/process_rotate.rs delete mode 100644 spec/rust/src/formats/process_to_user.rs delete mode 100644 spec/rust/src/formats/process_xor4_const.rs delete mode 100644 spec/rust/src/formats/process_xor4_value.rs delete mode 100644 spec/rust/src/formats/process_xor_const.rs delete mode 100644 spec/rust/src/formats/process_xor_value.rs delete mode 100644 spec/rust/src/formats/recursive_one.rs delete mode 100644 spec/rust/src/formats/repeat_eos_bit.rs delete mode 100644 spec/rust/src/formats/repeat_eos_struct.rs delete mode 100644 spec/rust/src/formats/repeat_eos_u4.rs delete mode 100644 spec/rust/src/formats/repeat_n_struct.rs delete mode 100644 spec/rust/src/formats/repeat_n_strz.rs delete mode 100644 spec/rust/src/formats/repeat_n_strz_double.rs delete mode 100644 spec/rust/src/formats/repeat_until_complex.rs delete mode 100644 spec/rust/src/formats/repeat_until_s4.rs delete mode 100644 spec/rust/src/formats/repeat_until_sized.rs delete mode 100644 spec/rust/src/formats/str_encodings.rs delete mode 100644 spec/rust/src/formats/str_encodings_default.rs delete mode 100644 spec/rust/src/formats/str_encodings_utf16.rs delete mode 100644 spec/rust/src/formats/str_eos.rs delete mode 100644 spec/rust/src/formats/str_literals.rs delete mode 100644 spec/rust/src/formats/str_literals2.rs delete mode 100644 spec/rust/src/formats/str_pad_term.rs delete mode 100644 spec/rust/src/formats/str_pad_term_empty.rs delete mode 100644 spec/rust/src/formats/switch_bytearray.rs delete mode 100644 spec/rust/src/formats/switch_cast.rs delete mode 100644 spec/rust/src/formats/switch_else_only.rs delete mode 100644 spec/rust/src/formats/switch_integers.rs delete mode 100644 spec/rust/src/formats/switch_integers2.rs delete mode 100644 spec/rust/src/formats/switch_manual_enum.rs delete mode 100644 spec/rust/src/formats/switch_manual_enum_invalid.rs delete mode 100644 spec/rust/src/formats/switch_manual_enum_invalid_else.rs delete mode 100644 spec/rust/src/formats/switch_manual_int.rs delete mode 100644 spec/rust/src/formats/switch_manual_int_else.rs delete mode 100644 spec/rust/src/formats/switch_manual_int_size.rs delete mode 100644 spec/rust/src/formats/switch_manual_int_size_else.rs delete mode 100644 spec/rust/src/formats/switch_manual_str.rs delete mode 100644 spec/rust/src/formats/switch_manual_str_else.rs delete mode 100644 spec/rust/src/formats/switch_multi_bool_ops.rs delete mode 100644 spec/rust/src/formats/switch_repeat_expr.rs delete mode 100644 spec/rust/src/formats/switch_repeat_expr_invalid.rs delete mode 100644 spec/rust/src/formats/term_bytes.rs delete mode 100644 spec/rust/src/formats/term_strz.rs delete mode 100644 spec/rust/src/formats/term_u1_val.rs delete mode 100644 spec/rust/src/formats/to_string_custom.rs delete mode 100644 spec/rust/src/formats/ts_packet_header.rs delete mode 100644 spec/rust/src/formats/type_int_unary_op.rs delete mode 100644 spec/rust/src/formats/type_ternary.rs delete mode 100644 spec/rust/src/formats/type_ternary_opaque.rs delete mode 100644 spec/rust/src/formats/user_type.rs delete mode 100644 spec/rust/src/formats/valid_eq_str_encodings.rs delete mode 100644 spec/rust/src/formats/valid_fail_anyof_int.rs delete mode 100644 spec/rust/src/formats/valid_fail_contents.rs delete mode 100644 spec/rust/src/formats/valid_fail_eq_bytes.rs delete mode 100644 spec/rust/src/formats/valid_fail_eq_int.rs delete mode 100644 spec/rust/src/formats/valid_fail_eq_str.rs delete mode 100644 spec/rust/src/formats/valid_fail_expr.rs delete mode 100644 spec/rust/src/formats/valid_fail_inst.rs delete mode 100644 spec/rust/src/formats/valid_fail_max_int.rs delete mode 100644 spec/rust/src/formats/valid_fail_min_int.rs delete mode 100644 spec/rust/src/formats/valid_fail_range_bytes.rs delete mode 100644 spec/rust/src/formats/valid_fail_range_float.rs delete mode 100644 spec/rust/src/formats/valid_fail_range_int.rs delete mode 100644 spec/rust/src/formats/valid_fail_range_str.rs delete mode 100644 spec/rust/src/formats/valid_long.rs delete mode 100644 spec/rust/src/formats/valid_not_parsed_if.rs delete mode 100644 spec/rust/src/formats/valid_optional_id.rs delete mode 100644 spec/rust/src/formats/valid_short.rs delete mode 100644 spec/rust/src/formats/valid_switch.rs delete mode 100644 spec/rust/src/formats/yaml_ints.rs delete mode 100644 spec/rust/src/formats/zlib_surrounded.rs delete mode 100644 spec/rust/src/formats/zlib_with_header_78.rs create mode 100644 spec/rust/src/lib.rs delete mode 100644 spec/rust/src/test_bcd_user_type_be.rs delete mode 100644 spec/rust/src/test_bcd_user_type_le.rs delete mode 100644 spec/rust/src/test_bits_byte_aligned.rs delete mode 100644 spec/rust/src/test_bits_enum.rs delete mode 100644 spec/rust/src/test_bits_seq_endian_combo.rs delete mode 100644 spec/rust/src/test_bits_shift_by_b32_le.rs delete mode 100644 spec/rust/src/test_bits_shift_by_b64_le.rs delete mode 100644 spec/rust/src/test_bits_signed_res_b32_be.rs delete mode 100644 spec/rust/src/test_bits_signed_res_b32_le.rs delete mode 100644 spec/rust/src/test_bits_signed_shift_b32_le.rs delete mode 100644 spec/rust/src/test_bits_signed_shift_b64_le.rs delete mode 100644 spec/rust/src/test_bits_simple.rs delete mode 100644 spec/rust/src/test_bits_simple_le.rs delete mode 100644 spec/rust/src/test_bits_unaligned_b32_be.rs delete mode 100644 spec/rust/src/test_bits_unaligned_b32_le.rs delete mode 100644 spec/rust/src/test_bits_unaligned_b64_be.rs delete mode 100644 spec/rust/src/test_bits_unaligned_b64_le.rs delete mode 100644 spec/rust/src/test_buffered_struct.rs delete mode 100644 spec/rust/src/test_bytes_pad_term.rs delete mode 100644 spec/rust/src/test_cast_nested.rs delete mode 100644 spec/rust/src/test_cast_to_imported.rs delete mode 100644 spec/rust/src/test_cast_to_top.rs delete mode 100644 spec/rust/src/test_combine_bool.rs delete mode 100644 spec/rust/src/test_combine_bytes.rs delete mode 100644 spec/rust/src/test_combine_enum.rs delete mode 100644 spec/rust/src/test_combine_str.rs delete mode 100644 spec/rust/src/test_debug_switch_user.rs delete mode 100644 spec/rust/src/test_default_big_endian.rs delete mode 100644 spec/rust/src/test_default_bit_endian_mod.rs delete mode 100644 spec/rust/src/test_default_endian_expr_inherited.rs delete mode 100644 spec/rust/src/test_default_endian_expr_is_be.rs delete mode 100644 spec/rust/src/test_default_endian_expr_is_le.rs delete mode 100644 spec/rust/src/test_default_endian_mod.rs delete mode 100644 spec/rust/src/test_docstrings.rs delete mode 100644 spec/rust/src/test_docstrings_docref.rs delete mode 100644 spec/rust/src/test_docstrings_docref_multi.rs delete mode 100644 spec/rust/src/test_enum_0.rs delete mode 100644 spec/rust/src/test_enum_1.rs delete mode 100644 spec/rust/src/test_enum_deep.rs delete mode 100644 spec/rust/src/test_enum_deep_literals.rs delete mode 100644 spec/rust/src/test_enum_fancy.rs delete mode 100644 spec/rust/src/test_enum_for_unknown_id.rs delete mode 100644 spec/rust/src/test_enum_if.rs delete mode 100644 spec/rust/src/test_enum_import.rs delete mode 100644 spec/rust/src/test_enum_int_range_s.rs delete mode 100644 spec/rust/src/test_enum_int_range_u.rs delete mode 100644 spec/rust/src/test_enum_invalid.rs delete mode 100644 spec/rust/src/test_enum_long_range_s.rs delete mode 100644 spec/rust/src/test_enum_long_range_u.rs delete mode 100644 spec/rust/src/test_enum_negative.rs delete mode 100644 spec/rust/src/test_enum_of_value_inst.rs delete mode 100644 spec/rust/src/test_enum_to_i.rs delete mode 100644 spec/rust/src/test_enum_to_i_class_border_1.rs delete mode 100644 spec/rust/src/test_expr_0.rs delete mode 100644 spec/rust/src/test_expr_1.rs delete mode 100644 spec/rust/src/test_expr_2.rs delete mode 100644 spec/rust/src/test_expr_3.rs delete mode 100644 spec/rust/src/test_expr_array.rs delete mode 100644 spec/rust/src/test_expr_bits.rs delete mode 100644 spec/rust/src/test_expr_bytes_cmp.rs delete mode 100644 spec/rust/src/test_expr_bytes_non_literal.rs delete mode 100644 spec/rust/src/test_expr_bytes_ops.rs delete mode 100644 spec/rust/src/test_expr_calc_array_ops.rs delete mode 100644 spec/rust/src/test_expr_enum.rs delete mode 100644 spec/rust/src/test_expr_if_int_ops.rs delete mode 100644 spec/rust/src/test_expr_int_div.rs delete mode 100644 spec/rust/src/test_expr_io_eof.rs delete mode 100644 spec/rust/src/test_expr_io_pos.rs delete mode 100644 spec/rust/src/test_expr_mod.rs delete mode 100644 spec/rust/src/test_expr_ops_parens.rs delete mode 100644 spec/rust/src/test_expr_sizeof_type_0.rs delete mode 100644 spec/rust/src/test_expr_sizeof_type_1.rs delete mode 100644 spec/rust/src/test_expr_sizeof_value_0.rs delete mode 100644 spec/rust/src/test_expr_sizeof_value_sized.rs delete mode 100644 spec/rust/src/test_expr_str_encodings.rs delete mode 100644 spec/rust/src/test_expr_str_ops.rs delete mode 100644 spec/rust/src/test_fixed_contents.rs delete mode 100644 spec/rust/src/test_fixed_struct.rs delete mode 100644 spec/rust/src/test_float_to_i.rs delete mode 100644 spec/rust/src/test_floating_points.rs delete mode 100644 spec/rust/src/test_hello_world.rs delete mode 100644 spec/rust/src/test_if_instances.rs delete mode 100644 spec/rust/src/test_if_struct.rs delete mode 100644 spec/rust/src/test_if_values.rs delete mode 100644 spec/rust/src/test_imports0.rs delete mode 100644 spec/rust/src/test_imports_abs_abs.rs delete mode 100644 spec/rust/src/test_imports_abs_rel.rs delete mode 100644 spec/rust/src/test_imports_circular_a.rs delete mode 100644 spec/rust/src/test_imports_rel_1.rs delete mode 100644 spec/rust/src/test_integers_double_overflow.rs delete mode 100644 spec/rust/src/test_integers_min_max.rs delete mode 100644 spec/rust/src/test_io_local_var.rs delete mode 100644 spec/rust/src/test_meta_tags.rs delete mode 100644 spec/rust/src/test_meta_xref.rs delete mode 100644 spec/rust/src/test_nav_parent_switch_cast.rs delete mode 100644 spec/rust/src/test_nested_type_param.rs delete mode 100644 spec/rust/src/test_opaque_external_type_02_parent.rs delete mode 100644 spec/rust/src/test_optional_id.rs delete mode 100644 spec/rust/src/test_params_call_extra_parens.rs delete mode 100644 spec/rust/src/test_params_pass_array_int.rs delete mode 100644 spec/rust/src/test_params_pass_array_str.rs delete mode 100644 spec/rust/src/test_params_pass_array_struct.rs delete mode 100644 spec/rust/src/test_params_pass_array_usertype.rs delete mode 100644 spec/rust/src/test_params_pass_bool.rs delete mode 100644 spec/rust/src/test_params_pass_struct.rs delete mode 100644 spec/rust/src/test_process_custom_no_args.rs delete mode 100644 spec/rust/src/test_process_repeat_bytes.rs delete mode 100644 spec/rust/src/test_process_repeat_usertype.rs delete mode 100644 spec/rust/src/test_repeat_eos_bit.rs delete mode 100644 spec/rust/src/test_repeat_until_calc_array_type.rs delete mode 100644 spec/rust/src/test_str_encodings_utf16.rs delete mode 100644 spec/rust/src/test_str_eos.rs delete mode 100644 spec/rust/src/test_switch_else_only.rs delete mode 100644 spec/rust/src/test_switch_manual_enum_invalid.rs delete mode 100644 spec/rust/src/test_switch_manual_enum_invalid_else.rs delete mode 100644 spec/rust/src/test_switch_manual_int_size.rs delete mode 100644 spec/rust/src/test_switch_manual_int_size_eos.rs delete mode 100644 spec/rust/src/test_switch_multi_bool_ops.rs delete mode 100644 spec/rust/src/test_switch_repeat_expr.rs delete mode 100644 spec/rust/src/test_switch_repeat_expr_invalid.rs delete mode 100644 spec/rust/src/test_term_u1_val.rs delete mode 100644 spec/rust/src/test_type_ternary_2nd_falsy.rs delete mode 100644 spec/rust/src/test_valid_eq_str_encodings.rs delete mode 100644 spec/rust/src/test_valid_long.rs delete mode 100644 spec/rust/src/test_valid_not_parsed_if.rs delete mode 100644 spec/rust/src/test_valid_short.rs delete mode 100644 spec/rust/src/test_valid_switch.rs delete mode 100644 spec/rust/src/test_yaml_ints.rs delete mode 100644 spec/rust/src/test_zlib_surrounded.rs create mode 100644 spec/rust/tests/manual_read_bytes.rs create mode 100644 spec/rust/tests/manual_str_literals.rs create mode 100644 spec/rust/tests/manual_str_repeat.rs create mode 100644 spec/rust/tests/manual_switch_cast.rs create mode 100644 spec/rust/tests/manual_switch_cast_parent.rs create mode 100644 spec/rust/tests/manual_test_parent.rs delete mode 100644 spec/rust/tests/test_bcd_user_type_be.rs delete mode 100644 spec/rust/tests/test_bcd_user_type_le.rs delete mode 100644 spec/rust/tests/test_bits_byte_aligned.rs delete mode 100644 spec/rust/tests/test_bits_simple.rs delete mode 100644 spec/rust/tests/test_buffered_struct.rs delete mode 100644 spec/rust/tests/test_bytes_pad_term.rs delete mode 100644 spec/rust/tests/test_cast_nested.rs delete mode 100644 spec/rust/tests/test_cast_to_imported.rs delete mode 100644 spec/rust/tests/test_cast_to_top.rs delete mode 100644 spec/rust/tests/test_default_big_endian.rs delete mode 100644 spec/rust/tests/test_default_endian_expr_inherited.rs delete mode 100644 spec/rust/tests/test_default_endian_expr_is_be.rs delete mode 100644 spec/rust/tests/test_default_endian_expr_is_le.rs delete mode 100644 spec/rust/tests/test_default_endian_mod.rs delete mode 100644 spec/rust/tests/test_docstrings.rs delete mode 100644 spec/rust/tests/test_docstrings_docref.rs delete mode 100644 spec/rust/tests/test_expr_2.rs delete mode 100644 spec/rust/tests/test_expr_3.rs delete mode 100644 spec/rust/tests/test_expr_array.rs delete mode 100644 spec/rust/tests/test_expr_bytes_cmp.rs delete mode 100644 spec/rust/tests/test_expr_io_pos.rs delete mode 100644 spec/rust/tests/test_expr_mod.rs delete mode 100644 spec/rust/tests/test_fixed_struct.rs delete mode 100644 spec/rust/tests/test_float_to_i.rs delete mode 100644 spec/rust/tests/test_hello_world.rs delete mode 100644 spec/rust/tests/test_if_struct.rs delete mode 100644 spec/rust/tests/test_if_values.rs delete mode 100644 spec/rust/tests/test_index_sizes.rs delete mode 100644 spec/rust/tests/test_index_to_param_eos.rs delete mode 100644 spec/rust/tests/test_index_to_param_expr.rs delete mode 100644 spec/rust/tests/test_index_to_param_until.rs delete mode 100644 spec/rust/tests/test_instance_io_user.rs delete mode 100644 spec/rust/tests/test_instance_std.rs delete mode 100644 spec/rust/tests/test_instance_std_array.rs delete mode 100644 spec/rust/tests/test_instance_user_array.rs delete mode 100644 spec/rust/tests/test_js_signed_right_shift.rs delete mode 100644 spec/rust/tests/test_meta_xref.rs delete mode 100644 spec/rust/tests/test_multiple_use.rs delete mode 100644 spec/rust/tests/test_nav_parent.rs delete mode 100644 spec/rust/tests/test_nav_parent2.rs delete mode 100644 spec/rust/tests/test_nav_parent3.rs delete mode 100644 spec/rust/tests/test_nav_parent_false.rs delete mode 100644 spec/rust/tests/test_nav_parent_false2.rs delete mode 100644 spec/rust/tests/test_nav_parent_override.rs delete mode 100644 spec/rust/tests/test_nav_parent_switch.rs delete mode 100644 spec/rust/tests/test_nav_parent_vs_value_inst.rs delete mode 100644 spec/rust/tests/test_nav_root.rs delete mode 100644 spec/rust/tests/test_nested_same_name.rs delete mode 100644 spec/rust/tests/test_nested_same_name2.rs delete mode 100644 spec/rust/tests/test_nested_types.rs delete mode 100644 spec/rust/tests/test_nested_types2.rs delete mode 100644 spec/rust/tests/test_nested_types3.rs delete mode 100644 spec/rust/tests/test_non_standard.rs delete mode 100644 spec/rust/tests/test_params_call_short.rs delete mode 100644 spec/rust/tests/test_params_pass_usertype.rs delete mode 100644 spec/rust/tests/test_position_abs.rs delete mode 100644 spec/rust/tests/test_position_in_seq.rs delete mode 100644 spec/rust/tests/test_position_to_end.rs delete mode 100644 spec/rust/tests/test_process_coerce_switch.rs delete mode 100644 spec/rust/tests/test_process_coerce_usertype1.rs delete mode 100644 spec/rust/tests/test_process_coerce_usertype2.rs delete mode 100644 spec/rust/tests/test_process_custom.rs delete mode 100644 spec/rust/tests/test_repeat_eos_struct.rs delete mode 100644 spec/rust/tests/test_repeat_eos_u4.rs delete mode 100644 spec/rust/tests/test_repeat_n_struct.rs delete mode 100644 spec/rust/tests/test_repeat_n_strz.rs delete mode 100644 spec/rust/tests/test_repeat_n_strz_double.rs delete mode 100644 spec/rust/tests/test_repeat_until_complex.rs delete mode 100644 spec/rust/tests/test_repeat_until_s4.rs delete mode 100644 spec/rust/tests/test_repeat_until_sized.rs create mode 100644 spec/rust/tests/test_str_encodings_utf16.rs create mode 100644 spec/rust/tests/test_switch_else_only.rs create mode 100644 spec/rust/tests/test_switch_manual_int_size.rs create mode 100644 spec/rust/tests/test_switch_manual_int_size_eos.rs create mode 100644 spec/rust/tests/test_term_u1_val.rs create mode 100644 spec/rust/tests/test_ts_packet_header.rs delete mode 100644 spec/rust/tests/test_user_type.rs create mode 100644 spec/rust/tests/test_valid_fail_inst.rs create mode 100644 spec/rust/tests/test_valid_fail_range_bytes.rs delete mode 100644 spec/rust/tests/test_zlib_with_header_78.rs diff --git a/spec/rust/Cargo.lock b/spec/rust/Cargo.lock deleted file mode 100644 index 31bdaab29..000000000 --- a/spec/rust/Cargo.lock +++ /dev/null @@ -1,121 +0,0 @@ -[[package]] -name = "byteorder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "cc" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "encoding" -version = "0.2.33" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-japanese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-korean" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-simpchinese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-singlebyte" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding-index-tradchinese" -version = "1.20141219.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "encoding_index_tests" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "flate2" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "kaitai_struct" -version = "0.2.0" -source = "git+https://github.com/CWood1/kaitai_struct_rust_runtime#b5484246b52c57ad7e2cb66af7b37347289c058e" -dependencies = [ - "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.40" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "miniz-sys" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "rust" -version = "0.1.0" -dependencies = [ - "kaitai_struct 0.2.0 (git+https://github.com/CWood1/kaitai_struct_rust_runtime)", -] - -[metadata] -"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc" -"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec" -"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91" -"checksum encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81" -"checksum encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7" -"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a" -"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18" -"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" -"checksum flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "e6234dd4468ae5d1e2dbb06fe2b058696fdc50a339c68a393aefbf00bc81e423" -"checksum kaitai_struct 0.2.0 (git+https://github.com/CWood1/kaitai_struct_rust_runtime)" = "" -"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" -"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index e79b56875..2b3bd7b7c 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -5,4 +5,4 @@ authors = ["Connor Wood "] build = "build.rs" [dependencies] -kaitai_struct = { git = "https://github.com/CWood1/kaitai_struct_rust_runtime" } +kaitai = { path = "../../../runtime/rust" } diff --git a/spec/rust/build.rs b/spec/rust/build.rs index d629f0b37..6c9243076 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -7,10 +7,20 @@ use std::{ path::Path }; +pub fn path_exists(path: &Path) -> bool { + fs::metadata(path).is_ok() +} + fn main() { let source_path = Path::new("../../compiled/rust"); - let destination_path = Path::new("./src"); - + let destination_path = Path::new("./tests/formats"); + + if !path_exists(destination_path) { + fs::create_dir(destination_path).unwrap_or_else(|e| { + println!("Unable to create dir: {}", e.to_string()); + }); + } + remove_existing(destination_path).unwrap_or_else(|e| { println!("Unable to remove existing files under test: {}", e.to_string()); }); @@ -25,6 +35,7 @@ fn remove_existing(destination_path: &Path) -> io::Result<()> { let entry = entry?; let path = entry.path(); + println!("cleaning {}", path.display().to_string()); fs::remove_file(path)?; } @@ -32,19 +43,20 @@ fn remove_existing(destination_path: &Path) -> io::Result<()> { } fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { - let mut librs = fs::File::create(source_path.join("lib.rs"))?; + let mut librs = fs::File::create(destination_path.join("mod.rs"))?; - write!(librs, "extern crate kaitai_struct;")?; - for entry in fs::read_dir(source_path)? { let entry = entry?; let path = entry.path(); if let Some(file_name) = path.file_name() { fs::copy(path.clone(), destination_path.join(file_name))?; + println!("copying {} to {}", path.as_path().display().to_string(), + destination_path.join(file_name).as_path().display().to_string()); write!(librs, "pub mod {};\n", path.file_stem().unwrap().to_str().unwrap())?; + println!("updating lib.rs with {}", path.file_stem().unwrap().to_str().unwrap()); } } diff --git a/spec/rust/src/formats/bcd_user_type_be.rs b/spec/rust/src/formats/bcd_user_type_be.rs deleted file mode 100644 index 76e680b1b..000000000 --- a/spec/rust/src/formats/bcd_user_type_be.rs +++ /dev/null @@ -1,558 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(ltr)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(rtl)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(leading_zero_ltr)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeBe { - pub ltr: Option, - pub rtl: Option, - pub leading_zero_ltr: Option, - pub raw_ltr: Vec, - pub raw_rtl: Vec, - pub raw_leading_zero_ltr: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - self.rtl = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - self.leading_zero_ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeBe { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeBe::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeBe_LtrObj { - pub b1: u8, - pub b2: u8, - pub b3: u8, - pub b4: u8, - pub as_int: Option, - pub digit2: Option, - pub digit4: Option, - pub digit3: Option, - pub digit5: Option, - pub digit8: Option, - pub digit6: Option, - pub as_str: Option, - pub digit1: Option, - pub digit7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe_LtrObj { - type Root = BcdUserTypeBe; - type ParentStack = (&'r BcdUserTypeBe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.b1 = _io.read_u1()?; - self.b2 = _io.read_u1()?; - self.b3 = _io.read_u1()?; - self.b4 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeBe_LtrObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeBe_LtrObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn as_int( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.as_int.is_some() { - return Ok(self.as_int.as_ref().unwrap()); - } - self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); - return Ok(self.as_int.as_ref().unwrap()); - } - fn digit2( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit2.is_some() { - return Ok(self.digit2.as_ref().unwrap()); - } - self.digit2 = Some((self.b1 & 15) as i32); - return Ok(self.digit2.as_ref().unwrap()); - } - fn digit4( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit4.is_some() { - return Ok(self.digit4.as_ref().unwrap()); - } - self.digit4 = Some((self.b2 & 15) as i32); - return Ok(self.digit4.as_ref().unwrap()); - } - fn digit3( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit3.is_some() { - return Ok(self.digit3.as_ref().unwrap()); - } - self.digit3 = Some(((self.b2 & 240) >> 4) as i32); - return Ok(self.digit3.as_ref().unwrap()); - } - fn digit5( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit5.is_some() { - return Ok(self.digit5.as_ref().unwrap()); - } - self.digit5 = Some(((self.b3 & 240) >> 4) as i32); - return Ok(self.digit5.as_ref().unwrap()); - } - fn digit8( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit8.is_some() { - return Ok(self.digit8.as_ref().unwrap()); - } - self.digit8 = Some((self.b4 & 15) as i32); - return Ok(self.digit8.as_ref().unwrap()); - } - fn digit6( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit6.is_some() { - return Ok(self.digit6.as_ref().unwrap()); - } - self.digit6 = Some((self.b3 & 15) as i32); - return Ok(self.digit6.as_ref().unwrap()); - } - fn as_str( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&String> { - if self.as_str.is_some() { - return Ok(self.as_str.as_ref().unwrap()); - } - self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); - return Ok(self.as_str.as_ref().unwrap()); - } - fn digit1( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit1.is_some() { - return Ok(self.digit1.as_ref().unwrap()); - } - self.digit1 = Some(((self.b1 & 240) >> 4) as i32); - return Ok(self.digit1.as_ref().unwrap()); - } - fn digit7( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit7.is_some() { - return Ok(self.digit7.as_ref().unwrap()); - } - self.digit7 = Some(((self.b4 & 240) >> 4) as i32); - return Ok(self.digit7.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeBe_RtlObj { - pub b1: u8, - pub b2: u8, - pub b3: u8, - pub b4: u8, - pub as_int: Option, - pub digit2: Option, - pub digit4: Option, - pub digit3: Option, - pub digit5: Option, - pub digit8: Option, - pub digit6: Option, - pub as_str: Option, - pub digit1: Option, - pub digit7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe_RtlObj { - type Root = BcdUserTypeBe; - type ParentStack = (&'r BcdUserTypeBe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.b1 = _io.read_u1()?; - self.b2 = _io.read_u1()?; - self.b3 = _io.read_u1()?; - self.b4 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeBe_RtlObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeBe_RtlObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn as_int( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.as_int.is_some() { - return Ok(self.as_int.as_ref().unwrap()); - } - self.as_int = Some(((((((((self.digit1(_io, _root, _parent)? * 1) + (self.digit2(_io, _root, _parent)? * 10)) + (self.digit3(_io, _root, _parent)? * 100)) + (self.digit4(_io, _root, _parent)? * 1000)) + (self.digit5(_io, _root, _parent)? * 10000)) + (self.digit6(_io, _root, _parent)? * 100000)) + (self.digit7(_io, _root, _parent)? * 1000000)) + (self.digit8(_io, _root, _parent)? * 10000000)) as i32); - return Ok(self.as_int.as_ref().unwrap()); - } - fn digit2( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit2.is_some() { - return Ok(self.digit2.as_ref().unwrap()); - } - self.digit2 = Some((self.b1 & 15) as i32); - return Ok(self.digit2.as_ref().unwrap()); - } - fn digit4( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit4.is_some() { - return Ok(self.digit4.as_ref().unwrap()); - } - self.digit4 = Some((self.b2 & 15) as i32); - return Ok(self.digit4.as_ref().unwrap()); - } - fn digit3( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit3.is_some() { - return Ok(self.digit3.as_ref().unwrap()); - } - self.digit3 = Some(((self.b2 & 240) >> 4) as i32); - return Ok(self.digit3.as_ref().unwrap()); - } - fn digit5( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit5.is_some() { - return Ok(self.digit5.as_ref().unwrap()); - } - self.digit5 = Some(((self.b3 & 240) >> 4) as i32); - return Ok(self.digit5.as_ref().unwrap()); - } - fn digit8( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit8.is_some() { - return Ok(self.digit8.as_ref().unwrap()); - } - self.digit8 = Some((self.b4 & 15) as i32); - return Ok(self.digit8.as_ref().unwrap()); - } - fn digit6( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit6.is_some() { - return Ok(self.digit6.as_ref().unwrap()); - } - self.digit6 = Some((self.b3 & 15) as i32); - return Ok(self.digit6.as_ref().unwrap()); - } - fn as_str( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&String> { - if self.as_str.is_some() { - return Ok(self.as_str.as_ref().unwrap()); - } - self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit8(_io, _root, _parent)?.to_string(), self.digit7(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit2(_io, _root, _parent)?.to_string()), self.digit1(_io, _root, _parent)?.to_string()).to_string()); - return Ok(self.as_str.as_ref().unwrap()); - } - fn digit1( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit1.is_some() { - return Ok(self.digit1.as_ref().unwrap()); - } - self.digit1 = Some(((self.b1 & 240) >> 4) as i32); - return Ok(self.digit1.as_ref().unwrap()); - } - fn digit7( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit7.is_some() { - return Ok(self.digit7.as_ref().unwrap()); - } - self.digit7 = Some(((self.b4 & 240) >> 4) as i32); - return Ok(self.digit7.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeBe_LeadingZeroLtrObj { - pub b1: u8, - pub b2: u8, - pub b3: u8, - pub b4: u8, - pub as_int: Option, - pub digit2: Option, - pub digit4: Option, - pub digit3: Option, - pub digit5: Option, - pub digit8: Option, - pub digit6: Option, - pub as_str: Option, - pub digit1: Option, - pub digit7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeBe_LeadingZeroLtrObj { - type Root = BcdUserTypeBe; - type ParentStack = (&'r BcdUserTypeBe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.b1 = _io.read_u1()?; - self.b2 = _io.read_u1()?; - self.b3 = _io.read_u1()?; - self.b4 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeBe_LeadingZeroLtrObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeBe_LeadingZeroLtrObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn as_int( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.as_int.is_some() { - return Ok(self.as_int.as_ref().unwrap()); - } - self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); - return Ok(self.as_int.as_ref().unwrap()); - } - fn digit2( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit2.is_some() { - return Ok(self.digit2.as_ref().unwrap()); - } - self.digit2 = Some((self.b1 & 15) as i32); - return Ok(self.digit2.as_ref().unwrap()); - } - fn digit4( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit4.is_some() { - return Ok(self.digit4.as_ref().unwrap()); - } - self.digit4 = Some((self.b2 & 15) as i32); - return Ok(self.digit4.as_ref().unwrap()); - } - fn digit3( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit3.is_some() { - return Ok(self.digit3.as_ref().unwrap()); - } - self.digit3 = Some(((self.b2 & 240) >> 4) as i32); - return Ok(self.digit3.as_ref().unwrap()); - } - fn digit5( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit5.is_some() { - return Ok(self.digit5.as_ref().unwrap()); - } - self.digit5 = Some(((self.b3 & 240) >> 4) as i32); - return Ok(self.digit5.as_ref().unwrap()); - } - fn digit8( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit8.is_some() { - return Ok(self.digit8.as_ref().unwrap()); - } - self.digit8 = Some((self.b4 & 15) as i32); - return Ok(self.digit8.as_ref().unwrap()); - } - fn digit6( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit6.is_some() { - return Ok(self.digit6.as_ref().unwrap()); - } - self.digit6 = Some((self.b3 & 15) as i32); - return Ok(self.digit6.as_ref().unwrap()); - } - fn as_str( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&String> { - if self.as_str.is_some() { - return Ok(self.as_str.as_ref().unwrap()); - } - self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); - return Ok(self.as_str.as_ref().unwrap()); - } - fn digit1( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit1.is_some() { - return Ok(self.digit1.as_ref().unwrap()); - } - self.digit1 = Some(((self.b1 & 240) >> 4) as i32); - return Ok(self.digit1.as_ref().unwrap()); - } - fn digit7( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit7.is_some() { - return Ok(self.digit7.as_ref().unwrap()); - } - self.digit7 = Some(((self.b4 & 240) >> 4) as i32); - return Ok(self.digit7.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/bcd_user_type_le.rs b/spec/rust/src/formats/bcd_user_type_le.rs deleted file mode 100644 index 4d09ade52..000000000 --- a/spec/rust/src/formats/bcd_user_type_le.rs +++ /dev/null @@ -1,558 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(ltr)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(rtl)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(leading_zero_ltr)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeLe { - pub ltr: Option, - pub rtl: Option, - pub leading_zero_ltr: Option, - pub raw_ltr: Vec, - pub raw_rtl: Vec, - pub raw_leading_zero_ltr: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - self.rtl = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - self.leading_zero_ltr = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeLe { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeLe::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeLe_LtrObj { - pub b1: u8, - pub b2: u8, - pub b3: u8, - pub b4: u8, - pub as_int: Option, - pub digit2: Option, - pub digit4: Option, - pub digit3: Option, - pub digit5: Option, - pub digit8: Option, - pub digit6: Option, - pub as_str: Option, - pub digit1: Option, - pub digit7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe_LtrObj { - type Root = BcdUserTypeLe; - type ParentStack = (&'r BcdUserTypeLe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.b1 = _io.read_u1()?; - self.b2 = _io.read_u1()?; - self.b3 = _io.read_u1()?; - self.b4 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeLe_LtrObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeLe_LtrObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn as_int( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.as_int.is_some() { - return Ok(self.as_int.as_ref().unwrap()); - } - self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); - return Ok(self.as_int.as_ref().unwrap()); - } - fn digit2( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit2.is_some() { - return Ok(self.digit2.as_ref().unwrap()); - } - self.digit2 = Some((self.b4 & 15) as i32); - return Ok(self.digit2.as_ref().unwrap()); - } - fn digit4( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit4.is_some() { - return Ok(self.digit4.as_ref().unwrap()); - } - self.digit4 = Some((self.b3 & 15) as i32); - return Ok(self.digit4.as_ref().unwrap()); - } - fn digit3( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit3.is_some() { - return Ok(self.digit3.as_ref().unwrap()); - } - self.digit3 = Some(((self.b3 & 240) >> 4) as i32); - return Ok(self.digit3.as_ref().unwrap()); - } - fn digit5( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit5.is_some() { - return Ok(self.digit5.as_ref().unwrap()); - } - self.digit5 = Some(((self.b2 & 240) >> 4) as i32); - return Ok(self.digit5.as_ref().unwrap()); - } - fn digit8( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit8.is_some() { - return Ok(self.digit8.as_ref().unwrap()); - } - self.digit8 = Some((self.b1 & 15) as i32); - return Ok(self.digit8.as_ref().unwrap()); - } - fn digit6( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit6.is_some() { - return Ok(self.digit6.as_ref().unwrap()); - } - self.digit6 = Some((self.b2 & 15) as i32); - return Ok(self.digit6.as_ref().unwrap()); - } - fn as_str( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&String> { - if self.as_str.is_some() { - return Ok(self.as_str.as_ref().unwrap()); - } - self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); - return Ok(self.as_str.as_ref().unwrap()); - } - fn digit1( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit1.is_some() { - return Ok(self.digit1.as_ref().unwrap()); - } - self.digit1 = Some(((self.b4 & 240) >> 4) as i32); - return Ok(self.digit1.as_ref().unwrap()); - } - fn digit7( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit7.is_some() { - return Ok(self.digit7.as_ref().unwrap()); - } - self.digit7 = Some(((self.b1 & 240) >> 4) as i32); - return Ok(self.digit7.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeLe_RtlObj { - pub b1: u8, - pub b2: u8, - pub b3: u8, - pub b4: u8, - pub as_int: Option, - pub digit2: Option, - pub digit4: Option, - pub digit3: Option, - pub digit5: Option, - pub digit8: Option, - pub digit6: Option, - pub as_str: Option, - pub digit1: Option, - pub digit7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe_RtlObj { - type Root = BcdUserTypeLe; - type ParentStack = (&'r BcdUserTypeLe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.b1 = _io.read_u1()?; - self.b2 = _io.read_u1()?; - self.b3 = _io.read_u1()?; - self.b4 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeLe_RtlObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeLe_RtlObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn as_int( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.as_int.is_some() { - return Ok(self.as_int.as_ref().unwrap()); - } - self.as_int = Some(((((((((self.digit1(_io, _root, _parent)? * 1) + (self.digit2(_io, _root, _parent)? * 10)) + (self.digit3(_io, _root, _parent)? * 100)) + (self.digit4(_io, _root, _parent)? * 1000)) + (self.digit5(_io, _root, _parent)? * 10000)) + (self.digit6(_io, _root, _parent)? * 100000)) + (self.digit7(_io, _root, _parent)? * 1000000)) + (self.digit8(_io, _root, _parent)? * 10000000)) as i32); - return Ok(self.as_int.as_ref().unwrap()); - } - fn digit2( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit2.is_some() { - return Ok(self.digit2.as_ref().unwrap()); - } - self.digit2 = Some((self.b4 & 15) as i32); - return Ok(self.digit2.as_ref().unwrap()); - } - fn digit4( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit4.is_some() { - return Ok(self.digit4.as_ref().unwrap()); - } - self.digit4 = Some((self.b3 & 15) as i32); - return Ok(self.digit4.as_ref().unwrap()); - } - fn digit3( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit3.is_some() { - return Ok(self.digit3.as_ref().unwrap()); - } - self.digit3 = Some(((self.b3 & 240) >> 4) as i32); - return Ok(self.digit3.as_ref().unwrap()); - } - fn digit5( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit5.is_some() { - return Ok(self.digit5.as_ref().unwrap()); - } - self.digit5 = Some(((self.b2 & 240) >> 4) as i32); - return Ok(self.digit5.as_ref().unwrap()); - } - fn digit8( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit8.is_some() { - return Ok(self.digit8.as_ref().unwrap()); - } - self.digit8 = Some((self.b1 & 15) as i32); - return Ok(self.digit8.as_ref().unwrap()); - } - fn digit6( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit6.is_some() { - return Ok(self.digit6.as_ref().unwrap()); - } - self.digit6 = Some((self.b2 & 15) as i32); - return Ok(self.digit6.as_ref().unwrap()); - } - fn as_str( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&String> { - if self.as_str.is_some() { - return Ok(self.as_str.as_ref().unwrap()); - } - self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit8(_io, _root, _parent)?.to_string(), self.digit7(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit2(_io, _root, _parent)?.to_string()), self.digit1(_io, _root, _parent)?.to_string()).to_string()); - return Ok(self.as_str.as_ref().unwrap()); - } - fn digit1( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit1.is_some() { - return Ok(self.digit1.as_ref().unwrap()); - } - self.digit1 = Some(((self.b4 & 240) >> 4) as i32); - return Ok(self.digit1.as_ref().unwrap()); - } - fn digit7( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit7.is_some() { - return Ok(self.digit7.as_ref().unwrap()); - } - self.digit7 = Some(((self.b1 & 240) >> 4) as i32); - return Ok(self.digit7.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct BcdUserTypeLe_LeadingZeroLtrObj { - pub b1: u8, - pub b2: u8, - pub b3: u8, - pub b4: u8, - pub as_int: Option, - pub digit2: Option, - pub digit4: Option, - pub digit3: Option, - pub digit5: Option, - pub digit8: Option, - pub digit6: Option, - pub as_str: Option, - pub digit1: Option, - pub digit7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BcdUserTypeLe_LeadingZeroLtrObj { - type Root = BcdUserTypeLe; - type ParentStack = (&'r BcdUserTypeLe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.b1 = _io.read_u1()?; - self.b2 = _io.read_u1()?; - self.b3 = _io.read_u1()?; - self.b4 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> BcdUserTypeLe_LeadingZeroLtrObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BcdUserTypeLe_LeadingZeroLtrObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn as_int( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.as_int.is_some() { - return Ok(self.as_int.as_ref().unwrap()); - } - self.as_int = Some(((((((((self.digit8(_io, _root, _parent)? * 1) + (self.digit7(_io, _root, _parent)? * 10)) + (self.digit6(_io, _root, _parent)? * 100)) + (self.digit5(_io, _root, _parent)? * 1000)) + (self.digit4(_io, _root, _parent)? * 10000)) + (self.digit3(_io, _root, _parent)? * 100000)) + (self.digit2(_io, _root, _parent)? * 1000000)) + (self.digit1(_io, _root, _parent)? * 10000000)) as i32); - return Ok(self.as_int.as_ref().unwrap()); - } - fn digit2( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit2.is_some() { - return Ok(self.digit2.as_ref().unwrap()); - } - self.digit2 = Some((self.b4 & 15) as i32); - return Ok(self.digit2.as_ref().unwrap()); - } - fn digit4( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit4.is_some() { - return Ok(self.digit4.as_ref().unwrap()); - } - self.digit4 = Some((self.b3 & 15) as i32); - return Ok(self.digit4.as_ref().unwrap()); - } - fn digit3( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit3.is_some() { - return Ok(self.digit3.as_ref().unwrap()); - } - self.digit3 = Some(((self.b3 & 240) >> 4) as i32); - return Ok(self.digit3.as_ref().unwrap()); - } - fn digit5( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit5.is_some() { - return Ok(self.digit5.as_ref().unwrap()); - } - self.digit5 = Some(((self.b2 & 240) >> 4) as i32); - return Ok(self.digit5.as_ref().unwrap()); - } - fn digit8( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit8.is_some() { - return Ok(self.digit8.as_ref().unwrap()); - } - self.digit8 = Some((self.b1 & 15) as i32); - return Ok(self.digit8.as_ref().unwrap()); - } - fn digit6( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit6.is_some() { - return Ok(self.digit6.as_ref().unwrap()); - } - self.digit6 = Some((self.b2 & 15) as i32); - return Ok(self.digit6.as_ref().unwrap()); - } - fn as_str( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&String> { - if self.as_str.is_some() { - return Ok(self.as_str.as_ref().unwrap()); - } - self.as_str = Some(format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", format!("{}{}", self.digit1(_io, _root, _parent)?.to_string(), self.digit2(_io, _root, _parent)?.to_string()), self.digit3(_io, _root, _parent)?.to_string()), self.digit4(_io, _root, _parent)?.to_string()), self.digit5(_io, _root, _parent)?.to_string()), self.digit6(_io, _root, _parent)?.to_string()), self.digit7(_io, _root, _parent)?.to_string()), self.digit8(_io, _root, _parent)?.to_string()).to_string()); - return Ok(self.as_str.as_ref().unwrap()); - } - fn digit1( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit1.is_some() { - return Ok(self.digit1.as_ref().unwrap()); - } - self.digit1 = Some(((self.b4 & 240) >> 4) as i32); - return Ok(self.digit1.as_ref().unwrap()); - } - fn digit7( - &mut self, - _io: &'s S, - _root: Option<&'r BcdUserTypeLe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.digit7.is_some() { - return Ok(self.digit7.as_ref().unwrap()); - } - self.digit7 = Some(((self.b1 & 240) >> 4) as i32); - return Ok(self.digit7.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/bits_byte_aligned.rs b/spec/rust/src/formats/bits_byte_aligned.rs deleted file mode 100644 index b8c09b521..000000000 --- a/spec/rust/src/formats/bits_byte_aligned.rs +++ /dev/null @@ -1,61 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsByteAligned { - pub one: u64, - pub byte_1: u8, - pub two: u64, - pub three: bool, - pub byte_2: u8, - pub four: u64, - pub byte_3: Vec, - pub full_byte: u64, - pub byte_4: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsByteAligned { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_bits_int(6)?; - _io.align_to_byte()?; - self.byte_1 = _io.read_u1()?; - self.two = _io.read_bits_int(3)?; - self.three = _io.read_bits_int(1)? != 0; - _io.align_to_byte()?; - self.byte_2 = _io.read_u1()?; - self.four = _io.read_bits_int(14)?; - _io.align_to_byte()?; - self.byte_3 = _io.read_bytes(1 as usize)?.to_vec(); - self.full_byte = _io.read_bits_int(8)?; - _io.align_to_byte()?; - self.byte_4 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsByteAligned { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsByteAligned::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_enum.rs b/spec/rust/src/formats/bits_enum.rs deleted file mode 100644 index 6c9d6249e..000000000 --- a/spec/rust/src/formats/bits_enum.rs +++ /dev/null @@ -1,65 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsEnum { - pub one: Option, - pub two: Option, - pub three: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsEnum { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some((_io.read_bits_int(4)? as i64).try_into()?); - self.two = Some((_io.read_bits_int(8)? as i64).try_into()?); - self.three = Some((_io.read_bits_int(1)? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> BitsEnum { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsEnum::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum BitsEnum_Animal { - Cat, - Dog, - Horse, - Platypus, -} -impl TryFrom for BitsEnum_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 0 => Ok(BitsEnum_Animal::Cat), - 1 => Ok(BitsEnum_Animal::Dog), - 4 => Ok(BitsEnum_Animal::Horse), - 5 => Ok(BitsEnum_Animal::Platypus), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/bits_seq_endian_combo.rs b/spec/rust/src/formats/bits_seq_endian_combo.rs deleted file mode 100644 index b558a4e85..000000000 --- a/spec/rust/src/formats/bits_seq_endian_combo.rs +++ /dev/null @@ -1,55 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsSeqEndianCombo { - pub be1: u64, - pub be2: u64, - pub le3: u64, - pub be4: u64, - pub le5: u64, - pub le6: u64, - pub le7: u64, - pub be8: bool, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsSeqEndianCombo { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.be1 = _io.read_bits_int(6)?; - self.be2 = _io.read_bits_int(10)?; - self.le3 = _io.read_bits_int(8)?; - self.be4 = _io.read_bits_int(8)?; - self.le5 = _io.read_bits_int(5)?; - self.le6 = _io.read_bits_int(6)?; - self.le7 = _io.read_bits_int(5)?; - self.be8 = _io.read_bits_int(1)? != 0; - Ok(()) - } -} -impl<'r, 's: 'r> BitsSeqEndianCombo { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsSeqEndianCombo::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_shift_by_b32_le.rs b/spec/rust/src/formats/bits_shift_by_b32_le.rs deleted file mode 100644 index 51bc1c064..000000000 --- a/spec/rust/src/formats/bits_shift_by_b32_le.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsShiftByB32Le { - pub a: u64, - pub b: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsShiftByB32Le { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(32)?; - self.b = _io.read_bits_int(8)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsShiftByB32Le { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsShiftByB32Le::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_shift_by_b64_le.rs b/spec/rust/src/formats/bits_shift_by_b64_le.rs deleted file mode 100644 index 55679664f..000000000 --- a/spec/rust/src/formats/bits_shift_by_b64_le.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsShiftByB64Le { - pub a: u64, - pub b: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsShiftByB64Le { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(64)?; - self.b = _io.read_bits_int(8)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsShiftByB64Le { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsShiftByB64Le::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_signed_res_b32_be.rs b/spec/rust/src/formats/bits_signed_res_b32_be.rs deleted file mode 100644 index 78dc78f26..000000000 --- a/spec/rust/src/formats/bits_signed_res_b32_be.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsSignedResB32Be { - pub a: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedResB32Be { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(32)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsSignedResB32Be { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsSignedResB32Be::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_signed_res_b32_le.rs b/spec/rust/src/formats/bits_signed_res_b32_le.rs deleted file mode 100644 index 44e6772a2..000000000 --- a/spec/rust/src/formats/bits_signed_res_b32_le.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsSignedResB32Le { - pub a: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedResB32Le { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(32)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsSignedResB32Le { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsSignedResB32Le::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_signed_shift_b32_le.rs b/spec/rust/src/formats/bits_signed_shift_b32_le.rs deleted file mode 100644 index 177b8e710..000000000 --- a/spec/rust/src/formats/bits_signed_shift_b32_le.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsSignedShiftB32Le { - pub a: u64, - pub b: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedShiftB32Le { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(31)?; - self.b = _io.read_bits_int(9)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsSignedShiftB32Le { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsSignedShiftB32Le::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_signed_shift_b64_le.rs b/spec/rust/src/formats/bits_signed_shift_b64_le.rs deleted file mode 100644 index fc04f649e..000000000 --- a/spec/rust/src/formats/bits_signed_shift_b64_le.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsSignedShiftB64Le { - pub a: u64, - pub b: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsSignedShiftB64Le { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(63)?; - self.b = _io.read_bits_int(9)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsSignedShiftB64Le { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsSignedShiftB64Le::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_simple.rs b/spec/rust/src/formats/bits_simple.rs deleted file mode 100644 index f3aa512e6..000000000 --- a/spec/rust/src/formats/bits_simple.rs +++ /dev/null @@ -1,82 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsSimple { - pub byte_1: u64, - pub byte_2: u64, - pub bits_a: bool, - pub bits_b: u64, - pub bits_c: u64, - pub large_bits_1: u64, - pub spacer: u64, - pub large_bits_2: u64, - pub normal_s2: i16, - pub byte_8_9_10: u64, - pub byte_11_to_14: u64, - pub byte_15_to_19: u64, - pub byte_20_to_27: u64, - pub test_if_b1: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsSimple { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.byte_1 = _io.read_bits_int(8)?; - self.byte_2 = _io.read_bits_int(8)?; - self.bits_a = _io.read_bits_int(1)? != 0; - self.bits_b = _io.read_bits_int(3)?; - self.bits_c = _io.read_bits_int(4)?; - self.large_bits_1 = _io.read_bits_int(10)?; - self.spacer = _io.read_bits_int(3)?; - self.large_bits_2 = _io.read_bits_int(11)?; - _io.align_to_byte()?; - self.normal_s2 = _io.read_s2be()?; - self.byte_8_9_10 = _io.read_bits_int(24)?; - self.byte_11_to_14 = _io.read_bits_int(32)?; - self.byte_15_to_19 = _io.read_bits_int(40)?; - self.byte_20_to_27 = _io.read_bits_int(64)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsSimple { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsSimple::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn test_if_b1( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i8> { - if self.test_if_b1.is_some() { - return Ok(self.test_if_b1.as_ref().unwrap()); - } - { - // condIfHeader(Compare(Name(identifier(bits_a)),Eq,Bool(false))) - self.test_if_b1 = Some(123 as i8); - } - return Ok(self.test_if_b1.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/bits_simple_le.rs b/spec/rust/src/formats/bits_simple_le.rs deleted file mode 100644 index 5df58495f..000000000 --- a/spec/rust/src/formats/bits_simple_le.rs +++ /dev/null @@ -1,82 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsSimpleLe { - pub byte_1: u64, - pub byte_2: u64, - pub bits_a: bool, - pub bits_b: u64, - pub bits_c: u64, - pub large_bits_1: u64, - pub spacer: u64, - pub large_bits_2: u64, - pub normal_s2: i16, - pub byte_8_9_10: u64, - pub byte_11_to_14: u64, - pub byte_15_to_19: u64, - pub byte_20_to_27: u64, - pub test_if_b1: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsSimpleLe { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.byte_1 = _io.read_bits_int(8)?; - self.byte_2 = _io.read_bits_int(8)?; - self.bits_a = _io.read_bits_int(1)? != 0; - self.bits_b = _io.read_bits_int(3)?; - self.bits_c = _io.read_bits_int(4)?; - self.large_bits_1 = _io.read_bits_int(10)?; - self.spacer = _io.read_bits_int(3)?; - self.large_bits_2 = _io.read_bits_int(11)?; - _io.align_to_byte()?; - self.normal_s2 = _io.read_s2be()?; - self.byte_8_9_10 = _io.read_bits_int(24)?; - self.byte_11_to_14 = _io.read_bits_int(32)?; - self.byte_15_to_19 = _io.read_bits_int(40)?; - self.byte_20_to_27 = _io.read_bits_int(64)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsSimpleLe { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsSimpleLe::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn test_if_b1( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i8> { - if self.test_if_b1.is_some() { - return Ok(self.test_if_b1.as_ref().unwrap()); - } - { - // condIfHeader(Compare(Name(identifier(bits_a)),Eq,Bool(true))) - self.test_if_b1 = Some(123 as i8); - } - return Ok(self.test_if_b1.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/bits_unaligned_b32_be.rs b/spec/rust/src/formats/bits_unaligned_b32_be.rs deleted file mode 100644 index 1cf858584..000000000 --- a/spec/rust/src/formats/bits_unaligned_b32_be.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsUnalignedB32Be { - pub a: bool, - pub b: u64, - pub c: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB32Be { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(1)? != 0; - self.b = _io.read_bits_int(32)?; - self.c = _io.read_bits_int(7)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsUnalignedB32Be { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsUnalignedB32Be::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_unaligned_b32_le.rs b/spec/rust/src/formats/bits_unaligned_b32_le.rs deleted file mode 100644 index b6ea72e5a..000000000 --- a/spec/rust/src/formats/bits_unaligned_b32_le.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsUnalignedB32Le { - pub a: bool, - pub b: u64, - pub c: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB32Le { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(1)? != 0; - self.b = _io.read_bits_int(32)?; - self.c = _io.read_bits_int(7)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsUnalignedB32Le { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsUnalignedB32Le::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_unaligned_b64_be.rs b/spec/rust/src/formats/bits_unaligned_b64_be.rs deleted file mode 100644 index 40c82f01d..000000000 --- a/spec/rust/src/formats/bits_unaligned_b64_be.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsUnalignedB64Be { - pub a: bool, - pub b: u64, - pub c: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB64Be { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(1)? != 0; - self.b = _io.read_bits_int(64)?; - self.c = _io.read_bits_int(7)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsUnalignedB64Be { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsUnalignedB64Be::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bits_unaligned_b64_le.rs b/spec/rust/src/formats/bits_unaligned_b64_le.rs deleted file mode 100644 index 760332cb2..000000000 --- a/spec/rust/src/formats/bits_unaligned_b64_le.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BitsUnalignedB64Le { - pub a: bool, - pub b: u64, - pub c: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BitsUnalignedB64Le { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bits_int(1)? != 0; - self.b = _io.read_bits_int(64)?; - self.c = _io.read_bits_int(7)?; - Ok(()) - } -} -impl<'r, 's: 'r> BitsUnalignedB64Le { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BitsUnalignedB64Le::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/buffered_struct.rs b/spec/rust/src/formats/buffered_struct.rs deleted file mode 100644 index fcc3fff4c..000000000 --- a/spec/rust/src/formats/buffered_struct.rs +++ /dev/null @@ -1,88 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(block1)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(block2)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct BufferedStruct { - pub len1: u32, - pub block1: Option, - pub len2: u32, - pub block2: Option, - pub finisher: u32, - pub raw_block1: Vec, - pub raw_block2: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BufferedStruct { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len1 = _io.read_u4le()?; - self.block1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len1 as usize)?), Some(self), _parent.push(self))?); - self.len2 = _io.read_u4le()?; - self.block2 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len2 as usize)?), Some(self), _parent.push(self))?); - self.finisher = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> BufferedStruct { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BufferedStruct::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct BufferedStruct_Block { - pub number1: u32, - pub number2: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BufferedStruct_Block { - type Root = BufferedStruct; - type ParentStack = (&'r BufferedStruct, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.number1 = _io.read_u4le()?; - self.number2 = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> BufferedStruct_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BufferedStruct_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/bytes_pad_term.rs b/spec/rust/src/formats/bytes_pad_term.rs deleted file mode 100644 index 2a63e5a53..000000000 --- a/spec/rust/src/formats/bytes_pad_term.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct BytesPadTerm { - pub str_pad: Vec, - pub str_term: Vec, - pub str_term_and_pad: Vec, - pub str_term_include: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for BytesPadTerm { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.str_pad = _io.bytes_strip_right(_io.read_bytes(20 as usize)?, 64).to_vec(); - self.str_term = _io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, false).to_vec(); - self.str_term_and_pad = _io.bytes_terminate(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 43), 64, false).to_vec(); - self.str_term_include = _io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, true).to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> BytesPadTerm { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = BytesPadTerm::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/cast_nested.rs b/spec/rust/src/formats/cast_nested.rs deleted file mode 100644 index 157cd94e0..000000000 --- a/spec/rust/src/formats/cast_nested.rs +++ /dev/null @@ -1,224 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct CastNested { - pub opcodes: Vec, - pub opcodes_0_str: Option, - pub opcodes_0_str_value: Option, - pub opcodes_1_int: Option, - pub opcodes_1_int_value: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CastNested { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = CastNested_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> CastNested { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CastNested::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn opcodes_0_str( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&CastNested_Opcode_Strval> { - if self.opcodes_0_str.is_some() { - return Ok(self.opcodes_0_str.as_ref().unwrap()); - } - self.opcodes_0_str = Some(self.opcodes[0 as usize].body as CastNested_Opcode_Strval); - return Ok(self.opcodes_0_str.as_ref().unwrap()); - } - fn opcodes_0_str_value( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.opcodes_0_str_value.is_some() { - return Ok(self.opcodes_0_str_value.as_ref().unwrap()); - } - self.opcodes_0_str_value = Some(self.opcodes[0 as usize].body.value.to_string()); - return Ok(self.opcodes_0_str_value.as_ref().unwrap()); - } - fn opcodes_1_int( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&CastNested_Opcode_Intval> { - if self.opcodes_1_int.is_some() { - return Ok(self.opcodes_1_int.as_ref().unwrap()); - } - self.opcodes_1_int = Some(self.opcodes[1 as usize].body as CastNested_Opcode_Intval); - return Ok(self.opcodes_1_int.as_ref().unwrap()); - } - fn opcodes_1_int_value( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.opcodes_1_int_value.is_some() { - return Ok(self.opcodes_1_int_value.as_ref().unwrap()); - } - self.opcodes_1_int_value = Some(self.opcodes[1 as usize].body.value as u8); - return Ok(self.opcodes_1_int_value.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct CastNested_Opcode { - pub code: u8, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum CastNested_Opcode_Body { - CastNested_Opcode_Intval(CastNested_Opcode_Intval), - CastNested_Opcode_Strval(CastNested_Opcode_Strval), -} -impl From for CastNested_Opcode_Body { - fn from(v: CastNested_Opcode_Intval) -> Self { - Self::CastNested_Opcode_Intval(v) - } -} -impl From for CastNested_Opcode_Body { - fn from(v: CastNested_Opcode_Strval) -> Self { - Self::CastNested_Opcode_Strval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for CastNested_Opcode { - type Root = CastNested; - type ParentStack = (&'r CastNested, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - match self.code { - 73 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - 83 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> CastNested_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CastNested_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct CastNested_Opcode_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CastNested_Opcode_Intval { - type Root = CastNested; - type ParentStack = (&'r CastNested_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> CastNested_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CastNested_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct CastNested_Opcode_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CastNested_Opcode_Strval { - type Root = CastNested; - type ParentStack = (&'r CastNested_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> CastNested_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CastNested_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/cast_to_imported.rs b/spec/rust/src/formats/cast_to_imported.rs deleted file mode 100644 index d7822ed2e..000000000 --- a/spec/rust/src/formats/cast_to_imported.rs +++ /dev/null @@ -1,55 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::hello_world::HelloWorld; - -#[derive(Default, Debug, PartialEq)] -pub struct CastToImported { - pub one: Option>, - pub one_casted: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CastToImported { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> CastToImported { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CastToImported::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn one_casted( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Box> { - if self.one_casted.is_some() { - return Ok(self.one_casted.as_ref().unwrap()); - } - self.one_casted = Some(self.one as HelloWorld); - return Ok(self.one_casted.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/cast_to_top.rs b/spec/rust/src/formats/cast_to_top.rs deleted file mode 100644 index 6dc4d5aed..000000000 --- a/spec/rust/src/formats/cast_to_top.rs +++ /dev/null @@ -1,69 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct CastToTop { - pub code: u8, - pub header: Option>, - pub header_casted: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CastToTop { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> CastToTop { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CastToTop::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn header( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Box> { - if self.header.is_some() { - return Ok(self.header.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(1)) - // popPos(_io) - return Ok(self.header.as_ref().unwrap()); - } - fn header_casted( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Box> { - if self.header_casted.is_some() { - return Ok(self.header_casted.as_ref().unwrap()); - } - self.header_casted = Some(self.header(_io, _root, _parent)? as CastToTop); - return Ok(self.header_casted.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/combine_bool.rs b/spec/rust/src/formats/combine_bool.rs deleted file mode 100644 index 1db57046f..000000000 --- a/spec/rust/src/formats/combine_bool.rs +++ /dev/null @@ -1,67 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct CombineBool { - pub bool_bit: bool, - pub bool_calc: Option, - pub bool_calc_bit: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CombineBool { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.bool_bit = _io.read_bits_int(1)? != 0; - Ok(()) - } -} -impl<'r, 's: 'r> CombineBool { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CombineBool::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn bool_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.bool_calc.is_some() { - return Ok(self.bool_calc.as_ref().unwrap()); - } - self.bool_calc = Some(false as bool); - return Ok(self.bool_calc.as_ref().unwrap()); - } - fn bool_calc_bit( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.bool_calc_bit.is_some() { - return Ok(self.bool_calc_bit.as_ref().unwrap()); - } - self.bool_calc_bit = Some(if true { self.bool_calc(_io, _root, _parent)? } else { self.bool_bit} as bool); - return Ok(self.bool_calc_bit.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/combine_bytes.rs b/spec/rust/src/formats/combine_bytes.rs deleted file mode 100644 index dd1a6b2c6..000000000 --- a/spec/rust/src/formats/combine_bytes.rs +++ /dev/null @@ -1,136 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct CombineBytes { - pub bytes_term: Vec, - pub bytes_limit: Vec, - pub bytes_eos: Vec, - pub limit_or_calc: Option>, - pub term_or_limit: Option>, - pub limit_or_eos: Option>, - pub eos_or_calc: Option>, - pub term_or_calc: Option>, - pub bytes_calc: Option>, - pub term_or_eos: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CombineBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.bytes_term = _io.read_bytes_term(124, false, true, true)?; - self.bytes_limit = _io.read_bytes(4 as usize)?.to_vec(); - self.bytes_eos = _io.read_bytes_full()?; - Ok(()) - } -} -impl<'r, 's: 'r> CombineBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CombineBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn limit_or_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.limit_or_calc.is_some() { - return Ok(self.limit_or_calc.as_ref().unwrap()); - } - self.limit_or_calc = Some(if false { self.bytes_limit } else { self.bytes_calc(_io, _root, _parent)?} as Vec); - return Ok(self.limit_or_calc.as_ref().unwrap()); - } - fn term_or_limit( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.term_or_limit.is_some() { - return Ok(self.term_or_limit.as_ref().unwrap()); - } - self.term_or_limit = Some(if true { self.bytes_term } else { self.bytes_limit} as Vec); - return Ok(self.term_or_limit.as_ref().unwrap()); - } - fn limit_or_eos( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.limit_or_eos.is_some() { - return Ok(self.limit_or_eos.as_ref().unwrap()); - } - self.limit_or_eos = Some(if true { self.bytes_limit } else { self.bytes_eos} as Vec); - return Ok(self.limit_or_eos.as_ref().unwrap()); - } - fn eos_or_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.eos_or_calc.is_some() { - return Ok(self.eos_or_calc.as_ref().unwrap()); - } - self.eos_or_calc = Some(if true { self.bytes_eos } else { self.bytes_calc(_io, _root, _parent)?} as Vec); - return Ok(self.eos_or_calc.as_ref().unwrap()); - } - fn term_or_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.term_or_calc.is_some() { - return Ok(self.term_or_calc.as_ref().unwrap()); - } - self.term_or_calc = Some(if true { self.bytes_term } else { self.bytes_calc(_io, _root, _parent)?} as Vec); - return Ok(self.term_or_calc.as_ref().unwrap()); - } - fn bytes_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.bytes_calc.is_some() { - return Ok(self.bytes_calc.as_ref().unwrap()); - } - self.bytes_calc = Some(&[0x52, 0x6e, 0x44] as Vec); - return Ok(self.bytes_calc.as_ref().unwrap()); - } - fn term_or_eos( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.term_or_eos.is_some() { - return Ok(self.term_or_eos.as_ref().unwrap()); - } - self.term_or_eos = Some(if false { self.bytes_term } else { self.bytes_eos} as Vec); - return Ok(self.term_or_eos.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/combine_enum.rs b/spec/rust/src/formats/combine_enum.rs deleted file mode 100644 index eace6ec19..000000000 --- a/spec/rust/src/formats/combine_enum.rs +++ /dev/null @@ -1,72 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct CombineEnum { - pub enum_u4: Option, - pub enum_u2: Option, - pub enum_u4_u2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CombineEnum { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.enum_u4 = Some((_io.read_u4le()? as i64).try_into()?); - self.enum_u2 = Some((_io.read_u2le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> CombineEnum { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CombineEnum::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn enum_u4_u2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&CombineEnum_Animal> { - if self.enum_u4_u2.is_some() { - return Ok(self.enum_u4_u2.as_ref().unwrap()); - } - self.enum_u4_u2 = Some(if false { self.enum_u4 } else { self.enum_u2} as i32); - return Ok(self.enum_u4_u2.as_ref().unwrap()); - } -} -#[derive(Debug, PartialEq)] -pub enum CombineEnum_Animal { - Pig, - Horse, -} -impl TryFrom for CombineEnum_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 7 => Ok(CombineEnum_Animal::Pig), - 12 => Ok(CombineEnum_Animal::Horse), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/combine_str.rs b/spec/rust/src/formats/combine_str.rs deleted file mode 100644 index 6adb3ee36..000000000 --- a/spec/rust/src/formats/combine_str.rs +++ /dev/null @@ -1,214 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct CombineStr { - pub str_term: String, - pub str_limit: String, - pub str_eos: String, - pub limit_or_calc_bytes: Option, - pub limit_or_calc: Option, - pub term_or_limit: Option, - pub limit_or_eos: Option, - pub calc_or_calc_bytes: Option, - pub str_calc_bytes: Option, - pub eos_or_calc: Option, - pub term_or_calc: Option, - pub term_or_calc_bytes: Option, - pub term_or_eos: Option, - pub str_calc: Option, - pub eos_or_calc_bytes: Option, - pub calc_bytes: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for CombineStr { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.str_term = decode_string(_io.read_bytes_term(124, false, true, true)?, "ASCII")?; - self.str_limit = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; - self.str_eos = decode_string(_io.read_bytes_full()?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> CombineStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = CombineStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn limit_or_calc_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.limit_or_calc_bytes.is_some() { - return Ok(self.limit_or_calc_bytes.as_ref().unwrap()); - } - self.limit_or_calc_bytes = Some(if true { self.str_limit } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); - return Ok(self.limit_or_calc_bytes.as_ref().unwrap()); - } - fn limit_or_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.limit_or_calc.is_some() { - return Ok(self.limit_or_calc.as_ref().unwrap()); - } - self.limit_or_calc = Some(if false { self.str_limit } else { self.str_calc(_io, _root, _parent)?}.to_string()); - return Ok(self.limit_or_calc.as_ref().unwrap()); - } - fn term_or_limit( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.term_or_limit.is_some() { - return Ok(self.term_or_limit.as_ref().unwrap()); - } - self.term_or_limit = Some(if true { self.str_term } else { self.str_limit}.to_string()); - return Ok(self.term_or_limit.as_ref().unwrap()); - } - fn limit_or_eos( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.limit_or_eos.is_some() { - return Ok(self.limit_or_eos.as_ref().unwrap()); - } - self.limit_or_eos = Some(if true { self.str_limit } else { self.str_eos}.to_string()); - return Ok(self.limit_or_eos.as_ref().unwrap()); - } - fn calc_or_calc_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.calc_or_calc_bytes.is_some() { - return Ok(self.calc_or_calc_bytes.as_ref().unwrap()); - } - self.calc_or_calc_bytes = Some(if false { self.str_calc(_io, _root, _parent)? } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); - return Ok(self.calc_or_calc_bytes.as_ref().unwrap()); - } - fn str_calc_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.str_calc_bytes.is_some() { - return Ok(self.str_calc_bytes.as_ref().unwrap()); - } - self.str_calc_bytes = Some(decode_string(self.calc_bytes(_io, _root, _parent)?, "ASCII")?.to_string()); - return Ok(self.str_calc_bytes.as_ref().unwrap()); - } - fn eos_or_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.eos_or_calc.is_some() { - return Ok(self.eos_or_calc.as_ref().unwrap()); - } - self.eos_or_calc = Some(if false { self.str_eos } else { self.str_calc(_io, _root, _parent)?}.to_string()); - return Ok(self.eos_or_calc.as_ref().unwrap()); - } - fn term_or_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.term_or_calc.is_some() { - return Ok(self.term_or_calc.as_ref().unwrap()); - } - self.term_or_calc = Some(if true { self.str_term } else { self.str_calc(_io, _root, _parent)?}.to_string()); - return Ok(self.term_or_calc.as_ref().unwrap()); - } - fn term_or_calc_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.term_or_calc_bytes.is_some() { - return Ok(self.term_or_calc_bytes.as_ref().unwrap()); - } - self.term_or_calc_bytes = Some(if false { self.str_term } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); - return Ok(self.term_or_calc_bytes.as_ref().unwrap()); - } - fn term_or_eos( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.term_or_eos.is_some() { - return Ok(self.term_or_eos.as_ref().unwrap()); - } - self.term_or_eos = Some(if false { self.str_term } else { self.str_eos}.to_string()); - return Ok(self.term_or_eos.as_ref().unwrap()); - } - fn str_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.str_calc.is_some() { - return Ok(self.str_calc.as_ref().unwrap()); - } - self.str_calc = Some("bar".to_string()); - return Ok(self.str_calc.as_ref().unwrap()); - } - fn eos_or_calc_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.eos_or_calc_bytes.is_some() { - return Ok(self.eos_or_calc_bytes.as_ref().unwrap()); - } - self.eos_or_calc_bytes = Some(if true { self.str_eos } else { self.str_calc_bytes(_io, _root, _parent)?}.to_string()); - return Ok(self.eos_or_calc_bytes.as_ref().unwrap()); - } - fn calc_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.calc_bytes.is_some() { - return Ok(self.calc_bytes.as_ref().unwrap()); - } - self.calc_bytes = Some(&[0x62, 0x61, 0x7a] as Vec); - return Ok(self.calc_bytes.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/debug_0.rs b/spec/rust/src/formats/debug_0.rs deleted file mode 100644 index ef53c2b95..000000000 --- a/spec/rust/src/formats/debug_0.rs +++ /dev/null @@ -1,49 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Debug0 { - pub one: u8, - pub array_of_ints: Vec, - pub _unnamed2: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Debug0 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - self.array_of_ints = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(array_of_ints), _io, Int1Type(false), IntNum(3)) - // handleAssignmentRepeatExpr(NamedIdentifier(array_of_ints), _io.read_u1()?) - } - self._unnamed2 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> Debug0 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Debug0::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/default_big_endian.rs b/spec/rust/src/formats/default_big_endian.rs deleted file mode 100644 index 8b71d7775..000000000 --- a/spec/rust/src/formats/default_big_endian.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultBigEndian { - pub one: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBigEndian { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u4be()?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultBigEndian { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultBigEndian::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/default_bit_endian_mod.rs b/spec/rust/src/formats/default_bit_endian_mod.rs deleted file mode 100644 index b278a5b9e..000000000 --- a/spec/rust/src/formats/default_bit_endian_mod.rs +++ /dev/null @@ -1,147 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultBitEndianMod { - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultBitEndianMod { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultBitEndianMod::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultBitEndianMod_MainObj { - pub one: u64, - pub two: u64, - pub nest: Option, - pub nest_be: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod_MainObj { - type Root = DefaultBitEndianMod; - type ParentStack = (&'r DefaultBitEndianMod, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_bits_int(9)?; - self.two = _io.read_bits_int(15)?; - _io.align_to_byte()?; - self.nest = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.nest_be = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultBitEndianMod_MainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultBitEndianMod_MainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultBitEndianMod_MainObj_Subnest { - pub two: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod_MainObj_Subnest { - type Root = DefaultBitEndianMod; - type ParentStack = (&'r DefaultBitEndianMod_MainObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.two = _io.read_bits_int(16)?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultBitEndianMod_MainObj_Subnest { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultBitEndianMod_MainObj_Subnest::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultBitEndianMod_MainObj_SubnestBe { - pub two: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultBitEndianMod_MainObj_SubnestBe { - type Root = DefaultBitEndianMod; - type ParentStack = (&'r DefaultBitEndianMod_MainObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.two = _io.read_bits_int(16)?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultBitEndianMod_MainObj_SubnestBe { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultBitEndianMod_MainObj_SubnestBe::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/default_endian_expr_exception.rs b/spec/rust/src/formats/default_endian_expr_exception.rs deleted file mode 100644 index 40d7819d2..000000000 --- a/spec/rust/src/formats/default_endian_expr_exception.rs +++ /dev/null @@ -1,119 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprException { - pub docs: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprException { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.docs = Vec::new(); - { - type ArrayElement = DefaultEndianExprException_Doc; - while !_io.is_eof() { - self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprException { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprException::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprException_Doc { - pub indicator: Vec, - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprException_Doc { - type Root = DefaultEndianExprException; - type ParentStack = (&'r DefaultEndianExprException, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.indicator = _io.read_bytes(2 as usize)?.to_vec(); - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprException_Doc { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprException_Doc::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprException_Doc_MainObj { - pub some_int: u32, - pub some_int_be: u16, - pub some_int_le: u16, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprException_Doc_MainObj { - type Root = DefaultEndianExprException; - type ParentStack = (&'r DefaultEndianExprException_Doc, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.some_int = panic!("Unable to parse unknown-endian integers"); - self.some_int_be = _io.read_u2be()?; - self.some_int_le = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprException_Doc_MainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprException_Doc_MainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/default_endian_expr_inherited.rs b/spec/rust/src/formats/default_endian_expr_inherited.rs deleted file mode 100644 index 39b59d9b4..000000000 --- a/spec/rust/src/formats/default_endian_expr_inherited.rs +++ /dev/null @@ -1,200 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprInherited { - pub docs: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.docs = Vec::new(); - { - type ArrayElement = DefaultEndianExprInherited_Doc; - while !_io.is_eof() { - self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprInherited { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprInherited::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprInherited_Doc { - pub indicator: Vec, - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc { - type Root = DefaultEndianExprInherited; - type ParentStack = (&'r DefaultEndianExprInherited, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.indicator = _io.read_bytes(2 as usize)?.to_vec(); - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprInherited_Doc { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprInherited_Doc::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprInherited_Doc_MainObj { - pub insides: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc_MainObj { - type Root = DefaultEndianExprInherited; - type ParentStack = (&'r DefaultEndianExprInherited_Doc, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.insides = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self), self._is_le)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprInherited_Doc_MainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprInherited_Doc_MainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprInherited_Doc_MainObj_SubObj { - pub some_int: u32, - pub more: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc_MainObj_SubObj { - type Root = DefaultEndianExprInherited; - type ParentStack = (&'r DefaultEndianExprInherited_Doc_MainObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.some_int = panic!("Unable to parse unknown-endian integers"); - self.more = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self), self._is_le)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprInherited_Doc_MainObj_SubObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprInherited_Doc_MainObj_SubObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj { - pub some_int1: u16, - pub some_int2: u16, - pub some_inst: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj { - type Root = DefaultEndianExprInherited; - type ParentStack = (&'r DefaultEndianExprInherited_Doc_MainObj_SubObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.some_int1 = panic!("Unable to parse unknown-endian integers"); - self.some_int2 = panic!("Unable to parse unknown-endian integers"); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprInherited_Doc_MainObj_SubObj_SubsubObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn some_inst( - &mut self, - _io: &'s S, - _root: Option<&'r DefaultEndianExprInherited>, - _parent: Option>::ParentStack)>> - ) -> KResult<&u32> { - if self.some_inst.is_some() { - return Ok(self.some_inst.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(2)) - // popPos(_io) - return Ok(self.some_inst.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/default_endian_expr_is_be.rs b/spec/rust/src/formats/default_endian_expr_is_be.rs deleted file mode 100644 index 1d38ef23d..000000000 --- a/spec/rust/src/formats/default_endian_expr_is_be.rs +++ /dev/null @@ -1,182 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprIsBe { - pub docs: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.docs = Vec::new(); - { - type ArrayElement = DefaultEndianExprIsBe_Doc; - while !_io.is_eof() { - self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprIsBe { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprIsBe::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprIsBe_Doc { - pub indicator: Vec, - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe_Doc { - type Root = DefaultEndianExprIsBe; - type ParentStack = (&'r DefaultEndianExprIsBe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.indicator = _io.read_bytes(2 as usize)?.to_vec(); - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprIsBe_Doc { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprIsBe_Doc::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprIsBe_Doc_MainObj { - pub some_int: u32, - pub some_int_be: u16, - pub some_int_le: u16, - pub inst_int: Option, - pub inst_sub: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe_Doc_MainObj { - type Root = DefaultEndianExprIsBe; - type ParentStack = (&'r DefaultEndianExprIsBe_Doc, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.some_int = panic!("Unable to parse unknown-endian integers"); - self.some_int_be = _io.read_u2be()?; - self.some_int_le = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprIsBe_Doc_MainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprIsBe_Doc_MainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn inst_int( - &mut self, - _io: &'s S, - _root: Option<&'r DefaultEndianExprIsBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&u32> { - if self.inst_int.is_some() { - return Ok(self.inst_int.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(2)) - // popPos(_io) - return Ok(self.inst_int.as_ref().unwrap()); - } - fn inst_sub( - &mut self, - _io: &'s S, - _root: Option<&'r DefaultEndianExprIsBe>, - _parent: Option>::ParentStack)>> - ) -> KResult<&DefaultEndianExprIsBe_Doc_MainObj_SubMainObj> { - if self.inst_sub.is_some() { - return Ok(self.inst_sub.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(2)) - // popPos(_io) - return Ok(self.inst_sub.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprIsBe_Doc_MainObj_SubMainObj { - pub foo: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsBe_Doc_MainObj_SubMainObj { - type Root = DefaultEndianExprIsBe; - type ParentStack = (&'r DefaultEndianExprIsBe_Doc_MainObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = panic!("Unable to parse unknown-endian integers"); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprIsBe_Doc_MainObj_SubMainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprIsBe_Doc_MainObj_SubMainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/default_endian_expr_is_le.rs b/spec/rust/src/formats/default_endian_expr_is_le.rs deleted file mode 100644 index ad1ccb6ef..000000000 --- a/spec/rust/src/formats/default_endian_expr_is_le.rs +++ /dev/null @@ -1,119 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprIsLe { - pub docs: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsLe { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.docs = Vec::new(); - { - type ArrayElement = DefaultEndianExprIsLe_Doc; - while !_io.is_eof() { - self.docs.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprIsLe { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprIsLe::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprIsLe_Doc { - pub indicator: Vec, - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsLe_Doc { - type Root = DefaultEndianExprIsLe; - type ParentStack = (&'r DefaultEndianExprIsLe, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.indicator = _io.read_bytes(2 as usize)?.to_vec(); - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprIsLe_Doc { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprIsLe_Doc::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianExprIsLe_Doc_MainObj { - pub some_int: u32, - pub some_int_be: u16, - pub some_int_le: u16, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianExprIsLe_Doc_MainObj { - type Root = DefaultEndianExprIsLe; - type ParentStack = (&'r DefaultEndianExprIsLe_Doc, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.some_int = panic!("Unable to parse unknown-endian integers"); - self.some_int_be = _io.read_u2be()?; - self.some_int_le = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianExprIsLe_Doc_MainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianExprIsLe_Doc_MainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/default_endian_mod.rs b/spec/rust/src/formats/default_endian_mod.rs deleted file mode 100644 index c59c93fa7..000000000 --- a/spec/rust/src/formats/default_endian_mod.rs +++ /dev/null @@ -1,144 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianMod { - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianMod { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianMod::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianMod_MainObj { - pub one: i32, - pub nest: Option, - pub nest_be: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod_MainObj { - type Root = DefaultEndianMod; - type ParentStack = (&'r DefaultEndianMod, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_s4le()?; - self.nest = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.nest_be = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianMod_MainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianMod_MainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianMod_MainObj_Subnest { - pub two: i32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod_MainObj_Subnest { - type Root = DefaultEndianMod; - type ParentStack = (&'r DefaultEndianMod_MainObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.two = _io.read_s4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianMod_MainObj_Subnest { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianMod_MainObj_Subnest::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct DefaultEndianMod_MainObj_SubnestBe { - pub two: i32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DefaultEndianMod_MainObj_SubnestBe { - type Root = DefaultEndianMod; - type ParentStack = (&'r DefaultEndianMod_MainObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.two = _io.read_s4be()?; - Ok(()) - } -} -impl<'r, 's: 'r> DefaultEndianMod_MainObj_SubnestBe { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DefaultEndianMod_MainObj_SubnestBe::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/docstrings.rs b/spec/rust/src/formats/docstrings.rs deleted file mode 100644 index 95c887ab8..000000000 --- a/spec/rust/src/formats/docstrings.rs +++ /dev/null @@ -1,105 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// universalDoc() - -#[derive(Default, Debug, PartialEq)] -pub struct Docstrings { - pub one: u8, - pub two: Option, - pub three: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Docstrings { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> Docstrings { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Docstrings::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - // universalDoc() - fn two( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.two.is_some() { - return Ok(self.two.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(0)) - // popPos(_io) - return Ok(self.two.as_ref().unwrap()); - } - // universalDoc() - fn three( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i8> { - if self.three.is_some() { - return Ok(self.three.as_ref().unwrap()); - } - self.three = Some(66 as i8); - return Ok(self.three.as_ref().unwrap()); - } -} -// universalDoc() -// universalDoc() - -#[derive(Default, Debug, PartialEq)] -pub struct Docstrings_ComplexSubtype { -} -impl<'r, 's: 'r> KStruct<'r, 's> for Docstrings_ComplexSubtype { - type Root = Docstrings; - type ParentStack = (&'r Docstrings, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> Docstrings_ComplexSubtype { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Docstrings_ComplexSubtype::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/docstrings_docref.rs b/spec/rust/src/formats/docstrings_docref.rs deleted file mode 100644 index c100671d8..000000000 --- a/spec/rust/src/formats/docstrings_docref.rs +++ /dev/null @@ -1,79 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// universalDoc() - -#[derive(Default, Debug, PartialEq)] -pub struct DocstringsDocref { - pub one: u8, - pub two: u8, - pub three: u8, - pub foo: Option, - pub parse_inst: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for DocstringsDocref { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - self.two = _io.read_u1()?; - self.three = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> DocstringsDocref { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DocstringsDocref::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - // universalDoc() - fn foo( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.foo.is_some() { - return Ok(self.foo.as_ref().unwrap()); - } - self.foo = Some(true as bool); - return Ok(self.foo.as_ref().unwrap()); - } - // universalDoc() - fn parse_inst( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.parse_inst.is_some() { - return Ok(self.parse_inst.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(0)) - // popPos(_io) - return Ok(self.parse_inst.as_ref().unwrap()); - } -} -// universalDoc() -// universalDoc() -// universalDoc() diff --git a/spec/rust/src/formats/docstrings_docref_multi.rs b/spec/rust/src/formats/docstrings_docref_multi.rs deleted file mode 100644 index 51bf5bdf7..000000000 --- a/spec/rust/src/formats/docstrings_docref_multi.rs +++ /dev/null @@ -1,40 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// universalDoc() - -#[derive(Default, Debug, PartialEq)] -pub struct DocstringsDocrefMulti { -} -impl<'r, 's: 'r> KStruct<'r, 's> for DocstringsDocrefMulti { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> DocstringsDocrefMulti { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = DocstringsDocrefMulti::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/enum_0.rs b/spec/rust/src/formats/enum_0.rs deleted file mode 100644 index 5bf2db999..000000000 --- a/spec/rust/src/formats/enum_0.rs +++ /dev/null @@ -1,61 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Enum0 { - pub pet_1: Option, - pub pet_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Enum0 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> Enum0 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Enum0::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum Enum0_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for Enum0_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(Enum0_Animal::Dog), - 7 => Ok(Enum0_Animal::Cat), - 12 => Ok(Enum0_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_1.rs b/spec/rust/src/formats/enum_1.rs deleted file mode 100644 index 84f126017..000000000 --- a/spec/rust/src/formats/enum_1.rs +++ /dev/null @@ -1,127 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Enum1 { - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Enum1 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> Enum1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Enum1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct Enum1_MainObj { - pub submain: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Enum1_MainObj { - type Root = Enum1; - type ParentStack = (&'r Enum1, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.submain = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> Enum1_MainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Enum1_MainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum Enum1_MainObj_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for Enum1_MainObj_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(Enum1_MainObj_Animal::Dog), - 7 => Ok(Enum1_MainObj_Animal::Cat), - 12 => Ok(Enum1_MainObj_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct Enum1_MainObj_SubmainObj { - pub pet_1: Option, - pub pet_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Enum1_MainObj_SubmainObj { - type Root = Enum1; - type ParentStack = (&'r Enum1_MainObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> Enum1_MainObj_SubmainObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Enum1_MainObj_SubmainObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/enum_deep.rs b/spec/rust/src/formats/enum_deep.rs deleted file mode 100644 index f0288281b..000000000 --- a/spec/rust/src/formats/enum_deep.rs +++ /dev/null @@ -1,141 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumDeep { - pub pet_1: Option, - pub pet_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeep { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumDeep { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumDeep::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct EnumDeep_Container1 { -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeep_Container1 { - type Root = EnumDeep; - type ParentStack = (&'r EnumDeep, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> EnumDeep_Container1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumDeep_Container1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumDeep_Container1_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for EnumDeep_Container1_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumDeep_Container1_Animal::Dog), - 7 => Ok(EnumDeep_Container1_Animal::Cat), - 12 => Ok(EnumDeep_Container1_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct EnumDeep_Container1_Container2 { -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeep_Container1_Container2 { - type Root = EnumDeep; - type ParentStack = (&'r EnumDeep_Container1, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> EnumDeep_Container1_Container2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumDeep_Container1_Container2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumDeep_Container1_Container2_Animal { - Canary, - Turtle, - Hare, -} -impl TryFrom for EnumDeep_Container1_Container2_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumDeep_Container1_Container2_Animal::Canary), - 7 => Ok(EnumDeep_Container1_Container2_Animal::Turtle), - 12 => Ok(EnumDeep_Container1_Container2_Animal::Hare), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_deep_literals.rs b/spec/rust/src/formats/enum_deep_literals.rs deleted file mode 100644 index 64d7002c8..000000000 --- a/spec/rust/src/formats/enum_deep_literals.rs +++ /dev/null @@ -1,167 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumDeepLiterals { - pub pet_1: Option, - pub pet_2: Option, - pub is_pet_1_ok: Option, - pub is_pet_2_ok: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeepLiterals { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumDeepLiterals { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumDeepLiterals::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn is_pet_1_ok( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_pet_1_ok.is_some() { - return Ok(self.is_pet_1_ok.as_ref().unwrap()); - } - self.is_pet_1_ok = Some(self.pet_1 == EnumDeepLiterals_Container1_Animal::Cat as bool); - return Ok(self.is_pet_1_ok.as_ref().unwrap()); - } - fn is_pet_2_ok( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_pet_2_ok.is_some() { - return Ok(self.is_pet_2_ok.as_ref().unwrap()); - } - self.is_pet_2_ok = Some(self.pet_2 == EnumDeepLiterals_Container1_Container2_Animal::Hare as bool); - return Ok(self.is_pet_2_ok.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct EnumDeepLiterals_Container1 { -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeepLiterals_Container1 { - type Root = EnumDeepLiterals; - type ParentStack = (&'r EnumDeepLiterals, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> EnumDeepLiterals_Container1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumDeepLiterals_Container1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumDeepLiterals_Container1_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for EnumDeepLiterals_Container1_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumDeepLiterals_Container1_Animal::Dog), - 7 => Ok(EnumDeepLiterals_Container1_Animal::Cat), - 12 => Ok(EnumDeepLiterals_Container1_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct EnumDeepLiterals_Container1_Container2 { -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumDeepLiterals_Container1_Container2 { - type Root = EnumDeepLiterals; - type ParentStack = (&'r EnumDeepLiterals_Container1, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> EnumDeepLiterals_Container1_Container2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumDeepLiterals_Container1_Container2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumDeepLiterals_Container1_Container2_Animal { - Canary, - Turtle, - Hare, -} -impl TryFrom for EnumDeepLiterals_Container1_Container2_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumDeepLiterals_Container1_Container2_Animal::Canary), - 7 => Ok(EnumDeepLiterals_Container1_Container2_Animal::Turtle), - 12 => Ok(EnumDeepLiterals_Container1_Container2_Animal::Hare), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_fancy.rs b/spec/rust/src/formats/enum_fancy.rs deleted file mode 100644 index 243aafa9a..000000000 --- a/spec/rust/src/formats/enum_fancy.rs +++ /dev/null @@ -1,63 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumFancy { - pub pet_1: Option, - pub pet_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumFancy { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumFancy { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumFancy::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumFancy_Animal { - // universalDoc() - Dog, - // universalDoc() - Cat, - Chicken, -} -impl TryFrom for EnumFancy_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumFancy_Animal::Dog), - 7 => Ok(EnumFancy_Animal::Cat), - 12 => Ok(EnumFancy_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_for_unknown_id.rs b/spec/rust/src/formats/enum_for_unknown_id.rs deleted file mode 100644 index a37a82fb5..000000000 --- a/spec/rust/src/formats/enum_for_unknown_id.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumForUnknownId { - pub one: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumForUnknownId { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some((_io.read_u1()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumForUnknownId { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumForUnknownId::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumForUnknownId_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for EnumForUnknownId_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumForUnknownId_Animal::Dog), - 7 => Ok(EnumForUnknownId_Animal::Cat), - 12 => Ok(EnumForUnknownId_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_if.rs b/spec/rust/src/formats/enum_if.rs deleted file mode 100644 index dfe1b8df0..000000000 --- a/spec/rust/src/formats/enum_if.rs +++ /dev/null @@ -1,174 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumIf { - pub op1: Option, - pub op2: Option, - pub op3: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.op1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.op2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.op3 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumIf { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumIf::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumIf_Opcodes { - AString, - ATuple, -} -impl TryFrom for EnumIf_Opcodes { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 83 => Ok(EnumIf_Opcodes::AString), - 84 => Ok(EnumIf_Opcodes::ATuple), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct EnumIf_Operation { - pub opcode: Option, - pub arg_tuple: Option, - pub arg_str: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf_Operation { - type Root = EnumIf; - type ParentStack = (&'r EnumIf, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcode = Some((_io.read_u1()? as i64).try_into()?); - { - // condIfHeader(Compare(Name(identifier(opcode)),Eq,EnumByLabel(identifier(opcodes),identifier(a_tuple),typeId(false,List(),false)))) - self.arg_tuple = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - } - { - // condIfHeader(Compare(Name(identifier(opcode)),Eq,EnumByLabel(identifier(opcodes),identifier(a_string),typeId(false,List(),false)))) - self.arg_str = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - } - Ok(()) - } -} -impl<'r, 's: 'r> EnumIf_Operation { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumIf_Operation::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct EnumIf_ArgTuple { - pub num1: u8, - pub num2: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf_ArgTuple { - type Root = EnumIf; - type ParentStack = (&'r EnumIf, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.num1 = _io.read_u1()?; - self.num2 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> EnumIf_ArgTuple { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumIf_ArgTuple::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct EnumIf_ArgStr { - pub len: u8, - pub str: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumIf_ArgStr { - type Root = EnumIf; - type ParentStack = (&'r EnumIf, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len = _io.read_u1()?; - self.str = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> EnumIf_ArgStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumIf_ArgStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/enum_import.rs b/spec/rust/src/formats/enum_import.rs deleted file mode 100644 index ca0535be0..000000000 --- a/spec/rust/src/formats/enum_import.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumImport { - pub pet_1: Option, - pub pet_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumImport { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumImport { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumImport::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/enum_int_range_s.rs b/spec/rust/src/formats/enum_int_range_s.rs deleted file mode 100644 index 3e04b147f..000000000 --- a/spec/rust/src/formats/enum_int_range_s.rs +++ /dev/null @@ -1,63 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumIntRangeS { - pub f1: Option, - pub f2: Option, - pub f3: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumIntRangeS { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.f1 = Some((_io.read_s4be()? as i64).try_into()?); - self.f2 = Some((_io.read_s4be()? as i64).try_into()?); - self.f3 = Some((_io.read_s4be()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumIntRangeS { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumIntRangeS::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumIntRangeS_Constants { - IntMin, - Zero, - IntMax, -} -impl TryFrom for EnumIntRangeS_Constants { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - -2147483648 => Ok(EnumIntRangeS_Constants::IntMin), - 0 => Ok(EnumIntRangeS_Constants::Zero), - 2147483647 => Ok(EnumIntRangeS_Constants::IntMax), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_int_range_u.rs b/spec/rust/src/formats/enum_int_range_u.rs deleted file mode 100644 index 05543f4cd..000000000 --- a/spec/rust/src/formats/enum_int_range_u.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumIntRangeU { - pub f1: Option, - pub f2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumIntRangeU { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.f1 = Some((_io.read_u4be()? as i64).try_into()?); - self.f2 = Some((_io.read_u4be()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumIntRangeU { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumIntRangeU::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumIntRangeU_Constants { - Zero, - IntMax, -} -impl TryFrom for EnumIntRangeU_Constants { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 0 => Ok(EnumIntRangeU_Constants::Zero), - 4294967295 => Ok(EnumIntRangeU_Constants::IntMax), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_invalid.rs b/spec/rust/src/formats/enum_invalid.rs deleted file mode 100644 index 11a6d0671..000000000 --- a/spec/rust/src/formats/enum_invalid.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumInvalid { - pub pet_1: Option, - pub pet_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumInvalid { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u1()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u1()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumInvalid { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumInvalid::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumInvalid_Animal { - Dog, - Cat, -} -impl TryFrom for EnumInvalid_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 102 => Ok(EnumInvalid_Animal::Dog), - 124 => Ok(EnumInvalid_Animal::Cat), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_long_range_s.rs b/spec/rust/src/formats/enum_long_range_s.rs deleted file mode 100644 index b80a9dff3..000000000 --- a/spec/rust/src/formats/enum_long_range_s.rs +++ /dev/null @@ -1,79 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumLongRangeS { - pub f1: Option, - pub f2: Option, - pub f3: Option, - pub f4: Option, - pub f5: Option, - pub f6: Option, - pub f7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumLongRangeS { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.f1 = Some((_io.read_s8be()? as i64).try_into()?); - self.f2 = Some((_io.read_s8be()? as i64).try_into()?); - self.f3 = Some((_io.read_s8be()? as i64).try_into()?); - self.f4 = Some((_io.read_s8be()? as i64).try_into()?); - self.f5 = Some((_io.read_s8be()? as i64).try_into()?); - self.f6 = Some((_io.read_s8be()? as i64).try_into()?); - self.f7 = Some((_io.read_s8be()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumLongRangeS { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumLongRangeS::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumLongRangeS_Constants { - LongMin, - IntBelowMin, - IntMin, - Zero, - IntMax, - IntOverMax, - LongMax, -} -impl TryFrom for EnumLongRangeS_Constants { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - -9223372036854775808 => Ok(EnumLongRangeS_Constants::LongMin), - -2147483649 => Ok(EnumLongRangeS_Constants::IntBelowMin), - -2147483648 => Ok(EnumLongRangeS_Constants::IntMin), - 0 => Ok(EnumLongRangeS_Constants::Zero), - 2147483647 => Ok(EnumLongRangeS_Constants::IntMax), - 2147483648 => Ok(EnumLongRangeS_Constants::IntOverMax), - 9223372036854775807 => Ok(EnumLongRangeS_Constants::LongMax), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_long_range_u.rs b/spec/rust/src/formats/enum_long_range_u.rs deleted file mode 100644 index fb974ee89..000000000 --- a/spec/rust/src/formats/enum_long_range_u.rs +++ /dev/null @@ -1,67 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumLongRangeU { - pub f1: Option, - pub f2: Option, - pub f3: Option, - pub f4: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumLongRangeU { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.f1 = Some((_io.read_u8be()? as i64).try_into()?); - self.f2 = Some((_io.read_u8be()? as i64).try_into()?); - self.f3 = Some((_io.read_u8be()? as i64).try_into()?); - self.f4 = Some((_io.read_u8be()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumLongRangeU { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumLongRangeU::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumLongRangeU_Constants { - Zero, - IntMax, - IntOverMax, - LongMax, -} -impl TryFrom for EnumLongRangeU_Constants { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 0 => Ok(EnumLongRangeU_Constants::Zero), - 4294967295 => Ok(EnumLongRangeU_Constants::IntMax), - 4294967296 => Ok(EnumLongRangeU_Constants::IntOverMax), - 9223372036854775807 => Ok(EnumLongRangeU_Constants::LongMax), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_negative.rs b/spec/rust/src/formats/enum_negative.rs deleted file mode 100644 index 59ceb25f9..000000000 --- a/spec/rust/src/formats/enum_negative.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumNegative { - pub f1: Option, - pub f2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumNegative { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.f1 = Some((_io.read_s1()? as i64).try_into()?); - self.f2 = Some((_io.read_s1()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumNegative { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumNegative::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum EnumNegative_Constants { - NegativeOne, - PositiveOne, -} -impl TryFrom for EnumNegative_Constants { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - -1 => Ok(EnumNegative_Constants::NegativeOne), - 1 => Ok(EnumNegative_Constants::PositiveOne), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_of_value_inst.rs b/spec/rust/src/formats/enum_of_value_inst.rs deleted file mode 100644 index db6bb488b..000000000 --- a/spec/rust/src/formats/enum_of_value_inst.rs +++ /dev/null @@ -1,87 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumOfValueInst { - pub pet_1: Option, - pub pet_2: Option, - pub pet_3: Option, - pub pet_4: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumOfValueInst { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumOfValueInst { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumOfValueInst::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn pet_3( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&EnumOfValueInst_Animal> { - if self.pet_3.is_some() { - return Ok(self.pet_3.as_ref().unwrap()); - } - self.pet_3 = Some(if self.pet_1 == EnumOfValueInst_Animal::Cat { 4 } else { 12} as i32); - return Ok(self.pet_3.as_ref().unwrap()); - } - fn pet_4( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&EnumOfValueInst_Animal> { - if self.pet_4.is_some() { - return Ok(self.pet_4.as_ref().unwrap()); - } - self.pet_4 = Some(if self.pet_1 == EnumOfValueInst_Animal::Cat { EnumOfValueInst_Animal::Dog } else { EnumOfValueInst_Animal::Chicken} as i32); - return Ok(self.pet_4.as_ref().unwrap()); - } -} -#[derive(Debug, PartialEq)] -pub enum EnumOfValueInst_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for EnumOfValueInst_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumOfValueInst_Animal::Dog), - 7 => Ok(EnumOfValueInst_Animal::Cat), - 12 => Ok(EnumOfValueInst_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_to_i.rs b/spec/rust/src/formats/enum_to_i.rs deleted file mode 100644 index 3ef671262..000000000 --- a/spec/rust/src/formats/enum_to_i.rs +++ /dev/null @@ -1,126 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumToI { - pub pet_1: Option, - pub pet_2: Option, - pub pet_1_i: Option, - pub pet_1_eq_int: Option, - pub one_lt_two: Option, - pub pet_1_mod: Option, - pub pet_2_eq_int: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumToI { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumToI { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumToI::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn pet_1_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.pet_1_i.is_some() { - return Ok(self.pet_1_i.as_ref().unwrap()); - } - self.pet_1_i = Some(self.pet_1 as i32); - return Ok(self.pet_1_i.as_ref().unwrap()); - } - fn pet_1_eq_int( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.pet_1_eq_int.is_some() { - return Ok(self.pet_1_eq_int.as_ref().unwrap()); - } - self.pet_1_eq_int = Some(self.pet_1 == 7 as bool); - return Ok(self.pet_1_eq_int.as_ref().unwrap()); - } - fn one_lt_two( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.one_lt_two.is_some() { - return Ok(self.one_lt_two.as_ref().unwrap()); - } - self.one_lt_two = Some(self.pet_1 < self.pet_2 as bool); - return Ok(self.one_lt_two.as_ref().unwrap()); - } - fn pet_1_mod( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.pet_1_mod.is_some() { - return Ok(self.pet_1_mod.as_ref().unwrap()); - } - self.pet_1_mod = Some((self.pet_1 + 32768) as i32); - return Ok(self.pet_1_mod.as_ref().unwrap()); - } - fn pet_2_eq_int( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.pet_2_eq_int.is_some() { - return Ok(self.pet_2_eq_int.as_ref().unwrap()); - } - self.pet_2_eq_int = Some(self.pet_2 == 5 as bool); - return Ok(self.pet_2_eq_int.as_ref().unwrap()); - } -} -#[derive(Debug, PartialEq)] -pub enum EnumToI_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for EnumToI_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumToI_Animal::Dog), - 7 => Ok(EnumToI_Animal::Cat), - 12 => Ok(EnumToI_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_to_i_class_border_1.rs b/spec/rust/src/formats/enum_to_i_class_border_1.rs deleted file mode 100644 index 1b58aa590..000000000 --- a/spec/rust/src/formats/enum_to_i_class_border_1.rs +++ /dev/null @@ -1,90 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::enum_to_i_class_border_2::EnumToIClassBorder2; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumToIClassBorder1 { - pub pet_1: Option, - pub pet_2: Option, - pub some_dog: Option, - pub checker: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumToIClassBorder1 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pet_1 = Some((_io.read_u4le()? as i64).try_into()?); - self.pet_2 = Some((_io.read_u4le()? as i64).try_into()?); - Ok(()) - } -} -impl<'r, 's: 'r> EnumToIClassBorder1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumToIClassBorder1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn some_dog( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&EnumToIClassBorder1_Animal> { - if self.some_dog.is_some() { - return Ok(self.some_dog.as_ref().unwrap()); - } - self.some_dog = Some(4 as i32); - return Ok(self.some_dog.as_ref().unwrap()); - } - fn checker( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Box> { - if self.checker.is_some() { - return Ok(self.checker.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(0)) - // popPos(_io) - return Ok(self.checker.as_ref().unwrap()); - } -} -#[derive(Debug, PartialEq)] -pub enum EnumToIClassBorder1_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for EnumToIClassBorder1_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(EnumToIClassBorder1_Animal::Dog), - 7 => Ok(EnumToIClassBorder1_Animal::Cat), - 12 => Ok(EnumToIClassBorder1_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/enum_to_i_class_border_2.rs b/spec/rust/src/formats/enum_to_i_class_border_2.rs deleted file mode 100644 index e387c1062..000000000 --- a/spec/rust/src/formats/enum_to_i_class_border_2.rs +++ /dev/null @@ -1,54 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::enum_to_i_class_border_1::EnumToIClassBorder1; - -#[derive(Default, Debug, PartialEq)] -pub struct EnumToIClassBorder2 { - pub parent: Option>, - pub is_dog: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EnumToIClassBorder2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> EnumToIClassBorder2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EnumToIClassBorder2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn is_dog( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_dog.is_some() { - return Ok(self.is_dog.as_ref().unwrap()); - } - self.is_dog = Some(self.parent.some_dog == 4 as bool); - return Ok(self.is_dog.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/eof_exception_bytes.rs b/spec/rust/src/formats/eof_exception_bytes.rs deleted file mode 100644 index 5ee1eb47f..000000000 --- a/spec/rust/src/formats/eof_exception_bytes.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EofExceptionBytes { - pub buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EofExceptionBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf = _io.read_bytes(13 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> EofExceptionBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EofExceptionBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/eof_exception_u4.rs b/spec/rust/src/formats/eof_exception_u4.rs deleted file mode 100644 index 9187e9fcb..000000000 --- a/spec/rust/src/formats/eof_exception_u4.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct EofExceptionU4 { - pub prebuf: Vec, - pub fail_int: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EofExceptionU4 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.prebuf = _io.read_bytes(9 as usize)?.to_vec(); - self.fail_int = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> EofExceptionU4 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EofExceptionU4::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/eos_exception_bytes.rs b/spec/rust/src/formats/eos_exception_bytes.rs deleted file mode 100644 index 8a3327ee8..000000000 --- a/spec/rust/src/formats/eos_exception_bytes.rs +++ /dev/null @@ -1,76 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(envelope)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct EosExceptionBytes { - pub envelope: Option, - pub raw_envelope: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.envelope = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(6 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> EosExceptionBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EosExceptionBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct EosExceptionBytes_Data { - pub buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionBytes_Data { - type Root = EosExceptionBytes; - type ParentStack = (&'r EosExceptionBytes, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf = _io.read_bytes(7 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> EosExceptionBytes_Data { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EosExceptionBytes_Data::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/eos_exception_u4.rs b/spec/rust/src/formats/eos_exception_u4.rs deleted file mode 100644 index 6c4ad0bb8..000000000 --- a/spec/rust/src/formats/eos_exception_u4.rs +++ /dev/null @@ -1,78 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(envelope)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct EosExceptionU4 { - pub envelope: Option, - pub raw_envelope: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionU4 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.envelope = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(6 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> EosExceptionU4 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EosExceptionU4::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct EosExceptionU4_Data { - pub prebuf: Vec, - pub fail_int: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for EosExceptionU4_Data { - type Root = EosExceptionU4; - type ParentStack = (&'r EosExceptionU4, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.prebuf = _io.read_bytes(3 as usize)?.to_vec(); - self.fail_int = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> EosExceptionU4_Data { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = EosExceptionU4_Data::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/expr_0.rs b/spec/rust/src/formats/expr_0.rs deleted file mode 100644 index 67be5b38e..000000000 --- a/spec/rust/src/formats/expr_0.rs +++ /dev/null @@ -1,67 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Expr0 { - pub len_of_1: u16, - pub must_be_f7: Option, - pub must_be_abc123: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Expr0 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_of_1 = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> Expr0 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Expr0::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn must_be_f7( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.must_be_f7.is_some() { - return Ok(self.must_be_f7.as_ref().unwrap()); - } - self.must_be_f7 = Some((7 + 240) as i32); - return Ok(self.must_be_f7.as_ref().unwrap()); - } - fn must_be_abc123( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.must_be_abc123.is_some() { - return Ok(self.must_be_abc123.as_ref().unwrap()); - } - self.must_be_abc123 = Some(format!("{}{}", "abc", "123").to_string()); - return Ok(self.must_be_abc123.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_1.rs b/spec/rust/src/formats/expr_1.rs deleted file mode 100644 index e677a7851..000000000 --- a/spec/rust/src/formats/expr_1.rs +++ /dev/null @@ -1,69 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Expr1 { - pub len_of_1: u16, - pub str1: String, - pub len_of_1_mod: Option, - pub str1_len: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Expr1 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_of_1 = _io.read_u2le()?; - self.str1 = decode_string(_io.read_bytes(self.len_of_1_mod(_io, _root, _parent)? as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> Expr1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Expr1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn len_of_1_mod( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.len_of_1_mod.is_some() { - return Ok(self.len_of_1_mod.as_ref().unwrap()); - } - self.len_of_1_mod = Some((self.len_of_1 - 2) as i32); - return Ok(self.len_of_1_mod.as_ref().unwrap()); - } - fn str1_len( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.str1_len.is_some() { - return Ok(self.str1_len.as_ref().unwrap()); - } - self.str1_len = Some(self.str1.len() as i32); - return Ok(self.str1_len.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_2.rs b/spec/rust/src/formats/expr_2.rs deleted file mode 100644 index 4db30fe40..000000000 --- a/spec/rust/src/formats/expr_2.rs +++ /dev/null @@ -1,266 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Expr2 { - pub str1: Option, - pub str2: Option, - pub str1_len_mod: Option, - pub str1_len: Option, - pub str1_tuple5: Option, - pub str2_tuple5: Option, - pub str1_avg: Option, - pub str1_byte1: Option, - pub str1_char5: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Expr2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.str1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.str2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> Expr2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Expr2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn str1_len_mod( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.str1_len_mod.is_some() { - return Ok(self.str1_len_mod.as_ref().unwrap()); - } - self.str1_len_mod = Some(self.str1.len_mod as i32); - return Ok(self.str1_len_mod.as_ref().unwrap()); - } - fn str1_len( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.str1_len.is_some() { - return Ok(self.str1_len.as_ref().unwrap()); - } - self.str1_len = Some(self.str1.str.len() as i32); - return Ok(self.str1_len.as_ref().unwrap()); - } - fn str1_tuple5( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Expr2_Tuple> { - if self.str1_tuple5.is_some() { - return Ok(self.str1_tuple5.as_ref().unwrap()); - } - self.str1_tuple5 = Some(self.str1.tuple5 as Tuple); - return Ok(self.str1_tuple5.as_ref().unwrap()); - } - fn str2_tuple5( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Expr2_Tuple> { - if self.str2_tuple5.is_some() { - return Ok(self.str2_tuple5.as_ref().unwrap()); - } - self.str2_tuple5 = Some(self.str2.tuple5 as Tuple); - return Ok(self.str2_tuple5.as_ref().unwrap()); - } - fn str1_avg( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.str1_avg.is_some() { - return Ok(self.str1_avg.as_ref().unwrap()); - } - self.str1_avg = Some(self.str1.rest.avg as i32); - return Ok(self.str1_avg.as_ref().unwrap()); - } - fn str1_byte1( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.str1_byte1.is_some() { - return Ok(self.str1_byte1.as_ref().unwrap()); - } - self.str1_byte1 = Some(self.str1.rest.byte1 as u8); - return Ok(self.str1_byte1.as_ref().unwrap()); - } - fn str1_char5( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.str1_char5.is_some() { - return Ok(self.str1_char5.as_ref().unwrap()); - } - self.str1_char5 = Some(self.str1.char5.to_string()); - return Ok(self.str1_char5.as_ref().unwrap()); - } -} -// extraAttrForIO(RawIdentifier(NamedIdentifier(rest)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct Expr2_ModStr { - pub len_orig: u16, - pub str: String, - pub rest: Option, - pub raw_rest: Vec, - pub len_mod: Option, - pub char5: Option, - pub tuple5: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Expr2_ModStr { - type Root = Expr2; - type ParentStack = (&'r Expr2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_orig = _io.read_u2le()?; - self.str = decode_string(_io.read_bytes(self.len_mod(_io, _root, _parent)? as usize)?, "UTF-8")?; - self.rest = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(3 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> Expr2_ModStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Expr2_ModStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn len_mod( - &mut self, - _io: &'s S, - _root: Option<&'r Expr2>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.len_mod.is_some() { - return Ok(self.len_mod.as_ref().unwrap()); - } - self.len_mod = Some((self.len_orig - 3) as i32); - return Ok(self.len_mod.as_ref().unwrap()); - } - fn char5( - &mut self, - _io: &'s S, - _root: Option<&'r Expr2>, - _parent: Option>::ParentStack)>> - ) -> KResult<&String> { - if self.char5.is_some() { - return Ok(self.char5.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(5)) - // popPos(_io) - return Ok(self.char5.as_ref().unwrap()); - } - fn tuple5( - &mut self, - _io: &'s S, - _root: Option<&'r Expr2>, - _parent: Option>::ParentStack)>> - ) -> KResult<&Expr2_Tuple> { - if self.tuple5.is_some() { - return Ok(self.tuple5.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(5)) - // popPos(_io) - return Ok(self.tuple5.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct Expr2_Tuple { - pub byte0: u8, - pub byte1: u8, - pub byte2: u8, - pub avg: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Expr2_Tuple { - type Root = Expr2; - type ParentStack = (&'r Expr2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.byte0 = _io.read_u1()?; - self.byte1 = _io.read_u1()?; - self.byte2 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> Expr2_Tuple { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Expr2_Tuple::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn avg( - &mut self, - _io: &'s S, - _root: Option<&'r Expr2>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.avg.is_some() { - return Ok(self.avg.as_ref().unwrap()); - } - self.avg = Some((self.byte1 + self.byte2) / 2 as i32); - return Ok(self.avg.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_3.rs b/spec/rust/src/formats/expr_3.rs deleted file mode 100644 index 3d7ca8235..000000000 --- a/spec/rust/src/formats/expr_3.rs +++ /dev/null @@ -1,173 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Expr3 { - pub one: u8, - pub two: String, - pub three: Option, - pub is_str_ge: Option, - pub is_str_ne: Option, - pub is_str_gt: Option, - pub is_str_le: Option, - pub is_str_lt2: Option, - pub test_not: Option, - pub is_str_lt: Option, - pub four: Option, - pub is_str_eq: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Expr3 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - self.two = decode_string(_io.read_bytes(3 as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> Expr3 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Expr3::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn three( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.three.is_some() { - return Ok(self.three.as_ref().unwrap()); - } - self.three = Some(format!("{}{}", "@", self.two).to_string()); - return Ok(self.three.as_ref().unwrap()); - } - fn is_str_ge( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_str_ge.is_some() { - return Ok(self.is_str_ge.as_ref().unwrap()); - } - self.is_str_ge = Some(self.two >= "ACK2" as bool); - return Ok(self.is_str_ge.as_ref().unwrap()); - } - fn is_str_ne( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_str_ne.is_some() { - return Ok(self.is_str_ne.as_ref().unwrap()); - } - self.is_str_ne = Some(self.two != "ACK" as bool); - return Ok(self.is_str_ne.as_ref().unwrap()); - } - fn is_str_gt( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_str_gt.is_some() { - return Ok(self.is_str_gt.as_ref().unwrap()); - } - self.is_str_gt = Some(self.two > "ACK2" as bool); - return Ok(self.is_str_gt.as_ref().unwrap()); - } - fn is_str_le( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_str_le.is_some() { - return Ok(self.is_str_le.as_ref().unwrap()); - } - self.is_str_le = Some(self.two <= "ACK2" as bool); - return Ok(self.is_str_le.as_ref().unwrap()); - } - fn is_str_lt2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_str_lt2.is_some() { - return Ok(self.is_str_lt2.as_ref().unwrap()); - } - self.is_str_lt2 = Some(self.three(_io, _root, _parent)? < self.two as bool); - return Ok(self.is_str_lt2.as_ref().unwrap()); - } - fn test_not( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.test_not.is_some() { - return Ok(self.test_not.as_ref().unwrap()); - } - self.test_not = Some(!(false) as bool); - return Ok(self.test_not.as_ref().unwrap()); - } - fn is_str_lt( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_str_lt.is_some() { - return Ok(self.is_str_lt.as_ref().unwrap()); - } - self.is_str_lt = Some(self.two < "ACK2" as bool); - return Ok(self.is_str_lt.as_ref().unwrap()); - } - fn four( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.four.is_some() { - return Ok(self.four.as_ref().unwrap()); - } - self.four = Some(format!("{}{}", format!("{}{}", "_", self.two), "_").to_string()); - return Ok(self.four.as_ref().unwrap()); - } - fn is_str_eq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_str_eq.is_some() { - return Ok(self.is_str_eq.as_ref().unwrap()); - } - self.is_str_eq = Some(self.two == "ACK" as bool); - return Ok(self.is_str_eq.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_array.rs b/spec/rust/src/formats/expr_array.rs deleted file mode 100644 index 7adc4b643..000000000 --- a/spec/rust/src/formats/expr_array.rs +++ /dev/null @@ -1,252 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprArray { - pub aint: Vec, - pub afloat: Vec, - pub astr: Vec, - pub aint_first: Option, - pub afloat_size: Option, - pub astr_size: Option, - pub aint_min: Option, - pub afloat_min: Option, - pub aint_size: Option, - pub aint_last: Option, - pub afloat_last: Option, - pub astr_first: Option, - pub astr_last: Option, - pub aint_max: Option, - pub afloat_first: Option, - pub astr_min: Option, - pub astr_max: Option, - pub afloat_max: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprArray { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.aint = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(aint), _io, IntMultiType(false,Width4,Some(LittleEndian)), IntNum(4)) - // handleAssignmentRepeatExpr(NamedIdentifier(aint), _io.read_u4le()?) - } - self.afloat = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(afloat), _io, FloatMultiType(Width8,Some(LittleEndian)), IntNum(3)) - // handleAssignmentRepeatExpr(NamedIdentifier(afloat), _io.read_f8le()?) - } - self.astr = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(astr), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), IntNum(3)) - // handleAssignmentRepeatExpr(NamedIdentifier(astr), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) - } - Ok(()) - } -} -impl<'r, 's: 'r> ExprArray { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprArray::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn aint_first( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u32> { - if self.aint_first.is_some() { - return Ok(self.aint_first.as_ref().unwrap()); - } - self.aint_first = Some(self.aint.first() as u32); - return Ok(self.aint_first.as_ref().unwrap()); - } - fn afloat_size( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.afloat_size.is_some() { - return Ok(self.afloat_size.as_ref().unwrap()); - } - self.afloat_size = Some(self.afloat.len() as i32); - return Ok(self.afloat_size.as_ref().unwrap()); - } - fn astr_size( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.astr_size.is_some() { - return Ok(self.astr_size.as_ref().unwrap()); - } - self.astr_size = Some(self.astr.len() as i32); - return Ok(self.astr_size.as_ref().unwrap()); - } - fn aint_min( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u32> { - if self.aint_min.is_some() { - return Ok(self.aint_min.as_ref().unwrap()); - } - self.aint_min = Some(self.aint.iter().min() as u32); - return Ok(self.aint_min.as_ref().unwrap()); - } - fn afloat_min( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.afloat_min.is_some() { - return Ok(self.afloat_min.as_ref().unwrap()); - } - self.afloat_min = Some(self.afloat.iter().min() as f64); - return Ok(self.afloat_min.as_ref().unwrap()); - } - fn aint_size( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.aint_size.is_some() { - return Ok(self.aint_size.as_ref().unwrap()); - } - self.aint_size = Some(self.aint.len() as i32); - return Ok(self.aint_size.as_ref().unwrap()); - } - fn aint_last( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u32> { - if self.aint_last.is_some() { - return Ok(self.aint_last.as_ref().unwrap()); - } - self.aint_last = Some(self.aint.last() as u32); - return Ok(self.aint_last.as_ref().unwrap()); - } - fn afloat_last( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.afloat_last.is_some() { - return Ok(self.afloat_last.as_ref().unwrap()); - } - self.afloat_last = Some(self.afloat.last() as f64); - return Ok(self.afloat_last.as_ref().unwrap()); - } - fn astr_first( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.astr_first.is_some() { - return Ok(self.astr_first.as_ref().unwrap()); - } - self.astr_first = Some(self.astr.first().to_string()); - return Ok(self.astr_first.as_ref().unwrap()); - } - fn astr_last( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.astr_last.is_some() { - return Ok(self.astr_last.as_ref().unwrap()); - } - self.astr_last = Some(self.astr.last().to_string()); - return Ok(self.astr_last.as_ref().unwrap()); - } - fn aint_max( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u32> { - if self.aint_max.is_some() { - return Ok(self.aint_max.as_ref().unwrap()); - } - self.aint_max = Some(self.aint.iter().max() as u32); - return Ok(self.aint_max.as_ref().unwrap()); - } - fn afloat_first( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.afloat_first.is_some() { - return Ok(self.afloat_first.as_ref().unwrap()); - } - self.afloat_first = Some(self.afloat.first() as f64); - return Ok(self.afloat_first.as_ref().unwrap()); - } - fn astr_min( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.astr_min.is_some() { - return Ok(self.astr_min.as_ref().unwrap()); - } - self.astr_min = Some(self.astr.iter().min().to_string()); - return Ok(self.astr_min.as_ref().unwrap()); - } - fn astr_max( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.astr_max.is_some() { - return Ok(self.astr_max.as_ref().unwrap()); - } - self.astr_max = Some(self.astr.iter().max().to_string()); - return Ok(self.astr_max.as_ref().unwrap()); - } - fn afloat_max( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.afloat_max.is_some() { - return Ok(self.afloat_max.as_ref().unwrap()); - } - self.afloat_max = Some(self.afloat.iter().max() as f64); - return Ok(self.afloat_max.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_bits.rs b/spec/rust/src/formats/expr_bits.rs deleted file mode 100644 index cd20bd91e..000000000 --- a/spec/rust/src/formats/expr_bits.rs +++ /dev/null @@ -1,148 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprBits { - pub enum_seq: Option, - pub a: u64, - pub byte_size: Vec, - pub repeat_expr: Vec, - pub switch_on_type: Option, - pub switch_on_endian: Option, - pub enum_inst: Option, - pub inst_pos: Option, -} -#[derive(Debug, PartialEq)] -pub enum ExprBits_SwitchOnType { - S1(i8), -} -impl From for ExprBits_SwitchOnType { - fn from(v: i8) -> Self { - Self::S1(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for ExprBits { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.enum_seq = Some((_io.read_bits_int(2)? as i64).try_into()?); - self.a = _io.read_bits_int(3)?; - _io.align_to_byte()?; - self.byte_size = _io.read_bytes(self.a as usize)?.to_vec(); - self.repeat_expr = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(repeat_expr), _io, Int1Type(true), Name(identifier(a))) - // handleAssignmentRepeatExpr(NamedIdentifier(repeat_expr), _io.read_s1()?) - } - match self.a { - 2 => { - self.switch_on_type = Some(_io.read_s1()?); - } - _ => panic!("unhandled value") - } - self.switch_on_endian = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ExprBits { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprBits::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn enum_inst( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&ExprBits_Items> { - if self.enum_inst.is_some() { - return Ok(self.enum_inst.as_ref().unwrap()); - } - self.enum_inst = Some(self.a as i32); - return Ok(self.enum_inst.as_ref().unwrap()); - } - fn inst_pos( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i8> { - if self.inst_pos.is_some() { - return Ok(self.inst_pos.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, Name(identifier(a))) - // popPos(_io) - return Ok(self.inst_pos.as_ref().unwrap()); - } -} -#[derive(Debug, PartialEq)] -pub enum ExprBits_Items { - Foo, - Bar, -} -impl TryFrom for ExprBits_Items { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 1 => Ok(ExprBits_Items::Foo), - 2 => Ok(ExprBits_Items::Bar), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct ExprBits_EndianSwitch { - pub foo: i16, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprBits_EndianSwitch { - type Root = ExprBits; - type ParentStack = (&'r ExprBits, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = panic!("Unable to parse unknown-endian integers"); - Ok(()) - } -} -impl<'r, 's: 'r> ExprBits_EndianSwitch { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprBits_EndianSwitch::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/expr_bytes_cmp.rs b/spec/rust/src/formats/expr_bytes_cmp.rs deleted file mode 100644 index aa4ba5590..000000000 --- a/spec/rust/src/formats/expr_bytes_cmp.rs +++ /dev/null @@ -1,186 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprBytesCmp { - pub one: Vec, - pub two: Vec, - pub is_le: Option, - pub ack: Option>, - pub is_gt2: Option, - pub is_gt: Option, - pub ack2: Option>, - pub is_eq: Option, - pub is_lt2: Option, - pub is_ge: Option, - pub hi_val: Option>, - pub is_ne: Option, - pub is_lt: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprBytesCmp { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_bytes(1 as usize)?.to_vec(); - self.two = _io.read_bytes(3 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ExprBytesCmp { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprBytesCmp::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn is_le( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_le.is_some() { - return Ok(self.is_le.as_ref().unwrap()); - } - self.is_le = Some(self.two <= self.ack2(_io, _root, _parent)? as bool); - return Ok(self.is_le.as_ref().unwrap()); - } - fn ack( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.ack.is_some() { - return Ok(self.ack.as_ref().unwrap()); - } - self.ack = Some(&[0x41, 0x43, 0x4b] as Vec); - return Ok(self.ack.as_ref().unwrap()); - } - fn is_gt2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_gt2.is_some() { - return Ok(self.is_gt2.as_ref().unwrap()); - } - self.is_gt2 = Some(self.hi_val(_io, _root, _parent)? > self.two as bool); - return Ok(self.is_gt2.as_ref().unwrap()); - } - fn is_gt( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_gt.is_some() { - return Ok(self.is_gt.as_ref().unwrap()); - } - self.is_gt = Some(self.two > self.ack2(_io, _root, _parent)? as bool); - return Ok(self.is_gt.as_ref().unwrap()); - } - fn ack2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.ack2.is_some() { - return Ok(self.ack2.as_ref().unwrap()); - } - self.ack2 = Some(&[0x41, 0x43, 0x4b, 0x32] as Vec); - return Ok(self.ack2.as_ref().unwrap()); - } - fn is_eq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_eq.is_some() { - return Ok(self.is_eq.as_ref().unwrap()); - } - self.is_eq = Some(self.two == self.ack(_io, _root, _parent)? as bool); - return Ok(self.is_eq.as_ref().unwrap()); - } - fn is_lt2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_lt2.is_some() { - return Ok(self.is_lt2.as_ref().unwrap()); - } - self.is_lt2 = Some(self.one < self.two as bool); - return Ok(self.is_lt2.as_ref().unwrap()); - } - fn is_ge( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_ge.is_some() { - return Ok(self.is_ge.as_ref().unwrap()); - } - self.is_ge = Some(self.two >= self.ack2(_io, _root, _parent)? as bool); - return Ok(self.is_ge.as_ref().unwrap()); - } - fn hi_val( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.hi_val.is_some() { - return Ok(self.hi_val.as_ref().unwrap()); - } - self.hi_val = Some(&[0x90, 0x43] as Vec); - return Ok(self.hi_val.as_ref().unwrap()); - } - fn is_ne( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_ne.is_some() { - return Ok(self.is_ne.as_ref().unwrap()); - } - self.is_ne = Some(self.two != self.ack(_io, _root, _parent)? as bool); - return Ok(self.is_ne.as_ref().unwrap()); - } - fn is_lt( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_lt.is_some() { - return Ok(self.is_lt.as_ref().unwrap()); - } - self.is_lt = Some(self.two < self.ack2(_io, _root, _parent)? as bool); - return Ok(self.is_lt.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_bytes_non_literal.rs b/spec/rust/src/formats/expr_bytes_non_literal.rs deleted file mode 100644 index 55d1a1c27..000000000 --- a/spec/rust/src/formats/expr_bytes_non_literal.rs +++ /dev/null @@ -1,56 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprBytesNonLiteral { - pub one: u8, - pub two: u8, - pub calc_bytes: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprBytesNonLiteral { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - self.two = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprBytesNonLiteral { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprBytesNonLiteral::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn calc_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.calc_bytes.is_some() { - return Ok(self.calc_bytes.as_ref().unwrap()); - } - self.calc_bytes = Some(pack('C*', self.one, self.two) as Vec); - return Ok(self.calc_bytes.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_bytes_ops.rs b/spec/rust/src/formats/expr_bytes_ops.rs deleted file mode 100644 index 2c9097a81..000000000 --- a/spec/rust/src/formats/expr_bytes_ops.rs +++ /dev/null @@ -1,210 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprBytesOps { - pub one: Vec, - pub two_last: Option, - pub two_max: Option, - pub one_min: Option, - pub one_first: Option, - pub one_mid: Option, - pub two: Option>, - pub two_min: Option, - pub two_mid: Option, - pub one_size: Option, - pub one_last: Option, - pub two_size: Option, - pub one_max: Option, - pub two_first: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprBytesOps { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_bytes(3 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ExprBytesOps { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprBytesOps::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn two_last( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.two_last.is_some() { - return Ok(self.two_last.as_ref().unwrap()); - } - self.two_last = Some(self.two(_io, _root, _parent)?.last() as u8); - return Ok(self.two_last.as_ref().unwrap()); - } - fn two_max( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.two_max.is_some() { - return Ok(self.two_max.as_ref().unwrap()); - } - self.two_max = Some(self.two(_io, _root, _parent)?.iter().max() as u8); - return Ok(self.two_max.as_ref().unwrap()); - } - fn one_min( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.one_min.is_some() { - return Ok(self.one_min.as_ref().unwrap()); - } - self.one_min = Some(self.one.iter().min() as u8); - return Ok(self.one_min.as_ref().unwrap()); - } - fn one_first( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.one_first.is_some() { - return Ok(self.one_first.as_ref().unwrap()); - } - self.one_first = Some(self.one.first() as u8); - return Ok(self.one_first.as_ref().unwrap()); - } - fn one_mid( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.one_mid.is_some() { - return Ok(self.one_mid.as_ref().unwrap()); - } - self.one_mid = Some(self.one[1 as usize] as u8); - return Ok(self.one_mid.as_ref().unwrap()); - } - fn two( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.two.is_some() { - return Ok(self.two.as_ref().unwrap()); - } - self.two = Some(&[0x41, 0xff, 0x4b] as Vec); - return Ok(self.two.as_ref().unwrap()); - } - fn two_min( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.two_min.is_some() { - return Ok(self.two_min.as_ref().unwrap()); - } - self.two_min = Some(self.two(_io, _root, _parent)?.iter().min() as u8); - return Ok(self.two_min.as_ref().unwrap()); - } - fn two_mid( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.two_mid.is_some() { - return Ok(self.two_mid.as_ref().unwrap()); - } - self.two_mid = Some(self.two(_io, _root, _parent)?[1 as usize] as u8); - return Ok(self.two_mid.as_ref().unwrap()); - } - fn one_size( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.one_size.is_some() { - return Ok(self.one_size.as_ref().unwrap()); - } - self.one_size = Some(self.one.len() as i32); - return Ok(self.one_size.as_ref().unwrap()); - } - fn one_last( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.one_last.is_some() { - return Ok(self.one_last.as_ref().unwrap()); - } - self.one_last = Some(self.one.last() as u8); - return Ok(self.one_last.as_ref().unwrap()); - } - fn two_size( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.two_size.is_some() { - return Ok(self.two_size.as_ref().unwrap()); - } - self.two_size = Some(self.two(_io, _root, _parent)?.len() as i32); - return Ok(self.two_size.as_ref().unwrap()); - } - fn one_max( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.one_max.is_some() { - return Ok(self.one_max.as_ref().unwrap()); - } - self.one_max = Some(self.one.iter().max() as u8); - return Ok(self.one_max.as_ref().unwrap()); - } - fn two_first( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.two_first.is_some() { - return Ok(self.two_first.as_ref().unwrap()); - } - self.two_first = Some(self.two(_io, _root, _parent)?.first() as u8); - return Ok(self.two_first.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_enum.rs b/spec/rust/src/formats/expr_enum.rs deleted file mode 100644 index af01c066b..000000000 --- a/spec/rust/src/formats/expr_enum.rs +++ /dev/null @@ -1,100 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprEnum { - pub one: u8, - pub const_dog: Option, - pub derived_boom: Option, - pub derived_dog: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprEnum { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprEnum { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprEnum::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn const_dog( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&ExprEnum_Animal> { - if self.const_dog.is_some() { - return Ok(self.const_dog.as_ref().unwrap()); - } - self.const_dog = Some(4 as i32); - return Ok(self.const_dog.as_ref().unwrap()); - } - fn derived_boom( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&ExprEnum_Animal> { - if self.derived_boom.is_some() { - return Ok(self.derived_boom.as_ref().unwrap()); - } - self.derived_boom = Some(self.one as i32); - return Ok(self.derived_boom.as_ref().unwrap()); - } - fn derived_dog( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&ExprEnum_Animal> { - if self.derived_dog.is_some() { - return Ok(self.derived_dog.as_ref().unwrap()); - } - self.derived_dog = Some((self.one - 98) as i32); - return Ok(self.derived_dog.as_ref().unwrap()); - } -} -#[derive(Debug, PartialEq)] -pub enum ExprEnum_Animal { - Dog, - Cat, - Chicken, - Boom, -} -impl TryFrom for ExprEnum_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(ExprEnum_Animal::Dog), - 7 => Ok(ExprEnum_Animal::Cat), - 12 => Ok(ExprEnum_Animal::Chicken), - 102 => Ok(ExprEnum_Animal::Boom), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/expr_if_int_ops.rs b/spec/rust/src/formats/expr_if_int_ops.rs deleted file mode 100644 index 5ba1dbb37..000000000 --- a/spec/rust/src/formats/expr_if_int_ops.rs +++ /dev/null @@ -1,77 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprIfIntOps { - pub skip: Vec, - pub it: i16, - pub boxed: i16, - pub is_eq_prim: Option, - pub is_eq_boxed: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprIfIntOps { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.skip = _io.read_bytes(2 as usize)?.to_vec(); - { - // condIfHeader(Bool(true)) - self.it = _io.read_s2le()?; - } - { - // condIfHeader(Bool(true)) - self.boxed = _io.read_s2le()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> ExprIfIntOps { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprIfIntOps::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn is_eq_prim( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_eq_prim.is_some() { - return Ok(self.is_eq_prim.as_ref().unwrap()); - } - self.is_eq_prim = Some(self.it == 16705 as bool); - return Ok(self.is_eq_prim.as_ref().unwrap()); - } - fn is_eq_boxed( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_eq_boxed.is_some() { - return Ok(self.is_eq_boxed.as_ref().unwrap()); - } - self.is_eq_boxed = Some(self.it == self.boxed as bool); - return Ok(self.is_eq_boxed.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_int_div.rs b/spec/rust/src/formats/expr_int_div.rs deleted file mode 100644 index d9b02226d..000000000 --- a/spec/rust/src/formats/expr_int_div.rs +++ /dev/null @@ -1,95 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprIntDiv { - pub int_u: u32, - pub int_s: i32, - pub div_pos_const: Option, - pub div_neg_const: Option, - pub div_pos_seq: Option, - pub div_neg_seq: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprIntDiv { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.int_u = _io.read_u4le()?; - self.int_s = _io.read_s4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprIntDiv { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprIntDiv::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn div_pos_const( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.div_pos_const.is_some() { - return Ok(self.div_pos_const.as_ref().unwrap()); - } - self.div_pos_const = Some(9837 / 13 as i32); - return Ok(self.div_pos_const.as_ref().unwrap()); - } - fn div_neg_const( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.div_neg_const.is_some() { - return Ok(self.div_neg_const.as_ref().unwrap()); - } - self.div_neg_const = Some(-9837 / 13 as i32); - return Ok(self.div_neg_const.as_ref().unwrap()); - } - fn div_pos_seq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.div_pos_seq.is_some() { - return Ok(self.div_pos_seq.as_ref().unwrap()); - } - self.div_pos_seq = Some(self.int_u / 13 as i32); - return Ok(self.div_pos_seq.as_ref().unwrap()); - } - fn div_neg_seq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.div_neg_seq.is_some() { - return Ok(self.div_neg_seq.as_ref().unwrap()); - } - self.div_neg_seq = Some(self.int_s / 13 as i32); - return Ok(self.div_neg_seq.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_io_eof.rs b/spec/rust/src/formats/expr_io_eof.rs deleted file mode 100644 index 53d6865b5..000000000 --- a/spec/rust/src/formats/expr_io_eof.rs +++ /dev/null @@ -1,98 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(substream1)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(substream2)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ExprIoEof { - pub substream1: Option, - pub substream2: Option, - pub raw_substream1: Vec, - pub raw_substream2: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoEof { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.substream1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - self.substream2 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(8 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ExprIoEof { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprIoEof::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ExprIoEof_OneOrTwo { - pub one: u32, - pub two: u32, - pub reflect_eof: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoEof_OneOrTwo { - type Root = ExprIoEof; - type ParentStack = (&'r ExprIoEof, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u4le()?; - { - // condIfHeader(UnaryOp(Not,Attribute(Name(identifier(_io)),identifier(eof)))) - self.two = _io.read_u4le()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> ExprIoEof_OneOrTwo { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprIoEof_OneOrTwo::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn reflect_eof( - &mut self, - _io: &'s S, - _root: Option<&'r ExprIoEof>, - _parent: Option>::ParentStack)>> - ) -> KResult<&bool> { - if self.reflect_eof.is_some() { - return Ok(self.reflect_eof.as_ref().unwrap()); - } - self.reflect_eof = Some(_io.is_eof as bool); - return Ok(self.reflect_eof.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_io_pos.rs b/spec/rust/src/formats/expr_io_pos.rs deleted file mode 100644 index a84957b58..000000000 --- a/spec/rust/src/formats/expr_io_pos.rs +++ /dev/null @@ -1,84 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(substream1)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(substream2)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ExprIoPos { - pub substream1: Option, - pub substream2: Option, - pub raw_substream1: Vec, - pub raw_substream2: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoPos { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.substream1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(16 as usize)?), Some(self), _parent.push(self))?); - self.substream2 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(14 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ExprIoPos { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprIoPos::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ExprIoPos_AllPlusNumber { - pub my_str: String, - pub body: Vec, - pub number: u16, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprIoPos_AllPlusNumber { - type Root = ExprIoPos; - type ParentStack = (&'r ExprIoPos, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.my_str = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; - self.body = _io.read_bytes(((_io.size - _io.pos) - 2) as usize)?.to_vec(); - self.number = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprIoPos_AllPlusNumber { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprIoPos_AllPlusNumber::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/expr_mod.rs b/spec/rust/src/formats/expr_mod.rs deleted file mode 100644 index 74139b6c5..000000000 --- a/spec/rust/src/formats/expr_mod.rs +++ /dev/null @@ -1,95 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprMod { - pub int_u: u32, - pub int_s: i32, - pub mod_pos_const: Option, - pub mod_neg_const: Option, - pub mod_pos_seq: Option, - pub mod_neg_seq: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprMod { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.int_u = _io.read_u4le()?; - self.int_s = _io.read_s4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprMod { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprMod::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn mod_pos_const( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.mod_pos_const.is_some() { - return Ok(self.mod_pos_const.as_ref().unwrap()); - } - self.mod_pos_const = Some(9837 % 13 as i32); - return Ok(self.mod_pos_const.as_ref().unwrap()); - } - fn mod_neg_const( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.mod_neg_const.is_some() { - return Ok(self.mod_neg_const.as_ref().unwrap()); - } - self.mod_neg_const = Some(-9837 % 13 as i32); - return Ok(self.mod_neg_const.as_ref().unwrap()); - } - fn mod_pos_seq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.mod_pos_seq.is_some() { - return Ok(self.mod_pos_seq.as_ref().unwrap()); - } - self.mod_pos_seq = Some(self.int_u % 13 as i32); - return Ok(self.mod_pos_seq.as_ref().unwrap()); - } - fn mod_neg_seq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.mod_neg_seq.is_some() { - return Ok(self.mod_neg_seq.as_ref().unwrap()); - } - self.mod_neg_seq = Some(self.int_s % 13 as i32); - return Ok(self.mod_neg_seq.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_ops_parens.rs b/spec/rust/src/formats/expr_ops_parens.rs deleted file mode 100644 index 51b0af591..000000000 --- a/spec/rust/src/formats/expr_ops_parens.rs +++ /dev/null @@ -1,234 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprOpsParens { - pub bool_and: Option, - pub str_0_to_4: Option, - pub bool_or: Option, - pub f_e: Option, - pub f_sum_to_int: Option, - pub f_2pi: Option, - pub str_concat_rev: Option, - pub i_m13: Option, - pub str_concat_len: Option, - pub str_concat_to_i: Option, - pub i_42: Option, - pub i_sum_to_str: Option, - pub bool_eq: Option, - pub str_5_to_9: Option, - pub str_concat_substr_2_to_7: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprOpsParens { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> ExprOpsParens { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprOpsParens::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn bool_and( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.bool_and.is_some() { - return Ok(self.bool_and.as_ref().unwrap()); - } - self.bool_and = Some( ((false) && (true)) as i32 as i32); - return Ok(self.bool_and.as_ref().unwrap()); - } - fn str_0_to_4( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.str_0_to_4.is_some() { - return Ok(self.str_0_to_4.as_ref().unwrap()); - } - self.str_0_to_4 = Some("01234".to_string()); - return Ok(self.str_0_to_4.as_ref().unwrap()); - } - fn bool_or( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.bool_or.is_some() { - return Ok(self.bool_or.as_ref().unwrap()); - } - self.bool_or = Some( ((!(false)) || (false)) as i32 as i32); - return Ok(self.bool_or.as_ref().unwrap()); - } - fn f_e( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.f_e.is_some() { - return Ok(self.f_e.as_ref().unwrap()); - } - self.f_e = Some(2.72 as f64); - return Ok(self.f_e.as_ref().unwrap()); - } - fn f_sum_to_int( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.f_sum_to_int.is_some() { - return Ok(self.f_sum_to_int.as_ref().unwrap()); - } - self.f_sum_to_int = Some((self.f_2pi(_io, _root, _parent)? + self.f_e(_io, _root, _parent)?) as i32 as i32); - return Ok(self.f_sum_to_int.as_ref().unwrap()); - } - fn f_2pi( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.f_2pi.is_some() { - return Ok(self.f_2pi.as_ref().unwrap()); - } - self.f_2pi = Some(6.28 as f64); - return Ok(self.f_2pi.as_ref().unwrap()); - } - fn str_concat_rev( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.str_concat_rev.is_some() { - return Ok(self.str_concat_rev.as_ref().unwrap()); - } - self.str_concat_rev = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).graphemes(true).rev().flat_map(|g| g.chars()).collect().to_string()); - return Ok(self.str_concat_rev.as_ref().unwrap()); - } - fn i_m13( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.i_m13.is_some() { - return Ok(self.i_m13.as_ref().unwrap()); - } - self.i_m13 = Some(-13 as i32); - return Ok(self.i_m13.as_ref().unwrap()); - } - fn str_concat_len( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.str_concat_len.is_some() { - return Ok(self.str_concat_len.as_ref().unwrap()); - } - self.str_concat_len = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).len() as i32); - return Ok(self.str_concat_len.as_ref().unwrap()); - } - fn str_concat_to_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.str_concat_to_i.is_some() { - return Ok(self.str_concat_to_i.as_ref().unwrap()); - } - self.str_concat_to_i = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).parse().unwrap() as i32); - return Ok(self.str_concat_to_i.as_ref().unwrap()); - } - fn i_42( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i8> { - if self.i_42.is_some() { - return Ok(self.i_42.as_ref().unwrap()); - } - self.i_42 = Some(42 as i8); - return Ok(self.i_42.as_ref().unwrap()); - } - fn i_sum_to_str( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.i_sum_to_str.is_some() { - return Ok(self.i_sum_to_str.as_ref().unwrap()); - } - self.i_sum_to_str = Some((self.i_42(_io, _root, _parent)? + self.i_m13(_io, _root, _parent)?).to_string().to_string()); - return Ok(self.i_sum_to_str.as_ref().unwrap()); - } - fn bool_eq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.bool_eq.is_some() { - return Ok(self.bool_eq.as_ref().unwrap()); - } - self.bool_eq = Some(false == true as i32 as i32); - return Ok(self.bool_eq.as_ref().unwrap()); - } - fn str_5_to_9( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.str_5_to_9.is_some() { - return Ok(self.str_5_to_9.as_ref().unwrap()); - } - self.str_5_to_9 = Some("56789".to_string()); - return Ok(self.str_5_to_9.as_ref().unwrap()); - } - fn str_concat_substr_2_to_7( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.str_concat_substr_2_to_7.is_some() { - return Ok(self.str_concat_substr_2_to_7.as_ref().unwrap()); - } - self.str_concat_substr_2_to_7 = Some(format!("{}{}", self.str_0_to_4(_io, _root, _parent)?, self.str_5_to_9(_io, _root, _parent)?).substring(2, 7).to_string()); - return Ok(self.str_concat_substr_2_to_7.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_sizeof_type_0.rs b/spec/rust/src/formats/expr_sizeof_type_0.rs deleted file mode 100644 index d1ca3785c..000000000 --- a/spec/rust/src/formats/expr_sizeof_type_0.rs +++ /dev/null @@ -1,89 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofType0 { - pub sizeof_block: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType0 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofType0 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofType0::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn sizeof_block( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block.is_some() { - return Ok(self.sizeof_block.as_ref().unwrap()); - } - self.sizeof_block = Some(7 as i32); - return Ok(self.sizeof_block.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofType0_Block { - pub a: u8, - pub b: u32, - pub c: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType0_Block { - type Root = ExprSizeofType0; - type ParentStack = (&'r ExprSizeofType0, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_u1()?; - self.b = _io.read_u4le()?; - self.c = _io.read_bytes(2 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofType0_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofType0_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/expr_sizeof_type_1.rs b/spec/rust/src/formats/expr_sizeof_type_1.rs deleted file mode 100644 index 27c60cd66..000000000 --- a/spec/rust/src/formats/expr_sizeof_type_1.rs +++ /dev/null @@ -1,137 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofType1 { - pub sizeof_block: Option, - pub sizeof_subblock: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType1 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofType1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofType1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn sizeof_block( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block.is_some() { - return Ok(self.sizeof_block.as_ref().unwrap()); - } - self.sizeof_block = Some(11 as i32); - return Ok(self.sizeof_block.as_ref().unwrap()); - } - fn sizeof_subblock( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_subblock.is_some() { - return Ok(self.sizeof_subblock.as_ref().unwrap()); - } - self.sizeof_subblock = Some(4 as i32); - return Ok(self.sizeof_subblock.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofType1_Block { - pub a: u8, - pub b: u32, - pub c: Vec, - pub d: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType1_Block { - type Root = ExprSizeofType1; - type ParentStack = (&'r ExprSizeofType1, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_u1()?; - self.b = _io.read_u4le()?; - self.c = _io.read_bytes(2 as usize)?.to_vec(); - self.d = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofType1_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofType1_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofType1_Block_Subblock { - pub a: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofType1_Block_Subblock { - type Root = ExprSizeofType1; - type ParentStack = (&'r ExprSizeofType1_Block, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_bytes(4 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofType1_Block_Subblock { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofType1_Block_Subblock::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/expr_sizeof_value_0.rs b/spec/rust/src/formats/expr_sizeof_value_0.rs deleted file mode 100644 index 72b743a8e..000000000 --- a/spec/rust/src/formats/expr_sizeof_value_0.rs +++ /dev/null @@ -1,145 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofValue0 { - pub block1: Option, - pub more: u16, - pub self_sizeof: Option, - pub sizeof_block: Option, - pub sizeof_block_b: Option, - pub sizeof_block_a: Option, - pub sizeof_block_c: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValue0 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.block1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.more = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofValue0 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofValue0::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn self_sizeof( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.self_sizeof.is_some() { - return Ok(self.self_sizeof.as_ref().unwrap()); - } - self.self_sizeof = Some(9 as i32); - return Ok(self.self_sizeof.as_ref().unwrap()); - } - fn sizeof_block( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block.is_some() { - return Ok(self.sizeof_block.as_ref().unwrap()); - } - self.sizeof_block = Some(7 as i32); - return Ok(self.sizeof_block.as_ref().unwrap()); - } - fn sizeof_block_b( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block_b.is_some() { - return Ok(self.sizeof_block_b.as_ref().unwrap()); - } - self.sizeof_block_b = Some(4 as i32); - return Ok(self.sizeof_block_b.as_ref().unwrap()); - } - fn sizeof_block_a( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block_a.is_some() { - return Ok(self.sizeof_block_a.as_ref().unwrap()); - } - self.sizeof_block_a = Some(1 as i32); - return Ok(self.sizeof_block_a.as_ref().unwrap()); - } - fn sizeof_block_c( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block_c.is_some() { - return Ok(self.sizeof_block_c.as_ref().unwrap()); - } - self.sizeof_block_c = Some(2 as i32); - return Ok(self.sizeof_block_c.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofValue0_Block { - pub a: u8, - pub b: u32, - pub c: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValue0_Block { - type Root = ExprSizeofValue0; - type ParentStack = (&'r ExprSizeofValue0, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_u1()?; - self.b = _io.read_u4le()?; - self.c = _io.read_bytes(2 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofValue0_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofValue0_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/expr_sizeof_value_sized.rs b/spec/rust/src/formats/expr_sizeof_value_sized.rs deleted file mode 100644 index a837264eb..000000000 --- a/spec/rust/src/formats/expr_sizeof_value_sized.rs +++ /dev/null @@ -1,147 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(block1)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofValueSized { - pub block1: Option, - pub more: u16, - pub raw_block1: Vec, - pub self_sizeof: Option, - pub sizeof_block: Option, - pub sizeof_block_b: Option, - pub sizeof_block_a: Option, - pub sizeof_block_c: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValueSized { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.block1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); - self.more = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofValueSized { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofValueSized::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn self_sizeof( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.self_sizeof.is_some() { - return Ok(self.self_sizeof.as_ref().unwrap()); - } - self.self_sizeof = Some(14 as i32); - return Ok(self.self_sizeof.as_ref().unwrap()); - } - fn sizeof_block( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block.is_some() { - return Ok(self.sizeof_block.as_ref().unwrap()); - } - self.sizeof_block = Some(12 as i32); - return Ok(self.sizeof_block.as_ref().unwrap()); - } - fn sizeof_block_b( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block_b.is_some() { - return Ok(self.sizeof_block_b.as_ref().unwrap()); - } - self.sizeof_block_b = Some(4 as i32); - return Ok(self.sizeof_block_b.as_ref().unwrap()); - } - fn sizeof_block_a( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block_a.is_some() { - return Ok(self.sizeof_block_a.as_ref().unwrap()); - } - self.sizeof_block_a = Some(1 as i32); - return Ok(self.sizeof_block_a.as_ref().unwrap()); - } - fn sizeof_block_c( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.sizeof_block_c.is_some() { - return Ok(self.sizeof_block_c.as_ref().unwrap()); - } - self.sizeof_block_c = Some(2 as i32); - return Ok(self.sizeof_block_c.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct ExprSizeofValueSized_Block { - pub a: u8, - pub b: u32, - pub c: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprSizeofValueSized_Block { - type Root = ExprSizeofValueSized; - type ParentStack = (&'r ExprSizeofValueSized, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_u1()?; - self.b = _io.read_u4le()?; - self.c = _io.read_bytes(2 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ExprSizeofValueSized_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprSizeofValueSized_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/expr_str_encodings.rs b/spec/rust/src/formats/expr_str_encodings.rs deleted file mode 100644 index 92bd46c84..000000000 --- a/spec/rust/src/formats/expr_str_encodings.rs +++ /dev/null @@ -1,146 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprStrEncodings { - pub len_of_1: u16, - pub str1: String, - pub len_of_2: u16, - pub str2: String, - pub len_of_3: u16, - pub str3: String, - pub len_of_4: u16, - pub str4: String, - pub str4_gt_str_from_bytes: Option, - pub str1_eq: Option, - pub str4_eq: Option, - pub str3_eq_str2: Option, - pub str4_gt_str_calc: Option, - pub str2_eq: Option, - pub str3_eq: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprStrEncodings { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_of_1 = _io.read_u2le()?; - self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "ASCII")?; - self.len_of_2 = _io.read_u2le()?; - self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; - self.len_of_3 = _io.read_u2le()?; - self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; - self.len_of_4 = _io.read_u2le()?; - self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprStrEncodings { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprStrEncodings::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn str4_gt_str_from_bytes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.str4_gt_str_from_bytes.is_some() { - return Ok(self.str4_gt_str_from_bytes.as_ref().unwrap()); - } - self.str4_gt_str_from_bytes = Some(self.str4 > decode_string(&[0xb4], "CP437")? as bool); - return Ok(self.str4_gt_str_from_bytes.as_ref().unwrap()); - } - fn str1_eq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.str1_eq.is_some() { - return Ok(self.str1_eq.as_ref().unwrap()); - } - self.str1_eq = Some(self.str1 == "Some ASCII" as bool); - return Ok(self.str1_eq.as_ref().unwrap()); - } - fn str4_eq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.str4_eq.is_some() { - return Ok(self.str4_eq.as_ref().unwrap()); - } - self.str4_eq = Some(self.str4 == "\u{2591}\u{2592}\u{2593}" as bool); - return Ok(self.str4_eq.as_ref().unwrap()); - } - fn str3_eq_str2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.str3_eq_str2.is_some() { - return Ok(self.str3_eq_str2.as_ref().unwrap()); - } - self.str3_eq_str2 = Some(self.str3 == self.str2 as bool); - return Ok(self.str3_eq_str2.as_ref().unwrap()); - } - fn str4_gt_str_calc( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.str4_gt_str_calc.is_some() { - return Ok(self.str4_gt_str_calc.as_ref().unwrap()); - } - self.str4_gt_str_calc = Some(self.str4 > "\u{2524}" as bool); - return Ok(self.str4_gt_str_calc.as_ref().unwrap()); - } - fn str2_eq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.str2_eq.is_some() { - return Ok(self.str2_eq.as_ref().unwrap()); - } - self.str2_eq = Some(self.str2 == "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}" as bool); - return Ok(self.str2_eq.as_ref().unwrap()); - } - fn str3_eq( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.str3_eq.is_some() { - return Ok(self.str3_eq.as_ref().unwrap()); - } - self.str3_eq = Some(self.str3 == "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}" as bool); - return Ok(self.str3_eq.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/expr_str_ops.rs b/spec/rust/src/formats/expr_str_ops.rs deleted file mode 100644 index f79f6bfe4..000000000 --- a/spec/rust/src/formats/expr_str_ops.rs +++ /dev/null @@ -1,249 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ExprStrOps { - pub one: String, - pub one_substr_3_to_3: Option, - pub to_i_r8: Option, - pub to_i_r16: Option, - pub two_substr_0_to_10: Option, - pub one_len: Option, - pub two_len: Option, - pub one_substr_2_to_5: Option, - pub to_i_r2: Option, - pub two_rev: Option, - pub two: Option, - pub two_substr_4_to_10: Option, - pub to_i_r10: Option, - pub two_substr_0_to_7: Option, - pub to_i_attr: Option, - pub one_substr_0_to_3: Option, - pub one_rev: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ExprStrOps { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = decode_string(_io.read_bytes(5 as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> ExprStrOps { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ExprStrOps::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn one_substr_3_to_3( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.one_substr_3_to_3.is_some() { - return Ok(self.one_substr_3_to_3.as_ref().unwrap()); - } - self.one_substr_3_to_3 = Some(self.one.substring(3, 3).to_string()); - return Ok(self.one_substr_3_to_3.as_ref().unwrap()); - } - fn to_i_r8( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.to_i_r8.is_some() { - return Ok(self.to_i_r8.as_ref().unwrap()); - } - self.to_i_r8 = Some(panic!("Converting from string to int in base {} is unimplemented"8) as i32); - return Ok(self.to_i_r8.as_ref().unwrap()); - } - fn to_i_r16( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.to_i_r16.is_some() { - return Ok(self.to_i_r16.as_ref().unwrap()); - } - self.to_i_r16 = Some(panic!("Converting from string to int in base {} is unimplemented"16) as i32); - return Ok(self.to_i_r16.as_ref().unwrap()); - } - fn two_substr_0_to_10( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.two_substr_0_to_10.is_some() { - return Ok(self.two_substr_0_to_10.as_ref().unwrap()); - } - self.two_substr_0_to_10 = Some(self.two(_io, _root, _parent)?.substring(0, 10).to_string()); - return Ok(self.two_substr_0_to_10.as_ref().unwrap()); - } - fn one_len( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.one_len.is_some() { - return Ok(self.one_len.as_ref().unwrap()); - } - self.one_len = Some(self.one.len() as i32); - return Ok(self.one_len.as_ref().unwrap()); - } - fn two_len( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.two_len.is_some() { - return Ok(self.two_len.as_ref().unwrap()); - } - self.two_len = Some(self.two(_io, _root, _parent)?.len() as i32); - return Ok(self.two_len.as_ref().unwrap()); - } - fn one_substr_2_to_5( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.one_substr_2_to_5.is_some() { - return Ok(self.one_substr_2_to_5.as_ref().unwrap()); - } - self.one_substr_2_to_5 = Some(self.one.substring(2, 5).to_string()); - return Ok(self.one_substr_2_to_5.as_ref().unwrap()); - } - fn to_i_r2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.to_i_r2.is_some() { - return Ok(self.to_i_r2.as_ref().unwrap()); - } - self.to_i_r2 = Some(panic!("Converting from string to int in base {} is unimplemented"2) as i32); - return Ok(self.to_i_r2.as_ref().unwrap()); - } - fn two_rev( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.two_rev.is_some() { - return Ok(self.two_rev.as_ref().unwrap()); - } - self.two_rev = Some(self.two(_io, _root, _parent)?.graphemes(true).rev().flat_map(|g| g.chars()).collect().to_string()); - return Ok(self.two_rev.as_ref().unwrap()); - } - fn two( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.two.is_some() { - return Ok(self.two.as_ref().unwrap()); - } - self.two = Some("0123456789".to_string()); - return Ok(self.two.as_ref().unwrap()); - } - fn two_substr_4_to_10( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.two_substr_4_to_10.is_some() { - return Ok(self.two_substr_4_to_10.as_ref().unwrap()); - } - self.two_substr_4_to_10 = Some(self.two(_io, _root, _parent)?.substring(4, 10).to_string()); - return Ok(self.two_substr_4_to_10.as_ref().unwrap()); - } - fn to_i_r10( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.to_i_r10.is_some() { - return Ok(self.to_i_r10.as_ref().unwrap()); - } - self.to_i_r10 = Some("-072".parse().unwrap() as i32); - return Ok(self.to_i_r10.as_ref().unwrap()); - } - fn two_substr_0_to_7( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.two_substr_0_to_7.is_some() { - return Ok(self.two_substr_0_to_7.as_ref().unwrap()); - } - self.two_substr_0_to_7 = Some(self.two(_io, _root, _parent)?.substring(0, 7).to_string()); - return Ok(self.two_substr_0_to_7.as_ref().unwrap()); - } - fn to_i_attr( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.to_i_attr.is_some() { - return Ok(self.to_i_attr.as_ref().unwrap()); - } - self.to_i_attr = Some("9173".parse().unwrap() as i32); - return Ok(self.to_i_attr.as_ref().unwrap()); - } - fn one_substr_0_to_3( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.one_substr_0_to_3.is_some() { - return Ok(self.one_substr_0_to_3.as_ref().unwrap()); - } - self.one_substr_0_to_3 = Some(self.one.substring(0, 3).to_string()); - return Ok(self.one_substr_0_to_3.as_ref().unwrap()); - } - fn one_rev( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.one_rev.is_some() { - return Ok(self.one_rev.as_ref().unwrap()); - } - self.one_rev = Some(self.one.graphemes(true).rev().flat_map(|g| g.chars()).collect().to_string()); - return Ok(self.one_rev.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/fixed_contents.rs b/spec/rust/src/formats/fixed_contents.rs deleted file mode 100644 index 5a427f7b3..000000000 --- a/spec/rust/src/formats/fixed_contents.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct FixedContents { - pub normal: Vec, - pub high_bit_8: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for FixedContents { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.normal = _io.read_bytes(6 as usize)?.to_vec(); - self.high_bit_8 = _io.read_bytes(2 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> FixedContents { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = FixedContents::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/fixed_struct.rs b/spec/rust/src/formats/fixed_struct.rs deleted file mode 100644 index 4c6a5068a..000000000 --- a/spec/rust/src/formats/fixed_struct.rs +++ /dev/null @@ -1,139 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct FixedStruct { - pub hdr: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for FixedStruct { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> FixedStruct { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = FixedStruct::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn hdr( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&FixedStruct_Header> { - if self.hdr.is_some() { - return Ok(self.hdr.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(0)) - // popPos(_io) - return Ok(self.hdr.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct FixedStruct_Header { - pub magic1: Vec, - pub uint8: u8, - pub sint8: i8, - pub magic_uint: Vec, - pub uint16: u16, - pub uint32: u32, - pub uint64: u64, - pub magic_sint: Vec, - pub sint16: i16, - pub sint32: i32, - pub sint64: i64, - pub magic_uint_le: Vec, - pub uint16le: u16, - pub uint32le: u32, - pub uint64le: u64, - pub magic_sint_le: Vec, - pub sint16le: i16, - pub sint32le: i32, - pub sint64le: i64, - pub magic_uint_be: Vec, - pub uint16be: u16, - pub uint32be: u32, - pub uint64be: u64, - pub magic_sint_be: Vec, - pub sint16be: i16, - pub sint32be: i32, - pub sint64be: i64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for FixedStruct_Header { - type Root = FixedStruct; - type ParentStack = (&'r FixedStruct, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); - self.uint8 = _io.read_u1()?; - self.sint8 = _io.read_s1()?; - self.magic_uint = _io.read_bytes(10 as usize)?.to_vec(); - self.uint16 = _io.read_u2le()?; - self.uint32 = _io.read_u4le()?; - self.uint64 = _io.read_u8le()?; - self.magic_sint = _io.read_bytes(10 as usize)?.to_vec(); - self.sint16 = _io.read_s2le()?; - self.sint32 = _io.read_s4le()?; - self.sint64 = _io.read_s8le()?; - self.magic_uint_le = _io.read_bytes(9 as usize)?.to_vec(); - self.uint16le = _io.read_u2le()?; - self.uint32le = _io.read_u4le()?; - self.uint64le = _io.read_u8le()?; - self.magic_sint_le = _io.read_bytes(9 as usize)?.to_vec(); - self.sint16le = _io.read_s2le()?; - self.sint32le = _io.read_s4le()?; - self.sint64le = _io.read_s8le()?; - self.magic_uint_be = _io.read_bytes(9 as usize)?.to_vec(); - self.uint16be = _io.read_u2be()?; - self.uint32be = _io.read_u4be()?; - self.uint64be = _io.read_u8be()?; - self.magic_sint_be = _io.read_bytes(9 as usize)?.to_vec(); - self.sint16be = _io.read_s2be()?; - self.sint32be = _io.read_s4be()?; - self.sint64be = _io.read_s8be()?; - Ok(()) - } -} -impl<'r, 's: 'r> FixedStruct_Header { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = FixedStruct_Header::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/float_to_i.rs b/spec/rust/src/formats/float_to_i.rs deleted file mode 100644 index d1764bab6..000000000 --- a/spec/rust/src/formats/float_to_i.rs +++ /dev/null @@ -1,173 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct FloatToI { - pub single_value: f32, - pub double_value: f64, - pub float2_i: Option, - pub calc_float1: Option, - pub float4_i: Option, - pub calc_float3: Option, - pub calc_float2: Option, - pub float1_i: Option, - pub double_i: Option, - pub float3_i: Option, - pub single_i: Option, - pub calc_float4: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for FloatToI { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.single_value = _io.read_f4le()?; - self.double_value = _io.read_f8le()?; - Ok(()) - } -} -impl<'r, 's: 'r> FloatToI { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = FloatToI::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn float2_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.float2_i.is_some() { - return Ok(self.float2_i.as_ref().unwrap()); - } - self.float2_i = Some(self.calc_float2(_io, _root, _parent)? as i32 as i32); - return Ok(self.float2_i.as_ref().unwrap()); - } - fn calc_float1( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.calc_float1.is_some() { - return Ok(self.calc_float1.as_ref().unwrap()); - } - self.calc_float1 = Some(1.234 as f64); - return Ok(self.calc_float1.as_ref().unwrap()); - } - fn float4_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.float4_i.is_some() { - return Ok(self.float4_i.as_ref().unwrap()); - } - self.float4_i = Some(self.calc_float4(_io, _root, _parent)? as i32 as i32); - return Ok(self.float4_i.as_ref().unwrap()); - } - fn calc_float3( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.calc_float3.is_some() { - return Ok(self.calc_float3.as_ref().unwrap()); - } - self.calc_float3 = Some(1.9 as f64); - return Ok(self.calc_float3.as_ref().unwrap()); - } - fn calc_float2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.calc_float2.is_some() { - return Ok(self.calc_float2.as_ref().unwrap()); - } - self.calc_float2 = Some(1.5 as f64); - return Ok(self.calc_float2.as_ref().unwrap()); - } - fn float1_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.float1_i.is_some() { - return Ok(self.float1_i.as_ref().unwrap()); - } - self.float1_i = Some(self.calc_float1(_io, _root, _parent)? as i32 as i32); - return Ok(self.float1_i.as_ref().unwrap()); - } - fn double_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.double_i.is_some() { - return Ok(self.double_i.as_ref().unwrap()); - } - self.double_i = Some(self.double_value as i32 as i32); - return Ok(self.double_i.as_ref().unwrap()); - } - fn float3_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.float3_i.is_some() { - return Ok(self.float3_i.as_ref().unwrap()); - } - self.float3_i = Some(self.calc_float3(_io, _root, _parent)? as i32 as i32); - return Ok(self.float3_i.as_ref().unwrap()); - } - fn single_i( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.single_i.is_some() { - return Ok(self.single_i.as_ref().unwrap()); - } - self.single_i = Some(self.single_value as i32 as i32); - return Ok(self.single_i.as_ref().unwrap()); - } - fn calc_float4( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.calc_float4.is_some() { - return Ok(self.calc_float4.as_ref().unwrap()); - } - self.calc_float4 = Some(-2.7 as f64); - return Ok(self.calc_float4.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/floating_points.rs b/spec/rust/src/formats/floating_points.rs deleted file mode 100644 index 7c41dbf26..000000000 --- a/spec/rust/src/formats/floating_points.rs +++ /dev/null @@ -1,88 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct FloatingPoints { - pub single_value: f32, - pub double_value: f64, - pub single_value_be: f32, - pub double_value_be: f64, - pub approximate_value: f32, - pub single_value_plus_int: Option, - pub single_value_plus_float: Option, - pub double_value_plus_float: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for FloatingPoints { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.single_value = _io.read_f4le()?; - self.double_value = _io.read_f8le()?; - self.single_value_be = _io.read_f4be()?; - self.double_value_be = _io.read_f8be()?; - self.approximate_value = _io.read_f4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> FloatingPoints { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = FloatingPoints::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn single_value_plus_int( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.single_value_plus_int.is_some() { - return Ok(self.single_value_plus_int.as_ref().unwrap()); - } - self.single_value_plus_int = Some((self.single_value + 1) as f64); - return Ok(self.single_value_plus_int.as_ref().unwrap()); - } - fn single_value_plus_float( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.single_value_plus_float.is_some() { - return Ok(self.single_value_plus_float.as_ref().unwrap()); - } - self.single_value_plus_float = Some((self.single_value + 0.5) as f64); - return Ok(self.single_value_plus_float.as_ref().unwrap()); - } - fn double_value_plus_float( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&f64> { - if self.double_value_plus_float.is_some() { - return Ok(self.double_value_plus_float.as_ref().unwrap()); - } - self.double_value_plus_float = Some((self.double_value + 0.05) as f64); - return Ok(self.double_value_plus_float.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/hello_world.rs b/spec/rust/src/formats/hello_world.rs deleted file mode 100644 index 8377b0c8a..000000000 --- a/spec/rust/src/formats/hello_world.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct HelloWorld { - pub one: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for HelloWorld { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> HelloWorld { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = HelloWorld::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/if_instances.rs b/spec/rust/src/formats/if_instances.rs deleted file mode 100644 index fc569cd8b..000000000 --- a/spec/rust/src/formats/if_instances.rs +++ /dev/null @@ -1,57 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IfInstances { - pub never_happens: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IfInstances { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> IfInstances { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IfInstances::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn never_happens( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.never_happens.is_some() { - return Ok(self.never_happens.as_ref().unwrap()); - } - { - // condIfHeader(Bool(false)) - // pushPos(_io) - // seek(_io, IntNum(100500)) - // popPos(_io) - } - return Ok(self.never_happens.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/if_struct.rs b/spec/rust/src/formats/if_struct.rs deleted file mode 100644 index 11e861e33..000000000 --- a/spec/rust/src/formats/if_struct.rs +++ /dev/null @@ -1,158 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IfStruct { - pub op1: Option, - pub op2: Option, - pub op3: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.op1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.op2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.op3 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> IfStruct { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IfStruct::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IfStruct_Operation { - pub opcode: u8, - pub arg_tuple: Option, - pub arg_str: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct_Operation { - type Root = IfStruct; - type ParentStack = (&'r IfStruct, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcode = _io.read_u1()?; - { - // condIfHeader(Compare(Name(identifier(opcode)),Eq,IntNum(84))) - self.arg_tuple = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - } - { - // condIfHeader(Compare(Name(identifier(opcode)),Eq,IntNum(83))) - self.arg_str = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - } - Ok(()) - } -} -impl<'r, 's: 'r> IfStruct_Operation { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IfStruct_Operation::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IfStruct_ArgTuple { - pub num1: u8, - pub num2: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct_ArgTuple { - type Root = IfStruct; - type ParentStack = (&'r IfStruct, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.num1 = _io.read_u1()?; - self.num2 = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> IfStruct_ArgTuple { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IfStruct_ArgTuple::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IfStruct_ArgStr { - pub len: u8, - pub str: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IfStruct_ArgStr { - type Root = IfStruct; - type ParentStack = (&'r IfStruct, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len = _io.read_u1()?; - self.str = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> IfStruct_ArgStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IfStruct_ArgStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/if_values.rs b/spec/rust/src/formats/if_values.rs deleted file mode 100644 index 23ea2e47e..000000000 --- a/spec/rust/src/formats/if_values.rs +++ /dev/null @@ -1,94 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IfValues { - pub codes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IfValues { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.codes = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(codes), _io, UserTypeInstream(List(code),None,List()), IntNum(3)) - // handleAssignmentRepeatExpr(NamedIdentifier(codes), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> IfValues { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IfValues::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IfValues_Code { - pub opcode: u8, - pub half_opcode: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IfValues_Code { - type Root = IfValues; - type ParentStack = (&'r IfValues, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcode = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> IfValues_Code { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IfValues_Code::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn half_opcode( - &mut self, - _io: &'s S, - _root: Option<&'r IfValues>, - _parent: Option>::ParentStack)>> - ) -> KResult<&i32> { - if self.half_opcode.is_some() { - return Ok(self.half_opcode.as_ref().unwrap()); - } - { - // condIfHeader(Compare(BinOp(Name(identifier(opcode)),Mod,IntNum(2)),Eq,IntNum(0))) - self.half_opcode = Some(self.opcode / 2 as i32); - } - return Ok(self.half_opcode.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/imported_1.rs b/spec/rust/src/formats/imported_1.rs deleted file mode 100644 index d2e38ba2e..000000000 --- a/spec/rust/src/formats/imported_1.rs +++ /dev/null @@ -1,44 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::imported_2::Imported2; - -#[derive(Default, Debug, PartialEq)] -pub struct Imported1 { - pub one: u8, - pub two: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Imported1 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - self.two = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> Imported1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Imported1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/imported_2.rs b/spec/rust/src/formats/imported_2.rs deleted file mode 100644 index 4914e8e70..000000000 --- a/spec/rust/src/formats/imported_2.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Imported2 { - pub one: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Imported2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> Imported2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Imported2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/imports0.rs b/spec/rust/src/formats/imports0.rs deleted file mode 100644 index 13113f591..000000000 --- a/spec/rust/src/formats/imports0.rs +++ /dev/null @@ -1,57 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::hello_world::HelloWorld; - -#[derive(Default, Debug, PartialEq)] -pub struct Imports0 { - pub two: u8, - pub hw: Option>, - pub hw_one: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Imports0 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.two = _io.read_u1()?; - self.hw = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> Imports0 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Imports0::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn hw_one( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.hw_one.is_some() { - return Ok(self.hw_one.as_ref().unwrap()); - } - self.hw_one = Some(self.hw.one as u8); - return Ok(self.hw_one.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/imports_circular_a.rs b/spec/rust/src/formats/imports_circular_a.rs deleted file mode 100644 index e1b4bb44d..000000000 --- a/spec/rust/src/formats/imports_circular_a.rs +++ /dev/null @@ -1,44 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::imports_circular_b::ImportsCircularB; - -#[derive(Default, Debug, PartialEq)] -pub struct ImportsCircularA { - pub code: u8, - pub two: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ImportsCircularA { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - self.two = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ImportsCircularA { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ImportsCircularA::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/imports_circular_b.rs b/spec/rust/src/formats/imports_circular_b.rs deleted file mode 100644 index 13d8a0c42..000000000 --- a/spec/rust/src/formats/imports_circular_b.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::imports_circular_a::ImportsCircularA; - -#[derive(Default, Debug, PartialEq)] -pub struct ImportsCircularB { - pub initial: u8, - pub back_ref: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ImportsCircularB { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.initial = _io.read_u1()?; - { - // condIfHeader(Compare(Name(identifier(initial)),Eq,IntNum(65))) - self.back_ref = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - } - Ok(()) - } -} -impl<'r, 's: 'r> ImportsCircularB { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ImportsCircularB::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/imports_rel_1.rs b/spec/rust/src/formats/imports_rel_1.rs deleted file mode 100644 index dd01ba44d..000000000 --- a/spec/rust/src/formats/imports_rel_1.rs +++ /dev/null @@ -1,44 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::imported_1::Imported1; - -#[derive(Default, Debug, PartialEq)] -pub struct ImportsRel1 { - pub one: u8, - pub two: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ImportsRel1 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - self.two = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ImportsRel1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ImportsRel1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/index_sizes.rs b/spec/rust/src/formats/index_sizes.rs deleted file mode 100644 index 3677def6c..000000000 --- a/spec/rust/src/formats/index_sizes.rs +++ /dev/null @@ -1,53 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IndexSizes { - pub qty: u32, - pub sizes: Vec, - pub bufs: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IndexSizes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty = _io.read_u4le()?; - self.sizes = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) - } - self.bufs = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(bufs), _io, StrFromBytesType(BytesLimitType(Subscript(Name(identifier(sizes)),Name(identifier(_index))),None,false,None,None),ASCII), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(bufs), decode_string(_io.read_bytes(self.sizes[i as usize] as usize)?, "ASCII")?) - } - Ok(()) - } -} -impl<'r, 's: 'r> IndexSizes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IndexSizes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/index_to_param_eos.rs b/spec/rust/src/formats/index_to_param_eos.rs deleted file mode 100644 index 431fdb310..000000000 --- a/spec/rust/src/formats/index_to_param_eos.rs +++ /dev/null @@ -1,89 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IndexToParamEos { - pub qty: u32, - pub sizes: Vec, - pub blocks: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamEos { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty = _io.read_u4le()?; - self.sizes = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) - } - self.blocks = Vec::new(); - { - type ArrayElement = IndexToParamEos_Block; - while !_io.is_eof() { - self.blocks.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> IndexToParamEos { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IndexToParamEos::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IndexToParamEos_Block { - pub idx: i32, - pub buf: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamEos_Block { - type Root = IndexToParamEos; - type ParentStack = (&'r IndexToParamEos, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.sizes[self.idx as usize] as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> IndexToParamEos_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IndexToParamEos_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/index_to_param_expr.rs b/spec/rust/src/formats/index_to_param_expr.rs deleted file mode 100644 index 2fe489870..000000000 --- a/spec/rust/src/formats/index_to_param_expr.rs +++ /dev/null @@ -1,87 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IndexToParamExpr { - pub qty: u32, - pub sizes: Vec, - pub blocks: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamExpr { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty = _io.read_u4le()?; - self.sizes = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) - } - self.blocks = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,ArrayBuffer(Name(identifier(_index)))), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(blocks), Self::read_into::(i, _io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> IndexToParamExpr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IndexToParamExpr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IndexToParamExpr_Block { - pub idx: i32, - pub buf: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamExpr_Block { - type Root = IndexToParamExpr; - type ParentStack = (&'r IndexToParamExpr, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.sizes[self.idx as usize] as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> IndexToParamExpr_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IndexToParamExpr_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/index_to_param_until.rs b/spec/rust/src/formats/index_to_param_until.rs deleted file mode 100644 index c056ccf57..000000000 --- a/spec/rust/src/formats/index_to_param_until.rs +++ /dev/null @@ -1,88 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IndexToParamUntil { - pub qty: u32, - pub sizes: Vec, - pub blocks: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamUntil { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty = _io.read_u4le()?; - self.sizes = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(sizes), _io, IntMultiType(false,Width4,Some(LittleEndian)), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(sizes), _io.read_u4le()?) - } - self.blocks = Vec::new(); - { - // condRepeatUntilHeader(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,ArrayBuffer(Name(identifier(_index)))), Attribute(Name(identifier(_io)),identifier(eof))) - // handleAssignmentRepeatUntil(NamedIdentifier(blocks), Self::read_into::(i, _io, _root, _parent.push(self))?.into(), false) - // condRepeatUntilFooter(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,ArrayBuffer(Name(identifier(_index)))), Attribute(Name(identifier(_io)),identifier(eof))) - } {} - Ok(()) - } -} -impl<'r, 's: 'r> IndexToParamUntil { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IndexToParamUntil::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IndexToParamUntil_Block { - pub idx: i32, - pub buf: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IndexToParamUntil_Block { - type Root = IndexToParamUntil; - type ParentStack = (&'r IndexToParamUntil, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.sizes[self.idx as usize] as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> IndexToParamUntil_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IndexToParamUntil_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/instance_std.rs b/spec/rust/src/formats/instance_std.rs deleted file mode 100644 index de3ad728c..000000000 --- a/spec/rust/src/formats/instance_std.rs +++ /dev/null @@ -1,54 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct InstanceStd { - pub header: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for InstanceStd { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> InstanceStd { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = InstanceStd::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn header( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.header.is_some() { - return Ok(self.header.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(2)) - // popPos(_io) - return Ok(self.header.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/instance_std_array.rs b/spec/rust/src/formats/instance_std_array.rs deleted file mode 100644 index dfb0f98a4..000000000 --- a/spec/rust/src/formats/instance_std_array.rs +++ /dev/null @@ -1,65 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct InstanceStdArray { - pub ofs: u32, - pub entry_size: u32, - pub qty_entries: u32, - pub entries: Vec>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for InstanceStdArray { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.ofs = _io.read_u4le()?; - self.entry_size = _io.read_u4le()?; - self.qty_entries = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> InstanceStdArray { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = InstanceStdArray::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn entries( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec>> { - if self.entries.is_some() { - return Ok(self.entries.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, Name(identifier(ofs))) - self.entries = Vec::new(); - { - // condRepeatExprHeader(InstanceIdentifier(entries), _io, BytesLimitType(Name(identifier(entry_size)),None,false,None,None), Name(identifier(qty_entries))) - // handleAssignmentRepeatExpr(InstanceIdentifier(entries), _io.read_bytes(self.entry_size as usize)?) - } - // popPos(_io) - return Ok(self.entries.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/instance_user_array.rs b/spec/rust/src/formats/instance_user_array.rs deleted file mode 100644 index 56fed5b10..000000000 --- a/spec/rust/src/formats/instance_user_array.rs +++ /dev/null @@ -1,106 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(InstanceIdentifier(user_entries)), RepeatExpr(Name(identifier(qty_entries)))) - -#[derive(Default, Debug, PartialEq)] -pub struct InstanceUserArray { - pub ofs: u32, - pub entry_size: u32, - pub qty_entries: u32, - pub raw_user_entries: Vec>, - pub user_entries: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for InstanceUserArray { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.ofs = _io.read_u4le()?; - self.entry_size = _io.read_u4le()?; - self.qty_entries = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> InstanceUserArray { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = InstanceUserArray::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn user_entries( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.user_entries.is_some() { - return Ok(self.user_entries.as_ref().unwrap()); - } - { - // condIfHeader(Compare(Name(identifier(ofs)),Gt,IntNum(0))) - // pushPos(_io) - // seek(_io, Name(identifier(ofs))) - self.user_entries = Vec::new(); - { - // condRepeatExprHeader(InstanceIdentifier(user_entries), _io, UserTypeFromBytes(List(entry),None,List(),BytesLimitType(Name(identifier(entry_size)),None,false,None,None),None), Name(identifier(qty_entries))) - // handleAssignmentRepeatExpr(RawIdentifier(InstanceIdentifier(user_entries)), _io.read_bytes(self.entry_size as usize)?) - // handleAssignmentRepeatExpr(InstanceIdentifier(user_entries), &BytesReader::new(_io.read_bytes(self.entry_size as usize)?)) - } - // popPos(_io) - } - return Ok(self.user_entries.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct InstanceUserArray_Entry { - pub word1: u16, - pub word2: u16, -} -impl<'r, 's: 'r> KStruct<'r, 's> for InstanceUserArray_Entry { - type Root = InstanceUserArray; - type ParentStack = (&'r InstanceUserArray, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.word1 = _io.read_u2le()?; - self.word2 = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> InstanceUserArray_Entry { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = InstanceUserArray_Entry::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/integers.rs b/spec/rust/src/formats/integers.rs deleted file mode 100644 index 29e4813fd..000000000 --- a/spec/rust/src/formats/integers.rs +++ /dev/null @@ -1,93 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct Integers { - pub magic1: Vec, - pub uint8: u8, - pub sint8: i8, - pub magic_uint: Vec, - pub uint16: u16, - pub uint32: u32, - pub uint64: u64, - pub magic_sint: Vec, - pub sint16: i16, - pub sint32: i32, - pub sint64: i64, - pub magic_uint_le: Vec, - pub uint16le: u16, - pub uint32le: u32, - pub uint64le: u64, - pub magic_sint_le: Vec, - pub sint16le: i16, - pub sint32le: i32, - pub sint64le: i64, - pub magic_uint_be: Vec, - pub uint16be: u16, - pub uint32be: u32, - pub uint64be: u64, - pub magic_sint_be: Vec, - pub sint16be: i16, - pub sint32be: i32, - pub sint64be: i64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for Integers { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); - self.uint8 = _io.read_u1()?; - self.sint8 = _io.read_s1()?; - self.magic_uint = _io.read_bytes(10 as usize)?.to_vec(); - self.uint16 = _io.read_u2le()?; - self.uint32 = _io.read_u4le()?; - self.uint64 = _io.read_u8le()?; - self.magic_sint = _io.read_bytes(10 as usize)?.to_vec(); - self.sint16 = _io.read_s2le()?; - self.sint32 = _io.read_s4le()?; - self.sint64 = _io.read_s8le()?; - self.magic_uint_le = _io.read_bytes(9 as usize)?.to_vec(); - self.uint16le = _io.read_u2le()?; - self.uint32le = _io.read_u4le()?; - self.uint64le = _io.read_u8le()?; - self.magic_sint_le = _io.read_bytes(9 as usize)?.to_vec(); - self.sint16le = _io.read_s2le()?; - self.sint32le = _io.read_s4le()?; - self.sint64le = _io.read_s8le()?; - self.magic_uint_be = _io.read_bytes(9 as usize)?.to_vec(); - self.uint16be = _io.read_u2be()?; - self.uint32be = _io.read_u4be()?; - self.uint64be = _io.read_u8be()?; - self.magic_sint_be = _io.read_bytes(9 as usize)?.to_vec(); - self.sint16be = _io.read_s2be()?; - self.sint32be = _io.read_s4be()?; - self.sint64be = _io.read_s8be()?; - Ok(()) - } -} -impl<'r, 's: 'r> Integers { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = Integers::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/integers_double_overflow.rs b/spec/rust/src/formats/integers_double_overflow.rs deleted file mode 100644 index 3faa0c24e..000000000 --- a/spec/rust/src/formats/integers_double_overflow.rs +++ /dev/null @@ -1,115 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IntegersDoubleOverflow { - pub signed_safe_min_be: i64, - pub signed_safe_min_le: i64, - pub signed_safe_max_be: i64, - pub signed_safe_max_le: i64, - pub signed_unsafe_neg_be: i64, - pub signed_unsafe_neg_le: i64, - pub signed_unsafe_pos_be: i64, - pub signed_unsafe_pos_le: i64, - pub unsigned_safe_max_be: Option, - pub unsigned_safe_max_le: Option, - pub unsigned_unsafe_pos_be: Option, - pub unsigned_unsafe_pos_le: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IntegersDoubleOverflow { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.signed_safe_min_be = _io.read_s8be()?; - self.signed_safe_min_le = _io.read_s8le()?; - self.signed_safe_max_be = _io.read_s8be()?; - self.signed_safe_max_le = _io.read_s8le()?; - self.signed_unsafe_neg_be = _io.read_s8be()?; - self.signed_unsafe_neg_le = _io.read_s8le()?; - self.signed_unsafe_pos_be = _io.read_s8be()?; - self.signed_unsafe_pos_le = _io.read_s8le()?; - Ok(()) - } -} -impl<'r, 's: 'r> IntegersDoubleOverflow { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IntegersDoubleOverflow::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn unsigned_safe_max_be( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u64> { - if self.unsigned_safe_max_be.is_some() { - return Ok(self.unsigned_safe_max_be.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(16)) - // popPos(_io) - return Ok(self.unsigned_safe_max_be.as_ref().unwrap()); - } - fn unsigned_safe_max_le( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u64> { - if self.unsigned_safe_max_le.is_some() { - return Ok(self.unsigned_safe_max_le.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(24)) - // popPos(_io) - return Ok(self.unsigned_safe_max_le.as_ref().unwrap()); - } - fn unsigned_unsafe_pos_be( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u64> { - if self.unsigned_unsafe_pos_be.is_some() { - return Ok(self.unsigned_unsafe_pos_be.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(48)) - // popPos(_io) - return Ok(self.unsigned_unsafe_pos_be.as_ref().unwrap()); - } - fn unsigned_unsafe_pos_le( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u64> { - if self.unsigned_unsafe_pos_le.is_some() { - return Ok(self.unsigned_unsafe_pos_le.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(56)) - // popPos(_io) - return Ok(self.unsigned_unsafe_pos_le.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/integers_min_max.rs b/spec/rust/src/formats/integers_min_max.rs deleted file mode 100644 index 1a0ece3a0..000000000 --- a/spec/rust/src/formats/integers_min_max.rs +++ /dev/null @@ -1,137 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct IntegersMinMax { - pub unsigned_min: Option, - pub unsigned_max: Option, - pub signed_min: Option, - pub signed_max: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IntegersMinMax { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.unsigned_min = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.unsigned_max = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.signed_min = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.signed_max = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> IntegersMinMax { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IntegersMinMax::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IntegersMinMax_Unsigned { - pub u1: u8, - pub u2le: u16, - pub u4le: u32, - pub u8le: u64, - pub u2be: u16, - pub u4be: u32, - pub u8be: u64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IntegersMinMax_Unsigned { - type Root = IntegersMinMax; - type ParentStack = (&'r IntegersMinMax, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.u1 = _io.read_u1()?; - self.u2le = _io.read_u2le()?; - self.u4le = _io.read_u4le()?; - self.u8le = _io.read_u8le()?; - self.u2be = _io.read_u2be()?; - self.u4be = _io.read_u4be()?; - self.u8be = _io.read_u8be()?; - Ok(()) - } -} -impl<'r, 's: 'r> IntegersMinMax_Unsigned { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IntegersMinMax_Unsigned::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct IntegersMinMax_Signed { - pub s1: i8, - pub s2le: i16, - pub s4le: i32, - pub s8le: i64, - pub s2be: i16, - pub s4be: i32, - pub s8be: i64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for IntegersMinMax_Signed { - type Root = IntegersMinMax; - type ParentStack = (&'r IntegersMinMax, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.s1 = _io.read_s1()?; - self.s2le = _io.read_s2le()?; - self.s4le = _io.read_s4le()?; - self.s8le = _io.read_s8le()?; - self.s2be = _io.read_s2be()?; - self.s4be = _io.read_s4be()?; - self.s8be = _io.read_s8be()?; - Ok(()) - } -} -impl<'r, 's: 'r> IntegersMinMax_Signed { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IntegersMinMax_Signed::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/io_local_var.rs b/spec/rust/src/formats/io_local_var.rs deleted file mode 100644 index ab8803eb0..000000000 --- a/spec/rust/src/formats/io_local_var.rs +++ /dev/null @@ -1,122 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(InstanceIdentifier(mess_up)), NoRepeat) -// extraAttrForIO(RawIdentifier(InstanceIdentifier(mess_up)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct IoLocalVar { - pub skip: Vec, - pub always_null: u8, - pub followup: u8, - pub raw_mess_up: Vec, - pub mess_up: Option, -} -#[derive(Debug, PartialEq)] -pub enum IoLocalVar_MessUp { - IoLocalVar_Dummy(IoLocalVar_Dummy), - Bytes(Vec), -} -impl From for IoLocalVar_MessUp { - fn from(v: IoLocalVar_Dummy) -> Self { - Self::IoLocalVar_Dummy(v) - } -} -impl From> for IoLocalVar_MessUp { - fn from(v: Vec) -> Self { - Self::Bytes(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for IoLocalVar { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.skip = _io.read_bytes(20 as usize)?.to_vec(); - { - // condIfHeader(Compare(Attribute(Attribute(CastToType(Name(identifier(mess_up)),typeId(false,ArrayBuffer(dummy),false)),identifier(_io)),identifier(pos)),Lt,IntNum(0))) - self.always_null = _io.read_u1()?; - } - self.followup = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> IoLocalVar { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IoLocalVar::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn mess_up( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&IoLocalVar_MessUp> { - if self.mess_up.is_some() { - return Ok(self.mess_up.as_ref().unwrap()); - } - // pushPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) - // seek(// useIO(Attribute(Name(identifier(_root)),identifier(_io))), IntNum(8)) - match 2 { - 1 => { - } - 2 => { - } - // switchElseStart() - } - _ => panic!("unhandled value") - } - // popPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) - return Ok(self.mess_up.as_ref().unwrap()); -} -} - -#[derive(Default, Debug, PartialEq)] -pub struct IoLocalVar_Dummy { -} -impl<'r, 's: 'r> KStruct<'r, 's> for IoLocalVar_Dummy { -type Root = IoLocalVar; -type ParentStack = (&'r IoLocalVar, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - Ok(()) -} -} -impl<'r, 's: 'r> IoLocalVar_Dummy { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = IoLocalVar_Dummy::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/js_signed_right_shift.rs b/spec/rust/src/formats/js_signed_right_shift.rs deleted file mode 100644 index 39cb2c32d..000000000 --- a/spec/rust/src/formats/js_signed_right_shift.rs +++ /dev/null @@ -1,65 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct JsSignedRightShift { - pub should_be_40000000: Option, - pub should_be_a00000: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for JsSignedRightShift { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> JsSignedRightShift { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = JsSignedRightShift::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn should_be_40000000( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.should_be_40000000.is_some() { - return Ok(self.should_be_40000000.as_ref().unwrap()); - } - self.should_be_40000000 = Some((2147483648 >> 1) as i32); - return Ok(self.should_be_40000000.as_ref().unwrap()); - } - fn should_be_a00000( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.should_be_a00000.is_some() { - return Ok(self.should_be_a00000.as_ref().unwrap()); - } - self.should_be_a00000 = Some((2684354560 >> 8) as i32); - return Ok(self.should_be_a00000.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/meta_tags.rs b/spec/rust/src/formats/meta_tags.rs deleted file mode 100644 index ef3524957..000000000 --- a/spec/rust/src/formats/meta_tags.rs +++ /dev/null @@ -1,39 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct MetaTags { -} -impl<'r, 's: 'r> KStruct<'r, 's> for MetaTags { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> MetaTags { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = MetaTags::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/meta_xref.rs b/spec/rust/src/formats/meta_xref.rs deleted file mode 100644 index 2ec4359db..000000000 --- a/spec/rust/src/formats/meta_xref.rs +++ /dev/null @@ -1,39 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct MetaXref { -} -impl<'r, 's: 'r> KStruct<'r, 's> for MetaXref { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> MetaXref { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = MetaXref::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/multiple_use.rs b/spec/rust/src/formats/multiple_use.rs deleted file mode 100644 index d18dc868e..000000000 --- a/spec/rust/src/formats/multiple_use.rs +++ /dev/null @@ -1,155 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct MultipleUse { - pub t1: Option, - pub t2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.t1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.t2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> MultipleUse { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = MultipleUse::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct MultipleUse_Multi { - pub value: i32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse_Multi { - type Root = MultipleUse; - type ParentStack = (&'r MultipleUse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_s4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> MultipleUse_Multi { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = MultipleUse_Multi::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct MultipleUse_Type1 { - pub first_use: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse_Type1 { - type Root = MultipleUse; - type ParentStack = (&'r MultipleUse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.first_use = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> MultipleUse_Type1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = MultipleUse_Type1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct MultipleUse_Type2 { - pub second_use: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for MultipleUse_Type2 { - type Root = MultipleUse; - type ParentStack = (&'r MultipleUse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> MultipleUse_Type2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = MultipleUse_Type2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn second_use( - &mut self, - _io: &'s S, - _root: Option<&'r MultipleUse>, - _parent: Option>::ParentStack)>> - ) -> KResult<&MultipleUse_Multi> { - if self.second_use.is_some() { - return Ok(self.second_use.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(0)) - // popPos(_io) - return Ok(self.second_use.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/nav_parent.rs b/spec/rust/src/formats/nav_parent.rs deleted file mode 100644 index 883f5c022..000000000 --- a/spec/rust/src/formats/nav_parent.rs +++ /dev/null @@ -1,150 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent { - pub header: Option, - pub index: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.header = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.index = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParent { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent_HeaderObj { - pub qty_entries: u32, - pub filename_len: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent_HeaderObj { - type Root = NavParent; - type ParentStack = (&'r NavParent, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty_entries = _io.read_u4le()?; - self.filename_len = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParent_HeaderObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent_HeaderObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent_IndexObj { - pub magic: Vec, - pub entries: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent_IndexObj { - type Root = NavParent; - type ParentStack = (&'r NavParent, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.magic = _io.read_bytes(4 as usize)?.to_vec(); - self.entries = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(entries), _io, UserTypeInstream(List(entry),None,List()), Attribute(Attribute(Name(identifier(_parent)),identifier(header)),identifier(qty_entries))) - // handleAssignmentRepeatExpr(NamedIdentifier(entries), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> NavParent_IndexObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent_IndexObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent_Entry { - pub filename: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent_Entry { - type Root = NavParent; - type ParentStack = (&'r NavParent, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.filename = decode_string(_io.read_bytes(_parent.peek()._parent.header.filename_len as usize)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParent_Entry { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent_Entry::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nav_parent2.rs b/spec/rust/src/formats/nav_parent2.rs deleted file mode 100644 index d779ac41d..000000000 --- a/spec/rust/src/formats/nav_parent2.rs +++ /dev/null @@ -1,149 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent2 { - pub ofs_tags: u32, - pub num_tags: u32, - pub tags: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.ofs_tags = _io.read_u4le()?; - self.num_tags = _io.read_u4le()?; - self.tags = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(tags), _io, UserTypeInstream(List(tag),None,List()), Name(identifier(num_tags))) - // handleAssignmentRepeatExpr(NamedIdentifier(tags), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> NavParent2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent2_Tag { - pub name: String, - pub ofs: u32, - pub num_items: u32, - pub tag_content: Option, -} -#[derive(Debug, PartialEq)] -pub enum NavParent2_Tag_TagContent { - NavParent2_Tag_TagChar(NavParent2_Tag_TagChar), -} -impl From for NavParent2_Tag_TagContent { - fn from(v: NavParent2_Tag_TagChar) -> Self { - Self::NavParent2_Tag_TagChar(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent2_Tag { - type Root = NavParent2; - type ParentStack = (&'r NavParent2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.name = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; - self.ofs = _io.read_u4le()?; - self.num_items = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParent2_Tag { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent2_Tag::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn tag_content( - &mut self, - _io: &'s S, - _root: Option<&'r NavParent2>, - _parent: Option>::ParentStack)>> - ) -> KResult<&NavParent2_Tag_TagContent> { - if self.tag_content.is_some() { - return Ok(self.tag_content.as_ref().unwrap()); - } - // pushPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) - // seek(// useIO(Attribute(Name(identifier(_root)),identifier(_io))), Name(identifier(ofs))) - { - let on = &self.name; - if on == "RAHC" { - } - } - // popPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) - return Ok(self.tag_content.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent2_Tag_TagChar { - pub content: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent2_Tag_TagChar { - type Root = NavParent2; - type ParentStack = (&'r NavParent2_Tag, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.content = decode_string(_io.read_bytes(_parent.peek().num_items as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParent2_Tag_TagChar { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent2_Tag_TagChar::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nav_parent3.rs b/spec/rust/src/formats/nav_parent3.rs deleted file mode 100644 index 8690b9370..000000000 --- a/spec/rust/src/formats/nav_parent3.rs +++ /dev/null @@ -1,163 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent3 { - pub ofs_tags: u32, - pub num_tags: u32, - pub tags: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent3 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.ofs_tags = _io.read_u4le()?; - self.num_tags = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParent3 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent3::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn tags( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Vec> { - if self.tags.is_some() { - return Ok(self.tags.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, Name(identifier(ofs_tags))) - self.tags = Vec::new(); - { - // condRepeatExprHeader(InstanceIdentifier(tags), _io, UserTypeInstream(List(tag),None,List()), Name(identifier(num_tags))) - // handleAssignmentRepeatExpr(InstanceIdentifier(tags), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - // popPos(_io) - return Ok(self.tags.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent3_Tag { - pub name: String, - pub ofs: u32, - pub num_items: u32, - pub tag_content: Option, -} -#[derive(Debug, PartialEq)] -pub enum NavParent3_Tag_TagContent { - NavParent3_Tag_TagChar(NavParent3_Tag_TagChar), -} -impl From for NavParent3_Tag_TagContent { - fn from(v: NavParent3_Tag_TagChar) -> Self { - Self::NavParent3_Tag_TagChar(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent3_Tag { - type Root = NavParent3; - type ParentStack = (&'r NavParent3, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.name = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; - self.ofs = _io.read_u4le()?; - self.num_items = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParent3_Tag { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent3_Tag::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn tag_content( - &mut self, - _io: &'s S, - _root: Option<&'r NavParent3>, - _parent: Option>::ParentStack)>> - ) -> KResult<&NavParent3_Tag_TagContent> { - if self.tag_content.is_some() { - return Ok(self.tag_content.as_ref().unwrap()); - } - // pushPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) - // seek(// useIO(Attribute(Name(identifier(_root)),identifier(_io))), Name(identifier(ofs))) - { - let on = &self.name; - if on == "RAHC" { - } - } - // popPos(// useIO(Attribute(Name(identifier(_root)),identifier(_io)))) - return Ok(self.tag_content.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParent3_Tag_TagChar { - pub content: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParent3_Tag_TagChar { - type Root = NavParent3; - type ParentStack = (&'r NavParent3_Tag, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.content = decode_string(_io.read_bytes(_parent.peek().num_items as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParent3_Tag_TagChar { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParent3_Tag_TagChar::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nav_parent_false.rs b/spec/rust/src/formats/nav_parent_false.rs deleted file mode 100644 index ea114a4df..000000000 --- a/spec/rust/src/formats/nav_parent_false.rs +++ /dev/null @@ -1,151 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentFalse { - pub child_size: u8, - pub element_a: Option, - pub element_b: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.child_size = _io.read_u1()?; - self.element_a = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.element_b = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentFalse { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentFalse::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentFalse_ParentA { - pub foo: Option, - pub bar: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse_ParentA { - type Root = NavParentFalse; - type ParentStack = (&'r NavParentFalse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.bar = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentFalse_ParentA { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentFalse_ParentA::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentFalse_ParentB { - pub foo: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse_ParentB { - type Root = NavParentFalse; - type ParentStack = (&'r NavParentFalse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, KStructUnit::parent_stack())?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentFalse_ParentB { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentFalse_ParentB::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentFalse_Child { - pub code: u8, - pub more: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse_Child { - type Root = NavParentFalse; - type ParentStack = (&'r NavParentFalse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - { - // condIfHeader(Compare(Name(identifier(code)),Eq,IntNum(73))) - self.more = _io.read_bytes(_parent.peek()._parent.child_size as usize)?.to_vec(); - } - Ok(()) - } -} -impl<'r, 's: 'r> NavParentFalse_Child { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentFalse_Child::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nav_parent_false2.rs b/spec/rust/src/formats/nav_parent_false2.rs deleted file mode 100644 index 1acd02ad8..000000000 --- a/spec/rust/src/formats/nav_parent_false2.rs +++ /dev/null @@ -1,74 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentFalse2 { - pub parentless: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.parentless = Some(Self::read_into::(Self::read_into::(_io, _root, KStructUnit::parent_stack())?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentFalse2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentFalse2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentFalse2_Child { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentFalse2_Child { - type Root = NavParentFalse2; - type ParentStack = (&'r NavParentFalse2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NavParentFalse2_Child { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentFalse2_Child::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nav_parent_override.rs b/spec/rust/src/formats/nav_parent_override.rs deleted file mode 100644 index 9ad2ff630..000000000 --- a/spec/rust/src/formats/nav_parent_override.rs +++ /dev/null @@ -1,111 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentOverride { - pub child_size: u8, - pub child_1: Option, - pub mediator_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentOverride { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.child_size = _io.read_u1()?; - self.child_1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.mediator_2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentOverride { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentOverride::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentOverride_Mediator { - pub child_2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentOverride_Mediator { - type Root = NavParentOverride; - type ParentStack = (&'r NavParentOverride, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.child_2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.peek())?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentOverride_Mediator { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentOverride_Mediator::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentOverride_Child { - pub data: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentOverride_Child { - type Root = NavParentOverride; - type ParentStack = (&'r NavParentOverride, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.data = _io.read_bytes(_parent.peek().child_size as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentOverride_Child { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentOverride_Child::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nav_parent_switch.rs b/spec/rust/src/formats/nav_parent_switch.rs deleted file mode 100644 index daa2f07da..000000000 --- a/spec/rust/src/formats/nav_parent_switch.rs +++ /dev/null @@ -1,129 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitch { - pub category: u8, - pub content: Option, -} -#[derive(Debug, PartialEq)] -pub enum NavParentSwitch_Content { - NavParentSwitch_Element1(NavParentSwitch_Element1), -} -impl From for NavParentSwitch_Content { - fn from(v: NavParentSwitch_Element1) -> Self { - Self::NavParentSwitch_Element1(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitch { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.category = _io.read_u1()?; - match self.category { - 1 => { - self.content = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> NavParentSwitch { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitch::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitch_Element1 { - pub foo: u8, - pub subelement: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitch_Element1 { - type Root = NavParentSwitch; - type ParentStack = (&'r NavParentSwitch, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - self.subelement = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentSwitch_Element1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitch_Element1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitch_Subelement1 { - pub bar: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitch_Subelement1 { - type Root = NavParentSwitch; - type ParentStack = (&'r NavParentSwitch, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - { - // condIfHeader(Compare(Attribute(Name(identifier(_parent)),identifier(foo)),Eq,IntNum(66))) - self.bar = _io.read_u1()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> NavParentSwitch_Subelement1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitch_Subelement1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nav_parent_switch_cast.rs b/spec/rust/src/formats/nav_parent_switch_cast.rs deleted file mode 100644 index c9799c28f..000000000 --- a/spec/rust/src/formats/nav_parent_switch_cast.rs +++ /dev/null @@ -1,224 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitchCast { - pub main: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentSwitchCast { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitchCast::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitchCast_Foo { - pub buf_type: u8, - pub flag: u8, - pub buf: Option, - pub raw_buf: Vec, -} -#[derive(Debug, PartialEq)] -pub enum NavParentSwitchCast_Foo_Buf { - NavParentSwitchCast_Foo_Zero(NavParentSwitchCast_Foo_Zero), - NavParentSwitchCast_Foo_One(NavParentSwitchCast_Foo_One), - Bytes(Vec), -} -impl From for NavParentSwitchCast_Foo_Buf { - fn from(v: NavParentSwitchCast_Foo_Zero) -> Self { - Self::NavParentSwitchCast_Foo_Zero(v) - } -} -impl From for NavParentSwitchCast_Foo_Buf { - fn from(v: NavParentSwitchCast_Foo_One) -> Self { - Self::NavParentSwitchCast_Foo_One(v) - } -} -impl From> for NavParentSwitchCast_Foo_Buf { - fn from(v: Vec) -> Self { - Self::Bytes(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo { - type Root = NavParentSwitchCast; - type ParentStack = (&'r NavParentSwitchCast, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf_type = _io.read_u1()?; - self.flag = _io.read_u1()?; - match self.buf_type { - 0 => { - self.buf = Some(&BytesReader::new(_io.read_bytes(4 as usize)?)); - } - 1 => { - self.buf = Some(&BytesReader::new(_io.read_bytes(4 as usize)?)); - } - // switchElseStart() - self.buf = Some(_io.read_bytes(4 as usize)?); - } - _ => panic!("unhandled value") - } - Ok(()) -} -} -impl<'r, 's: 'r> NavParentSwitchCast_Foo { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitchCast_Foo::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitchCast_Foo_Zero { -pub branch: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo_Zero { -type Root = NavParentSwitchCast; -type ParentStack = (&'r NavParentSwitchCast_Foo, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.branch = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) -} -} -impl<'r, 's: 'r> NavParentSwitchCast_Foo_Zero { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitchCast_Foo_Zero::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitchCast_Foo_One { -pub branch: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo_One { -type Root = NavParentSwitchCast; -type ParentStack = (&'r NavParentSwitchCast_Foo, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.branch = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) -} -} -impl<'r, 's: 'r> NavParentSwitchCast_Foo_One { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitchCast_Foo_One::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentSwitchCast_Foo_Common { -pub flag: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentSwitchCast_Foo_Common { -type Root = NavParentSwitchCast; -type ParentStack = (&'r NavParentSwitchCast_Foo, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - Ok(()) -} -} -impl<'r, 's: 'r> NavParentSwitchCast_Foo_Common { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentSwitchCast_Foo_Common::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -fn flag( - &mut self, - _io: &'s S, - _root: Option<&'r NavParentSwitchCast>, - _parent: Option>::ParentStack)>> -) -> KResult<&u8> { - if self.flag.is_some() { - return Ok(self.flag.as_ref().unwrap()); - } - self.flag = Some(_parent.peek()._parent.flag as u8); - return Ok(self.flag.as_ref().unwrap()); -} -} diff --git a/spec/rust/src/formats/nav_parent_vs_value_inst.rs b/spec/rust/src/formats/nav_parent_vs_value_inst.rs deleted file mode 100644 index f31ea31e1..000000000 --- a/spec/rust/src/formats/nav_parent_vs_value_inst.rs +++ /dev/null @@ -1,87 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentVsValueInst { - pub s1: String, - pub child: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentVsValueInst { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; - self.child = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavParentVsValueInst { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentVsValueInst::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavParentVsValueInst_ChildObj { - pub do_something: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavParentVsValueInst_ChildObj { - type Root = NavParentVsValueInst; - type ParentStack = (&'r NavParentVsValueInst, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> NavParentVsValueInst_ChildObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavParentVsValueInst_ChildObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn do_something( - &mut self, - _io: &'s S, - _root: Option<&'r NavParentVsValueInst>, - _parent: Option>::ParentStack)>> - ) -> KResult<&bool> { - if self.do_something.is_some() { - return Ok(self.do_something.as_ref().unwrap()); - } - self.do_something = Some(if _parent.peek().s1 == "foo" { true } else { false} as bool); - return Ok(self.do_something.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/nav_root.rs b/spec/rust/src/formats/nav_root.rs deleted file mode 100644 index 435a8b6e9..000000000 --- a/spec/rust/src/formats/nav_root.rs +++ /dev/null @@ -1,150 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NavRoot { - pub header: Option, - pub index: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.header = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.index = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NavRoot { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavRoot::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavRoot_HeaderObj { - pub qty_entries: u32, - pub filename_len: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot_HeaderObj { - type Root = NavRoot; - type ParentStack = (&'r NavRoot, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty_entries = _io.read_u4le()?; - self.filename_len = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> NavRoot_HeaderObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavRoot_HeaderObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavRoot_IndexObj { - pub magic: Vec, - pub entries: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot_IndexObj { - type Root = NavRoot; - type ParentStack = (&'r NavRoot, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.magic = _io.read_bytes(4 as usize)?.to_vec(); - self.entries = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(entries), _io, UserTypeInstream(List(entry),None,List()), Attribute(Attribute(Name(identifier(_root)),identifier(header)),identifier(qty_entries))) - // handleAssignmentRepeatExpr(NamedIdentifier(entries), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> NavRoot_IndexObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavRoot_IndexObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NavRoot_Entry { - pub filename: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NavRoot_Entry { - type Root = NavRoot; - type ParentStack = (&'r NavRoot, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.filename = decode_string(_io.read_bytes(_root.ok_or(KError::MissingRoot)?.header.filename_len as usize)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> NavRoot_Entry { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NavRoot_Entry::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nested_same_name.rs b/spec/rust/src/formats/nested_same_name.rs deleted file mode 100644 index c0d682109..000000000 --- a/spec/rust/src/formats/nested_same_name.rs +++ /dev/null @@ -1,173 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName { - pub main_data: Option, - pub dummy: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main_data = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.dummy = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName_Main { - pub main_size: i32, - pub foo: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_Main { - type Root = NestedSameName; - type ParentStack = (&'r NestedSameName, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main_size = _io.read_s4le()?; - self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName_Main { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName_Main::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName_Main_FooObj { - pub data: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_Main_FooObj { - type Root = NestedSameName; - type ParentStack = (&'r NestedSameName_Main, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.data = _io.read_bytes((_parent.peek().main_size * 2) as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName_Main_FooObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName_Main_FooObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName_DummyObj { -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_DummyObj { - type Root = NestedSameName; - type ParentStack = (&'r NestedSameName, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName_DummyObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName_DummyObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName_DummyObj_Foo { -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName_DummyObj_Foo { - type Root = NestedSameName; - type ParentStack = (&'r NestedSameName_DummyObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName_DummyObj_Foo { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName_DummyObj_Foo::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nested_same_name2.rs b/spec/rust/src/formats/nested_same_name2.rs deleted file mode 100644 index a191e08fc..000000000 --- a/spec/rust/src/formats/nested_same_name2.rs +++ /dev/null @@ -1,181 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName2 { - pub version: u32, - pub main_data: Option, - pub dummy: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.version = _io.read_u4le()?; - self.main_data = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.dummy = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName2_Main { - pub main_size: i32, - pub foo: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_Main { - type Root = NestedSameName2; - type ParentStack = (&'r NestedSameName2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main_size = _io.read_s4le()?; - self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName2_Main { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName2_Main::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName2_Main_FooObj { - pub data1: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_Main_FooObj { - type Root = NestedSameName2; - type ParentStack = (&'r NestedSameName2_Main, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.data1 = _io.read_bytes((_parent.peek().main_size * 2) as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName2_Main_FooObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName2_Main_FooObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName2_DummyObj { - pub dummy_size: i32, - pub foo: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_DummyObj { - type Root = NestedSameName2; - type ParentStack = (&'r NestedSameName2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.dummy_size = _io.read_s4le()?; - self.foo = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName2_DummyObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName2_DummyObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedSameName2_DummyObj_FooObj { - pub data2: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedSameName2_DummyObj_FooObj { - type Root = NestedSameName2; - type ParentStack = (&'r NestedSameName2_DummyObj, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.data2 = _io.read_bytes((_parent.peek().dummy_size * 2) as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> NestedSameName2_DummyObj_FooObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedSameName2_DummyObj_FooObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nested_type_param.rs b/spec/rust/src/formats/nested_type_param.rs deleted file mode 100644 index cb226dbe1..000000000 --- a/spec/rust/src/formats/nested_type_param.rs +++ /dev/null @@ -1,106 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypeParam { - pub main_seq: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypeParam { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.main_seq = Some(Self::read_into::(Self::read_into::(5, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypeParam { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypeParam::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypeParam_Nested { -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypeParam_Nested { - type Root = NestedTypeParam; - type ParentStack = (&'r NestedTypeParam, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypeParam_Nested { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypeParam_Nested::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypeParam_Nested_MyType { - pub my_len: u32, - pub body: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypeParam_Nested_MyType { - type Root = NestedTypeParam; - type ParentStack = (&'r NestedTypeParam_Nested, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.body = decode_string(_io.read_bytes(self.my_len as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypeParam_Nested_MyType { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypeParam_Nested_MyType::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nested_types.rs b/spec/rust/src/formats/nested_types.rs deleted file mode 100644 index 23c79304b..000000000 --- a/spec/rust/src/formats/nested_types.rs +++ /dev/null @@ -1,144 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes { - pub one: Option, - pub two: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.two = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes_SubtypeA { - pub typed_at_root: Option, - pub typed_here: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes_SubtypeA { - type Root = NestedTypes; - type ParentStack = (&'r NestedTypes, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.typed_at_root = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.typed_here = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes_SubtypeA { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes_SubtypeA::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes_SubtypeA_SubtypeC { - pub value_c: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes_SubtypeA_SubtypeC { - type Root = NestedTypes; - type ParentStack = (&'r NestedTypes_SubtypeA, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_c = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes_SubtypeA_SubtypeC { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes_SubtypeA_SubtypeC::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes_SubtypeB { - pub value_b: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes_SubtypeB { - type Root = NestedTypes; - type ParentStack = (&'r NestedTypes, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_b = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes_SubtypeB { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes_SubtypeB::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nested_types2.rs b/spec/rust/src/formats/nested_types2.rs deleted file mode 100644 index e9d9cd97e..000000000 --- a/spec/rust/src/formats/nested_types2.rs +++ /dev/null @@ -1,218 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes2 { - pub one: Option, - pub two: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.two = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes2_SubtypeA { - pub typed_at_root: Option, - pub typed_here1: Option, - pub typed_here2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA { - type Root = NestedTypes2; - type ParentStack = (&'r NestedTypes2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.typed_at_root = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.typed_here1 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.typed_here2 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes2_SubtypeA { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes2_SubtypeA::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes2_SubtypeA_SubtypeC { - pub value_c: i8, - pub typed_here: Option, - pub typed_parent: Option, - pub typed_root: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA_SubtypeC { - type Root = NestedTypes2; - type ParentStack = (&'r NestedTypes2_SubtypeA, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_c = _io.read_s1()?; - self.typed_here = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.typed_parent = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.typed_root = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes2_SubtypeA_SubtypeC { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes2_SubtypeA_SubtypeC::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes2_SubtypeA_SubtypeC_SubtypeD { - pub value_d: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA_SubtypeC_SubtypeD { - type Root = NestedTypes2; - type ParentStack = (&'r NestedTypes2_SubtypeA_SubtypeC, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_d = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes2_SubtypeA_SubtypeC_SubtypeD { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes2_SubtypeA_SubtypeC_SubtypeD::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes2_SubtypeA_SubtypeCc { - pub value_cc: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeA_SubtypeCc { - type Root = NestedTypes2; - type ParentStack = (&'r NestedTypes2_SubtypeA, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_cc = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes2_SubtypeA_SubtypeCc { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes2_SubtypeA_SubtypeCc::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes2_SubtypeB { - pub value_b: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes2_SubtypeB { - type Root = NestedTypes2; - type ParentStack = (&'r NestedTypes2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_b = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes2_SubtypeB { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes2_SubtypeB::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/nested_types3.rs b/spec/rust/src/formats/nested_types3.rs deleted file mode 100644 index d64b89447..000000000 --- a/spec/rust/src/formats/nested_types3.rs +++ /dev/null @@ -1,210 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes3 { - pub a_cc: Option, - pub a_c_d: Option, - pub b: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a_cc = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.a_c_d = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.b = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes3 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes3::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes3_SubtypeA { -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA { - type Root = NestedTypes3; - type ParentStack = (&'r NestedTypes3, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes3_SubtypeA { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes3_SubtypeA::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes3_SubtypeA_SubtypeC { -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA_SubtypeC { - type Root = NestedTypes3; - type ParentStack = (&'r NestedTypes3_SubtypeA, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes3_SubtypeA_SubtypeC { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes3_SubtypeA_SubtypeC::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes3_SubtypeA_SubtypeC_SubtypeD { - pub value_d: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA_SubtypeC_SubtypeD { - type Root = NestedTypes3; - type ParentStack = (&'r NestedTypes3_SubtypeA_SubtypeC, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_d = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes3_SubtypeA_SubtypeC_SubtypeD { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes3_SubtypeA_SubtypeC_SubtypeD::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes3_SubtypeA_SubtypeCc { - pub value_cc: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeA_SubtypeCc { - type Root = NestedTypes3; - type ParentStack = (&'r NestedTypes3_SubtypeA, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_cc = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes3_SubtypeA_SubtypeCc { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes3_SubtypeA_SubtypeCc::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct NestedTypes3_SubtypeB { - pub value_b: i8, - pub a_cc: Option, - pub a_c_d: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for NestedTypes3_SubtypeB { - type Root = NestedTypes3; - type ParentStack = (&'r NestedTypes3, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_b = _io.read_s1()?; - self.a_cc = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.a_c_d = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> NestedTypes3_SubtypeB { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NestedTypes3_SubtypeB::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/non_standard.rs b/spec/rust/src/formats/non_standard.rs deleted file mode 100644 index 8e21e7de6..000000000 --- a/spec/rust/src/formats/non_standard.rs +++ /dev/null @@ -1,95 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct NonStandard { - pub foo: u8, - pub bar: Option, - pub vi: Option, - pub pi: Option, -} -#[derive(Debug, PartialEq)] -pub enum NonStandard_Bar { - U2(u16), - U4(u32), -} -impl From for NonStandard_Bar { - fn from(v: u16) -> Self { - Self::U2(v) - } -} -impl From for NonStandard_Bar { - fn from(v: u32) -> Self { - Self::U4(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for NonStandard { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - match self.foo { - 42 => { - self.bar = Some(_io.read_u2le()?); - } - 43 => { - self.bar = Some(_io.read_u4le()?); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> NonStandard { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = NonStandard::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn vi( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.vi.is_some() { - return Ok(self.vi.as_ref().unwrap()); - } - self.vi = Some(self.foo as u8); - return Ok(self.vi.as_ref().unwrap()); - } - fn pi( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.pi.is_some() { - return Ok(self.pi.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(0)) - // popPos(_io) - return Ok(self.pi.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/opaque_external_type.rs b/spec/rust/src/formats/opaque_external_type.rs deleted file mode 100644 index 515918256..000000000 --- a/spec/rust/src/formats/opaque_external_type.rs +++ /dev/null @@ -1,42 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::term_strz::TermStrz; - -#[derive(Default, Debug, PartialEq)] -pub struct OpaqueExternalType { - pub one: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> OpaqueExternalType { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = OpaqueExternalType::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/opaque_external_type_02_child.rs b/spec/rust/src/formats/opaque_external_type_02_child.rs deleted file mode 100644 index e4375ac3e..000000000 --- a/spec/rust/src/formats/opaque_external_type_02_child.rs +++ /dev/null @@ -1,94 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct OpaqueExternalType02Child { - pub s1: String, - pub s2: String, - pub s3: Option, - pub some_method: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Child { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; - self.s2 = decode_string(_io.read_bytes_term(124, false, false, true)?, "UTF-8")?; - self.s3 = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> OpaqueExternalType02Child { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = OpaqueExternalType02Child::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn some_method( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.some_method.is_some() { - return Ok(self.some_method.as_ref().unwrap()); - } - self.some_method = Some(true as bool); - return Ok(self.some_method.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct OpaqueExternalType02Child_OpaqueExternalType02ChildChild { - pub s3: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Child_OpaqueExternalType02ChildChild { - type Root = OpaqueExternalType02Child; - type ParentStack = (&'r OpaqueExternalType02Child, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - { - // condIfHeader(Attribute(Name(identifier(_root)),identifier(some_method))) - self.s3 = decode_string(_io.read_bytes_term(64, true, true, true)?, "UTF-8")?; - } - Ok(()) - } -} -impl<'r, 's: 'r> OpaqueExternalType02Child_OpaqueExternalType02ChildChild { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = OpaqueExternalType02Child_OpaqueExternalType02ChildChild::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/opaque_external_type_02_parent.rs b/spec/rust/src/formats/opaque_external_type_02_parent.rs deleted file mode 100644 index 141c7eba3..000000000 --- a/spec/rust/src/formats/opaque_external_type_02_parent.rs +++ /dev/null @@ -1,75 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::opaque_external_type_02_child::OpaqueExternalType02Child; - -#[derive(Default, Debug, PartialEq)] -pub struct OpaqueExternalType02Parent { - pub parent: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Parent { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.parent = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> OpaqueExternalType02Parent { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = OpaqueExternalType02Parent::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct OpaqueExternalType02Parent_ParentObj { - pub child: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueExternalType02Parent_ParentObj { - type Root = OpaqueExternalType02Parent; - type ParentStack = (&'r OpaqueExternalType02Parent, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.child = Some(Self::read_into::>(Self::read_into::(_io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> OpaqueExternalType02Parent_ParentObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = OpaqueExternalType02Parent_ParentObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/opaque_with_param.rs b/spec/rust/src/formats/opaque_with_param.rs deleted file mode 100644 index 95124fe68..000000000 --- a/spec/rust/src/formats/opaque_with_param.rs +++ /dev/null @@ -1,42 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::params_def::ParamsDef; - -#[derive(Default, Debug, PartialEq)] -pub struct OpaqueWithParam { - pub one: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for OpaqueWithParam { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some(Self::read_into::>(Self::read_into::(5, true, _io)?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> OpaqueWithParam { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = OpaqueWithParam::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/optional_id.rs b/spec/rust/src/formats/optional_id.rs deleted file mode 100644 index 7b054fd16..000000000 --- a/spec/rust/src/formats/optional_id.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct OptionalId { - pub _unnamed0: u8, - pub _unnamed1: u8, - pub _unnamed2: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for OptionalId { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self._unnamed0 = _io.read_u1()?; - self._unnamed1 = _io.read_u1()?; - self._unnamed2 = _io.read_bytes(5 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> OptionalId { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = OptionalId::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/params_call_extra_parens.rs b/spec/rust/src/formats/params_call_extra_parens.rs deleted file mode 100644 index 3fbded590..000000000 --- a/spec/rust/src/formats/params_call_extra_parens.rs +++ /dev/null @@ -1,75 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsCallExtraParens { - pub buf1: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallExtraParens { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf1 = Some(Self::read_into::(Self::read_into::(5, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsCallExtraParens { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsCallExtraParens::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsCallExtraParens_MyStr1 { - pub len: u32, - pub body: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallExtraParens_MyStr1 { - type Root = ParamsCallExtraParens; - type ParentStack = (&'r ParamsCallExtraParens, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.body = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> ParamsCallExtraParens_MyStr1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsCallExtraParens_MyStr1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/params_call_short.rs b/spec/rust/src/formats/params_call_short.rs deleted file mode 100644 index 885c85b83..000000000 --- a/spec/rust/src/formats/params_call_short.rs +++ /dev/null @@ -1,117 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsCallShort { - pub buf1: Option, - pub buf2: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallShort { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf1 = Some(Self::read_into::(Self::read_into::(5, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.buf2 = Some(Self::read_into::(Self::read_into::((2 + 3), true, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsCallShort { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsCallShort::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsCallShort_MyStr1 { - pub len: u32, - pub body: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallShort_MyStr1 { - type Root = ParamsCallShort; - type ParentStack = (&'r ParamsCallShort, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.body = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> ParamsCallShort_MyStr1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsCallShort_MyStr1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsCallShort_MyStr2 { - pub len: u32, - pub has_trailer: bool, - pub body: String, - pub trailer: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsCallShort_MyStr2 { - type Root = ParamsCallShort; - type ParentStack = (&'r ParamsCallShort, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.body = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; - { - // condIfHeader(Name(identifier(has_trailer))) - self.trailer = _io.read_u1()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> ParamsCallShort_MyStr2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsCallShort_MyStr2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/params_def.rs b/spec/rust/src/formats/params_def.rs deleted file mode 100644 index e7427bf49..000000000 --- a/spec/rust/src/formats/params_def.rs +++ /dev/null @@ -1,48 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsDef { - pub len: u32, - pub has_trailer: bool, - pub buf: String, - pub trailer: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsDef { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf = decode_string(_io.read_bytes(self.len as usize)?, "UTF-8")?; - { - // condIfHeader(Name(identifier(has_trailer))) - self.trailer = _io.read_u1()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> ParamsDef { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsDef::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/params_enum.rs b/spec/rust/src/formats/params_enum.rs deleted file mode 100644 index 08b9e1e67..000000000 --- a/spec/rust/src/formats/params_enum.rs +++ /dev/null @@ -1,106 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsEnum { - pub one: Option, - pub invoke_with_param: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsEnum { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some((_io.read_u1()? as i64).try_into()?); - self.invoke_with_param = Some(Self::read_into::(Self::read_into::(self.one, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsEnum { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsEnum::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum ParamsEnum_Animal { - Dog, - Cat, - Chicken, -} -impl TryFrom for ParamsEnum_Animal { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 4 => Ok(ParamsEnum_Animal::Dog), - 7 => Ok(ParamsEnum_Animal::Cat), - 12 => Ok(ParamsEnum_Animal::Chicken), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsEnum_WithParam { - pub enumerated_one: Option, - pub is_cat: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsEnum_WithParam { - type Root = ParamsEnum; - type ParentStack = (&'r ParamsEnum, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> ParamsEnum_WithParam { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsEnum_WithParam::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn is_cat( - &mut self, - _io: &'s S, - _root: Option<&'r ParamsEnum>, - _parent: Option>::ParentStack)>> - ) -> KResult<&bool> { - if self.is_cat.is_some() { - return Ok(self.is_cat.as_ref().unwrap()); - } - self.is_cat = Some(self.enumerated_one == ParamsEnum_Animal::Cat as bool); - return Ok(self.is_cat.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/params_pass_array_usertype.rs b/spec/rust/src/formats/params_pass_array_usertype.rs deleted file mode 100644 index a465a1db4..000000000 --- a/spec/rust/src/formats/params_pass_array_usertype.rs +++ /dev/null @@ -1,116 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassArrayUsertype { - pub blocks: Vec, - pub pass_blocks: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassArrayUsertype { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.blocks = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(blocks), _io, UserTypeInstream(List(block),None,List()), IntNum(2)) - // handleAssignmentRepeatExpr(NamedIdentifier(blocks), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - self.pass_blocks = Some(Self::read_into::(Self::read_into::(self.blocks, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassArrayUsertype { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassArrayUsertype::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassArrayUsertype_Block { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassArrayUsertype_Block { - type Root = ParamsPassArrayUsertype; - type ParentStack = (&'r ParamsPassArrayUsertype, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassArrayUsertype_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassArrayUsertype_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassArrayUsertype_ParamType { - pub bar: Vec, - pub one: Vec, - pub two: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassArrayUsertype_ParamType { - type Root = ParamsPassArrayUsertype; - type ParentStack = (&'r ParamsPassArrayUsertype, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_bytes(self.bar[0 as usize].foo as usize)?.to_vec(); - self.two = _io.read_bytes(self.bar[1 as usize].foo as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassArrayUsertype_ParamType { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassArrayUsertype_ParamType::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/params_pass_bool.rs b/spec/rust/src/formats/params_pass_bool.rs deleted file mode 100644 index e05e81f53..000000000 --- a/spec/rust/src/formats/params_pass_bool.rs +++ /dev/null @@ -1,150 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassBool { - pub s_false: bool, - pub s_true: bool, - pub seq_b1: Option, - pub seq_bool: Option, - pub literal_b1: Option, - pub literal_bool: Option, - pub inst_b1: Option, - pub inst_bool: Option, - pub v_false: Option, - pub v_true: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassBool { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.s_false = _io.read_bits_int(1)? != 0; - self.s_true = _io.read_bits_int(1)? != 0; - _io.align_to_byte()?; - self.seq_b1 = Some(Self::read_into::(Self::read_into::(self.s_true, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.seq_bool = Some(Self::read_into::(Self::read_into::(self.s_false, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.literal_b1 = Some(Self::read_into::(Self::read_into::(false, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.literal_bool = Some(Self::read_into::(Self::read_into::(true, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.inst_b1 = Some(Self::read_into::(Self::read_into::(self.v_true(_io, _root, _parent)?, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.inst_bool = Some(Self::read_into::(Self::read_into::(self.v_false(_io, _root, _parent)?, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassBool { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassBool::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn v_false( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.v_false.is_some() { - return Ok(self.v_false.as_ref().unwrap()); - } - self.v_false = Some(false as bool); - return Ok(self.v_false.as_ref().unwrap()); - } - fn v_true( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.v_true.is_some() { - return Ok(self.v_true.as_ref().unwrap()); - } - self.v_true = Some(true as bool); - return Ok(self.v_true.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassBool_ParamTypeB1 { - pub arg: bool, - pub foo: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassBool_ParamTypeB1 { - type Root = ParamsPassBool; - type ParentStack = (&'r ParamsPassBool, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_bytes(if self.arg { 1 } else { 2} as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassBool_ParamTypeB1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassBool_ParamTypeB1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassBool_ParamTypeBool { - pub arg: bool, - pub foo: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassBool_ParamTypeBool { - type Root = ParamsPassBool; - type ParentStack = (&'r ParamsPassBool, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_bytes(if self.arg { 1 } else { 2} as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassBool_ParamTypeBool { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassBool_ParamTypeBool::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/params_pass_usertype.rs b/spec/rust/src/formats/params_pass_usertype.rs deleted file mode 100644 index 909391db5..000000000 --- a/spec/rust/src/formats/params_pass_usertype.rs +++ /dev/null @@ -1,110 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassUsertype { - pub first: Option, - pub one: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassUsertype { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.first = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - self.one = Some(Self::read_into::(Self::read_into::(self.first, _io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassUsertype { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassUsertype::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassUsertype_Block { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassUsertype_Block { - type Root = ParamsPassUsertype; - type ParentStack = (&'r ParamsPassUsertype, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassUsertype_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassUsertype_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ParamsPassUsertype_ParamType { - pub foo: Option, - pub buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ParamsPassUsertype_ParamType { - type Root = ParamsPassUsertype; - type ParentStack = (&'r ParamsPassUsertype, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.buf = _io.read_bytes(self.foo.foo as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ParamsPassUsertype_ParamType { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ParamsPassUsertype_ParamType::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/position_abs.rs b/spec/rust/src/formats/position_abs.rs deleted file mode 100644 index 2cc648e8f..000000000 --- a/spec/rust/src/formats/position_abs.rs +++ /dev/null @@ -1,89 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct PositionAbs { - pub index_offset: u32, - pub index: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for PositionAbs { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.index_offset = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> PositionAbs { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = PositionAbs::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn index( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&PositionAbs_IndexObj> { - if self.index.is_some() { - return Ok(self.index.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, Name(identifier(index_offset))) - // popPos(_io) - return Ok(self.index.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct PositionAbs_IndexObj { - pub entry: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for PositionAbs_IndexObj { - type Root = PositionAbs; - type ParentStack = (&'r PositionAbs, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.entry = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> PositionAbs_IndexObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = PositionAbs_IndexObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/position_in_seq.rs b/spec/rust/src/formats/position_in_seq.rs deleted file mode 100644 index 546c0dc58..000000000 --- a/spec/rust/src/formats/position_in_seq.rs +++ /dev/null @@ -1,93 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct PositionInSeq { - pub numbers: Vec, - pub header: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for PositionInSeq { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.numbers = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(numbers), _io, Int1Type(false), Attribute(Name(identifier(header)),identifier(qty_numbers))) - // handleAssignmentRepeatExpr(NamedIdentifier(numbers), _io.read_u1()?) - } - Ok(()) - } -} -impl<'r, 's: 'r> PositionInSeq { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = PositionInSeq::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn header( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&PositionInSeq_HeaderObj> { - if self.header.is_some() { - return Ok(self.header.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(16)) - // popPos(_io) - return Ok(self.header.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct PositionInSeq_HeaderObj { - pub qty_numbers: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for PositionInSeq_HeaderObj { - type Root = PositionInSeq; - type ParentStack = (&'r PositionInSeq, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty_numbers = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> PositionInSeq_HeaderObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = PositionInSeq_HeaderObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/position_to_end.rs b/spec/rust/src/formats/position_to_end.rs deleted file mode 100644 index 2a2f62191..000000000 --- a/spec/rust/src/formats/position_to_end.rs +++ /dev/null @@ -1,89 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct PositionToEnd { - pub index: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for PositionToEnd { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> PositionToEnd { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = PositionToEnd::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn index( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&PositionToEnd_IndexObj> { - if self.index.is_some() { - return Ok(self.index.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, BinOp(Attribute(Name(identifier(_io)),identifier(size)),Sub,IntNum(8))) - // popPos(_io) - return Ok(self.index.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct PositionToEnd_IndexObj { - pub foo: u32, - pub bar: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for PositionToEnd_IndexObj { - type Root = PositionToEnd; - type ParentStack = (&'r PositionToEnd, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u4le()?; - self.bar = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> PositionToEnd_IndexObj { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = PositionToEnd_IndexObj::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_coerce_bytes.rs b/spec/rust/src/formats/process_coerce_bytes.rs deleted file mode 100644 index 26c30992c..000000000 --- a/spec/rust/src/formats/process_coerce_bytes.rs +++ /dev/null @@ -1,103 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceBytes { - pub records: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.records = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(records), _io, UserTypeInstream(List(record),None,List()), IntNum(2)) - // handleAssignmentRepeatExpr(NamedIdentifier(records), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -// extraAttrForIO(NamedIdentifier(buf_proc), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceBytes_Record { - pub flag: u8, - pub buf_unproc: Vec, - pub buf_proc: Vec, - pub raw_buf_proc: Vec, - pub buf: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceBytes_Record { - type Root = ProcessCoerceBytes; - type ParentStack = (&'r ProcessCoerceBytes, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.flag = _io.read_u1()?; - { - // condIfHeader(Compare(Name(identifier(flag)),Eq,IntNum(0))) - self.buf_unproc = _io.read_bytes(4 as usize)?.to_vec(); - } - { - // condIfHeader(Compare(Name(identifier(flag)),NotEq,IntNum(0))) - // attrProcess(ProcessXor(IntNum(170)), RawIdentifier(NamedIdentifier(buf_proc)), NamedIdentifier(buf_proc), NoRepeat) - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceBytes_Record { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceBytes_Record::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn buf( - &mut self, - _io: &'s S, - _root: Option<&'r ProcessCoerceBytes>, - _parent: Option>::ParentStack)>> - ) -> KResult<&Vec> { - if self.buf.is_some() { - return Ok(self.buf.as_ref().unwrap()); - } - self.buf = Some(if self.flag == 0 { self.buf_unproc } else { self.buf_proc} as Vec); - return Ok(self.buf.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/process_coerce_usertype1.rs b/spec/rust/src/formats/process_coerce_usertype1.rs deleted file mode 100644 index c9e4d0050..000000000 --- a/spec/rust/src/formats/process_coerce_usertype1.rs +++ /dev/null @@ -1,141 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceUsertype1 { - pub records: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype1 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.records = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(records), _io, UserTypeInstream(List(record),None,List()), IntNum(2)) - // handleAssignmentRepeatExpr(NamedIdentifier(records), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceUsertype1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceUsertype1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_unproc)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceUsertype1_Record { - pub flag: u8, - pub buf_unproc: Option, - pub buf_proc: Option, - pub raw_buf_unproc: Vec, - pub raw_buf_proc: Vec, - pub raw_raw_buf_proc: Vec, - pub buf: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype1_Record { - type Root = ProcessCoerceUsertype1; - type ParentStack = (&'r ProcessCoerceUsertype1, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.flag = _io.read_u1()?; - { - // condIfHeader(Compare(Name(identifier(flag)),Eq,IntNum(0))) - self.buf_unproc = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - } - { - // condIfHeader(Compare(Name(identifier(flag)),NotEq,IntNum(0))) - // attrProcess(ProcessXor(IntNum(170)), RawIdentifier(RawIdentifier(NamedIdentifier(buf_proc))), RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) - self.buf_proc = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceUsertype1_Record { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceUsertype1_Record::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn buf( - &mut self, - _io: &'s S, - _root: Option<&'r ProcessCoerceUsertype1>, - _parent: Option>::ParentStack)>> - ) -> KResult<&ProcessCoerceUsertype1_Foo> { - if self.buf.is_some() { - return Ok(self.buf.as_ref().unwrap()); - } - self.buf = Some(if self.flag == 0 { self.buf_unproc } else { self.buf_proc} as Foo); - return Ok(self.buf.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceUsertype1_Foo { - pub value: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype1_Foo { - type Root = ProcessCoerceUsertype1; - type ParentStack = (&'r ProcessCoerceUsertype1, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceUsertype1_Foo { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceUsertype1_Foo::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_coerce_usertype2.rs b/spec/rust/src/formats/process_coerce_usertype2.rs deleted file mode 100644 index 49bed3f23..000000000 --- a/spec/rust/src/formats/process_coerce_usertype2.rs +++ /dev/null @@ -1,139 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceUsertype2 { - pub records: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.records = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(records), _io, UserTypeInstream(List(record),None,List()), IntNum(2)) - // handleAssignmentRepeatExpr(NamedIdentifier(records), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceUsertype2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceUsertype2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceUsertype2_Record { - pub flag: u8, - pub buf_unproc: Option, - pub buf_proc: Option, - pub raw_buf_proc: Vec, - pub raw_raw_buf_proc: Vec, - pub buf: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype2_Record { - type Root = ProcessCoerceUsertype2; - type ParentStack = (&'r ProcessCoerceUsertype2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.flag = _io.read_u1()?; - { - // condIfHeader(Compare(Name(identifier(flag)),Eq,IntNum(0))) - self.buf_unproc = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - } - { - // condIfHeader(Compare(Name(identifier(flag)),NotEq,IntNum(0))) - // attrProcess(ProcessXor(IntNum(170)), RawIdentifier(RawIdentifier(NamedIdentifier(buf_proc))), RawIdentifier(NamedIdentifier(buf_proc)), NoRepeat) - self.buf_proc = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(4 as usize)?), Some(self), _parent.push(self))?); - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceUsertype2_Record { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceUsertype2_Record::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn buf( - &mut self, - _io: &'s S, - _root: Option<&'r ProcessCoerceUsertype2>, - _parent: Option>::ParentStack)>> - ) -> KResult<&ProcessCoerceUsertype2_Foo> { - if self.buf.is_some() { - return Ok(self.buf.as_ref().unwrap()); - } - self.buf = Some(if self.flag == 0 { self.buf_unproc } else { self.buf_proc} as Foo); - return Ok(self.buf.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCoerceUsertype2_Foo { - pub value: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCoerceUsertype2_Foo { - type Root = ProcessCoerceUsertype2; - type ParentStack = (&'r ProcessCoerceUsertype2, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCoerceUsertype2_Foo { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCoerceUsertype2_Foo::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_custom.rs b/spec/rust/src/formats/process_custom.rs deleted file mode 100644 index 844a8b4ad..000000000 --- a/spec/rust/src/formats/process_custom.rs +++ /dev/null @@ -1,53 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(buf1), NoRepeat) -// extraAttrForIO(NamedIdentifier(buf2), NoRepeat) -// extraAttrForIO(NamedIdentifier(buf3), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCustom { - pub buf1: Vec, - pub buf2: Vec, - pub key: u8, - pub buf3: Vec, - pub raw_buf1: Vec, - pub raw_buf2: Vec, - pub raw_buf3: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCustom { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - // attrProcess(ProcessCustom(List(my_custom_fx),ArrayBuffer(IntNum(7), Bool(true), List(ArrayBuffer(IntNum(32), IntNum(48), IntNum(64))))), RawIdentifier(NamedIdentifier(buf1)), NamedIdentifier(buf1), NoRepeat) - // attrProcess(ProcessCustom(List(nested, deeply, custom_fx),ArrayBuffer(IntNum(7))), RawIdentifier(NamedIdentifier(buf2)), NamedIdentifier(buf2), NoRepeat) - self.key = _io.read_u1()?; - // attrProcess(ProcessCustom(List(my_custom_fx),ArrayBuffer(Name(identifier(key)), Bool(false), List(ArrayBuffer(IntNum(0))))), RawIdentifier(NamedIdentifier(buf3)), NamedIdentifier(buf3), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCustom { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCustom::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_custom_no_args.rs b/spec/rust/src/formats/process_custom_no_args.rs deleted file mode 100644 index 415825d80..000000000 --- a/spec/rust/src/formats/process_custom_no_args.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(buf), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessCustomNoArgs { - pub buf: Vec, - pub raw_buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessCustomNoArgs { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - // attrProcess(ProcessCustom(List(custom_fx_no_args),List()), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ProcessCustomNoArgs { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessCustomNoArgs::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_repeat_bytes.rs b/spec/rust/src/formats/process_repeat_bytes.rs deleted file mode 100644 index 8dc31fec0..000000000 --- a/spec/rust/src/formats/process_repeat_bytes.rs +++ /dev/null @@ -1,48 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(bufs), RepeatExpr(IntNum(2))) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessRepeatBytes { - pub bufs: Vec>, - pub raw_bufs: Vec>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRepeatBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.bufs = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(bufs), _io, BytesLimitType(IntNum(5),None,false,None,Some(ProcessXor(IntNum(158)))), IntNum(2)) - // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(bufs)), _io.read_bytes(5 as usize)?) - // attrProcess(ProcessXor(IntNum(158)), RawIdentifier(NamedIdentifier(bufs)), NamedIdentifier(bufs), RepeatExpr(IntNum(2))) - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessRepeatBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessRepeatBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_repeat_usertype.rs b/spec/rust/src/formats/process_repeat_usertype.rs deleted file mode 100644 index 7256f775a..000000000 --- a/spec/rust/src/formats/process_repeat_usertype.rs +++ /dev/null @@ -1,86 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(blocks)), RepeatExpr(IntNum(2))) -// extraAttrForIO(RawIdentifier(NamedIdentifier(blocks)), RepeatExpr(IntNum(2))) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessRepeatUsertype { - pub blocks: Vec, - pub raw_blocks: Vec>, - pub raw_raw_blocks: Vec>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRepeatUsertype { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.blocks = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(blocks), _io, UserTypeFromBytes(List(block),None,List(),BytesLimitType(IntNum(5),None,false,None,Some(ProcessXor(IntNum(158)))),Some(ProcessXor(IntNum(158)))), IntNum(2)) - // handleAssignmentRepeatExpr(RawIdentifier(RawIdentifier(NamedIdentifier(blocks))), _io.read_bytes(5 as usize)?) - // attrProcess(ProcessXor(IntNum(158)), RawIdentifier(RawIdentifier(NamedIdentifier(blocks))), RawIdentifier(NamedIdentifier(blocks)), RepeatExpr(IntNum(2))) - // handleAssignmentRepeatExpr(NamedIdentifier(blocks), &BytesReader::new(_io.read_bytes(5 as usize)?)) - } - Ok(()) - } -} -impl<'r, 's: 'r> ProcessRepeatUsertype { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessRepeatUsertype::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessRepeatUsertype_Block { - pub a: i32, - pub b: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRepeatUsertype_Block { - type Root = ProcessRepeatUsertype; - type ParentStack = (&'r ProcessRepeatUsertype, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_s4le()?; - self.b = _io.read_s1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ProcessRepeatUsertype_Block { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessRepeatUsertype_Block::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_rotate.rs b/spec/rust/src/formats/process_rotate.rs deleted file mode 100644 index d17b69b80..000000000 --- a/spec/rust/src/formats/process_rotate.rs +++ /dev/null @@ -1,53 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(buf1), NoRepeat) -// extraAttrForIO(NamedIdentifier(buf2), NoRepeat) -// extraAttrForIO(NamedIdentifier(buf3), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessRotate { - pub buf1: Vec, - pub buf2: Vec, - pub key: u8, - pub buf3: Vec, - pub raw_buf1: Vec, - pub raw_buf2: Vec, - pub raw_buf3: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessRotate { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - // attrProcess(ProcessRotate(true,IntNum(3)), RawIdentifier(NamedIdentifier(buf1)), NamedIdentifier(buf1), NoRepeat) - // attrProcess(ProcessRotate(false,IntNum(3)), RawIdentifier(NamedIdentifier(buf2)), NamedIdentifier(buf2), NoRepeat) - self.key = _io.read_u1()?; - // attrProcess(ProcessRotate(true,Name(identifier(key))), RawIdentifier(NamedIdentifier(buf3)), NamedIdentifier(buf3), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ProcessRotate { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessRotate::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_to_user.rs b/spec/rust/src/formats/process_to_user.rs deleted file mode 100644 index 45aa800bd..000000000 --- a/spec/rust/src/formats/process_to_user.rs +++ /dev/null @@ -1,79 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf1)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(buf1)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessToUser { - pub buf1: Option, - pub raw_buf1: Vec, - pub raw_raw_buf1: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessToUser { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - // attrProcess(ProcessRotate(true,IntNum(3)), RawIdentifier(RawIdentifier(NamedIdentifier(buf1))), RawIdentifier(NamedIdentifier(buf1)), NoRepeat) - self.buf1 = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(5 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> ProcessToUser { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessToUser::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessToUser_JustStr { - pub str: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessToUser_JustStr { - type Root = ProcessToUser; - type ParentStack = (&'r ProcessToUser, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.str = decode_string(_io.read_bytes_full()?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> ProcessToUser_JustStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessToUser_JustStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_xor4_const.rs b/spec/rust/src/formats/process_xor4_const.rs deleted file mode 100644 index 60f0a651e..000000000 --- a/spec/rust/src/formats/process_xor4_const.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(buf), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessXor4Const { - pub key: Vec, - pub buf: Vec, - pub raw_buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXor4Const { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.key = _io.read_bytes(4 as usize)?.to_vec(); - // attrProcess(ProcessXor(List(ArrayBuffer(IntNum(236), IntNum(187), IntNum(163), IntNum(20)))), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ProcessXor4Const { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessXor4Const::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_xor4_value.rs b/spec/rust/src/formats/process_xor4_value.rs deleted file mode 100644 index 858cd36e1..000000000 --- a/spec/rust/src/formats/process_xor4_value.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(buf), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessXor4Value { - pub key: Vec, - pub buf: Vec, - pub raw_buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXor4Value { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.key = _io.read_bytes(4 as usize)?.to_vec(); - // attrProcess(ProcessXor(Name(identifier(key))), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ProcessXor4Value { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessXor4Value::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_xor_const.rs b/spec/rust/src/formats/process_xor_const.rs deleted file mode 100644 index 51ea1a7d7..000000000 --- a/spec/rust/src/formats/process_xor_const.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(buf), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessXorConst { - pub key: u8, - pub buf: Vec, - pub raw_buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXorConst { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.key = _io.read_u1()?; - // attrProcess(ProcessXor(IntNum(255)), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ProcessXorConst { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessXorConst::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/process_xor_value.rs b/spec/rust/src/formats/process_xor_value.rs deleted file mode 100644 index 535908a4d..000000000 --- a/spec/rust/src/formats/process_xor_value.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(buf), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ProcessXorValue { - pub key: u8, - pub buf: Vec, - pub raw_buf: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ProcessXorValue { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.key = _io.read_u1()?; - // attrProcess(ProcessXor(Name(identifier(key))), RawIdentifier(NamedIdentifier(buf)), NamedIdentifier(buf), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ProcessXorValue { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ProcessXorValue::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/recursive_one.rs b/spec/rust/src/formats/recursive_one.rs deleted file mode 100644 index 152188b6f..000000000 --- a/spec/rust/src/formats/recursive_one.rs +++ /dev/null @@ -1,106 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RecursiveOne { - pub one: u8, - pub next: Option, -} -#[derive(Debug, PartialEq)] -pub enum RecursiveOne_Next { - RecursiveOne(Box), - RecursiveOne_Fini(RecursiveOne_Fini), -} -impl From> for RecursiveOne_Next { - fn from(v: Box) -> Self { - Self::RecursiveOne(v) - } -} -impl From for RecursiveOne_Next { - fn from(v: RecursiveOne_Fini) -> Self { - Self::RecursiveOne_Fini(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for RecursiveOne { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = _io.read_u1()?; - match (self.one & 3) { - 0 => { - self.next = Some(Self::read_into::(_io)?.into()); - } - 1 => { - self.next = Some(Self::read_into::(_io)?.into()); - } - 2 => { - self.next = Some(Self::read_into::(_io)?.into()); - } - 3 => { - self.next = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> RecursiveOne { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RecursiveOne::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct RecursiveOne_Fini { - pub finisher: u16, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RecursiveOne_Fini { - type Root = RecursiveOne; - type ParentStack = (&'r RecursiveOne, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.finisher = _io.read_u2le()?; - Ok(()) - } -} -impl<'r, 's: 'r> RecursiveOne_Fini { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RecursiveOne_Fini::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_eos_bit.rs b/spec/rust/src/formats/repeat_eos_bit.rs deleted file mode 100644 index 538e3a47b..000000000 --- a/spec/rust/src/formats/repeat_eos_bit.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatEosBit { - pub nibbles: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosBit { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.nibbles = Vec::new(); - { - type ArrayElement = u64; - while !_io.is_eof() { - self.nibbles.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatEosBit { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatEosBit::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_eos_struct.rs b/spec/rust/src/formats/repeat_eos_struct.rs deleted file mode 100644 index 01fe73f0a..000000000 --- a/spec/rust/src/formats/repeat_eos_struct.rs +++ /dev/null @@ -1,82 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatEosStruct { - pub chunks: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosStruct { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.chunks = Vec::new(); - { - type ArrayElement = RepeatEosStruct_Chunk; - while !_io.is_eof() { - self.chunks.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatEosStruct { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatEosStruct::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatEosStruct_Chunk { - pub offset: u32, - pub len: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosStruct_Chunk { - type Root = RepeatEosStruct; - type ParentStack = (&'r RepeatEosStruct, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.offset = _io.read_u4le()?; - self.len = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> RepeatEosStruct_Chunk { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatEosStruct_Chunk::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_eos_u4.rs b/spec/rust/src/formats/repeat_eos_u4.rs deleted file mode 100644 index 7e14baaf2..000000000 --- a/spec/rust/src/formats/repeat_eos_u4.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatEosU4 { - pub numbers: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatEosU4 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.numbers = Vec::new(); - { - type ArrayElement = u32; - while !_io.is_eof() { - self.numbers.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatEosU4 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatEosU4::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_n_struct.rs b/spec/rust/src/formats/repeat_n_struct.rs deleted file mode 100644 index 5420796b3..000000000 --- a/spec/rust/src/formats/repeat_n_struct.rs +++ /dev/null @@ -1,82 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatNStruct { - pub qty: u32, - pub chunks: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStruct { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty = _io.read_u4le()?; - self.chunks = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(chunks), _io, UserTypeInstream(List(chunk),None,List()), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(chunks), Self::read_into::(_io, _root, _parent.push(self))?.into()) - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatNStruct { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatNStruct::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatNStruct_Chunk { - pub offset: u32, - pub len: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStruct_Chunk { - type Root = RepeatNStruct; - type ParentStack = (&'r RepeatNStruct, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.offset = _io.read_u4le()?; - self.len = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> RepeatNStruct_Chunk { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatNStruct_Chunk::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_n_strz.rs b/spec/rust/src/formats/repeat_n_strz.rs deleted file mode 100644 index 85969ae76..000000000 --- a/spec/rust/src/formats/repeat_n_strz.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatNStrz { - pub qty: u32, - pub lines: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStrz { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty = _io.read_u4le()?; - self.lines = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(lines), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), Name(identifier(qty))) - // handleAssignmentRepeatExpr(NamedIdentifier(lines), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatNStrz { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatNStrz::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_n_strz_double.rs b/spec/rust/src/formats/repeat_n_strz_double.rs deleted file mode 100644 index ef1a1a346..000000000 --- a/spec/rust/src/formats/repeat_n_strz_double.rs +++ /dev/null @@ -1,53 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatNStrzDouble { - pub qty: u32, - pub lines1: Vec, - pub lines2: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatNStrzDouble { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.qty = _io.read_u4le()?; - self.lines1 = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(lines1), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), BinOp(Name(identifier(qty)),Div,IntNum(2))) - // handleAssignmentRepeatExpr(NamedIdentifier(lines1), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) - } - self.lines2 = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(lines2), _io, StrFromBytesType(BytesTerminatedType(0,false,true,true,None),UTF-8), BinOp(Name(identifier(qty)),Div,IntNum(2))) - // handleAssignmentRepeatExpr(NamedIdentifier(lines2), decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?) - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatNStrzDouble { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatNStrzDouble::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_until_complex.rs b/spec/rust/src/formats/repeat_until_complex.rs deleted file mode 100644 index 2917034a9..000000000 --- a/spec/rust/src/formats/repeat_until_complex.rs +++ /dev/null @@ -1,138 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatUntilComplex { - pub first: Vec, - pub second: Vec, - pub third: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilComplex { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.first = Vec::new(); - { - // condRepeatUntilHeader(NamedIdentifier(first), _io, UserTypeInstream(List(type_u1),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) - // handleAssignmentRepeatUntil(NamedIdentifier(first), Self::read_into::(_io, _root, _parent.push(self))?.into(), false) - // condRepeatUntilFooter(NamedIdentifier(first), _io, UserTypeInstream(List(type_u1),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) - } {} - self.second = Vec::new(); - { - // condRepeatUntilHeader(NamedIdentifier(second), _io, UserTypeInstream(List(type_u2),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) - // handleAssignmentRepeatUntil(NamedIdentifier(second), Self::read_into::(_io, _root, _parent.push(self))?.into(), false) - // condRepeatUntilFooter(NamedIdentifier(second), _io, UserTypeInstream(List(type_u2),None,List()), Compare(Attribute(Name(identifier(_)),identifier(count)),Eq,IntNum(0))) - } {} - self.third = Vec::new(); - { - // condRepeatUntilHeader(NamedIdentifier(third), _io, Int1Type(false), Compare(Name(identifier(_)),Eq,IntNum(0))) - // handleAssignmentRepeatUntil(NamedIdentifier(third), _io.read_u1()?, false) - // condRepeatUntilFooter(NamedIdentifier(third), _io, Int1Type(false), Compare(Name(identifier(_)),Eq,IntNum(0))) - } {} - Ok(()) - } -} -impl<'r, 's: 'r> RepeatUntilComplex { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatUntilComplex::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatUntilComplex_TypeU1 { - pub count: u8, - pub values: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilComplex_TypeU1 { - type Root = RepeatUntilComplex; - type ParentStack = (&'r RepeatUntilComplex, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.count = _io.read_u1()?; - self.values = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(values), _io, Int1Type(false), Name(identifier(count))) - // handleAssignmentRepeatExpr(NamedIdentifier(values), _io.read_u1()?) - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatUntilComplex_TypeU1 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatUntilComplex_TypeU1::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatUntilComplex_TypeU2 { - pub count: u16, - pub values: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilComplex_TypeU2 { - type Root = RepeatUntilComplex; - type ParentStack = (&'r RepeatUntilComplex, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.count = _io.read_u2le()?; - self.values = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(values), _io, IntMultiType(false,Width2,Some(LittleEndian)), Name(identifier(count))) - // handleAssignmentRepeatExpr(NamedIdentifier(values), _io.read_u2le()?) - } - Ok(()) - } -} -impl<'r, 's: 'r> RepeatUntilComplex_TypeU2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatUntilComplex_TypeU2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_until_s4.rs b/spec/rust/src/formats/repeat_until_s4.rs deleted file mode 100644 index e5b5cc99a..000000000 --- a/spec/rust/src/formats/repeat_until_s4.rs +++ /dev/null @@ -1,48 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatUntilS4 { - pub entries: Vec, - pub afterall: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilS4 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.entries = Vec::new(); - { - // condRepeatUntilHeader(NamedIdentifier(entries), _io, IntMultiType(true,Width4,Some(LittleEndian)), Compare(Name(identifier(_)),Eq,UnaryOp(Minus,IntNum(1)))) - // handleAssignmentRepeatUntil(NamedIdentifier(entries), _io.read_s4le()?, false) - // condRepeatUntilFooter(NamedIdentifier(entries), _io, IntMultiType(true,Width4,Some(LittleEndian)), Compare(Name(identifier(_)),Eq,UnaryOp(Minus,IntNum(1)))) - } {} - self.afterall = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> RepeatUntilS4 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatUntilS4::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/repeat_until_sized.rs b/spec/rust/src/formats/repeat_until_sized.rs deleted file mode 100644 index 5c830a964..000000000 --- a/spec/rust/src/formats/repeat_until_sized.rs +++ /dev/null @@ -1,84 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(records)), RepeatUntil(Compare(Attribute(Name(identifier(_)),identifier(marker)),Eq,IntNum(170)))) - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatUntilSized { - pub records: Vec, - pub raw_records: Vec>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilSized { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.records = Vec::new(); - { - // condRepeatUntilHeader(NamedIdentifier(records), _io, UserTypeFromBytes(List(record),None,List(),BytesLimitType(IntNum(5),None,false,None,None),None), Compare(Attribute(Name(identifier(_)),identifier(marker)),Eq,IntNum(170))) - // handleAssignmentRepeatUntil(RawIdentifier(NamedIdentifier(records)), _io.read_bytes(5 as usize)?, true) - // handleAssignmentRepeatUntil(NamedIdentifier(records), &BytesReader::new(_io.read_bytes(5 as usize)?), false) - // condRepeatUntilFooter(NamedIdentifier(records), _io, UserTypeFromBytes(List(record),None,List(),BytesLimitType(IntNum(5),None,false,None,None),None), Compare(Attribute(Name(identifier(_)),identifier(marker)),Eq,IntNum(170))) - } {} - Ok(()) - } -} -impl<'r, 's: 'r> RepeatUntilSized { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatUntilSized::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct RepeatUntilSized_Record { - pub marker: u8, - pub body: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for RepeatUntilSized_Record { - type Root = RepeatUntilSized; - type ParentStack = (&'r RepeatUntilSized, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.marker = _io.read_u1()?; - self.body = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> RepeatUntilSized_Record { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = RepeatUntilSized_Record::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/str_encodings.rs b/spec/rust/src/formats/str_encodings.rs deleted file mode 100644 index a0b5c91bb..000000000 --- a/spec/rust/src/formats/str_encodings.rs +++ /dev/null @@ -1,55 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct StrEncodings { - pub len_of_1: u16, - pub str1: String, - pub len_of_2: u16, - pub str2: String, - pub len_of_3: u16, - pub str3: String, - pub len_of_4: u16, - pub str4: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodings { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_of_1 = _io.read_u2le()?; - self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "ASCII")?; - self.len_of_2 = _io.read_u2le()?; - self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; - self.len_of_3 = _io.read_u2le()?; - self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; - self.len_of_4 = _io.read_u2le()?; - self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; - Ok(()) - } -} -impl<'r, 's: 'r> StrEncodings { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrEncodings::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/str_encodings_default.rs b/spec/rust/src/formats/str_encodings_default.rs deleted file mode 100644 index 5258a526c..000000000 --- a/spec/rust/src/formats/str_encodings_default.rs +++ /dev/null @@ -1,88 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct StrEncodingsDefault { - pub len_of_1: u16, - pub str1: String, - pub rest: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsDefault { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_of_1 = _io.read_u2le()?; - self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "UTF-8")?; - self.rest = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> StrEncodingsDefault { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrEncodingsDefault::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct StrEncodingsDefault_Subtype { - pub len_of_2: u16, - pub str2: String, - pub len_of_3: u16, - pub str3: String, - pub len_of_4: u16, - pub str4: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsDefault_Subtype { - type Root = StrEncodingsDefault; - type ParentStack = (&'r StrEncodingsDefault, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_of_2 = _io.read_u2le()?; - self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; - self.len_of_3 = _io.read_u2le()?; - self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; - self.len_of_4 = _io.read_u2le()?; - self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; - Ok(()) - } -} -impl<'r, 's: 'r> StrEncodingsDefault_Subtype { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrEncodingsDefault_Subtype::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/str_encodings_utf16.rs b/spec/rust/src/formats/str_encodings_utf16.rs deleted file mode 100644 index 6b1c7def4..000000000 --- a/spec/rust/src/formats/str_encodings_utf16.rs +++ /dev/null @@ -1,121 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(be_bom_removed)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(le_bom_removed)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct StrEncodingsUtf16 { - pub len_be: u32, - pub be_bom_removed: Option, - pub len_le: u32, - pub le_bom_removed: Option, - pub raw_be_bom_removed: Vec, - pub raw_le_bom_removed: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsUtf16 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_be = _io.read_u4le()?; - self.be_bom_removed = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len_be as usize)?), Some(self), _parent.push(self))?); - self.len_le = _io.read_u4le()?; - self.le_bom_removed = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(self.len_le as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> StrEncodingsUtf16 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrEncodingsUtf16::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct StrEncodingsUtf16_StrBeBomRemoved { - pub bom: u16, - pub str: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsUtf16_StrBeBomRemoved { - type Root = StrEncodingsUtf16; - type ParentStack = (&'r StrEncodingsUtf16, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.bom = _io.read_u2be()?; - self.str = decode_string(_io.read_bytes_full()?, "UTF-16BE")?; - Ok(()) - } -} -impl<'r, 's: 'r> StrEncodingsUtf16_StrBeBomRemoved { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrEncodingsUtf16_StrBeBomRemoved::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct StrEncodingsUtf16_StrLeBomRemoved { - pub bom: u16, - pub str: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrEncodingsUtf16_StrLeBomRemoved { - type Root = StrEncodingsUtf16; - type ParentStack = (&'r StrEncodingsUtf16, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.bom = _io.read_u2le()?; - self.str = decode_string(_io.read_bytes_full()?, "UTF-16LE")?; - Ok(()) - } -} -impl<'r, 's: 'r> StrEncodingsUtf16_StrLeBomRemoved { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrEncodingsUtf16_StrLeBomRemoved::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/str_eos.rs b/spec/rust/src/formats/str_eos.rs deleted file mode 100644 index 8eb6f220b..000000000 --- a/spec/rust/src/formats/str_eos.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct StrEos { - pub str: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrEos { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.str = decode_string(_io.read_bytes_full()?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> StrEos { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrEos::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/str_literals.rs b/spec/rust/src/formats/str_literals.rs deleted file mode 100644 index 71e2e76fa..000000000 --- a/spec/rust/src/formats/str_literals.rs +++ /dev/null @@ -1,104 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct StrLiterals { - pub octal_eatup2: Option, - pub backslashes: Option, - pub octal_eatup: Option, - pub double_quotes: Option, - pub complex_str: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrLiterals { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> StrLiterals { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrLiterals::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn octal_eatup2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.octal_eatup2.is_some() { - return Ok(self.octal_eatup2.as_ref().unwrap()); - } - self.octal_eatup2 = Some("\u{2}2".to_string()); - return Ok(self.octal_eatup2.as_ref().unwrap()); - } - fn backslashes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.backslashes.is_some() { - return Ok(self.backslashes.as_ref().unwrap()); - } - self.backslashes = Some("\\\\\\".to_string()); - return Ok(self.backslashes.as_ref().unwrap()); - } - fn octal_eatup( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.octal_eatup.is_some() { - return Ok(self.octal_eatup.as_ref().unwrap()); - } - self.octal_eatup = Some("\u{0}22".to_string()); - return Ok(self.octal_eatup.as_ref().unwrap()); - } - fn double_quotes( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.double_quotes.is_some() { - return Ok(self.double_quotes.as_ref().unwrap()); - } - self.double_quotes = Some("\"\"\"".to_string()); - return Ok(self.double_quotes.as_ref().unwrap()); - } - fn complex_str( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.complex_str.is_some() { - return Ok(self.complex_str.as_ref().unwrap()); - } - self.complex_str = Some("\u{0}\u{1}\u{2}\u{7}\u{8}\n\r\t\u{b}\u{c}\u{1b}=\u{7}\n$\u{263b}".to_string()); - return Ok(self.complex_str.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/str_literals2.rs b/spec/rust/src/formats/str_literals2.rs deleted file mode 100644 index 338e684b1..000000000 --- a/spec/rust/src/formats/str_literals2.rs +++ /dev/null @@ -1,91 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct StrLiterals2 { - pub dollar1: Option, - pub dollar2: Option, - pub hash: Option, - pub at_sign: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrLiterals2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> StrLiterals2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrLiterals2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn dollar1( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.dollar1.is_some() { - return Ok(self.dollar1.as_ref().unwrap()); - } - self.dollar1 = Some("$foo".to_string()); - return Ok(self.dollar1.as_ref().unwrap()); - } - fn dollar2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.dollar2.is_some() { - return Ok(self.dollar2.as_ref().unwrap()); - } - self.dollar2 = Some("${foo}".to_string()); - return Ok(self.dollar2.as_ref().unwrap()); - } - fn hash( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.hash.is_some() { - return Ok(self.hash.as_ref().unwrap()); - } - self.hash = Some("#{foo}".to_string()); - return Ok(self.hash.as_ref().unwrap()); - } - fn at_sign( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.at_sign.is_some() { - return Ok(self.at_sign.as_ref().unwrap()); - } - self.at_sign = Some("@foo".to_string()); - return Ok(self.at_sign.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/str_pad_term.rs b/spec/rust/src/formats/str_pad_term.rs deleted file mode 100644 index c033ba432..000000000 --- a/spec/rust/src/formats/str_pad_term.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct StrPadTerm { - pub str_pad: String, - pub str_term: String, - pub str_term_and_pad: String, - pub str_term_include: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrPadTerm { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.str_pad = decode_string(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 64), "UTF-8")?; - self.str_term = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, false), "UTF-8")?; - self.str_term_and_pad = decode_string(_io.bytes_terminate(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 43), 64, false), "UTF-8")?; - self.str_term_include = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, true), "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> StrPadTerm { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrPadTerm::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/str_pad_term_empty.rs b/spec/rust/src/formats/str_pad_term_empty.rs deleted file mode 100644 index e241a4117..000000000 --- a/spec/rust/src/formats/str_pad_term_empty.rs +++ /dev/null @@ -1,47 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct StrPadTermEmpty { - pub str_pad: String, - pub str_term: String, - pub str_term_and_pad: String, - pub str_term_include: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for StrPadTermEmpty { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.str_pad = decode_string(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 64), "UTF-8")?; - self.str_term = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, false), "UTF-8")?; - self.str_term_and_pad = decode_string(_io.bytes_terminate(_io.bytes_strip_right(_io.read_bytes(20 as usize)?, 43), 64, false), "UTF-8")?; - self.str_term_include = decode_string(_io.bytes_terminate(_io.read_bytes(20 as usize)?, 64, true), "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> StrPadTermEmpty { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = StrPadTermEmpty::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_bytearray.rs b/spec/rust/src/formats/switch_bytearray.rs deleted file mode 100644 index 7a2403b4a..000000000 --- a/spec/rust/src/formats/switch_bytearray.rs +++ /dev/null @@ -1,172 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchBytearray { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchBytearray_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchBytearray { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchBytearray::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchBytearray_Opcode { - pub code: Vec, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchBytearray_Opcode_Body { - SwitchBytearray_Opcode_Intval(SwitchBytearray_Opcode_Intval), - SwitchBytearray_Opcode_Strval(SwitchBytearray_Opcode_Strval), -} -impl From for SwitchBytearray_Opcode_Body { - fn from(v: SwitchBytearray_Opcode_Intval) -> Self { - Self::SwitchBytearray_Opcode_Intval(v) - } -} -impl From for SwitchBytearray_Opcode_Body { - fn from(v: SwitchBytearray_Opcode_Strval) -> Self { - Self::SwitchBytearray_Opcode_Strval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray_Opcode { - type Root = SwitchBytearray; - type ParentStack = (&'r SwitchBytearray, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_bytes(1 as usize)?.to_vec(); - { - let on = &self.code; - if on == &[0x49] { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - else if on == &[0x53] { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchBytearray_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchBytearray_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchBytearray_Opcode_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray_Opcode_Intval { - type Root = SwitchBytearray; - type ParentStack = (&'r SwitchBytearray_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchBytearray_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchBytearray_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchBytearray_Opcode_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchBytearray_Opcode_Strval { - type Root = SwitchBytearray; - type ParentStack = (&'r SwitchBytearray_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchBytearray_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchBytearray_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_cast.rs b/spec/rust/src/formats/switch_cast.rs deleted file mode 100644 index 366d238af..000000000 --- a/spec/rust/src/formats/switch_cast.rs +++ /dev/null @@ -1,211 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchCast { - pub opcodes: Vec, - pub first_obj: Option, - pub second_val: Option, - pub err_cast: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchCast_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchCast { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchCast::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn first_obj( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&SwitchCast_Strval> { - if self.first_obj.is_some() { - return Ok(self.first_obj.as_ref().unwrap()); - } - self.first_obj = Some(self.opcodes[0 as usize].body as SwitchCast_Strval); - return Ok(self.first_obj.as_ref().unwrap()); - } - fn second_val( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.second_val.is_some() { - return Ok(self.second_val.as_ref().unwrap()); - } - self.second_val = Some(self.opcodes[1 as usize].body.value as u8); - return Ok(self.second_val.as_ref().unwrap()); - } - fn err_cast( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&SwitchCast_Strval> { - if self.err_cast.is_some() { - return Ok(self.err_cast.as_ref().unwrap()); - } - self.err_cast = Some(self.opcodes[2 as usize].body as SwitchCast_Strval); - return Ok(self.err_cast.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchCast_Opcode { - pub code: u8, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchCast_Opcode_Body { - SwitchCast_Intval(SwitchCast_Intval), - SwitchCast_Strval(SwitchCast_Strval), -} -impl From for SwitchCast_Opcode_Body { - fn from(v: SwitchCast_Intval) -> Self { - Self::SwitchCast_Intval(v) - } -} -impl From for SwitchCast_Opcode_Body { - fn from(v: SwitchCast_Strval) -> Self { - Self::SwitchCast_Strval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast_Opcode { - type Root = SwitchCast; - type ParentStack = (&'r SwitchCast, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - match self.code { - 73 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - 83 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchCast_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchCast_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchCast_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast_Intval { - type Root = SwitchCast; - type ParentStack = (&'r SwitchCast, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchCast_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchCast_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchCast_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchCast_Strval { - type Root = SwitchCast; - type ParentStack = (&'r SwitchCast, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchCast_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchCast_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_else_only.rs b/spec/rust/src/formats/switch_else_only.rs deleted file mode 100644 index 3ebcc4b83..000000000 --- a/spec/rust/src/formats/switch_else_only.rs +++ /dev/null @@ -1,100 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchElseOnly { - pub opcode: i8, - pub prim_byte: Option, - pub indicator: Vec, - pub ut: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchElseOnly_PrimByte { - S1(i8), -} -impl From for SwitchElseOnly_PrimByte { - fn from(v: i8) -> Self { - Self::S1(v) - } -} - -#[derive(Debug, PartialEq)] -pub enum SwitchElseOnly_Ut { - SwitchElseOnly_Data(SwitchElseOnly_Data), -} -impl From for SwitchElseOnly_Ut { - fn from(v: SwitchElseOnly_Data) -> Self { - Self::SwitchElseOnly_Data(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchElseOnly { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcode = _io.read_s1()?; - self.prim_byte = Some(_io.read_s1()?); - self.indicator = _io.read_bytes(4 as usize)?.to_vec(); - self.ut = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - Ok(()) - } -} -impl<'r, 's: 'r> SwitchElseOnly { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchElseOnly::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchElseOnly_Data { - pub value: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchElseOnly_Data { - type Root = SwitchElseOnly; - type ParentStack = (&'r SwitchElseOnly, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_bytes(4 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> SwitchElseOnly_Data { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchElseOnly_Data::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_integers.rs b/spec/rust/src/formats/switch_integers.rs deleted file mode 100644 index 26c040c4f..000000000 --- a/spec/rust/src/formats/switch_integers.rs +++ /dev/null @@ -1,124 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchIntegers { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchIntegers { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchIntegers_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchIntegers { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchIntegers::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchIntegers_Opcode { - pub code: u8, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchIntegers_Opcode_Body { - U1(u8), - U2(u16), - U4(u32), - U8(u64), -} -impl From for SwitchIntegers_Opcode_Body { - fn from(v: u8) -> Self { - Self::U1(v) - } -} -impl From for SwitchIntegers_Opcode_Body { - fn from(v: u16) -> Self { - Self::U2(v) - } -} -impl From for SwitchIntegers_Opcode_Body { - fn from(v: u32) -> Self { - Self::U4(v) - } -} -impl From for SwitchIntegers_Opcode_Body { - fn from(v: u64) -> Self { - Self::U8(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchIntegers_Opcode { - type Root = SwitchIntegers; - type ParentStack = (&'r SwitchIntegers, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - match self.code { - 1 => { - self.body = Some(_io.read_u1()?); - } - 2 => { - self.body = Some(_io.read_u2le()?); - } - 4 => { - self.body = Some(_io.read_u4le()?); - } - 8 => { - self.body = Some(_io.read_u8le()?); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchIntegers_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchIntegers_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_integers2.rs b/spec/rust/src/formats/switch_integers2.rs deleted file mode 100644 index 64aff3d30..000000000 --- a/spec/rust/src/formats/switch_integers2.rs +++ /dev/null @@ -1,105 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchIntegers2 { - pub code: u8, - pub len: Option, - pub ham: Vec, - pub padding: u8, - pub len_mod_str: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchIntegers2_Len { - U1(u8), - U2(u16), - U4(u32), - U8(u64), -} -impl From for SwitchIntegers2_Len { - fn from(v: u8) -> Self { - Self::U1(v) - } -} -impl From for SwitchIntegers2_Len { - fn from(v: u16) -> Self { - Self::U2(v) - } -} -impl From for SwitchIntegers2_Len { - fn from(v: u32) -> Self { - Self::U4(v) - } -} -impl From for SwitchIntegers2_Len { - fn from(v: u64) -> Self { - Self::U8(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchIntegers2 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - match self.code { - 1 => { - self.len = Some(_io.read_u1()?); - } - 2 => { - self.len = Some(_io.read_u2le()?); - } - 4 => { - self.len = Some(_io.read_u4le()?); - } - 8 => { - self.len = Some(_io.read_u8le()?); - } - _ => panic!("unhandled value") - } - self.ham = _io.read_bytes(self.len as usize)?.to_vec(); - { - // condIfHeader(Compare(Name(identifier(len)),Gt,IntNum(3))) - self.padding = _io.read_u1()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchIntegers2 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchIntegers2::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn len_mod_str( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&String> { - if self.len_mod_str.is_some() { - return Ok(self.len_mod_str.as_ref().unwrap()); - } - self.len_mod_str = Some(((self.len * 2) - 1).to_string().to_string()); - return Ok(self.len_mod_str.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/switch_manual_enum.rs b/spec/rust/src/formats/switch_manual_enum.rs deleted file mode 100644 index d36b58fc6..000000000 --- a/spec/rust/src/formats/switch_manual_enum.rs +++ /dev/null @@ -1,188 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnum { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchManualEnum_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnum { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnum::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnum_Opcode { - pub code: Option, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualEnum_Opcode_Body { - SwitchManualEnum_Opcode_Intval(SwitchManualEnum_Opcode_Intval), - SwitchManualEnum_Opcode_Strval(SwitchManualEnum_Opcode_Strval), -} -impl From for SwitchManualEnum_Opcode_Body { - fn from(v: SwitchManualEnum_Opcode_Intval) -> Self { - Self::SwitchManualEnum_Opcode_Intval(v) - } -} -impl From for SwitchManualEnum_Opcode_Body { - fn from(v: SwitchManualEnum_Opcode_Strval) -> Self { - Self::SwitchManualEnum_Opcode_Strval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum_Opcode { - type Root = SwitchManualEnum; - type ParentStack = (&'r SwitchManualEnum, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = Some((_io.read_u1()? as i64).try_into()?); - match self.code { - SwitchManualEnum_Opcode_CodeEnum::Intval => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - SwitchManualEnum_Opcode_CodeEnum::Strval => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnum_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnum_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualEnum_Opcode_CodeEnum { - Intval, - Strval, -} -impl TryFrom for SwitchManualEnum_Opcode_CodeEnum { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 73 => Ok(SwitchManualEnum_Opcode_CodeEnum::Intval), - 83 => Ok(SwitchManualEnum_Opcode_CodeEnum::Strval), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnum_Opcode_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum_Opcode_Intval { - type Root = SwitchManualEnum; - type ParentStack = (&'r SwitchManualEnum_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnum_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnum_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnum_Opcode_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnum_Opcode_Strval { - type Root = SwitchManualEnum; - type ParentStack = (&'r SwitchManualEnum_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnum_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnum_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_manual_enum_invalid.rs b/spec/rust/src/formats/switch_manual_enum_invalid.rs deleted file mode 100644 index 2d419998e..000000000 --- a/spec/rust/src/formats/switch_manual_enum_invalid.rs +++ /dev/null @@ -1,188 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalid { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchManualEnumInvalid_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnumInvalid { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalid::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalid_Opcode { - pub code: Option, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualEnumInvalid_Opcode_Body { - SwitchManualEnumInvalid_Opcode_Intval(SwitchManualEnumInvalid_Opcode_Intval), - SwitchManualEnumInvalid_Opcode_Strval(SwitchManualEnumInvalid_Opcode_Strval), -} -impl From for SwitchManualEnumInvalid_Opcode_Body { - fn from(v: SwitchManualEnumInvalid_Opcode_Intval) -> Self { - Self::SwitchManualEnumInvalid_Opcode_Intval(v) - } -} -impl From for SwitchManualEnumInvalid_Opcode_Body { - fn from(v: SwitchManualEnumInvalid_Opcode_Strval) -> Self { - Self::SwitchManualEnumInvalid_Opcode_Strval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid_Opcode { - type Root = SwitchManualEnumInvalid; - type ParentStack = (&'r SwitchManualEnumInvalid, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = Some((_io.read_u1()? as i64).try_into()?); - match self.code { - SwitchManualEnumInvalid_Opcode_CodeEnum::Intval => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - SwitchManualEnumInvalid_Opcode_CodeEnum::Strval => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnumInvalid_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalid_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualEnumInvalid_Opcode_CodeEnum { - Intval, - Strval, -} -impl TryFrom for SwitchManualEnumInvalid_Opcode_CodeEnum { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 73 => Ok(SwitchManualEnumInvalid_Opcode_CodeEnum::Intval), - 83 => Ok(SwitchManualEnumInvalid_Opcode_CodeEnum::Strval), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalid_Opcode_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid_Opcode_Intval { - type Root = SwitchManualEnumInvalid; - type ParentStack = (&'r SwitchManualEnumInvalid_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnumInvalid_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalid_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalid_Opcode_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalid_Opcode_Strval { - type Root = SwitchManualEnumInvalid; - type ParentStack = (&'r SwitchManualEnumInvalid_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnumInvalid_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalid_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_manual_enum_invalid_else.rs b/spec/rust/src/formats/switch_manual_enum_invalid_else.rs deleted file mode 100644 index aef7b2440..000000000 --- a/spec/rust/src/formats/switch_manual_enum_invalid_else.rs +++ /dev/null @@ -1,241 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalidElse { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchManualEnumInvalidElse_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualEnumInvalidElse { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalidElse::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalidElse_Opcode { - pub code: Option, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualEnumInvalidElse_Opcode_Body { - SwitchManualEnumInvalidElse_Opcode_Intval(SwitchManualEnumInvalidElse_Opcode_Intval), - SwitchManualEnumInvalidElse_Opcode_Strval(SwitchManualEnumInvalidElse_Opcode_Strval), - SwitchManualEnumInvalidElse_Opcode_Defval(SwitchManualEnumInvalidElse_Opcode_Defval), -} -impl From for SwitchManualEnumInvalidElse_Opcode_Body { - fn from(v: SwitchManualEnumInvalidElse_Opcode_Intval) -> Self { - Self::SwitchManualEnumInvalidElse_Opcode_Intval(v) - } -} -impl From for SwitchManualEnumInvalidElse_Opcode_Body { - fn from(v: SwitchManualEnumInvalidElse_Opcode_Strval) -> Self { - Self::SwitchManualEnumInvalidElse_Opcode_Strval(v) - } -} -impl From for SwitchManualEnumInvalidElse_Opcode_Body { - fn from(v: SwitchManualEnumInvalidElse_Opcode_Defval) -> Self { - Self::SwitchManualEnumInvalidElse_Opcode_Defval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode { - type Root = SwitchManualEnumInvalidElse; - type ParentStack = (&'r SwitchManualEnumInvalidElse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = Some((_io.read_u1()? as i64).try_into()?); - match self.code { - SwitchManualEnumInvalidElse_Opcode_CodeEnum::Intval => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - SwitchManualEnumInvalidElse_Opcode_CodeEnum::Strval => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - // switchElseStart() - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalidElse_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualEnumInvalidElse_Opcode_CodeEnum { -Intval, -Strval, -} -impl TryFrom for SwitchManualEnumInvalidElse_Opcode_CodeEnum { -type Error = KError; -fn try_from(flag: i64) -> KResult { - match flag { - 73 => Ok(SwitchManualEnumInvalidElse_Opcode_CodeEnum::Intval), - 83 => Ok(SwitchManualEnumInvalidElse_Opcode_CodeEnum::Strval), - _ => Err(KError::UnknownVariant(flag)), - } -} -} - - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalidElse_Opcode_Intval { -pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode_Intval { -type Root = SwitchManualEnumInvalidElse; -type ParentStack = (&'r SwitchManualEnumInvalidElse_Opcode, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalidElse_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalidElse_Opcode_Strval { -pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode_Strval { -type Root = SwitchManualEnumInvalidElse; -type ParentStack = (&'r SwitchManualEnumInvalidElse_Opcode, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalidElse_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualEnumInvalidElse_Opcode_Defval { -pub value: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualEnumInvalidElse_Opcode_Defval { -type Root = SwitchManualEnumInvalidElse; -type ParentStack = (&'r SwitchManualEnumInvalidElse_Opcode, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualEnumInvalidElse_Opcode_Defval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualEnumInvalidElse_Opcode_Defval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -fn value( - &mut self, - _io: &'s S, - _root: Option<&'r SwitchManualEnumInvalidElse>, - _parent: Option>::ParentStack)>> -) -> KResult<&i8> { - if self.value.is_some() { - return Ok(self.value.as_ref().unwrap()); - } - self.value = Some(123 as i8); - return Ok(self.value.as_ref().unwrap()); -} -} diff --git a/spec/rust/src/formats/switch_manual_int.rs b/spec/rust/src/formats/switch_manual_int.rs deleted file mode 100644 index 3bba746ac..000000000 --- a/spec/rust/src/formats/switch_manual_int.rs +++ /dev/null @@ -1,172 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualInt { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchManualInt_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualInt { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualInt::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualInt_Opcode { - pub code: u8, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualInt_Opcode_Body { - SwitchManualInt_Opcode_Intval(SwitchManualInt_Opcode_Intval), - SwitchManualInt_Opcode_Strval(SwitchManualInt_Opcode_Strval), -} -impl From for SwitchManualInt_Opcode_Body { - fn from(v: SwitchManualInt_Opcode_Intval) -> Self { - Self::SwitchManualInt_Opcode_Intval(v) - } -} -impl From for SwitchManualInt_Opcode_Body { - fn from(v: SwitchManualInt_Opcode_Strval) -> Self { - Self::SwitchManualInt_Opcode_Strval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt_Opcode { - type Root = SwitchManualInt; - type ParentStack = (&'r SwitchManualInt, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - match self.code { - 73 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - 83 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualInt_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualInt_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualInt_Opcode_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt_Opcode_Intval { - type Root = SwitchManualInt; - type ParentStack = (&'r SwitchManualInt_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualInt_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualInt_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualInt_Opcode_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualInt_Opcode_Strval { - type Root = SwitchManualInt; - type ParentStack = (&'r SwitchManualInt_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualInt_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualInt_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_manual_int_else.rs b/spec/rust/src/formats/switch_manual_int_else.rs deleted file mode 100644 index 65e2b4b0e..000000000 --- a/spec/rust/src/formats/switch_manual_int_else.rs +++ /dev/null @@ -1,214 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntElse { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchManualIntElse_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualIntElse { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntElse::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntElse_Opcode { - pub code: u8, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualIntElse_Opcode_Body { - SwitchManualIntElse_Opcode_Intval(SwitchManualIntElse_Opcode_Intval), - SwitchManualIntElse_Opcode_Strval(SwitchManualIntElse_Opcode_Strval), - SwitchManualIntElse_Opcode_Noneval(SwitchManualIntElse_Opcode_Noneval), -} -impl From for SwitchManualIntElse_Opcode_Body { - fn from(v: SwitchManualIntElse_Opcode_Intval) -> Self { - Self::SwitchManualIntElse_Opcode_Intval(v) - } -} -impl From for SwitchManualIntElse_Opcode_Body { - fn from(v: SwitchManualIntElse_Opcode_Strval) -> Self { - Self::SwitchManualIntElse_Opcode_Strval(v) - } -} -impl From for SwitchManualIntElse_Opcode_Body { - fn from(v: SwitchManualIntElse_Opcode_Noneval) -> Self { - Self::SwitchManualIntElse_Opcode_Noneval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode { - type Root = SwitchManualIntElse; - type ParentStack = (&'r SwitchManualIntElse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - match self.code { - 73 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - 83 => { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - // switchElseStart() - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - _ => panic!("unhandled value") - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntElse_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntElse_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntElse_Opcode_Intval { -pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode_Intval { -type Root = SwitchManualIntElse; -type ParentStack = (&'r SwitchManualIntElse_Opcode, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntElse_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntElse_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntElse_Opcode_Strval { -pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode_Strval { -type Root = SwitchManualIntElse; -type ParentStack = (&'r SwitchManualIntElse_Opcode, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntElse_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntElse_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntElse_Opcode_Noneval { -pub filler: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntElse_Opcode_Noneval { -type Root = SwitchManualIntElse; -type ParentStack = (&'r SwitchManualIntElse_Opcode, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.filler = _io.read_u4le()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntElse_Opcode_Noneval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntElse_Opcode_Noneval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_manual_int_size.rs b/spec/rust/src/formats/switch_manual_int_size.rs deleted file mode 100644 index 1a5b425de..000000000 --- a/spec/rust/src/formats/switch_manual_int_size.rs +++ /dev/null @@ -1,194 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSize { - pub chunks: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.chunks = Vec::new(); - { - type ArrayElement = SwitchManualIntSize_Chunk; - while !_io.is_eof() { - self.chunks.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualIntSize { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSize::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSize_Chunk { - pub code: u8, - pub size: u32, - pub body: Option, - pub raw_body: Vec, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualIntSize_Chunk_Body { - SwitchManualIntSize_Chunk_ChunkMeta(SwitchManualIntSize_Chunk_ChunkMeta), - SwitchManualIntSize_Chunk_ChunkDir(SwitchManualIntSize_Chunk_ChunkDir), - Bytes(Vec), -} -impl From for SwitchManualIntSize_Chunk_Body { - fn from(v: SwitchManualIntSize_Chunk_ChunkMeta) -> Self { - Self::SwitchManualIntSize_Chunk_ChunkMeta(v) - } -} -impl From for SwitchManualIntSize_Chunk_Body { - fn from(v: SwitchManualIntSize_Chunk_ChunkDir) -> Self { - Self::SwitchManualIntSize_Chunk_ChunkDir(v) - } -} -impl From> for SwitchManualIntSize_Chunk_Body { - fn from(v: Vec) -> Self { - Self::Bytes(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize_Chunk { - type Root = SwitchManualIntSize; - type ParentStack = (&'r SwitchManualIntSize, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - self.size = _io.read_u4le()?; - match self.code { - 17 => { - self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); - } - 34 => { - self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); - } - // switchElseStart() - self.body = Some(_io.read_bytes(self.size as usize)?); - } - _ => panic!("unhandled value") - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntSize_Chunk { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSize_Chunk::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSize_Chunk_ChunkMeta { -pub title: String, -pub author: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize_Chunk_ChunkMeta { -type Root = SwitchManualIntSize; -type ParentStack = (&'r SwitchManualIntSize_Chunk, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.title = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; - self.author = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntSize_Chunk_ChunkMeta { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSize_Chunk_ChunkMeta::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSize_Chunk_ChunkDir { -pub entries: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSize_Chunk_ChunkDir { -type Root = SwitchManualIntSize; -type ParentStack = (&'r SwitchManualIntSize_Chunk, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.entries = Vec::new(); - { - type ArrayElement = String; - while !_io.is_eof() { - self.entries.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntSize_Chunk_ChunkDir { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSize_Chunk_ChunkDir::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_manual_int_size_else.rs b/spec/rust/src/formats/switch_manual_int_size_else.rs deleted file mode 100644 index ee2b6b45d..000000000 --- a/spec/rust/src/formats/switch_manual_int_size_else.rs +++ /dev/null @@ -1,228 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSizeElse { - pub chunks: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.chunks = Vec::new(); - { - type ArrayElement = SwitchManualIntSizeElse_Chunk; - while !_io.is_eof() { - self.chunks.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualIntSizeElse { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSizeElse::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSizeElse_Chunk { - pub code: u8, - pub size: u32, - pub body: Option, - pub raw_body: Vec, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualIntSizeElse_Chunk_Body { - SwitchManualIntSizeElse_Chunk_ChunkMeta(SwitchManualIntSizeElse_Chunk_ChunkMeta), - SwitchManualIntSizeElse_Chunk_ChunkDir(SwitchManualIntSizeElse_Chunk_ChunkDir), - SwitchManualIntSizeElse_Chunk_Dummy(SwitchManualIntSizeElse_Chunk_Dummy), -} -impl From for SwitchManualIntSizeElse_Chunk_Body { - fn from(v: SwitchManualIntSizeElse_Chunk_ChunkMeta) -> Self { - Self::SwitchManualIntSizeElse_Chunk_ChunkMeta(v) - } -} -impl From for SwitchManualIntSizeElse_Chunk_Body { - fn from(v: SwitchManualIntSizeElse_Chunk_ChunkDir) -> Self { - Self::SwitchManualIntSizeElse_Chunk_ChunkDir(v) - } -} -impl From for SwitchManualIntSizeElse_Chunk_Body { - fn from(v: SwitchManualIntSizeElse_Chunk_Dummy) -> Self { - Self::SwitchManualIntSizeElse_Chunk_Dummy(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk { - type Root = SwitchManualIntSizeElse; - type ParentStack = (&'r SwitchManualIntSizeElse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - self.size = _io.read_u4le()?; - match self.code { - 17 => { - self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); - } - 34 => { - self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); - } - // switchElseStart() - self.body = Some(&BytesReader::new(_io.read_bytes(self.size as usize)?)); - } - _ => panic!("unhandled value") - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSizeElse_Chunk::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSizeElse_Chunk_ChunkMeta { -pub title: String, -pub author: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk_ChunkMeta { -type Root = SwitchManualIntSizeElse; -type ParentStack = (&'r SwitchManualIntSizeElse_Chunk, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.title = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; - self.author = decode_string(_io.read_bytes_term(0, false, true, true)?, "UTF-8")?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk_ChunkMeta { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSizeElse_Chunk_ChunkMeta::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSizeElse_Chunk_ChunkDir { -pub entries: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk_ChunkDir { -type Root = SwitchManualIntSizeElse; -type ParentStack = (&'r SwitchManualIntSizeElse_Chunk, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.entries = Vec::new(); - { - type ArrayElement = String; - while !_io.is_eof() { - self.entries.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk_ChunkDir { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSizeElse_Chunk_ChunkDir::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualIntSizeElse_Chunk_Dummy { -pub rest: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualIntSizeElse_Chunk_Dummy { -type Root = SwitchManualIntSizeElse; -type ParentStack = (&'r SwitchManualIntSizeElse_Chunk, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.rest = _io.read_bytes_full()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchManualIntSizeElse_Chunk_Dummy { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualIntSizeElse_Chunk_Dummy::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_manual_str.rs b/spec/rust/src/formats/switch_manual_str.rs deleted file mode 100644 index 45bba2750..000000000 --- a/spec/rust/src/formats/switch_manual_str.rs +++ /dev/null @@ -1,172 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStr { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchManualStr_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStr_Opcode { - pub code: String, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualStr_Opcode_Body { - SwitchManualStr_Opcode_Intval(SwitchManualStr_Opcode_Intval), - SwitchManualStr_Opcode_Strval(SwitchManualStr_Opcode_Strval), -} -impl From for SwitchManualStr_Opcode_Body { - fn from(v: SwitchManualStr_Opcode_Intval) -> Self { - Self::SwitchManualStr_Opcode_Intval(v) - } -} -impl From for SwitchManualStr_Opcode_Body { - fn from(v: SwitchManualStr_Opcode_Strval) -> Self { - Self::SwitchManualStr_Opcode_Strval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr_Opcode { - type Root = SwitchManualStr; - type ParentStack = (&'r SwitchManualStr, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = decode_string(_io.read_bytes(1 as usize)?, "ASCII")?; - { - let on = &self.code; - if on == "I" { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - else if on == "S" { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStr_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStr_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStr_Opcode_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr_Opcode_Intval { - type Root = SwitchManualStr; - type ParentStack = (&'r SwitchManualStr_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStr_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStr_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStr_Opcode_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStr_Opcode_Strval { - type Root = SwitchManualStr; - type ParentStack = (&'r SwitchManualStr_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStr_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStr_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_manual_str_else.rs b/spec/rust/src/formats/switch_manual_str_else.rs deleted file mode 100644 index 0a2763e0b..000000000 --- a/spec/rust/src/formats/switch_manual_str_else.rs +++ /dev/null @@ -1,214 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStrElse { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchManualStrElse_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStrElse { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStrElse::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStrElse_Opcode { - pub code: String, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchManualStrElse_Opcode_Body { - SwitchManualStrElse_Opcode_Intval(SwitchManualStrElse_Opcode_Intval), - SwitchManualStrElse_Opcode_Strval(SwitchManualStrElse_Opcode_Strval), - SwitchManualStrElse_Opcode_Noneval(SwitchManualStrElse_Opcode_Noneval), -} -impl From for SwitchManualStrElse_Opcode_Body { - fn from(v: SwitchManualStrElse_Opcode_Intval) -> Self { - Self::SwitchManualStrElse_Opcode_Intval(v) - } -} -impl From for SwitchManualStrElse_Opcode_Body { - fn from(v: SwitchManualStrElse_Opcode_Strval) -> Self { - Self::SwitchManualStrElse_Opcode_Strval(v) - } -} -impl From for SwitchManualStrElse_Opcode_Body { - fn from(v: SwitchManualStrElse_Opcode_Noneval) -> Self { - Self::SwitchManualStrElse_Opcode_Noneval(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode { - type Root = SwitchManualStrElse; - type ParentStack = (&'r SwitchManualStrElse, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = decode_string(_io.read_bytes(1 as usize)?, "ASCII")?; - { - let on = &self.code; - if on == "I" { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - else if on == "S" { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - else { - self.body = Some(Self::read_into::(_io, _root, _parent.push(self))?.into()); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStrElse_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStrElse_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStrElse_Opcode_Intval { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode_Intval { - type Root = SwitchManualStrElse; - type ParentStack = (&'r SwitchManualStrElse_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStrElse_Opcode_Intval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStrElse_Opcode_Intval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStrElse_Opcode_Strval { - pub value: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode_Strval { - type Root = SwitchManualStrElse; - type ParentStack = (&'r SwitchManualStrElse_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = decode_string(_io.read_bytes_term(0, false, true, true)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStrElse_Opcode_Strval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStrElse_Opcode_Strval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchManualStrElse_Opcode_Noneval { - pub filler: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchManualStrElse_Opcode_Noneval { - type Root = SwitchManualStrElse; - type ParentStack = (&'r SwitchManualStrElse_Opcode, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.filler = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> SwitchManualStrElse_Opcode_Noneval { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchManualStrElse_Opcode_Noneval::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_multi_bool_ops.rs b/spec/rust/src/formats/switch_multi_bool_ops.rs deleted file mode 100644 index 275402c8e..000000000 --- a/spec/rust/src/formats/switch_multi_bool_ops.rs +++ /dev/null @@ -1,124 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchMultiBoolOps { - pub opcodes: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchMultiBoolOps { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.opcodes = Vec::new(); - { - type ArrayElement = SwitchMultiBoolOps_Opcode; - while !_io.is_eof() { - self.opcodes.push(Self::read_into::(_io, _root, _parent.push(self))?); - } - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchMultiBoolOps { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchMultiBoolOps::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchMultiBoolOps_Opcode { - pub code: u8, - pub body: Option, -} -#[derive(Debug, PartialEq)] -pub enum SwitchMultiBoolOps_Opcode_Body { - U1(u8), - U2(u16), - U4(u32), - U8(u64), -} -impl From for SwitchMultiBoolOps_Opcode_Body { - fn from(v: u8) -> Self { - Self::U1(v) - } -} -impl From for SwitchMultiBoolOps_Opcode_Body { - fn from(v: u16) -> Self { - Self::U2(v) - } -} -impl From for SwitchMultiBoolOps_Opcode_Body { - fn from(v: u32) -> Self { - Self::U4(v) - } -} -impl From for SwitchMultiBoolOps_Opcode_Body { - fn from(v: u64) -> Self { - Self::U8(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchMultiBoolOps_Opcode { - type Root = SwitchMultiBoolOps; - type ParentStack = (&'r SwitchMultiBoolOps, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - match if ((self.code > 0) && (self.code <= 8) && (if self.code != 10 { true } else { false})) { self.code } else { 0} { - 1 => { - self.body = Some(_io.read_u1()?); - } - 2 => { - self.body = Some(_io.read_u2le()?); - } - 4 => { - self.body = Some(_io.read_u4le()?); - } - 8 => { - self.body = Some(_io.read_u8le()?); - } - _ => panic!("unhandled value") - } - Ok(()) - } -} -impl<'r, 's: 'r> SwitchMultiBoolOps_Opcode { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchMultiBoolOps_Opcode::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_repeat_expr.rs b/spec/rust/src/formats/switch_repeat_expr.rs deleted file mode 100644 index 2a389aefc..000000000 --- a/spec/rust/src/formats/switch_repeat_expr.rs +++ /dev/null @@ -1,153 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchRepeatExpr { - pub code: u8, - pub size: u32, - pub body: Vec, - pub raw_body: Vec>, -} -#[derive(Debug, PartialEq)] -pub enum SwitchRepeatExpr_Body { - SwitchRepeatExpr_One(SwitchRepeatExpr_One), - SwitchRepeatExpr_Two(SwitchRepeatExpr_Two), - Bytes(Vec), -} -impl From for SwitchRepeatExpr_Body { - fn from(v: SwitchRepeatExpr_One) -> Self { - Self::SwitchRepeatExpr_One(v) - } -} -impl From for SwitchRepeatExpr_Body { - fn from(v: SwitchRepeatExpr_Two) -> Self { - Self::SwitchRepeatExpr_Two(v) - } -} -impl From> for SwitchRepeatExpr_Body { - fn from(v: Vec) -> Self { - Self::Bytes(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExpr { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - self.size = _io.read_u4le()?; - self.body = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(body), _io, SwitchType(Name(identifier(code)),Map(IntNum(17) -> UserTypeFromBytes(List(one),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), IntNum(34) -> UserTypeFromBytes(List(two),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), Name(identifier(_)) -> BytesLimitType(Name(identifier(size)),None,false,None,None)),true), IntNum(1)) - match self.code { - 17 => { - // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) - // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) - } - 34 => { - // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) - // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) - } - // switchElseStart() - // handleAssignmentRepeatExpr(NamedIdentifier(body), _io.read_bytes(self.size as usize)?) - } - _ => panic!("unhandled value") - } - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchRepeatExpr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchRepeatExpr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchRepeatExpr_One { -pub first: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExpr_One { -type Root = SwitchRepeatExpr; -type ParentStack = (&'r SwitchRepeatExpr, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.first = _io.read_bytes_full()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchRepeatExpr_One { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchRepeatExpr_One::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchRepeatExpr_Two { -pub second: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExpr_Two { -type Root = SwitchRepeatExpr; -type ParentStack = (&'r SwitchRepeatExpr, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.second = _io.read_bytes_full()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchRepeatExpr_Two { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchRepeatExpr_Two::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/switch_repeat_expr_invalid.rs b/spec/rust/src/formats/switch_repeat_expr_invalid.rs deleted file mode 100644 index fcd70b5e3..000000000 --- a/spec/rust/src/formats/switch_repeat_expr_invalid.rs +++ /dev/null @@ -1,153 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) -// extraAttrForIO(RawIdentifier(NamedIdentifier(body)), RepeatExpr(IntNum(1))) - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchRepeatExprInvalid { - pub code: u8, - pub size: u32, - pub body: Vec, - pub raw_body: Vec>, -} -#[derive(Debug, PartialEq)] -pub enum SwitchRepeatExprInvalid_Body { - SwitchRepeatExprInvalid_One(SwitchRepeatExprInvalid_One), - SwitchRepeatExprInvalid_Two(SwitchRepeatExprInvalid_Two), - Bytes(Vec), -} -impl From for SwitchRepeatExprInvalid_Body { - fn from(v: SwitchRepeatExprInvalid_One) -> Self { - Self::SwitchRepeatExprInvalid_One(v) - } -} -impl From for SwitchRepeatExprInvalid_Body { - fn from(v: SwitchRepeatExprInvalid_Two) -> Self { - Self::SwitchRepeatExprInvalid_Two(v) - } -} -impl From> for SwitchRepeatExprInvalid_Body { - fn from(v: Vec) -> Self { - Self::Bytes(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExprInvalid { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.code = _io.read_u1()?; - self.size = _io.read_u4le()?; - self.body = Vec::new(); - { - // condRepeatExprHeader(NamedIdentifier(body), _io, SwitchType(Name(identifier(code)),Map(IntNum(255) -> UserTypeFromBytes(List(one),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), IntNum(34) -> UserTypeFromBytes(List(two),None,List(),BytesLimitType(Name(identifier(size)),None,false,None,None),None), Name(identifier(_)) -> BytesLimitType(Name(identifier(size)),None,false,None,None)),true), IntNum(1)) - match self.code { - 255 => { - // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) - // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) - } - 34 => { - // handleAssignmentRepeatExpr(RawIdentifier(NamedIdentifier(body)), _io.read_bytes(self.size as usize)?) - // handleAssignmentRepeatExpr(NamedIdentifier(body), &BytesReader::new(_io.read_bytes(self.size as usize)?)) - } - // switchElseStart() - // handleAssignmentRepeatExpr(NamedIdentifier(body), _io.read_bytes(self.size as usize)?) - } - _ => panic!("unhandled value") - } - } - Ok(()) -} -} -impl<'r, 's: 'r> SwitchRepeatExprInvalid { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchRepeatExprInvalid::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchRepeatExprInvalid_One { -pub first: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExprInvalid_One { -type Root = SwitchRepeatExprInvalid; -type ParentStack = (&'r SwitchRepeatExprInvalid, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.first = _io.read_bytes_full()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchRepeatExprInvalid_One { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchRepeatExprInvalid_One::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct SwitchRepeatExprInvalid_Two { -pub second: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for SwitchRepeatExprInvalid_Two { -type Root = SwitchRepeatExprInvalid; -type ParentStack = (&'r SwitchRepeatExprInvalid, >::ParentStack); - -fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> -) -> KResult<()> { - self.second = _io.read_bytes_full()?; - Ok(()) -} -} -impl<'r, 's: 'r> SwitchRepeatExprInvalid_Two { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = SwitchRepeatExprInvalid_Two::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/term_bytes.rs b/spec/rust/src/formats/term_bytes.rs deleted file mode 100644 index c567a6eaf..000000000 --- a/spec/rust/src/formats/term_bytes.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct TermBytes { - pub s1: Vec, - pub s2: Vec, - pub s3: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TermBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.s1 = _io.read_bytes_term(124, false, true, true)?; - self.s2 = _io.read_bytes_term(124, false, false, true)?; - self.s3 = _io.read_bytes_term(64, true, true, true)?; - Ok(()) - } -} -impl<'r, 's: 'r> TermBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TermBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/term_strz.rs b/spec/rust/src/formats/term_strz.rs deleted file mode 100644 index d1526e2f3..000000000 --- a/spec/rust/src/formats/term_strz.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct TermStrz { - pub s1: String, - pub s2: String, - pub s3: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TermStrz { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; - self.s2 = decode_string(_io.read_bytes_term(124, false, false, true)?, "UTF-8")?; - self.s3 = decode_string(_io.read_bytes_term(64, true, true, true)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> TermStrz { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TermStrz::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/term_u1_val.rs b/spec/rust/src/formats/term_u1_val.rs deleted file mode 100644 index c8222135e..000000000 --- a/spec/rust/src/formats/term_u1_val.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct TermU1Val { - pub foo: Vec, - pub bar: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TermU1Val { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_bytes_term(227, false, false, true)?; - self.bar = decode_string(_io.read_bytes_term(171, true, true, true)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> TermU1Val { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TermU1Val::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/to_string_custom.rs b/spec/rust/src/formats/to_string_custom.rs deleted file mode 100644 index e70fe052b..000000000 --- a/spec/rust/src/formats/to_string_custom.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ToStringCustom { - pub s1: String, - pub s2: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ToStringCustom { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.s1 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; - self.s2 = decode_string(_io.read_bytes_term(124, false, true, true)?, "UTF-8")?; - Ok(()) - } -} -impl<'r, 's: 'r> ToStringCustom { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ToStringCustom::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/ts_packet_header.rs b/spec/rust/src/formats/ts_packet_header.rs deleted file mode 100644 index a679ba5f8..000000000 --- a/spec/rust/src/formats/ts_packet_header.rs +++ /dev/null @@ -1,79 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// universalDoc() - -#[derive(Default, Debug, PartialEq)] -pub struct TsPacketHeader { - pub sync_byte: u8, - pub transport_error_indicator: bool, - pub payload_unit_start_indicator: bool, - pub transport_priority: bool, - pub pid: u64, - pub transport_scrambling_control: u64, - pub adaptation_field_control: Option, - pub continuity_counter: u64, - pub ts_packet_remain: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TsPacketHeader { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.sync_byte = _io.read_u1()?; - self.transport_error_indicator = _io.read_bits_int(1)? != 0; - self.payload_unit_start_indicator = _io.read_bits_int(1)? != 0; - self.transport_priority = _io.read_bits_int(1)? != 0; - self.pid = _io.read_bits_int(13)?; - self.transport_scrambling_control = _io.read_bits_int(2)?; - self.adaptation_field_control = Some((_io.read_bits_int(2)? as i64).try_into()?); - self.continuity_counter = _io.read_bits_int(4)?; - _io.align_to_byte()?; - self.ts_packet_remain = _io.read_bytes(184 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> TsPacketHeader { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TsPacketHeader::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} -#[derive(Debug, PartialEq)] -pub enum TsPacketHeader_AdaptationFieldControlEnum { - Reserved, - PayloadOnly, - AdaptationFieldOnly, - AdaptationFieldAndPayload, -} -impl TryFrom for TsPacketHeader_AdaptationFieldControlEnum { - type Error = KError; - fn try_from(flag: i64) -> KResult { - match flag { - 0 => Ok(TsPacketHeader_AdaptationFieldControlEnum::Reserved), - 1 => Ok(TsPacketHeader_AdaptationFieldControlEnum::PayloadOnly), - 2 => Ok(TsPacketHeader_AdaptationFieldControlEnum::AdaptationFieldOnly), - 3 => Ok(TsPacketHeader_AdaptationFieldControlEnum::AdaptationFieldAndPayload), - _ => Err(KError::UnknownVariant(flag)), - } - } -} - diff --git a/spec/rust/src/formats/type_int_unary_op.rs b/spec/rust/src/formats/type_int_unary_op.rs deleted file mode 100644 index 30b542525..000000000 --- a/spec/rust/src/formats/type_int_unary_op.rs +++ /dev/null @@ -1,69 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct TypeIntUnaryOp { - pub value_s2: i16, - pub value_s8: i64, - pub unary_s2: Option, - pub unary_s8: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TypeIntUnaryOp { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value_s2 = _io.read_s2le()?; - self.value_s8 = _io.read_s8le()?; - Ok(()) - } -} -impl<'r, 's: 'r> TypeIntUnaryOp { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TypeIntUnaryOp::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn unary_s2( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.unary_s2.is_some() { - return Ok(self.unary_s2.as_ref().unwrap()); - } - self.unary_s2 = Some(-(self.value_s2) as i32); - return Ok(self.unary_s2.as_ref().unwrap()); - } - fn unary_s8( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i64> { - if self.unary_s8.is_some() { - return Ok(self.unary_s8.as_ref().unwrap()); - } - self.unary_s8 = Some(-(self.value_s8) as i64); - return Ok(self.unary_s8.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/type_ternary.rs b/spec/rust/src/formats/type_ternary.rs deleted file mode 100644 index 7968f844a..000000000 --- a/spec/rust/src/formats/type_ternary.rs +++ /dev/null @@ -1,125 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_wo_hack)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct TypeTernary { - pub dif_wo_hack: Option, - pub dif_with_hack: Option, - pub raw_dif_wo_hack: Vec, - pub raw_dif_with_hack: Vec, - pub raw_raw_dif_with_hack: Vec, - pub is_hack: Option, - pub dif: Option, - pub dif_value: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TypeTernary { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - { - // condIfHeader(UnaryOp(Not,Name(identifier(is_hack)))) - self.dif_wo_hack = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(1 as usize)?), Some(self), _parent.push(self))?); - } - // attrProcess(ProcessXor(IntNum(3)), RawIdentifier(RawIdentifier(NamedIdentifier(dif_with_hack))), RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) - self.dif_with_hack = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(1 as usize)?), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> TypeTernary { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TypeTernary::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn is_hack( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_hack.is_some() { - return Ok(self.is_hack.as_ref().unwrap()); - } - self.is_hack = Some(true as bool); - return Ok(self.is_hack.as_ref().unwrap()); - } - fn dif( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&TypeTernary_Dummy> { - if self.dif.is_some() { - return Ok(self.dif.as_ref().unwrap()); - } - self.dif = Some(if !(self.is_hack(_io, _root, _parent)?) { self.dif_wo_hack } else { self.dif_with_hack} as Dummy); - return Ok(self.dif.as_ref().unwrap()); - } - fn dif_value( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.dif_value.is_some() { - return Ok(self.dif_value.as_ref().unwrap()); - } - self.dif_value = Some(self.dif(_io, _root, _parent)?.value as u8); - return Ok(self.dif_value.as_ref().unwrap()); - } -} - -#[derive(Default, Debug, PartialEq)] -pub struct TypeTernary_Dummy { - pub value: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TypeTernary_Dummy { - type Root = TypeTernary; - type ParentStack = (&'r TypeTernary, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.value = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> TypeTernary_Dummy { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TypeTernary_Dummy::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/type_ternary_opaque.rs b/spec/rust/src/formats/type_ternary_opaque.rs deleted file mode 100644 index b134dd440..000000000 --- a/spec/rust/src/formats/type_ternary_opaque.rs +++ /dev/null @@ -1,83 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -use crate::term_strz::TermStrz; -// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_wo_hack)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct TypeTernaryOpaque { - pub dif_wo_hack: Option>, - pub dif_with_hack: Option>, - pub raw_dif_wo_hack: Vec, - pub raw_dif_with_hack: Vec, - pub raw_raw_dif_with_hack: Vec, - pub is_hack: Option, - pub dif: Option>, -} -impl<'r, 's: 'r> KStruct<'r, 's> for TypeTernaryOpaque { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - { - // condIfHeader(UnaryOp(Not,Name(identifier(is_hack)))) - self.dif_wo_hack = Some(Self::read_into::>(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); - } - { - // condIfHeader(Name(identifier(is_hack))) - // attrProcess(ProcessXor(IntNum(3)), RawIdentifier(RawIdentifier(NamedIdentifier(dif_with_hack))), RawIdentifier(NamedIdentifier(dif_with_hack)), NoRepeat) - self.dif_with_hack = Some(Self::read_into::>(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); - } - Ok(()) - } -} -impl<'r, 's: 'r> TypeTernaryOpaque { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = TypeTernaryOpaque::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn is_hack( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&bool> { - if self.is_hack.is_some() { - return Ok(self.is_hack.as_ref().unwrap()); - } - self.is_hack = Some(false as bool); - return Ok(self.is_hack.as_ref().unwrap()); - } - fn dif( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&Box> { - if self.dif.is_some() { - return Ok(self.dif.as_ref().unwrap()); - } - self.dif = Some(if !(self.is_hack(_io, _root, _parent)?) { self.dif_wo_hack } else { self.dif_with_hack} as TermStrz); - return Ok(self.dif.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/user_type.rs b/spec/rust/src/formats/user_type.rs deleted file mode 100644 index 44b64cc42..000000000 --- a/spec/rust/src/formats/user_type.rs +++ /dev/null @@ -1,76 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct UserType { - pub one: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for UserType { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.one = Some(Self::read_into::(Self::read_into::(_io, _root, _parent.push(self))?.into(), Some(self), _parent.push(self))?); - Ok(()) - } -} -impl<'r, 's: 'r> UserType { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = UserType::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct UserType_Header { - pub width: u32, - pub height: u32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for UserType_Header { - type Root = UserType; - type ParentStack = (&'r UserType, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.width = _io.read_u4le()?; - self.height = _io.read_u4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> UserType_Header { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = UserType_Header::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_eq_str_encodings.rs b/spec/rust/src/formats/valid_eq_str_encodings.rs deleted file mode 100644 index f908fc4d3..000000000 --- a/spec/rust/src/formats/valid_eq_str_encodings.rs +++ /dev/null @@ -1,55 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidEqStrEncodings { - pub len_of_1: u16, - pub str1: String, - pub len_of_2: u16, - pub str2: String, - pub len_of_3: u16, - pub str3: String, - pub len_of_4: u16, - pub str4: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidEqStrEncodings { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.len_of_1 = _io.read_u2le()?; - self.str1 = decode_string(_io.read_bytes(self.len_of_1 as usize)?, "ASCII")?; - self.len_of_2 = _io.read_u2le()?; - self.str2 = decode_string(_io.read_bytes(self.len_of_2 as usize)?, "UTF-8")?; - self.len_of_3 = _io.read_u2le()?; - self.str3 = decode_string(_io.read_bytes(self.len_of_3 as usize)?, "SJIS")?; - self.len_of_4 = _io.read_u2le()?; - self.str4 = decode_string(_io.read_bytes(self.len_of_4 as usize)?, "CP437")?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidEqStrEncodings { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidEqStrEncodings::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_anyof_int.rs b/spec/rust/src/formats/valid_fail_anyof_int.rs deleted file mode 100644 index d306a99db..000000000 --- a/spec/rust/src/formats/valid_fail_anyof_int.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailAnyofInt { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailAnyofInt { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailAnyofInt { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailAnyofInt::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_contents.rs b/spec/rust/src/formats/valid_fail_contents.rs deleted file mode 100644 index 9a5ec2f8d..000000000 --- a/spec/rust/src/formats/valid_fail_contents.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailContents { - pub foo: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailContents { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_bytes(2 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailContents { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailContents::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_eq_bytes.rs b/spec/rust/src/formats/valid_fail_eq_bytes.rs deleted file mode 100644 index b03f9a0c5..000000000 --- a/spec/rust/src/formats/valid_fail_eq_bytes.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailEqBytes { - pub foo: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailEqBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_bytes(2 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailEqBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailEqBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_eq_int.rs b/spec/rust/src/formats/valid_fail_eq_int.rs deleted file mode 100644 index 6e6026394..000000000 --- a/spec/rust/src/formats/valid_fail_eq_int.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailEqInt { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailEqInt { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailEqInt { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailEqInt::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_eq_str.rs b/spec/rust/src/formats/valid_fail_eq_str.rs deleted file mode 100644 index ea4d91eac..000000000 --- a/spec/rust/src/formats/valid_fail_eq_str.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailEqStr { - pub foo: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailEqStr { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = decode_string(_io.read_bytes(4 as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailEqStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailEqStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_expr.rs b/spec/rust/src/formats/valid_fail_expr.rs deleted file mode 100644 index 78c34b34b..000000000 --- a/spec/rust/src/formats/valid_fail_expr.rs +++ /dev/null @@ -1,45 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailExpr { - pub foo: u8, - pub bar: i16, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailExpr { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - u8 tmpa = foo(); - self.bar = _io.read_s2le()?; - i16 tmpa = bar(); - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailExpr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailExpr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_inst.rs b/spec/rust/src/formats/valid_fail_inst.rs deleted file mode 100644 index 1179bcf37..000000000 --- a/spec/rust/src/formats/valid_fail_inst.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailInst { - pub a: u8, - pub inst: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailInst { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - { - // condIfHeader(Compare(Name(identifier(inst)),GtE,IntNum(0))) - self.a = _io.read_u1()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailInst { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailInst::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn inst( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&u8> { - if self.inst.is_some() { - return Ok(self.inst.as_ref().unwrap()); - } - // pushPos(_io) - // seek(_io, IntNum(5)) - // popPos(_io) - return Ok(self.inst.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/valid_fail_max_int.rs b/spec/rust/src/formats/valid_fail_max_int.rs deleted file mode 100644 index c15405b57..000000000 --- a/spec/rust/src/formats/valid_fail_max_int.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailMaxInt { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailMaxInt { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailMaxInt { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailMaxInt::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_min_int.rs b/spec/rust/src/formats/valid_fail_min_int.rs deleted file mode 100644 index 8c2f00308..000000000 --- a/spec/rust/src/formats/valid_fail_min_int.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailMinInt { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailMinInt { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailMinInt { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailMinInt::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_range_bytes.rs b/spec/rust/src/formats/valid_fail_range_bytes.rs deleted file mode 100644 index 9124ee3cb..000000000 --- a/spec/rust/src/formats/valid_fail_range_bytes.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailRangeBytes { - pub foo: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeBytes { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_bytes(2 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailRangeBytes { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailRangeBytes::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_range_float.rs b/spec/rust/src/formats/valid_fail_range_float.rs deleted file mode 100644 index 26e1a161e..000000000 --- a/spec/rust/src/formats/valid_fail_range_float.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailRangeFloat { - pub foo: f32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeFloat { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_f4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailRangeFloat { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailRangeFloat::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_range_int.rs b/spec/rust/src/formats/valid_fail_range_int.rs deleted file mode 100644 index 84eb7daf5..000000000 --- a/spec/rust/src/formats/valid_fail_range_int.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailRangeInt { - pub foo: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeInt { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = _io.read_u1()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailRangeInt { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailRangeInt::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_fail_range_str.rs b/spec/rust/src/formats/valid_fail_range_str.rs deleted file mode 100644 index 44185d6e5..000000000 --- a/spec/rust/src/formats/valid_fail_range_str.rs +++ /dev/null @@ -1,41 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidFailRangeStr { - pub foo: String, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidFailRangeStr { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.foo = decode_string(_io.read_bytes(2 as usize)?, "ASCII")?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidFailRangeStr { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidFailRangeStr::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_long.rs b/spec/rust/src/formats/valid_long.rs deleted file mode 100644 index 5a8f88554..000000000 --- a/spec/rust/src/formats/valid_long.rs +++ /dev/null @@ -1,61 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidLong { - pub magic1: Vec, - pub uint8: u8, - pub sint8: i8, - pub magic_uint: String, - pub uint16: u16, - pub uint32: u32, - pub uint64: u64, - pub magic_sint: String, - pub sint16: i16, - pub sint32: i32, - pub sint64: i64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidLong { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); - self.uint8 = _io.read_u1()?; - self.sint8 = _io.read_s1()?; - self.magic_uint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; - self.uint16 = _io.read_u2le()?; - self.uint32 = _io.read_u4le()?; - self.uint64 = _io.read_u8le()?; - self.magic_sint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; - self.sint16 = _io.read_s2le()?; - self.sint32 = _io.read_s4le()?; - self.sint64 = _io.read_s8le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidLong { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidLong::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_not_parsed_if.rs b/spec/rust/src/formats/valid_not_parsed_if.rs deleted file mode 100644 index 8d36ef739..000000000 --- a/spec/rust/src/formats/valid_not_parsed_if.rs +++ /dev/null @@ -1,49 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidNotParsedIf { - pub not_parsed: u8, - pub parsed: u8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidNotParsedIf { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - { - // condIfHeader(Bool(false)) - self.not_parsed = _io.read_u1()?; - } - { - // condIfHeader(Bool(true)) - self.parsed = _io.read_u1()?; - } - Ok(()) - } -} -impl<'r, 's: 'r> ValidNotParsedIf { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidNotParsedIf::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_optional_id.rs b/spec/rust/src/formats/valid_optional_id.rs deleted file mode 100644 index 4feab7cad..000000000 --- a/spec/rust/src/formats/valid_optional_id.rs +++ /dev/null @@ -1,46 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidOptionalId { - pub _unnamed0: Vec, - pub _unnamed1: u8, - pub _unnamed2: i8, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidOptionalId { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self._unnamed0 = _io.read_bytes(6 as usize)?.to_vec(); - self._unnamed1 = _io.read_u1()?; - self._unnamed2 = _io.read_s1()?; - i8 tmpa = _unnamed2(); - Ok(()) - } -} -impl<'r, 's: 'r> ValidOptionalId { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidOptionalId::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_short.rs b/spec/rust/src/formats/valid_short.rs deleted file mode 100644 index 7a26e0f8a..000000000 --- a/spec/rust/src/formats/valid_short.rs +++ /dev/null @@ -1,61 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidShort { - pub magic1: Vec, - pub uint8: u8, - pub sint8: i8, - pub magic_uint: String, - pub uint16: u16, - pub uint32: u32, - pub uint64: u64, - pub magic_sint: String, - pub sint16: i16, - pub sint32: i32, - pub sint64: i64, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ValidShort { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.magic1 = _io.read_bytes(6 as usize)?.to_vec(); - self.uint8 = _io.read_u1()?; - self.sint8 = _io.read_s1()?; - self.magic_uint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; - self.uint16 = _io.read_u2le()?; - self.uint32 = _io.read_u4le()?; - self.uint64 = _io.read_u8le()?; - self.magic_sint = decode_string(_io.read_bytes(10 as usize)?, "utf-8")?; - self.sint16 = _io.read_s2le()?; - self.sint32 = _io.read_s4le()?; - self.sint64 = _io.read_s8le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ValidShort { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidShort::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/valid_switch.rs b/spec/rust/src/formats/valid_switch.rs deleted file mode 100644 index 17c5528c3..000000000 --- a/spec/rust/src/formats/valid_switch.rs +++ /dev/null @@ -1,67 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct ValidSwitch { - pub a: u8, - pub b: Option, -} -#[derive(Debug, PartialEq)] -pub enum ValidSwitch_B { - U2(u16), - U2(u16), -} -impl From for ValidSwitch_B { - fn from(v: u16) -> Self { - Self::U2(v) - } -} -impl From for ValidSwitch_B { - fn from(v: u16) -> Self { - Self::U2(v) - } -} - -impl<'r, 's: 'r> KStruct<'r, 's> for ValidSwitch { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.a = _io.read_u1()?; - match self.a { - 80 => { - self.b = Some(_io.read_u2le()?); - } - // switchElseStart() - self.b = Some(_io.read_u2be()?); - } - _ => panic!("unhandled value") - } - Ok(()) -} -} -impl<'r, 's: 'r> ValidSwitch { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ValidSwitch::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/yaml_ints.rs b/spec/rust/src/formats/yaml_ints.rs deleted file mode 100644 index eafdb6777..000000000 --- a/spec/rust/src/formats/yaml_ints.rs +++ /dev/null @@ -1,91 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; - -#[derive(Default, Debug, PartialEq)] -pub struct YamlInts { - pub test_u4_dec: Option, - pub test_u4_hex: Option, - pub test_u8_dec: Option, - pub test_u8_hex: Option, -} -impl<'r, 's: 'r> KStruct<'r, 's> for YamlInts { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - Ok(()) - } -} -impl<'r, 's: 'r> YamlInts { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = YamlInts::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - - fn test_u4_dec( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.test_u4_dec.is_some() { - return Ok(self.test_u4_dec.as_ref().unwrap()); - } - self.test_u4_dec = Some(4294967295 as i32); - return Ok(self.test_u4_dec.as_ref().unwrap()); - } - fn test_u4_hex( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.test_u4_hex.is_some() { - return Ok(self.test_u4_hex.as_ref().unwrap()); - } - self.test_u4_hex = Some(4294967295 as i32); - return Ok(self.test_u4_hex.as_ref().unwrap()); - } - fn test_u8_dec( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.test_u8_dec.is_some() { - return Ok(self.test_u8_dec.as_ref().unwrap()); - } - self.test_u8_dec = Some(18446744073709551615 as i32); - return Ok(self.test_u8_dec.as_ref().unwrap()); - } - fn test_u8_hex( - &mut self, - _io: &'s S, - _root: Option<&'r Self>, - _parent: Option> - ) -> KResult<&i32> { - if self.test_u8_hex.is_some() { - return Ok(self.test_u8_hex.as_ref().unwrap()); - } - self.test_u8_hex = Some(18446744073709551615 as i32); - return Ok(self.test_u8_hex.as_ref().unwrap()); - } -} diff --git a/spec/rust/src/formats/zlib_surrounded.rs b/spec/rust/src/formats/zlib_surrounded.rs deleted file mode 100644 index 7591b1032..000000000 --- a/spec/rust/src/formats/zlib_surrounded.rs +++ /dev/null @@ -1,83 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(RawIdentifier(NamedIdentifier(zlib)), NoRepeat) -// extraAttrForIO(RawIdentifier(NamedIdentifier(zlib)), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ZlibSurrounded { - pub pre: Vec, - pub zlib: Option, - pub post: Vec, - pub raw_zlib: Vec, - pub raw_raw_zlib: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ZlibSurrounded { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.pre = _io.read_bytes(4 as usize)?.to_vec(); - // attrProcess(ProcessZlib, RawIdentifier(RawIdentifier(NamedIdentifier(zlib))), RawIdentifier(NamedIdentifier(zlib)), NoRepeat) - self.zlib = Some(Self::read_into::(&BytesReader::new(_io.read_bytes(12 as usize)?), Some(self), _parent.push(self))?); - self.post = _io.read_bytes(4 as usize)?.to_vec(); - Ok(()) - } -} -impl<'r, 's: 'r> ZlibSurrounded { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ZlibSurrounded::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} - -#[derive(Default, Debug, PartialEq)] -pub struct ZlibSurrounded_Inflated { - pub num: i32, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ZlibSurrounded_Inflated { - type Root = ZlibSurrounded; - type ParentStack = (&'r ZlibSurrounded, >::ParentStack); - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - self.num = _io.read_s4le()?; - Ok(()) - } -} -impl<'r, 's: 'r> ZlibSurrounded_Inflated { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ZlibSurrounded_Inflated::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/formats/zlib_with_header_78.rs b/spec/rust/src/formats/zlib_with_header_78.rs deleted file mode 100644 index 803fea25c..000000000 --- a/spec/rust/src/formats/zlib_with_header_78.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild - -#![allow(unused_imports)] -#![allow(non_snake_case)] -#![allow(non_camel_case_types)] - -use kaitai::*; -use std::{fs, path::PathBuf, convert::{TryFrom, TryInto}}; -// extraAttrForIO(NamedIdentifier(data), NoRepeat) - -#[derive(Default, Debug, PartialEq)] -pub struct ZlibWithHeader78 { - pub data: Vec, - pub raw_data: Vec, -} -impl<'r, 's: 'r> KStruct<'r, 's> for ZlibWithHeader78 { - type Root = Self; - type ParentStack = KStructUnit; - - fn read( - &mut self, - _io: &'s S, - _root: Option<&'r Self::Root>, - _parent: Option> - ) -> KResult<()> { - // attrProcess(ProcessZlib, RawIdentifier(NamedIdentifier(data)), NamedIdentifier(data), NoRepeat) - Ok(()) - } -} -impl<'r, 's: 'r> ZlibWithHeader78 { - pub fn from_file(path: &str) -> Self { - let bytes = fs::read(path).unwrap(); - let reader = BytesReader::new(&bytes); - let mut obj = ZlibWithHeader78::default(); - - if let Err(err) = obj.read(&reader, None, None) { - panic!("error '{:?}' reading from file '{}'", err, path); - } - - obj - } - -} diff --git a/spec/rust/src/lib.rs b/spec/rust/src/lib.rs new file mode 100644 index 000000000..cfa374bdb --- /dev/null +++ b/spec/rust/src/lib.rs @@ -0,0 +1 @@ +// empty \ No newline at end of file diff --git a/spec/rust/src/test_bcd_user_type_be.rs b/spec/rust/src/test_bcd_user_type_be.rs deleted file mode 100644 index 9577c7cb0..000000000 --- a/spec/rust/src/test_bcd_user_type_be.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BcdUserTypeBe; - -#[test] -fn test_bcd_user_type_be() { - if let Ok(r) = BcdUserTypeBe::from_file("src/bcd_user_type_be.bin") { - - assert_eq!(r.ltr.as_int, 12345678); - assert_eq!(r.ltr.as_str, "12345678"); - assert_eq!(r.rtl.as_int, 87654321); - assert_eq!(r.rtl.as_str, "87654321"); - assert_eq!(r.leading_zero_ltr.as_int, 123456); - assert_eq!(r.leading_zero_ltr.as_str, "00123456"); - } -} diff --git a/spec/rust/src/test_bcd_user_type_le.rs b/spec/rust/src/test_bcd_user_type_le.rs deleted file mode 100644 index ec7eee864..000000000 --- a/spec/rust/src/test_bcd_user_type_le.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BcdUserTypeLe; - -#[test] -fn test_bcd_user_type_le() { - if let Ok(r) = BcdUserTypeLe::from_file("src/bcd_user_type_le.bin") { - - assert_eq!(r.ltr.as_int, 12345678); - assert_eq!(r.ltr.as_str, "12345678"); - assert_eq!(r.rtl.as_int, 87654321); - assert_eq!(r.rtl.as_str, "87654321"); - assert_eq!(r.leading_zero_ltr.as_int, 123456); - assert_eq!(r.leading_zero_ltr.as_str, "00123456"); - } -} diff --git a/spec/rust/src/test_bits_byte_aligned.rs b/spec/rust/src/test_bits_byte_aligned.rs deleted file mode 100644 index e45589006..000000000 --- a/spec/rust/src/test_bits_byte_aligned.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsByteAligned; - -#[test] -fn test_bits_byte_aligned() { - if let Ok(r) = BitsByteAligned::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, 20); - assert_eq!(r.byte_1, 65); - assert_eq!(r.two, 2); - assert_eq!(r.three, false); - assert_eq!(r.byte_2, 75); - assert_eq!(r.four, 2892); - assert_eq!(r.byte_3, &[0xff]); - assert_eq!(r.full_byte, 255); - assert_eq!(r.byte_4, 80); - } -} diff --git a/spec/rust/src/test_bits_enum.rs b/spec/rust/src/test_bits_enum.rs deleted file mode 100644 index 433004059..000000000 --- a/spec/rust/src/test_bits_enum.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsEnum; - -#[test] -fn test_bits_enum() { - if let Ok(r) = BitsEnum::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, BitsEnum_Animal::Platypus); - assert_eq!(r.two, BitsEnum_Animal::Horse); - assert_eq!(r.three, BitsEnum_Animal::Cat); - } -} diff --git a/spec/rust/src/test_bits_seq_endian_combo.rs b/spec/rust/src/test_bits_seq_endian_combo.rs deleted file mode 100644 index 042023f58..000000000 --- a/spec/rust/src/test_bits_seq_endian_combo.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSeqEndianCombo; - -#[test] -fn test_bits_seq_endian_combo() { - if let Ok(r) = BitsSeqEndianCombo::from_file("src/process_xor_4.bin") { - - assert_eq!(r.be1, 59); - assert_eq!(r.be2, 187); - assert_eq!(r.le3, 163); - assert_eq!(r.be4, 20); - assert_eq!(r.le5, 10); - assert_eq!(r.le6, 36); - assert_eq!(r.le7, 26); - assert_eq!(r.be8, true); - } -} diff --git a/spec/rust/src/test_bits_shift_by_b32_le.rs b/spec/rust/src/test_bits_shift_by_b32_le.rs deleted file mode 100644 index 79c69a18f..000000000 --- a/spec/rust/src/test_bits_shift_by_b32_le.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsShiftByB32Le; - -#[test] -fn test_bits_shift_by_b32_le() { - if let Ok(r) = BitsShiftByB32Le::from_file("src/bits_shift_by_b32_le.bin") { - - assert_eq!(r.a, 4294967295); - assert_eq!(r.b, 0); - } -} diff --git a/spec/rust/src/test_bits_shift_by_b64_le.rs b/spec/rust/src/test_bits_shift_by_b64_le.rs deleted file mode 100644 index 20a51ab94..000000000 --- a/spec/rust/src/test_bits_shift_by_b64_le.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsShiftByB64Le; - -#[test] -fn test_bits_shift_by_b64_le() { - if let Ok(r) = BitsShiftByB64Le::from_file("src/bits_shift_by_b64_le.bin") { - - assert_eq!(r.a, 18446744073709551615); - assert_eq!(r.b, 0); - } -} diff --git a/spec/rust/src/test_bits_signed_res_b32_be.rs b/spec/rust/src/test_bits_signed_res_b32_be.rs deleted file mode 100644 index 4efcec4c6..000000000 --- a/spec/rust/src/test_bits_signed_res_b32_be.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSignedResB32Be; - -#[test] -fn test_bits_signed_res_b32_be() { - if let Ok(r) = BitsSignedResB32Be::from_file("src/bits_shift_by_b32_le.bin") { - - assert_eq!(r.a, 4294967295); - } -} diff --git a/spec/rust/src/test_bits_signed_res_b32_le.rs b/spec/rust/src/test_bits_signed_res_b32_le.rs deleted file mode 100644 index 08f93abbc..000000000 --- a/spec/rust/src/test_bits_signed_res_b32_le.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSignedResB32Le; - -#[test] -fn test_bits_signed_res_b32_le() { - if let Ok(r) = BitsSignedResB32Le::from_file("src/bits_shift_by_b32_le.bin") { - - assert_eq!(r.a, 4294967295); - } -} diff --git a/spec/rust/src/test_bits_signed_shift_b32_le.rs b/spec/rust/src/test_bits_signed_shift_b32_le.rs deleted file mode 100644 index b57988f9f..000000000 --- a/spec/rust/src/test_bits_signed_shift_b32_le.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSignedShiftB32Le; - -#[test] -fn test_bits_signed_shift_b32_le() { - if let Ok(r) = BitsSignedShiftB32Le::from_file("src/bits_signed_shift_b32_le.bin") { - - assert_eq!(r.a, 0); - assert_eq!(r.b, 255); - } -} diff --git a/spec/rust/src/test_bits_signed_shift_b64_le.rs b/spec/rust/src/test_bits_signed_shift_b64_le.rs deleted file mode 100644 index 196b6d995..000000000 --- a/spec/rust/src/test_bits_signed_shift_b64_le.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSignedShiftB64Le; - -#[test] -fn test_bits_signed_shift_b64_le() { - if let Ok(r) = BitsSignedShiftB64Le::from_file("src/bits_signed_shift_b64_le.bin") { - - assert_eq!(r.a, 0); - assert_eq!(r.b, 255); - } -} diff --git a/spec/rust/src/test_bits_simple.rs b/spec/rust/src/test_bits_simple.rs deleted file mode 100644 index c074a740a..000000000 --- a/spec/rust/src/test_bits_simple.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSimple; - -#[test] -fn test_bits_simple() { - if let Ok(r) = BitsSimple::from_file("src/fixed_struct.bin") { - - assert_eq!(r.byte_1, 80); - assert_eq!(r.byte_2, 65); - assert_eq!(r.bits_a, false); - assert_eq!(r.bits_b, 4); - assert_eq!(r.bits_c, 3); - assert_eq!(r.large_bits_1, 300); - assert_eq!(r.spacer, 5); - assert_eq!(r.large_bits_2, 1329); - assert_eq!(r.normal_s2, -1); - assert_eq!(r.byte_8_9_10, 5259587); - assert_eq!(r.byte_11_to_14, 1261262125); - assert_eq!(r.byte_15_to_19, 293220057087); - assert_eq!(r.byte_20_to_27, 18446744073709551615); - assert_eq!(r.test_if_b1, 123); - } -} diff --git a/spec/rust/src/test_bits_simple_le.rs b/spec/rust/src/test_bits_simple_le.rs deleted file mode 100644 index be32e114d..000000000 --- a/spec/rust/src/test_bits_simple_le.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSimpleLe; - -#[test] -fn test_bits_simple_le() { - if let Ok(r) = BitsSimpleLe::from_file("src/fixed_struct.bin") { - - assert_eq!(r.byte_1, 80); - assert_eq!(r.byte_2, 65); - assert_eq!(r.bits_a, true); - assert_eq!(r.bits_b, 1); - assert_eq!(r.bits_c, 4); - assert_eq!(r.large_bits_1, 331); - assert_eq!(r.spacer, 3); - assert_eq!(r.large_bits_2, 393); - assert_eq!(r.normal_s2, -1); - assert_eq!(r.byte_8_9_10, 4407632); - assert_eq!(r.byte_11_to_14, 760556875); - assert_eq!(r.byte_15_to_19, 1099499455812); - assert_eq!(r.byte_20_to_27, 18446744073709551615); - assert_eq!(r.test_if_b1, 123); - } -} diff --git a/spec/rust/src/test_bits_unaligned_b32_be.rs b/spec/rust/src/test_bits_unaligned_b32_be.rs deleted file mode 100644 index 8b79d1fc7..000000000 --- a/spec/rust/src/test_bits_unaligned_b32_be.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsUnalignedB32Be; - -#[test] -fn test_bits_unaligned_b32_be() { - if let Ok(r) = BitsUnalignedB32Be::from_file("src/process_xor_4.bin") { - - assert_eq!(r.a, true); - assert_eq!(r.b, 3648472617); - assert_eq!(r.c, 10); - } -} diff --git a/spec/rust/src/test_bits_unaligned_b32_le.rs b/spec/rust/src/test_bits_unaligned_b32_le.rs deleted file mode 100644 index f10b8fea3..000000000 --- a/spec/rust/src/test_bits_unaligned_b32_le.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsUnalignedB32Le; - -#[test] -fn test_bits_unaligned_b32_le() { - if let Ok(r) = BitsUnalignedB32Le::from_file("src/process_xor_4.bin") { - - assert_eq!(r.a, false); - assert_eq!(r.b, 173137398); - assert_eq!(r.c, 69); - } -} diff --git a/spec/rust/src/test_bits_unaligned_b64_be.rs b/spec/rust/src/test_bits_unaligned_b64_be.rs deleted file mode 100644 index f363228f6..000000000 --- a/spec/rust/src/test_bits_unaligned_b64_be.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsUnalignedB64Be; - -#[test] -fn test_bits_unaligned_b64_be() { - if let Ok(r) = BitsUnalignedB64Be::from_file("src/process_xor_4.bin") { - - assert_eq!(r.a, true); - assert_eq!(r.b, 15670070570729969769); - assert_eq!(r.c, 14); - } -} diff --git a/spec/rust/src/test_bits_unaligned_b64_le.rs b/spec/rust/src/test_bits_unaligned_b64_le.rs deleted file mode 100644 index 01e65d299..000000000 --- a/spec/rust/src/test_bits_unaligned_b64_le.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsUnalignedB64Le; - -#[test] -fn test_bits_unaligned_b64_le() { - if let Ok(r) = BitsUnalignedB64Le::from_file("src/process_xor_4.bin") { - - assert_eq!(r.a, false); - assert_eq!(r.b, 1902324737369038326); - assert_eq!(r.c, 71); - } -} diff --git a/spec/rust/src/test_buffered_struct.rs b/spec/rust/src/test_buffered_struct.rs deleted file mode 100644 index ef2a828dc..000000000 --- a/spec/rust/src/test_buffered_struct.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BufferedStruct; - -#[test] -fn test_buffered_struct() { - if let Ok(r) = BufferedStruct::from_file("src/buffered_struct.bin") { - - assert_eq!(r.len1, 16); - assert_eq!(r.block1.number1, 66); - assert_eq!(r.block1.number2, 67); - assert_eq!(r.len2, 8); - assert_eq!(r.block2.number1, 68); - assert_eq!(r.block2.number2, 69); - assert_eq!(r.finisher, 238); - } -} diff --git a/spec/rust/src/test_bytes_pad_term.rs b/spec/rust/src/test_bytes_pad_term.rs deleted file mode 100644 index 14706cc4f..000000000 --- a/spec/rust/src/test_bytes_pad_term.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::BytesPadTerm; - -#[test] -fn test_bytes_pad_term() { - if let Ok(r) = BytesPadTerm::from_file("src/str_pad_term.bin") { - - assert_eq!(r.str_pad, &[0x73, 0x74, 0x72, 0x31]); - assert_eq!(r.str_term, &[0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f]); - assert_eq!(r.str_term_and_pad, &[0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b]); - assert_eq!(r.str_term_include, &[0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40]); - } -} diff --git a/spec/rust/src/test_cast_nested.rs b/spec/rust/src/test_cast_nested.rs deleted file mode 100644 index 120413e35..000000000 --- a/spec/rust/src/test_cast_nested.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastNested; - -#[test] -fn test_cast_nested() { - if let Ok(r) = CastNested::from_file("src/switch_opcodes.bin") { - - assert_eq!(r.opcodes_0_str.value, "foobar"); - assert_eq!(r.opcodes_0_str_value, "foobar"); - assert_eq!(r.opcodes_1_int.value, 66); - assert_eq!(r.opcodes_1_int_value, 66); - } -} diff --git a/spec/rust/src/test_cast_to_imported.rs b/spec/rust/src/test_cast_to_imported.rs deleted file mode 100644 index 656c4c6dd..000000000 --- a/spec/rust/src/test_cast_to_imported.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastToImported; - -#[test] -fn test_cast_to_imported() { - if let Ok(r) = CastToImported::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one.one, 80); - assert_eq!(r.one_casted.one, 80); - } -} diff --git a/spec/rust/src/test_cast_to_top.rs b/spec/rust/src/test_cast_to_top.rs deleted file mode 100644 index 22abe6450..000000000 --- a/spec/rust/src/test_cast_to_top.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastToTop; - -#[test] -fn test_cast_to_top() { - if let Ok(r) = CastToTop::from_file("src/fixed_struct.bin") { - - assert_eq!(r.code, 80); - assert_eq!(r.header.code, 65); - assert_eq!(r.header_casted.code, 65); - } -} diff --git a/spec/rust/src/test_combine_bool.rs b/spec/rust/src/test_combine_bool.rs deleted file mode 100644 index 6028ecc4a..000000000 --- a/spec/rust/src/test_combine_bool.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CombineBool; - -#[test] -fn test_combine_bool() { - if let Ok(r) = CombineBool::from_file("src/enum_negative.bin") { - - assert_eq!(r.bool_bit, true); - assert_eq!(r.bool_calc_bit, false); - } -} diff --git a/spec/rust/src/test_combine_bytes.rs b/spec/rust/src/test_combine_bytes.rs deleted file mode 100644 index 3478e95d8..000000000 --- a/spec/rust/src/test_combine_bytes.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CombineBytes; - -#[test] -fn test_combine_bytes() { - if let Ok(r) = CombineBytes::from_file("src/term_strz.bin") { - - assert_eq!(r.bytes_term, vec!([0x66, 0x6f, 0x6f])); - assert_eq!(r.bytes_limit, vec!([0x62, 0x61, 0x72, 0x7c])); - assert_eq!(r.bytes_eos, vec!([0x62, 0x61, 0x7a, 0x40])); - assert_eq!(r.bytes_calc, vec!([0x52, 0x6e, 0x44])); - assert_eq!(r.term_or_limit, vec!([0x66, 0x6f, 0x6f])); - assert_eq!(r.term_or_eos, vec!([0x62, 0x61, 0x7a, 0x40])); - assert_eq!(r.term_or_calc, vec!([0x66, 0x6f, 0x6f])); - assert_eq!(r.limit_or_eos, vec!([0x62, 0x61, 0x72, 0x7c])); - assert_eq!(r.limit_or_calc, vec!([0x52, 0x6e, 0x44])); - assert_eq!(r.eos_or_calc, vec!([0x62, 0x61, 0x7a, 0x40])); - } -} diff --git a/spec/rust/src/test_combine_enum.rs b/spec/rust/src/test_combine_enum.rs deleted file mode 100644 index c8a1da4b6..000000000 --- a/spec/rust/src/test_combine_enum.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CombineEnum; - -#[test] -fn test_combine_enum() { - if let Ok(r) = CombineEnum::from_file("src/enum_0.bin") { - - assert_eq!(r.enum_u4, CombineEnum__Animal::PIG); - assert_eq!(r.enum_u2, CombineEnum__Animal::HORSE); - assert_eq!(r.enum_u4_u2, CombineEnum__Animal::HORSE); - } -} diff --git a/spec/rust/src/test_combine_str.rs b/spec/rust/src/test_combine_str.rs deleted file mode 100644 index 19bbd71d6..000000000 --- a/spec/rust/src/test_combine_str.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CombineStr; - -#[test] -fn test_combine_str() { - if let Ok(r) = CombineStr::from_file("src/term_strz.bin") { - - assert_eq!(r.str_term, "foo"); - assert_eq!(r.str_limit, "bar|"); - assert_eq!(r.str_eos, "baz@"); - assert_eq!(r.str_calc, "bar"); - assert_eq!(r.str_calc_bytes, "baz"); - assert_eq!(r.term_or_limit, "foo"); - assert_eq!(r.term_or_eos, "baz@"); - assert_eq!(r.term_or_calc, "foo"); - assert_eq!(r.term_or_calc_bytes, "baz"); - assert_eq!(r.limit_or_eos, "bar|"); - assert_eq!(r.limit_or_calc, "bar"); - assert_eq!(r.limit_or_calc_bytes, "bar|"); - assert_eq!(r.eos_or_calc, "bar"); - assert_eq!(r.eos_or_calc_bytes, "baz@"); - assert_eq!(r.calc_or_calc_bytes, "baz"); - } -} diff --git a/spec/rust/src/test_debug_switch_user.rs b/spec/rust/src/test_debug_switch_user.rs deleted file mode 100644 index a708987d3..000000000 --- a/spec/rust/src/test_debug_switch_user.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DebugSwitchUser; - -#[test] -fn test_debug_switch_user() { - if let Ok(r) = DebugSwitchUser::from_file("src/nav_parent_switch.bin") { - - assert_eq!(r.code, 1); - assert_eq!(r.data.val, -190); - } -} diff --git a/spec/rust/src/test_default_big_endian.rs b/spec/rust/src/test_default_big_endian.rs deleted file mode 100644 index 3d85db5d1..000000000 --- a/spec/rust/src/test_default_big_endian.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultBigEndian; - -#[test] -fn test_default_big_endian() { - if let Ok(r) = DefaultBigEndian::from_file("src/enum_0.bin") { - - assert_eq!(r.one, 117440512); - } -} diff --git a/spec/rust/src/test_default_bit_endian_mod.rs b/spec/rust/src/test_default_bit_endian_mod.rs deleted file mode 100644 index 82725b2ee..000000000 --- a/spec/rust/src/test_default_bit_endian_mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultBitEndianMod; - -#[test] -fn test_default_bit_endian_mod() { - if let Ok(r) = DefaultBitEndianMod::from_file("src/fixed_struct.bin") { - - assert_eq!(r.main.one, 336); - assert_eq!(r.main.two, 8608); - assert_eq!(r.main.nest.two, 11595); - assert_eq!(r.main.nest_be.two, 12799); - } -} diff --git a/spec/rust/src/test_default_endian_expr_inherited.rs b/spec/rust/src/test_default_endian_expr_inherited.rs deleted file mode 100644 index bc30542b9..000000000 --- a/spec/rust/src/test_default_endian_expr_inherited.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprInherited; - -#[test] -fn test_default_endian_expr_inherited() { - if let Ok(r) = DefaultEndianExprInherited::from_file("src/endian_expr.bin") { - - assert_eq!(r.docs[0 as usize].indicator, &[0x49, 0x49]); - assert_eq!(r.docs[0 as usize].main.insides.some_int, 66); - assert_eq!(r.docs[0 as usize].main.insides.more.some_int1, 16896); - assert_eq!(r.docs[0 as usize].main.insides.more.some_int2, 66); - assert_eq!(r.docs[0 as usize].main.insides.more.some_inst, 66); - assert_eq!(r.docs[1 as usize].indicator, &[0x4d, 0x4d]); - assert_eq!(r.docs[1 as usize].main.insides.some_int, 66); - assert_eq!(r.docs[1 as usize].main.insides.more.some_int1, 66); - assert_eq!(r.docs[1 as usize].main.insides.more.some_int2, 16896); - assert_eq!(r.docs[1 as usize].main.insides.more.some_inst, 1107296256); - assert_eq!(r.docs[2 as usize].indicator, &[0x58, 0x58]); - assert_eq!(r.docs[2 as usize].main.insides.some_int, 66); - assert_eq!(r.docs[2 as usize].main.insides.more.some_int1, 66); - assert_eq!(r.docs[2 as usize].main.insides.more.some_int2, 16896); - assert_eq!(r.docs[2 as usize].main.insides.more.some_inst, 1107296256); - } -} diff --git a/spec/rust/src/test_default_endian_expr_is_be.rs b/spec/rust/src/test_default_endian_expr_is_be.rs deleted file mode 100644 index 26a034410..000000000 --- a/spec/rust/src/test_default_endian_expr_is_be.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprIsBe; - -#[test] -fn test_default_endian_expr_is_be() { - if let Ok(r) = DefaultEndianExprIsBe::from_file("src/endian_expr.bin") { - - assert_eq!(r.docs[0 as usize].indicator, &[0x49, 0x49]); - assert_eq!(r.docs[0 as usize].main.some_int, 66); - assert_eq!(r.docs[0 as usize].main.some_int_be, 66); - assert_eq!(r.docs[0 as usize].main.some_int_le, 66); - assert_eq!(r.docs[0 as usize].main.inst_int, 66); - assert_eq!(r.docs[0 as usize].main.inst_sub.foo, 66); - assert_eq!(r.docs[1 as usize].indicator, &[0x4d, 0x4d]); - assert_eq!(r.docs[1 as usize].main.some_int, 66); - assert_eq!(r.docs[1 as usize].main.some_int_be, 66); - assert_eq!(r.docs[1 as usize].main.some_int_le, 66); - assert_eq!(r.docs[1 as usize].main.inst_int, 1107296256); - assert_eq!(r.docs[1 as usize].main.inst_sub.foo, 1107296256); - assert_eq!(r.docs[2 as usize].indicator, &[0x58, 0x58]); - assert_eq!(r.docs[2 as usize].main.some_int, 1107296256); - assert_eq!(r.docs[2 as usize].main.some_int_be, 66); - assert_eq!(r.docs[2 as usize].main.some_int_le, 66); - assert_eq!(r.docs[2 as usize].main.inst_int, 66); - assert_eq!(r.docs[2 as usize].main.inst_sub.foo, 66); - } -} diff --git a/spec/rust/src/test_default_endian_expr_is_le.rs b/spec/rust/src/test_default_endian_expr_is_le.rs deleted file mode 100644 index c02ea05f3..000000000 --- a/spec/rust/src/test_default_endian_expr_is_le.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprIsLe; - -#[test] -fn test_default_endian_expr_is_le() { - if let Ok(r) = DefaultEndianExprIsLe::from_file("src/endian_expr.bin") { - - assert_eq!(r.docs[0 as usize].indicator, &[0x49, 0x49]); - assert_eq!(r.docs[0 as usize].main.some_int, 66); - assert_eq!(r.docs[0 as usize].main.some_int_be, 66); - assert_eq!(r.docs[0 as usize].main.some_int_le, 66); - assert_eq!(r.docs[1 as usize].indicator, &[0x4d, 0x4d]); - assert_eq!(r.docs[1 as usize].main.some_int, 66); - assert_eq!(r.docs[1 as usize].main.some_int_be, 66); - assert_eq!(r.docs[1 as usize].main.some_int_le, 66); - assert_eq!(r.docs[2 as usize].indicator, &[0x58, 0x58]); - assert_eq!(r.docs[2 as usize].main.some_int, 66); - assert_eq!(r.docs[2 as usize].main.some_int_be, 66); - assert_eq!(r.docs[2 as usize].main.some_int_le, 66); - } -} diff --git a/spec/rust/src/test_default_endian_mod.rs b/spec/rust/src/test_default_endian_mod.rs deleted file mode 100644 index 6823715ed..000000000 --- a/spec/rust/src/test_default_endian_mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianMod; - -#[test] -fn test_default_endian_mod() { - if let Ok(r) = DefaultEndianMod::from_file("src/fixed_struct.bin") { - - assert_eq!(r.main.one, 1262698832); - assert_eq!(r.main.nest.two, -52947); - assert_eq!(r.main.nest_be.two, 1346454347); - } -} diff --git a/spec/rust/src/test_docstrings.rs b/spec/rust/src/test_docstrings.rs deleted file mode 100644 index 3ab726f38..000000000 --- a/spec/rust/src/test_docstrings.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Docstrings; - -#[test] -fn test_docstrings() { - if let Ok(r) = Docstrings::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_docstrings_docref.rs b/spec/rust/src/test_docstrings_docref.rs deleted file mode 100644 index c2c1df62e..000000000 --- a/spec/rust/src/test_docstrings_docref.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DocstringsDocref; - -#[test] -fn test_docstrings_docref() { - if let Ok(r) = DocstringsDocref::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_docstrings_docref_multi.rs b/spec/rust/src/test_docstrings_docref_multi.rs deleted file mode 100644 index 1bc4f5a53..000000000 --- a/spec/rust/src/test_docstrings_docref_multi.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::DocstringsDocrefMulti; - -#[test] -fn test_docstrings_docref_multi() { - if let Ok(r) = DocstringsDocrefMulti::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_enum_0.rs b/spec/rust/src/test_enum_0.rs deleted file mode 100644 index bf3a99705..000000000 --- a/spec/rust/src/test_enum_0.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Enum0; - -#[test] -fn test_enum_0() { - if let Ok(r) = Enum0::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, Enum0_Animal::Cat); - assert_eq!(r.pet_2, Enum0_Animal::Chicken); - } -} diff --git a/spec/rust/src/test_enum_1.rs b/spec/rust/src/test_enum_1.rs deleted file mode 100644 index 229012977..000000000 --- a/spec/rust/src/test_enum_1.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Enum1; - -#[test] -fn test_enum_1() { - if let Ok(r) = Enum1::from_file("src/enum_0.bin") { - - assert_eq!(r.main.submain.pet_1, Enum1_MainObj_Animal::Cat); - assert_eq!(r.main.submain.pet_2, Enum1_MainObj_Animal::Chicken); - } -} diff --git a/spec/rust/src/test_enum_deep.rs b/spec/rust/src/test_enum_deep.rs deleted file mode 100644 index 0f8b5178d..000000000 --- a/spec/rust/src/test_enum_deep.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumDeep; - -#[test] -fn test_enum_deep() { - if let Ok(r) = EnumDeep::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, EnumDeep_Container1_Animal::Cat); - assert_eq!(r.pet_2, EnumDeep_Container1_Container2_Animal::Hare); - } -} diff --git a/spec/rust/src/test_enum_deep_literals.rs b/spec/rust/src/test_enum_deep_literals.rs deleted file mode 100644 index 4ad8ad1bc..000000000 --- a/spec/rust/src/test_enum_deep_literals.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumDeepLiterals; - -#[test] -fn test_enum_deep_literals() { - if let Ok(r) = EnumDeepLiterals::from_file("src/enum_0.bin") { - - assert_eq!(r.is_pet_1_ok, true); - assert_eq!(r.is_pet_2_ok, true); - } -} diff --git a/spec/rust/src/test_enum_fancy.rs b/spec/rust/src/test_enum_fancy.rs deleted file mode 100644 index d999dfff3..000000000 --- a/spec/rust/src/test_enum_fancy.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumFancy; - -#[test] -fn test_enum_fancy() { - if let Ok(r) = EnumFancy::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, EnumFancy_Animal::Cat); - assert_eq!(r.pet_2, EnumFancy_Animal::Chicken); - } -} diff --git a/spec/rust/src/test_enum_for_unknown_id.rs b/spec/rust/src/test_enum_for_unknown_id.rs deleted file mode 100644 index ed34ca9b1..000000000 --- a/spec/rust/src/test_enum_for_unknown_id.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumForUnknownId; - -#[test] -fn test_enum_for_unknown_id() { - if let Ok(r) = EnumForUnknownId::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, 80); - } -} diff --git a/spec/rust/src/test_enum_if.rs b/spec/rust/src/test_enum_if.rs deleted file mode 100644 index 28e21df8d..000000000 --- a/spec/rust/src/test_enum_if.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumIf; - -#[test] -fn test_enum_if() { - if let Ok(r) = EnumIf::from_file("src/if_struct.bin") { - - assert_eq!(r.op1.opcode, EnumIf_Opcodes::AString); - assert_eq!(r.op1.arg_str.str, "foo"); - assert_eq!(r.op2.opcode, EnumIf_Opcodes::ATuple); - assert_eq!(r.op2.arg_tuple.num1, 66); - assert_eq!(r.op2.arg_tuple.num2, 67); - assert_eq!(r.op3.opcode, EnumIf_Opcodes::AString); - assert_eq!(r.op3.arg_str.str, "bar"); - } -} diff --git a/spec/rust/src/test_enum_import.rs b/spec/rust/src/test_enum_import.rs deleted file mode 100644 index 9dd1fca8e..000000000 --- a/spec/rust/src/test_enum_import.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumImport; - -#[test] -fn test_enum_import() { - if let Ok(r) = EnumImport::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, Enum0__Animal::CAT); - assert_eq!(r.pet_2, EnumDeep__Container1__Container2__Animal::HARE); - } -} diff --git a/spec/rust/src/test_enum_int_range_s.rs b/spec/rust/src/test_enum_int_range_s.rs deleted file mode 100644 index c696c12ad..000000000 --- a/spec/rust/src/test_enum_int_range_s.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumIntRangeS; - -#[test] -fn test_enum_int_range_s() { - if let Ok(r) = EnumIntRangeS::from_file("src/enum_int_range_s.bin") { - - assert_eq!(r.f1, EnumIntRangeS__Constants::INT_MIN); - assert_eq!(r.f2, EnumIntRangeS__Constants::ZERO); - assert_eq!(r.f3, EnumIntRangeS__Constants::INT_MAX); - } -} diff --git a/spec/rust/src/test_enum_int_range_u.rs b/spec/rust/src/test_enum_int_range_u.rs deleted file mode 100644 index fcb7d722c..000000000 --- a/spec/rust/src/test_enum_int_range_u.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumIntRangeU; - -#[test] -fn test_enum_int_range_u() { - if let Ok(r) = EnumIntRangeU::from_file("src/enum_int_range_u.bin") { - - assert_eq!(r.f1, EnumIntRangeU__Constants::ZERO); - assert_eq!(r.f2, EnumIntRangeU__Constants::INT_MAX); - } -} diff --git a/spec/rust/src/test_enum_invalid.rs b/spec/rust/src/test_enum_invalid.rs deleted file mode 100644 index de93ff0d7..000000000 --- a/spec/rust/src/test_enum_invalid.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumInvalid; - -#[test] -fn test_enum_invalid() { - if let Ok(r) = EnumInvalid::from_file("src/term_strz.bin") { - - assert_eq!(r.pet_1, EnumInvalid__Animal::DOG); - assert_eq!(r.pet_2, 111); - } -} diff --git a/spec/rust/src/test_enum_long_range_s.rs b/spec/rust/src/test_enum_long_range_s.rs deleted file mode 100644 index 4d6b324b0..000000000 --- a/spec/rust/src/test_enum_long_range_s.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumLongRangeS; - -#[test] -fn test_enum_long_range_s() { - if let Ok(r) = EnumLongRangeS::from_file("src/enum_long_range_s.bin") { - - assert_eq!(r.f1, EnumLongRangeS__Constants::LONG_MIN); - assert_eq!(r.f2, EnumLongRangeS__Constants::INT_BELOW_MIN); - assert_eq!(r.f3, EnumLongRangeS__Constants::INT_MIN); - assert_eq!(r.f4, EnumLongRangeS__Constants::ZERO); - assert_eq!(r.f5, EnumLongRangeS__Constants::INT_MAX); - assert_eq!(r.f6, EnumLongRangeS__Constants::INT_OVER_MAX); - assert_eq!(r.f7, EnumLongRangeS__Constants::LONG_MAX); - } -} diff --git a/spec/rust/src/test_enum_long_range_u.rs b/spec/rust/src/test_enum_long_range_u.rs deleted file mode 100644 index 9ebf317d4..000000000 --- a/spec/rust/src/test_enum_long_range_u.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumLongRangeU; - -#[test] -fn test_enum_long_range_u() { - if let Ok(r) = EnumLongRangeU::from_file("src/enum_long_range_u.bin") { - - assert_eq!(r.f1, EnumLongRangeU__Constants::ZERO); - assert_eq!(r.f2, EnumLongRangeU__Constants::INT_MAX); - assert_eq!(r.f3, EnumLongRangeU__Constants::INT_OVER_MAX); - assert_eq!(r.f4, EnumLongRangeU__Constants::LONG_MAX); - } -} diff --git a/spec/rust/src/test_enum_negative.rs b/spec/rust/src/test_enum_negative.rs deleted file mode 100644 index f473aaf7f..000000000 --- a/spec/rust/src/test_enum_negative.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumNegative; - -#[test] -fn test_enum_negative() { - if let Ok(r) = EnumNegative::from_file("src/enum_negative.bin") { - - assert_eq!(r.f1, EnumNegative_Constants::NegativeOne); - assert_eq!(r.f2, EnumNegative_Constants::PositiveOne); - } -} diff --git a/spec/rust/src/test_enum_of_value_inst.rs b/spec/rust/src/test_enum_of_value_inst.rs deleted file mode 100644 index 8005cf9cc..000000000 --- a/spec/rust/src/test_enum_of_value_inst.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumOfValueInst; - -#[test] -fn test_enum_of_value_inst() { - if let Ok(r) = EnumOfValueInst::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, EnumOfValueInst_Animal::Cat); - assert_eq!(r.pet_2, EnumOfValueInst_Animal::Chicken); - assert_eq!(r.pet_3, EnumOfValueInst_Animal::Dog); - assert_eq!(r.pet_4, EnumOfValueInst_Animal::Dog); - } -} diff --git a/spec/rust/src/test_enum_to_i.rs b/spec/rust/src/test_enum_to_i.rs deleted file mode 100644 index 5b5c5cedb..000000000 --- a/spec/rust/src/test_enum_to_i.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumToI; - -#[test] -fn test_enum_to_i() { - if let Ok(r) = EnumToI::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, EnumToI__Animal::CAT); - assert_eq!(r.pet_2, EnumToI__Animal::CHICKEN); - assert_eq!(r.pet_1_i, 7); - assert_eq!(r.pet_1_mod, 32775); - assert_eq!(r.one_lt_two, true); - assert_eq!(r.pet_1_eq_int, true); - assert_eq!(r.pet_2_eq_int, false); - } -} diff --git a/spec/rust/src/test_enum_to_i_class_border_1.rs b/spec/rust/src/test_enum_to_i_class_border_1.rs deleted file mode 100644 index 175c56a8c..000000000 --- a/spec/rust/src/test_enum_to_i_class_border_1.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumToIClassBorder1; - -#[test] -fn test_enum_to_i_class_border_1() { - if let Ok(r) = EnumToIClassBorder1::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, EnumToIClassBorder1__Animal::CAT); - assert_eq!(r.pet_2, EnumToIClassBorder1__Animal::CHICKEN); - assert_eq!(r.checker.is_dog, true); - } -} diff --git a/spec/rust/src/test_expr_0.rs b/spec/rust/src/test_expr_0.rs deleted file mode 100644 index daccff261..000000000 --- a/spec/rust/src/test_expr_0.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr0; - -#[test] -fn test_expr_0() { - if let Ok(r) = Expr0::from_file("src/str_encodings.bin") { - - assert_eq!(r.must_be_f7, 247); - assert_eq!(r.must_be_abc123, "abc123"); - } -} diff --git a/spec/rust/src/test_expr_1.rs b/spec/rust/src/test_expr_1.rs deleted file mode 100644 index 44573a63f..000000000 --- a/spec/rust/src/test_expr_1.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr1; - -#[test] -fn test_expr_1() { - if let Ok(r) = Expr1::from_file("src/str_encodings.bin") { - - assert_eq!(r.len_of_1, 10); - assert_eq!(r.len_of_1_mod, 8); - assert_eq!(r.str1, "Some ASC"); - assert_eq!(r.str1_len, 8); - } -} diff --git a/spec/rust/src/test_expr_2.rs b/spec/rust/src/test_expr_2.rs deleted file mode 100644 index 736e9e4ba..000000000 --- a/spec/rust/src/test_expr_2.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr2; - -#[test] -fn test_expr_2() { - if let Ok(r) = Expr2::from_file("src/str_encodings.bin") { - - assert_eq!(r.str1.len_orig, 10); - assert_eq!(r.str1.len_mod, 7); - assert_eq!(r.str1.str, "Some AS"); - assert_eq!(r.str1_len, 7); - assert_eq!(r.str1_len_mod, 7); - assert_eq!(r.str1_byte1, 73); - assert_eq!(r.str1_avg, 73); - assert_eq!(r.str1_char5, "e"); - assert_eq!(r.str1_tuple5.byte0, 101); - assert_eq!(r.str1_tuple5.byte0, 101); - assert_eq!(r.str1_tuple5.byte1, 32); - assert_eq!(r.str1_tuple5.byte2, 65); - assert_eq!(r.str1_tuple5.avg, 48); - assert_eq!(r.str2_tuple5.byte0, 101); - assert_eq!(r.str2_tuple5.byte1, 32); - assert_eq!(r.str2_tuple5.byte2, 65); - assert_eq!(r.str2_tuple5.avg, 48); - } -} diff --git a/spec/rust/src/test_expr_3.rs b/spec/rust/src/test_expr_3.rs deleted file mode 100644 index 4bb03fe9f..000000000 --- a/spec/rust/src/test_expr_3.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr3; - -#[test] -fn test_expr_3() { - if let Ok(r) = Expr3::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, 80); - assert_eq!(r.two, "ACK"); - assert_eq!(r.three, "@ACK"); - assert_eq!(r.four, "_ACK_"); - assert_eq!(r.is_str_eq, true); - assert_eq!(r.is_str_ne, false); - assert_eq!(r.is_str_lt, true); - assert_eq!(r.is_str_gt, false); - assert_eq!(r.is_str_le, true); - assert_eq!(r.is_str_ge, false); - assert_eq!(r.is_str_lt2, true); - assert_eq!(r.test_not, true); - } -} diff --git a/spec/rust/src/test_expr_array.rs b/spec/rust/src/test_expr_array.rs deleted file mode 100644 index 16e25538d..000000000 --- a/spec/rust/src/test_expr_array.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprArray; - -#[test] -fn test_expr_array() { - if let Ok(r) = ExprArray::from_file("src/expr_array.bin") { - - assert_eq!(r.aint_size, 4); - assert_eq!(r.aint_first, 7657765); - assert_eq!(r.aint_last, 16272640); - assert_eq!(r.aint_min, 49185); - assert_eq!(r.aint_max, 1123362332); - assert_eq!(r.afloat_size, 3); - assert_eq!(r.afloat_first, -2.6839530254859364E-121); - assert_eq!(r.afloat_last, -1.1103359815095273E-175); - assert_eq!(r.afloat_min, -8.754689149998834E+288); - assert_eq!(r.afloat_max, -1.1103359815095273E-175); - assert_eq!(r.astr_size, 3); - assert_eq!(r.astr_first, "foo"); - assert_eq!(r.astr_last, "baz"); - assert_eq!(r.astr_min, "bar"); - assert_eq!(r.astr_max, "foo"); - } -} diff --git a/spec/rust/src/test_expr_bits.rs b/spec/rust/src/test_expr_bits.rs deleted file mode 100644 index 316b4a9b6..000000000 --- a/spec/rust/src/test_expr_bits.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprBits; - -#[test] -fn test_expr_bits() { - if let Ok(r) = ExprBits::from_file("src/switch_opcodes.bin") { - - assert_eq!(r.a, 2); - assert_eq!(r.enum_seq, ExprBits__Items::FOO); - assert_eq!(r.byte_size, vec!([0x66, 0x6f])); - assert_eq!(r.repeat_expr.len(), 2); - assert_eq!(r.repeat_expr[0], 111); - assert_eq!(r.repeat_expr[1], 98); - assert_eq!(r.switch_on_type, 97); - assert_eq!(r.switch_on_endian.foo, 29184); - assert_eq!(r.enum_inst, ExprBits__Items::BAR); - assert_eq!(r.inst_pos, 111); - } -} diff --git a/spec/rust/src/test_expr_bytes_cmp.rs b/spec/rust/src/test_expr_bytes_cmp.rs deleted file mode 100644 index c08306a64..000000000 --- a/spec/rust/src/test_expr_bytes_cmp.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprBytesCmp; - -#[test] -fn test_expr_bytes_cmp() { - if let Ok(r) = ExprBytesCmp::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, &[0x50]); - assert_eq!(r.two, &[0x41, 0x43, 0x4b]); - assert_eq!(r.is_eq, true); - assert_eq!(r.is_ne, false); - assert_eq!(r.is_lt, true); - assert_eq!(r.is_gt, false); - assert_eq!(r.is_le, true); - assert_eq!(r.is_ge, false); - assert_eq!(r.is_lt2, false); - assert_eq!(r.is_gt2, true); - } -} diff --git a/spec/rust/src/test_expr_bytes_non_literal.rs b/spec/rust/src/test_expr_bytes_non_literal.rs deleted file mode 100644 index d61cc5872..000000000 --- a/spec/rust/src/test_expr_bytes_non_literal.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprBytesNonLiteral; - -#[test] -fn test_expr_bytes_non_literal() { - if let Ok(r) = ExprBytesNonLiteral::from_file("src/enum_negative.bin") { - - assert_eq!(r.calc_bytes.len(), 2); - assert_eq!(r.calc_bytes[0], 255); - assert_eq!(r.calc_bytes[1], 1); - } -} diff --git a/spec/rust/src/test_expr_bytes_ops.rs b/spec/rust/src/test_expr_bytes_ops.rs deleted file mode 100644 index 093d4a182..000000000 --- a/spec/rust/src/test_expr_bytes_ops.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprBytesOps; - -#[test] -fn test_expr_bytes_ops() { - if let Ok(r) = ExprBytesOps::from_file("src/nav_parent_switch.bin") { - - assert_eq!(r.one_size, 3); - assert_eq!(r.one_first, 1); - assert_eq!(r.one_mid, 66); - assert_eq!(r.one_last, 255); - assert_eq!(r.one_last.to_string(), "255"); - assert_eq!(r.one_min, 1); - assert_eq!(r.one_max, 255); - assert_eq!(r.one_max.to_string(), "255"); - assert_eq!(r.two_size, 3); - assert_eq!(r.two_first, 65); - assert_eq!(r.two_mid, 255); - assert_eq!(r.two_mid.to_string(), "255"); - assert_eq!(r.two_last, 75); - assert_eq!(r.two_min, 65); - assert_eq!(r.two_max, 255); - assert_eq!(r.two_max.to_string(), "255"); - } -} diff --git a/spec/rust/src/test_expr_calc_array_ops.rs b/spec/rust/src/test_expr_calc_array_ops.rs deleted file mode 100644 index 6ce63be43..000000000 --- a/spec/rust/src/test_expr_calc_array_ops.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprCalcArrayOps; - -#[test] -fn test_expr_calc_array_ops() { - if let Ok(r) = ExprCalcArrayOps::from_file("src/fixed_struct.bin") { - - assert_eq!(r.int_array_size, 7); - assert_eq!(r.int_array_first, 10); - assert_eq!(r.int_array_mid, 25); - assert_eq!(r.int_array_last, 1000); - assert_eq!(r.int_array_min, 10); - assert_eq!(r.int_array_max, 1000); - assert_eq!(r.double_array_size, 5); - assert_eq!(r.double_array_first, 10.0); - assert_eq!(r.double_array_mid, 25.0); - assert_eq!(r.double_array_last, 3.14159); - assert_eq!(r.double_array_min, 3.14159); - assert_eq!(r.double_array_max, 100.0); - assert_eq!(r.str_array_size, 4); - assert_eq!(r.str_array_first, "un"); - assert_eq!(r.str_array_mid, "deux"); - assert_eq!(r.str_array_last, "quatre"); - assert_eq!(r.str_array_min, "deux"); - assert_eq!(r.str_array_max, "un"); - } -} diff --git a/spec/rust/src/test_expr_enum.rs b/spec/rust/src/test_expr_enum.rs deleted file mode 100644 index 91a086f1f..000000000 --- a/spec/rust/src/test_expr_enum.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprEnum; - -#[test] -fn test_expr_enum() { - if let Ok(r) = ExprEnum::from_file("src/term_strz.bin") { - - assert_eq!(r.const_dog, ExprEnum_Animal::Dog); - assert_eq!(r.derived_boom, ExprEnum_Animal::Boom); - assert_eq!(r.derived_dog, ExprEnum_Animal::Dog); - } -} diff --git a/spec/rust/src/test_expr_if_int_ops.rs b/spec/rust/src/test_expr_if_int_ops.rs deleted file mode 100644 index 5fcc93aa9..000000000 --- a/spec/rust/src/test_expr_if_int_ops.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprIfIntOps; - -#[test] -fn test_expr_if_int_ops() { - if let Ok(r) = ExprIfIntOps::from_file("src/process_coerce_switch.bin") { - - assert_eq!(r.is_eq_prim, true); - assert_eq!(r.is_eq_boxed, true); - } -} diff --git a/spec/rust/src/test_expr_int_div.rs b/spec/rust/src/test_expr_int_div.rs deleted file mode 100644 index 7ecb682ff..000000000 --- a/spec/rust/src/test_expr_int_div.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprIntDiv; - -#[test] -fn test_expr_int_div() { - if let Ok(r) = ExprIntDiv::from_file("src/fixed_struct.bin") { - - assert_eq!(r.int_u, 1262698832); - assert_eq!(r.int_s, -52947); - assert_eq!(r.div_pos_const, 756); - assert_eq!(r.div_neg_const, -757); - assert_eq!(r.div_pos_seq, 97130679); - assert_eq!(r.div_neg_seq, -4073); - } -} diff --git a/spec/rust/src/test_expr_io_eof.rs b/spec/rust/src/test_expr_io_eof.rs deleted file mode 100644 index cbf9b0606..000000000 --- a/spec/rust/src/test_expr_io_eof.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprIoEof; - -#[test] -fn test_expr_io_eof() { - if let Ok(r) = ExprIoEof::from_file("src/fixed_struct.bin") { - - assert_eq!(r.substream1.one, 1262698832); - assertNull(r.substream1.two); - assert_eq!(r.substream2.one, 4294914349); - assert_eq!(r.substream2.two, 1262698832); - } -} diff --git a/spec/rust/src/test_expr_io_pos.rs b/spec/rust/src/test_expr_io_pos.rs deleted file mode 100644 index 486c0f03f..000000000 --- a/spec/rust/src/test_expr_io_pos.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprIoPos; - -#[test] -fn test_expr_io_pos() { - if let Ok(r) = ExprIoPos::from_file("src/expr_io_pos.bin") { - - assert_eq!(r.substream1.my_str, "CURIOSITY"); - assert_eq!(r.substream1.body, &[0x11, 0x22, 0x33, 0x44]); - assert_eq!(r.substream1.number, 66); - assert_eq!(r.substream2.my_str, "KILLED"); - assert_eq!(r.substream2.body, &[0x61, 0x20, 0x63, 0x61, 0x74]); - assert_eq!(r.substream2.number, 103); - } -} diff --git a/spec/rust/src/test_expr_mod.rs b/spec/rust/src/test_expr_mod.rs deleted file mode 100644 index f9c63448e..000000000 --- a/spec/rust/src/test_expr_mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprMod; - -#[test] -fn test_expr_mod() { - if let Ok(r) = ExprMod::from_file("src/fixed_struct.bin") { - - assert_eq!(r.int_u, 1262698832); - assert_eq!(r.int_s, -52947); - assert_eq!(r.mod_pos_const, 9); - assert_eq!(r.mod_neg_const, 4); - assert_eq!(r.mod_pos_seq, 5); - assert_eq!(r.mod_neg_seq, 2); - } -} diff --git a/spec/rust/src/test_expr_ops_parens.rs b/spec/rust/src/test_expr_ops_parens.rs deleted file mode 100644 index 7cfd742ca..000000000 --- a/spec/rust/src/test_expr_ops_parens.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprOpsParens; - -#[test] -fn test_expr_ops_parens() { - if let Ok(r) = ExprOpsParens::from_file("src/enum_negative.bin") { - - assert_eq!(r.i_sum_to_str, "29"); - assert_eq!(r.f_sum_to_int, 9); - assert_eq!(r.str_concat_len, 10); - assert_eq!(r.str_concat_rev, "9876543210"); - assert_eq!(r.str_concat_substr_2_to_7, "23456"); - assert_eq!(r.str_concat_to_i, 123456789); - assert_eq!(r.bool_eq, 0); - assert_eq!(r.bool_and, 0); - assert_eq!(r.bool_or, 1); - } -} diff --git a/spec/rust/src/test_expr_sizeof_type_0.rs b/spec/rust/src/test_expr_sizeof_type_0.rs deleted file mode 100644 index 67cb1b5ce..000000000 --- a/spec/rust/src/test_expr_sizeof_type_0.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofType0; - -#[test] -fn test_expr_sizeof_type_0() { - if let Ok(r) = ExprSizeofType0::from_file("src/fixed_struct.bin") { - assert_eq!(r.sizeof_block, ((1 + 4) + 2)); - } -} diff --git a/spec/rust/src/test_expr_sizeof_type_1.rs b/spec/rust/src/test_expr_sizeof_type_1.rs deleted file mode 100644 index 9ab8e1f8c..000000000 --- a/spec/rust/src/test_expr_sizeof_type_1.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofType1; - -#[test] -fn test_expr_sizeof_type_1() { - if let Ok(r) = ExprSizeofType1::from_file("src/fixed_struct.bin") { - assert_eq!(r.sizeof_block, (((1 + 4) + 2) + 4)); - assert_eq!(r.sizeof_subblock, 4); - } -} diff --git a/spec/rust/src/test_expr_sizeof_value_0.rs b/spec/rust/src/test_expr_sizeof_value_0.rs deleted file mode 100644 index c51d563a7..000000000 --- a/spec/rust/src/test_expr_sizeof_value_0.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofValue0; - -#[test] -fn test_expr_sizeof_value_0() { - if let Ok(r) = ExprSizeofValue0::from_file("src/fixed_struct.bin") { - assert_eq!(r.self_sizeof, (((1 + 4) + 2) + 2)); - assert_eq!(r.sizeof_block, ((1 + 4) + 2)); - assert_eq!(r.sizeof_block_a, 1); - assert_eq!(r.sizeof_block_b, 4); - assert_eq!(r.sizeof_block_c, 2); - } -} diff --git a/spec/rust/src/test_expr_sizeof_value_sized.rs b/spec/rust/src/test_expr_sizeof_value_sized.rs deleted file mode 100644 index 50f5839d2..000000000 --- a/spec/rust/src/test_expr_sizeof_value_sized.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprSizeofValueSized; - -#[test] -fn test_expr_sizeof_value_sized() { - if let Ok(r) = ExprSizeofValueSized::from_file("src/fixed_struct.bin") { - assert_eq!(r.self_sizeof, (12 + 2)); - assert_eq!(r.sizeof_block, 12); - assert_eq!(r.sizeof_block_a, 1); - assert_eq!(r.sizeof_block_b, 4); - assert_eq!(r.sizeof_block_c, 2); - } -} diff --git a/spec/rust/src/test_expr_str_encodings.rs b/spec/rust/src/test_expr_str_encodings.rs deleted file mode 100644 index c4f9b64b4..000000000 --- a/spec/rust/src/test_expr_str_encodings.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprStrEncodings; - -#[test] -fn test_expr_str_encodings() { - if let Ok(r) = ExprStrEncodings::from_file("src/str_encodings.bin") { - - assert_eq!(r.str1_eq, true); - assert_eq!(r.str2_eq, true); - assert_eq!(r.str3_eq, true); - assert_eq!(r.str3_eq_str2, true); - assert_eq!(r.str4_eq, true); - assert_eq!(r.str4_gt_str_calc, true); - assert_eq!(r.str4_gt_str_from_bytes, true); - } -} diff --git a/spec/rust/src/test_expr_str_ops.rs b/spec/rust/src/test_expr_str_ops.rs deleted file mode 100644 index f428c2adf..000000000 --- a/spec/rust/src/test_expr_str_ops.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprStrOps; - -#[test] -fn test_expr_str_ops() { - if let Ok(r) = ExprStrOps::from_file("src/term_strz.bin") { - - assert_eq!(r.one, "foo|b"); - assert_eq!(r.one_len, 5); - assert_eq!(r.one_rev, "b|oof"); - assert_eq!(r.one_substr_0_to_3, "foo"); - assert_eq!(r.one_substr_2_to_5, "o|b"); - assert_eq!(r.one_substr_3_to_3, ""); - assert_eq!(r.two, "0123456789"); - assert_eq!(r.two_len, 10); - assert_eq!(r.two_rev, "9876543210"); - assert_eq!(r.two_substr_0_to_7, "0123456"); - assert_eq!(r.two_substr_4_to_10, "456789"); - assert_eq!(r.two_substr_0_to_10, "0123456789"); - assert_eq!(r.to_i_attr, 9173); - assert_eq!(r.to_i_r10, -72); - assert_eq!(r.to_i_r2, 86); - assert_eq!(r.to_i_r8, 465); - assert_eq!(r.to_i_r16, 18383); - } -} diff --git a/spec/rust/src/test_fixed_contents.rs b/spec/rust/src/test_fixed_contents.rs deleted file mode 100644 index 1a57a8c5c..000000000 --- a/spec/rust/src/test_fixed_contents.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::FixedContents; - -#[test] -fn test_fixed_contents() { - if let Ok(r) = FixedContents::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_fixed_struct.rs b/spec/rust/src/test_fixed_struct.rs deleted file mode 100644 index b667f6ef1..000000000 --- a/spec/rust/src/test_fixed_struct.rs +++ /dev/null @@ -1,34 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::FixedStruct; - -#[test] -fn test_fixed_struct() { - if let Ok(r) = FixedStruct::from_file("src/fixed_struct.bin") { - - assert_eq!(r.hdr.uint8, 255); - assert_eq!(r.hdr.uint16, 65535); - assert_eq!(r.hdr.uint32, 4294967295); - assert_eq!(r.hdr.uint64, 18446744073709551615); - assert_eq!(r.hdr.sint8, -1); - assert_eq!(r.hdr.sint16, -1); - assert_eq!(r.hdr.sint32, -1); - assert_eq!(r.hdr.sint64, -1); - assert_eq!(r.hdr.uint16le, 66); - assert_eq!(r.hdr.uint32le, 66); - assert_eq!(r.hdr.uint64le, 66); - assert_eq!(r.hdr.sint16le, -66); - assert_eq!(r.hdr.sint32le, -66); - assert_eq!(r.hdr.sint64le, -66); - assert_eq!(r.hdr.uint16be, 66); - assert_eq!(r.hdr.uint32be, 66); - assert_eq!(r.hdr.uint64be, 66); - assert_eq!(r.hdr.sint16be, -66); - assert_eq!(r.hdr.sint32be, -66); - assert_eq!(r.hdr.sint64be, -66); - } -} diff --git a/spec/rust/src/test_float_to_i.rs b/spec/rust/src/test_float_to_i.rs deleted file mode 100644 index ae0d2921f..000000000 --- a/spec/rust/src/test_float_to_i.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::FloatToI; - -#[test] -fn test_float_to_i() { - if let Ok(r) = FloatToI::from_file("src/floating_points.bin") { - - assert_eq!(r.single_value, 0.5); - assert_eq!(r.double_value, 0.25); - assert_eq!(r.single_i, 0); - assert_eq!(r.double_i, 0); - assert_eq!(r.float1_i, 1); - assert_eq!(r.float2_i, 1); - assert_eq!(r.float3_i, 1); - assert_eq!(r.float4_i, -2); - } -} diff --git a/spec/rust/src/test_floating_points.rs b/spec/rust/src/test_floating_points.rs deleted file mode 100644 index 1d88cbb9f..000000000 --- a/spec/rust/src/test_floating_points.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::FloatingPoints; - -#[test] -fn test_floating_points() { - if let Ok(r) = FloatingPoints::from_file("src/floating_points.bin") { - - assert_eq!(r.single_value, 0.5); - assert_eq!(r.single_value_be, 0.5); - assert_eq!(r.double_value, 0.25); - assert_eq!(r.double_value_be, 0.25); - assert_eq!(r.approximate_value, 1.2345); - assert_eq!(r.single_value_plus_int, 1.5); - assert_eq!(r.single_value_plus_float, 1.0); - assert_eq!(r.double_value_plus_float, 0.3); - } -} diff --git a/spec/rust/src/test_hello_world.rs b/spec/rust/src/test_hello_world.rs deleted file mode 100644 index 4f751ffb6..000000000 --- a/spec/rust/src/test_hello_world.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::HelloWorld; - -#[test] -fn test_hello_world() { - if let Ok(r) = HelloWorld::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, 80); - } -} diff --git a/spec/rust/src/test_if_instances.rs b/spec/rust/src/test_if_instances.rs deleted file mode 100644 index ed8393b86..000000000 --- a/spec/rust/src/test_if_instances.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::IfInstances; - -#[test] -fn test_if_instances() { - if let Ok(r) = IfInstances::from_file("src/fixed_struct.bin") { - - assertNull(r.never_happens); - } -} diff --git a/spec/rust/src/test_if_struct.rs b/spec/rust/src/test_if_struct.rs deleted file mode 100644 index 65c23c1ea..000000000 --- a/spec/rust/src/test_if_struct.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::IfStruct; - -#[test] -fn test_if_struct() { - if let Ok(r) = IfStruct::from_file("src/if_struct.bin") { - - assert_eq!(r.op1.opcode, 83); - assert_eq!(r.op1.arg_str.str, "foo"); - assert_eq!(r.op2.opcode, 84); - assert_eq!(r.op2.arg_tuple.num1, 66); - assert_eq!(r.op2.arg_tuple.num2, 67); - assert_eq!(r.op3.opcode, 83); - assert_eq!(r.op3.arg_str.str, "bar"); - } -} diff --git a/spec/rust/src/test_if_values.rs b/spec/rust/src/test_if_values.rs deleted file mode 100644 index 0b629bf8b..000000000 --- a/spec/rust/src/test_if_values.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::IfValues; - -#[test] -fn test_if_values() { - if let Ok(r) = IfValues::from_file("src/fixed_struct.bin") { - - assert_eq!(r.codes[0 as usize].opcode, 80); - assert_eq!(r.codes[0 as usize].half_opcode, 40); - assert_eq!(r.codes[1 as usize].opcode, 65); - assertNull(r.codes[1 as usize].half_opcode); - assert_eq!(r.codes[2 as usize].opcode, 67); - assertNull(r.codes[2 as usize].half_opcode); - } -} diff --git a/spec/rust/src/test_imports0.rs b/spec/rust/src/test_imports0.rs deleted file mode 100644 index 1c5fecae4..000000000 --- a/spec/rust/src/test_imports0.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::Imports0; - -#[test] -fn test_imports0() { - if let Ok(r) = Imports0::from_file("src/fixed_struct.bin") { - - assert_eq!(r.two, 80); - assert_eq!(r.hw.one, 65); - assert_eq!(r.hw_one, 65); - } -} diff --git a/spec/rust/src/test_imports_abs_abs.rs b/spec/rust/src/test_imports_abs_abs.rs deleted file mode 100644 index 386641991..000000000 --- a/spec/rust/src/test_imports_abs_abs.rs +++ /dev/null @@ -1,15 +0,0 @@ -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ImportsAbsAbs; - -#[test] -fn test_imports_abs_abs() { - if let Ok(r) = ImportsAbsAbs::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, 80); - assert_eq!(r.two.one, 65); - assert_eq!(r.two.two.one, 67); - } -} diff --git a/spec/rust/src/test_imports_abs_rel.rs b/spec/rust/src/test_imports_abs_rel.rs deleted file mode 100644 index d6394effd..000000000 --- a/spec/rust/src/test_imports_abs_rel.rs +++ /dev/null @@ -1,15 +0,0 @@ -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ImportsAbsRel; - -#[test] -fn test_imports_abs_rel() { - if let Ok(r) = ImportsAbsRel::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, 80); - assert_eq!(r.two.one, 65); - assert_eq!(r.two.two.one, 67); - } -} diff --git a/spec/rust/src/test_imports_circular_a.rs b/spec/rust/src/test_imports_circular_a.rs deleted file mode 100644 index 5be49aa2c..000000000 --- a/spec/rust/src/test_imports_circular_a.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ImportsCircularA; - -#[test] -fn test_imports_circular_a() { - if let Ok(r) = ImportsCircularA::from_file("src/fixed_struct.bin") { - - assert_eq!(r.code, 80); - assert_eq!(r.two.initial, 65); - assert_eq!(r.two.back_ref.code, 67); - assert_eq!(r.two.back_ref.two.initial, 75); - assertNull(r.two.back_ref.two.back_ref); - } -} diff --git a/spec/rust/src/test_imports_rel_1.rs b/spec/rust/src/test_imports_rel_1.rs deleted file mode 100644 index 767d1f753..000000000 --- a/spec/rust/src/test_imports_rel_1.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ImportsRel1; - -#[test] -fn test_imports_rel_1() { - if let Ok(r) = ImportsRel1::from_file("src/fixed_struct.bin") { - - assert_eq!(r.one, 80); - assert_eq!(r.two.one, 65); - assert_eq!(r.two.two.one, 67); - } -} diff --git a/spec/rust/src/test_integers_double_overflow.rs b/spec/rust/src/test_integers_double_overflow.rs deleted file mode 100644 index 0d9a8f9f2..000000000 --- a/spec/rust/src/test_integers_double_overflow.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IntegersDoubleOverflow; - -#[test] -fn test_integers_double_overflow() { - if let Ok(r) = IntegersDoubleOverflow::from_file("src/integers_double_overflow.bin") { - - assert_eq!(r.signed_safe_min_be, -9007199254740991); - assert_eq!(r.signed_safe_min_le, -9007199254740991); - assert_eq!(r.signed_safe_max_be, 9007199254740991); - assert_eq!(r.signed_safe_max_le, 9007199254740991); - assert_eq!(r.signed_unsafe_neg_be.to_string(), "-9007199254740993"); - assert_eq!(r.signed_unsafe_neg_le.to_string(), "-9007199254740993"); - assert_eq!(r.signed_unsafe_pos_be.to_string(), "9007199254740993"); - assert_eq!(r.signed_unsafe_pos_be.to_string(), "9007199254740993"); - } -} diff --git a/spec/rust/src/test_integers_min_max.rs b/spec/rust/src/test_integers_min_max.rs deleted file mode 100644 index 1740c0dfb..000000000 --- a/spec/rust/src/test_integers_min_max.rs +++ /dev/null @@ -1,42 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IntegersMinMax; - -#[test] -fn test_integers_min_max() { - if let Ok(r) = IntegersMinMax::from_file("src/integers_min_max.bin") { - - assert_eq!(r.unsigned_min.u1, 0); - assert_eq!(r.unsigned_min.u2le, 0); - assert_eq!(r.unsigned_min.u4le, 0); - assert_eq!(r.unsigned_min.u8le, 0); - assert_eq!(r.unsigned_min.u2be, 0); - assert_eq!(r.unsigned_min.u4be, 0); - assert_eq!(r.unsigned_min.u8be, 0); - assert_eq!(r.unsigned_max.u1, 255); - assert_eq!(r.unsigned_max.u2le, 65535); - assert_eq!(r.unsigned_max.u4le, 4294967295); - assert_eq!(r.unsigned_max.u8le, 18446744073709551615); - assert_eq!(r.unsigned_max.u2be, 65535); - assert_eq!(r.unsigned_max.u4be, 4294967295); - assert_eq!(r.unsigned_max.u8be, 18446744073709551615); - assert_eq!(r.signed_min.s1, -128); - assert_eq!(r.signed_min.s2le, -32768); - assert_eq!(r.signed_min.s4le, -2147483648); - assert_eq!(r.signed_min.s8le, -9223372036854775808); - assert_eq!(r.signed_min.s2be, -32768); - assert_eq!(r.signed_min.s4be, -2147483648); - assert_eq!(r.signed_min.s8be, -9223372036854775808); - assert_eq!(r.signed_max.s1, 127); - assert_eq!(r.signed_max.s2le, 32767); - assert_eq!(r.signed_max.s4le, 2147483647); - assert_eq!(r.signed_max.s8le, 9223372036854775807); - assert_eq!(r.signed_max.s2be, 32767); - assert_eq!(r.signed_max.s4be, 2147483647); - assert_eq!(r.signed_max.s8be, 9223372036854775807); - } -} diff --git a/spec/rust/src/test_io_local_var.rs b/spec/rust/src/test_io_local_var.rs deleted file mode 100644 index 3d861355c..000000000 --- a/spec/rust/src/test_io_local_var.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IoLocalVar; - -#[test] -fn test_io_local_var() { - if let Ok(r) = IoLocalVar::from_file("src/full256.bin") { - assert_eq!(r.skip, vec!([0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, 0x10, 0x11, 0x12, 0x13])); - assert_eq!(r.followup, 20); - } -} diff --git a/spec/rust/src/test_meta_tags.rs b/spec/rust/src/test_meta_tags.rs deleted file mode 100644 index 4978b9f09..000000000 --- a/spec/rust/src/test_meta_tags.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MetaTags; - -#[test] -fn test_meta_tags() { - if let Ok(r) = MetaTags::from_file("src/fixed_struct.bin") { - } -} diff --git a/spec/rust/src/test_meta_xref.rs b/spec/rust/src/test_meta_xref.rs deleted file mode 100644 index 9f068b47a..000000000 --- a/spec/rust/src/test_meta_xref.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MetaXref; - -#[test] -fn test_meta_xref() { - if let Ok(r) = MetaXref::from_file("src/fixed_struct.bin") { - } -} diff --git a/spec/rust/src/test_nav_parent_switch_cast.rs b/spec/rust/src/test_nav_parent_switch_cast.rs deleted file mode 100644 index 68f83a4a4..000000000 --- a/spec/rust/src/test_nav_parent_switch_cast.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentSwitchCast; - -#[test] -fn test_nav_parent_switch_cast() { - if let Ok(r) = NavParentSwitchCast::from_file("src/switch_integers.bin") { - - assert_eq!(r.main.buf_type, 1); - assert_eq!(r.main.flag, 7); - assert_eq!(r.main.buf.branch.flag, 7); - } -} diff --git a/spec/rust/src/test_nested_type_param.rs b/spec/rust/src/test_nested_type_param.rs deleted file mode 100644 index a0734e442..000000000 --- a/spec/rust/src/test_nested_type_param.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypeParam; - -#[test] -fn test_nested_type_param() { - if let Ok(r) = NestedTypeParam::from_file("src/term_strz.bin") { - - assert_eq!(r.main_seq.my_len, 5); - assert_eq!(r.main_seq.body, "foo|b"); - } -} diff --git a/spec/rust/src/test_opaque_external_type_02_parent.rs b/spec/rust/src/test_opaque_external_type_02_parent.rs deleted file mode 100644 index 776be1f18..000000000 --- a/spec/rust/src/test_opaque_external_type_02_parent.rs +++ /dev/null @@ -1,15 +0,0 @@ -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::OpaqueExternalType02Parent; - -#[test] -fn test_opaque_external_type_02_parent() { - if let Ok(r) = OpaqueExternalType02Parent::from_file("src/term_strz.bin") { - - assert_eq!(r.parent.child.s1, "foo"); - assert_eq!(r.parent.child.s2, "bar"); - assert_eq!(r.parent.child.s3.s3, "|baz@"); - } -} diff --git a/spec/rust/src/test_optional_id.rs b/spec/rust/src/test_optional_id.rs deleted file mode 100644 index aa4df6d26..000000000 --- a/spec/rust/src/test_optional_id.rs +++ /dev/null @@ -1,15 +0,0 @@ -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::OptionalId; - -#[test] -fn test_optional_id() { - if let Ok(r) = OptionalId::from_file("src/fixed_struct.bin") { - - assert_eq!(r._unnamed0, 80); - assert_eq!(r._unnamed1, 65); - assert_eq!(r._unnamed2, vec!([0x43, 0x4b, 0x2d, 0x31, 0xff])); - } -} diff --git a/spec/rust/src/test_params_call_extra_parens.rs b/spec/rust/src/test_params_call_extra_parens.rs deleted file mode 100644 index 31bc621b7..000000000 --- a/spec/rust/src/test_params_call_extra_parens.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsCallExtraParens; - -#[test] -fn test_params_call_extra_parens() { - if let Ok(r) = ParamsCallExtraParens::from_file("src/term_strz.bin") { - - assert_eq!(r.buf1.body, "foo|b"); - } -} diff --git a/spec/rust/src/test_params_pass_array_int.rs b/spec/rust/src/test_params_pass_array_int.rs deleted file mode 100644 index 68c3450e8..000000000 --- a/spec/rust/src/test_params_pass_array_int.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassArrayInt; - -#[test] -fn test_params_pass_array_int() { - if let Ok(r) = ParamsPassArrayInt::from_file("src/position_to_end.bin") { - - assert_eq!(r.pass_ints.nums.len(), 3); - assert_eq!(r.pass_ints.nums[0], 513); - assert_eq!(r.pass_ints.nums[1], 1027); - assert_eq!(r.pass_ints.nums[2], 1541); - assert_eq!(r.pass_ints_calc.nums.len(), 2); - assert_eq!(r.pass_ints_calc.nums[0], 27643); - assert_eq!(r.pass_ints_calc.nums[1], 7); - } -} diff --git a/spec/rust/src/test_params_pass_array_str.rs b/spec/rust/src/test_params_pass_array_str.rs deleted file mode 100644 index 2890396db..000000000 --- a/spec/rust/src/test_params_pass_array_str.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassArrayStr; - -#[test] -fn test_params_pass_array_str() { - if let Ok(r) = ParamsPassArrayStr::from_file("src/term_strz.bin") { - - assert_eq!(r.pass_str_array.strs.len(), 3); - assert_eq!(r.pass_str_array.strs[0], "fo"); - assert_eq!(r.pass_str_array.strs[1], "o|"); - assert_eq!(r.pass_str_array.strs[2], "ba"); - assert_eq!(r.pass_str_array_calc.strs.len(), 2); - assert_eq!(r.pass_str_array_calc.strs[0], "aB"); - assert_eq!(r.pass_str_array_calc.strs[1], "Cd"); - } -} diff --git a/spec/rust/src/test_params_pass_array_struct.rs b/spec/rust/src/test_params_pass_array_struct.rs deleted file mode 100644 index 9ccada67d..000000000 --- a/spec/rust/src/test_params_pass_array_struct.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassArrayStruct; - -#[test] -fn test_params_pass_array_struct() { - if let Ok(r) = ParamsPassArrayStruct::from_file("src/position_to_end.bin") { - - assert_eq!(r.pass_structs.structs.len(), 2); - assert_eq!(r.pass_structs.structs[0].f, 1); - assert_eq!(r.pass_structs.structs[1].b, 2); - } -} diff --git a/spec/rust/src/test_params_pass_array_usertype.rs b/spec/rust/src/test_params_pass_array_usertype.rs deleted file mode 100644 index 089c58c63..000000000 --- a/spec/rust/src/test_params_pass_array_usertype.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassArrayUsertype; - -#[test] -fn test_params_pass_array_usertype() { - if let Ok(r) = ParamsPassArrayUsertype::from_file("src/position_to_end.bin") { - - assert_eq!(r.pass_blocks.bar.len(), 2); - assert_eq!(r.pass_blocks.bar[0].foo, 1); - assert_eq!(r.pass_blocks.bar[1].foo, 2); - assert_eq!(r.pass_blocks.one, vec!([0x3])); - assert_eq!(r.pass_blocks.two, vec!([0x4, 0x5])); - } -} diff --git a/spec/rust/src/test_params_pass_bool.rs b/spec/rust/src/test_params_pass_bool.rs deleted file mode 100644 index e33003d08..000000000 --- a/spec/rust/src/test_params_pass_bool.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassBool; - -#[test] -fn test_params_pass_bool() { - if let Ok(r) = ParamsPassBool::from_file("src/term_strz.bin") { - - assert_eq!(r.s_false, false); - assert_eq!(r.s_true, true); - assert_eq!(r.seq_b1.arg, true); - assert_eq!(r.seq_b1.foo.len(), 1); - assert_eq!(r.seq_bool.arg, false); - assert_eq!(r.seq_bool.foo.len(), 2); - assert_eq!(r.literal_b1.arg, false); - assert_eq!(r.literal_b1.foo.len(), 2); - assert_eq!(r.literal_bool.arg, true); - assert_eq!(r.literal_bool.foo.len(), 1); - assert_eq!(r.inst_b1.arg, true); - assert_eq!(r.inst_b1.foo.len(), 1); - assert_eq!(r.inst_bool.arg, false); - assert_eq!(r.inst_bool.foo.len(), 2); - } -} diff --git a/spec/rust/src/test_params_pass_struct.rs b/spec/rust/src/test_params_pass_struct.rs deleted file mode 100644 index de5b00b67..000000000 --- a/spec/rust/src/test_params_pass_struct.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassStruct; - -#[test] -fn test_params_pass_struct() { - if let Ok(r) = ParamsPassStruct::from_file("src/enum_negative.bin") { - - assert_eq!(r.first.foo, 255); - assert_eq!(r.one.bar.qux, 1); - assert_eq!(r.one.foo.foo, 255); - assert_eq!(r.one.bar.foo.foo, 255); - } -} diff --git a/spec/rust/src/test_process_custom_no_args.rs b/spec/rust/src/test_process_custom_no_args.rs deleted file mode 100644 index 5de1d925e..000000000 --- a/spec/rust/src/test_process_custom_no_args.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCustomNoArgs; - -#[test] -fn test_process_custom_no_args() { - if let Ok(r) = ProcessCustomNoArgs::from_file("src/process_rotate.bin") { - - assert_eq!(r.buf, vec!([0x5f, 0x9, 0xac, 0x8d, 0x8d, 0xed, 0x5f])); - } -} diff --git a/spec/rust/src/test_process_repeat_bytes.rs b/spec/rust/src/test_process_repeat_bytes.rs deleted file mode 100644 index 9be158d1f..000000000 --- a/spec/rust/src/test_process_repeat_bytes.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessRepeatBytes; - -#[test] -fn test_process_repeat_bytes() { - if let Ok(r) = ProcessRepeatBytes::from_file("src/process_xor_4.bin") { - - assert_eq!(r.bufs[0], vec!([0x72, 0x25, 0x3d, 0x8a, 0x14])); - assert_eq!(r.bufs[1], vec!([0x4a, 0x52, 0xaa, 0x10, 0x44])); - } -} diff --git a/spec/rust/src/test_process_repeat_usertype.rs b/spec/rust/src/test_process_repeat_usertype.rs deleted file mode 100644 index 997487790..000000000 --- a/spec/rust/src/test_process_repeat_usertype.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessRepeatUsertype; - -#[test] -fn test_process_repeat_usertype() { - if let Ok(r) = ProcessRepeatUsertype::from_file("src/process_xor_4.bin") { - - assert_eq!(r.blocks[0].a, -1975704206); - assert_eq!(r.blocks[0].b, 20); - assert_eq!(r.blocks[1].a, 279597642); - assert_eq!(r.blocks[1].b, 68); - } -} diff --git a/spec/rust/src/test_repeat_eos_bit.rs b/spec/rust/src/test_repeat_eos_bit.rs deleted file mode 100644 index a7518aade..000000000 --- a/spec/rust/src/test_repeat_eos_bit.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatEosBit; - -#[test] -fn test_repeat_eos_bit() { - if let Ok(r) = RepeatEosBit::from_file("src/enum_0.bin") { - assert_eq!(r.nibbles.len(), 16); - } -} diff --git a/spec/rust/src/test_repeat_until_calc_array_type.rs b/spec/rust/src/test_repeat_until_calc_array_type.rs deleted file mode 100644 index ad35a2b62..000000000 --- a/spec/rust/src/test_repeat_until_calc_array_type.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatUntilCalcArrayType; - -#[test] -fn test_repeat_until_calc_array_type() { - if let Ok(r) = RepeatUntilCalcArrayType::from_file("src/repeat_until_process.bin") { - - assert_eq!(r.records.len(), 3); - assert_eq!(r.records[0].marker, 232); - assert_eq!(r.records[0].body, 2863311546); - assert_eq!(r.records[1].marker, 250); - assert_eq!(r.records[1].body, 2863315102); - assert_eq!(r.records[2].marker, 170); - assert_eq!(r.records[2].body, 1431655765); - } -} diff --git a/spec/rust/src/test_str_encodings_utf16.rs b/spec/rust/src/test_str_encodings_utf16.rs deleted file mode 100644 index 7c7e79e07..000000000 --- a/spec/rust/src/test_str_encodings_utf16.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEncodingsUtf16; - -#[test] -fn test_str_encodings_utf16() { - if let Ok(r) = StrEncodingsUtf16::from_file("src/str_encodings_utf16.bin") { - - assert_eq!(r.len_be, 12); - assert_eq!(r.be_bom_removed.bom, 65279); - assert_eq!(r.be_bom_removed.str, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.len_le, 12); - assert_eq!(r.le_bom_removed.bom, 65279); - assert_eq!(r.le_bom_removed.str, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - } -} diff --git a/spec/rust/src/test_str_eos.rs b/spec/rust/src/test_str_eos.rs deleted file mode 100644 index 8c861443d..000000000 --- a/spec/rust/src/test_str_eos.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate kaitai_rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEos; - -#[test] -fn test_str_eos() { - if let Ok(r) = StrEos::from_file("src/term_strz.bin") { - - assert_eq!(r.str, "foo|bar|baz@"); - } -} diff --git a/spec/rust/src/test_switch_else_only.rs b/spec/rust/src/test_switch_else_only.rs deleted file mode 100644 index be7d21115..000000000 --- a/spec/rust/src/test_switch_else_only.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchElseOnly; - -#[test] -fn test_switch_else_only() { - if let Ok(r) = SwitchElseOnly::from_file("src/switch_opcodes.bin") { - - assert_eq!(r.opcode, 83); - assert_eq!(r.prim_byte, 102); - assert_eq!(r.ut.value, vec!([0x72, 0x0, 0x49, 0x42])); - } -} diff --git a/spec/rust/src/test_switch_manual_enum_invalid.rs b/spec/rust/src/test_switch_manual_enum_invalid.rs deleted file mode 100644 index ea7bc0a8e..000000000 --- a/spec/rust/src/test_switch_manual_enum_invalid.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualEnumInvalid; - -#[test] -fn test_switch_manual_enum_invalid() { - if let Ok(r) = SwitchManualEnumInvalid::from_file("src/enum_negative.bin") { - - assert_eq!(r.opcodes.len(), 2); - assert_eq!(r.opcodes[0].code, 255); - assertNull(r.opcodes[0].body); - assert_eq!(r.opcodes[1].code, 1); - assertNull(r.opcodes[1].body); - } -} diff --git a/spec/rust/src/test_switch_manual_enum_invalid_else.rs b/spec/rust/src/test_switch_manual_enum_invalid_else.rs deleted file mode 100644 index e11c5ea0d..000000000 --- a/spec/rust/src/test_switch_manual_enum_invalid_else.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualEnumInvalidElse; - -#[test] -fn test_switch_manual_enum_invalid_else() { - if let Ok(r) = SwitchManualEnumInvalidElse::from_file("src/enum_negative.bin") { - - assert_eq!(r.opcodes.len(), 2); - assert_eq!(r.opcodes[0].code, 255); - assert_eq!(r.opcodes[0].body.value, 123); - assert_eq!(r.opcodes[1].code, 1); - assert_eq!(r.opcodes[1].body.value, 123); - } -} diff --git a/spec/rust/src/test_switch_manual_int_size.rs b/spec/rust/src/test_switch_manual_int_size.rs deleted file mode 100644 index 9dcfbe71a..000000000 --- a/spec/rust/src/test_switch_manual_int_size.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualIntSize; - -#[test] -fn test_switch_manual_int_size() { - if let Ok(r) = SwitchManualIntSize::from_file("src/switch_tlv.bin") { - - assert_eq!(r.chunks.len(), 4); - assert_eq!(r.chunks[0].code, 17); - assert_eq!(r.chunks[0].body.title, "Stuff"); - assert_eq!(r.chunks[0].body.author, "Me"); - assert_eq!(r.chunks[1].code, 34); - assert_eq!(r.chunks[1].body.entries, ["AAAA", "BBBB", "CCCC"]); - assert_eq!(r.chunks[2].code, 51); - assert_eq!(r.chunks[2].body, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80])); - assert_eq!(r.chunks[3].code, 255); - assert_eq!(r.chunks[3].body, vec!([])); - } -} diff --git a/spec/rust/src/test_switch_manual_int_size_eos.rs b/spec/rust/src/test_switch_manual_int_size_eos.rs deleted file mode 100644 index 734dde0c3..000000000 --- a/spec/rust/src/test_switch_manual_int_size_eos.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualIntSizeEos; - -#[test] -fn test_switch_manual_int_size_eos() { - if let Ok(r) = SwitchManualIntSizeEos::from_file("src/switch_tlv.bin") { - - assert_eq!(r.chunks.len(), 4); - assert_eq!(r.chunks[0].code, 17); - assert_eq!(r.chunks[0].body.body.title, "Stuff"); - assert_eq!(r.chunks[0].body.body.author, "Me"); - assert_eq!(r.chunks[1].code, 34); - assert_eq!(r.chunks[1].body.body.entries, ["AAAA", "BBBB", "CCCC"]); - assert_eq!(r.chunks[2].code, 51); - assert_eq!(r.chunks[2].body.body, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80])); - assert_eq!(r.chunks[3].code, 255); - assert_eq!(r.chunks[3].body.body, vec!([])); - } -} diff --git a/spec/rust/src/test_switch_multi_bool_ops.rs b/spec/rust/src/test_switch_multi_bool_ops.rs deleted file mode 100644 index 044aac09a..000000000 --- a/spec/rust/src/test_switch_multi_bool_ops.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchMultiBoolOps; - -#[test] -fn test_switch_multi_bool_ops() { - if let Ok(r) = SwitchMultiBoolOps::from_file("src/switch_integers.bin") { - - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, 1); - assert_eq!(r.opcodes[0].body, 7); - assert_eq!(r.opcodes[1].code, 2); - assert_eq!(r.opcodes[1].body, 16448); - assert_eq!(r.opcodes[2].code, 4); - assert_eq!(r.opcodes[2].body, 4919); - assert_eq!(r.opcodes[3].code, 8); - assert_eq!(r.opcodes[3].body, 4919); - } -} diff --git a/spec/rust/src/test_switch_repeat_expr.rs b/spec/rust/src/test_switch_repeat_expr.rs deleted file mode 100644 index 7fbb69a2e..000000000 --- a/spec/rust/src/test_switch_repeat_expr.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchRepeatExpr; - -#[test] -fn test_switch_repeat_expr() { - if let Ok(r) = SwitchRepeatExpr::from_file("src/switch_tlv.bin") { - - assert_eq!(r.code, 17); - assert_eq!(r.size, 9); - assert_eq!(r.body[0].first, vec!([0x53, 0x74, 0x75, 0x66, 0x66, 0x0, 0x4d, 0x65, 0x0])); - } -} diff --git a/spec/rust/src/test_switch_repeat_expr_invalid.rs b/spec/rust/src/test_switch_repeat_expr_invalid.rs deleted file mode 100644 index 6249eb70f..000000000 --- a/spec/rust/src/test_switch_repeat_expr_invalid.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchRepeatExprInvalid; - -#[test] -fn test_switch_repeat_expr_invalid() { - if let Ok(r) = SwitchRepeatExprInvalid::from_file("src/switch_tlv.bin") { - - assert_eq!(r.code, 17); - assert_eq!(r.size, 9); - assert_eq!(r.body[0], vec!([0x53, 0x74, 0x75, 0x66, 0x66, 0x0, 0x4d, 0x65, 0x0])); - } -} diff --git a/spec/rust/src/test_term_u1_val.rs b/spec/rust/src/test_term_u1_val.rs deleted file mode 100644 index bff937bcf..000000000 --- a/spec/rust/src/test_term_u1_val.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TermU1Val; - -#[test] -fn test_term_u1_val() { - if let Ok(r) = TermU1Val::from_file("src/str_encodings.bin") { - - assert_eq!(r.foo, vec!([0xa, 0x0, 0x53, 0x6f, 0x6d, 0x65, 0x20, 0x41, 0x53, 0x43, 0x49, 0x49, 0xf, 0x0])); - assert_eq!(r.bar, "\u{3053}\u{3093}\u{306b}"); - } -} diff --git a/spec/rust/src/test_type_ternary_2nd_falsy.rs b/spec/rust/src/test_type_ternary_2nd_falsy.rs deleted file mode 100644 index db684c869..000000000 --- a/spec/rust/src/test_type_ternary_2nd_falsy.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TypeTernary2ndFalsy; - -#[test] -fn test_type_ternary_2nd_falsy() { - if let Ok(r) = TypeTernary2ndFalsy::from_file("src/switch_integers.bin") { - - assert_eq!(r.v_false, false); - assert_eq!(r.v_int_zero, 0); - assert_eq!(r.v_int_neg_zero, -0); - assert_eq!(r.v_float_zero, 0.0); - assert_eq!(r.v_float_neg_zero, -0.0); - assert_eq!(r.v_str_w_zero, "0"); - assert_eq!(r.v_str_w_zero.len(), 1); - assert_eq!(r.ut.m, 7); - assertNull(r.v_null_ut); - assert_eq!(r.v_str_empty, ""); - assert_eq!(r.v_str_empty.len(), 0); - assert_eq!(r.int_array.len(), 2); - assert_eq!(r.v_int_array_empty.len(), 0); - } -} diff --git a/spec/rust/src/test_valid_eq_str_encodings.rs b/spec/rust/src/test_valid_eq_str_encodings.rs deleted file mode 100644 index 543823869..000000000 --- a/spec/rust/src/test_valid_eq_str_encodings.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ValidEqStrEncodings; - -#[test] -fn test_valid_eq_str_encodings() { - if let Ok(r) = ValidEqStrEncodings::from_file("src/str_encodings.bin") { - - } -} diff --git a/spec/rust/src/test_valid_long.rs b/spec/rust/src/test_valid_long.rs deleted file mode 100644 index bd8b3ec66..000000000 --- a/spec/rust/src/test_valid_long.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ValidLong; - -#[test] -fn test_valid_long() { - if let Ok(r) = ValidLong::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_valid_not_parsed_if.rs b/spec/rust/src/test_valid_not_parsed_if.rs deleted file mode 100644 index 400418205..000000000 --- a/spec/rust/src/test_valid_not_parsed_if.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ValidNotParsedIf; - -#[test] -fn test_valid_not_parsed_if() { - if let Ok(r) = ValidNotParsedIf::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_valid_short.rs b/spec/rust/src/test_valid_short.rs deleted file mode 100644 index f857b0d14..000000000 --- a/spec/rust/src/test_valid_short.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ValidShort; - -#[test] -fn test_valid_short() { - if let Ok(r) = ValidShort::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_valid_switch.rs b/spec/rust/src/test_valid_switch.rs deleted file mode 100644 index 33111ad07..000000000 --- a/spec/rust/src/test_valid_switch.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ValidSwitch; - -#[test] -fn test_valid_switch() { - if let Ok(r) = ValidSwitch::from_file("src/fixed_struct.bin") { - - } -} diff --git a/spec/rust/src/test_yaml_ints.rs b/spec/rust/src/test_yaml_ints.rs deleted file mode 100644 index 4723d3dae..000000000 --- a/spec/rust/src/test_yaml_ints.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::YamlInts; - -#[test] -fn test_yaml_ints() { - if let Ok(r) = YamlInts::from_file("src/fixed_struct.bin") { - - assert_eq!(r.test_u4_dec, 4294967295); - assert_eq!(r.test_u4_hex, 4294967295); - assert_eq!(r.test_u8_dec, 18446744073709551615); - assert_eq!(r.test_u8_hex, 18446744073709551615); - } -} diff --git a/spec/rust/src/test_zlib_surrounded.rs b/spec/rust/src/test_zlib_surrounded.rs deleted file mode 100644 index d10797e26..000000000 --- a/spec/rust/src/test_zlib_surrounded.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ZlibSurrounded; - -#[test] -fn test_zlib_surrounded() { - if let Ok(r) = ZlibSurrounded::from_file("src/zlib_surrounded.bin") { - - assert_eq!(r.zlib.num, -1); - } -} diff --git a/spec/rust/tests/manual_read_bytes.rs b/spec/rust/tests/manual_read_bytes.rs new file mode 100644 index 000000000..2ce7690b1 --- /dev/null +++ b/spec/rust/tests/manual_read_bytes.rs @@ -0,0 +1,24 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::read_bytes::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let reader = BytesReader::new(&bytes); + + let mut r = ReadBytes::default(); + { + let res = r.read(&reader, None, KStructUnit::parent_stack()); + println!("{:?}", res); + assert!(res.is_ok()); + } + + assert_eq!(1, r.len()); + assert_eq!(vec![7], *r.val()); + assert_eq!(vec![0x2, 0x40], *r.padding()); +} diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/manual_str_literals.rs new file mode 100644 index 000000000..523396b4d --- /dev/null +++ b/spec/rust/tests/manual_str_literals.rs @@ -0,0 +1,35 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_literals::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + + let mut r = StrLiterals::default(); + { + let res = r.read(&reader, None, KStructUnit::parent_stack()); + println!("{:?}", res); + assert!(res.is_ok()); + } + + let backslashes = r.backslashes(&reader).unwrap(); + assert_eq!("\u{005c}\u{005c}\u{005c}", *backslashes); + + let octal_eatup = r.octal_eatup(&reader).unwrap(); + assert_eq!("\u{0}\u{0032}\u{0032}", *octal_eatup); + + let octal_eatup2 = r.octal_eatup2(&reader).unwrap(); + assert_eq!("\u{2}\u{32}", *octal_eatup2); + + let double_quotes = r.double_quotes(&reader).unwrap(); + assert_eq!("\u{22}\u{22}\u{22}", *double_quotes); + + let complex_str = r.complex_str(&reader).unwrap(); + assert_eq!("\u{0}\u{1}\u{2}\u{7}\u{8}\u{0a}\u{0d}\u{09}\u{0b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}", *complex_str); +} \ No newline at end of file diff --git a/spec/rust/tests/manual_str_repeat.rs b/spec/rust/tests/manual_str_repeat.rs new file mode 100644 index 000000000..b0630e0bc --- /dev/null +++ b/spec/rust/tests/manual_str_repeat.rs @@ -0,0 +1,23 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_repeat::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrRepeat::default(); + { + let res = r.read(&reader, None, KStructUnit::parent_stack()); + println!("{:?}", res); + assert!(res.is_ok()); + } + + assert_eq!("foo|", r.entries()[0]); + assert_eq!("bar|", r.entries()[1]); + assert_eq!("baz@", r.entries()[2]); +} diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs new file mode 100644 index 000000000..c912ffe39 --- /dev/null +++ b/spec/rust/tests/manual_switch_cast.rs @@ -0,0 +1,50 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_cast::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + + let mut r = SwitchCast::default(); + { + let res = r.read(&reader, None, KStructUnit::parent_stack()); + println!("{:?}", res); + assert!(res.is_ok()); + } + + assert_eq!(4, r.opcodes.len()); + + assert_eq!(0x53, r.opcodes[0].code()); + if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes[0].body() { + assert_eq!("foobar", s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Strval"); + } + + assert_eq!(0x49, r.opcodes[1].code); + if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes[1].body() { + assert_eq!(66, s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Intval"); + } + + assert_eq!(0x49, r.opcodes[2].code); + if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes[2].body() { + assert_eq!(55, s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Intval"); + } + + assert_eq!(0x53, r.opcodes[3].code); + if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes[3].body() { + assert_eq!("", s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Strval"); + } +} \ No newline at end of file diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs new file mode 100644 index 000000000..0f83f307f --- /dev/null +++ b/spec/rust/tests/manual_switch_cast_parent.rs @@ -0,0 +1,50 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_cast_parent::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + + let mut r = SwitchCastParent::default(); + { + let res = r.read(&reader, None, KStructUnit::parent_stack()); + println!("{:?}", res); + assert!(res.is_ok()); + } + + assert_eq!(4, r.opcodes.len()); + + assert_eq!(0x53, r.opcodes[0].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes[0].body() { + assert_eq!("foobar", s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Strval"); + } + + assert_eq!(0x49, r.opcodes[1].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes[1].body() { + assert_eq!(66, s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Intval"); + } + + assert_eq!(0x49, r.opcodes[2].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes[2].body() { + assert_eq!(55, s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Intval"); + } + + assert_eq!(0x53, r.opcodes[3].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes[3].body() { + assert_eq!("", s.value); + } else { + panic!("expected enum SwitchCast_Opcode_Strval"); + } +} \ No newline at end of file diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs new file mode 100644 index 000000000..d9658c29b --- /dev/null +++ b/spec/rust/tests/manual_test_parent.rs @@ -0,0 +1,24 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::test_parent::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TestParent::default(); + { + let res = r.read(&reader, None, KStructUnit::parent_stack()); + println!("{:?}", res); + assert!(res.is_ok()); + } + + assert_eq!(1, r.root_byte()); + assert_eq!(7, r.child().child_byte()); + assert_eq!(1, r.child().child2().len()); + assert_eq!(vec![2, 64, 64, 4, 55, 19, 0], *r.child().child2()[0].child2_byte()); +} diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs deleted file mode 100644 index 640195c8b..000000000 --- a/spec/rust/tests/test_bcd_user_type_be.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BcdUserTypeBe; - -#[test] -fn test_bcd_user_type_be() { - if let Ok(r) = BcdUserTypeBe::from_file("src/bcd_user_type_be.bin") { - assert_eq!(r.ltr.as_int, 12345678); - assert_eq!(r.ltr.as_str, "12345678"); - assert_eq!(r.rtl.as_int, 87654321); - assert_eq!(r.rtl.as_str, "87654321"); - assert_eq!(r.leading_zero_ltr.as_int, 123456); - assert_eq!(r.leading_zero_ltr.as_str, "00123456"); - } -} diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs deleted file mode 100644 index 9769abc1a..000000000 --- a/spec/rust/tests/test_bcd_user_type_le.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BcdUserTypeLe; - -#[test] -fn test_bcd_user_type_le() { - if let Ok(r) = BcdUserTypeLe::from_file("src/bcd_user_type_le.bin") { - assert_eq!(r.ltr.as_int, 12345678); - assert_eq!(r.ltr.as_str, "12345678"); - assert_eq!(r.rtl.as_int, 87654321); - assert_eq!(r.rtl.as_str, "87654321"); - assert_eq!(r.leading_zero_ltr.as_int, 123456); - assert_eq!(r.leading_zero_ltr.as_str, "00123456"); - } -} diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs deleted file mode 100644 index 128edb632..000000000 --- a/spec/rust/tests/test_bits_byte_aligned.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsByteAligned; - -#[test] -fn test_bits_byte_aligned() { - if let Ok(r) = BitsByteAligned::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, 20); - assert_eq!(r.byte_1, 65); - assert_eq!(r.two, 2); - assert_eq!(r.three, false); - assert_eq!(r.byte_2, 75); - assert_eq!(r.four, 2892); - assert_eq!(r.byte_3, vec!([0xff])); - assert_eq!(r.full_byte, 255); - assert_eq!(r.byte_4, 80); - } -} diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs deleted file mode 100644 index c3eb6a06c..000000000 --- a/spec/rust/tests/test_bits_simple.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BitsSimple; - -#[test] -fn test_bits_simple() { - if let Ok(r) = BitsSimple::from_file("src/fixed_struct.bin") { - assert_eq!(r.byte_1, 80); - assert_eq!(r.byte_2, 65); - assert_eq!(r.bits_a, false); - assert_eq!(r.bits_b, 4); - assert_eq!(r.bits_c, 3); - assert_eq!(r.large_bits_1, 300); - assert_eq!(r.spacer, 5); - assert_eq!(r.large_bits_2, 1329); - assert_eq!(r.normal_s2, -1); - assert_eq!(r.byte_8_9_10, 5259587); - assert_eq!(r.byte_11_to_14, 1261262125); - assert_eq!(r.byte_15_to_19, 293220057087); - assert_eq!(r.byte_20_to_27, 18446744073709551615); - assert_eq!(r.test_if_b1, 123); - } -} diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs deleted file mode 100644 index 2b4a8d82e..000000000 --- a/spec/rust/tests/test_buffered_struct.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BufferedStruct; - -#[test] -fn test_buffered_struct() { - if let Ok(r) = BufferedStruct::from_file("src/buffered_struct.bin") { - assert_eq!(r.len1, 16); - assert_eq!(r.block1.number1, 66); - assert_eq!(r.block1.number2, 67); - assert_eq!(r.len2, 8); - assert_eq!(r.block2.number1, 68); - assert_eq!(r.block2.number2, 69); - assert_eq!(r.finisher, 238); - } -} diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs deleted file mode 100644 index 87ac91cd8..000000000 --- a/spec/rust/tests/test_bytes_pad_term.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::BytesPadTerm; - -#[test] -fn test_bytes_pad_term() { - if let Ok(r) = BytesPadTerm::from_file("src/str_pad_term.bin") { - assert_eq!(r.str_pad, vec!([0x73, 0x74, 0x72, 0x31])); - assert_eq!(r.str_term, vec!([0x73, 0x74, 0x72, 0x32, 0x66, 0x6f, 0x6f])); - assert_eq!(r.str_term_and_pad, vec!([0x73, 0x74, 0x72, 0x2b, 0x2b, 0x2b, 0x33, 0x62, 0x61, 0x72, 0x2b, 0x2b, 0x2b])); - assert_eq!(r.str_term_include, vec!([0x73, 0x74, 0x72, 0x34, 0x62, 0x61, 0x7a, 0x40])); - } -} diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs deleted file mode 100644 index 80a1d7566..000000000 --- a/spec/rust/tests/test_cast_nested.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastNested; - -#[test] -fn test_cast_nested() { - if let Ok(r) = CastNested::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes_0_str.value, "foobar"); - assert_eq!(r.opcodes_0_str_value, "foobar"); - assert_eq!(r.opcodes_1_int.value, 66); - assert_eq!(r.opcodes_1_int_value, 66); - } -} diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs deleted file mode 100644 index 896ee9be3..000000000 --- a/spec/rust/tests/test_cast_to_imported.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastToImported; - -#[test] -fn test_cast_to_imported() { - if let Ok(r) = CastToImported::from_file("src/fixed_struct.bin") { - assert_eq!(r.one.one, 80); - assert_eq!(r.one_casted.one, 80); - } -} diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs deleted file mode 100644 index 8c248dc84..000000000 --- a/spec/rust/tests/test_cast_to_top.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::CastToTop; - -#[test] -fn test_cast_to_top() { - if let Ok(r) = CastToTop::from_file("src/fixed_struct.bin") { - assert_eq!(r.code, 80); - assert_eq!(r.header.code, 65); - assert_eq!(r.header_casted.code, 65); - } -} diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs deleted file mode 100644 index f5fc0ee75..000000000 --- a/spec/rust/tests/test_default_big_endian.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultBigEndian; - -#[test] -fn test_default_big_endian() { - if let Ok(r) = DefaultBigEndian::from_file("src/enum_0.bin") { - assert_eq!(r.one, 117440512); - } -} diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs deleted file mode 100644 index f48bf523f..000000000 --- a/spec/rust/tests/test_default_endian_expr_inherited.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprInherited; - -#[test] -fn test_default_endian_expr_inherited() { - if let Ok(r) = DefaultEndianExprInherited::from_file("src/endian_expr.bin") { - assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - assert_eq!(r.docs[0].main.insides.some_int, 66); - assert_eq!(r.docs[0].main.insides.more.some_int1, 16896); - assert_eq!(r.docs[0].main.insides.more.some_int2, 66); - assert_eq!(r.docs[0].main.insides.more.some_inst, 66); - assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - assert_eq!(r.docs[1].main.insides.some_int, 66); - assert_eq!(r.docs[1].main.insides.more.some_int1, 66); - assert_eq!(r.docs[1].main.insides.more.some_int2, 16896); - assert_eq!(r.docs[1].main.insides.more.some_inst, 1107296256); - assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - assert_eq!(r.docs[2].main.insides.some_int, 66); - assert_eq!(r.docs[2].main.insides.more.some_int1, 66); - assert_eq!(r.docs[2].main.insides.more.some_int2, 16896); - assert_eq!(r.docs[2].main.insides.more.some_inst, 1107296256); - } -} diff --git a/spec/rust/tests/test_default_endian_expr_is_be.rs b/spec/rust/tests/test_default_endian_expr_is_be.rs deleted file mode 100644 index 031394522..000000000 --- a/spec/rust/tests/test_default_endian_expr_is_be.rs +++ /dev/null @@ -1,31 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprIsBe; - -#[test] -fn test_default_endian_expr_is_be() { - if let Ok(r) = DefaultEndianExprIsBe::from_file("src/endian_expr.bin") { - assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - assert_eq!(r.docs[0].main.some_int, 66); - assert_eq!(r.docs[0].main.some_int_be, 66); - assert_eq!(r.docs[0].main.some_int_le, 66); - assert_eq!(r.docs[0].main.inst_int, 66); - assert_eq!(r.docs[0].main.inst_sub.foo, 66); - assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - assert_eq!(r.docs[1].main.some_int, 66); - assert_eq!(r.docs[1].main.some_int_be, 66); - assert_eq!(r.docs[1].main.some_int_le, 66); - assert_eq!(r.docs[1].main.inst_int, 1107296256); - assert_eq!(r.docs[1].main.inst_sub.foo, 1107296256); - assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - assert_eq!(r.docs[2].main.some_int, 1107296256); - assert_eq!(r.docs[2].main.some_int_be, 66); - assert_eq!(r.docs[2].main.some_int_le, 66); - assert_eq!(r.docs[2].main.inst_int, 66); - assert_eq!(r.docs[2].main.inst_sub.foo, 66); - } -} diff --git a/spec/rust/tests/test_default_endian_expr_is_le.rs b/spec/rust/tests/test_default_endian_expr_is_le.rs deleted file mode 100644 index 5172458be..000000000 --- a/spec/rust/tests/test_default_endian_expr_is_le.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianExprIsLe; - -#[test] -fn test_default_endian_expr_is_le() { - if let Ok(r) = DefaultEndianExprIsLe::from_file("src/endian_expr.bin") { - assert_eq!(r.docs[0].indicator, vec!([0x49, 0x49])); - assert_eq!(r.docs[0].main.some_int, 66); - assert_eq!(r.docs[0].main.some_int_be, 66); - assert_eq!(r.docs[0].main.some_int_le, 66); - assert_eq!(r.docs[1].indicator, vec!([0x4d, 0x4d])); - assert_eq!(r.docs[1].main.some_int, 66); - assert_eq!(r.docs[1].main.some_int_be, 66); - assert_eq!(r.docs[1].main.some_int_le, 66); - assert_eq!(r.docs[2].indicator, vec!([0x58, 0x58])); - assert_eq!(r.docs[2].main.some_int, 66); - assert_eq!(r.docs[2].main.some_int_be, 66); - assert_eq!(r.docs[2].main.some_int_le, 66); - } -} diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs deleted file mode 100644 index d8f21e85b..000000000 --- a/spec/rust/tests/test_default_endian_mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DefaultEndianMod; - -#[test] -fn test_default_endian_mod() { - if let Ok(r) = DefaultEndianMod::from_file("src/fixed_struct.bin") { - assert_eq!(r.main.one, 1262698832); - assert_eq!(r.main.nest.two, -52947); - assert_eq!(r.main.nest_be.two, 1346454347); - } -} diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs deleted file mode 100644 index c71d39911..000000000 --- a/spec/rust/tests/test_docstrings.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Docstrings; - -#[test] -fn test_docstrings() { - if let Ok(r) = Docstrings::from_file("src/fixed_struct.bin") { - } -} diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs deleted file mode 100644 index 6a0603587..000000000 --- a/spec/rust/tests/test_docstrings_docref.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::DocstringsDocref; - -#[test] -fn test_docstrings_docref() { - if let Ok(r) = DocstringsDocref::from_file("src/fixed_struct.bin") { - } -} diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index 686cfdd53..d5bf625ed 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -1,15 +1,21 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr0; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_0::*; #[test] fn test_expr_0() { - if let Ok(r) = Expr0::from_file("src/str_encodings.bin") { - assert_eq!(r.must_be_f7, 247); - assert_eq!(r.must_be_abc123, "abc123"); + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = Expr0::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(*r.must_be_f7(&reader).unwrap(), 247); + assert_eq!(r.must_be_abc123(&reader).unwrap(), "abc123"); } diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index 7b1377902..918b6ba49 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -1,17 +1,28 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr1; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_1::*; #[test] fn test_expr_1() { - if let Ok(r) = Expr1::from_file("src/str_encodings.bin") { - assert_eq!(r.len_of_1, 10); - assert_eq!(r.len_of_1_mod, 8); - assert_eq!(r.str1, "Some ASC"); - assert_eq!(r.str1_len, 8); + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = Expr1::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(10, r.len_of_1); + + let res = r.len_of_1_mod(&reader); + assert_eq!(8, *res.unwrap()); + + assert_eq!("Some ASC", *r.str1()); + + let res = r.str1_len(&reader); + assert_eq!(8, *res.unwrap()); } diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs deleted file mode 100644 index eb7a2cb6a..000000000 --- a/spec/rust/tests/test_expr_2.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr2; - -#[test] -fn test_expr_2() { - if let Ok(r) = Expr2::from_file("src/str_encodings.bin") { - assert_eq!(r.str1.len_orig, 10); - assert_eq!(r.str1.len_mod, 7); - assert_eq!(r.str1.str, "Some AS"); - assert_eq!(r.str1_len, 7); - assert_eq!(r.str1_len_mod, 7); - assert_eq!(r.str1_byte1, 73); - assert_eq!(r.str1_avg, 73); - assert_eq!(r.str1_char5, "e"); - assert_eq!(r.str1_tuple5.byte0, 101); - assert_eq!(r.str1_tuple5.byte0, 101); - assert_eq!(r.str1_tuple5.byte1, 32); - assert_eq!(r.str1_tuple5.byte2, 65); - assert_eq!(r.str1_tuple5.avg, 48); - assert_eq!(r.str2_tuple5.byte0, 101); - assert_eq!(r.str2_tuple5.byte1, 32); - assert_eq!(r.str2_tuple5.byte2, 65); - assert_eq!(r.str2_tuple5.avg, 48); - } -} diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs deleted file mode 100644 index 9998e367a..000000000 --- a/spec/rust/tests/test_expr_3.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::Expr3; - -#[test] -fn test_expr_3() { - if let Ok(r) = Expr3::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, 80); - assert_eq!(r.two, "ACK"); - assert_eq!(r.three, "@ACK"); - assert_eq!(r.four, "_ACK_"); - assert_eq!(r.is_str_eq, true); - assert_eq!(r.is_str_ne, false); - assert_eq!(r.is_str_lt, true); - assert_eq!(r.is_str_gt, false); - assert_eq!(r.is_str_le, true); - assert_eq!(r.is_str_ge, false); - assert_eq!(r.is_str_lt2, true); - assert_eq!(r.test_not, true); - } -} diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs deleted file mode 100644 index 21504b7d4..000000000 --- a/spec/rust/tests/test_expr_array.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprArray; - -#[test] -fn test_expr_array() { - if let Ok(r) = ExprArray::from_file("src/expr_array.bin") { - assert_eq!(r.aint_size, 4); - assert_eq!(r.aint_first, 7657765); - assert_eq!(r.aint_last, 16272640); - assert_eq!(r.aint_min, 49185); - assert_eq!(r.aint_max, 1123362332); - assert_eq!(r.afloat_size, 3); - assert_eq!(r.afloat_first, -2.6839530254859364E-121); - assert_eq!(r.afloat_last, -1.1103359815095273E-175); - assert_eq!(r.afloat_min, -8.754689149998834E+288); - assert_eq!(r.afloat_max, -1.1103359815095273E-175); - assert_eq!(r.astr_size, 3); - assert_eq!(r.astr_first, "foo"); - assert_eq!(r.astr_last, "baz"); - assert_eq!(r.astr_min, "bar"); - assert_eq!(r.astr_max, "foo"); - } -} diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs deleted file mode 100644 index 58656b11c..000000000 --- a/spec/rust/tests/test_expr_bytes_cmp.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprBytesCmp; - -#[test] -fn test_expr_bytes_cmp() { - if let Ok(r) = ExprBytesCmp::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, vec!([0x50])); - assert_eq!(r.two, vec!([0x41, 0x43, 0x4b])); - assert_eq!(r.is_eq, true); - assert_eq!(r.is_ne, false); - assert_eq!(r.is_lt, true); - assert_eq!(r.is_gt, false); - assert_eq!(r.is_le, true); - assert_eq!(r.is_ge, false); - assert_eq!(r.is_lt2, false); - assert_eq!(r.is_gt2, true); - } -} diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs deleted file mode 100644 index f2410bae0..000000000 --- a/spec/rust/tests/test_expr_io_pos.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprIoPos; - -#[test] -fn test_expr_io_pos() { - if let Ok(r) = ExprIoPos::from_file("src/expr_io_pos.bin") { - assert_eq!(r.substream1.my_str, "CURIOSITY"); - assert_eq!(r.substream1.body, vec!([0x11, 0x22, 0x33, 0x44])); - assert_eq!(r.substream1.number, 66); - assert_eq!(r.substream2.my_str, "KILLED"); - assert_eq!(r.substream2.body, vec!([0x61, 0x20, 0x63, 0x61, 0x74])); - assert_eq!(r.substream2.number, 103); - } -} diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs deleted file mode 100644 index 14001402e..000000000 --- a/spec/rust/tests/test_expr_mod.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprMod; - -#[test] -fn test_expr_mod() { - if let Ok(r) = ExprMod::from_file("src/fixed_struct.bin") { - assert_eq!(r.int_u, 1262698832); - assert_eq!(r.int_s, -52947); - assert_eq!(r.mod_pos_const, 9); - assert_eq!(r.mod_neg_const, 4); - assert_eq!(r.mod_pos_seq, 5); - assert_eq!(r.mod_neg_seq, 2); - } -} diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs index fb0a425c0..03bf8b104 100644 --- a/spec/rust/tests/test_fixed_contents.rs +++ b/spec/rust/tests/test_fixed_contents.rs @@ -1,13 +1,19 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::FixedContents; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::fixed_contents::*; #[test] fn test_fixed_contents() { - if let Ok(r) = FixedContents::from_file("src/fixed_struct.bin") { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = FixedContents::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } } diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs deleted file mode 100644 index a47a7e8d5..000000000 --- a/spec/rust/tests/test_fixed_struct.rs +++ /dev/null @@ -1,33 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::FixedStruct; - -#[test] -fn test_fixed_struct() { - if let Ok(r) = FixedStruct::from_file("src/fixed_struct.bin") { - assert_eq!(r.hdr.uint8, 255); - assert_eq!(r.hdr.uint16, 65535); - assert_eq!(r.hdr.uint32, 4294967295); - assert_eq!(r.hdr.uint64, 18446744073709551615); - assert_eq!(r.hdr.sint8, -1); - assert_eq!(r.hdr.sint16, -1); - assert_eq!(r.hdr.sint32, -1); - assert_eq!(r.hdr.sint64, -1); - assert_eq!(r.hdr.uint16le, 66); - assert_eq!(r.hdr.uint32le, 66); - assert_eq!(r.hdr.uint64le, 66); - assert_eq!(r.hdr.sint16le, -66); - assert_eq!(r.hdr.sint32le, -66); - assert_eq!(r.hdr.sint64le, -66); - assert_eq!(r.hdr.uint16be, 66); - assert_eq!(r.hdr.uint32be, 66); - assert_eq!(r.hdr.uint64be, 66); - assert_eq!(r.hdr.sint16be, -66); - assert_eq!(r.hdr.sint32be, -66); - assert_eq!(r.hdr.sint64be, -66); - } -} diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs deleted file mode 100644 index 661d31f48..000000000 --- a/spec/rust/tests/test_float_to_i.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::FloatToI; - -#[test] -fn test_float_to_i() { - if let Ok(r) = FloatToI::from_file("src/floating_points.bin") { - assert_eq!(r.single_value, 0.5); - assert_eq!(r.double_value, 0.25); - assert_eq!(r.single_i, 0); - assert_eq!(r.double_i, 0); - assert_eq!(r.float1_i, 1); - assert_eq!(r.float2_i, 1); - assert_eq!(r.float3_i, 1); - assert_eq!(r.float4_i, -2); - } -} diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs deleted file mode 100644 index 6397cfb2a..000000000 --- a/spec/rust/tests/test_hello_world.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::HelloWorld; - -#[test] -fn test_hello_world() { - if let Ok(r) = HelloWorld::from_file("src/fixed_struct.bin") { - assert_eq!(r.one, 80); - } -} diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs deleted file mode 100644 index 475ef1e50..000000000 --- a/spec/rust/tests/test_if_struct.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IfStruct; - -#[test] -fn test_if_struct() { - if let Ok(r) = IfStruct::from_file("src/if_struct.bin") { - assert_eq!(r.op1.opcode, 83); - assert_eq!(r.op1.arg_str.str, "foo"); - assert_eq!(r.op2.opcode, 84); - assert_eq!(r.op2.arg_tuple.num1, 66); - assert_eq!(r.op2.arg_tuple.num2, 67); - assert_eq!(r.op3.opcode, 83); - assert_eq!(r.op3.arg_str.str, "bar"); - } -} diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs deleted file mode 100644 index a0ce3dab8..000000000 --- a/spec/rust/tests/test_if_values.rs +++ /dev/null @@ -1,19 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IfValues; - -#[test] -fn test_if_values() { - if let Ok(r) = IfValues::from_file("src/fixed_struct.bin") { - assert_eq!(r.codes[0].opcode, 80); - assert_eq!(r.codes[0].half_opcode, 40); - assert_eq!(r.codes[1].opcode, 65); - assertNull(r.codes[1].half_opcode); - assert_eq!(r.codes[2].opcode, 67); - assertNull(r.codes[2].half_opcode); - } -} diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs deleted file mode 100644 index 8d9e033d3..000000000 --- a/spec/rust/tests/test_index_sizes.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexSizes; - -#[test] -fn test_index_sizes() { - if let Ok(r) = IndexSizes::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.bufs[0], "A"); - assert_eq!(r.bufs[1], "BBBBBBBB"); - assert_eq!(r.bufs[2], "CCCC"); - } -} diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs deleted file mode 100644 index f727d6f72..000000000 --- a/spec/rust/tests/test_index_to_param_eos.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexToParamEos; - -#[test] -fn test_index_to_param_eos() { - if let Ok(r) = IndexToParamEos::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.blocks[0].buf, "A"); - assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - assert_eq!(r.blocks[2].buf, "CCCC"); - } -} diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs deleted file mode 100644 index 321f27012..000000000 --- a/spec/rust/tests/test_index_to_param_expr.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexToParamExpr; - -#[test] -fn test_index_to_param_expr() { - if let Ok(r) = IndexToParamExpr::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.blocks[0].buf, "A"); - assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - assert_eq!(r.blocks[2].buf, "CCCC"); - } -} diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs deleted file mode 100644 index 71d09ffbe..000000000 --- a/spec/rust/tests/test_index_to_param_until.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::IndexToParamUntil; - -#[test] -fn test_index_to_param_until() { - if let Ok(r) = IndexToParamUntil::from_file("src/index_sizes.bin") { - assert_eq!(r.qty, 3); - assert_eq!(r.sizes[0], 1); - assert_eq!(r.sizes[1], 8); - assert_eq!(r.sizes[2], 4); - assert_eq!(r.blocks[0].buf, "A"); - assert_eq!(r.blocks[1].buf, "BBBBBBBB"); - assert_eq!(r.blocks[2].buf, "CCCC"); - } -} diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs deleted file mode 100644 index c389a5d3b..000000000 --- a/spec/rust/tests/test_instance_io_user.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceIoUser; - -#[test] -fn test_instance_io_user() { - if let Ok(r) = InstanceIoUser::from_file("src/instance_io.bin") { - assert_eq!(r.qty_entries, 3); - assert_eq!(r.entries[0].name, "the"); - assert_eq!(r.entries[1].name, "rainy"); - assert_eq!(r.entries[2].name, "day it is"); - } -} diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs deleted file mode 100644 index 0a798b75c..000000000 --- a/spec/rust/tests/test_instance_std.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceStd; - -#[test] -fn test_instance_std() { - if let Ok(r) = InstanceStd::from_file("src/str_encodings.bin") { - assert_eq!(r.header, "Some "); - } -} diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs deleted file mode 100644 index 07df25cd1..000000000 --- a/spec/rust/tests/test_instance_std_array.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceStdArray; - -#[test] -fn test_instance_std_array() { - if let Ok(r) = InstanceStdArray::from_file("src/instance_std_array.bin") { - assert_eq!(r.ofs, 16); - assert_eq!(r.qty_entries, 3); - assert_eq!(r.entry_size, 4); - assert_eq!(r.entries.len(), 3); - assert_eq!(r.entries[0], vec!([0x11, 0x11, 0x11, 0x11])); - assert_eq!(r.entries[1], vec!([0x22, 0x22, 0x22, 0x22])); - assert_eq!(r.entries[2], vec!([0x33, 0x33, 0x33, 0x33])); - } -} diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs deleted file mode 100644 index 3cbf3c76d..000000000 --- a/spec/rust/tests/test_instance_user_array.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::InstanceUserArray; - -#[test] -fn test_instance_user_array() { - if let Ok(r) = InstanceUserArray::from_file("src/instance_std_array.bin") { - assert_eq!(r.ofs, 16); - assert_eq!(r.qty_entries, 3); - assert_eq!(r.entry_size, 4); - assert_eq!(r.user_entries.len(), 3); - assert_eq!(r.user_entries[0].word1, 4369); - assert_eq!(r.user_entries[0].word2, 4369); - assert_eq!(r.user_entries[1].word1, 8738); - assert_eq!(r.user_entries[1].word2, 8738); - assert_eq!(r.user_entries[2].word1, 13107); - assert_eq!(r.user_entries[2].word2, 13107); - } -} diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs deleted file mode 100644 index 305913aa5..000000000 --- a/spec/rust/tests/test_js_signed_right_shift.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::JsSignedRightShift; - -#[test] -fn test_js_signed_right_shift() { - if let Ok(r) = JsSignedRightShift::from_file("src/fixed_struct.bin") { - assert_eq!(r.should_be_40000000, 1073741824); - assert_eq!(r.should_be_a00000, 10485760); - } -} diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs deleted file mode 100644 index 9f068b47a..000000000 --- a/spec/rust/tests/test_meta_xref.rs +++ /dev/null @@ -1,13 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MetaXref; - -#[test] -fn test_meta_xref() { - if let Ok(r) = MetaXref::from_file("src/fixed_struct.bin") { - } -} diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs deleted file mode 100644 index c66faece9..000000000 --- a/spec/rust/tests/test_multiple_use.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::MultipleUse; - -#[test] -fn test_multiple_use() { - if let Ok(r) = MultipleUse::from_file("src/position_abs.bin") { - assert_eq!(r.t1.first_use.value, 32); - assert_eq!(r.t2.second_use.value, 32); - } -} diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs deleted file mode 100644 index c43fbd303..000000000 --- a/spec/rust/tests/test_nav_parent.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParent; - -#[test] -fn test_nav_parent() { - if let Ok(r) = NavParent::from_file("src/nav.bin") { - assert_eq!(r.header.qty_entries, 2); - assert_eq!(r.header.filename_len, 8); - assert_eq!(r.index.entries.len(), 2); - assert_eq!(r.index.entries[0].filename, "FIRST___"); - assert_eq!(r.index.entries[1].filename, "SECOND__"); - } -} diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs deleted file mode 100644 index c2f6d256f..000000000 --- a/spec/rust/tests/test_nav_parent2.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParent2; - -#[test] -fn test_nav_parent2() { - if let Ok(r) = NavParent2::from_file("src/nav_parent2.bin") { - assert_eq!(r.ofs_tags, 8); - assert_eq!(r.num_tags, 2); - assert_eq!(r.tags[0].name, "RAHC"); - assert_eq!(r.tags[0].ofs, 32); - assert_eq!(r.tags[0].num_items, 3); - assert_eq!(r.tags[0].tag_content.content, "foo"); - assert_eq!(r.tags[1].name, "RAHC"); - assert_eq!(r.tags[1].ofs, 35); - assert_eq!(r.tags[1].num_items, 6); - assert_eq!(r.tags[1].tag_content.content, "barbaz"); - } -} diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs deleted file mode 100644 index cc5abd5b2..000000000 --- a/spec/rust/tests/test_nav_parent3.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParent3; - -#[test] -fn test_nav_parent3() { - if let Ok(r) = NavParent3::from_file("src/nav_parent2.bin") { - assert_eq!(r.ofs_tags, 8); - assert_eq!(r.num_tags, 2); - assert_eq!(r.tags[0].name, "RAHC"); - assert_eq!(r.tags[0].ofs, 32); - assert_eq!(r.tags[0].num_items, 3); - assert_eq!(r.tags[0].tag_content.content, "foo"); - assert_eq!(r.tags[1].name, "RAHC"); - assert_eq!(r.tags[1].ofs, 35); - assert_eq!(r.tags[1].num_items, 6); - assert_eq!(r.tags[1].tag_content.content, "barbaz"); - } -} diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs deleted file mode 100644 index f8e935120..000000000 --- a/spec/rust/tests/test_nav_parent_false.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentFalse; - -#[test] -fn test_nav_parent_false() { - if let Ok(r) = NavParentFalse::from_file("src/nav_parent_codes.bin") { - assert_eq!(r.child_size, 3); - assert_eq!(r.element_a.foo.code, 73); - assert_eq!(r.element_a.foo.more, vec!([0x31, 0x32, 0x33])); - assert_eq!(r.element_a.bar.foo.code, 66); - assert_eq!(r.element_b.foo.code, 98); - } -} diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs deleted file mode 100644 index 868d60f24..000000000 --- a/spec/rust/tests/test_nav_parent_false2.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentFalse2; - -#[test] -fn test_nav_parent_false2() { - if let Ok(r) = NavParentFalse2::from_file("src/fixed_struct.bin") { - assert_eq!(r.parentless.foo, 80); - } -} diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs deleted file mode 100644 index 2ebc78835..000000000 --- a/spec/rust/tests/test_nav_parent_override.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentOverride; - -#[test] -fn test_nav_parent_override() { - if let Ok(r) = NavParentOverride::from_file("src/nav_parent_codes.bin") { - assert_eq!(r.child_size, 3); - assert_eq!(r.child_1.data, vec!([0x49, 0x31, 0x32])); - assert_eq!(r.mediator_2.child_2.data, vec!([0x33, 0x42, 0x62])); - } -} diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs deleted file mode 100644 index b2373ef91..000000000 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentSwitch; - -#[test] -fn test_nav_parent_switch() { - if let Ok(r) = NavParentSwitch::from_file("src/nav_parent_switch.bin") { - assert_eq!(r.category, 1); - assert_eq!(r.content.foo, 66); - assert_eq!(r.content.subelement.bar, 255); - } -} diff --git a/spec/rust/tests/test_nav_parent_vs_value_inst.rs b/spec/rust/tests/test_nav_parent_vs_value_inst.rs deleted file mode 100644 index 944464338..000000000 --- a/spec/rust/tests/test_nav_parent_vs_value_inst.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavParentVsValueInst; - -#[test] -fn test_nav_parent_vs_value_inst() { - if let Ok(r) = NavParentVsValueInst::from_file("src/term_strz.bin") { - assert_eq!(r.s1, "foo"); - } -} diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs deleted file mode 100644 index 1bf59f436..000000000 --- a/spec/rust/tests/test_nav_root.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NavRoot; - -#[test] -fn test_nav_root() { - if let Ok(r) = NavRoot::from_file("src/nav.bin") { - assert_eq!(r.header.qty_entries, 2); - assert_eq!(r.header.filename_len, 8); - assert_eq!(r.index.entries.len(), 2); - assert_eq!(r.index.entries[0].filename, "FIRST___"); - assert_eq!(r.index.entries[1].filename, "SECOND__"); - } -} diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs deleted file mode 100644 index ca73804cf..000000000 --- a/spec/rust/tests/test_nested_same_name.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedSameName; - -#[test] -fn test_nested_same_name() { - if let Ok(r) = NestedSameName::from_file("src/repeat_n_struct.bin") { - assert_eq!(r.main_data.main_size, 2); - assert_eq!(r.main_data.foo.data, vec!([0x10, 0x0, 0x0, 0x0])); - } -} diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs deleted file mode 100644 index 1087cb851..000000000 --- a/spec/rust/tests/test_nested_same_name2.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedSameName2; - -#[test] -fn test_nested_same_name2() { - if let Ok(r) = NestedSameName2::from_file("src/nested_same_name2.bin") { - assert_eq!(r.version, 66); - assert_eq!(r.main_data.main_size, 2); - assert_eq!(r.main_data.foo.data1, vec!([0x11, 0x11, 0x11, 0x11])); - assert_eq!(r.dummy.dummy_size, 3); - assert_eq!(r.dummy.foo.data2, vec!([0x22, 0x22, 0x22, 0x22, 0x22, 0x22])); - } -} diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs deleted file mode 100644 index 796b4dda8..000000000 --- a/spec/rust/tests/test_nested_types.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypes; - -#[test] -fn test_nested_types() { - if let Ok(r) = NestedTypes::from_file("src/fixed_struct.bin") { - assert_eq!(r.one.typed_at_root.value_b, 80); - assert_eq!(r.one.typed_here.value_c, 65); - assert_eq!(r.two.value_b, 67); - } -} diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs deleted file mode 100644 index ed295df76..000000000 --- a/spec/rust/tests/test_nested_types2.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypes2; - -#[test] -fn test_nested_types2() { - if let Ok(r) = NestedTypes2::from_file("src/fixed_struct.bin") { - assert_eq!(r.one.typed_at_root.value_b, 80); - assert_eq!(r.one.typed_here1.value_c, 65); - assert_eq!(r.one.typed_here1.typed_here.value_d, 67); - assert_eq!(r.one.typed_here1.typed_parent.value_cc, 75); - assert_eq!(r.one.typed_here1.typed_root.value_b, 45); - assert_eq!(r.one.typed_here2.value_cc, 49); - assert_eq!(r.two.value_b, -1); - } -} diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs deleted file mode 100644 index ee2fd8f97..000000000 --- a/spec/rust/tests/test_nested_types3.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypes3; - -#[test] -fn test_nested_types3() { - if let Ok(r) = NestedTypes3::from_file("src/fixed_struct.bin") { - assert_eq!(r.a_cc.value_cc, 80); - assert_eq!(r.a_c_d.value_d, 65); - assert_eq!(r.b.value_b, 67); - assert_eq!(r.b.a_cc.value_cc, 75); - assert_eq!(r.b.a_c_d.value_d, 45); - } -} diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs deleted file mode 100644 index c649b8283..000000000 --- a/spec/rust/tests/test_non_standard.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NonStandard; - -#[test] -fn test_non_standard() { - if let Ok(r) = NonStandard::from_file("src/fixed_struct.bin") { - assert_eq!(r.foo, 80); - } -} diff --git a/spec/rust/tests/test_params_call_short.rs b/spec/rust/tests/test_params_call_short.rs deleted file mode 100644 index e979f2124..000000000 --- a/spec/rust/tests/test_params_call_short.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsCallShort; - -#[test] -fn test_params_call_short() { - if let Ok(r) = ParamsCallShort::from_file("src/term_strz.bin") { - assert_eq!(r.buf1.body, "foo|b"); - assert_eq!(r.buf2.body, "ar|ba"); - assert_eq!(r.buf2.trailer, 122); - } -} diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs deleted file mode 100644 index 619950a9f..000000000 --- a/spec/rust/tests/test_params_pass_usertype.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ParamsPassUsertype; - -#[test] -fn test_params_pass_usertype() { - if let Ok(r) = ParamsPassUsertype::from_file("src/position_in_seq.bin") { - assert_eq!(r.first.foo, 1); - assert_eq!(r.one.buf, vec!([0x2])); - } -} diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs deleted file mode 100644 index 27c477617..000000000 --- a/spec/rust/tests/test_position_abs.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::PositionAbs; - -#[test] -fn test_position_abs() { - if let Ok(r) = PositionAbs::from_file("src/position_abs.bin") { - assert_eq!(r.index_offset, 32); - assert_eq!(r.index.entry, "foo"); - } -} diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs deleted file mode 100644 index 31a69b08e..000000000 --- a/spec/rust/tests/test_position_in_seq.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::PositionInSeq; - -#[test] -fn test_position_in_seq() { - if let Ok(r) = PositionInSeq::from_file("src/position_in_seq.bin") { - assert_eq!(r.numbers, [(0 + 1), 2, 3]); - } -} diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs deleted file mode 100644 index 97f5ddd06..000000000 --- a/spec/rust/tests/test_position_to_end.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::PositionToEnd; - -#[test] -fn test_position_to_end() { - if let Ok(r) = PositionToEnd::from_file("src/position_to_end.bin") { - assert_eq!(r.index.foo, 66); - assert_eq!(r.index.bar, 4660); - } -} diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index 3cc865f9f..462f6683a 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -1,17 +1,30 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceBytes; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_coerce_bytes::*; #[test] fn test_process_coerce_bytes() { - if let Ok(r) = ProcessCoerceBytes::from_file("src/process_coerce_bytes.bin") { - assert_eq!(r.records[0].flag, 0); - assert_eq!(r.records[0].buf, vec!([0x41, 0x41, 0x41, 0x41])); - assert_eq!(r.records[1].flag, 1); - assert_eq!(r.records[1].buf, vec!([0x42, 0x42, 0x42, 0x42])); + let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessCoerceBytes::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(0, r.records[0].flag()); + + let mut i = r.records.iter_mut(); + + let buf : Vec = vec![0x41, 0x41, 0x41, 0x41]; + let x = i.next().unwrap(); + assert_eq!(&buf, x.buf(&reader).unwrap()); + + let buf : Vec = vec![0x42, 0x42, 0x42, 0x42]; + let x = i.next().unwrap(); + assert_eq!(&buf, x.buf(&reader).unwrap()); } diff --git a/spec/rust/tests/test_process_coerce_switch.rs b/spec/rust/tests/test_process_coerce_switch.rs deleted file mode 100644 index 5373c7ad7..000000000 --- a/spec/rust/tests/test_process_coerce_switch.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceSwitch; - -#[test] -fn test_process_coerce_switch() { - if let Ok(r) = ProcessCoerceSwitch::from_file("src/process_coerce_switch.bin") { - assert_eq!(r.buf_type, 0); - assert_eq!(r.flag, 0); - assert_eq!(r.buf.bar, vec!([0x41, 0x41, 0x41, 0x41])); - } -} diff --git a/spec/rust/tests/test_process_coerce_usertype1.rs b/spec/rust/tests/test_process_coerce_usertype1.rs deleted file mode 100644 index e5b91114d..000000000 --- a/spec/rust/tests/test_process_coerce_usertype1.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceUsertype1; - -#[test] -fn test_process_coerce_usertype1() { - if let Ok(r) = ProcessCoerceUsertype1::from_file("src/process_coerce_bytes.bin") { - assert_eq!(r.records[0].flag, 0); - assert_eq!(r.records[0].buf.value, 1094795585); - assert_eq!(r.records[1].flag, 1); - assert_eq!(r.records[1].buf.value, 1111638594); - } -} diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs deleted file mode 100644 index b0ecbd8cf..000000000 --- a/spec/rust/tests/test_process_coerce_usertype2.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCoerceUsertype2; - -#[test] -fn test_process_coerce_usertype2() { - if let Ok(r) = ProcessCoerceUsertype2::from_file("src/process_coerce_bytes.bin") { - assert_eq!(r.records[0].flag, 0); - assert_eq!(r.records[0].buf.value, 1094795585); - assert_eq!(r.records[1].flag, 1); - assert_eq!(r.records[1].buf.value, 1111638594); - } -} diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs deleted file mode 100644 index d07d106b2..000000000 --- a/spec/rust/tests/test_process_custom.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessCustom; - -#[test] -fn test_process_custom() { - if let Ok(r) = ProcessCustom::from_file("src/process_rotate.bin") { - assert_eq!(r.buf1, vec!([0x10, 0xb3, 0x94, 0x94, 0xf4])); - assert_eq!(r.buf2, vec!([0x5f, 0xba, 0x7b, 0x93, 0x63, 0x23, 0x5f])); - assert_eq!(r.buf3, vec!([0x29, 0x33, 0xb1, 0x38, 0xb1])); - } -} diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs index 1ab694a8f..7b9d2d942 100644 --- a/spec/rust/tests/test_process_rotate.rs +++ b/spec/rust/tests/test_process_rotate.rs @@ -1,16 +1,22 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessRotate; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_rotate::*; #[test] fn test_process_rotate() { - if let Ok(r) = ProcessRotate::from_file("src/process_rotate.bin") { - assert_eq!(r.buf1, vec!([0x48, 0x65, 0x6c, 0x6c, 0x6f])); - assert_eq!(r.buf2, vec!([0x57, 0x6f, 0x72, 0x6c, 0x64])); - assert_eq!(r.buf3, vec!([0x54, 0x68, 0x65, 0x72, 0x65])); + let bytes = fs::read("../../src/process_rotate.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessRotate::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(*r.buf1(), [0x48u8, 0x65u8, 0x6cu8, 0x6cu8, 0x6fu8].to_vec()); + assert_eq!(*r.buf2(), [0x57u8, 0x6fu8, 0x72u8, 0x6cu8, 0x64u8].to_vec()); + assert_eq!(*r.buf3(), [0x54u8, 0x68u8, 0x65u8, 0x72u8, 0x65u8].to_vec()); } diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs index 35fe9f85c..2e0d95de9 100644 --- a/spec/rust/tests/test_process_to_user.rs +++ b/spec/rust/tests/test_process_to_user.rs @@ -1,14 +1,20 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessToUser; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_to_user::*; #[test] fn test_process_to_user() { - if let Ok(r) = ProcessToUser::from_file("src/process_rotate.bin") { - assert_eq!(r.buf1.str, "Hello"); + let bytes = fs::read("../../src/process_rotate.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessToUser::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.buf1().str(), "Hello"); } diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs index cb41dcc7f..c78fb00da 100644 --- a/spec/rust/tests/test_process_xor4_const.rs +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -1,15 +1,21 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXor4Const; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_xor4_const::*; #[test] fn test_process_xor4_const() { - if let Ok(r) = ProcessXor4Const::from_file("src/process_xor_4.bin") { - assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessXor4Const::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(*r.key(), [0xecu8, 0xbbu8, 0xa3u8, 0x14u8].to_vec()); + assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); } diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs index deff2c110..e5e6e301c 100644 --- a/spec/rust/tests/test_process_xor4_value.rs +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -1,15 +1,21 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXor4Value; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_xor4_value::*; #[test] fn test_process_xor4_value() { - if let Ok(r) = ProcessXor4Value::from_file("src/process_xor_4.bin") { - assert_eq!(r.key, vec!([0xec, 0xbb, 0xa3, 0x14])); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessXor4Value::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(*r.key(), [0xecu8, 0xbbu8, 0xa3u8, 0x14u8].to_vec()); + assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); } diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 268c1e802..044fcd84c 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -1,15 +1,21 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXorConst; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_xor_const::*; #[test] fn test_process_xor_const() { - if let Ok(r) = ProcessXorConst::from_file("src/process_xor_1.bin") { - assert_eq!(r.key, 255); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessXorConst::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.key(), 255); + assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); } diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index e0a266145..ffd2149ee 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -1,15 +1,21 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ProcessXorValue; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_xor_value::*; #[test] fn test_process_xor_value() { - if let Ok(r) = ProcessXorValue::from_file("src/process_xor_1.bin") { - assert_eq!(r.key, 255); - assert_eq!(r.buf, vec!([0x66, 0x6f, 0x6f, 0x20, 0x62, 0x61, 0x72])); + let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessXorValue::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.key(), 255); + assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); } diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs deleted file mode 100644 index 2eca3a73c..000000000 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatEosStruct; - -#[test] -fn test_repeat_eos_struct() { - if let Ok(r) = RepeatEosStruct::from_file("src/repeat_eos_struct.bin") { - assert_eq!(r.chunks.len(), 2); - assert_eq!(r.chunks[0].offset, 0); - assert_eq!(r.chunks[0].len, 66); - assert_eq!(r.chunks[1].offset, 66); - assert_eq!(r.chunks[1].len, 2069); - } -} diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs deleted file mode 100644 index 74f5d24cf..000000000 --- a/spec/rust/tests/test_repeat_eos_u4.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatEosU4; - -#[test] -fn test_repeat_eos_u4() { - if let Ok(r) = RepeatEosU4::from_file("src/repeat_eos_struct.bin") { - assert_eq!(r.numbers, [0, 66, 66, 2069]); - } -} diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs deleted file mode 100644 index 802fb7497..000000000 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatNStruct; - -#[test] -fn test_repeat_n_struct() { - if let Ok(r) = RepeatNStruct::from_file("src/repeat_n_struct.bin") { - assert_eq!(r.chunks.len(), 2); - assert_eq!(r.chunks[0].offset, 16); - assert_eq!(r.chunks[0].len, 8312); - assert_eq!(r.chunks[1].offset, 8328); - assert_eq!(r.chunks[1].len, 15); - } -} diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs deleted file mode 100644 index 87c87b8d4..000000000 --- a/spec/rust/tests/test_repeat_n_strz.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatNStrz; - -#[test] -fn test_repeat_n_strz() { - if let Ok(r) = RepeatNStrz::from_file("src/repeat_n_strz.bin") { - assert_eq!(r.qty, 2); - assert_eq!(r.lines, ["foo", "bar"]); - } -} diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs deleted file mode 100644 index 0286318ab..000000000 --- a/spec/rust/tests/test_repeat_n_strz_double.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatNStrzDouble; - -#[test] -fn test_repeat_n_strz_double() { - if let Ok(r) = RepeatNStrzDouble::from_file("src/repeat_n_strz.bin") { - assert_eq!(r.qty, 2); - assert_eq!(r.lines1, ["foo"]); - assert_eq!(r.lines2, ["bar"]); - } -} diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs deleted file mode 100644 index 158fc16b9..000000000 --- a/spec/rust/tests/test_repeat_until_complex.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatUntilComplex; - -#[test] -fn test_repeat_until_complex() { - if let Ok(r) = RepeatUntilComplex::from_file("src/repeat_until_complex.bin") { - assert_eq!(r.first.len(), 3); - assert_eq!(r.first[0].count, 4); - assert_eq!(r.first[0].values, [(0 + 1), 2, 3, 4]); - assert_eq!(r.first[1].count, 2); - assert_eq!(r.first[1].values, [(0 + 1), 2]); - assert_eq!(r.first[2].count, 0); - assert_eq!(r.second.len(), 4); - assert_eq!(r.second[0].count, 6); - assert_eq!(r.second[0].values, [(0 + 1), 2, 3, 4, 5, 6]); - assert_eq!(r.second[1].count, 3); - assert_eq!(r.second[1].values, [(0 + 1), 2, 3]); - assert_eq!(r.second[2].count, 4); - assert_eq!(r.second[2].values, [(0 + 1), 2, 3, 4]); - assert_eq!(r.second[3].count, 0); - assert_eq!(r.third, [(0 + 102), 111, 111, 98, 97, 114, 0]); - } -} diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs deleted file mode 100644 index 2fe282b51..000000000 --- a/spec/rust/tests/test_repeat_until_s4.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatUntilS4; - -#[test] -fn test_repeat_until_s4() { - if let Ok(r) = RepeatUntilS4::from_file("src/repeat_until_s4.bin") { - assert_eq!(r.entries, [66, 4919, -251658241, -1]); - assert_eq!(r.afterall, "foobar"); - } -} diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs deleted file mode 100644 index 3d23c1efc..000000000 --- a/spec/rust/tests/test_repeat_until_sized.rs +++ /dev/null @@ -1,20 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::RepeatUntilSized; - -#[test] -fn test_repeat_until_sized() { - if let Ok(r) = RepeatUntilSized::from_file("src/repeat_until_process.bin") { - assert_eq!(r.records.len(), 3); - assert_eq!(r.records[0].marker, 232); - assert_eq!(r.records[0].body, 2863311546); - assert_eq!(r.records[1].marker, 250); - assert_eq!(r.records[1].body, 2863315102); - assert_eq!(r.records[2].marker, 170); - assert_eq!(r.records[2].body, 1431655765); - } -} diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs index 7759fd83f..ad99cbc3a 100644 --- a/spec/rust/tests/test_str_encodings.rs +++ b/spec/rust/tests/test_str_encodings.rs @@ -1,17 +1,23 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEncodings; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_encodings::*; #[test] fn test_str_encodings() { - if let Ok(r) = StrEncodings::from_file("src/str_encodings.bin") { - assert_eq!(r.str1, "Some ASCII"); - assert_eq!(r.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.str4, "\u{2591}\u{2592}\u{2593}"); + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrEncodings::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.str1(), "Some ASCII"); + assert_eq!(r.str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(r.str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(r.str4(), "\u{2591}\u{2592}\u{2593}"); } diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs index e2cdd782a..2f04524ce 100644 --- a/spec/rust/tests/test_str_encodings_default.rs +++ b/spec/rust/tests/test_str_encodings_default.rs @@ -1,17 +1,23 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEncodingsDefault; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_encodings_default::*; #[test] fn test_str_encodings_default() { - if let Ok(r) = StrEncodingsDefault::from_file("src/str_encodings.bin") { - assert_eq!(r.str1, "Some ASCII"); - assert_eq!(r.rest.str2, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.rest.str3, "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.rest.str4, "\u{2591}\u{2592}\u{2593}"); + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrEncodingsDefault::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.str1(), "Some ASCII"); + assert_eq!(r.rest().str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(r.rest().str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(r.rest().str4(), "\u{2591}\u{2592}\u{2593}"); } diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs new file mode 100644 index 000000000..49ce3d952 --- /dev/null +++ b/spec/rust/tests/test_str_encodings_utf16.rs @@ -0,0 +1,25 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_encodings_utf16::*; + +#[test] +fn test_str_encodings_utf16() { + let bytes = fs::read("../../src/str_encodings_utf16.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrEncodingsUtf16::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(r.len_be(), 12); + assert_eq!(r.be_bom_removed().bom(), 65279); + assert_eq!(r.be_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(r.len_le(), 12); + assert_eq!(r.le_bom_removed().bom(), 65279); + assert_eq!(r.le_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); +} diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs index dda25ba85..da946fc9a 100644 --- a/spec/rust/tests/test_str_eos.rs +++ b/spec/rust/tests/test_str_eos.rs @@ -1,14 +1,20 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrEos; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_eos::*; #[test] fn test_str_eos() { - if let Ok(r) = StrEos::from_file("src/term_strz.bin") { - assert_eq!(r.str, "foo|bar|baz@"); + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrEos::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.str(), "foo|bar|baz@"); } diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs index 95c5148a8..854bf68b3 100644 --- a/spec/rust/tests/test_str_literals2.rs +++ b/spec/rust/tests/test_str_literals2.rs @@ -1,17 +1,30 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrLiterals2; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_literals2::*; #[test] fn test_str_literals2() { - if let Ok(r) = StrLiterals2::from_file("src/fixed_struct.bin") { - assert_eq!(r.dollar1, "$foo"); - assert_eq!(r.dollar2, "${foo}"); - assert_eq!(r.hash, "#{foo}"); - assert_eq!(r.at_sign, "@foo"); + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrLiterals2::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + let dollar1 = r.dollar1(&reader).unwrap(); + assert_eq!("$foo", *dollar1); + + let dollar2 = r.dollar2(&reader).unwrap(); + assert_eq!("${foo}", *dollar2); + + let hash = r.hash(&reader).unwrap(); + assert_eq!("#{foo}", *hash); + + let at_sign = r.at_sign(&reader).unwrap(); + assert_eq!("@foo", *at_sign); } diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs index 8b953fd98..9124a485c 100644 --- a/spec/rust/tests/test_str_pad_term.rs +++ b/spec/rust/tests/test_str_pad_term.rs @@ -1,17 +1,23 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::StrPadTerm; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_pad_term::*; #[test] fn test_str_pad_term() { - if let Ok(r) = StrPadTerm::from_file("src/str_pad_term.bin") { - assert_eq!(r.str_pad, "str1"); - assert_eq!(r.str_term, "str2foo"); - assert_eq!(r.str_term_and_pad, "str+++3bar+++"); - assert_eq!(r.str_term_include, "str4baz@"); + let bytes = fs::read("../../src/str_pad_term.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrPadTerm::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.str_pad(), "str1"); + assert_eq!(r.str_term(), "str2foo"); + assert_eq!(r.str_term_and_pad(), "str+++3bar+++"); + assert_eq!(r.str_term_include(), "str4baz@"); } diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index 72ef1bd5c..5002393d8 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -1,17 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -extern crate kaitai_struct; -extern crate rust; +#![allow(dead_code)] +use std::fs; -use kaitai_struct::KaitaiStruct; -use rust::StrPadTermEmpty; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::str_pad_term_empty::*; #[test] fn test_str_pad_term_empty() { - if let Ok(r) = StrPadTermEmpty::from_file("src/str_pad_term_empty.bin") { - assert_eq!(r.str_pad, ""); - assert_eq!(r.str_term, ""); - assert_eq!(r.str_term_and_pad, ""); - assert_eq!(r.str_term_include, "@"); + let bytes = fs::read("../../src/str_pad_term_empty.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = StrPadTermEmpty::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.str_pad, ""); + assert_eq!(r.str_term, ""); + assert_eq!(r.str_term_and_pad, ""); + assert_eq!(r.str_term_include, "@"); } diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index 427692a69..0cbbb96b2 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -1,22 +1,48 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchBytearray; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_bytearray::*; #[test] fn test_switch_bytearray() { - if let Ok(r) = SwitchBytearray::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, vec!([0x53])); - assert_eq!(r.opcodes[0].body.value, "foobar"); - assert_eq!(r.opcodes[1].code, vec!([0x49])); - assert_eq!(r.opcodes[1].body.value, 66); - assert_eq!(r.opcodes[2].code, vec!([0x49])); - assert_eq!(r.opcodes[2].body.value, 55); - assert_eq!(r.opcodes[3].code, vec!([0x53])); - assert_eq!(r.opcodes[3].body.value, ""); + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchBytearray::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(4, r.opcodes.len()); + + assert_eq!(vec![0x53], r.opcodes[0].code); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes[0].body() { + assert_eq!("foobar", s.value); + } else { + panic!("expected enum SwitchBytearray_Opcode_Strval"); + } + + assert_eq!(vec![0x49], r.opcodes[1].code); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes[1].body() { + assert_eq!(66, s.value); + } else { + panic!("expected enum SwitchBytearray_Opcode_Intval"); + } + + assert_eq!(vec![0x49], r.opcodes[2].code); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes[2].body() { + assert_eq!(55, s.value); + } else { + panic!("expected enum SwitchBytearray_Opcode_Intval"); + } + + assert_eq!(vec![0x53], r.opcodes[3].code); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes[3].body() { + assert_eq!("", s.value); + } else { + panic!("expected enum SwitchBytearray_Opcode_Strval"); } } diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs new file mode 100644 index 000000000..63f815da6 --- /dev/null +++ b/spec/rust/tests/test_switch_else_only.rs @@ -0,0 +1,25 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_else_only::*; + +#[test] +fn test_switch_else_only() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchElseOnly::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(83, r.opcode); + let SwitchElseOnly_PrimByte::S1(v) = r.prim_byte.as_ref().unwrap(); + assert_eq!(102, *v); + + let SwitchElseOnly_Ut::SwitchElseOnly_Data(d) = r.ut.as_ref().unwrap(); + assert_eq!(vec![0x72, 0x00, 0x49, 0x42], d.value); +} diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index f873b3bda..2e6ddf531 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -1,22 +1,28 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchIntegers; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_integers::*; #[test] fn test_switch_integers() { - if let Ok(r) = SwitchIntegers::from_file("src/switch_integers.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, 1); - assert_eq!(r.opcodes[0].body, 7); - assert_eq!(r.opcodes[1].code, 2); - assert_eq!(r.opcodes[1].body, 16448); - assert_eq!(r.opcodes[2].code, 4); - assert_eq!(r.opcodes[2].body, 4919); - assert_eq!(r.opcodes[3].code, 8); - assert_eq!(r.opcodes[3].body, 4919); + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchIntegers::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.opcodes.len(), 4); + assert_eq!(r.opcodes[0 as usize].code(), 1); + assert_eq!(r.opcodes[0 as usize].body(), 7); + assert_eq!(r.opcodes[1 as usize].code(), 2); + assert_eq!(r.opcodes[1 as usize].body(), 16448); + assert_eq!(r.opcodes[2 as usize].code(), 4); + assert_eq!(r.opcodes[2 as usize].body(), 4919); + assert_eq!(r.opcodes[3 as usize].code(), 8); + assert_eq!(r.opcodes[3 as usize].body(), 4919); } diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index 6e7872a2f..08f3db3b0 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -1,18 +1,24 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchIntegers2; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_integers2::*; #[test] fn test_switch_integers2() { - if let Ok(r) = SwitchIntegers2::from_file("src/switch_integers.bin") { - assert_eq!(r.code, 1); - assert_eq!(r.len, 7); - assert_eq!(r.ham, vec!([0x2, 0x40, 0x40, 0x4, 0x37, 0x13, 0x0])); - assert_eq!(r.padding, 0); - assert_eq!(r.len_mod_str, "13"); + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchIntegers2::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.code(), 1); + assert_eq!(r.len(), 7); + assert_eq!(r.ham(), &[0x2u8, 0x40u8, 0x40u8, 0x4u8, 0x37u8, 0x13u8, 0x0u8].to_vec()); + assert_eq!(r.padding(), 0); + assert_eq!(r.len_mod_str(&reader).unwrap(), "13"); } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index 776a6b1b2..31c441500 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -1,22 +1,46 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualInt; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_int::*; #[test] fn test_switch_manual_int() { - if let Ok(r) = SwitchManualInt::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, 83); - assert_eq!(r.opcodes[0].body.value, "foobar"); - assert_eq!(r.opcodes[1].code, 73); - assert_eq!(r.opcodes[1].body.value, 66); - assert_eq!(r.opcodes[2].code, 73); - assert_eq!(r.opcodes[2].body.value, 55); - assert_eq!(r.opcodes[3].code, 83); - assert_eq!(r.opcodes[3].body.value, ""); + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualInt::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(83, r.opcodes()[0].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes[0].body() { + assert_eq!("foobar", s.value()); + } else { + panic!("expected enum SwitchManualInt_Opcode_Body"); + } + + assert_eq!(73, r.opcodes()[1].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes[1].body() { + assert_eq!(66, s.value()); + } else { + panic!("expected enum SwitchManualInt_Opcode_Body"); + } + + assert_eq!(73, r.opcodes()[2].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes[2].body() { + assert_eq!(55, s.value()); + } else { + panic!("expected enum SwitchManualInt_Opcode_Body"); + } + + assert_eq!(83, r.opcodes()[3].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes[3].body() { + assert_eq!("", s.value()); + } else { + panic!("expected enum SwitchManualInt_Opcode_Body"); } } diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index cae8cfba0..83d2f5175 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -1,22 +1,48 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualIntElse; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_int_else::*; #[test] fn test_switch_manual_int_else() { - if let Ok(r) = SwitchManualIntElse::from_file("src/switch_opcodes2.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, 83); - assert_eq!(r.opcodes[0].body.value, "foo"); - assert_eq!(r.opcodes[1].code, 88); - assert_eq!(r.opcodes[1].body.filler, 66); - assert_eq!(r.opcodes[2].code, 89); - assert_eq!(r.opcodes[2].body.filler, 51966); - assert_eq!(r.opcodes[3].code, 73); - assert_eq!(r.opcodes[3].body.value, 7); + let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualIntElse::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(4, r.opcodes().len()); + + assert_eq!(83, r.opcodes()[0].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Strval(s) = r.opcodes[0].body() { + assert_eq!("foo", s.value); + } else { + panic!("expected enum SwitchManualIntElse_Opcode_Strval"); + } + + assert_eq!(88, r.opcodes()[1].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes[1].body() { + assert_eq!(66, s.filler); + } else { + panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); + } + + assert_eq!(89, r.opcodes()[2].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes[2].body() { + assert_eq!(51966, s.filler); + } else { + panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); + } + + assert_eq!(73, r.opcodes()[3].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Intval(s) = r.opcodes[3].body() { + assert_eq!(7, s.value); + } else { + panic!("expected enum SwitchManualIntElse_Opcode_Intval"); } } diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs new file mode 100644 index 000000000..f307ecc8f --- /dev/null +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -0,0 +1,52 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_int_size::*; + +#[test] +fn test_switch_manual_int_size() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualIntSize::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(4, r.chunks().len()); + + assert_eq!(17, r.chunks()[0].code); + if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkMeta(s) = r.chunks[0].body() { + assert_eq!("Stuff", s.title()); + assert_eq!("Me", s.author()); + } else { + panic!("expected enum SwitchManualIntSize_Chunk_ChunkMeta"); + } + + assert_eq!(34, r.chunks()[1].code); + if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkDir(s) = r.chunks[1].body() { + let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); + assert_eq!(strings, *s.entries()); + } else { + panic!("expected enum SwitchManualIntSize_Chunk_ChunkDir"); + } + + assert_eq!(51, r.chunks()[2].code); + if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks[2].body() { + let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; + assert_eq!(raw, *s); + } else { + panic!("expected enum Bytes"); + } + + assert_eq!(255, r.chunks()[3].code); + if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks[3].body() { + let raw : Vec = vec![]; + assert_eq!(raw, *s); + } else { + panic!("expected enum Bytes"); + } +} diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index 91e53241c..717366743 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -1,23 +1,52 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualIntSizeElse; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_int_size_else::*; #[test] fn test_switch_manual_int_size_else() { - if let Ok(r) = SwitchManualIntSizeElse::from_file("src/switch_tlv.bin") { - assert_eq!(r.chunks.len(), 4); - assert_eq!(r.chunks[0].code, 17); - assert_eq!(r.chunks[0].body.title, "Stuff"); - assert_eq!(r.chunks[0].body.author, "Me"); - assert_eq!(r.chunks[1].code, 34); - assert_eq!(r.chunks[1].body.entries, ["AAAA", "BBBB", "CCCC"]); - assert_eq!(r.chunks[2].code, 51); - assert_eq!(r.chunks[2].body.rest, vec!([0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80])); - assert_eq!(r.chunks[3].code, 255); - assert_eq!(r.chunks[3].body.rest, vec!([])); + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualIntSizeElse::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(4, r.chunks().len()); + + assert_eq!(17, r.chunks()[0].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkMeta(s) = r.chunks[0].body() { + assert_eq!("Stuff", s.title()); + assert_eq!("Me", s.author()); + } else { + panic!("expected enum SwitchManualIntSizeElse_Chunk_ChunkMeta"); + } + + assert_eq!(34, r.chunks()[1].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkDir(s) = r.chunks[1].body() { + let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); + assert_eq!(strings, *s.entries()); + } else { + panic!("expected enum SwitchManualIntSizeElse_Chunk_ChunkDir"); + } + + assert_eq!(51, r.chunks()[2].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks[2].body() { + let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; + assert_eq!(raw, *s.rest()); + } else { + panic!("expected enum SwitchManualIntSizeElse_Chunk_Dummy"); + } + + assert_eq!(255, r.chunks()[3].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks[3].body() { + let raw : Vec = vec![]; + assert_eq!(raw, *s.rest()); + } else { + panic!("expected enum SwitchManualIntSizeElse_Chunk_Dummy"); } } diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs new file mode 100644 index 000000000..d2f23846d --- /dev/null +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -0,0 +1,52 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_int_size_eos::*; + +#[test] +fn test_switch_manual_int_size_eos() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualIntSizeEos::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(4, r.chunks().len()); + + assert_eq!(17, r.chunks()[0].code()); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkMeta(s) = r.chunks[0].body().body() { + assert_eq!("Stuff", s.title()); + assert_eq!("Me", s.author()); + } else { + panic!("expected enum SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkMeta"); + } + + assert_eq!(34, r.chunks()[1].code()); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkDir(s) = r.chunks[1].body().body() { + let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); + assert_eq!(strings, *s.entries()); + } else { + panic!("expected enum SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkDir"); + } + + assert_eq!(51, r.chunks()[2].code); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks[2].body().body() { + let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; + assert_eq!(raw, *s); + } else { + panic!("expected enum Bytes"); + } + + assert_eq!(255, r.chunks()[3].code); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks[3].body().body() { + let raw : Vec = vec![]; + assert_eq!(raw, *s); + } else { + panic!("expected enum Bytes"); + } +} diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 16b2eb92e..38d15e1ef 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -1,22 +1,48 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualStr; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_str::*; #[test] fn test_switch_manual_str() { - if let Ok(r) = SwitchManualStr::from_file("src/switch_opcodes.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, "S"); - assert_eq!(r.opcodes[0].body.value, "foobar"); - assert_eq!(r.opcodes[1].code, "I"); - assert_eq!(r.opcodes[1].body.value, 66); - assert_eq!(r.opcodes[2].code, "I"); - assert_eq!(r.opcodes[2].body.value, 55); - assert_eq!(r.opcodes[3].code, "S"); - assert_eq!(r.opcodes[3].body.value, ""); + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualStr::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(4, r.opcodes().len()); + + assert_eq!("S", r.opcodes()[0].code()); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes[0].body() { + assert_eq!("foobar", s.value()); + } else { + panic!("expected enum SwitchManualStr_Opcode_Strval"); + } + + assert_eq!("I", r.opcodes()[1].code()); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes[1].body() { + assert_eq!(66, s.value()); + } else { + panic!("expected enum SwitchManualStr_Opcode_Intval"); + } + + assert_eq!("I", r.opcodes()[2].code()); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes[2].body() { + assert_eq!(55, s.value()); + } else { + panic!("expected enum SwitchManualStr_Opcode_Intval"); + } + + assert_eq!("S", r.opcodes()[3].code); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes[3].body() { + assert_eq!("", s.value()); + } else { + panic!("expected enum SwitchManualStr_Opcode_Strval"); } } diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index c27d75a23..31fb9461d 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -1,22 +1,48 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::SwitchManualStrElse; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_str_else::*; #[test] fn test_switch_manual_str_else() { - if let Ok(r) = SwitchManualStrElse::from_file("src/switch_opcodes2.bin") { - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0].code, "S"); - assert_eq!(r.opcodes[0].body.value, "foo"); - assert_eq!(r.opcodes[1].code, "X"); - assert_eq!(r.opcodes[1].body.filler, 66); - assert_eq!(r.opcodes[2].code, "Y"); - assert_eq!(r.opcodes[2].body.filler, 51966); - assert_eq!(r.opcodes[3].code, "I"); - assert_eq!(r.opcodes[3].body.value, 7); + let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualStrElse::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(4, r.opcodes().len()); + + assert_eq!("S", r.opcodes()[0].code()); + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Strval(s) = r.opcodes[0].body() { + assert_eq!("foo", s.value()); + } else { + panic!("expected enum SwitchManualStrElse_Opcode_Strval"); + } + + assert_eq!("X", r.opcodes()[1].code()); + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes[1].body() { + assert_eq!(66, s.filler()); + } else { + panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); + } + + assert_eq!("Y", r.opcodes()[2].code()); + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes[2].body() { + assert_eq!(51966, s.filler()); + } else { + panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); + } + + assert_eq!("I", r.opcodes()[3].code()); + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Intval(s) = r.opcodes[3].body() { + assert_eq!(7, s.value()); + } else { + panic!("expected enum SwitchManualStrElse_Opcode_Strval"); } } diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs index 23375a5fa..9f3b9ad81 100644 --- a/spec/rust/tests/test_term_bytes.rs +++ b/spec/rust/tests/test_term_bytes.rs @@ -1,16 +1,22 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TermBytes; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::term_bytes::*; #[test] fn test_term_bytes() { - if let Ok(r) = TermBytes::from_file("src/term_strz.bin") { - assert_eq!(r.s1, vec!([0x66, 0x6f, 0x6f])); - assert_eq!(r.s2, vec!([0x62, 0x61, 0x72])); - assert_eq!(r.s3, vec!([0x7c, 0x62, 0x61, 0x7a, 0x40])); + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TermBytes::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(*r.s1(), [0x66u8, 0x6fu8, 0x6fu8].to_vec()); + assert_eq!(*r.s2(), [0x62u8, 0x61u8, 0x72u8].to_vec()); + assert_eq!(*r.s3(), [0x7cu8, 0x62u8, 0x61u8, 0x7au8, 0x40u8].to_vec()); } diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs index c40bce5cd..0b8f4e714 100644 --- a/spec/rust/tests/test_term_strz.rs +++ b/spec/rust/tests/test_term_strz.rs @@ -1,16 +1,22 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TermStrz; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::term_strz::*; #[test] fn test_term_strz() { - if let Ok(r) = TermStrz::from_file("src/term_strz.bin") { - assert_eq!(r.s1, "foo"); - assert_eq!(r.s2, "bar"); - assert_eq!(r.s3, "|baz@"); + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TermStrz::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.s1(), "foo"); + assert_eq!(r.s2(), "bar"); + assert_eq!(r.s3(), "|baz@"); } diff --git a/spec/rust/tests/test_term_u1_val.rs b/spec/rust/tests/test_term_u1_val.rs new file mode 100644 index 000000000..64d6cfa16 --- /dev/null +++ b/spec/rust/tests/test_term_u1_val.rs @@ -0,0 +1,21 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::term_u1_val::*; + +#[test] +fn test_term_u1_val() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TermU1Val::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(*r.foo(), [0xau8, 0x0u8, 0x53u8, 0x6fu8, 0x6du8, 0x65u8, 0x20u8, 0x41u8, 0x53u8, 0x43u8, 0x49u8, 0x49u8, 0xfu8, 0x0u8].to_vec()); + assert_eq!(r.bar(), "\u{3053}\u{3093}\u{306b}"); +} diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs new file mode 100644 index 000000000..693c6324f --- /dev/null +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -0,0 +1,26 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::ts_packet_header::*; + +#[test] +fn test_ts_packet_header() { + let bytes = fs::read("../../src/ts_packet.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TsPacketHeader::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(r.sync_byte(), 71); + assert_eq!(r.transport_error_indicator(), false); + assert_eq!(r.payload_unit_start_indicator(), false); + assert_eq!(r.transport_priority(), true); + assert_eq!(r.pid(), 33); + assert_eq!(r.transport_scrambling_control(), 0); + assert_eq!(*r.adaptation_field_control(), TsPacketHeader_AdaptationFieldControlEnum::PayloadOnly); +} diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index cdc32dfe2..8434ac91c 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -1,17 +1,23 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TypeIntUnaryOp; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::type_int_unary_op::*; #[test] fn test_type_int_unary_op() { - if let Ok(r) = TypeIntUnaryOp::from_file("src/fixed_struct.bin") { - assert_eq!(r.value_s2, 16720); - assert_eq!(r.value_s8, 4706543082108963651); - assert_eq!(r.unary_s2, -16720); - assert_eq!(r.unary_s8, -4706543082108963651); + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TypeIntUnaryOp::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.value_s2(), 16720); + assert_eq!(r.value_s8(), 4706543082108963651); + assert_eq!(*r.unary_s2(&reader).unwrap(), -16720); + assert_eq!(*r.unary_s8(&reader).unwrap(), -4706543082108963651); } diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs index 6e2412116..117e10629 100644 --- a/spec/rust/tests/test_type_ternary.rs +++ b/spec/rust/tests/test_type_ternary.rs @@ -1,14 +1,20 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(dead_code)] +use std::fs; -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::TypeTernary; +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::type_ternary::*; #[test] fn test_type_ternary() { - if let Ok(r) = TypeTernary::from_file("src/term_strz.bin") { - assert_eq!(r.dif.value, 101); + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TypeTernary::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); } + assert_eq!(r.dif(&reader).unwrap().value(), 101); } diff --git a/spec/rust/tests/test_user_type.rs b/spec/rust/tests/test_user_type.rs deleted file mode 100644 index 358ec2130..000000000 --- a/spec/rust/tests/test_user_type.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::UserType; - -#[test] -fn test_user_type() { - if let Ok(r) = UserType::from_file("src/repeat_until_s4.bin") { - assert_eq!(r.one.width, 66); - assert_eq!(r.one.height, 4919); - } -} diff --git a/spec/rust/tests/test_valid_fail_inst.rs b/spec/rust/tests/test_valid_fail_inst.rs new file mode 100644 index 000000000..161d41a0e --- /dev/null +++ b/spec/rust/tests/test_valid_fail_inst.rs @@ -0,0 +1,20 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_inst::*; + +#[test] +fn test_valid_fail_inst() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailInst::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_bytes.rs b/spec/rust/tests/test_valid_fail_range_bytes.rs new file mode 100644 index 000000000..9e7e4f4ed --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_bytes.rs @@ -0,0 +1,20 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_range_bytes::*; + +#[test] +fn test_valid_fail_range_bytes() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailRangeBytes::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcBytesType)", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(CalcBytesType)"); + } +} diff --git a/spec/rust/tests/test_zlib_with_header_78.rs b/spec/rust/tests/test_zlib_with_header_78.rs deleted file mode 100644 index 8001b37bf..000000000 --- a/spec/rust/tests/test_zlib_with_header_78.rs +++ /dev/null @@ -1,14 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ZlibWithHeader78; - -#[test] -fn test_zlib_with_header_78() { - if let Ok(r) = ZlibWithHeader78::from_file("src/zlib_with_header_78.bin") { - assert_eq!(r.data, vec!([0x61, 0x20, 0x71, 0x75, 0x69, 0x63, 0x6b, 0x20, 0x62, 0x72, 0x6f, 0x77, 0x6e, 0x20, 0x66, 0x6f, 0x78, 0x20, 0x6a, 0x75, 0x6d, 0x70, 0x73, 0x20, 0x6f, 0x76, 0x65, 0x72])); - } -} From 20b8f5492df8e93156894eebddbf81721266244a Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 14:34:18 +0800 Subject: [PATCH 015/198] gitignore updated. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 1aab4ada0..5dba3e907 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,6 @@ _* spec/nim/bin # Rust compiled code, cargo and rls data +spec/rust/Cargo.lock spec/rust/target/ +spec/rust/tests/formats/ From 905f1f2aa2065c0f40ec753d46710ba0d684a185 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 14:35:42 +0800 Subject: [PATCH 016/198] rust testtranslator updated. --- .../specgenerators/RustSG.scala | 50 ++++++++----------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index a7a30a845..4f4b5fabc 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -17,36 +17,31 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def header(): Unit = { val code = - s""" - |#[cfg(test)] - |mod tests { - | use std::fs; - | - | use kaitai::*; - | use crate::formats::${spec.id}::*; - | - | #[test] - | fn test_${spec.id}() { - | let bytes = fs::read("src/${spec.data}").unwrap(); - | let mut reader = BytesReader::new(&bytes); - | let mut r = $className::default(); - | - | if let Err(err) = r.read(&mut reader, None, None) {""".stripMargin - + s"""|#![allow(dead_code)] + |use std::fs; + | + |extern crate kaitai; + |use self::kaitai::*; + |mod formats; + |use formats::${spec.id}::*; + | + |#[test] + |fn test_${spec.id}() { + | let bytes = fs::read("../../src/${spec.data}").unwrap(); + | let reader = BytesReader::new(&bytes); + | let mut r = $className::default(); + | + | if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) {""".stripMargin out.puts(code) out.inc - out.inc } override def runParseExpectError(exception: KSError): Unit = { val code = - s""" println!("err: {:?}, exception: ${exception}", err); - | } else { - | panic!("no expected exception: ${exception}"); - | } - | - |""".stripMargin - + s""" println!("expected err: {:?}, exception: ${exception}", err); + | } else { + | panic!("no expected exception: ${exception}"); + | }""".stripMargin out.puts(code) do_panic = false // out.puts("err = r.Read(s, &r, &r)") @@ -74,8 +69,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def footer(): Unit = { out.dec out.puts("}") - out.dec - out.puts("}") } override def simpleAssert(check: TestAssert): Unit = { @@ -91,11 +84,12 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def nullAssert(actual: Ast.expr): Unit = { val actStr = translateAct(actual) finish_panic() - out.puts(s"assertNull($actStr);") + out.puts(s"assert_eq!($actStr, 0);") // TODO: Figure out what's meant to happen here } override def trueArrayAssert(check: TestAssert, elType: DataType, elts: Seq[Ast.expr]): Unit = { + out.puts("trueArrayAssert $check, $elType, $elts") simpleAssert(check) // FIXME } @@ -107,5 +101,5 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( } def translateAct(x: Ast.expr) = - translator.translate(x).replace("self." + Main.INIT_OBJ_NAME, "r") + translator.translate(x).replace("self." + Main.INIT_OBJ_NAME + "()", "r") } From 38a284e301d91d04ff3b369779daf4486bbb3a99 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 27 Jul 2022 21:06:37 +0800 Subject: [PATCH 017/198] update files if formats dir were changed. --- spec/rust/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/rust/build.rs b/spec/rust/build.rs index 6c9243076..d5c28c9aa 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -28,6 +28,8 @@ fn main() { copy_new(source_path, destination_path).unwrap_or_else(|e| { println!("Unable to copy new files under test: {}", e.to_string()); }); + + println!("cargo:rerun-if-changed={}", source_path.display().to_string()); } fn remove_existing(destination_path: &Path) -> io::Result<()> { From fe40ee2f1740a749f27188da2adb432f44182576 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Wed, 27 Jul 2022 21:45:27 +0200 Subject: [PATCH 018/198] make specKsDir and formatsDir fields --- .../scala/io/kaitai/struct/testtranslator/Main.scala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala index ef81bc384..a04fd0a2f 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala @@ -1,15 +1,16 @@ package io.kaitai.struct.testtranslator import java.io.File - import _root_.io.kaitai.struct.format._ import io.kaitai.struct.Version object Main extends App { - val baseDir = ".." + var baseDir = ".." val specDir = s"$baseDir/spec" - val specKsDir = s"$baseDir/spec/ks" - val formatsDir = s"$baseDir/formats" + def specKsDir = s"$baseDir/spec/ks" + def specKsDir_=(v:String) { specKsDir = v } + def formatsDir = s"$baseDir/formats" + def formatsDir_=(v:String) { formatsDir = v } val defaultOutDir = s"$specKsDir/out" val importsDir = s"$baseDir/../formats" From 91d513d8ec7aeee6b658ed09efb0b4bb000d2943 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Wed, 27 Jul 2022 21:46:28 +0200 Subject: [PATCH 019/198] make simple enums working --- .../struct/testtranslator/specgenerators/RustSG.scala | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index a7a30a845..9238ff3a0 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -31,7 +31,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( | let mut reader = BytesReader::new(&bytes); | let mut r = $className::default(); | - | if let Err(err) = r.read(&mut reader, None, None) {""".stripMargin + | if let Err(err) = r.read(&mut reader, None, KStructUnit::parent_stack()) {""".stripMargin out.puts(code) out.inc @@ -81,9 +81,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def simpleAssert(check: TestAssert): Unit = { val actStr = translateAct(check.actual) var expStr = translator.translate(check.expected) - if (expStr.toLowerCase.startsWith("enum")) { - expStr = s"Some($expStr)" - } finish_panic() out.puts(s"assert_eq!($actStr, $expStr);") } @@ -107,5 +104,5 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( } def translateAct(x: Ast.expr) = - translator.translate(x).replace("self." + Main.INIT_OBJ_NAME, "r") + translator.translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") } From af7572877867ae090f8c0c6242a9a962ed7d2c95 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Wed, 27 Jul 2022 21:47:57 +0200 Subject: [PATCH 020/198] if source path isAbsolute() modify `baseDir` --- .../testtranslator/TestTranslator.scala | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index fcb8c5449..f0660877f 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -8,19 +8,36 @@ import io.kaitai.struct.formats.JavaKSYParser import io.kaitai.struct.problems.ProblemSeverity import io.kaitai.struct.testtranslator.Main.{CLIOptions, defaultOutDir} import io.kaitai.struct.testtranslator.specgenerators._ -import io.kaitai.struct.{ClassTypeProvider, CppRuntimeConfig} +import io.kaitai.struct.{ClassTypeProvider, CppRuntimeConfig, RuntimeConfig} + +import java.nio.file.Path class TestTranslator(options: CLIOptions) { import Main._ def run(): Unit = { + if(options.srcFiles.length == 1) { + val path = Path.of(options.srcFiles(0)); + + if (path.isAbsolute()) { + val specKs = specKsDir.split('/').drop(1).mkString("/") + val parent = path.getParent().toString().replace('\\', '/') + assert(parent.endsWith(specKs)) + baseDir = parent.replace(specKs, "") + } + } + + val exactOutDir = (options.outDir != defaultOutDir) options.srcFiles.foreach(testName => - doTestSpec(testName, options.targets, options.outDir, options.outDir != defaultOutDir) + doTestSpec(testName, options.targets, options.outDir, exactOutDir) ) } - def doTestSpec(testName: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { - Console.println(s"Translating: $testName") + def doTestSpec(ts: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { + Console.println(s"Translating: $ts") + + val path = Path.of(ts) + val testName = if(path.isAbsolute()) { path.getFileName().toString() } else { ts } val testSpec = loadTestSpec(testName) val classSpecs = loadClassSpecs(testName) @@ -31,7 +48,7 @@ class TestTranslator(options: CLIOptions) { val sg = getSG(langName, testSpec, provider) try { sg.run() - val outFile = if (exactOutDir) { s"$outDir/${sg.fileName(testName)}" } else { s"$outDir/$langName/${sg.fileName(testName)}" } + val outFile = if(exactOutDir) { s"$outDir/${sg.fileName(testName)}" } else { s"$outDir/$langName/${sg.fileName(testName)}" } Console.println(s"... generating $outFile") writeFile(outFile, sg.results) } catch { @@ -52,8 +69,9 @@ class TestTranslator(options: CLIOptions) { fw.close() } - def loadTestSpec(testName: String): TestSpec = + def loadTestSpec(testName: String): TestSpec = { TestSpec.fromFile(s"$specKsDir/$testName.kst") + } def loadClassSpecs(testName: String): ClassSpecs = { val cliConfig = CLIConfig(importPaths = Seq(importsDir)) From 6e591c3950b36f517734f841c0f977b0b25de09a Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Wed, 27 Jul 2022 21:50:46 +0200 Subject: [PATCH 021/198] edition = "2021" --- spec/rust/Cargo.lock | 89 ++++++++++++++------------------------------ spec/rust/Cargo.toml | 7 +++- 2 files changed, 33 insertions(+), 63 deletions(-) diff --git a/spec/rust/Cargo.lock b/spec/rust/Cargo.lock index 31bdaab29..f6caf4d8c 100644 --- a/spec/rust/Cargo.lock +++ b/spec/rust/Cargo.lock @@ -1,121 +1,88 @@ -[[package]] -name = "byteorder" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 [[package]] -name = "cc" -version = "1.0.9" +name = "byteorder" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] name = "encoding" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec" dependencies = [ - "encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding-index-japanese", + "encoding-index-korean", + "encoding-index-simpchinese", + "encoding-index-singlebyte", + "encoding-index-tradchinese", ] [[package]] name = "encoding-index-japanese" version = "1.20141219.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91" dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding_index_tests", ] [[package]] name = "encoding-index-korean" version = "1.20141219.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81" dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding_index_tests", ] [[package]] name = "encoding-index-simpchinese" version = "1.20141219.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7" dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding_index_tests", ] [[package]] name = "encoding-index-singlebyte" version = "1.20141219.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a" dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding_index_tests", ] [[package]] name = "encoding-index-tradchinese" version = "1.20141219.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18" dependencies = [ - "encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "encoding_index_tests", ] [[package]] name = "encoding_index_tests" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" [[package]] -name = "flate2" -version = "0.2.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "kaitai_struct" -version = "0.2.0" -source = "git+https://github.com/CWood1/kaitai_struct_rust_runtime#b5484246b52c57ad7e2cb66af7b37347289c058e" -dependencies = [ - "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "libc" -version = "0.2.40" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "miniz-sys" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" +name = "kaitai" +version = "0.1.0" dependencies = [ - "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder", + "encoding", ] [[package]] name = "rust" version = "0.1.0" dependencies = [ - "kaitai_struct 0.2.0 (git+https://github.com/CWood1/kaitai_struct_rust_runtime)", + "kaitai", ] - -[metadata] -"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc" -"checksum encoding 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "6b0d943856b990d12d3b55b359144ff341533e516d94098b1d3fc1ac666d36ec" -"checksum encoding-index-japanese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "04e8b2ff42e9a05335dbf8b5c6f7567e5591d0d916ccef4e0b1710d32a0d0c91" -"checksum encoding-index-korean 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc33fb8e6bcba213fe2f14275f0963fd16f0a02c878e3095ecfdf5bee529d81" -"checksum encoding-index-simpchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d87a7194909b9118fc707194baa434a4e3b0fb6a5a757c73c3adb07aa25031f7" -"checksum encoding-index-singlebyte 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3351d5acffb224af9ca265f435b859c7c01537c0849754d3db3fdf2bfe2ae84a" -"checksum encoding-index-tradchinese 1.20141219.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fd0e20d5688ce3cab59eb3ef3a2083a5c77bf496cb798dc6fcdb75f323890c18" -"checksum encoding_index_tests 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a246d82be1c9d791c5dfde9a2bd045fc3cbba3fa2b11ad558f27d01712f00569" -"checksum flate2 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "e6234dd4468ae5d1e2dbb06fe2b058696fdc50a339c68a393aefbf00bc81e423" -"checksum kaitai_struct 0.2.0 (git+https://github.com/CWood1/kaitai_struct_rust_runtime)" = "" -"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" -"checksum miniz-sys 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "609ce024854aeb19a0ef7567d348aaa5a746b32fb72e336df7fcc16869d7e2b4" diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index e79b56875..cf2a954b7 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -2,7 +2,10 @@ name = "rust" version = "0.1.0" authors = ["Connor Wood "] -build = "build.rs" +edition = "2021" +#build = "build.rs" +build = false [dependencies] -kaitai_struct = { git = "https://github.com/CWood1/kaitai_struct_rust_runtime" } +#kaitai_struct = { git = "https://github.com/CWood1/kaitai_struct_rust_runtime" } +kaitai = { path = "../../../kaitai_rust" } From 475e031d30b74b3b39c3e0fb291a59e457ac9594 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Wed, 27 Jul 2022 21:55:05 +0200 Subject: [PATCH 022/198] tests' list --- spec/rust/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 spec/rust/src/lib.rs diff --git a/spec/rust/src/lib.rs b/spec/rust/src/lib.rs new file mode 100644 index 000000000..bcfe959e1 --- /dev/null +++ b/spec/rust/src/lib.rs @@ -0,0 +1,5 @@ +mod formats; +mod test_enum_0; +mod test_enum_1; +mod test_enum_deep; +mod test_enum_deep_literals; From 4b635c1090090b9cbace5b50d2117cc7454b8d19 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 28 Jul 2022 15:41:28 +0800 Subject: [PATCH 023/198] disable useless warnings for generated code. --- spec/rust/build.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/rust/build.rs b/spec/rust/build.rs index d5c28c9aa..3870dfebf 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -47,6 +47,9 @@ fn remove_existing(destination_path: &Path) -> io::Result<()> { fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { let mut librs = fs::File::create(destination_path.join("mod.rs"))?; + write!(librs, "#![allow(unused_parens)]\n")?; + write!(librs, "#![allow(dead_code)]\n")?; + for entry in fs::read_dir(source_path)? { let entry = entry?; let path = entry.path(); From a9703e52b285b5a913a980b272b85fc172f30216 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 28 Jul 2022 15:43:14 +0800 Subject: [PATCH 024/198] disabling of warnings moved to mod.rs --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 4f4b5fabc..954c9350c 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -17,8 +17,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def header(): Unit = { val code = - s"""|#![allow(dead_code)] - |use std::fs; + s"""|use std::fs; | |extern crate kaitai; |use self::kaitai::*; From e2f580026bb34f2dc4b0ab991e68827de0a10fb6 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 28 Jul 2022 16:05:44 +0800 Subject: [PATCH 025/198] formatting issue fixed. --- .../struct/testtranslator/specgenerators/RustSG.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 954c9350c..c3fde35dd 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -38,9 +38,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def runParseExpectError(exception: KSError): Unit = { val code = s""" println!("expected err: {:?}, exception: ${exception}", err); - | } else { - | panic!("no expected exception: ${exception}"); - | }""".stripMargin + | } else { + | panic!("no expected exception: ${exception}"); + | }""".stripMargin out.puts(code) do_panic = false // out.puts("err = r.Read(s, &r, &r)") From 4461d38a54ca828d34724b86977f0c00751a8b27 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 28 Jul 2022 16:07:03 +0800 Subject: [PATCH 026/198] valid_* tests added. --- formats_rust/switch_multi_bool_ops.ksy | 23 +++++++++ formats_rust/valid_fail_anyof_int.ksy | 15 ++++++ formats_rust/valid_fail_contents.ksy | 5 ++ formats_rust/valid_fail_eq_bytes.ksy | 6 +++ formats_rust/valid_fail_eq_int.ksy | 6 +++ formats_rust/valid_fail_eq_str.ksy | 8 +++ formats_rust/valid_fail_expr.ksy | 11 ++++ formats_rust/valid_fail_max_int.ksy | 7 +++ formats_rust/valid_fail_min_int.ksy | 7 +++ formats_rust/valid_fail_range_float.ksy | 8 +++ formats_rust/valid_fail_range_int.ksy | 8 +++ formats_rust/valid_fail_range_str.ksy | 11 ++++ formats_rust/valid_long.ksy | 51 +++++++++++++++++++ formats_rust/valid_not_parsed_if.ksy | 11 ++++ formats_rust/valid_optional_id.ksy | 10 ++++ formats_rust/valid_short.ksy | 40 +++++++++++++++ formats_rust/valid_switch.ksy | 13 +++++ spec/rust/tests/test_switch_multi_bool_ops.rs | 29 +++++++++++ spec/rust/tests/test_valid_fail_anyof_int.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_contents.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_eq_bytes.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_eq_int.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_eq_str.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_expr.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_inst.rs | 3 +- spec/rust/tests/test_valid_fail_max_int.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_min_int.rs | 21 ++++++++ .../rust/tests/test_valid_fail_range_bytes.rs | 3 +- .../rust/tests/test_valid_fail_range_float.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_range_int.rs | 21 ++++++++ spec/rust/tests/test_valid_fail_range_str.rs | 21 ++++++++ spec/rust/tests/test_valid_long.rs | 18 +++++++ spec/rust/tests/test_valid_not_parsed_if.rs | 18 +++++++ spec/rust/tests/test_valid_optional_id.rs | 18 +++++++ spec/rust/tests/test_valid_short.rs | 18 +++++++ spec/rust/tests/test_valid_switch.rs | 18 +++++++ 36 files changed, 594 insertions(+), 2 deletions(-) create mode 100644 formats_rust/switch_multi_bool_ops.ksy create mode 100644 formats_rust/valid_fail_anyof_int.ksy create mode 100644 formats_rust/valid_fail_contents.ksy create mode 100644 formats_rust/valid_fail_eq_bytes.ksy create mode 100644 formats_rust/valid_fail_eq_int.ksy create mode 100644 formats_rust/valid_fail_eq_str.ksy create mode 100644 formats_rust/valid_fail_expr.ksy create mode 100644 formats_rust/valid_fail_max_int.ksy create mode 100644 formats_rust/valid_fail_min_int.ksy create mode 100644 formats_rust/valid_fail_range_float.ksy create mode 100644 formats_rust/valid_fail_range_int.ksy create mode 100644 formats_rust/valid_fail_range_str.ksy create mode 100644 formats_rust/valid_long.ksy create mode 100644 formats_rust/valid_not_parsed_if.ksy create mode 100644 formats_rust/valid_optional_id.ksy create mode 100644 formats_rust/valid_short.ksy create mode 100644 formats_rust/valid_switch.ksy create mode 100644 spec/rust/tests/test_switch_multi_bool_ops.rs create mode 100644 spec/rust/tests/test_valid_fail_anyof_int.rs create mode 100644 spec/rust/tests/test_valid_fail_contents.rs create mode 100644 spec/rust/tests/test_valid_fail_eq_bytes.rs create mode 100644 spec/rust/tests/test_valid_fail_eq_int.rs create mode 100644 spec/rust/tests/test_valid_fail_eq_str.rs create mode 100644 spec/rust/tests/test_valid_fail_expr.rs create mode 100644 spec/rust/tests/test_valid_fail_max_int.rs create mode 100644 spec/rust/tests/test_valid_fail_min_int.rs create mode 100644 spec/rust/tests/test_valid_fail_range_float.rs create mode 100644 spec/rust/tests/test_valid_fail_range_int.rs create mode 100644 spec/rust/tests/test_valid_fail_range_str.rs create mode 100644 spec/rust/tests/test_valid_long.rs create mode 100644 spec/rust/tests/test_valid_not_parsed_if.rs create mode 100644 spec/rust/tests/test_valid_optional_id.rs create mode 100644 spec/rust/tests/test_valid_short.rs create mode 100644 spec/rust/tests/test_valid_switch.rs diff --git a/formats_rust/switch_multi_bool_ops.ksy b/formats_rust/switch_multi_bool_ops.ksy new file mode 100644 index 000000000..38ffbb448 --- /dev/null +++ b/formats_rust/switch_multi_bool_ops.ksy @@ -0,0 +1,23 @@ +# https://github.com/kaitai-io/kaitai_struct_compiler/issues/39 +meta: + id: switch_multi_bool_ops + endian: le +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: u1 + - id: body + type: + switch-on: "( (code > 0) and + (code <= 8) and + ((code != 10) ? true : false)) ? code : 0" + cases: + 1: u1 + 2: u2 + 4: u4 + 8: u8 diff --git a/formats_rust/valid_fail_anyof_int.ksy b/formats_rust/valid_fail_anyof_int.ksy new file mode 100644 index 000000000..645007dec --- /dev/null +++ b/formats_rust/valid_fail_anyof_int.ksy @@ -0,0 +1,15 @@ +meta: + id: valid_fail_anyof_int +seq: + - id: foo + type: u1 + valid: # there is actually 0x50 in the file + any-of: + - 5 + - 6 + - 7 + - 8 + - 10 + - 11 + - 12 + - 47 diff --git a/formats_rust/valid_fail_contents.ksy b/formats_rust/valid_fail_contents.ksy new file mode 100644 index 000000000..e06ce0f02 --- /dev/null +++ b/formats_rust/valid_fail_contents.ksy @@ -0,0 +1,5 @@ +meta: + id: valid_fail_contents +seq: + - id: foo + contents: [0x51, 0x41] # there is actually [0x50, 0x41] in the file diff --git a/formats_rust/valid_fail_eq_bytes.ksy b/formats_rust/valid_fail_eq_bytes.ksy new file mode 100644 index 000000000..9582dcd30 --- /dev/null +++ b/formats_rust/valid_fail_eq_bytes.ksy @@ -0,0 +1,6 @@ +meta: + id: valid_fail_eq_bytes +seq: + - id: foo + size: 2 + valid: '[0x51, 0x41]' # there is actually [0x50, 0x41] in the file diff --git a/formats_rust/valid_fail_eq_int.ksy b/formats_rust/valid_fail_eq_int.ksy new file mode 100644 index 000000000..924e6f5b1 --- /dev/null +++ b/formats_rust/valid_fail_eq_int.ksy @@ -0,0 +1,6 @@ +meta: + id: valid_fail_eq_int +seq: + - id: foo + type: u1 + valid: 123 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_eq_str.ksy b/formats_rust/valid_fail_eq_str.ksy new file mode 100644 index 000000000..50a72e9cc --- /dev/null +++ b/formats_rust/valid_fail_eq_str.ksy @@ -0,0 +1,8 @@ +meta: + id: valid_fail_eq_str + encoding: ASCII +seq: + - id: foo + size: 4 + type: str + valid: '"BACK"' # there is actually "PACK" in the file diff --git a/formats_rust/valid_fail_expr.ksy b/formats_rust/valid_fail_expr.ksy new file mode 100644 index 000000000..444eb0795 --- /dev/null +++ b/formats_rust/valid_fail_expr.ksy @@ -0,0 +1,11 @@ +meta: + id: valid_fail_expr +seq: + - id: foo + type: u1 + valid: # should pass + expr: _ == 1 + - id: bar + type: s2le + valid: # there's actually -190 in the file + expr: _ < -190 or _ > -190 diff --git a/formats_rust/valid_fail_max_int.ksy b/formats_rust/valid_fail_max_int.ksy new file mode 100644 index 000000000..7ba628d22 --- /dev/null +++ b/formats_rust/valid_fail_max_int.ksy @@ -0,0 +1,7 @@ +meta: + id: valid_fail_max_int +seq: + - id: foo + type: u1 + valid: + max: 12 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_min_int.ksy b/formats_rust/valid_fail_min_int.ksy new file mode 100644 index 000000000..bafc45595 --- /dev/null +++ b/formats_rust/valid_fail_min_int.ksy @@ -0,0 +1,7 @@ +meta: + id: valid_fail_min_int +seq: + - id: foo + type: u1 + valid: + min: 123 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_range_float.ksy b/formats_rust/valid_fail_range_float.ksy new file mode 100644 index 000000000..f058db5b6 --- /dev/null +++ b/formats_rust/valid_fail_range_float.ksy @@ -0,0 +1,8 @@ +meta: + id: valid_fail_range_float +seq: + - id: foo + type: f4le + valid: + min: 0.2 + max: 0.4 # there is actually 0.5 in the file diff --git a/formats_rust/valid_fail_range_int.ksy b/formats_rust/valid_fail_range_int.ksy new file mode 100644 index 000000000..71dd2dafc --- /dev/null +++ b/formats_rust/valid_fail_range_int.ksy @@ -0,0 +1,8 @@ +meta: + id: valid_fail_range_int +seq: + - id: foo + type: u1 + valid: + min: 5 + max: 10 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_range_str.ksy b/formats_rust/valid_fail_range_str.ksy new file mode 100644 index 000000000..755f23f99 --- /dev/null +++ b/formats_rust/valid_fail_range_str.ksy @@ -0,0 +1,11 @@ +meta: + id: valid_fail_range_str + encoding: ASCII +seq: + - id: foo + size: 2 + type: str + # there is actually [80, 65] ("PA") in the file + valid: + min: '"P"' # [80] + max: '"P1"' # [80, 49] diff --git a/formats_rust/valid_long.ksy b/formats_rust/valid_long.ksy new file mode 100644 index 000000000..3a328a61f --- /dev/null +++ b/formats_rust/valid_long.ksy @@ -0,0 +1,51 @@ +meta: + id: valid_long + encoding: utf-8 + endian: le +seq: + - id: magic1 + size: 6 + valid: + eq: '[0x50, 0x41, 0x43, 0x4b, 0x2d, 0x31]' + - id: uint8 + type: u1 + valid: + eq: 255 + - id: sint8 + type: s1 + valid: + eq: -1 + - id: magic_uint + type: str + size: 10 + valid: + eq: '"PACK-U-DEF"' + - id: uint16 + type: u2 + valid: + eq: 65535 + - id: uint32 + type: u4 + valid: + eq: 4294967295 + - id: uint64 + type: u8 + valid: + eq: 18446744073709551615 + - id: magic_sint + type: str + size: 10 + valid: + eq: '"PACK-S-DEF"' + - id: sint16 + type: s2 + valid: + eq: -1 + - id: sint32 + type: s4 + valid: + eq: -1 + - id: sint64 + type: s8 + valid: + eq: -1 diff --git a/formats_rust/valid_not_parsed_if.ksy b/formats_rust/valid_not_parsed_if.ksy new file mode 100644 index 000000000..f693e7018 --- /dev/null +++ b/formats_rust/valid_not_parsed_if.ksy @@ -0,0 +1,11 @@ +meta: + id: valid_not_parsed_if +seq: + - id: not_parsed + if: false + type: u1 + valid: 42 + - id: parsed + if: true + type: u1 + valid: 0x50 diff --git a/formats_rust/valid_optional_id.ksy b/formats_rust/valid_optional_id.ksy new file mode 100644 index 000000000..0751358a5 --- /dev/null +++ b/formats_rust/valid_optional_id.ksy @@ -0,0 +1,10 @@ +meta: + id: valid_optional_id +seq: + - contents: 'PACK-1' + - type: u1 + valid: + eq: 0xff + - type: s1 + valid: + expr: _ == -1 diff --git a/formats_rust/valid_short.ksy b/formats_rust/valid_short.ksy new file mode 100644 index 000000000..259284ad6 --- /dev/null +++ b/formats_rust/valid_short.ksy @@ -0,0 +1,40 @@ +meta: + id: valid_short + encoding: utf-8 + endian: le +seq: + - id: magic1 + size: 6 + valid: '[0x50, 0x41, 0x43, 0x4b, 0x2d, 0x31]' + - id: uint8 + type: u1 + valid: 255 + - id: sint8 + type: s1 + valid: -1 + - id: magic_uint + type: str + size: 10 + valid: '"PACK-U-DEF"' + - id: uint16 + type: u2 + valid: 65535 + - id: uint32 + type: u4 + valid: 4294967295 + - id: uint64 + type: u8 + valid: 18446744073709551615 + - id: magic_sint + type: str + size: 10 + valid: '"PACK-S-DEF"' + - id: sint16 + type: s2 + valid: -1 + - id: sint32 + type: s4 + valid: -1 + - id: sint64 + type: s8 + valid: -1 diff --git a/formats_rust/valid_switch.ksy b/formats_rust/valid_switch.ksy new file mode 100644 index 000000000..c17c02542 --- /dev/null +++ b/formats_rust/valid_switch.ksy @@ -0,0 +1,13 @@ +meta: + id: valid_switch +seq: + - id: a + type: u1 + valid: 0x50 + - id: b + type: + switch-on: a + cases: + 0x50: u2le + _: u2be + valid: 0x4341 diff --git a/spec/rust/tests/test_switch_multi_bool_ops.rs b/spec/rust/tests/test_switch_multi_bool_ops.rs new file mode 100644 index 000000000..fded52737 --- /dev/null +++ b/spec/rust/tests/test_switch_multi_bool_ops.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_multi_bool_ops::*; + +#[test] +fn test_switch_multi_bool_ops() { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchMultiBoolOps::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } + assert_eq!(r.opcodes.len(), 4); + assert_eq!(r.opcodes[0 as usize].code(), 1); + assert_eq!(r.opcodes[0 as usize].body(), 7); + assert_eq!(r.opcodes[1 as usize].code(), 2); + assert_eq!(r.opcodes[1 as usize].body(), 16448); + assert_eq!(r.opcodes[2 as usize].code(), 4); + assert_eq!(r.opcodes[2 as usize].body(), 4919); + assert_eq!(r.opcodes[3 as usize].code(), 8); + assert_eq!(r.opcodes[3 as usize].body(), 4919); +} diff --git a/spec/rust/tests/test_valid_fail_anyof_int.rs b/spec/rust/tests/test_valid_fail_anyof_int.rs new file mode 100644 index 000000000..84a5bfb5b --- /dev/null +++ b/spec/rust/tests/test_valid_fail_anyof_int.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_anyof_int::*; + +#[test] +fn test_valid_fail_anyof_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailAnyofInt::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationNotAnyOfError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationNotAnyOfError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_contents.rs b/spec/rust/tests/test_valid_fail_contents.rs new file mode 100644 index 000000000..8ff038656 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_contents.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_contents::*; + +#[test] +fn test_valid_fail_contents() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailContents::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); + } else { + panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); + } +} diff --git a/spec/rust/tests/test_valid_fail_eq_bytes.rs b/spec/rust/tests/test_valid_fail_eq_bytes.rs new file mode 100644 index 000000000..c462ad311 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_eq_bytes.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_eq_bytes::*; + +#[test] +fn test_valid_fail_eq_bytes() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailEqBytes::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); + } else { + panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); + } +} diff --git a/spec/rust/tests/test_valid_fail_eq_int.rs b/spec/rust/tests/test_valid_fail_eq_int.rs new file mode 100644 index 000000000..089fc9445 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_eq_int.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_eq_int::*; + +#[test] +fn test_valid_fail_eq_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailEqInt::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_eq_str.rs b/spec/rust/tests/test_valid_fail_eq_str.rs new file mode 100644 index 000000000..65f5c40d2 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_eq_str.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_eq_str::*; + +#[test] +fn test_valid_fail_eq_str() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailEqStr::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationNotEqualError(CalcStrType)", err); + } else { + panic!("no expected exception: ValidationNotEqualError(CalcStrType)"); + } +} diff --git a/spec/rust/tests/test_valid_fail_expr.rs b/spec/rust/tests/test_valid_fail_expr.rs new file mode 100644 index 000000000..80228b102 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_expr.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_expr::*; + +#[test] +fn test_valid_fail_expr() { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailExpr::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationExprError(IntMultiType(true,Width2,None))", err); + } else { + panic!("no expected exception: ValidationExprError(IntMultiType(true,Width2,None))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_inst.rs b/spec/rust/tests/test_valid_fail_inst.rs index 161d41a0e..302e691ca 100644 --- a/spec/rust/tests/test_valid_fail_inst.rs +++ b/spec/rust/tests/test_valid_fail_inst.rs @@ -1,4 +1,5 @@ -#![allow(dead_code)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; diff --git a/spec/rust/tests/test_valid_fail_max_int.rs b/spec/rust/tests/test_valid_fail_max_int.rs new file mode 100644 index 000000000..544317f62 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_max_int.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_max_int::*; + +#[test] +fn test_valid_fail_max_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailMaxInt::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_min_int.rs b/spec/rust/tests/test_valid_fail_min_int.rs new file mode 100644 index 000000000..a6d98b7a1 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_min_int.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_min_int::*; + +#[test] +fn test_valid_fail_min_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailMinInt::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationLessThanError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationLessThanError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_bytes.rs b/spec/rust/tests/test_valid_fail_range_bytes.rs index 9e7e4f4ed..b38b9939d 100644 --- a/spec/rust/tests/test_valid_fail_range_bytes.rs +++ b/spec/rust/tests/test_valid_fail_range_bytes.rs @@ -1,4 +1,5 @@ -#![allow(dead_code)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; diff --git a/spec/rust/tests/test_valid_fail_range_float.rs b/spec/rust/tests/test_valid_fail_range_float.rs new file mode 100644 index 000000000..2f41fb4e7 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_float.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_range_float::*; + +#[test] +fn test_valid_fail_range_float() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailRangeFloat::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationGreaterThanError(FloatMultiType(Width4,None))", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(FloatMultiType(Width4,None))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_int.rs b/spec/rust/tests/test_valid_fail_range_int.rs new file mode 100644 index 000000000..448265c7c --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_int.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_range_int::*; + +#[test] +fn test_valid_fail_range_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailRangeInt::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_str.rs b/spec/rust/tests/test_valid_fail_range_str.rs new file mode 100644 index 000000000..278119a6c --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_str.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_fail_range_str::*; + +#[test] +fn test_valid_fail_range_str() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidFailRangeStr::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcStrType)", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(CalcStrType)"); + } +} diff --git a/spec/rust/tests/test_valid_long.rs b/spec/rust/tests/test_valid_long.rs new file mode 100644 index 000000000..ca823d3b3 --- /dev/null +++ b/spec/rust/tests/test_valid_long.rs @@ -0,0 +1,18 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_long::*; + +#[test] +fn test_valid_long() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidLong::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } +} diff --git a/spec/rust/tests/test_valid_not_parsed_if.rs b/spec/rust/tests/test_valid_not_parsed_if.rs new file mode 100644 index 000000000..1c7c907e2 --- /dev/null +++ b/spec/rust/tests/test_valid_not_parsed_if.rs @@ -0,0 +1,18 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_not_parsed_if::*; + +#[test] +fn test_valid_not_parsed_if() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidNotParsedIf::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } +} diff --git a/spec/rust/tests/test_valid_optional_id.rs b/spec/rust/tests/test_valid_optional_id.rs new file mode 100644 index 000000000..0f12ddbff --- /dev/null +++ b/spec/rust/tests/test_valid_optional_id.rs @@ -0,0 +1,18 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_optional_id::*; + +#[test] +fn test_valid_optional_id() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidOptionalId::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } +} diff --git a/spec/rust/tests/test_valid_short.rs b/spec/rust/tests/test_valid_short.rs new file mode 100644 index 000000000..907d75f84 --- /dev/null +++ b/spec/rust/tests/test_valid_short.rs @@ -0,0 +1,18 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_short::*; + +#[test] +fn test_valid_short() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidShort::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } +} diff --git a/spec/rust/tests/test_valid_switch.rs b/spec/rust/tests/test_valid_switch.rs new file mode 100644 index 000000000..4879118e6 --- /dev/null +++ b/spec/rust/tests/test_valid_switch.rs @@ -0,0 +1,18 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::valid_switch::*; + +#[test] +fn test_valid_switch() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ValidSwitch::default(); + + if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + + panic!("{:?}", err); + } +} From ee619c9285c9d1fd3a221ca3a20709813e8b2bcd Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 28 Jul 2022 17:08:12 +0800 Subject: [PATCH 027/198] changes reverted. --- spec/rust/Cargo.toml | 3 +-- spec/rust/src/lib.rs | 6 +----- .../struct/testtranslator/specgenerators/RustSG.scala | 3 ++- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index d1311420a..ac81dd53d 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -3,8 +3,7 @@ name = "rust" version = "0.1.0" authors = ["Connor Wood "] edition = "2021" -#build = "build.rs" -build = false +build = "build.rs" [dependencies] kaitai = { path = "../../../runtime/rust" } diff --git a/spec/rust/src/lib.rs b/spec/rust/src/lib.rs index 9377e518e..8b1a39374 100644 --- a/spec/rust/src/lib.rs +++ b/spec/rust/src/lib.rs @@ -1,5 +1 @@ -mod formats; -mod test_enum_0; -mod test_enum_1; -mod test_enum_deep; -//mod test_enum_deep_literals; +// empty diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index db710278f..bef6abfb6 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -21,7 +21,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( | |extern crate kaitai; |use self::kaitai::*; - |use crate::formats::${spec.id}::*; + |mod formats; + |use formats::${spec.id}::*; | |#[test] |fn test_${spec.id}() { From d3a920bca9c4d9167825de60f4f39a0d0d36c709 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Mon, 1 Aug 2022 23:53:36 +0200 Subject: [PATCH 028/198] not verbose to see exceptions --- build-rust-formats | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/build-rust-formats b/build-rust-formats index eda59a1b9..fe23874e7 100755 --- a/build-rust-formats +++ b/build-rust-formats @@ -7,7 +7,8 @@ FORMATS_COMPILED_DIR=$FORMATS_COMPILED_DIR/rust rm -rf "$FORMATS_COMPILED_DIR" mkdir -p "$FORMATS_COMPILED_DIR" "$COMPILER_DIR/jvm/target/universal/stage/bin/kaitai-struct-compiler" -- \ - --verbose all -t rust -d "$FORMATS_COMPILED_DIR" \ + -t rust -d "$FORMATS_COMPILED_DIR" \ + --ksc-exceptions \ --import-path "$FORMATS_REPO_DIR" \ --import-path "$FORMATS_KSY_DIR/ks_path" \ --java-package io.kaitai.struct.testformats \ From 1155e107f02d4ee9653d57ca2262f0f3569444df Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Mon, 1 Aug 2022 23:55:15 +0200 Subject: [PATCH 029/198] ./spec_kst_to_all -f ../$EXIST_TESTS_DIR ... --- build-rust-tests | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/build-rust-tests b/build-rust-tests index 705142c5a..036d3ea69 100755 --- a/build-rust-tests +++ b/build-rust-tests @@ -52,10 +52,7 @@ else echo generating tests for $LANG: echo $FORMATS_FILES - ./spec_kst_to_all -t $LANG $FORMATS_FILES - - mv "$KS_DIR/out/$LANG"/* "$EXIST_TESTS_DIR" - rm -rf spec/ks/out + ./spec_kst_to_all -f ../$EXIST_TESTS_DIR -t $LANG $FORMATS_FILES fi # check for manual tests From a5327063e5f0af5741437cf7dd51ce84db555757 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Tue, 2 Aug 2022 00:00:40 +0200 Subject: [PATCH 030/198] some enums --- formats_rust/enum_0.ksy | 15 +++++++++++++++ formats_rust/enum_1.ksy | 26 ++++++++++++++++++++++++++ formats_rust/enum_deep.ksy | 24 ++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 formats_rust/enum_0.ksy create mode 100644 formats_rust/enum_1.ksy create mode 100644 formats_rust/enum_deep.ksy diff --git a/formats_rust/enum_0.ksy b/formats_rust/enum_0.ksy new file mode 100644 index 000000000..8f9162d57 --- /dev/null +++ b/formats_rust/enum_0.ksy @@ -0,0 +1,15 @@ +meta: + id: enum_0 + endian: le +seq: + - id: pet_1 + type: u4 + enum: animal + - id: pet_2 + type: u4 + enum: animal +enums: + animal: + 4: dog + 7: cat + 12: chicken diff --git a/formats_rust/enum_1.ksy b/formats_rust/enum_1.ksy new file mode 100644 index 000000000..cce503952 --- /dev/null +++ b/formats_rust/enum_1.ksy @@ -0,0 +1,26 @@ +# Enum declared in top-level type, used in subtype +meta: + id: enum_1 + endian: le +seq: + - id: main + type: main_obj +types: + main_obj: + seq: + - id: submain + type: submain_obj + types: + submain_obj: + seq: + - id: pet_1 + type: u4 + enum: animal + - id: pet_2 + type: u4 + enum: animal + enums: + animal: + 4: dog + 7: cat + 12: chicken diff --git a/formats_rust/enum_deep.ksy b/formats_rust/enum_deep.ksy new file mode 100644 index 000000000..29503ca91 --- /dev/null +++ b/formats_rust/enum_deep.ksy @@ -0,0 +1,24 @@ +meta: + id: enum_deep + endian: le +seq: + - id: pet_1 + type: u4 + enum: container1::animal + - id: pet_2 + type: u4 + enum: container1::container2::animal +types: + container1: + enums: + animal: + 4: dog + 7: cat + 12: chicken + types: + container2: + enums: + animal: + 4: canary + 7: turtle + 12: hare From 6e78944ad085f9e87b8de791e51b5399450915aa Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 2 Aug 2022 15:59:14 +0800 Subject: [PATCH 031/198] handle only '*.ksy' files. --- build-rust-tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-rust-tests b/build-rust-tests index 036d3ea69..f378b5350 100755 --- a/build-rust-tests +++ b/build-rust-tests @@ -25,7 +25,7 @@ popd FORMATS= FORMATS_ONLY_RUST= KEEPING_TESTS= -for fn in $FORMATS_DIR/*; do +for fn in $FORMATS_DIR/*.ksy; do f=$(basename -- ${fn%%.*}) # regenerate tests only if there no such test exist From f3147a4d29d8716f0c12b3909dbb8c6de1f811ff Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 2 Aug 2022 16:03:20 +0800 Subject: [PATCH 032/198] new test expr_2 added. --- formats_rust/expr_2.ksy | 57 ++++++++++++++++++++++++++++++++++ spec/rust/tests/test_expr_2.rs | 37 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 formats_rust/expr_2.ksy create mode 100644 spec/rust/tests/test_expr_2.rs diff --git a/formats_rust/expr_2.ksy b/formats_rust/expr_2.ksy new file mode 100644 index 000000000..1158b346d --- /dev/null +++ b/formats_rust/expr_2.ksy @@ -0,0 +1,57 @@ +meta: + id: expr_2 + endian: le +seq: + - id: str1 + type: mod_str + - id: str2 + type: mod_str +types: + mod_str: + seq: + - id: len_orig + type: u2 + - id: str + type: str + size: len_mod + encoding: UTF-8 + - id: rest + type: tuple + size: 3 + instances: + len_mod: + value: len_orig - 3 + char5: + pos: 5 + type: str + size: 1 + encoding: ASCII + tuple5: + pos: 5 + type: tuple + tuple: + seq: + - id: byte0 + type: u1 + - id: byte1 + type: u1 + - id: byte2 + type: u1 + instances: + avg: + value: (byte1 + byte2) / 2 +instances: + str1_len: + value: str1.str.length + str1_len_mod: + value: str1.len_mod + str1_byte1: + value: str1.rest.byte1 + str1_avg: + value: str1.rest.avg + str1_char5: + value: str1.char5 + str1_tuple5: + value: str1.tuple5 + str2_tuple5: + value: str2.tuple5 diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs new file mode 100644 index 000000000..abab7ba34 --- /dev/null +++ b/spec/rust/tests/test_expr_2.rs @@ -0,0 +1,37 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_2::*; + +#[test] +fn test_expr_2() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = Expr2::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(r.str1().len_orig(), 10); + assert_eq!(r.str1().len_mod(&reader).unwrap(), 7); + assert_eq!(r.str1().str, "Some AS"); + assert_eq!(r.str1_len(&reader).unwrap(), 7); + assert_eq!(r.str1_len_mod(&reader).unwrap(), 7); + assert_eq!(r.str1_byte1(&reader).unwrap(), 73); + assert_eq!(r.str1_avg(&reader).unwrap(), 73); + assert_eq!(r.str1_char5(&reader).unwrap(), "e"); + assert_eq!(r.str1_tuple5(&reader).unwrap().byte0, 101); + assert_eq!(r.str1_tuple5(&reader).unwrap().byte0, 101); + assert_eq!(r.str1_tuple5(&reader).unwrap().byte1, 32); + assert_eq!(r.str1_tuple5(&reader).unwrap().byte2, 65); + assert_eq!(r.str1_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); + assert_eq!(r.str2_tuple5(&reader).unwrap().byte0, 101); + assert_eq!(r.str2_tuple5(&reader).unwrap().byte1, 32); + assert_eq!(r.str2_tuple5(&reader).unwrap().byte2, 65); + assert_eq!(r.str2_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); +} From 48002dc6a9dc0331cb3c515a809e0215eb66b8f7 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 2 Aug 2022 16:04:43 +0800 Subject: [PATCH 033/198] parent as option updated. --- spec/rust/tests/manual_read_bytes.rs | 2 +- spec/rust/tests/manual_str_literals.rs | 2 +- spec/rust/tests/manual_str_repeat.rs | 2 +- spec/rust/tests/manual_switch_cast.rs | 2 +- spec/rust/tests/manual_switch_cast_parent.rs | 2 +- spec/rust/tests/manual_test_parent.rs | 2 +- spec/rust/tests/test_expr_0.rs | 4 ++-- spec/rust/tests/test_expr_1.rs | 6 +++--- spec/rust/tests/test_fixed_contents.rs | 2 +- spec/rust/tests/test_process_coerce_bytes.rs | 2 +- spec/rust/tests/test_process_rotate.rs | 2 +- spec/rust/tests/test_process_to_user.rs | 2 +- spec/rust/tests/test_process_xor4_const.rs | 2 +- spec/rust/tests/test_process_xor4_value.rs | 2 +- spec/rust/tests/test_process_xor_const.rs | 2 +- spec/rust/tests/test_process_xor_value.rs | 2 +- spec/rust/tests/test_str_encodings.rs | 2 +- spec/rust/tests/test_str_encodings_default.rs | 2 +- spec/rust/tests/test_str_encodings_utf16.rs | 2 +- spec/rust/tests/test_str_eos.rs | 2 +- spec/rust/tests/test_str_literals2.rs | 2 +- spec/rust/tests/test_str_pad_term.rs | 2 +- spec/rust/tests/test_str_pad_term_empty.rs | 2 +- spec/rust/tests/test_switch_bytearray.rs | 2 +- spec/rust/tests/test_switch_else_only.rs | 2 +- spec/rust/tests/test_switch_integers.rs | 2 +- spec/rust/tests/test_switch_integers2.rs | 2 +- spec/rust/tests/test_switch_manual_int.rs | 2 +- spec/rust/tests/test_switch_manual_int_else.rs | 2 +- spec/rust/tests/test_switch_manual_int_size.rs | 2 +- spec/rust/tests/test_switch_manual_int_size_else.rs | 2 +- spec/rust/tests/test_switch_manual_int_size_eos.rs | 2 +- spec/rust/tests/test_switch_manual_str.rs | 2 +- spec/rust/tests/test_switch_manual_str_else.rs | 2 +- spec/rust/tests/test_switch_multi_bool_ops.rs | 2 +- spec/rust/tests/test_term_bytes.rs | 2 +- spec/rust/tests/test_term_strz.rs | 2 +- spec/rust/tests/test_term_u1_val.rs | 2 +- spec/rust/tests/test_ts_packet_header.rs | 2 +- spec/rust/tests/test_type_int_unary_op.rs | 6 +++--- spec/rust/tests/test_type_ternary.rs | 2 +- spec/rust/tests/test_valid_fail_anyof_int.rs | 2 +- spec/rust/tests/test_valid_fail_contents.rs | 2 +- spec/rust/tests/test_valid_fail_eq_bytes.rs | 2 +- spec/rust/tests/test_valid_fail_eq_int.rs | 2 +- spec/rust/tests/test_valid_fail_eq_str.rs | 2 +- spec/rust/tests/test_valid_fail_expr.rs | 2 +- spec/rust/tests/test_valid_fail_inst.rs | 2 +- spec/rust/tests/test_valid_fail_max_int.rs | 2 +- spec/rust/tests/test_valid_fail_min_int.rs | 2 +- spec/rust/tests/test_valid_fail_range_bytes.rs | 2 +- spec/rust/tests/test_valid_fail_range_float.rs | 2 +- spec/rust/tests/test_valid_fail_range_int.rs | 2 +- spec/rust/tests/test_valid_fail_range_str.rs | 2 +- spec/rust/tests/test_valid_long.rs | 2 +- spec/rust/tests/test_valid_not_parsed_if.rs | 2 +- spec/rust/tests/test_valid_optional_id.rs | 2 +- spec/rust/tests/test_valid_short.rs | 2 +- spec/rust/tests/test_valid_switch.rs | 2 +- .../struct/testtranslator/specgenerators/RustSG.scala | 2 +- 60 files changed, 65 insertions(+), 65 deletions(-) diff --git a/spec/rust/tests/manual_read_bytes.rs b/spec/rust/tests/manual_read_bytes.rs index 2ce7690b1..a0dac3fa3 100644 --- a/spec/rust/tests/manual_read_bytes.rs +++ b/spec/rust/tests/manual_read_bytes.rs @@ -13,7 +13,7 @@ fn basic_parse() { let mut r = ReadBytes::default(); { - let res = r.read(&reader, None, KStructUnit::parent_stack()); + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); println!("{:?}", res); assert!(res.is_ok()); } diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/manual_str_literals.rs index 523396b4d..b012e4d8b 100644 --- a/spec/rust/tests/manual_str_literals.rs +++ b/spec/rust/tests/manual_str_literals.rs @@ -13,7 +13,7 @@ fn basic_parse() { let mut r = StrLiterals::default(); { - let res = r.read(&reader, None, KStructUnit::parent_stack()); + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); println!("{:?}", res); assert!(res.is_ok()); } diff --git a/spec/rust/tests/manual_str_repeat.rs b/spec/rust/tests/manual_str_repeat.rs index b0630e0bc..aeb6d85ed 100644 --- a/spec/rust/tests/manual_str_repeat.rs +++ b/spec/rust/tests/manual_str_repeat.rs @@ -12,7 +12,7 @@ fn basic_parse() { let reader = BytesReader::new(&bytes); let mut r = StrRepeat::default(); { - let res = r.read(&reader, None, KStructUnit::parent_stack()); + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); println!("{:?}", res); assert!(res.is_ok()); } diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index c912ffe39..1628b4455 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -13,7 +13,7 @@ fn basic_parse() { let mut r = SwitchCast::default(); { - let res = r.read(&reader, None, KStructUnit::parent_stack()); + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); println!("{:?}", res); assert!(res.is_ok()); } diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs index 0f83f307f..f638de75d 100644 --- a/spec/rust/tests/manual_switch_cast_parent.rs +++ b/spec/rust/tests/manual_switch_cast_parent.rs @@ -13,7 +13,7 @@ fn basic_parse() { let mut r = SwitchCastParent::default(); { - let res = r.read(&reader, None, KStructUnit::parent_stack()); + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); println!("{:?}", res); assert!(res.is_ok()); } diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs index d9658c29b..af5730783 100644 --- a/spec/rust/tests/manual_test_parent.rs +++ b/spec/rust/tests/manual_test_parent.rs @@ -12,7 +12,7 @@ fn basic_parse() { let reader = BytesReader::new(&bytes); let mut r = TestParent::default(); { - let res = r.read(&reader, None, KStructUnit::parent_stack()); + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); println!("{:?}", res); assert!(res.is_ok()); } diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index d5bf625ed..2b16f9dba 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -12,10 +12,10 @@ fn test_expr_0() { let reader = BytesReader::new(&bytes); let mut r = Expr0::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } - assert_eq!(*r.must_be_f7(&reader).unwrap(), 247); + assert_eq!(r.must_be_f7(&reader).unwrap(), 247); assert_eq!(r.must_be_abc123(&reader).unwrap(), "abc123"); } diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index 918b6ba49..1a8977a81 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -12,17 +12,17 @@ fn test_expr_1() { let reader = BytesReader::new(&bytes); let mut r = Expr1::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } assert_eq!(10, r.len_of_1); let res = r.len_of_1_mod(&reader); - assert_eq!(8, *res.unwrap()); + assert_eq!(8, res.unwrap()); assert_eq!("Some ASC", *r.str1()); let res = r.str1_len(&reader); - assert_eq!(8, *res.unwrap()); + assert_eq!(8, res.unwrap()); } diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs index 03bf8b104..42c2c53c8 100644 --- a/spec/rust/tests/test_fixed_contents.rs +++ b/spec/rust/tests/test_fixed_contents.rs @@ -12,7 +12,7 @@ fn test_fixed_contents() { let reader = BytesReader::new(&bytes); let mut r = FixedContents::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index 462f6683a..cd3e52e30 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -12,7 +12,7 @@ fn test_process_coerce_bytes() { let reader = BytesReader::new(&bytes); let mut r = ProcessCoerceBytes::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs index 7b9d2d942..7f9348fa0 100644 --- a/spec/rust/tests/test_process_rotate.rs +++ b/spec/rust/tests/test_process_rotate.rs @@ -12,7 +12,7 @@ fn test_process_rotate() { let reader = BytesReader::new(&bytes); let mut r = ProcessRotate::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs index 2e0d95de9..a4f51ea52 100644 --- a/spec/rust/tests/test_process_to_user.rs +++ b/spec/rust/tests/test_process_to_user.rs @@ -12,7 +12,7 @@ fn test_process_to_user() { let reader = BytesReader::new(&bytes); let mut r = ProcessToUser::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs index c78fb00da..3b7664019 100644 --- a/spec/rust/tests/test_process_xor4_const.rs +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -12,7 +12,7 @@ fn test_process_xor4_const() { let reader = BytesReader::new(&bytes); let mut r = ProcessXor4Const::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs index e5e6e301c..a06108647 100644 --- a/spec/rust/tests/test_process_xor4_value.rs +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -12,7 +12,7 @@ fn test_process_xor4_value() { let reader = BytesReader::new(&bytes); let mut r = ProcessXor4Value::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 044fcd84c..1286c6f6d 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -12,7 +12,7 @@ fn test_process_xor_const() { let reader = BytesReader::new(&bytes); let mut r = ProcessXorConst::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index ffd2149ee..4642cf854 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -12,7 +12,7 @@ fn test_process_xor_value() { let reader = BytesReader::new(&bytes); let mut r = ProcessXorValue::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs index ad99cbc3a..a9d521b95 100644 --- a/spec/rust/tests/test_str_encodings.rs +++ b/spec/rust/tests/test_str_encodings.rs @@ -12,7 +12,7 @@ fn test_str_encodings() { let reader = BytesReader::new(&bytes); let mut r = StrEncodings::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs index 2f04524ce..ee455ca4f 100644 --- a/spec/rust/tests/test_str_encodings_default.rs +++ b/spec/rust/tests/test_str_encodings_default.rs @@ -12,7 +12,7 @@ fn test_str_encodings_default() { let reader = BytesReader::new(&bytes); let mut r = StrEncodingsDefault::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs index 49ce3d952..a08e88564 100644 --- a/spec/rust/tests/test_str_encodings_utf16.rs +++ b/spec/rust/tests/test_str_encodings_utf16.rs @@ -12,7 +12,7 @@ fn test_str_encodings_utf16() { let reader = BytesReader::new(&bytes); let mut r = StrEncodingsUtf16::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs index da946fc9a..554b0e1db 100644 --- a/spec/rust/tests/test_str_eos.rs +++ b/spec/rust/tests/test_str_eos.rs @@ -12,7 +12,7 @@ fn test_str_eos() { let reader = BytesReader::new(&bytes); let mut r = StrEos::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs index 854bf68b3..8cf6beb9f 100644 --- a/spec/rust/tests/test_str_literals2.rs +++ b/spec/rust/tests/test_str_literals2.rs @@ -12,7 +12,7 @@ fn test_str_literals2() { let reader = BytesReader::new(&bytes); let mut r = StrLiterals2::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs index 9124a485c..2dc9d5176 100644 --- a/spec/rust/tests/test_str_pad_term.rs +++ b/spec/rust/tests/test_str_pad_term.rs @@ -12,7 +12,7 @@ fn test_str_pad_term() { let reader = BytesReader::new(&bytes); let mut r = StrPadTerm::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index 5002393d8..5bfe3360d 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -14,7 +14,7 @@ fn test_str_pad_term_empty() { let reader = BytesReader::new(&bytes); let mut r = StrPadTermEmpty::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index 0cbbb96b2..b2eda6495 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -12,7 +12,7 @@ fn test_switch_bytearray() { let reader = BytesReader::new(&bytes); let mut r = SwitchBytearray::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs index 63f815da6..1c5170547 100644 --- a/spec/rust/tests/test_switch_else_only.rs +++ b/spec/rust/tests/test_switch_else_only.rs @@ -12,7 +12,7 @@ fn test_switch_else_only() { let reader = BytesReader::new(&bytes); let mut r = SwitchElseOnly::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index 2e6ddf531..6bf94c6b3 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -12,7 +12,7 @@ fn test_switch_integers() { let reader = BytesReader::new(&bytes); let mut r = SwitchIntegers::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index 08f3db3b0..c2fa6f81c 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -12,7 +12,7 @@ fn test_switch_integers2() { let reader = BytesReader::new(&bytes); let mut r = SwitchIntegers2::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index 31c441500..3815e71ea 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -12,7 +12,7 @@ fn test_switch_manual_int() { let reader = BytesReader::new(&bytes); let mut r = SwitchManualInt::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index 83d2f5175..79bb7037b 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -12,7 +12,7 @@ fn test_switch_manual_int_else() { let reader = BytesReader::new(&bytes); let mut r = SwitchManualIntElse::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index f307ecc8f..770e2adf1 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -12,7 +12,7 @@ fn test_switch_manual_int_size() { let reader = BytesReader::new(&bytes); let mut r = SwitchManualIntSize::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index 717366743..7884be1f4 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -12,7 +12,7 @@ fn test_switch_manual_int_size_else() { let reader = BytesReader::new(&bytes); let mut r = SwitchManualIntSizeElse::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index d2f23846d..976e4adc4 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -12,7 +12,7 @@ fn test_switch_manual_int_size_eos() { let reader = BytesReader::new(&bytes); let mut r = SwitchManualIntSizeEos::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 38d15e1ef..e9c7d73a2 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -12,7 +12,7 @@ fn test_switch_manual_str() { let reader = BytesReader::new(&bytes); let mut r = SwitchManualStr::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index 31fb9461d..682f69c0c 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -12,7 +12,7 @@ fn test_switch_manual_str_else() { let reader = BytesReader::new(&bytes); let mut r = SwitchManualStrElse::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_switch_multi_bool_ops.rs b/spec/rust/tests/test_switch_multi_bool_ops.rs index fded52737..800aadd51 100644 --- a/spec/rust/tests/test_switch_multi_bool_ops.rs +++ b/spec/rust/tests/test_switch_multi_bool_ops.rs @@ -13,7 +13,7 @@ fn test_switch_multi_bool_ops() { let reader = BytesReader::new(&bytes); let mut r = SwitchMultiBoolOps::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs index 9f3b9ad81..240545922 100644 --- a/spec/rust/tests/test_term_bytes.rs +++ b/spec/rust/tests/test_term_bytes.rs @@ -12,7 +12,7 @@ fn test_term_bytes() { let reader = BytesReader::new(&bytes); let mut r = TermBytes::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs index 0b8f4e714..b3f38fdcf 100644 --- a/spec/rust/tests/test_term_strz.rs +++ b/spec/rust/tests/test_term_strz.rs @@ -12,7 +12,7 @@ fn test_term_strz() { let reader = BytesReader::new(&bytes); let mut r = TermStrz::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_term_u1_val.rs b/spec/rust/tests/test_term_u1_val.rs index 64d6cfa16..ac7e7717a 100644 --- a/spec/rust/tests/test_term_u1_val.rs +++ b/spec/rust/tests/test_term_u1_val.rs @@ -12,7 +12,7 @@ fn test_term_u1_val() { let reader = BytesReader::new(&bytes); let mut r = TermU1Val::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs index 693c6324f..5231eb430 100644 --- a/spec/rust/tests/test_ts_packet_header.rs +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -12,7 +12,7 @@ fn test_ts_packet_header() { let reader = BytesReader::new(&bytes); let mut r = TsPacketHeader::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index 8434ac91c..73f238ba7 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -12,12 +12,12 @@ fn test_type_int_unary_op() { let reader = BytesReader::new(&bytes); let mut r = TypeIntUnaryOp::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } assert_eq!(r.value_s2(), 16720); assert_eq!(r.value_s8(), 4706543082108963651); - assert_eq!(*r.unary_s2(&reader).unwrap(), -16720); - assert_eq!(*r.unary_s8(&reader).unwrap(), -4706543082108963651); + assert_eq!(r.unary_s2(&reader).unwrap(), -16720); + assert_eq!(r.unary_s8(&reader).unwrap(), -4706543082108963651); } diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs index 117e10629..83ec44e22 100644 --- a/spec/rust/tests/test_type_ternary.rs +++ b/spec/rust/tests/test_type_ternary.rs @@ -12,7 +12,7 @@ fn test_type_ternary() { let reader = BytesReader::new(&bytes); let mut r = TypeTernary::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_valid_fail_anyof_int.rs b/spec/rust/tests/test_valid_fail_anyof_int.rs index 84a5bfb5b..2b77295db 100644 --- a/spec/rust/tests/test_valid_fail_anyof_int.rs +++ b/spec/rust/tests/test_valid_fail_anyof_int.rs @@ -13,7 +13,7 @@ fn test_valid_fail_anyof_int() { let reader = BytesReader::new(&bytes); let mut r = ValidFailAnyofInt::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationNotAnyOfError(Int1Type(false))", err); } else { panic!("no expected exception: ValidationNotAnyOfError(Int1Type(false))"); diff --git a/spec/rust/tests/test_valid_fail_contents.rs b/spec/rust/tests/test_valid_fail_contents.rs index 8ff038656..73ce1626f 100644 --- a/spec/rust/tests/test_valid_fail_contents.rs +++ b/spec/rust/tests/test_valid_fail_contents.rs @@ -13,7 +13,7 @@ fn test_valid_fail_contents() { let reader = BytesReader::new(&bytes); let mut r = ValidFailContents::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); } else { panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); diff --git a/spec/rust/tests/test_valid_fail_eq_bytes.rs b/spec/rust/tests/test_valid_fail_eq_bytes.rs index c462ad311..0a76ed491 100644 --- a/spec/rust/tests/test_valid_fail_eq_bytes.rs +++ b/spec/rust/tests/test_valid_fail_eq_bytes.rs @@ -13,7 +13,7 @@ fn test_valid_fail_eq_bytes() { let reader = BytesReader::new(&bytes); let mut r = ValidFailEqBytes::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); } else { panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); diff --git a/spec/rust/tests/test_valid_fail_eq_int.rs b/spec/rust/tests/test_valid_fail_eq_int.rs index 089fc9445..59779cbf3 100644 --- a/spec/rust/tests/test_valid_fail_eq_int.rs +++ b/spec/rust/tests/test_valid_fail_eq_int.rs @@ -13,7 +13,7 @@ fn test_valid_fail_eq_int() { let reader = BytesReader::new(&bytes); let mut r = ValidFailEqInt::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); } else { panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); diff --git a/spec/rust/tests/test_valid_fail_eq_str.rs b/spec/rust/tests/test_valid_fail_eq_str.rs index 65f5c40d2..494ebc5ae 100644 --- a/spec/rust/tests/test_valid_fail_eq_str.rs +++ b/spec/rust/tests/test_valid_fail_eq_str.rs @@ -13,7 +13,7 @@ fn test_valid_fail_eq_str() { let reader = BytesReader::new(&bytes); let mut r = ValidFailEqStr::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationNotEqualError(CalcStrType)", err); } else { panic!("no expected exception: ValidationNotEqualError(CalcStrType)"); diff --git a/spec/rust/tests/test_valid_fail_expr.rs b/spec/rust/tests/test_valid_fail_expr.rs index 80228b102..a5d9a1e92 100644 --- a/spec/rust/tests/test_valid_fail_expr.rs +++ b/spec/rust/tests/test_valid_fail_expr.rs @@ -13,7 +13,7 @@ fn test_valid_fail_expr() { let reader = BytesReader::new(&bytes); let mut r = ValidFailExpr::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationExprError(IntMultiType(true,Width2,None))", err); } else { panic!("no expected exception: ValidationExprError(IntMultiType(true,Width2,None))"); diff --git a/spec/rust/tests/test_valid_fail_inst.rs b/spec/rust/tests/test_valid_fail_inst.rs index 302e691ca..8097e4036 100644 --- a/spec/rust/tests/test_valid_fail_inst.rs +++ b/spec/rust/tests/test_valid_fail_inst.rs @@ -13,7 +13,7 @@ fn test_valid_fail_inst() { let reader = BytesReader::new(&bytes); let mut r = ValidFailInst::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); } else { panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); diff --git a/spec/rust/tests/test_valid_fail_max_int.rs b/spec/rust/tests/test_valid_fail_max_int.rs index 544317f62..886b9fcf8 100644 --- a/spec/rust/tests/test_valid_fail_max_int.rs +++ b/spec/rust/tests/test_valid_fail_max_int.rs @@ -13,7 +13,7 @@ fn test_valid_fail_max_int() { let reader = BytesReader::new(&bytes); let mut r = ValidFailMaxInt::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); } else { panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); diff --git a/spec/rust/tests/test_valid_fail_min_int.rs b/spec/rust/tests/test_valid_fail_min_int.rs index a6d98b7a1..e02427ac6 100644 --- a/spec/rust/tests/test_valid_fail_min_int.rs +++ b/spec/rust/tests/test_valid_fail_min_int.rs @@ -13,7 +13,7 @@ fn test_valid_fail_min_int() { let reader = BytesReader::new(&bytes); let mut r = ValidFailMinInt::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationLessThanError(Int1Type(false))", err); } else { panic!("no expected exception: ValidationLessThanError(Int1Type(false))"); diff --git a/spec/rust/tests/test_valid_fail_range_bytes.rs b/spec/rust/tests/test_valid_fail_range_bytes.rs index b38b9939d..3440a01cf 100644 --- a/spec/rust/tests/test_valid_fail_range_bytes.rs +++ b/spec/rust/tests/test_valid_fail_range_bytes.rs @@ -13,7 +13,7 @@ fn test_valid_fail_range_bytes() { let reader = BytesReader::new(&bytes); let mut r = ValidFailRangeBytes::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcBytesType)", err); } else { panic!("no expected exception: ValidationGreaterThanError(CalcBytesType)"); diff --git a/spec/rust/tests/test_valid_fail_range_float.rs b/spec/rust/tests/test_valid_fail_range_float.rs index 2f41fb4e7..b77e1bf6d 100644 --- a/spec/rust/tests/test_valid_fail_range_float.rs +++ b/spec/rust/tests/test_valid_fail_range_float.rs @@ -13,7 +13,7 @@ fn test_valid_fail_range_float() { let reader = BytesReader::new(&bytes); let mut r = ValidFailRangeFloat::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationGreaterThanError(FloatMultiType(Width4,None))", err); } else { panic!("no expected exception: ValidationGreaterThanError(FloatMultiType(Width4,None))"); diff --git a/spec/rust/tests/test_valid_fail_range_int.rs b/spec/rust/tests/test_valid_fail_range_int.rs index 448265c7c..f1cf3c9e0 100644 --- a/spec/rust/tests/test_valid_fail_range_int.rs +++ b/spec/rust/tests/test_valid_fail_range_int.rs @@ -13,7 +13,7 @@ fn test_valid_fail_range_int() { let reader = BytesReader::new(&bytes); let mut r = ValidFailRangeInt::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); } else { panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); diff --git a/spec/rust/tests/test_valid_fail_range_str.rs b/spec/rust/tests/test_valid_fail_range_str.rs index 278119a6c..9621c39c6 100644 --- a/spec/rust/tests/test_valid_fail_range_str.rs +++ b/spec/rust/tests/test_valid_fail_range_str.rs @@ -13,7 +13,7 @@ fn test_valid_fail_range_str() { let reader = BytesReader::new(&bytes); let mut r = ValidFailRangeStr::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcStrType)", err); } else { panic!("no expected exception: ValidationGreaterThanError(CalcStrType)"); diff --git a/spec/rust/tests/test_valid_long.rs b/spec/rust/tests/test_valid_long.rs index ca823d3b3..590035ba9 100644 --- a/spec/rust/tests/test_valid_long.rs +++ b/spec/rust/tests/test_valid_long.rs @@ -11,7 +11,7 @@ fn test_valid_long() { let reader = BytesReader::new(&bytes); let mut r = ValidLong::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_valid_not_parsed_if.rs b/spec/rust/tests/test_valid_not_parsed_if.rs index 1c7c907e2..52107f5b1 100644 --- a/spec/rust/tests/test_valid_not_parsed_if.rs +++ b/spec/rust/tests/test_valid_not_parsed_if.rs @@ -11,7 +11,7 @@ fn test_valid_not_parsed_if() { let reader = BytesReader::new(&bytes); let mut r = ValidNotParsedIf::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_valid_optional_id.rs b/spec/rust/tests/test_valid_optional_id.rs index 0f12ddbff..84e2248cb 100644 --- a/spec/rust/tests/test_valid_optional_id.rs +++ b/spec/rust/tests/test_valid_optional_id.rs @@ -11,7 +11,7 @@ fn test_valid_optional_id() { let reader = BytesReader::new(&bytes); let mut r = ValidOptionalId::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_valid_short.rs b/spec/rust/tests/test_valid_short.rs index 907d75f84..21a298e54 100644 --- a/spec/rust/tests/test_valid_short.rs +++ b/spec/rust/tests/test_valid_short.rs @@ -11,7 +11,7 @@ fn test_valid_short() { let reader = BytesReader::new(&bytes); let mut r = ValidShort::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/spec/rust/tests/test_valid_switch.rs b/spec/rust/tests/test_valid_switch.rs index 4879118e6..0a916332a 100644 --- a/spec/rust/tests/test_valid_switch.rs +++ b/spec/rust/tests/test_valid_switch.rs @@ -11,7 +11,7 @@ fn test_valid_switch() { let reader = BytesReader::new(&bytes); let mut r = ValidSwitch::default(); - if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) { + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { panic!("{:?}", err); } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index bef6abfb6..b100b999b 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -30,7 +30,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( | let reader = BytesReader::new(&bytes); | let mut r = $className::default(); | - | if let Err(err) = r.read(&reader, None, KStructUnit::parent_stack()) {""".stripMargin + | if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) {""".stripMargin out.puts(code) out.inc } From 040084d6e40c85b0ae9206ebe6954c398a15feee Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 5 Aug 2022 22:41:39 +0800 Subject: [PATCH 034/198] tests updated with latest generator. --- formats_rust/expr_3.ksy | 31 +++++++++++++++++ spec/rust/tests/manual_read_bytes.rs | 2 +- spec/rust/tests/manual_switch_cast.rs | 26 +++++++------- spec/rust/tests/manual_switch_cast_parent.rs | 26 +++++++------- spec/rust/tests/manual_test_parent.rs | 4 +-- spec/rust/tests/test_enum_0.rs | 22 ++++++++++++ spec/rust/tests/test_enum_1.rs | 22 ++++++++++++ spec/rust/tests/test_enum_deep.rs | 22 ++++++++++++ spec/rust/tests/test_expr_0.rs | 4 +-- spec/rust/tests/test_expr_1.rs | 6 ++-- spec/rust/tests/test_expr_2.rs | 34 +++++++++---------- spec/rust/tests/test_expr_3.rs | 32 +++++++++++++++++ spec/rust/tests/test_process_coerce_bytes.rs | 12 +++---- spec/rust/tests/test_process_xor_const.rs | 2 +- spec/rust/tests/test_process_xor_value.rs | 2 +- spec/rust/tests/test_str_encodings_utf16.rs | 8 ++--- spec/rust/tests/test_str_pad_term_empty.rs | 8 ++--- spec/rust/tests/test_switch_bytearray.rs | 26 +++++++------- spec/rust/tests/test_switch_else_only.rs | 8 ++--- spec/rust/tests/test_switch_integers.rs | 18 +++++----- spec/rust/tests/test_switch_integers2.rs | 6 ++-- spec/rust/tests/test_switch_manual_int.rs | 22 ++++++------ .../rust/tests/test_switch_manual_int_else.rs | 24 ++++++------- .../rust/tests/test_switch_manual_int_size.rs | 16 ++++----- .../tests/test_switch_manual_int_size_else.rs | 16 ++++----- .../tests/test_switch_manual_int_size_eos.rs | 18 +++++----- spec/rust/tests/test_switch_manual_str.rs | 18 +++++----- .../rust/tests/test_switch_manual_str_else.rs | 14 ++++---- spec/rust/tests/test_switch_multi_bool_ops.rs | 18 +++++----- spec/rust/tests/test_ts_packet_header.rs | 12 +++---- spec/rust/tests/test_type_int_unary_op.rs | 8 ++--- spec/rust/tests/test_type_ternary.rs | 2 +- 32 files changed, 307 insertions(+), 182 deletions(-) create mode 100644 formats_rust/expr_3.ksy create mode 100644 spec/rust/tests/test_enum_0.rs create mode 100644 spec/rust/tests/test_enum_1.rs create mode 100644 spec/rust/tests/test_enum_deep.rs create mode 100644 spec/rust/tests/test_expr_3.rs diff --git a/formats_rust/expr_3.ksy b/formats_rust/expr_3.ksy new file mode 100644 index 000000000..e0b63ed12 --- /dev/null +++ b/formats_rust/expr_3.ksy @@ -0,0 +1,31 @@ +# Tests string concat, comparisons and boolean instance results +meta: + id: expr_3 +seq: + - id: one + type: u1 + - id: two + type: str + encoding: ASCII + size: 3 +instances: + three: + value: '"@" + two' + four: + value: '"_" + two + "_"' + is_str_eq: + value: two == "ACK" + is_str_ne: + value: two != "ACK" + is_str_lt: + value: two < "ACK2" + is_str_gt: + value: two > "ACK2" + is_str_le: + value: two <= "ACK2" + is_str_ge: + value: two >= "ACK2" + is_str_lt2: + value: three < two + test_not: + value: not false diff --git a/spec/rust/tests/manual_read_bytes.rs b/spec/rust/tests/manual_read_bytes.rs index a0dac3fa3..b6d3cf0a4 100644 --- a/spec/rust/tests/manual_read_bytes.rs +++ b/spec/rust/tests/manual_read_bytes.rs @@ -18,7 +18,7 @@ fn basic_parse() { assert!(res.is_ok()); } - assert_eq!(1, r.len()); + assert_eq!(1, *r.len()); assert_eq!(vec![7], *r.val()); assert_eq!(vec![0x2, 0x40], *r.padding()); } diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index 1628b4455..f4baaea5a 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -18,32 +18,32 @@ fn basic_parse() { assert!(res.is_ok()); } - assert_eq!(4, r.opcodes.len()); + assert_eq!(4, r.opcodes().len()); - assert_eq!(0x53, r.opcodes[0].code()); - if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes[0].body() { - assert_eq!("foobar", s.value); + assert_eq!(0x53, *r.opcodes()[0].code()); + if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes()[0].body() { + assert_eq!("foobar", s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); } - assert_eq!(0x49, r.opcodes[1].code); - if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes[1].body() { - assert_eq!(66, s.value); + assert_eq!(0x49, *r.opcodes()[1].code()); + if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes()[1].body() { + assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } - assert_eq!(0x49, r.opcodes[2].code); - if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes[2].body() { - assert_eq!(55, s.value); + assert_eq!(0x49, *r.opcodes()[2].code()); + if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes()[2].body() { + assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } - assert_eq!(0x53, r.opcodes[3].code); - if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes[3].body() { - assert_eq!("", s.value); + assert_eq!(0x53, *r.opcodes()[3].code()); + if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes()[3].body() { + assert_eq!("", s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); } diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs index f638de75d..30754a670 100644 --- a/spec/rust/tests/manual_switch_cast_parent.rs +++ b/spec/rust/tests/manual_switch_cast_parent.rs @@ -18,32 +18,32 @@ fn basic_parse() { assert!(res.is_ok()); } - assert_eq!(4, r.opcodes.len()); + assert_eq!(4, r.opcodes().len()); - assert_eq!(0x53, r.opcodes[0].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes[0].body() { - assert_eq!("foobar", s.value); + assert_eq!(0x53, *r.opcodes()[0].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes()[0].body() { + assert_eq!("foobar", s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); } - assert_eq!(0x49, r.opcodes[1].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes[1].body() { - assert_eq!(66, s.value); + assert_eq!(0x49, *r.opcodes()[1].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes()[1].body() { + assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } - assert_eq!(0x49, r.opcodes[2].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes[2].body() { - assert_eq!(55, s.value); + assert_eq!(0x49, *r.opcodes()[2].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes()[2].body() { + assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } - assert_eq!(0x53, r.opcodes[3].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes[3].body() { - assert_eq!("", s.value); + assert_eq!(0x53, *r.opcodes()[3].code()); + if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes()[3].body() { + assert_eq!("", s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); } diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs index af5730783..30624d663 100644 --- a/spec/rust/tests/manual_test_parent.rs +++ b/spec/rust/tests/manual_test_parent.rs @@ -17,8 +17,8 @@ fn basic_parse() { assert!(res.is_ok()); } - assert_eq!(1, r.root_byte()); - assert_eq!(7, r.child().child_byte()); + assert_eq!(1, *r.root_byte()); + assert_eq!(7, *r.child().child_byte()); assert_eq!(1, r.child().child2().len()); assert_eq!(vec![2, 64, 64, 4, 55, 19, 0], *r.child().child2()[0].child2_byte()); } diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs new file mode 100644 index 000000000..ae5e979b3 --- /dev/null +++ b/spec/rust/tests/test_enum_0.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::enum_0::*; + +#[test] +fn test_enum_0() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = Enum0::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(r.pet_1(), &Enum0_Animal::Cat); + assert_eq!(r.pet_2(), &Enum0_Animal::Chicken); +} diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs new file mode 100644 index 000000000..5f477865c --- /dev/null +++ b/spec/rust/tests/test_enum_1.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::enum_1::*; + +#[test] +fn test_enum_1() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = Enum1::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(r.main().submain().pet_1(), &Enum1_MainObj_Animal::Cat); + assert_eq!(r.main().submain().pet_2(), &Enum1_MainObj_Animal::Chicken); +} diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs new file mode 100644 index 000000000..754dc1501 --- /dev/null +++ b/spec/rust/tests/test_enum_deep.rs @@ -0,0 +1,22 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::enum_deep::*; + +#[test] +fn test_enum_deep() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = EnumDeep::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(r.pet_1(), &EnumDeep_Container1_Animal::Cat); + assert_eq!(r.pet_2(), &EnumDeep_Container1_Container2_Animal::Hare); +} diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index 2b16f9dba..5b9c4e67e 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -16,6 +16,6 @@ fn test_expr_0() { panic!("{:?}", err); } - assert_eq!(r.must_be_f7(&reader).unwrap(), 247); - assert_eq!(r.must_be_abc123(&reader).unwrap(), "abc123"); + assert_eq!(*r.must_be_f7(&reader).unwrap(), 247); + assert_eq!(*r.must_be_abc123(&reader).unwrap(), "abc123"); } diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index 1a8977a81..20a9603e6 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -16,13 +16,13 @@ fn test_expr_1() { panic!("{:?}", err); } - assert_eq!(10, r.len_of_1); + assert_eq!(10, *r.len_of_1()); let res = r.len_of_1_mod(&reader); - assert_eq!(8, res.unwrap()); + assert_eq!(8, *res.unwrap()); assert_eq!("Some ASC", *r.str1()); let res = r.str1_len(&reader); - assert_eq!(8, res.unwrap()); + assert_eq!(8, *res.unwrap()); } diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs index abab7ba34..7d0736449 100644 --- a/spec/rust/tests/test_expr_2.rs +++ b/spec/rust/tests/test_expr_2.rs @@ -17,21 +17,21 @@ fn test_expr_2() { panic!("{:?}", err); } - assert_eq!(r.str1().len_orig(), 10); - assert_eq!(r.str1().len_mod(&reader).unwrap(), 7); - assert_eq!(r.str1().str, "Some AS"); - assert_eq!(r.str1_len(&reader).unwrap(), 7); - assert_eq!(r.str1_len_mod(&reader).unwrap(), 7); - assert_eq!(r.str1_byte1(&reader).unwrap(), 73); - assert_eq!(r.str1_avg(&reader).unwrap(), 73); - assert_eq!(r.str1_char5(&reader).unwrap(), "e"); - assert_eq!(r.str1_tuple5(&reader).unwrap().byte0, 101); - assert_eq!(r.str1_tuple5(&reader).unwrap().byte0, 101); - assert_eq!(r.str1_tuple5(&reader).unwrap().byte1, 32); - assert_eq!(r.str1_tuple5(&reader).unwrap().byte2, 65); - assert_eq!(r.str1_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); - assert_eq!(r.str2_tuple5(&reader).unwrap().byte0, 101); - assert_eq!(r.str2_tuple5(&reader).unwrap().byte1, 32); - assert_eq!(r.str2_tuple5(&reader).unwrap().byte2, 65); - assert_eq!(r.str2_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); + assert_eq!(*r.str1().len_orig(), 10); + assert_eq!(*r.str1().len_mod(&reader).unwrap(), 7); + assert_eq!(*r.str1().str(), "Some AS"); + assert_eq!(*r.str1_len(&reader).unwrap(), 7); + assert_eq!(*r.str1_len_mod(&reader).unwrap(), 7); + assert_eq!(*r.str1_byte1(&reader).unwrap(), 73); + assert_eq!(*r.str1_avg(&reader).unwrap(), 73); + assert_eq!(*r.str1_char5(&reader).unwrap(), "e"); + assert_eq!(*r.str1_tuple5(&reader).unwrap().byte0(), 101); + assert_eq!(*r.str1_tuple5(&reader).unwrap().byte0(), 101); + assert_eq!(*r.str1_tuple5(&reader).unwrap().byte1(), 32); + assert_eq!(*r.str1_tuple5(&reader).unwrap().byte2(), 65); + assert_eq!(*r.str1_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); + assert_eq!(*r.str2_tuple5(&reader).unwrap().byte0(), 101); + assert_eq!(*r.str2_tuple5(&reader).unwrap().byte1(), 32); + assert_eq!(*r.str2_tuple5(&reader).unwrap().byte2(), 65); + assert_eq!(*r.str2_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); } diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs new file mode 100644 index 000000000..37ab49d6b --- /dev/null +++ b/spec/rust/tests/test_expr_3.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_3::*; + +#[test] +fn test_expr_3() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = Expr3::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.one(), 80); + assert_eq!(*r.two(), "ACK"); + assert_eq!(*r.three(&reader).unwrap(), "@ACK"); + assert_eq!(*r.four(&reader).unwrap(), "_ACK_"); + assert_eq!(*r.is_str_eq(&reader).unwrap(), true); + assert_eq!(*r.is_str_ne(&reader).unwrap(), false); + assert_eq!(*r.is_str_lt(&reader).unwrap(), true); + assert_eq!(*r.is_str_gt(&reader).unwrap(), false); + assert_eq!(*r.is_str_le(&reader).unwrap(), true); + assert_eq!(*r.is_str_ge(&reader).unwrap(), false); + assert_eq!(*r.is_str_lt2(&reader).unwrap(), true); + assert_eq!(*r.test_not(&reader).unwrap(), true); +} diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index cd3e52e30..4a72e8a67 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -16,15 +16,11 @@ fn test_process_coerce_bytes() { panic!("{:?}", err); } - assert_eq!(0, r.records[0].flag()); - - let mut i = r.records.iter_mut(); - + assert_eq!(0, *r.records()[0].flag()); let buf : Vec = vec![0x41, 0x41, 0x41, 0x41]; - let x = i.next().unwrap(); - assert_eq!(&buf, x.buf(&reader).unwrap()); + assert_eq!(buf, *r.records()[0].buf(&reader).unwrap()); + assert_eq!(1, *r.records()[1].flag()); let buf : Vec = vec![0x42, 0x42, 0x42, 0x42]; - let x = i.next().unwrap(); - assert_eq!(&buf, x.buf(&reader).unwrap()); + assert_eq!(buf, *r.records()[1].buf(&reader).unwrap()); } diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 1286c6f6d..2ea2c0dce 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -16,6 +16,6 @@ fn test_process_xor_const() { panic!("{:?}", err); } - assert_eq!(r.key(), 255); + assert_eq!(*r.key(), 255); assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); } diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index 4642cf854..9f642f04e 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -16,6 +16,6 @@ fn test_process_xor_value() { panic!("{:?}", err); } - assert_eq!(r.key(), 255); + assert_eq!(*r.key(), 255); assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); } diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs index a08e88564..d0b70629e 100644 --- a/spec/rust/tests/test_str_encodings_utf16.rs +++ b/spec/rust/tests/test_str_encodings_utf16.rs @@ -16,10 +16,10 @@ fn test_str_encodings_utf16() { panic!("{:?}", err); } - assert_eq!(r.len_be(), 12); - assert_eq!(r.be_bom_removed().bom(), 65279); + assert_eq!(*r.len_be(), 12); + assert_eq!(*r.be_bom_removed().bom(), 65279); assert_eq!(r.be_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.len_le(), 12); - assert_eq!(r.le_bom_removed().bom(), 65279); + assert_eq!(*r.len_le(), 12); + assert_eq!(*r.le_bom_removed().bom(), 65279); assert_eq!(r.le_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); } diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index 5bfe3360d..0f0816eb8 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -18,8 +18,8 @@ fn test_str_pad_term_empty() { panic!("{:?}", err); } - assert_eq!(r.str_pad, ""); - assert_eq!(r.str_term, ""); - assert_eq!(r.str_term_and_pad, ""); - assert_eq!(r.str_term_include, "@"); + assert_eq!(r.str_pad(), ""); + assert_eq!(r.str_term(), ""); + assert_eq!(r.str_term_and_pad(), ""); + assert_eq!(r.str_term_include(), "@"); } diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index b2eda6495..de8c6027c 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -16,32 +16,32 @@ fn test_switch_bytearray() { panic!("{:?}", err); } - assert_eq!(4, r.opcodes.len()); + assert_eq!(4, r.opcodes().len()); - assert_eq!(vec![0x53], r.opcodes[0].code); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes[0].body() { - assert_eq!("foobar", s.value); + assert_eq!(vec![0x53], *r.opcodes()[0].code()); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes()[0].body() { + assert_eq!("foobar", s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Strval"); } - assert_eq!(vec![0x49], r.opcodes[1].code); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes[1].body() { - assert_eq!(66, s.value); + assert_eq!(vec![0x49], *r.opcodes()[1].code()); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes()[1].body() { + assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Intval"); } - assert_eq!(vec![0x49], r.opcodes[2].code); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes[2].body() { - assert_eq!(55, s.value); + assert_eq!(vec![0x49], *r.opcodes()[2].code()); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes()[2].body() { + assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Intval"); } - assert_eq!(vec![0x53], r.opcodes[3].code); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes[3].body() { - assert_eq!("", s.value); + assert_eq!(vec![0x53], *r.opcodes()[3].code()); + if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes()[3].body() { + assert_eq!("", s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Strval"); } diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs index 1c5170547..820c31621 100644 --- a/spec/rust/tests/test_switch_else_only.rs +++ b/spec/rust/tests/test_switch_else_only.rs @@ -16,10 +16,10 @@ fn test_switch_else_only() { panic!("{:?}", err); } - assert_eq!(83, r.opcode); - let SwitchElseOnly_PrimByte::S1(v) = r.prim_byte.as_ref().unwrap(); + assert_eq!(83, *r.opcode()); + let SwitchElseOnly_PrimByte::S1(v) = r.prim_byte_enum(); assert_eq!(102, *v); - let SwitchElseOnly_Ut::SwitchElseOnly_Data(d) = r.ut.as_ref().unwrap(); - assert_eq!(vec![0x72, 0x00, 0x49, 0x42], d.value); + let SwitchElseOnly_Ut::SwitchElseOnly_Data(d) = r.ut(); + assert_eq!(vec![0x72, 0x00, 0x49, 0x42], *d.value()); } diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index 6bf94c6b3..a22458401 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -16,13 +16,13 @@ fn test_switch_integers() { panic!("{:?}", err); } - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0 as usize].code(), 1); - assert_eq!(r.opcodes[0 as usize].body(), 7); - assert_eq!(r.opcodes[1 as usize].code(), 2); - assert_eq!(r.opcodes[1 as usize].body(), 16448); - assert_eq!(r.opcodes[2 as usize].code(), 4); - assert_eq!(r.opcodes[2 as usize].body(), 4919); - assert_eq!(r.opcodes[3 as usize].code(), 8); - assert_eq!(r.opcodes[3 as usize].body(), 4919); + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), 1); + assert_eq!(r.opcodes()[0 as usize].body(), 7); + assert_eq!(*r.opcodes()[1 as usize].code(), 2); + assert_eq!(r.opcodes()[1 as usize].body(), 16448); + assert_eq!(*r.opcodes()[2 as usize].code(), 4); + assert_eq!(r.opcodes()[2 as usize].body(), 4919); + assert_eq!(*r.opcodes()[3 as usize].code(), 8); + assert_eq!(r.opcodes()[3 as usize].body(), 4919); } diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index c2fa6f81c..f910519f8 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -16,9 +16,9 @@ fn test_switch_integers2() { panic!("{:?}", err); } - assert_eq!(r.code(), 1); + assert_eq!(*r.code(), 1); assert_eq!(r.len(), 7); assert_eq!(r.ham(), &[0x2u8, 0x40u8, 0x40u8, 0x4u8, 0x37u8, 0x13u8, 0x0u8].to_vec()); - assert_eq!(r.padding(), 0); - assert_eq!(r.len_mod_str(&reader).unwrap(), "13"); + assert_eq!(*r.padding(), 0); + assert_eq!(*r.len_mod_str(&reader).unwrap(), "13"); } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index 3815e71ea..ac7a31904 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -16,30 +16,30 @@ fn test_switch_manual_int() { panic!("{:?}", err); } - assert_eq!(83, r.opcodes()[0].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes[0].body() { + assert_eq!(83, *r.opcodes()[0].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes()[0].body() { assert_eq!("foobar", s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); } - assert_eq!(73, r.opcodes()[1].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes[1].body() { - assert_eq!(66, s.value()); + assert_eq!(73, *r.opcodes()[1].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes()[1].body() { + assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); } - assert_eq!(73, r.opcodes()[2].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes[2].body() { - assert_eq!(55, s.value()); + assert_eq!(73, *r.opcodes()[2].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes()[2].body() { + assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); } - assert_eq!(83, r.opcodes()[3].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes[3].body() { - assert_eq!("", s.value()); + assert_eq!(83, *r.opcodes()[3].code()); + if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes()[3].body() { + assert_eq!("", *s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); } diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index 79bb7037b..8806ab574 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -18,30 +18,30 @@ fn test_switch_manual_int_else() { } assert_eq!(4, r.opcodes().len()); - assert_eq!(83, r.opcodes()[0].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Strval(s) = r.opcodes[0].body() { - assert_eq!("foo", s.value); + assert_eq!(83, *r.opcodes()[0].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Strval(s) = r.opcodes()[0].body() { + assert_eq!("foo", *s.value()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Strval"); } - assert_eq!(88, r.opcodes()[1].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes[1].body() { - assert_eq!(66, s.filler); + assert_eq!(88, *r.opcodes()[1].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes()[1].body() { + assert_eq!(66, *s.filler()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); } - assert_eq!(89, r.opcodes()[2].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes[2].body() { - assert_eq!(51966, s.filler); + assert_eq!(89, *r.opcodes()[2].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes()[2].body() { + assert_eq!(51966, *s.filler()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); } - assert_eq!(73, r.opcodes()[3].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Intval(s) = r.opcodes[3].body() { - assert_eq!(7, s.value); + assert_eq!(73, *r.opcodes()[3].code()); + if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Intval(s) = r.opcodes()[3].body() { + assert_eq!(7, *s.value()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Intval"); } diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index 770e2adf1..f3599bf32 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -18,32 +18,32 @@ fn test_switch_manual_int_size() { } assert_eq!(4, r.chunks().len()); - assert_eq!(17, r.chunks()[0].code); - if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkMeta(s) = r.chunks[0].body() { + assert_eq!(17, *r.chunks()[0].code()); + if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkMeta(s) = r.chunks()[0].body() { assert_eq!("Stuff", s.title()); assert_eq!("Me", s.author()); } else { panic!("expected enum SwitchManualIntSize_Chunk_ChunkMeta"); } - assert_eq!(34, r.chunks()[1].code); - if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkDir(s) = r.chunks[1].body() { + assert_eq!(34, *r.chunks()[1].code()); + if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkDir(s) = r.chunks()[1].body() { let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); assert_eq!(strings, *s.entries()); } else { panic!("expected enum SwitchManualIntSize_Chunk_ChunkDir"); } - assert_eq!(51, r.chunks()[2].code); - if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks[2].body() { + assert_eq!(51, *r.chunks()[2].code()); + if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks()[2].body() { let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s); } else { panic!("expected enum Bytes"); } - assert_eq!(255, r.chunks()[3].code); - if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks[3].body() { + assert_eq!(255, *r.chunks()[3].code()); + if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks()[3].body() { let raw : Vec = vec![]; assert_eq!(raw, *s); } else { diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index 7884be1f4..1f2cd9b4d 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -18,32 +18,32 @@ fn test_switch_manual_int_size_else() { } assert_eq!(4, r.chunks().len()); - assert_eq!(17, r.chunks()[0].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkMeta(s) = r.chunks[0].body() { + assert_eq!(17, *r.chunks()[0].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkMeta(s) = r.chunks()[0].body() { assert_eq!("Stuff", s.title()); assert_eq!("Me", s.author()); } else { panic!("expected enum SwitchManualIntSizeElse_Chunk_ChunkMeta"); } - assert_eq!(34, r.chunks()[1].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkDir(s) = r.chunks[1].body() { + assert_eq!(34, *r.chunks()[1].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkDir(s) = r.chunks()[1].body() { let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); assert_eq!(strings, *s.entries()); } else { panic!("expected enum SwitchManualIntSizeElse_Chunk_ChunkDir"); } - assert_eq!(51, r.chunks()[2].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks[2].body() { + assert_eq!(51, *r.chunks()[2].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks()[2].body() { let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s.rest()); } else { panic!("expected enum SwitchManualIntSizeElse_Chunk_Dummy"); } - assert_eq!(255, r.chunks()[3].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks[3].body() { + assert_eq!(255, *r.chunks()[3].code()); + if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks()[3].body() { let raw : Vec = vec![]; assert_eq!(raw, *s.rest()); } else { diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 976e4adc4..1493b4ad7 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -18,35 +18,35 @@ fn test_switch_manual_int_size_eos() { } assert_eq!(4, r.chunks().len()); - assert_eq!(17, r.chunks()[0].code()); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkMeta(s) = r.chunks[0].body().body() { + assert_eq!(17, *r.chunks()[0].code()); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkMeta(s) = r.chunks()[0].body().body() { assert_eq!("Stuff", s.title()); assert_eq!("Me", s.author()); } else { panic!("expected enum SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkMeta"); } - assert_eq!(34, r.chunks()[1].code()); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkDir(s) = r.chunks[1].body().body() { + assert_eq!(34, *r.chunks()[1].code()); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkDir(s) = r.chunks()[1].body().body() { let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); assert_eq!(strings, *s.entries()); } else { panic!("expected enum SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkDir"); } - assert_eq!(51, r.chunks()[2].code); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks[2].body().body() { + assert_eq!(51, *r.chunks()[2].code()); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks()[2].body().body() { let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s); } else { panic!("expected enum Bytes"); } - assert_eq!(255, r.chunks()[3].code); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks[3].body().body() { + assert_eq!(255, *r.chunks()[3].code()); + if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks()[3].body().body() { let raw : Vec = vec![]; assert_eq!(raw, *s); } else { panic!("expected enum Bytes"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index e9c7d73a2..985bf1c51 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -19,29 +19,29 @@ fn test_switch_manual_str() { assert_eq!(4, r.opcodes().len()); assert_eq!("S", r.opcodes()[0].code()); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes[0].body() { - assert_eq!("foobar", s.value()); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes()[0].body() { + assert_eq!("foobar", *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Strval"); } assert_eq!("I", r.opcodes()[1].code()); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes[1].body() { - assert_eq!(66, s.value()); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes()[1].body() { + assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Intval"); } assert_eq!("I", r.opcodes()[2].code()); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes[2].body() { - assert_eq!(55, s.value()); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes()[2].body() { + assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Intval"); } - assert_eq!("S", r.opcodes()[3].code); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes[3].body() { - assert_eq!("", s.value()); + assert_eq!("S", r.opcodes()[3].code()); + if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes()[3].body() { + assert_eq!("", *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Strval"); } diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index 682f69c0c..e2edf7a0f 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -19,29 +19,29 @@ fn test_switch_manual_str_else() { assert_eq!(4, r.opcodes().len()); assert_eq!("S", r.opcodes()[0].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Strval(s) = r.opcodes[0].body() { + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Strval(s) = r.opcodes()[0].body() { assert_eq!("foo", s.value()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Strval"); } assert_eq!("X", r.opcodes()[1].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes[1].body() { - assert_eq!(66, s.filler()); + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes()[1].body() { + assert_eq!(66, *s.filler()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); } assert_eq!("Y", r.opcodes()[2].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes[2].body() { - assert_eq!(51966, s.filler()); + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes()[2].body() { + assert_eq!(51966, *s.filler()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); } assert_eq!("I", r.opcodes()[3].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Intval(s) = r.opcodes[3].body() { - assert_eq!(7, s.value()); + if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Intval(s) = r.opcodes()[3].body() { + assert_eq!(7, *s.value()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Strval"); } diff --git a/spec/rust/tests/test_switch_multi_bool_ops.rs b/spec/rust/tests/test_switch_multi_bool_ops.rs index 800aadd51..6a6f1db84 100644 --- a/spec/rust/tests/test_switch_multi_bool_ops.rs +++ b/spec/rust/tests/test_switch_multi_bool_ops.rs @@ -17,13 +17,13 @@ fn test_switch_multi_bool_ops() { panic!("{:?}", err); } - assert_eq!(r.opcodes.len(), 4); - assert_eq!(r.opcodes[0 as usize].code(), 1); - assert_eq!(r.opcodes[0 as usize].body(), 7); - assert_eq!(r.opcodes[1 as usize].code(), 2); - assert_eq!(r.opcodes[1 as usize].body(), 16448); - assert_eq!(r.opcodes[2 as usize].code(), 4); - assert_eq!(r.opcodes[2 as usize].body(), 4919); - assert_eq!(r.opcodes[3 as usize].code(), 8); - assert_eq!(r.opcodes[3 as usize].body(), 4919); + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), 1); + assert_eq!(r.opcodes()[0 as usize].body(), 7); + assert_eq!(*r.opcodes()[1 as usize].code(), 2); + assert_eq!(r.opcodes()[1 as usize].body(), 16448); + assert_eq!(*r.opcodes()[2 as usize].code(), 4); + assert_eq!(r.opcodes()[2 as usize].body(), 4919); + assert_eq!(*r.opcodes()[3 as usize].code(), 8); + assert_eq!(r.opcodes()[3 as usize].body(), 4919); } diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs index 5231eb430..ad910b8a6 100644 --- a/spec/rust/tests/test_ts_packet_header.rs +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -16,11 +16,11 @@ fn test_ts_packet_header() { panic!("{:?}", err); } - assert_eq!(r.sync_byte(), 71); - assert_eq!(r.transport_error_indicator(), false); - assert_eq!(r.payload_unit_start_indicator(), false); - assert_eq!(r.transport_priority(), true); - assert_eq!(r.pid(), 33); - assert_eq!(r.transport_scrambling_control(), 0); + assert_eq!(*r.sync_byte(), 71); + assert_eq!(*r.transport_error_indicator(), false); + assert_eq!(*r.payload_unit_start_indicator(), false); + assert_eq!(*r.transport_priority(), true); + assert_eq!(*r.pid(), 33); + assert_eq!(*r.transport_scrambling_control(), 0); assert_eq!(*r.adaptation_field_control(), TsPacketHeader_AdaptationFieldControlEnum::PayloadOnly); } diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index 73f238ba7..818145467 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -16,8 +16,8 @@ fn test_type_int_unary_op() { panic!("{:?}", err); } - assert_eq!(r.value_s2(), 16720); - assert_eq!(r.value_s8(), 4706543082108963651); - assert_eq!(r.unary_s2(&reader).unwrap(), -16720); - assert_eq!(r.unary_s8(&reader).unwrap(), -4706543082108963651); + assert_eq!(*r.value_s2(), 16720); + assert_eq!(*r.value_s8(), 4706543082108963651); + assert_eq!(*r.unary_s2(&reader).unwrap(), -16720); + assert_eq!(*r.unary_s8(&reader).unwrap(), -4706543082108963651); } diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs index 83ec44e22..4f4cd2440 100644 --- a/spec/rust/tests/test_type_ternary.rs +++ b/spec/rust/tests/test_type_ternary.rs @@ -16,5 +16,5 @@ fn test_type_ternary() { panic!("{:?}", err); } - assert_eq!(r.dif(&reader).unwrap().value(), 101); + assert_eq!(*r.dif(&reader).unwrap().value(), 101); } From e3e28af67e4d3734a3575b2184c189c417040bae Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Sun, 7 Aug 2022 21:22:58 +0200 Subject: [PATCH 035/198] getSG(..., classSpecs) --- .../io/kaitai/struct/testtranslator/TestTranslator.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index f0660877f..50124fb7a 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -45,7 +45,7 @@ class TestTranslator(options: CLIOptions) { val provider = new ClassTypeProvider(classSpecs, initObj) langs.foreach(langName => { - val sg = getSG(langName, testSpec, provider) + val sg = getSG(langName, testSpec, provider, classSpecs) try { sg.run() val outFile = if(exactOutDir) { s"$outDir/${sg.fileName(testName)}" } else { s"$outDir/$langName/${sg.fileName(testName)}" } @@ -124,7 +124,7 @@ class TestTranslator(options: CLIOptions) { origSpecs } - def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider): BaseGenerator = lang match { + def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs): BaseGenerator = lang match { case "construct" => new ConstructSG(testSpec, provider) case "cpp_stl_98" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp98()) case "cpp_stl_11" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp11()) @@ -138,6 +138,6 @@ class TestTranslator(options: CLIOptions) { case "php" => new PHPSG(testSpec, provider) case "python" => new PythonSG(testSpec, provider) case "ruby" => new RubySG(testSpec, provider) - case "rust" => new RustSG(testSpec, provider) + case "rust" => new RustSG(testSpec, provider, classSpecs) } } From 262e0a0d7b9510fe3d8d53f2c7f06ab352ed8ab0 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Sun, 7 Aug 2022 21:28:04 +0200 Subject: [PATCH 036/198] add `?` if `attr` is an `instance` --- .../specgenerators/RustSG.scala | 39 ++++++++++++++++--- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index b100b999b..71a34a6d9 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -1,14 +1,15 @@ package io.kaitai.struct.testtranslator.specgenerators -import _root_.io.kaitai.struct.{ClassTypeProvider, RuntimeConfig} +import _root_.io.kaitai.struct.{ClassTypeProvider, JSON, RuntimeConfig} import _root_.io.kaitai.struct.datatype.{DataType, KSError} -import _root_.io.kaitai.struct.datatype.DataType._ import _root_.io.kaitai.struct.exprlang.Ast import _root_.io.kaitai.struct.languages.RustCompiler import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} import _root_.io.kaitai.struct.translators.RustTranslator +import io.kaitai.struct.exprlang.Ast.expr.Attribute +import io.kaitai.struct.format.{ClassSpecs, InstanceIdentifier} -class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(spec) { +class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs) extends BaseGenerator(spec) { val className = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) var do_panic = true; @@ -72,7 +73,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def simpleAssert(check: TestAssert): Unit = { val actStr = translateAct(check.actual) - var expStr = translator.translate(check.expected) + var expStr = translate(check.expected) finish_panic() out.puts(s"assert_eq!($actStr, $expStr);") } @@ -96,6 +97,34 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( out.result } + import pprint._ + + object Implicits { + implicit class CaseClassToString(c: AnyRef) { + def toStringWithFields: String = { + val fields = (Map[String, Any]() /: c.getClass.getDeclaredFields) { (a, f) => + f.setAccessible(true) + a + (f.getName -> f.get(c)) + } + + s"${c.getClass.getName}(${fields.mkString("\n")})" + } + } + } + + def translate(x: Ast.expr): String = { + val txt = translator.translate(x) + x match { + case Attribute(value, attr) => + if (classSpecs.firstSpec.instances.contains(InstanceIdentifier(attr.name))) { + s"$txt?" + } else { + txt + } + case _ => txt + } + } + def translateAct(x: Ast.expr) = - translator.translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") + translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") } From 8af7899bfa742f291df8763c85d5a87beb7523d6 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 8 Aug 2022 09:56:03 +0800 Subject: [PATCH 037/198] new tests added (expr_array, float_to_i, floating_points). --- formats_rust/expr_array.ksy | 50 +++++++++++++++++++++++++ formats_rust/float_to_i.ksy | 29 ++++++++++++++ formats_rust/floating_points.ksy | 21 +++++++++++ spec/rust/tests/test_expr_array.rs | 35 +++++++++++++++++ spec/rust/tests/test_float_to_i.rs | 28 ++++++++++++++ spec/rust/tests/test_floating_points.rs | 28 ++++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 formats_rust/expr_array.ksy create mode 100644 formats_rust/float_to_i.ksy create mode 100644 formats_rust/floating_points.ksy create mode 100644 spec/rust/tests/test_expr_array.rs create mode 100644 spec/rust/tests/test_float_to_i.rs create mode 100644 spec/rust/tests/test_floating_points.rs diff --git a/formats_rust/expr_array.ksy b/formats_rust/expr_array.ksy new file mode 100644 index 000000000..af08b8e91 --- /dev/null +++ b/formats_rust/expr_array.ksy @@ -0,0 +1,50 @@ +meta: + id: expr_array + endian: le + encoding: UTF-8 +seq: + - id: aint + type: u4 + repeat: expr + repeat-expr: 4 + - id: afloat + type: f8 + repeat: expr + repeat-expr: 3 + - id: astr + type: strz + repeat: expr + repeat-expr: 3 +instances: + aint_size: + value: aint.size + aint_first: + value: aint.first + aint_last: + value: aint.last + aint_min: + value: aint.min + aint_max: + value: aint.max + + afloat_size: + value: afloat.size + afloat_first: + value: afloat.first + afloat_last: + value: afloat.last + afloat_min: + value: afloat.min + afloat_max: + value: afloat.max + + astr_size: + value: astr.size + astr_first: + value: astr.first + astr_last: + value: astr.last + astr_min: + value: astr.min + astr_max: + value: astr.max diff --git a/formats_rust/float_to_i.ksy b/formats_rust/float_to_i.ksy new file mode 100644 index 000000000..6370838af --- /dev/null +++ b/formats_rust/float_to_i.ksy @@ -0,0 +1,29 @@ +meta: + id: float_to_i + endian: le +seq: + - id: single_value + type: f4 + - id: double_value + type: f8 +instances: + calc_float1: + value: 1.234 + calc_float2: + value: 1.5 + calc_float3: + value: 1.9 + calc_float4: + value: -2.7 + single_i: + value: single_value.to_i + double_i: + value: double_value.to_i + float1_i: + value: calc_float1.to_i + float2_i: + value: calc_float2.to_i + float3_i: + value: calc_float3.to_i + float4_i: + value: calc_float4.to_i diff --git a/formats_rust/floating_points.ksy b/formats_rust/floating_points.ksy new file mode 100644 index 000000000..a30880144 --- /dev/null +++ b/formats_rust/floating_points.ksy @@ -0,0 +1,21 @@ +meta: + id: floating_points + endian: le +seq: + - id: single_value + type: f4 + - id: double_value + type: f8 + - id: single_value_be + type: f4be + - id: double_value_be + type: f8be + - id: approximate_value + type: f4 +instances: + single_value_plus_int: + value: single_value + 1.0 # float + int doesn't work on rust + single_value_plus_float: + value: single_value + 0.5 + double_value_plus_float: + value: double_value + 0.05 diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs new file mode 100644 index 000000000..ce6f95d1f --- /dev/null +++ b/spec/rust/tests/test_expr_array.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_array::*; + +#[test] +fn test_expr_array() { + let bytes = fs::read("../../src/expr_array.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ExprArray::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.aint_size(&reader).unwrap(), 4); + assert_eq!(*r.aint_first(&reader).unwrap(), 7657765); + assert_eq!(*r.aint_last(&reader).unwrap(), 16272640); + assert_eq!(*r.aint_min(&reader).unwrap(), 49185); + assert_eq!(*r.aint_max(&reader).unwrap(), 1123362332); + assert_eq!(*r.afloat_size(&reader).unwrap(), 3); + assert_eq!(*r.afloat_first(&reader).unwrap(), -2.6839530254859364E-121); + assert_eq!(*r.afloat_last(&reader).unwrap(), -1.1103359815095273E-175); + assert_eq!(*r.afloat_min(&reader).unwrap(), -8.754689149998834E+288); + assert_eq!(*r.afloat_max(&reader).unwrap(), -1.1103359815095273E-175); + assert_eq!(*r.astr_size(&reader).unwrap(), 3); + assert_eq!(*r.astr_first(&reader).unwrap(), "foo"); + assert_eq!(*r.astr_last(&reader).unwrap(), "baz"); + assert_eq!(*r.astr_min(&reader).unwrap(), "bar"); + assert_eq!(*r.astr_max(&reader).unwrap(), "foo"); +} diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs new file mode 100644 index 000000000..6dce31ee0 --- /dev/null +++ b/spec/rust/tests/test_float_to_i.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::float_to_i::*; + +#[test] +fn test_float_to_i() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = FloatToI::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.single_value(), 0.5); + assert_eq!(*r.double_value(), 0.25); + assert_eq!(*r.single_i(&reader).unwrap(), 0); + assert_eq!(*r.double_i(&reader).unwrap(), 0); + assert_eq!(*r.float1_i(&reader).unwrap(), 1); + assert_eq!(*r.float2_i(&reader).unwrap(), 1); + assert_eq!(*r.float3_i(&reader).unwrap(), 1); + assert_eq!(*r.float4_i(&reader).unwrap(), -2); +} diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs new file mode 100644 index 000000000..8778be1e9 --- /dev/null +++ b/spec/rust/tests/test_floating_points.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::floating_points::*; + +#[test] +fn test_floating_points() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = FloatingPoints::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.single_value(), 0.5); + assert_eq!(*r.single_value_be(), 0.5); + assert_eq!(*r.double_value(), 0.25); + assert_eq!(*r.double_value_be(), 0.25); + assert_eq!(*r.approximate_value(), 1.2345); + assert_eq!(*r.single_value_plus_int(&reader).unwrap(), 1.5); + assert_eq!(*r.single_value_plus_float(&reader).unwrap(), 1.0); + assert_eq!(*r.double_value_plus_float(&reader).unwrap(), 0.3); +} From 998fc6de6f4840f95cab7db26cf812f99feff72c Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 8 Aug 2022 12:55:45 +0800 Subject: [PATCH 038/198] correct instance calling (with io). --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 71a34a6d9..2a844ede9 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -97,8 +97,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs out.result } - import pprint._ - object Implicits { implicit class CaseClassToString(c: AnyRef) { def toStringWithFields: String = { @@ -117,7 +115,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs x match { case Attribute(value, attr) => if (classSpecs.firstSpec.instances.contains(InstanceIdentifier(attr.name))) { - s"$txt?" + s"${txt.dropRight(2)}(&reader).unwrap()" } else { txt } From 85f94a0ed45b6cfa0d6d428369bf114ca116f9c0 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 8 Aug 2022 13:15:38 +0800 Subject: [PATCH 039/198] deref attr depend on type of attr. --- .../testtranslator/specgenerators/RustSG.scala | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 2a844ede9..fb3e48f2d 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -2,6 +2,7 @@ package io.kaitai.struct.testtranslator.specgenerators import _root_.io.kaitai.struct.{ClassTypeProvider, JSON, RuntimeConfig} import _root_.io.kaitai.struct.datatype.{DataType, KSError} +import io.kaitai.struct.datatype.DataType._ import _root_.io.kaitai.struct.exprlang.Ast import _root_.io.kaitai.struct.languages.RustCompiler import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} @@ -117,7 +118,22 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs if (classSpecs.firstSpec.instances.contains(InstanceIdentifier(attr.name))) { s"${txt.dropRight(2)}(&reader).unwrap()" } else { - txt + var deref = true; + val found = translator.get_attr(classSpecs.firstSpec, attr.name) + if (found.isDefined) { + deref = found.get.dataTypeComposite match { + case _: SwitchType => false + case _: UserType => false + case _: BytesType => false + case _: ArrayType => false + case _ => true + } + } + if (deref) { + txt + } else { + s"${translator.remove_deref(txt)}" + } } case _ => txt } From 11a047b9263b8063beb45ad01a22e734ec1899f7 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Mon, 8 Aug 2022 21:47:11 +0200 Subject: [PATCH 040/198] use translator.detectType(...) to correct references --- .../specgenerators/RustSG.scala | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 71a34a6d9..be0940fe2 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -6,6 +6,7 @@ import _root_.io.kaitai.struct.exprlang.Ast import _root_.io.kaitai.struct.languages.RustCompiler import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} import _root_.io.kaitai.struct.translators.RustTranslator +import io.kaitai.struct.datatype.DataType.{CalcBooleanType, EnumType} import io.kaitai.struct.exprlang.Ast.expr.Attribute import io.kaitai.struct.format.{ClassSpecs, InstanceIdentifier} @@ -22,8 +23,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs | |extern crate kaitai; |use self::kaitai::*; - |mod formats; - |use formats::${spec.id}::*; + |use crate::formats::${spec.id}::*; | |#[test] |fn test_${spec.id}() { @@ -72,8 +72,27 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } override def simpleAssert(check: TestAssert): Unit = { - val actStr = translateAct(check.actual) - var expStr = translate(check.expected) + val actType = translator.detectType(check.actual) + val expType = translator.detectType(check.expected) + val act = translateAct(check.actual) + val actStr = + actType match { + case EnumType(_, _) => //TODO: remove override def anyField(...) from RustTranslator + remove_deref(act) + case CalcBooleanType => + remove_deref(act) + case _ => translateAct(check.actual) + } + + val exp = translator.translate(check.expected) + val expStr = expType match { + case EnumType(_, _) => //TODO: remove override def anyField(...) from RustTranslator + remove_deref(exp) + case CalcBooleanType => + remove_deref(exp) + case _ => translator.translate(check.expected) + } + finish_panic() out.puts(s"assert_eq!($actStr, $expStr);") } @@ -97,34 +116,15 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs out.result } - import pprint._ - - object Implicits { - implicit class CaseClassToString(c: AnyRef) { - def toStringWithFields: String = { - val fields = (Map[String, Any]() /: c.getClass.getDeclaredFields) { (a, f) => - f.setAccessible(true) - a + (f.getName -> f.get(c)) - } - - s"${c.getClass.getName}(${fields.mkString("\n")})" - } - } - } + def translateAct(x: Ast.expr) = + translator.translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") - def translate(x: Ast.expr): String = { - val txt = translator.translate(x) - x match { - case Attribute(value, attr) => - if (classSpecs.firstSpec.instances.contains(InstanceIdentifier(attr.name))) { - s"$txt?" - } else { - txt - } - case _ => txt + def remove_deref(s: String): String = { + if (s.charAt(0) == '*') { + s.substring(1, s.length()) + } else { + s } } - def translateAct(x: Ast.expr) = - translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") } From de7efcd99774861e7e0fd7692698a30633577dda Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 9 Aug 2022 16:54:28 +0800 Subject: [PATCH 041/198] _parent tests. --- formats_rust/nav_parent.ksy | 33 +++++++++++++++++++++++++++ formats_rust/test_parent.ksy | 12 ++++++++++ spec/rust/tests/manual_test_parent.rs | 2 ++ spec/rust/tests/test_nav_parent.rs | 25 ++++++++++++++++++++ 4 files changed, 72 insertions(+) create mode 100644 formats_rust/nav_parent.ksy create mode 100644 spec/rust/tests/test_nav_parent.rs diff --git a/formats_rust/nav_parent.ksy b/formats_rust/nav_parent.ksy new file mode 100644 index 000000000..e2e554d2b --- /dev/null +++ b/formats_rust/nav_parent.ksy @@ -0,0 +1,33 @@ +meta: + id: nav_parent + endian: le +seq: + - id: header + type: header_obj + - id: index + type: index_obj +types: + header_obj: + seq: + - id: qty_entries + type: u4 + - id: filename_len + type: u4 + index_obj: + seq: + - id: magic + size: 4 + - id: entries + type: entry + repeat: expr + repeat-expr: _parent.header.qty_entries + types: + entry: + seq: + - id: filename + type: str + size: _parent._parent.header.filename_len + encoding: UTF-8 + +# here is kaitai bug +# this is fixed test with correct alignmnet \ No newline at end of file diff --git a/formats_rust/test_parent.ksy b/formats_rust/test_parent.ksy index b1d777eab..787f24995 100644 --- a/formats_rust/test_parent.ksy +++ b/formats_rust/test_parent.ksy @@ -21,4 +21,16 @@ types: type: u1 repeat: expr repeat-expr: _parent.child_byte + - id: child3_struct + type: child3_struct + repeat: expr + repeat-expr: _parent._parent.root_byte + types: + child3_struct: + seq: + - id: child3_byte + type: u1 + repeat: expr + repeat-expr: _parent._parent._parent.root_byte + diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs index 30624d663..723ad3f76 100644 --- a/spec/rust/tests/manual_test_parent.rs +++ b/spec/rust/tests/manual_test_parent.rs @@ -21,4 +21,6 @@ fn basic_parse() { assert_eq!(7, *r.child().child_byte()); assert_eq!(1, r.child().child2().len()); assert_eq!(vec![2, 64, 64, 4, 55, 19, 0], *r.child().child2()[0].child2_byte()); + assert_eq!(1, r.child().child2()[0].child3_struct().len()); + assert_eq!(vec![0], *r.child().child2()[0].child3_struct()[0].child3_byte()); } diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs new file mode 100644 index 000000000..5d51cf020 --- /dev/null +++ b/spec/rust/tests/test_nav_parent.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::nav_parent::*; + +#[test] +fn test_nav_parent() { + let bytes = fs::read("../../src/nav.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = NavParent::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.header().qty_entries(), 2); + assert_eq!(*r.header().filename_len(), 8); + assert_eq!(r.index().entries().len(), 2); + assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); + assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); +} From c65e6534a479dc30d3184ad1aa450983472350f6 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 9 Aug 2022 16:54:53 +0800 Subject: [PATCH 042/198] root test. --- formats_rust/nav_root.ksy | 29 +++++++++++++++++++++++++++++ spec/rust/tests/test_nav_root.rs | 25 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 formats_rust/nav_root.ksy create mode 100644 spec/rust/tests/test_nav_root.rs diff --git a/formats_rust/nav_root.ksy b/formats_rust/nav_root.ksy new file mode 100644 index 000000000..2072e6993 --- /dev/null +++ b/formats_rust/nav_root.ksy @@ -0,0 +1,29 @@ +meta: + id: nav_root + endian: le +seq: + - id: header + type: header_obj + - id: index + type: index_obj +types: + header_obj: + seq: + - id: qty_entries + type: u4 + - id: filename_len + type: u4 + index_obj: + seq: + - id: magic + size: 4 + - id: entries + type: entry + repeat: expr + repeat-expr: _root.header.qty_entries + entry: + seq: + - id: filename + type: str + size: _root.header.filename_len + encoding: UTF-8 diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs new file mode 100644 index 000000000..200bb4af9 --- /dev/null +++ b/spec/rust/tests/test_nav_root.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::nav_root::*; + +#[test] +fn test_nav_root() { + let bytes = fs::read("../../src/nav.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = NavRoot::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.header().qty_entries(), 2); + assert_eq!(*r.header().filename_len(), 8); + assert_eq!(r.index().entries().len(), 2); + assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); + assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); +} From 7fff52795b37c6ec34c8f452e67b78d27e4f8375 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 9 Aug 2022 16:55:13 +0800 Subject: [PATCH 043/198] expr_bytes_cmp test. --- formats_rust/expr_bytes_cmp.ksy | 31 ++++++++++++++++++++++++++ spec/rust/tests/test_expr_bytes_cmp.rs | 30 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 formats_rust/expr_bytes_cmp.ksy create mode 100644 spec/rust/tests/test_expr_bytes_cmp.rs diff --git a/formats_rust/expr_bytes_cmp.ksy b/formats_rust/expr_bytes_cmp.ksy new file mode 100644 index 000000000..5233b58ac --- /dev/null +++ b/formats_rust/expr_bytes_cmp.ksy @@ -0,0 +1,31 @@ +# Tests bytearray comparisons +meta: + id: expr_bytes_cmp +seq: + - id: one + size: 1 + - id: two + size: 3 +instances: + ack: + value: '[65, 67, 75]' + ack2: + value: '[65, 67, 75, 50]' + hi_val: + value: '[0x90, 67]' + is_eq: + value: two == ack + is_ne: + value: two != ack + is_lt: + value: two < ack2 + is_gt: + value: two > ack2 + is_le: + value: two <= ack2 + is_ge: + value: two >= ack2 + is_lt2: + value: one < two + is_gt2: + value: hi_val > two diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs new file mode 100644 index 000000000..5eb318358 --- /dev/null +++ b/spec/rust/tests/test_expr_bytes_cmp.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_bytes_cmp::*; + +#[test] +fn test_expr_bytes_cmp() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ExprBytesCmp::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(r.one(), &[0x50u8].to_vec()); + assert_eq!(r.two(), &[0x41u8, 0x43u8, 0x4bu8].to_vec()); + assert_eq!(*r.is_eq(&reader).unwrap(), true); + assert_eq!(*r.is_ne(&reader).unwrap(), false); + assert_eq!(*r.is_lt(&reader).unwrap(), true); + assert_eq!(*r.is_gt(&reader).unwrap(), false); + assert_eq!(*r.is_le(&reader).unwrap(), true); + assert_eq!(*r.is_ge(&reader).unwrap(), false); + assert_eq!(*r.is_lt2(&reader).unwrap(), false); + assert_eq!(*r.is_gt2(&reader).unwrap(), true); +} From 57b1ea62c4485bc84e0b25e87443458b70221d4c Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 9 Aug 2022 19:18:57 +0800 Subject: [PATCH 044/198] expr_bytes_non_literal added. --- formats_rust/expr_bytes_non_literal.ksy | 10 ++++++++ .../rust/tests/test_expr_bytes_non_literal.rs | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 formats_rust/expr_bytes_non_literal.ksy create mode 100644 spec/rust/tests/test_expr_bytes_non_literal.rs diff --git a/formats_rust/expr_bytes_non_literal.ksy b/formats_rust/expr_bytes_non_literal.ksy new file mode 100644 index 000000000..5f1ba49bf --- /dev/null +++ b/formats_rust/expr_bytes_non_literal.ksy @@ -0,0 +1,10 @@ +meta: + id: expr_bytes_non_literal +seq: + - id: one + type: u1 + - id: two + type: u1 +instances: + calc_bytes: + value: '[one, two].as' diff --git a/spec/rust/tests/test_expr_bytes_non_literal.rs b/spec/rust/tests/test_expr_bytes_non_literal.rs new file mode 100644 index 000000000..72653ebf5 --- /dev/null +++ b/spec/rust/tests/test_expr_bytes_non_literal.rs @@ -0,0 +1,23 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_bytes_non_literal::*; + +#[test] +fn test_expr_bytes_non_literal() { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ExprBytesNonLiteral::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(r.calc_bytes(&reader).unwrap().len(), 2); + assert_eq!(r.calc_bytes(&reader).unwrap()[0 as usize], 255); + assert_eq!(r.calc_bytes(&reader).unwrap()[1 as usize], 1); +} From a10e6cc73bc6b3ebecb5f06d74abc354e22390be Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Tue, 9 Aug 2022 21:31:37 +0200 Subject: [PATCH 045/198] up to date --- formats_rust/expr_array.ksy | 50 +++++++++++++++++++++++++ formats_rust/float_to_i.ksy | 29 ++++++++++++++ formats_rust/floating_points.ksy | 21 +++++++++++ spec/rust/tests/test_expr_array.rs | 35 +++++++++++++++++ spec/rust/tests/test_float_to_i.rs | 28 ++++++++++++++ spec/rust/tests/test_floating_points.rs | 28 ++++++++++++++ 6 files changed, 191 insertions(+) create mode 100644 formats_rust/expr_array.ksy create mode 100644 formats_rust/float_to_i.ksy create mode 100644 formats_rust/floating_points.ksy create mode 100644 spec/rust/tests/test_expr_array.rs create mode 100644 spec/rust/tests/test_float_to_i.rs create mode 100644 spec/rust/tests/test_floating_points.rs diff --git a/formats_rust/expr_array.ksy b/formats_rust/expr_array.ksy new file mode 100644 index 000000000..af08b8e91 --- /dev/null +++ b/formats_rust/expr_array.ksy @@ -0,0 +1,50 @@ +meta: + id: expr_array + endian: le + encoding: UTF-8 +seq: + - id: aint + type: u4 + repeat: expr + repeat-expr: 4 + - id: afloat + type: f8 + repeat: expr + repeat-expr: 3 + - id: astr + type: strz + repeat: expr + repeat-expr: 3 +instances: + aint_size: + value: aint.size + aint_first: + value: aint.first + aint_last: + value: aint.last + aint_min: + value: aint.min + aint_max: + value: aint.max + + afloat_size: + value: afloat.size + afloat_first: + value: afloat.first + afloat_last: + value: afloat.last + afloat_min: + value: afloat.min + afloat_max: + value: afloat.max + + astr_size: + value: astr.size + astr_first: + value: astr.first + astr_last: + value: astr.last + astr_min: + value: astr.min + astr_max: + value: astr.max diff --git a/formats_rust/float_to_i.ksy b/formats_rust/float_to_i.ksy new file mode 100644 index 000000000..6370838af --- /dev/null +++ b/formats_rust/float_to_i.ksy @@ -0,0 +1,29 @@ +meta: + id: float_to_i + endian: le +seq: + - id: single_value + type: f4 + - id: double_value + type: f8 +instances: + calc_float1: + value: 1.234 + calc_float2: + value: 1.5 + calc_float3: + value: 1.9 + calc_float4: + value: -2.7 + single_i: + value: single_value.to_i + double_i: + value: double_value.to_i + float1_i: + value: calc_float1.to_i + float2_i: + value: calc_float2.to_i + float3_i: + value: calc_float3.to_i + float4_i: + value: calc_float4.to_i diff --git a/formats_rust/floating_points.ksy b/formats_rust/floating_points.ksy new file mode 100644 index 000000000..a30880144 --- /dev/null +++ b/formats_rust/floating_points.ksy @@ -0,0 +1,21 @@ +meta: + id: floating_points + endian: le +seq: + - id: single_value + type: f4 + - id: double_value + type: f8 + - id: single_value_be + type: f4be + - id: double_value_be + type: f8be + - id: approximate_value + type: f4 +instances: + single_value_plus_int: + value: single_value + 1.0 # float + int doesn't work on rust + single_value_plus_float: + value: single_value + 0.5 + double_value_plus_float: + value: double_value + 0.05 diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs new file mode 100644 index 000000000..ce6f95d1f --- /dev/null +++ b/spec/rust/tests/test_expr_array.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_array::*; + +#[test] +fn test_expr_array() { + let bytes = fs::read("../../src/expr_array.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ExprArray::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.aint_size(&reader).unwrap(), 4); + assert_eq!(*r.aint_first(&reader).unwrap(), 7657765); + assert_eq!(*r.aint_last(&reader).unwrap(), 16272640); + assert_eq!(*r.aint_min(&reader).unwrap(), 49185); + assert_eq!(*r.aint_max(&reader).unwrap(), 1123362332); + assert_eq!(*r.afloat_size(&reader).unwrap(), 3); + assert_eq!(*r.afloat_first(&reader).unwrap(), -2.6839530254859364E-121); + assert_eq!(*r.afloat_last(&reader).unwrap(), -1.1103359815095273E-175); + assert_eq!(*r.afloat_min(&reader).unwrap(), -8.754689149998834E+288); + assert_eq!(*r.afloat_max(&reader).unwrap(), -1.1103359815095273E-175); + assert_eq!(*r.astr_size(&reader).unwrap(), 3); + assert_eq!(*r.astr_first(&reader).unwrap(), "foo"); + assert_eq!(*r.astr_last(&reader).unwrap(), "baz"); + assert_eq!(*r.astr_min(&reader).unwrap(), "bar"); + assert_eq!(*r.astr_max(&reader).unwrap(), "foo"); +} diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs new file mode 100644 index 000000000..6dce31ee0 --- /dev/null +++ b/spec/rust/tests/test_float_to_i.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::float_to_i::*; + +#[test] +fn test_float_to_i() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = FloatToI::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.single_value(), 0.5); + assert_eq!(*r.double_value(), 0.25); + assert_eq!(*r.single_i(&reader).unwrap(), 0); + assert_eq!(*r.double_i(&reader).unwrap(), 0); + assert_eq!(*r.float1_i(&reader).unwrap(), 1); + assert_eq!(*r.float2_i(&reader).unwrap(), 1); + assert_eq!(*r.float3_i(&reader).unwrap(), 1); + assert_eq!(*r.float4_i(&reader).unwrap(), -2); +} diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs new file mode 100644 index 000000000..8778be1e9 --- /dev/null +++ b/spec/rust/tests/test_floating_points.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::floating_points::*; + +#[test] +fn test_floating_points() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = FloatingPoints::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + + panic!("{:?}", err); + } + assert_eq!(*r.single_value(), 0.5); + assert_eq!(*r.single_value_be(), 0.5); + assert_eq!(*r.double_value(), 0.25); + assert_eq!(*r.double_value_be(), 0.25); + assert_eq!(*r.approximate_value(), 1.2345); + assert_eq!(*r.single_value_plus_int(&reader).unwrap(), 1.5); + assert_eq!(*r.single_value_plus_float(&reader).unwrap(), 1.0); + assert_eq!(*r.double_value_plus_float(&reader).unwrap(), 0.3); +} From 6abca996f80013555f6164b85764047d40bf1c31 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 10 Aug 2022 20:21:59 +0800 Subject: [PATCH 046/198] tests autogeneration fixed (edited tests commited). --- spec/rust/tests/test_enum_0.rs | 22 ----- spec/rust/tests/test_enum_1.rs | 22 ----- spec/rust/tests/test_enum_deep.rs | 22 ----- spec/rust/tests/test_expr_0.rs | 21 ---- spec/rust/tests/test_expr_1.rs | 28 ------ spec/rust/tests/test_expr_2.rs | 37 -------- spec/rust/tests/test_expr_3.rs | 32 ------- spec/rust/tests/test_expr_array.rs | 35 ------- spec/rust/tests/test_expr_bytes_cmp.rs | 30 ------ .../rust/tests/test_expr_bytes_non_literal.rs | 23 ----- spec/rust/tests/test_fixed_contents.rs | 19 ---- spec/rust/tests/test_float_to_i.rs | 28 ------ spec/rust/tests/test_floating_points.rs | 28 ------ spec/rust/tests/test_nav_parent.rs | 25 ----- spec/rust/tests/test_nav_root.rs | 25 ----- spec/rust/tests/test_process_coerce_bytes.rs | 26 ----- spec/rust/tests/test_process_rotate.rs | 22 ----- spec/rust/tests/test_process_to_user.rs | 20 ---- spec/rust/tests/test_process_xor4_const.rs | 21 ---- spec/rust/tests/test_process_xor4_value.rs | 21 ---- spec/rust/tests/test_process_xor_const.rs | 21 ---- spec/rust/tests/test_process_xor_value.rs | 21 ---- spec/rust/tests/test_str_encodings.rs | 23 ----- spec/rust/tests/test_str_encodings_default.rs | 23 ----- spec/rust/tests/test_str_encodings_utf16.rs | 25 ----- spec/rust/tests/test_str_eos.rs | 20 ---- spec/rust/tests/test_str_literals2.rs | 30 ------ spec/rust/tests/test_str_pad_term.rs | 23 ----- spec/rust/tests/test_str_pad_term_empty.rs | 25 ----- spec/rust/tests/test_switch_integers.rs | 28 ------ spec/rust/tests/test_switch_integers2.rs | 24 ----- spec/rust/tests/test_switch_multi_bool_ops.rs | 29 ------ spec/rust/tests/test_term_bytes.rs | 22 ----- spec/rust/tests/test_term_strz.rs | 22 ----- spec/rust/tests/test_term_u1_val.rs | 21 ---- spec/rust/tests/test_ts_packet_header.rs | 26 ----- spec/rust/tests/test_type_int_unary_op.rs | 23 ----- spec/rust/tests/test_type_ternary.rs | 20 ---- spec/rust/tests/test_valid_fail_anyof_int.rs | 21 ---- spec/rust/tests/test_valid_fail_contents.rs | 21 ---- spec/rust/tests/test_valid_fail_eq_bytes.rs | 21 ---- spec/rust/tests/test_valid_fail_eq_int.rs | 21 ---- spec/rust/tests/test_valid_fail_eq_str.rs | 21 ---- spec/rust/tests/test_valid_fail_expr.rs | 21 ---- spec/rust/tests/test_valid_fail_inst.rs | 21 ---- spec/rust/tests/test_valid_fail_max_int.rs | 21 ---- spec/rust/tests/test_valid_fail_min_int.rs | 21 ---- .../rust/tests/test_valid_fail_range_bytes.rs | 21 ---- .../rust/tests/test_valid_fail_range_float.rs | 21 ---- spec/rust/tests/test_valid_fail_range_int.rs | 21 ---- spec/rust/tests/test_valid_fail_range_str.rs | 21 ---- spec/rust/tests/test_valid_long.rs | 18 ---- spec/rust/tests/test_valid_not_parsed_if.rs | 18 ---- spec/rust/tests/test_valid_optional_id.rs | 18 ---- spec/rust/tests/test_valid_short.rs | 18 ---- spec/rust/tests/test_valid_switch.rs | 18 ---- .../specgenerators/RustSG.scala | 95 +++++++++++-------- 57 files changed, 56 insertions(+), 1335 deletions(-) delete mode 100644 spec/rust/tests/test_enum_0.rs delete mode 100644 spec/rust/tests/test_enum_1.rs delete mode 100644 spec/rust/tests/test_enum_deep.rs delete mode 100644 spec/rust/tests/test_expr_0.rs delete mode 100644 spec/rust/tests/test_expr_1.rs delete mode 100644 spec/rust/tests/test_expr_2.rs delete mode 100644 spec/rust/tests/test_expr_3.rs delete mode 100644 spec/rust/tests/test_expr_array.rs delete mode 100644 spec/rust/tests/test_expr_bytes_cmp.rs delete mode 100644 spec/rust/tests/test_expr_bytes_non_literal.rs delete mode 100644 spec/rust/tests/test_fixed_contents.rs delete mode 100644 spec/rust/tests/test_float_to_i.rs delete mode 100644 spec/rust/tests/test_floating_points.rs delete mode 100644 spec/rust/tests/test_nav_parent.rs delete mode 100644 spec/rust/tests/test_nav_root.rs delete mode 100644 spec/rust/tests/test_process_coerce_bytes.rs delete mode 100644 spec/rust/tests/test_process_rotate.rs delete mode 100644 spec/rust/tests/test_process_to_user.rs delete mode 100644 spec/rust/tests/test_process_xor4_const.rs delete mode 100644 spec/rust/tests/test_process_xor4_value.rs delete mode 100644 spec/rust/tests/test_process_xor_const.rs delete mode 100644 spec/rust/tests/test_process_xor_value.rs delete mode 100644 spec/rust/tests/test_str_encodings.rs delete mode 100644 spec/rust/tests/test_str_encodings_default.rs delete mode 100644 spec/rust/tests/test_str_encodings_utf16.rs delete mode 100644 spec/rust/tests/test_str_eos.rs delete mode 100644 spec/rust/tests/test_str_literals2.rs delete mode 100644 spec/rust/tests/test_str_pad_term.rs delete mode 100644 spec/rust/tests/test_str_pad_term_empty.rs delete mode 100644 spec/rust/tests/test_switch_integers.rs delete mode 100644 spec/rust/tests/test_switch_integers2.rs delete mode 100644 spec/rust/tests/test_switch_multi_bool_ops.rs delete mode 100644 spec/rust/tests/test_term_bytes.rs delete mode 100644 spec/rust/tests/test_term_strz.rs delete mode 100644 spec/rust/tests/test_term_u1_val.rs delete mode 100644 spec/rust/tests/test_ts_packet_header.rs delete mode 100644 spec/rust/tests/test_type_int_unary_op.rs delete mode 100644 spec/rust/tests/test_type_ternary.rs delete mode 100644 spec/rust/tests/test_valid_fail_anyof_int.rs delete mode 100644 spec/rust/tests/test_valid_fail_contents.rs delete mode 100644 spec/rust/tests/test_valid_fail_eq_bytes.rs delete mode 100644 spec/rust/tests/test_valid_fail_eq_int.rs delete mode 100644 spec/rust/tests/test_valid_fail_eq_str.rs delete mode 100644 spec/rust/tests/test_valid_fail_expr.rs delete mode 100644 spec/rust/tests/test_valid_fail_inst.rs delete mode 100644 spec/rust/tests/test_valid_fail_max_int.rs delete mode 100644 spec/rust/tests/test_valid_fail_min_int.rs delete mode 100644 spec/rust/tests/test_valid_fail_range_bytes.rs delete mode 100644 spec/rust/tests/test_valid_fail_range_float.rs delete mode 100644 spec/rust/tests/test_valid_fail_range_int.rs delete mode 100644 spec/rust/tests/test_valid_fail_range_str.rs delete mode 100644 spec/rust/tests/test_valid_long.rs delete mode 100644 spec/rust/tests/test_valid_not_parsed_if.rs delete mode 100644 spec/rust/tests/test_valid_optional_id.rs delete mode 100644 spec/rust/tests/test_valid_short.rs delete mode 100644 spec/rust/tests/test_valid_switch.rs diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs deleted file mode 100644 index ae5e979b3..000000000 --- a/spec/rust/tests/test_enum_0.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::enum_0::*; - -#[test] -fn test_enum_0() { - let bytes = fs::read("../../src/enum_0.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = Enum0::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.pet_1(), &Enum0_Animal::Cat); - assert_eq!(r.pet_2(), &Enum0_Animal::Chicken); -} diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs deleted file mode 100644 index 5f477865c..000000000 --- a/spec/rust/tests/test_enum_1.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::enum_1::*; - -#[test] -fn test_enum_1() { - let bytes = fs::read("../../src/enum_0.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = Enum1::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.main().submain().pet_1(), &Enum1_MainObj_Animal::Cat); - assert_eq!(r.main().submain().pet_2(), &Enum1_MainObj_Animal::Chicken); -} diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs deleted file mode 100644 index 754dc1501..000000000 --- a/spec/rust/tests/test_enum_deep.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::enum_deep::*; - -#[test] -fn test_enum_deep() { - let bytes = fs::read("../../src/enum_0.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = EnumDeep::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.pet_1(), &EnumDeep_Container1_Animal::Cat); - assert_eq!(r.pet_2(), &EnumDeep_Container1_Container2_Animal::Hare); -} diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs deleted file mode 100644 index 5b9c4e67e..000000000 --- a/spec/rust/tests/test_expr_0.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::expr_0::*; - -#[test] -fn test_expr_0() { - let bytes = fs::read("../../src/str_encodings.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = Expr0::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.must_be_f7(&reader).unwrap(), 247); - assert_eq!(*r.must_be_abc123(&reader).unwrap(), "abc123"); -} diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs deleted file mode 100644 index 20a9603e6..000000000 --- a/spec/rust/tests/test_expr_1.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::expr_1::*; - -#[test] -fn test_expr_1() { - let bytes = fs::read("../../src/str_encodings.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = Expr1::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(10, *r.len_of_1()); - - let res = r.len_of_1_mod(&reader); - assert_eq!(8, *res.unwrap()); - - assert_eq!("Some ASC", *r.str1()); - - let res = r.str1_len(&reader); - assert_eq!(8, *res.unwrap()); -} diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs deleted file mode 100644 index 7d0736449..000000000 --- a/spec/rust/tests/test_expr_2.rs +++ /dev/null @@ -1,37 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::expr_2::*; - -#[test] -fn test_expr_2() { - let bytes = fs::read("../../src/str_encodings.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = Expr2::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.str1().len_orig(), 10); - assert_eq!(*r.str1().len_mod(&reader).unwrap(), 7); - assert_eq!(*r.str1().str(), "Some AS"); - assert_eq!(*r.str1_len(&reader).unwrap(), 7); - assert_eq!(*r.str1_len_mod(&reader).unwrap(), 7); - assert_eq!(*r.str1_byte1(&reader).unwrap(), 73); - assert_eq!(*r.str1_avg(&reader).unwrap(), 73); - assert_eq!(*r.str1_char5(&reader).unwrap(), "e"); - assert_eq!(*r.str1_tuple5(&reader).unwrap().byte0(), 101); - assert_eq!(*r.str1_tuple5(&reader).unwrap().byte0(), 101); - assert_eq!(*r.str1_tuple5(&reader).unwrap().byte1(), 32); - assert_eq!(*r.str1_tuple5(&reader).unwrap().byte2(), 65); - assert_eq!(*r.str1_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); - assert_eq!(*r.str2_tuple5(&reader).unwrap().byte0(), 101); - assert_eq!(*r.str2_tuple5(&reader).unwrap().byte1(), 32); - assert_eq!(*r.str2_tuple5(&reader).unwrap().byte2(), 65); - assert_eq!(*r.str2_tuple5(&reader).unwrap().avg(&reader).unwrap(), 48); -} diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs deleted file mode 100644 index 37ab49d6b..000000000 --- a/spec/rust/tests/test_expr_3.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::expr_3::*; - -#[test] -fn test_expr_3() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = Expr3::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.one(), 80); - assert_eq!(*r.two(), "ACK"); - assert_eq!(*r.three(&reader).unwrap(), "@ACK"); - assert_eq!(*r.four(&reader).unwrap(), "_ACK_"); - assert_eq!(*r.is_str_eq(&reader).unwrap(), true); - assert_eq!(*r.is_str_ne(&reader).unwrap(), false); - assert_eq!(*r.is_str_lt(&reader).unwrap(), true); - assert_eq!(*r.is_str_gt(&reader).unwrap(), false); - assert_eq!(*r.is_str_le(&reader).unwrap(), true); - assert_eq!(*r.is_str_ge(&reader).unwrap(), false); - assert_eq!(*r.is_str_lt2(&reader).unwrap(), true); - assert_eq!(*r.test_not(&reader).unwrap(), true); -} diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs deleted file mode 100644 index ce6f95d1f..000000000 --- a/spec/rust/tests/test_expr_array.rs +++ /dev/null @@ -1,35 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::expr_array::*; - -#[test] -fn test_expr_array() { - let bytes = fs::read("../../src/expr_array.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ExprArray::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.aint_size(&reader).unwrap(), 4); - assert_eq!(*r.aint_first(&reader).unwrap(), 7657765); - assert_eq!(*r.aint_last(&reader).unwrap(), 16272640); - assert_eq!(*r.aint_min(&reader).unwrap(), 49185); - assert_eq!(*r.aint_max(&reader).unwrap(), 1123362332); - assert_eq!(*r.afloat_size(&reader).unwrap(), 3); - assert_eq!(*r.afloat_first(&reader).unwrap(), -2.6839530254859364E-121); - assert_eq!(*r.afloat_last(&reader).unwrap(), -1.1103359815095273E-175); - assert_eq!(*r.afloat_min(&reader).unwrap(), -8.754689149998834E+288); - assert_eq!(*r.afloat_max(&reader).unwrap(), -1.1103359815095273E-175); - assert_eq!(*r.astr_size(&reader).unwrap(), 3); - assert_eq!(*r.astr_first(&reader).unwrap(), "foo"); - assert_eq!(*r.astr_last(&reader).unwrap(), "baz"); - assert_eq!(*r.astr_min(&reader).unwrap(), "bar"); - assert_eq!(*r.astr_max(&reader).unwrap(), "foo"); -} diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs deleted file mode 100644 index 5eb318358..000000000 --- a/spec/rust/tests/test_expr_bytes_cmp.rs +++ /dev/null @@ -1,30 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::expr_bytes_cmp::*; - -#[test] -fn test_expr_bytes_cmp() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ExprBytesCmp::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.one(), &[0x50u8].to_vec()); - assert_eq!(r.two(), &[0x41u8, 0x43u8, 0x4bu8].to_vec()); - assert_eq!(*r.is_eq(&reader).unwrap(), true); - assert_eq!(*r.is_ne(&reader).unwrap(), false); - assert_eq!(*r.is_lt(&reader).unwrap(), true); - assert_eq!(*r.is_gt(&reader).unwrap(), false); - assert_eq!(*r.is_le(&reader).unwrap(), true); - assert_eq!(*r.is_ge(&reader).unwrap(), false); - assert_eq!(*r.is_lt2(&reader).unwrap(), false); - assert_eq!(*r.is_gt2(&reader).unwrap(), true); -} diff --git a/spec/rust/tests/test_expr_bytes_non_literal.rs b/spec/rust/tests/test_expr_bytes_non_literal.rs deleted file mode 100644 index 72653ebf5..000000000 --- a/spec/rust/tests/test_expr_bytes_non_literal.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::expr_bytes_non_literal::*; - -#[test] -fn test_expr_bytes_non_literal() { - let bytes = fs::read("../../src/enum_negative.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ExprBytesNonLiteral::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.calc_bytes(&reader).unwrap().len(), 2); - assert_eq!(r.calc_bytes(&reader).unwrap()[0 as usize], 255); - assert_eq!(r.calc_bytes(&reader).unwrap()[1 as usize], 1); -} diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs deleted file mode 100644 index 42c2c53c8..000000000 --- a/spec/rust/tests/test_fixed_contents.rs +++ /dev/null @@ -1,19 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::fixed_contents::*; - -#[test] -fn test_fixed_contents() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = FixedContents::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } -} diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs deleted file mode 100644 index 6dce31ee0..000000000 --- a/spec/rust/tests/test_float_to_i.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::float_to_i::*; - -#[test] -fn test_float_to_i() { - let bytes = fs::read("../../src/floating_points.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = FloatToI::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.single_value(), 0.5); - assert_eq!(*r.double_value(), 0.25); - assert_eq!(*r.single_i(&reader).unwrap(), 0); - assert_eq!(*r.double_i(&reader).unwrap(), 0); - assert_eq!(*r.float1_i(&reader).unwrap(), 1); - assert_eq!(*r.float2_i(&reader).unwrap(), 1); - assert_eq!(*r.float3_i(&reader).unwrap(), 1); - assert_eq!(*r.float4_i(&reader).unwrap(), -2); -} diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs deleted file mode 100644 index 8778be1e9..000000000 --- a/spec/rust/tests/test_floating_points.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::floating_points::*; - -#[test] -fn test_floating_points() { - let bytes = fs::read("../../src/floating_points.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = FloatingPoints::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.single_value(), 0.5); - assert_eq!(*r.single_value_be(), 0.5); - assert_eq!(*r.double_value(), 0.25); - assert_eq!(*r.double_value_be(), 0.25); - assert_eq!(*r.approximate_value(), 1.2345); - assert_eq!(*r.single_value_plus_int(&reader).unwrap(), 1.5); - assert_eq!(*r.single_value_plus_float(&reader).unwrap(), 1.0); - assert_eq!(*r.double_value_plus_float(&reader).unwrap(), 0.3); -} diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs deleted file mode 100644 index 5d51cf020..000000000 --- a/spec/rust/tests/test_nav_parent.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::nav_parent::*; - -#[test] -fn test_nav_parent() { - let bytes = fs::read("../../src/nav.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = NavParent::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.header().qty_entries(), 2); - assert_eq!(*r.header().filename_len(), 8); - assert_eq!(r.index().entries().len(), 2); - assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); - assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); -} diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs deleted file mode 100644 index 200bb4af9..000000000 --- a/spec/rust/tests/test_nav_root.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::nav_root::*; - -#[test] -fn test_nav_root() { - let bytes = fs::read("../../src/nav.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = NavRoot::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.header().qty_entries(), 2); - assert_eq!(*r.header().filename_len(), 8); - assert_eq!(r.index().entries().len(), 2); - assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); - assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); -} diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs deleted file mode 100644 index 4a72e8a67..000000000 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_coerce_bytes::*; - -#[test] -fn test_process_coerce_bytes() { - let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ProcessCoerceBytes::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(0, *r.records()[0].flag()); - let buf : Vec = vec![0x41, 0x41, 0x41, 0x41]; - assert_eq!(buf, *r.records()[0].buf(&reader).unwrap()); - - assert_eq!(1, *r.records()[1].flag()); - let buf : Vec = vec![0x42, 0x42, 0x42, 0x42]; - assert_eq!(buf, *r.records()[1].buf(&reader).unwrap()); -} diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs deleted file mode 100644 index 7f9348fa0..000000000 --- a/spec/rust/tests/test_process_rotate.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_rotate::*; - -#[test] -fn test_process_rotate() { - let bytes = fs::read("../../src/process_rotate.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ProcessRotate::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.buf1(), [0x48u8, 0x65u8, 0x6cu8, 0x6cu8, 0x6fu8].to_vec()); - assert_eq!(*r.buf2(), [0x57u8, 0x6fu8, 0x72u8, 0x6cu8, 0x64u8].to_vec()); - assert_eq!(*r.buf3(), [0x54u8, 0x68u8, 0x65u8, 0x72u8, 0x65u8].to_vec()); -} diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs deleted file mode 100644 index a4f51ea52..000000000 --- a/spec/rust/tests/test_process_to_user.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_to_user::*; - -#[test] -fn test_process_to_user() { - let bytes = fs::read("../../src/process_rotate.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ProcessToUser::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.buf1().str(), "Hello"); -} diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs deleted file mode 100644 index 3b7664019..000000000 --- a/spec/rust/tests/test_process_xor4_const.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_xor4_const::*; - -#[test] -fn test_process_xor4_const() { - let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ProcessXor4Const::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.key(), [0xecu8, 0xbbu8, 0xa3u8, 0x14u8].to_vec()); - assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); -} diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs deleted file mode 100644 index a06108647..000000000 --- a/spec/rust/tests/test_process_xor4_value.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_xor4_value::*; - -#[test] -fn test_process_xor4_value() { - let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ProcessXor4Value::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.key(), [0xecu8, 0xbbu8, 0xa3u8, 0x14u8].to_vec()); - assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); -} diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs deleted file mode 100644 index 2ea2c0dce..000000000 --- a/spec/rust/tests/test_process_xor_const.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_xor_const::*; - -#[test] -fn test_process_xor_const() { - let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ProcessXorConst::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.key(), 255); - assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); -} diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs deleted file mode 100644 index 9f642f04e..000000000 --- a/spec/rust/tests/test_process_xor_value.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_xor_value::*; - -#[test] -fn test_process_xor_value() { - let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ProcessXorValue::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.key(), 255); - assert_eq!(*r.buf(), [0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8].to_vec()); -} diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs deleted file mode 100644 index a9d521b95..000000000 --- a/spec/rust/tests/test_str_encodings.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_encodings::*; - -#[test] -fn test_str_encodings() { - let bytes = fs::read("../../src/str_encodings.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = StrEncodings::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.str1(), "Some ASCII"); - assert_eq!(r.str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.str4(), "\u{2591}\u{2592}\u{2593}"); -} diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs deleted file mode 100644 index ee455ca4f..000000000 --- a/spec/rust/tests/test_str_encodings_default.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_encodings_default::*; - -#[test] -fn test_str_encodings_default() { - let bytes = fs::read("../../src/str_encodings.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = StrEncodingsDefault::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.str1(), "Some ASCII"); - assert_eq!(r.rest().str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.rest().str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(r.rest().str4(), "\u{2591}\u{2592}\u{2593}"); -} diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs deleted file mode 100644 index d0b70629e..000000000 --- a/spec/rust/tests/test_str_encodings_utf16.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_encodings_utf16::*; - -#[test] -fn test_str_encodings_utf16() { - let bytes = fs::read("../../src/str_encodings_utf16.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = StrEncodingsUtf16::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.len_be(), 12); - assert_eq!(*r.be_bom_removed().bom(), 65279); - assert_eq!(r.be_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); - assert_eq!(*r.len_le(), 12); - assert_eq!(*r.le_bom_removed().bom(), 65279); - assert_eq!(r.le_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); -} diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs deleted file mode 100644 index 554b0e1db..000000000 --- a/spec/rust/tests/test_str_eos.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_eos::*; - -#[test] -fn test_str_eos() { - let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = StrEos::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.str(), "foo|bar|baz@"); -} diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs deleted file mode 100644 index 8cf6beb9f..000000000 --- a/spec/rust/tests/test_str_literals2.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_literals2::*; - -#[test] -fn test_str_literals2() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = StrLiterals2::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - let dollar1 = r.dollar1(&reader).unwrap(); - assert_eq!("$foo", *dollar1); - - let dollar2 = r.dollar2(&reader).unwrap(); - assert_eq!("${foo}", *dollar2); - - let hash = r.hash(&reader).unwrap(); - assert_eq!("#{foo}", *hash); - - let at_sign = r.at_sign(&reader).unwrap(); - assert_eq!("@foo", *at_sign); -} diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs deleted file mode 100644 index 2dc9d5176..000000000 --- a/spec/rust/tests/test_str_pad_term.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_pad_term::*; - -#[test] -fn test_str_pad_term() { - let bytes = fs::read("../../src/str_pad_term.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = StrPadTerm::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.str_pad(), "str1"); - assert_eq!(r.str_term(), "str2foo"); - assert_eq!(r.str_term_and_pad(), "str+++3bar+++"); - assert_eq!(r.str_term_include(), "str4baz@"); -} diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs deleted file mode 100644 index 0f0816eb8..000000000 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_pad_term_empty::*; - -#[test] -fn test_str_pad_term_empty() { - let bytes = fs::read("../../src/str_pad_term_empty.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = StrPadTermEmpty::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.str_pad(), ""); - assert_eq!(r.str_term(), ""); - assert_eq!(r.str_term_and_pad(), ""); - assert_eq!(r.str_term_include(), "@"); -} diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs deleted file mode 100644 index a22458401..000000000 --- a/spec/rust/tests/test_switch_integers.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_integers::*; - -#[test] -fn test_switch_integers() { - let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = SwitchIntegers::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.opcodes().len(), 4); - assert_eq!(*r.opcodes()[0 as usize].code(), 1); - assert_eq!(r.opcodes()[0 as usize].body(), 7); - assert_eq!(*r.opcodes()[1 as usize].code(), 2); - assert_eq!(r.opcodes()[1 as usize].body(), 16448); - assert_eq!(*r.opcodes()[2 as usize].code(), 4); - assert_eq!(r.opcodes()[2 as usize].body(), 4919); - assert_eq!(*r.opcodes()[3 as usize].code(), 8); - assert_eq!(r.opcodes()[3 as usize].body(), 4919); -} diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs deleted file mode 100644 index f910519f8..000000000 --- a/spec/rust/tests/test_switch_integers2.rs +++ /dev/null @@ -1,24 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_integers2::*; - -#[test] -fn test_switch_integers2() { - let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = SwitchIntegers2::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.code(), 1); - assert_eq!(r.len(), 7); - assert_eq!(r.ham(), &[0x2u8, 0x40u8, 0x40u8, 0x4u8, 0x37u8, 0x13u8, 0x0u8].to_vec()); - assert_eq!(*r.padding(), 0); - assert_eq!(*r.len_mod_str(&reader).unwrap(), "13"); -} diff --git a/spec/rust/tests/test_switch_multi_bool_ops.rs b/spec/rust/tests/test_switch_multi_bool_ops.rs deleted file mode 100644 index 6a6f1db84..000000000 --- a/spec/rust/tests/test_switch_multi_bool_ops.rs +++ /dev/null @@ -1,29 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_multi_bool_ops::*; - -#[test] -fn test_switch_multi_bool_ops() { - let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = SwitchMultiBoolOps::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.opcodes().len(), 4); - assert_eq!(*r.opcodes()[0 as usize].code(), 1); - assert_eq!(r.opcodes()[0 as usize].body(), 7); - assert_eq!(*r.opcodes()[1 as usize].code(), 2); - assert_eq!(r.opcodes()[1 as usize].body(), 16448); - assert_eq!(*r.opcodes()[2 as usize].code(), 4); - assert_eq!(r.opcodes()[2 as usize].body(), 4919); - assert_eq!(*r.opcodes()[3 as usize].code(), 8); - assert_eq!(r.opcodes()[3 as usize].body(), 4919); -} diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs deleted file mode 100644 index 240545922..000000000 --- a/spec/rust/tests/test_term_bytes.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::term_bytes::*; - -#[test] -fn test_term_bytes() { - let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = TermBytes::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.s1(), [0x66u8, 0x6fu8, 0x6fu8].to_vec()); - assert_eq!(*r.s2(), [0x62u8, 0x61u8, 0x72u8].to_vec()); - assert_eq!(*r.s3(), [0x7cu8, 0x62u8, 0x61u8, 0x7au8, 0x40u8].to_vec()); -} diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs deleted file mode 100644 index b3f38fdcf..000000000 --- a/spec/rust/tests/test_term_strz.rs +++ /dev/null @@ -1,22 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::term_strz::*; - -#[test] -fn test_term_strz() { - let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = TermStrz::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(r.s1(), "foo"); - assert_eq!(r.s2(), "bar"); - assert_eq!(r.s3(), "|baz@"); -} diff --git a/spec/rust/tests/test_term_u1_val.rs b/spec/rust/tests/test_term_u1_val.rs deleted file mode 100644 index ac7e7717a..000000000 --- a/spec/rust/tests/test_term_u1_val.rs +++ /dev/null @@ -1,21 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::term_u1_val::*; - -#[test] -fn test_term_u1_val() { - let bytes = fs::read("../../src/str_encodings.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = TermU1Val::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.foo(), [0xau8, 0x0u8, 0x53u8, 0x6fu8, 0x6du8, 0x65u8, 0x20u8, 0x41u8, 0x53u8, 0x43u8, 0x49u8, 0x49u8, 0xfu8, 0x0u8].to_vec()); - assert_eq!(r.bar(), "\u{3053}\u{3093}\u{306b}"); -} diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs deleted file mode 100644 index ad910b8a6..000000000 --- a/spec/rust/tests/test_ts_packet_header.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::ts_packet_header::*; - -#[test] -fn test_ts_packet_header() { - let bytes = fs::read("../../src/ts_packet.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = TsPacketHeader::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.sync_byte(), 71); - assert_eq!(*r.transport_error_indicator(), false); - assert_eq!(*r.payload_unit_start_indicator(), false); - assert_eq!(*r.transport_priority(), true); - assert_eq!(*r.pid(), 33); - assert_eq!(*r.transport_scrambling_control(), 0); - assert_eq!(*r.adaptation_field_control(), TsPacketHeader_AdaptationFieldControlEnum::PayloadOnly); -} diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs deleted file mode 100644 index 818145467..000000000 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ /dev/null @@ -1,23 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::type_int_unary_op::*; - -#[test] -fn test_type_int_unary_op() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = TypeIntUnaryOp::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.value_s2(), 16720); - assert_eq!(*r.value_s8(), 4706543082108963651); - assert_eq!(*r.unary_s2(&reader).unwrap(), -16720); - assert_eq!(*r.unary_s8(&reader).unwrap(), -4706543082108963651); -} diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs deleted file mode 100644 index 4f4cd2440..000000000 --- a/spec/rust/tests/test_type_ternary.rs +++ /dev/null @@ -1,20 +0,0 @@ -#![allow(dead_code)] -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::type_ternary::*; - -#[test] -fn test_type_ternary() { - let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = TypeTernary::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } - assert_eq!(*r.dif(&reader).unwrap().value(), 101); -} diff --git a/spec/rust/tests/test_valid_fail_anyof_int.rs b/spec/rust/tests/test_valid_fail_anyof_int.rs deleted file mode 100644 index 2b77295db..000000000 --- a/spec/rust/tests/test_valid_fail_anyof_int.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_anyof_int::*; - -#[test] -fn test_valid_fail_anyof_int() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailAnyofInt::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationNotAnyOfError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationNotAnyOfError(Int1Type(false))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_contents.rs b/spec/rust/tests/test_valid_fail_contents.rs deleted file mode 100644 index 73ce1626f..000000000 --- a/spec/rust/tests/test_valid_fail_contents.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_contents::*; - -#[test] -fn test_valid_fail_contents() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailContents::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); - } else { - panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); - } -} diff --git a/spec/rust/tests/test_valid_fail_eq_bytes.rs b/spec/rust/tests/test_valid_fail_eq_bytes.rs deleted file mode 100644 index 0a76ed491..000000000 --- a/spec/rust/tests/test_valid_fail_eq_bytes.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_eq_bytes::*; - -#[test] -fn test_valid_fail_eq_bytes() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailEqBytes::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); - } else { - panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); - } -} diff --git a/spec/rust/tests/test_valid_fail_eq_int.rs b/spec/rust/tests/test_valid_fail_eq_int.rs deleted file mode 100644 index 59779cbf3..000000000 --- a/spec/rust/tests/test_valid_fail_eq_int.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_eq_int::*; - -#[test] -fn test_valid_fail_eq_int() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailEqInt::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_eq_str.rs b/spec/rust/tests/test_valid_fail_eq_str.rs deleted file mode 100644 index 494ebc5ae..000000000 --- a/spec/rust/tests/test_valid_fail_eq_str.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_eq_str::*; - -#[test] -fn test_valid_fail_eq_str() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailEqStr::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationNotEqualError(CalcStrType)", err); - } else { - panic!("no expected exception: ValidationNotEqualError(CalcStrType)"); - } -} diff --git a/spec/rust/tests/test_valid_fail_expr.rs b/spec/rust/tests/test_valid_fail_expr.rs deleted file mode 100644 index a5d9a1e92..000000000 --- a/spec/rust/tests/test_valid_fail_expr.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_expr::*; - -#[test] -fn test_valid_fail_expr() { - let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailExpr::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationExprError(IntMultiType(true,Width2,None))", err); - } else { - panic!("no expected exception: ValidationExprError(IntMultiType(true,Width2,None))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_inst.rs b/spec/rust/tests/test_valid_fail_inst.rs deleted file mode 100644 index 8097e4036..000000000 --- a/spec/rust/tests/test_valid_fail_inst.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_inst::*; - -#[test] -fn test_valid_fail_inst() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailInst::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_max_int.rs b/spec/rust/tests/test_valid_fail_max_int.rs deleted file mode 100644 index 886b9fcf8..000000000 --- a/spec/rust/tests/test_valid_fail_max_int.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_max_int::*; - -#[test] -fn test_valid_fail_max_int() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailMaxInt::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_min_int.rs b/spec/rust/tests/test_valid_fail_min_int.rs deleted file mode 100644 index e02427ac6..000000000 --- a/spec/rust/tests/test_valid_fail_min_int.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_min_int::*; - -#[test] -fn test_valid_fail_min_int() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailMinInt::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationLessThanError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationLessThanError(Int1Type(false))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_range_bytes.rs b/spec/rust/tests/test_valid_fail_range_bytes.rs deleted file mode 100644 index 3440a01cf..000000000 --- a/spec/rust/tests/test_valid_fail_range_bytes.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_range_bytes::*; - -#[test] -fn test_valid_fail_range_bytes() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailRangeBytes::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcBytesType)", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(CalcBytesType)"); - } -} diff --git a/spec/rust/tests/test_valid_fail_range_float.rs b/spec/rust/tests/test_valid_fail_range_float.rs deleted file mode 100644 index b77e1bf6d..000000000 --- a/spec/rust/tests/test_valid_fail_range_float.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_range_float::*; - -#[test] -fn test_valid_fail_range_float() { - let bytes = fs::read("../../src/floating_points.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailRangeFloat::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationGreaterThanError(FloatMultiType(Width4,None))", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(FloatMultiType(Width4,None))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_range_int.rs b/spec/rust/tests/test_valid_fail_range_int.rs deleted file mode 100644 index f1cf3c9e0..000000000 --- a/spec/rust/tests/test_valid_fail_range_int.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_range_int::*; - -#[test] -fn test_valid_fail_range_int() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailRangeInt::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); - } -} diff --git a/spec/rust/tests/test_valid_fail_range_str.rs b/spec/rust/tests/test_valid_fail_range_str.rs deleted file mode 100644 index 9621c39c6..000000000 --- a/spec/rust/tests/test_valid_fail_range_str.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_fail_range_str::*; - -#[test] -fn test_valid_fail_range_str() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidFailRangeStr::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcStrType)", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(CalcStrType)"); - } -} diff --git a/spec/rust/tests/test_valid_long.rs b/spec/rust/tests/test_valid_long.rs deleted file mode 100644 index 590035ba9..000000000 --- a/spec/rust/tests/test_valid_long.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_long::*; - -#[test] -fn test_valid_long() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidLong::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } -} diff --git a/spec/rust/tests/test_valid_not_parsed_if.rs b/spec/rust/tests/test_valid_not_parsed_if.rs deleted file mode 100644 index 52107f5b1..000000000 --- a/spec/rust/tests/test_valid_not_parsed_if.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_not_parsed_if::*; - -#[test] -fn test_valid_not_parsed_if() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidNotParsedIf::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } -} diff --git a/spec/rust/tests/test_valid_optional_id.rs b/spec/rust/tests/test_valid_optional_id.rs deleted file mode 100644 index 84e2248cb..000000000 --- a/spec/rust/tests/test_valid_optional_id.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_optional_id::*; - -#[test] -fn test_valid_optional_id() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidOptionalId::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } -} diff --git a/spec/rust/tests/test_valid_short.rs b/spec/rust/tests/test_valid_short.rs deleted file mode 100644 index 21a298e54..000000000 --- a/spec/rust/tests/test_valid_short.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_short::*; - -#[test] -fn test_valid_short() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidShort::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } -} diff --git a/spec/rust/tests/test_valid_switch.rs b/spec/rust/tests/test_valid_switch.rs deleted file mode 100644 index 0a916332a..000000000 --- a/spec/rust/tests/test_valid_switch.rs +++ /dev/null @@ -1,18 +0,0 @@ -use std::fs; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::valid_switch::*; - -#[test] -fn test_valid_switch() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let mut r = ValidSwitch::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - - panic!("{:?}", err); - } -} diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 40e70912e..8a44006dc 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -37,6 +37,10 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs out.inc } + override def runParse(): Unit = { + finish_panic() + } + override def runParseExpectError(exception: KSError): Unit = { val code = s""" println!("expected err: {:?}, exception: ${exception}", err); @@ -45,17 +49,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs | }""".stripMargin out.puts(code) do_panic = false - // out.puts("err = r.Read(s, &r, &r)") -// out.puts("switch v := err.(type) {") -// out.puts(s"case ${errorName}:") -// out.inc -// out.puts("break") -// out.dec -// out.puts("default:") -// out.inc -// out.puts("t.Fatalf(\"expected " + errorName + ", got %T\", v)") -// out.dec -// out.puts("}") } def finish_panic(): Unit = { @@ -77,19 +70,19 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs var actStr = translateAct(check.actual) val expType = translator.detectType(check.expected) var expStr = translate(check.expected) - (actType, expType) match { - case (at: EnumType, et: EnumType) => - expStr = remove_ref(expStr) case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => actStr = actStr + " as u64" - // case => - // remove_deref(txt) case _ => } - + // fix expStr as vector + if (actStr.charAt(0) == '*' && expStr.length() > 2 && + expStr.charAt(0) == '&' && expStr.charAt(1) == '[') + { + expStr = remove_ref(expStr) + } finish_panic() out.puts(s"assert_eq!($actStr, $expStr);") } @@ -102,7 +95,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } override def trueArrayAssert(check: TestAssert, elType: DataType, elts: Seq[Ast.expr]): Unit = { - out.puts("trueArrayAssert $check, $elType, $elts") + out.puts(s"// trueArrayAssert $check, $elType, $elts") simpleAssert(check) // FIXME } @@ -114,36 +107,60 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } def translate(x: Ast.expr): String = { - val txt = translator.translate(x) - x match { - case Attribute(value, attr) => - if (classSpecs.firstSpec.instances.contains(InstanceIdentifier(attr.name))) { - s"${txt.dropRight(2)}(&reader).unwrap()" - } else { - var deref = true; - val found = translator.get_attr(classSpecs.firstSpec, attr.name) + val ttx = translator.translate(x) + // append (&reader).unwrap() to instance call + val dots = ttx.split("\\.") + var ttx2 = dots(0) + var last = "" + var last_full = "" + dots.drop(1).foreach { + case attr_full => + last_full = attr_full + val ind = attr_full indexOf "()" + if (ind > 0) { + val attr = attr_full.substring(0, ind) + last = attr + val found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), attr) if (found.isDefined) { - deref = found.get.dataTypeComposite match { - case _: SwitchType => false - case _: UserType => false - case _: BytesType => false - case _: ArrayType => false - case _ => true - } - } - if (deref) { - txt + ttx2 = s"${ttx2}.$attr(&reader).unwrap()${attr_full.substring(ind+2, attr_full.length())}" } else { - s"${translator.remove_deref(txt)}" + ttx2 = s"${ttx2}.${attr_full}" } + } else { + ttx2 = s"${ttx2}.${attr_full}" } - case _ => txt + } + // do we need to deref? + if (!last.isEmpty) { + var deref = true; + if (last == "len" || last_full.contains("[")) { + deref = false + } else { + val found = translator.get_attr(translator.get_top_class(classSpecs.firstSpec), last) + if (found.isDefined) { + deref = found.get.dataTypeComposite match { + case _: SwitchType => false + case _: EnumType => false + case _: UserType => false + case _: BytesType => false + case _: ArrayType => false + case _ => true + } + } + } + if (deref) { + ttx2 + } else { + s"${translator.remove_deref(ttx2)}" + } + } else { + ttx } } def remove_ref(s: String): String = { if (s.charAt(0) == '&') { - s.substring(1, s.length()) + s.substring(1) } else { s } From 9e0501136b8d664cbf2300ff2eb4211269b3e898 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 11 Aug 2022 19:33:06 +0800 Subject: [PATCH 047/198] new tests added. --- formats_rust/expr_bytes_ops.ksy | 34 ++++++++++++++++++++ formats_rust/expr_calc_array_ops.ksy | 48 ++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 formats_rust/expr_bytes_ops.ksy create mode 100644 formats_rust/expr_calc_array_ops.ksy diff --git a/formats_rust/expr_bytes_ops.ksy b/formats_rust/expr_bytes_ops.ksy new file mode 100644 index 000000000..5c7ad8e08 --- /dev/null +++ b/formats_rust/expr_bytes_ops.ksy @@ -0,0 +1,34 @@ +meta: + id: expr_bytes_ops +seq: + - id: one + size: 3 +instances: + two: + value: '[0x41, 0xff, 0x4b]' + + one_size: + value: one.size + one_first: + value: one.first + one_mid: + value: one[1] + one_last: + value: one.last + one_min: + value: one.min + one_max: + value: one.max + + two_size: + value: two.size + two_first: + value: two.first + two_mid: + value: two[1] + two_last: + value: two.last + two_min: + value: two.min + two_max: + value: two.max diff --git a/formats_rust/expr_calc_array_ops.ksy b/formats_rust/expr_calc_array_ops.ksy new file mode 100644 index 000000000..693555dd6 --- /dev/null +++ b/formats_rust/expr_calc_array_ops.ksy @@ -0,0 +1,48 @@ +meta: + id: expr_calc_array_ops +instances: + int_array: + value: '[10, 25, 50, 100, 200, 500, 1000]' + double_array: + value: '[10.0, 25.0, 50.0, 100.0, 3.14159]' + str_array: + value: '["un", "deux", "trois", "quatre"]' + + int_array_size: + value: int_array.size + int_array_first: + value: int_array.first + int_array_mid: + value: int_array[1] + int_array_last: + value: int_array.last + int_array_min: + value: int_array.min + int_array_max: + value: int_array.max + + double_array_size: + value: double_array.size + double_array_first: + value: double_array.first + double_array_mid: + value: double_array[1] + double_array_last: + value: double_array.last + double_array_min: + value: double_array.min + double_array_max: + value: double_array.max + + str_array_size: + value: str_array.size + str_array_first: + value: str_array.first + str_array_mid: + value: str_array[1] + str_array_last: + value: str_array.last + str_array_min: + value: str_array.min + str_array_max: + value: str_array.max From b5d369fe63ce8d11c8d9ca51273ed4c93baa7ad4 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Thu, 11 Aug 2022 21:43:02 +0200 Subject: [PATCH 048/198] add `CLIOptions::unitTest` --- .../kaitai/struct/testtranslator/Main.scala | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala index a04fd0a2f..455d8c5ed 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala @@ -8,9 +8,9 @@ object Main extends App { var baseDir = ".." val specDir = s"$baseDir/spec" def specKsDir = s"$baseDir/spec/ks" - def specKsDir_=(v:String) { specKsDir = v } + def specKsDir_=(v:String): Unit = { specKsDir = v } def formatsDir = s"$baseDir/formats" - def formatsDir_=(v:String) { formatsDir = v } + def formatsDir_=(v:String): Unit = { formatsDir = v } val defaultOutDir = s"$specKsDir/out" val importsDir = s"$baseDir/../formats" @@ -39,7 +39,8 @@ object Main extends App { case class CLIOptions( srcFiles: Seq[String] = Seq(), targets: Seq[String] = Seq(), - outDir: String = defaultOutDir + outDir: String = defaultOutDir, + unitTest: Boolean = false, ) // Stupid ksc build-time issue: no simple way to get that generated constant @@ -58,15 +59,15 @@ object Main extends App { x } c.copy(srcFiles = c.srcFiles :+ testName) - } text("source test names (.kst)") + } text "source test names (.kst)" - opt[String]('t', "target") unbounded() valueName("") action { (x, c) => + opt[String]('t', "target") unbounded() valueName "" action { (x, c) => if (x == "all") { c.copy(targets = ALL_GOOD_LANGS) } else { c.copy(targets = c.targets :+ x) } - } text(s"target languages (${ALL_LANGS.mkString(", ")}, default: all)") validate { x => + } text s"target languages (${ALL_LANGS.mkString(", ")}, default: all)" validate { x => if (ALL_LANGS.contains(x) || x == "all") { success } else { @@ -80,11 +81,15 @@ object Main extends App { filter(_.endsWith(".kst")). map(fn => fn.substring(0, fn.length - 4)) c.copy(srcFiles = list.toSeq) - } text("process all KST files available") + } text "process all KST files available" opt[String]('f', "force") action { (x, c) => c.copy(outDir = x) - } text(s"force overwrite specs in production spec dirs (default: generate in $defaultOutDir)") + } text s"force overwrite specs in production spec dirs (default: generate in $defaultOutDir)" + + opt[Boolean]('u', "unit-test") + .action((d, c) => c.copy(unitTest = d)) + .text("rust only: generate unit tests (not integration tests)") } parser.parse(args, CLIOptions()) match { From 3624f5e1cd2dec0a795b19463081f316f1aa1dee Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Thu, 11 Aug 2022 21:51:45 +0200 Subject: [PATCH 049/198] process `extraImports`, correct enums' comparison, add `options: CLIOptions` to class parameters --- .../specgenerators/RustSG.scala | 47 +++++++++++-------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 8a44006dc..926e28ef5 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -4,27 +4,34 @@ import _root_.io.kaitai.struct.{ClassTypeProvider, JSON, RuntimeConfig} import _root_.io.kaitai.struct.datatype.{DataType, KSError} import _root_.io.kaitai.struct.exprlang.Ast import _root_.io.kaitai.struct.languages.RustCompiler -import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} import _root_.io.kaitai.struct.translators.RustTranslator -import _root_.io.kaitai.struct.datatype.DataType.{BooleanType, EnumType, SwitchType, UserType, BytesType, ArrayType, IntType} -import io.kaitai.struct.exprlang.Ast.expr.Attribute -import io.kaitai.struct.format.{ClassSpecs, InstanceIdentifier} +import _root_.io.kaitai.struct.datatype.DataType.{ArrayType, BooleanType, BytesType, EnumType, IntType, SwitchType, UserType} +import _root_.io.kaitai.struct.format.ClassSpecs +import io.kaitai.struct.testtranslator.Main.CLIOptions +import io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} -class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs) extends BaseGenerator(spec) { - val className = RustCompiler.type2class(spec.id) +class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs, options: CLIOptions) extends BaseGenerator(spec) { + val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) - var do_panic = true; + var do_panic = true override def fileName(name: String): String = s"test_$name.rs" override def header(): Unit = { + val use_mod = if (options.unitTest) + s"use crate::" + else + s"mod formats;\nuse " + var imports = "" + spec.extraImports.foreach{ name => imports = s"$imports\n${use_mod}formats::$name::*;" } + val code = s"""|use std::fs; | |extern crate kaitai; |use self::kaitai::*; - |mod formats; - |use formats::${spec.id}::*; + |${use_mod}formats::${spec.id}::*; + |$imports | |#[test] |fn test_${spec.id}() { @@ -43,9 +50,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def runParseExpectError(exception: KSError): Unit = { val code = - s""" println!("expected err: {:?}, exception: ${exception}", err); + s""" println!("expected err: {:?}, exception: $exception", err); | } else { - | panic!("no expected exception: ${exception}"); + | panic!("no expected exception: $exception"); | }""".stripMargin out.puts(code) do_panic = false @@ -71,10 +78,12 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val expType = translator.detectType(check.expected) var expStr = translate(check.expected) (actType, expType) match { + case (at: EnumType, et: EnumType) => + expStr = "&" + expStr case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => - actStr = actStr + " as u64" + actStr = actStr + ".clone().to_owned() as u64" case _ => } // fix expStr as vector @@ -114,7 +123,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs var last = "" var last_full = "" dots.drop(1).foreach { - case attr_full => + attr_full => last_full = attr_full val ind = attr_full indexOf "()" if (ind > 0) { @@ -122,17 +131,17 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs last = attr val found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), attr) if (found.isDefined) { - ttx2 = s"${ttx2}.$attr(&reader).unwrap()${attr_full.substring(ind+2, attr_full.length())}" + ttx2 = s"$ttx2.$attr(&reader).unwrap()${attr_full.substring(ind + 2, attr_full.length())}" } else { - ttx2 = s"${ttx2}.${attr_full}" + ttx2 = s"$ttx2.$attr_full" } } else { - ttx2 = s"${ttx2}.${attr_full}" + ttx2 = s"$ttx2.$attr_full" } } // do we need to deref? - if (!last.isEmpty) { - var deref = true; + if (last.nonEmpty) { + var deref = true if (last == "len" || last_full.contains("[")) { deref = false } else { @@ -166,6 +175,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } } - def translateAct(x: Ast.expr) = + def translateAct(x: Ast.expr): String = translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") } From 96eec22b84bb35f974b7c9d6cac02c537f853ecc Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 12 Aug 2022 11:30:31 +0800 Subject: [PATCH 050/198] new tests added. --- formats_rust/expr_if_int_ops.ksy | 17 +++++++++++++++++ formats_rust/expr_int_div.ksy | 20 ++++++++++++++++++++ formats_rust/expr_io_eof.ksy | 22 ++++++++++++++++++++++ formats_rust/expr_io_pos.ksy | 21 +++++++++++++++++++++ spec/rust/tests/manual_expr_int_div.rs | 26 ++++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 formats_rust/expr_if_int_ops.ksy create mode 100644 formats_rust/expr_int_div.ksy create mode 100644 formats_rust/expr_io_eof.ksy create mode 100644 formats_rust/expr_io_pos.ksy create mode 100644 spec/rust/tests/manual_expr_int_div.rs diff --git a/formats_rust/expr_if_int_ops.ksy b/formats_rust/expr_if_int_ops.ksy new file mode 100644 index 000000000..8fbc48c42 --- /dev/null +++ b/formats_rust/expr_if_int_ops.ksy @@ -0,0 +1,17 @@ +meta: + id: expr_if_int_ops + endian: le +seq: + - id: skip + size: 2 + - id: it + type: s2 + if: true + - id: boxed + type: s2 + if: true +instances: + is_eq_prim: + value: it == 0x4141 + is_eq_boxed: + value: it == boxed diff --git a/formats_rust/expr_int_div.ksy b/formats_rust/expr_int_div.ksy new file mode 100644 index 000000000..31b690948 --- /dev/null +++ b/formats_rust/expr_int_div.ksy @@ -0,0 +1,20 @@ +# Tests division operation, both positive and negative +# See https://github.com/kaitai-io/kaitai_struct/issues/746 +# => the KS division operation `a / b` should do `floor(a / b)` +meta: + id: expr_int_div + endian: le +seq: + - id: int_u + type: u4 + - id: int_s + type: s4 +instances: + div_pos_const: + value: 9837 / 13 + div_neg_const: + value: -9837 / 13 + div_pos_seq: + value: int_u / 13 + div_neg_seq: + value: int_s / 13 diff --git a/formats_rust/expr_io_eof.ksy b/formats_rust/expr_io_eof.ksy new file mode 100644 index 000000000..d27f1847c --- /dev/null +++ b/formats_rust/expr_io_eof.ksy @@ -0,0 +1,22 @@ +# Tests _io.eof operation +meta: + id: expr_io_eof + endian: le +seq: + - id: substream1 + size: 4 + type: one_or_two + - id: substream2 + size: 8 + type: one_or_two +types: + one_or_two: + seq: + - id: one + type: u4 + - id: two + type: u4 + if: not _io.eof + instances: + reflect_eof: + value: _io.eof diff --git a/formats_rust/expr_io_pos.ksy b/formats_rust/expr_io_pos.ksy new file mode 100644 index 000000000..247478a6e --- /dev/null +++ b/formats_rust/expr_io_pos.ksy @@ -0,0 +1,21 @@ +# Tests _io.pos operation +meta: + id: expr_io_pos + endian: le +seq: + - id: substream1 + size: 16 + type: all_plus_number + - id: substream2 + size: 14 + type: all_plus_number +types: + all_plus_number: + seq: + - id: my_str + type: strz + encoding: UTF-8 + - id: body + size: _io.size - _io.pos - 2 + - id: number + type: u2 diff --git a/spec/rust/tests/manual_expr_int_div.rs b/spec/rust/tests/manual_expr_int_div.rs new file mode 100644 index 000000000..8dece0ddb --- /dev/null +++ b/spec/rust/tests/manual_expr_int_div.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::expr_int_div::*; + +#[test] +fn test_expr_int_div() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ExprIntDiv::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.int_u(), 1262698832); + assert_eq!(*r.int_s(), -52947); + assert_eq!(*r.div_pos_const(&reader).unwrap(), 756); + assert_eq!(*r.div_neg_const(&reader).unwrap(), -756); + assert_eq!(*r.div_pos_seq(&reader).unwrap(), 97130679); + assert_eq!(*r.div_neg_seq(&reader).unwrap(), -4072); +} From af31e781a6a12c940243238e7beb76c383f6c4d2 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 12 Aug 2022 11:31:00 +0800 Subject: [PATCH 051/198] ref/deref fixed. --- .../struct/testtranslator/specgenerators/RustSG.scala | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 926e28ef5..9cb0fb6aa 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -155,10 +155,18 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs case _: ArrayType => false case _ => true } + } else if (translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { + deref = true + } else { + deref = false } } if (deref) { - ttx2 + if (ttx2.charAt(0) == '*') { + ttx2 + } else { + s"*$ttx2" + } } else { s"${translator.remove_deref(ttx2)}" } From 2ccb7d68d269339f77a3059a47e1886888f54029 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 12 Aug 2022 11:53:42 +0800 Subject: [PATCH 052/198] options commented, ref for enum fixed. --- .../struct/testtranslator/specgenerators/RustSG.scala | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 9cb0fb6aa..0061c11e3 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -10,7 +10,7 @@ import _root_.io.kaitai.struct.format.ClassSpecs import io.kaitai.struct.testtranslator.Main.CLIOptions import io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} -class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs, options: CLIOptions) extends BaseGenerator(spec) { +class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs/*, options: CLIOptions*/) extends BaseGenerator(spec) { val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) var do_panic = true @@ -18,7 +18,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def fileName(name: String): String = s"test_$name.rs" override def header(): Unit = { - val use_mod = if (options.unitTest) + val use_mod = if (/*options.unitTest*/false) s"use crate::" else s"mod formats;\nuse " @@ -78,8 +78,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val expType = translator.detectType(check.expected) var expStr = translate(check.expected) (actType, expType) match { - case (at: EnumType, et: EnumType) => - expStr = "&" + expStr case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => From bf9493243067efcf7b601803529f5bce6a82e219 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 12 Aug 2022 11:54:20 +0800 Subject: [PATCH 053/198] renamed. --- .../rust/tests/{manual_expr_int_div.rs => test_expr_int_div.rs} | 2 -- 1 file changed, 2 deletions(-) rename spec/rust/tests/{manual_expr_int_div.rs => test_expr_int_div.rs} (89%) diff --git a/spec/rust/tests/manual_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs similarity index 89% rename from spec/rust/tests/manual_expr_int_div.rs rename to spec/rust/tests/test_expr_int_div.rs index 8dece0ddb..e88b4b780 100644 --- a/spec/rust/tests/manual_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -1,5 +1,3 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - use std::fs; extern crate kaitai; From 1f3124c0b262dfbfb65b06057ccec554fd80a308 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 12 Aug 2022 15:15:46 +0800 Subject: [PATCH 054/198] more tests. --- formats_rust/nav_parent_false2.ksy | 12 ++++++++++++ formats_rust/position_to_end.ksy | 14 ++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 formats_rust/nav_parent_false2.ksy create mode 100644 formats_rust/position_to_end.ksy diff --git a/formats_rust/nav_parent_false2.ksy b/formats_rust/nav_parent_false2.ksy new file mode 100644 index 000000000..f69bc2a85 --- /dev/null +++ b/formats_rust/nav_parent_false2.ksy @@ -0,0 +1,12 @@ +meta: + id: nav_parent_false2 +seq: + - id: parentless + type: child + parent: false +types: + child: + # should have no parents + seq: + - id: foo + type: u1 diff --git a/formats_rust/position_to_end.ksy b/formats_rust/position_to_end.ksy new file mode 100644 index 000000000..3651796f3 --- /dev/null +++ b/formats_rust/position_to_end.ksy @@ -0,0 +1,14 @@ +meta: + id: position_to_end + endian: le +instances: + index: + pos: _io.size - 8 + type: index_obj +types: + index_obj: + seq: + - id: foo + type: u4 + - id: bar + type: u4 From 26ae9b67cbe53cd507548196b5b2b5636bd445fa Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Fri, 12 Aug 2022 11:02:50 +0200 Subject: [PATCH 055/198] doTestSpec(..., options: CLIOptions), remove some warnings --- .../testtranslator/TestTranslator.scala | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index 50124fb7a..46b0e9292 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -17,27 +17,28 @@ class TestTranslator(options: CLIOptions) { def run(): Unit = { if(options.srcFiles.length == 1) { - val path = Path.of(options.srcFiles(0)); + val path = Path.of(options.srcFiles.head) - if (path.isAbsolute()) { + if (path.isAbsolute) { val specKs = specKsDir.split('/').drop(1).mkString("/") - val parent = path.getParent().toString().replace('\\', '/') + val parent = path.getParent.toString.replace('\\', '/') assert(parent.endsWith(specKs)) baseDir = parent.replace(specKs, "") } } - val exactOutDir = (options.outDir != defaultOutDir) options.srcFiles.foreach(testName => - doTestSpec(testName, options.targets, options.outDir, exactOutDir) + doTestSpec(testName, options.targets, options) ) } - def doTestSpec(ts: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { + def doTestSpec(ts: String, langs: Seq[String], options: CLIOptions): Unit = { Console.println(s"Translating: $ts") + val outDir = options.outDir + val exactOutDir = options.outDir != defaultOutDir val path = Path.of(ts) - val testName = if(path.isAbsolute()) { path.getFileName().toString() } else { ts } + val testName = if(path.isAbsolute) { path.getFileName.toString } else { ts } val testSpec = loadTestSpec(testName) val classSpecs = loadClassSpecs(testName) @@ -45,7 +46,7 @@ class TestTranslator(options: CLIOptions) { val provider = new ClassTypeProvider(classSpecs, initObj) langs.foreach(langName => { - val sg = getSG(langName, testSpec, provider, classSpecs) + val sg = getSG(langName, testSpec, provider, classSpecs, options) try { sg.run() val outFile = if(exactOutDir) { s"$outDir/${sg.fileName(testName)}" } else { s"$outDir/$langName/${sg.fileName(testName)}" } @@ -124,7 +125,7 @@ class TestTranslator(options: CLIOptions) { origSpecs } - def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs): BaseGenerator = lang match { + def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs, options: CLIOptions): BaseGenerator = lang match { case "construct" => new ConstructSG(testSpec, provider) case "cpp_stl_98" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp98()) case "cpp_stl_11" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp11()) @@ -138,6 +139,6 @@ class TestTranslator(options: CLIOptions) { case "php" => new PHPSG(testSpec, provider) case "python" => new PythonSG(testSpec, provider) case "ruby" => new RubySG(testSpec, provider) - case "rust" => new RustSG(testSpec, provider, classSpecs) + case "rust" => new RustSG(testSpec, provider, classSpecs, options) } } From 228e82a5178fb574504ce3d0c5079d50c583b574 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Fri, 12 Aug 2022 11:06:11 +0200 Subject: [PATCH 056/198] use `options` --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 0061c11e3..03a90faee 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -10,7 +10,7 @@ import _root_.io.kaitai.struct.format.ClassSpecs import io.kaitai.struct.testtranslator.Main.CLIOptions import io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} -class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs/*, options: CLIOptions*/) extends BaseGenerator(spec) { +class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs, options: CLIOptions) extends BaseGenerator(spec) { val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) var do_panic = true @@ -18,7 +18,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def fileName(name: String): String = s"test_$name.rs" override def header(): Unit = { - val use_mod = if (/*options.unitTest*/false) + val use_mod = if (options.unitTest) s"use crate::" else s"mod formats;\nuse " From 25a93f406c0055a39ded7491e55c1af0f29aa67b Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Wed, 17 Aug 2022 21:21:11 +0200 Subject: [PATCH 057/198] deref enums --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 03a90faee..59a1f38be 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -78,6 +78,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val expType = translator.detectType(check.expected) var expStr = translate(check.expected) (actType, expType) match { +// case (at: EnumType, et: EnumType) => +// expStr = "&" + expStr case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => @@ -147,7 +149,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs if (found.isDefined) { deref = found.get.dataTypeComposite match { case _: SwitchType => false - case _: EnumType => false + //case _: EnumType => false case _: UserType => false case _: BytesType => false case _: ArrayType => false From 3db8818bd40d09a3e574a87a40c88b74fd2852f8 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 18 Aug 2022 10:28:28 +0200 Subject: [PATCH 058/198] combine tests added. --- formats_rust/combine_bool.ksy | 10 ++++++++ formats_rust/combine_bytes.ksy | 27 +++++++++++++++++++++ formats_rust/combine_str.ksy | 44 ++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 formats_rust/combine_bool.ksy create mode 100644 formats_rust/combine_bytes.ksy create mode 100644 formats_rust/combine_str.ksy diff --git a/formats_rust/combine_bool.ksy b/formats_rust/combine_bool.ksy new file mode 100644 index 000000000..496026c6a --- /dev/null +++ b/formats_rust/combine_bool.ksy @@ -0,0 +1,10 @@ +meta: + id: combine_bool +seq: + - id: bool_bit + type: b1 +instances: + bool_calc: + value: false + bool_calc_bit: + value: 'true ? bool_calc : bool_bit' diff --git a/formats_rust/combine_bytes.ksy b/formats_rust/combine_bytes.ksy new file mode 100644 index 000000000..00256370e --- /dev/null +++ b/formats_rust/combine_bytes.ksy @@ -0,0 +1,27 @@ +meta: + id: combine_bytes +seq: + - id: bytes_term + terminator: 0x7c + - id: bytes_limit + size: 4 + - id: bytes_eos + size-eos: true +instances: + bytes_calc: + value: '[0x52, 0x6e, 0x44]' + + term_or_limit: + value: 'true ? bytes_term : bytes_limit' + term_or_eos: + value: 'false ? bytes_term : bytes_eos' + term_or_calc: + value: 'true ? bytes_term : bytes_calc' + + limit_or_eos: + value: 'true ? bytes_limit : bytes_eos' + limit_or_calc: + value: 'false ? bytes_limit : bytes_calc' + + eos_or_calc: + value: 'true ? bytes_eos : bytes_calc' diff --git a/formats_rust/combine_str.ksy b/formats_rust/combine_str.ksy new file mode 100644 index 000000000..aa3cd2860 --- /dev/null +++ b/formats_rust/combine_str.ksy @@ -0,0 +1,44 @@ +meta: + id: combine_str + encoding: ASCII +seq: + - id: str_term + type: str + terminator: 0x7c + - id: str_limit + type: str + size: 4 + - id: str_eos + type: str + size-eos: true +instances: + str_calc: + value: '"bar"' + calc_bytes: + value: '[0x62, 0x61, 0x7a]' + str_calc_bytes: + value: 'calc_bytes.to_s("ASCII")' + + term_or_limit: + value: 'true ? str_term : str_limit' + term_or_eos: + value: 'false ? str_term : str_eos' + term_or_calc: + value: 'true ? str_term : str_calc' + term_or_calc_bytes: + value: 'false ? str_term : str_calc_bytes' + + limit_or_eos: + value: 'true ? str_limit : str_eos' + limit_or_calc: + value: 'false ? str_limit : str_calc' + limit_or_calc_bytes: + value: 'true ? str_limit : str_calc_bytes' + + eos_or_calc: + value: 'false ? str_eos : str_calc' + eos_or_calc_bytes: + value: 'true ? str_eos : str_calc_bytes' + + calc_or_calc_bytes: + value: 'false ? str_calc : str_calc_bytes' From 05ec1487753672b3071bf436a43781e3ffb9c784 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 18 Aug 2022 11:52:42 +0200 Subject: [PATCH 059/198] small fixes with enum ref. --- .../struct/testtranslator/specgenerators/RustSG.scala | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 59a1f38be..33d9b3b7d 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -78,8 +78,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val expType = translator.detectType(check.expected) var expStr = translate(check.expected) (actType, expType) match { -// case (at: EnumType, et: EnumType) => -// expStr = "&" + expStr + case (at: EnumType, et: EnumType) => + expStr = remove_ref(expStr) case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => @@ -87,9 +87,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs case _ => } // fix expStr as vector - if (actStr.charAt(0) == '*' && expStr.length() > 2 && - expStr.charAt(0) == '&' && expStr.charAt(1) == '[') - { + if (actStr.charAt(0) == '*' && expStr.startsWith("&vec![")) { expStr = remove_ref(expStr) } finish_panic() @@ -149,7 +147,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs if (found.isDefined) { deref = found.get.dataTypeComposite match { case _: SwitchType => false - //case _: EnumType => false case _: UserType => false case _: BytesType => false case _: ArrayType => false From ea400c7e1dc421edaa219a99bc65022c206877b0 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 20 Aug 2022 09:04:43 +0200 Subject: [PATCH 060/198] more tests added. --- formats_rust/nav_parent.ksy | 3 +-- formats_rust/nav_parent_switch.ksy | 23 ++++++++++++++++ formats_rust/nested_same_name.ksy | 23 ++++++++++++++++ formats_rust/nested_same_name2.ksy | 33 +++++++++++++++++++++++ spec/rust/tests/test_nav_parent_switch.rs | 25 +++++++++++++++++ 5 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 formats_rust/nav_parent_switch.ksy create mode 100644 formats_rust/nested_same_name.ksy create mode 100644 formats_rust/nested_same_name2.ksy create mode 100644 spec/rust/tests/test_nav_parent_switch.rs diff --git a/formats_rust/nav_parent.ksy b/formats_rust/nav_parent.ksy index e2e554d2b..87b8e010d 100644 --- a/formats_rust/nav_parent.ksy +++ b/formats_rust/nav_parent.ksy @@ -29,5 +29,4 @@ types: size: _parent._parent.header.filename_len encoding: UTF-8 -# here is kaitai bug -# this is fixed test with correct alignmnet \ No newline at end of file +# this is fixed test with correct alignmnet (parent as subtypes) \ No newline at end of file diff --git a/formats_rust/nav_parent_switch.ksy b/formats_rust/nav_parent_switch.ksy new file mode 100644 index 000000000..859c50d09 --- /dev/null +++ b/formats_rust/nav_parent_switch.ksy @@ -0,0 +1,23 @@ +meta: + id: nav_parent_switch +seq: + - id: category + type: u1 + - id: content + type: + switch-on: category + cases: + 1: element_1 +types: + element_1: + seq: + - id: foo + type: u1 + - id: subelement + type: subelement_1 + types: + subelement_1: + seq: + - id: bar + type: u1 + if: _parent.foo == 0x42 diff --git a/formats_rust/nested_same_name.ksy b/formats_rust/nested_same_name.ksy new file mode 100644 index 000000000..0603b4cd0 --- /dev/null +++ b/formats_rust/nested_same_name.ksy @@ -0,0 +1,23 @@ +meta: + id: nested_same_name + endian: le +seq: + - id: main_data + type: main + - id: dummy + type: dummy_obj +types: + main: + seq: + - id: main_size + type: s4 + - id: foo + type: foo_obj + types: + foo_obj: + seq: + - id: data + size: '_parent.main_size * 2' + dummy_obj: + types: + foo: {} diff --git a/formats_rust/nested_same_name2.ksy b/formats_rust/nested_same_name2.ksy new file mode 100644 index 000000000..39a53a5e9 --- /dev/null +++ b/formats_rust/nested_same_name2.ksy @@ -0,0 +1,33 @@ +meta: + id: nested_same_name2 + endian: le +seq: + - id: version + type: u4 + - id: main_data + type: main + - id: dummy + type: dummy_obj +types: + main: + seq: + - id: main_size + type: s4 + - id: foo + type: foo_obj + types: + foo_obj: + seq: + - id: data1 + size: _parent.main_size * 2 + dummy_obj: + seq: + - id: dummy_size + type: s4 + - id: foo + type: foo_obj + types: + foo_obj: + seq: + - id: data2 + size: _parent.dummy_size * 2 diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs new file mode 100644 index 000000000..a28dffed1 --- /dev/null +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::nav_parent_switch::*; + + +#[test] +fn test_nav_parent_switch() { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = NavParentSwitch::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.category(), 1); + let NavParentSwitch_Content::NavParentSwitch_Element1(s) = r.content(); + assert_eq!(*s.foo(), 66); + assert_eq!(*s.subelement().bar(), 255); +} From 6a881577ce580a5d6dd5c13d0b990bf287479e7d Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 24 Aug 2022 17:10:58 +0200 Subject: [PATCH 061/198] params test added. --- formats_rust/nested_types.ksy | 23 ++++++++++++ formats_rust/params_call_extra_parens.ksy | 15 ++++++++ formats_rust/params_call_short.ksy | 31 ++++++++++++++++ formats_rust/params_def.ksy | 16 +++++++++ formats_rust/params_enum.ksy | 22 ++++++++++++ formats_rust/params_pass_array_int.ksy | 20 +++++++++++ formats_rust/params_pass_array_str.ksy | 21 +++++++++++ formats_rust/params_pass_array_usertype.ksy | 23 ++++++++++++ formats_rust/params_pass_bool.ksy | 39 +++++++++++++++++++++ formats_rust/params_pass_usertype.ksy | 19 ++++++++++ 10 files changed, 229 insertions(+) create mode 100644 formats_rust/nested_types.ksy create mode 100644 formats_rust/params_call_extra_parens.ksy create mode 100644 formats_rust/params_call_short.ksy create mode 100644 formats_rust/params_def.ksy create mode 100644 formats_rust/params_enum.ksy create mode 100644 formats_rust/params_pass_array_int.ksy create mode 100644 formats_rust/params_pass_array_str.ksy create mode 100644 formats_rust/params_pass_array_usertype.ksy create mode 100644 formats_rust/params_pass_bool.ksy create mode 100644 formats_rust/params_pass_usertype.ksy diff --git a/formats_rust/nested_types.ksy b/formats_rust/nested_types.ksy new file mode 100644 index 000000000..9254555a5 --- /dev/null +++ b/formats_rust/nested_types.ksy @@ -0,0 +1,23 @@ +meta: + id: nested_types +seq: + - id: one + type: subtype_a + - id: two + type: subtype_b +types: + subtype_a: + seq: + - id: typed_at_root + type: subtype_b + - id: typed_here + type: subtype_c + types: + subtype_c: + seq: + - id: value_c + type: s1 + subtype_b: + seq: + - id: value_b + type: s1 diff --git a/formats_rust/params_call_extra_parens.ksy b/formats_rust/params_call_extra_parens.ksy new file mode 100644 index 000000000..e17ea1b21 --- /dev/null +++ b/formats_rust/params_call_extra_parens.ksy @@ -0,0 +1,15 @@ +meta: + id: params_call_extra_parens +seq: + - id: buf1 + type: my_str1((5)) +types: + my_str1: + params: + - id: len + type: u4 + seq: + - id: body + type: str + size: len + encoding: UTF-8 diff --git a/formats_rust/params_call_short.ksy b/formats_rust/params_call_short.ksy new file mode 100644 index 000000000..07be4ceaa --- /dev/null +++ b/formats_rust/params_call_short.ksy @@ -0,0 +1,31 @@ +meta: + id: params_call_short +seq: + - id: buf1 + type: my_str1(5) + - id: buf2 + type: my_str2(2 + 3, true) +types: + my_str1: + params: + - id: len + type: u4 + seq: + - id: body + type: str + size: len + encoding: UTF-8 + my_str2: + params: + - id: len + type: u4 + - id: has_trailer + type: bool + seq: + - id: body + type: str + size: len + encoding: UTF-8 + - id: trailer + type: u1 + if: has_trailer diff --git a/formats_rust/params_def.ksy b/formats_rust/params_def.ksy new file mode 100644 index 000000000..dd674cd1f --- /dev/null +++ b/formats_rust/params_def.ksy @@ -0,0 +1,16 @@ +meta: + id: params_def + endian: le +params: + - id: len + type: u4 + - id: has_trailer + type: bool +seq: + - id: buf + type: str + size: len + encoding: UTF-8 + - id: trailer + type: u1 + if: has_trailer diff --git a/formats_rust/params_enum.ksy b/formats_rust/params_enum.ksy new file mode 100644 index 000000000..291391365 --- /dev/null +++ b/formats_rust/params_enum.ksy @@ -0,0 +1,22 @@ +meta: + id: params_enum +enums: + animal: + 4: dog + 7: cat + 12: chicken +seq: + - id: one + type: u1 + enum: animal + - id: invoke_with_param + type: with_param(one) +types: + with_param: + params: + - id: enumerated_one + type: u1 + enum: animal + instances: + is_cat: + value: enumerated_one == animal::cat # would break if there's a bug diff --git a/formats_rust/params_pass_array_int.ksy b/formats_rust/params_pass_array_int.ksy new file mode 100644 index 000000000..7d065cf64 --- /dev/null +++ b/formats_rust/params_pass_array_int.ksy @@ -0,0 +1,20 @@ +meta: + id: params_pass_array_int + endian: le +seq: + - id: ints + type: u2 + repeat: expr + repeat-expr: 3 + - id: pass_ints + type: wants_ints(ints) + - id: pass_ints_calc + type: wants_ints(ints_calc) +types: + wants_ints: + params: + - id: nums + type: u2[] +instances: + ints_calc: + value: '[27643, 7].as' diff --git a/formats_rust/params_pass_array_str.ksy b/formats_rust/params_pass_array_str.ksy new file mode 100644 index 000000000..2caaa811d --- /dev/null +++ b/formats_rust/params_pass_array_str.ksy @@ -0,0 +1,21 @@ +meta: + id: params_pass_array_str + encoding: ascii +seq: + - id: str_array + type: str + size: 2 + repeat: expr + repeat-expr: 3 + - id: pass_str_array + type: wants_strs(str_array) + - id: pass_str_array_calc + type: wants_strs(str_array_calc) +types: + wants_strs: + params: + - id: strs + type: str[] +instances: + str_array_calc: + value: '["aB", "Cd"]' diff --git a/formats_rust/params_pass_array_usertype.ksy b/formats_rust/params_pass_array_usertype.ksy new file mode 100644 index 000000000..e3e71eed2 --- /dev/null +++ b/formats_rust/params_pass_array_usertype.ksy @@ -0,0 +1,23 @@ +meta: + id: params_pass_array_usertype +seq: + - id: blocks + type: block + repeat: expr + repeat-expr: 2 + - id: pass_blocks + type: param_type(blocks) +types: + block: + seq: + - id: foo + type: u1 + param_type: + params: + - id: bar + type: block[] + seq: + - id: one + size: bar[0].foo + - id: two + size: bar[1].foo diff --git a/formats_rust/params_pass_bool.ksy b/formats_rust/params_pass_bool.ksy new file mode 100644 index 000000000..7d2b986f1 --- /dev/null +++ b/formats_rust/params_pass_bool.ksy @@ -0,0 +1,39 @@ +meta: + id: params_pass_bool +seq: + - id: s_false + type: b1 + - id: s_true + type: b1 + - id: seq_b1 + type: param_type_b1(s_true) + - id: seq_bool + type: param_type_bool(s_false) + - id: literal_b1 + type: param_type_b1(false) + - id: literal_bool + type: param_type_bool(true) + - id: inst_b1 + type: param_type_b1(v_true) + - id: inst_bool + type: param_type_bool(v_false) +instances: + v_false: + value: false + v_true: + value: true +types: + param_type_b1: + params: + - id: arg + type: b1 + seq: + - id: foo + size: 'arg ? 1 : 2' + param_type_bool: + params: + - id: arg + type: bool + seq: + - id: foo + size: 'arg ? 1 : 2' diff --git a/formats_rust/params_pass_usertype.ksy b/formats_rust/params_pass_usertype.ksy new file mode 100644 index 000000000..8fa7b2747 --- /dev/null +++ b/formats_rust/params_pass_usertype.ksy @@ -0,0 +1,19 @@ +meta: + id: params_pass_usertype +seq: + - id: first + type: block + - id: one + type: param_type(first) +types: + block: + seq: + - id: foo + type: u1 + param_type: + params: + - id: foo + type: block + seq: + - id: buf + size: foo.foo From 2d3408f14dd40a3bbb683ec5e7c5b6a609143936 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 24 Aug 2022 17:11:20 +0200 Subject: [PATCH 062/198] catch params. --- .../io/kaitai/struct/testtranslator/specgenerators/RustSG.scala | 2 ++ 1 file changed, 2 insertions(+) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 33d9b3b7d..aac9ba124 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -154,6 +154,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } } else if (translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { deref = true + } else if (translator.get_param(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { + deref = true } else { deref = false } From fa55096c6788d07b0d735ce7dd2f5830d0371d14 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 25 Aug 2022 08:41:49 +0200 Subject: [PATCH 063/198] position tests. --- formats_rust/position_abs.ksy | 16 ++++++++++++++++ formats_rust/position_in_seq.ksy | 17 +++++++++++++++++ .../testtranslator/specgenerators/RustSG.scala | 2 -- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 formats_rust/position_abs.ksy create mode 100644 formats_rust/position_in_seq.ksy diff --git a/formats_rust/position_abs.ksy b/formats_rust/position_abs.ksy new file mode 100644 index 000000000..e4e877f1c --- /dev/null +++ b/formats_rust/position_abs.ksy @@ -0,0 +1,16 @@ +meta: + id: position_abs + endian: le +seq: + - id: index_offset + type: u4 +types: + index_obj: + seq: + - id: entry + type: strz + encoding: UTF-8 +instances: + index: + pos: index_offset + type: index_obj diff --git a/formats_rust/position_in_seq.ksy b/formats_rust/position_in_seq.ksy new file mode 100644 index 000000000..51a229e9c --- /dev/null +++ b/formats_rust/position_in_seq.ksy @@ -0,0 +1,17 @@ +meta: + id: position_in_seq + endian: le +seq: + - id: numbers + type: u1 + repeat: expr + repeat-expr: header.qty_numbers +types: + header_obj: + seq: + - id: qty_numbers + type: u4 +instances: + header: + pos: 0x10 + type: header_obj diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index aac9ba124..8cef60567 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -102,7 +102,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } override def trueArrayAssert(check: TestAssert, elType: DataType, elts: Seq[Ast.expr]): Unit = { - out.puts(s"// trueArrayAssert $check, $elType, $elts") simpleAssert(check) // FIXME } @@ -149,7 +148,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs case _: SwitchType => false case _: UserType => false case _: BytesType => false - case _: ArrayType => false case _ => true } } else if (translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { From ef2017c8ff40e96c68fe6af5736918eb2dc3d2bb Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 25 Aug 2022 08:47:15 +0200 Subject: [PATCH 064/198] more tests. --- formats_rust/buffered_struct.ksy | 23 +++++++++++++++++++++++ formats_rust/bytes_pad_term.ksy | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 formats_rust/buffered_struct.ksy create mode 100644 formats_rust/bytes_pad_term.ksy diff --git a/formats_rust/buffered_struct.ksy b/formats_rust/buffered_struct.ksy new file mode 100644 index 000000000..39212f0fe --- /dev/null +++ b/formats_rust/buffered_struct.ksy @@ -0,0 +1,23 @@ +meta: + id: buffered_struct + endian: le +seq: + - id: len1 + type: u4 + - id: block1 + type: block + size: len1 + - id: len2 + type: u4 + - id: block2 + type: block + size: len2 + - id: finisher + type: u4 +types: + block: + seq: + - id: number1 + type: u4 + - id: number2 + type: u4 diff --git a/formats_rust/bytes_pad_term.ksy b/formats_rust/bytes_pad_term.ksy new file mode 100644 index 000000000..139a00737 --- /dev/null +++ b/formats_rust/bytes_pad_term.ksy @@ -0,0 +1,18 @@ +# Tests "pad-right" and "terminator" functionality in fixed-length byte arrays +meta: + id: bytes_pad_term +seq: + - id: str_pad + size: 20 + pad-right: 0x40 + - id: str_term + size: 20 + terminator: 0x40 + - id: str_term_and_pad + size: 20 + terminator: 0x40 + pad-right: 0x2b + - id: str_term_include + size: 20 + terminator: 0x40 + include: true From 71288f401fa6e53700f8fd61094d440000afabb9 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 25 Aug 2022 09:00:21 +0200 Subject: [PATCH 065/198] docref tests added. --- formats_rust/docstrings.ksy | 31 ++++++++++++++++++++++++ formats_rust/docstrings_docref.ksy | 26 ++++++++++++++++++++ formats_rust/docstrings_docref_multi.ksy | 7 ++++++ 3 files changed, 64 insertions(+) create mode 100644 formats_rust/docstrings.ksy create mode 100644 formats_rust/docstrings_docref.ksy create mode 100644 formats_rust/docstrings_docref_multi.ksy diff --git a/formats_rust/docstrings.ksy b/formats_rust/docstrings.ksy new file mode 100644 index 000000000..9edbbb0b5 --- /dev/null +++ b/formats_rust/docstrings.ksy @@ -0,0 +1,31 @@ +meta: + id: docstrings +doc: One-liner description of a type. +seq: + - id: one + type: u1 + doc: A pretty verbose description for sequence attribute "one" +types: + complex_subtype: + doc: | + This subtype is never used, yet has a very long description + that spans multiple lines. It should be formatted accordingly, + even in languages that have single-line comments for + docstrings. Actually, there's even a MarkDown-style list here + with several bullets: + + * one + * two + * three + + And the text continues after that. Here's a MarkDown-style link: + [woohoo](http://example.com) - one day it will be supported as + well. +instances: + two: + pos: 0 + type: u1 + doc: Another description for parse instance "two" + three: + value: 0x42 + doc: And yet another one for value instance "three" diff --git a/formats_rust/docstrings_docref.ksy b/formats_rust/docstrings_docref.ksy new file mode 100644 index 000000000..f4aadf20d --- /dev/null +++ b/formats_rust/docstrings_docref.ksy @@ -0,0 +1,26 @@ +meta: + id: docstrings_docref +doc: Another one-liner +doc-ref: http://www.example.com/some/path/?even_with=query&more=2 +seq: + - id: one + type: u1 + doc-ref: Plain text description of doc ref, page 42 + - id: two + type: u1 + doc: Both doc and doc-ref are defined + doc-ref: http://www.example.com/with/url/again + - id: three + type: u1 + doc-ref: http://www.example.com/three Documentation name +instances: + foo: + doc-ref: Doc ref for instance, a plain one + value: true + parse_inst: + pos: 0 + type: u1 + doc-ref: | + Now this is a really + long document ref that + spans multiple lines. diff --git a/formats_rust/docstrings_docref_multi.ksy b/formats_rust/docstrings_docref_multi.ksy new file mode 100644 index 000000000..7a3bc642b --- /dev/null +++ b/formats_rust/docstrings_docref_multi.ksy @@ -0,0 +1,7 @@ +meta: + id: docstrings_docref_multi +doc: Sample docstring +doc-ref: + - Plain text description of doc ref, page 42 + - http://www.example.com/some/path/?even_with=query&more=2 + - http://www.example.com/three Documentation name From 3b395064bfd19fdc86df011cbfab081215a1628f Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 25 Aug 2022 09:15:48 +0200 Subject: [PATCH 066/198] eos/eof tests. --- formats_rust/eof_exception_bytes.ksy | 6 ++++++ formats_rust/eof_exception_u4.ksy | 8 ++++++++ formats_rust/eos_exception_bytes.ksy | 11 +++++++++++ formats_rust/eos_exception_u4.ksy | 13 +++++++++++++ 4 files changed, 38 insertions(+) create mode 100644 formats_rust/eof_exception_bytes.ksy create mode 100644 formats_rust/eof_exception_u4.ksy create mode 100644 formats_rust/eos_exception_bytes.ksy create mode 100644 formats_rust/eos_exception_u4.ksy diff --git a/formats_rust/eof_exception_bytes.ksy b/formats_rust/eof_exception_bytes.ksy new file mode 100644 index 000000000..22f5ff876 --- /dev/null +++ b/formats_rust/eof_exception_bytes.ksy @@ -0,0 +1,6 @@ +meta: + id: eof_exception_bytes +seq: + - id: buf + # only 12 bytes available, should fail with EOF exception + size: 13 diff --git a/formats_rust/eof_exception_u4.ksy b/formats_rust/eof_exception_u4.ksy new file mode 100644 index 000000000..2a0e7c97c --- /dev/null +++ b/formats_rust/eof_exception_u4.ksy @@ -0,0 +1,8 @@ +meta: + id: eof_exception_u4 +seq: + # only 12 bytes available, should fail with EOF exception + - id: prebuf + size: 9 + - id: fail_int + type: u4le diff --git a/formats_rust/eos_exception_bytes.ksy b/formats_rust/eos_exception_bytes.ksy new file mode 100644 index 000000000..ca7e7a452 --- /dev/null +++ b/formats_rust/eos_exception_bytes.ksy @@ -0,0 +1,11 @@ +meta: + id: eos_exception_bytes +seq: + - id: envelope + type: data + size: 6 +types: + data: + seq: + - id: buf + size: 7 diff --git a/formats_rust/eos_exception_u4.ksy b/formats_rust/eos_exception_u4.ksy new file mode 100644 index 000000000..e3cd4a153 --- /dev/null +++ b/formats_rust/eos_exception_u4.ksy @@ -0,0 +1,13 @@ +meta: + id: eos_exception_u4 +seq: + - id: envelope + type: data + size: 6 +types: + data: + seq: + - id: prebuf + size: 3 + - id: fail_int + type: u4le From bc8228938b93ee75c671993be9447d636c010a9d Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 25 Aug 2022 09:16:05 +0200 Subject: [PATCH 067/198] params_def test. --- spec/rust/tests/manual_params_def.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/rust/tests/manual_params_def.rs diff --git a/spec/rust/tests/manual_params_def.rs b/spec/rust/tests/manual_params_def.rs new file mode 100644 index 000000000..0cc8a1920 --- /dev/null +++ b/spec/rust/tests/manual_params_def.rs @@ -0,0 +1,23 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::params_def::*; + + +#[test] +fn test_params_def() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ParamsDef::default(); + + r.set_params(5, true); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.buf(), "foo|b"); + assert_eq!(*r.trailer(), 0x61); +} From fbee8d9ac13452071110a2092f9e1b121a793384 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Thu, 25 Aug 2022 21:24:37 +0200 Subject: [PATCH 068/198] deref for (EnumType, IntType) --- .../io/kaitai/struct/testtranslator/specgenerators/RustSG.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index aac9ba124..d00bb09d2 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -83,7 +83,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => - actStr = actStr + ".clone().to_owned() as u64" + actStr = s"${translator.remove_deref(actStr)}.clone().to_owned() as u64" case _ => } // fix expStr as vector From eb9d23f105f7e4924f7431da7265474fc928adb4 Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Thu, 25 Aug 2022 21:29:33 +0200 Subject: [PATCH 069/198] working tests --- formats_rust/enum_deep_literals.ksy | 29 ++++++++++++++++++++ formats_rust/enum_fancy.ksy | 21 +++++++++++++++ formats_rust/enum_for_unknown_id.ksy | 11 ++++++++ formats_rust/enum_if.ksy | 40 ++++++++++++++++++++++++++++ formats_rust/enum_import.ksy | 13 +++++++++ formats_rust/enum_int_range_s.ksy | 21 +++++++++++++++ formats_rust/enum_int_range_u.ksy | 17 ++++++++++++ formats_rust/enum_invalid.ksy | 13 +++++++++ formats_rust/enum_long_range_s.ksy | 37 +++++++++++++++++++++++++ formats_rust/enum_long_range_u.ksy | 25 +++++++++++++++++ formats_rust/enum_negative.ksy | 13 +++++++++ formats_rust/enum_of_value_inst.ksy | 21 +++++++++++++++ formats_rust/enum_to_i.ksy | 26 ++++++++++++++++++ 13 files changed, 287 insertions(+) create mode 100644 formats_rust/enum_deep_literals.ksy create mode 100644 formats_rust/enum_fancy.ksy create mode 100644 formats_rust/enum_for_unknown_id.ksy create mode 100644 formats_rust/enum_if.ksy create mode 100644 formats_rust/enum_import.ksy create mode 100644 formats_rust/enum_int_range_s.ksy create mode 100644 formats_rust/enum_int_range_u.ksy create mode 100644 formats_rust/enum_invalid.ksy create mode 100644 formats_rust/enum_long_range_s.ksy create mode 100644 formats_rust/enum_long_range_u.ksy create mode 100644 formats_rust/enum_negative.ksy create mode 100644 formats_rust/enum_of_value_inst.ksy create mode 100644 formats_rust/enum_to_i.ksy diff --git a/formats_rust/enum_deep_literals.ksy b/formats_rust/enum_deep_literals.ksy new file mode 100644 index 000000000..f3b44ef14 --- /dev/null +++ b/formats_rust/enum_deep_literals.ksy @@ -0,0 +1,29 @@ +meta: + id: enum_deep_literals + endian: le +seq: + - id: pet_1 + type: u4 + enum: container1::animal + - id: pet_2 + type: u4 + enum: container1::container2::animal +instances: + is_pet_1_ok: + value: pet_1 == container1::animal::cat + is_pet_2_ok: + value: pet_2 == container1::container2::animal::hare +types: + container1: + enums: + animal: + 4: dog + 7: cat + 12: chicken + types: + container2: + enums: + animal: + 4: canary + 7: turtle + 12: hare diff --git a/formats_rust/enum_fancy.ksy b/formats_rust/enum_fancy.ksy new file mode 100644 index 000000000..e6b899eb2 --- /dev/null +++ b/formats_rust/enum_fancy.ksy @@ -0,0 +1,21 @@ +meta: + id: enum_fancy + endian: le +seq: + - id: pet_1 + type: u4 + enum: animal + - id: pet_2 + type: u4 + enum: animal +enums: + animal: + 4: + id: dog + doc: A member of genus Canis. + -orig-id: MH_CANINE + 7: + id: cat + doc: Small, typically furry, carnivorous mammal. + -orig-id: MH_FELINE + 12: chicken diff --git a/formats_rust/enum_for_unknown_id.ksy b/formats_rust/enum_for_unknown_id.ksy new file mode 100644 index 000000000..fce1630e9 --- /dev/null +++ b/formats_rust/enum_for_unknown_id.ksy @@ -0,0 +1,11 @@ +meta: + id: enum_for_unknown_id +seq: + - id: one + type: u1 + enum: animal +enums: + animal: + 4: dog + 7: cat + 12: chicken diff --git a/formats_rust/enum_if.ksy b/formats_rust/enum_if.ksy new file mode 100644 index 000000000..26d0b0098 --- /dev/null +++ b/formats_rust/enum_if.ksy @@ -0,0 +1,40 @@ +meta: + id: enum_if + endian: le +seq: + - id: op1 + type: operation + - id: op2 + type: operation + - id: op3 + type: operation +types: + operation: + seq: + - id: opcode + type: u1 + enum: opcodes + - id: arg_tuple + type: arg_tuple + if: opcode == opcodes::a_tuple + - id: arg_str + type: arg_str + if: opcode == opcodes::a_string + arg_tuple: + seq: + - id: num1 + type: u1 + - id: num2 + type: u1 + arg_str: + seq: + - id: len + type: u1 + - id: str + type: str + size: len + encoding: UTF-8 +enums: + opcodes: + 0x53: a_string + 0x54: a_tuple diff --git a/formats_rust/enum_import.ksy b/formats_rust/enum_import.ksy new file mode 100644 index 000000000..bec0bff8a --- /dev/null +++ b/formats_rust/enum_import.ksy @@ -0,0 +1,13 @@ +meta: + id: enum_import + endian: le + imports: + - enum_0 + - enum_deep +seq: + - id: pet_1 + type: u4 + enum: enum_0::animal + - id: pet_2 + type: u4 + enum: enum_deep::container1::container2::animal diff --git a/formats_rust/enum_int_range_s.ksy b/formats_rust/enum_int_range_s.ksy new file mode 100644 index 000000000..a72c03bb9 --- /dev/null +++ b/formats_rust/enum_int_range_s.ksy @@ -0,0 +1,21 @@ +# Assert that enum id's can handle values in Int's range +meta: + id: enum_int_range_s + endian: be + +enums: + constants: + -2147483648: int_min + 0: zero + 2147483647: int_max + +seq: + - id: f1 + type: s4 + enum: constants + - id: f2 + type: s4 + enum: constants + - id: f3 + type: s4 + enum: constants diff --git a/formats_rust/enum_int_range_u.ksy b/formats_rust/enum_int_range_u.ksy new file mode 100644 index 000000000..120b3a1f8 --- /dev/null +++ b/formats_rust/enum_int_range_u.ksy @@ -0,0 +1,17 @@ +# Assert that enum id's can handle values in Int's range +meta: + id: enum_int_range_u + endian: be + +enums: + constants: + 0: zero + 4294967295: int_max + +seq: + - id: f1 + type: u4 + enum: constants + - id: f2 + type: u4 + enum: constants diff --git a/formats_rust/enum_invalid.ksy b/formats_rust/enum_invalid.ksy new file mode 100644 index 000000000..bace37da8 --- /dev/null +++ b/formats_rust/enum_invalid.ksy @@ -0,0 +1,13 @@ +meta: + id: enum_invalid +seq: + - id: pet_1 + type: u1 + enum: animal + - id: pet_2 + type: u1 + enum: animal +enums: + animal: + 0x66: dog + 0x7c: cat diff --git a/formats_rust/enum_long_range_s.ksy b/formats_rust/enum_long_range_s.ksy new file mode 100644 index 000000000..17e025817 --- /dev/null +++ b/formats_rust/enum_long_range_s.ksy @@ -0,0 +1,37 @@ +# Assert that enum id's can handle values in Long's range +meta: + id: enum_long_range_s + endian: be + +enums: + constants: + -9223372036854775808: long_min + -2147483649: int_below_min + -2147483648: int_min + 0: zero + 2147483647: int_max + 2147483648: int_over_max + 9223372036854775807: long_max + +seq: + - id: f1 + type: s8 + enum: constants + - id: f2 + type: s8 + enum: constants + - id: f3 + type: s8 + enum: constants + - id: f4 + type: s8 + enum: constants + - id: f5 + type: s8 + enum: constants + - id: f6 + type: s8 + enum: constants + - id: f7 + type: s8 + enum: constants diff --git a/formats_rust/enum_long_range_u.ksy b/formats_rust/enum_long_range_u.ksy new file mode 100644 index 000000000..453dc0856 --- /dev/null +++ b/formats_rust/enum_long_range_u.ksy @@ -0,0 +1,25 @@ +# Assert that enum id's can handle values in Long's range +meta: + id: enum_long_range_u + endian: be + +enums: + constants: + 0: zero + 4294967295: int_max + 4294967296: int_over_max + 9223372036854775807: long_max # todo with `9223372036854775807` generator will fail with `io.kaitai.struct.format.YAMLParseException: /enums/constants: expected int, got 18446744073709551615 (class java.math.BigInteger)` + +seq: + - id: f1 + type: u8 + enum: constants + - id: f2 + type: u8 + enum: constants + - id: f3 + type: u8 + enum: constants + - id: f4 + type: u8 + enum: constants diff --git a/formats_rust/enum_negative.ksy b/formats_rust/enum_negative.ksy new file mode 100644 index 000000000..ea7142c2a --- /dev/null +++ b/formats_rust/enum_negative.ksy @@ -0,0 +1,13 @@ +meta: + id: enum_negative +enums: + constants: + -1: negative_one + 1: positive_one +seq: + - id: f1 + type: s1 + enum: constants + - id: f2 + type: s1 + enum: constants diff --git a/formats_rust/enum_of_value_inst.ksy b/formats_rust/enum_of_value_inst.ksy new file mode 100644 index 000000000..c3e24a908 --- /dev/null +++ b/formats_rust/enum_of_value_inst.ksy @@ -0,0 +1,21 @@ +meta: + id: enum_of_value_inst + endian: le +seq: + - id: pet_1 + type: u4 + enum: animal + - id: pet_2 + type: u4 + enum: animal +enums: + animal: + 4: dog + 7: cat + 12: chicken +instances: + pet_3: + value: "pet_1 == animal::cat ? 4 : 12" + enum: animal + pet_4: + value: "pet_1 == animal::cat ? animal::dog : animal::chicken" diff --git a/formats_rust/enum_to_i.ksy b/formats_rust/enum_to_i.ksy new file mode 100644 index 000000000..3de13f6a0 --- /dev/null +++ b/formats_rust/enum_to_i.ksy @@ -0,0 +1,26 @@ +meta: + id: enum_to_i + endian: le +seq: + - id: pet_1 + type: u4 + enum: animal + - id: pet_2 + type: u4 + enum: animal +enums: + animal: + 4: dog + 7: cat + 12: chicken +instances: + pet_1_i: + value: pet_1.to_i + pet_1_mod: + value: pet_1.to_i + 0x8000 + one_lt_two: + value: pet_1.to_i < pet_2.to_i + pet_1_eq_int: + value: pet_1.to_i == 7 + pet_2_eq_int: + value: pet_2.to_i == 5 From 2d270d242ee45afa829fe13d462049b893114aef Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 27 Aug 2022 09:21:15 +0200 Subject: [PATCH 070/198] enum_import need to be fixed (removed). --- formats_rust/enum_import.ksy | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 formats_rust/enum_import.ksy diff --git a/formats_rust/enum_import.ksy b/formats_rust/enum_import.ksy deleted file mode 100644 index bec0bff8a..000000000 --- a/formats_rust/enum_import.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: enum_import - endian: le - imports: - - enum_0 - - enum_deep -seq: - - id: pet_1 - type: u4 - enum: enum_0::animal - - id: pet_2 - type: u4 - enum: enum_deep::container1::container2::animal From e344dfd1666ea983ca57181a6a63cd65103799e9 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 1 Sep 2022 08:14:58 +0200 Subject: [PATCH 071/198] added fixed version of test_enum_for_unknown_id. --- spec/rust/tests/test_enum_for_unknown_id.rs | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 spec/rust/tests/test_enum_for_unknown_id.rs diff --git a/spec/rust/tests/test_enum_for_unknown_id.rs b/spec/rust/tests/test_enum_for_unknown_id.rs new file mode 100644 index 000000000..025cb3bc8 --- /dev/null +++ b/spec/rust/tests/test_enum_for_unknown_id.rs @@ -0,0 +1,22 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::enum_for_unknown_id::*; + + +#[test] +fn test_enum_for_unknown_id() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = EnumForUnknownId::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + println!("expected err: {:?}, exception: UnknownVariant", err); + } else { + panic!("no expected exception: UnknownVariant"); + } + + //assert_eq!(r.one().clone().to_owned() as u64, 80); +} From 75da8a10163ca12c666829b2e42781f686c6f931 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 1 Sep 2022 08:45:48 +0200 Subject: [PATCH 072/198] manually edited test_enum_invalid added. --- spec/rust/tests/test_enum_invalid.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 spec/rust/tests/test_enum_invalid.rs diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs new file mode 100644 index 000000000..e310dd5e1 --- /dev/null +++ b/spec/rust/tests/test_enum_invalid.rs @@ -0,0 +1,23 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::enum_invalid::*; + + +#[test] +fn test_enum_invalid() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = EnumInvalid::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + println!("expected err: {:?}, exception: UnknownVariant", err); + } else { + panic!("no expected exception: UnknownVariant"); + } + + // assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); + // assert_eq!(r.pet_2().clone().to_owned() as u64, 111); +} From 7c2948053cc9e8dab81d97a075f0c4797445255f Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 1 Sep 2022 14:15:26 +0200 Subject: [PATCH 073/198] expr_mod test. --- formats_rust/expr_mod.ksy | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 formats_rust/expr_mod.ksy diff --git a/formats_rust/expr_mod.ksy b/formats_rust/expr_mod.ksy new file mode 100644 index 000000000..bd218a7ee --- /dev/null +++ b/formats_rust/expr_mod.ksy @@ -0,0 +1,18 @@ +# Tests modulo operation, both positive and negative +meta: + id: expr_mod + endian: le +seq: + - id: int_u + type: u4 + - id: int_s + type: s4 +instances: + mod_pos_const: + value: 9837 % 13 + mod_neg_const: + value: -9837 % 13 + mod_pos_seq: + value: int_u % 13 + mod_neg_seq: + value: int_s % 13 From 4e19b3f83c53fa406bd160eaf06dd117218746f2 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 1 Sep 2022 16:04:01 +0200 Subject: [PATCH 074/198] expr_ops_parens tests. --- formats_rust/expr_ops_parens.ksy | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 formats_rust/expr_ops_parens.ksy diff --git a/formats_rust/expr_ops_parens.ksy b/formats_rust/expr_ops_parens.ksy new file mode 100644 index 000000000..1ed344356 --- /dev/null +++ b/formats_rust/expr_ops_parens.ksy @@ -0,0 +1,36 @@ +meta: + id: expr_ops_parens +instances: + i_42: + value: 42 + i_m13: + value: -13 + i_sum_to_str: + value: (i_42 + i_m13).to_s + + f_2pi: + value: 6.28 + f_e: + value: 2.72 + f_sum_to_int: + value: (f_2pi + f_e).to_i + + str_0_to_4: + value: '"01234"' + str_5_to_9: + value: '"56789"' + str_concat_len: + value: (str_0_to_4 + str_5_to_9).length + str_concat_rev: + value: (str_0_to_4 + str_5_to_9).reverse + str_concat_substr_2_to_7: + value: (str_0_to_4 + str_5_to_9).substring(2, 7) + str_concat_to_i: + value: (str_0_to_4 + str_5_to_9).to_i + + bool_eq: + value: (false == true).to_i + bool_and: + value: (false and true).to_i + bool_or: + value: (not false or false).to_i From 257821fce75e68f90ccbf85212df401af8ef5798 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 2 Sep 2022 09:55:19 +0200 Subject: [PATCH 075/198] expr_enum tests. --- formats_rust/expr_enum.ksy | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 formats_rust/expr_enum.ksy diff --git a/formats_rust/expr_enum.ksy b/formats_rust/expr_enum.ksy new file mode 100644 index 000000000..793949db8 --- /dev/null +++ b/formats_rust/expr_enum.ksy @@ -0,0 +1,22 @@ +# Tests enum for value instances +meta: + id: expr_enum +seq: + - id: one + type: u1 +instances: + const_dog: + value: 4 + enum: animal + derived_boom: + value: one + enum: animal + derived_dog: + value: one - 98 + enum: animal +enums: + animal: + 4: dog + 7: cat + 12: chicken + 0x66: boom From e7343c859def7bd18f1038e733dfadc208b266ec Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 2 Sep 2022 09:55:34 +0200 Subject: [PATCH 076/198] expr_sizeof_type_0 tests. --- formats_rust/expr_sizeof_type_0.ksy | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 formats_rust/expr_sizeof_type_0.ksy diff --git a/formats_rust/expr_sizeof_type_0.ksy b/formats_rust/expr_sizeof_type_0.ksy new file mode 100644 index 000000000..1bdd2f6d0 --- /dev/null +++ b/formats_rust/expr_sizeof_type_0.ksy @@ -0,0 +1,15 @@ +meta: + id: expr_sizeof_type_0 + endian: le +types: + block: + seq: + - id: a + type: u1 + - id: b + type: u4 + - id: c + size: 2 +instances: + sizeof_block: + value: sizeof From 0660cac2f0599c671b5b28f134ee17761f4ad667 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 2 Sep 2022 21:10:48 +0200 Subject: [PATCH 077/198] new tests. --- formats_rust/expr_sizeof_type_1.ksy | 24 ++++++++++++++ formats_rust/expr_sizeof_value_0.ksy | 28 ++++++++++++++++ formats_rust/expr_sizeof_value_sized.ksy | 29 ++++++++++++++++ formats_rust/expr_str_ops.ksy | 42 ++++++++++++++++++++++++ 4 files changed, 123 insertions(+) create mode 100644 formats_rust/expr_sizeof_type_1.ksy create mode 100644 formats_rust/expr_sizeof_value_0.ksy create mode 100644 formats_rust/expr_sizeof_value_sized.ksy create mode 100644 formats_rust/expr_str_ops.ksy diff --git a/formats_rust/expr_sizeof_type_1.ksy b/formats_rust/expr_sizeof_type_1.ksy new file mode 100644 index 000000000..98aeb04b1 --- /dev/null +++ b/formats_rust/expr_sizeof_type_1.ksy @@ -0,0 +1,24 @@ +meta: + id: expr_sizeof_type_1 + endian: le +types: + block: + seq: + - id: a + type: u1 + - id: b + type: u4 + - id: c + size: 2 + - id: d + type: subblock + types: + subblock: + seq: + - id: a + size: 4 +instances: + sizeof_block: + value: sizeof + sizeof_subblock: + value: sizeof diff --git a/formats_rust/expr_sizeof_value_0.ksy b/formats_rust/expr_sizeof_value_0.ksy new file mode 100644 index 000000000..977aa3601 --- /dev/null +++ b/formats_rust/expr_sizeof_value_0.ksy @@ -0,0 +1,28 @@ +meta: + id: expr_sizeof_value_0 + endian: le +types: + block: + seq: + - id: a + type: u1 + - id: b + type: u4 + - id: c + size: 2 +seq: + - id: block1 + type: block + - id: more + type: u2 +instances: + self_sizeof: + value: _sizeof + sizeof_block: + value: block1._sizeof + sizeof_block_a: + value: block1.a._sizeof + sizeof_block_b: + value: block1.b._sizeof + sizeof_block_c: + value: block1.c._sizeof diff --git a/formats_rust/expr_sizeof_value_sized.ksy b/formats_rust/expr_sizeof_value_sized.ksy new file mode 100644 index 000000000..ad07613fd --- /dev/null +++ b/formats_rust/expr_sizeof_value_sized.ksy @@ -0,0 +1,29 @@ +meta: + id: expr_sizeof_value_sized + endian: le +types: + block: + seq: + - id: a + type: u1 + - id: b + type: u4 + - id: c + size: 2 +seq: + - id: block1 + type: block + size: 12 + - id: more + type: u2 +instances: + self_sizeof: + value: _sizeof + sizeof_block: + value: block1._sizeof + sizeof_block_a: + value: block1.a._sizeof + sizeof_block_b: + value: block1.b._sizeof + sizeof_block_c: + value: block1.c._sizeof diff --git a/formats_rust/expr_str_ops.ksy b/formats_rust/expr_str_ops.ksy new file mode 100644 index 000000000..6337bd6ae --- /dev/null +++ b/formats_rust/expr_str_ops.ksy @@ -0,0 +1,42 @@ +meta: + id: expr_str_ops + encoding: ASCII +seq: + - id: one + type: str + size: 5 +instances: + one_len: + value: one.length + one_rev: + value: one.reverse + one_substr_0_to_3: + value: one.substring(0, 3) + one_substr_2_to_5: + value: one.substring(2, 5) + one_substr_3_to_3: + value: one.substring(3, 3) + + two: + value: '"0123456789"' + two_len: + value: two.length + two_rev: + value: two.reverse + two_substr_0_to_7: + value: two.substring(0, 7) + two_substr_4_to_10: + value: two.substring(4, 10) + two_substr_0_to_10: + value: two.substring(0, 10) + + to_i_attr: + value: '"9173".to_i' + to_i_r10: + value: '"-072".to_i(10)' + to_i_r2: + value: '"1010110".to_i(2)' + to_i_r8: + value: '"721".to_i(8)' + to_i_r16: + value: '"47cf".to_i(16)' From 7bd569b58df99ad52dc77c74c0c75040fe926196 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 3 Sep 2022 13:31:29 +0200 Subject: [PATCH 078/198] expr_str_encodings test. --- formats_rust/expr_str_encodings.ksy | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 formats_rust/expr_str_encodings.ksy diff --git a/formats_rust/expr_str_encodings.ksy b/formats_rust/expr_str_encodings.ksy new file mode 100644 index 000000000..34759905e --- /dev/null +++ b/formats_rust/expr_str_encodings.ksy @@ -0,0 +1,44 @@ +meta: + id: expr_str_encodings + endian: le +seq: + - id: len_of_1 + type: u2 + - id: str1 + type: str + size: len_of_1 + encoding: ASCII + - id: len_of_2 + type: u2 + - id: str2 + type: str + size: len_of_2 + encoding: UTF-8 + - id: len_of_3 + type: u2 + - id: str3 + type: str + size: len_of_3 + encoding: SJIS + - id: len_of_4 + type: u2 + - id: str4 + type: str + size: len_of_4 + encoding: CP866 +instances: + str1_eq: + value: str1 == "Some ASCII" + str2_eq: + value: str2 == "こんにちは" + str3_eq: + value: str3 == "こんにちは" + str3_eq_str2: + value: str3 == str2 + str4_eq: + value: str4 == "░▒▓" + str4_gt_str_calc: + value: str4 > "┤" # in UTF-8 "░" (U+2591) > "┤" (U+2524), + # in CP437 "░" (0xB0) < "┤" (0xB4) + str4_gt_str_from_bytes: + value: 'str4 > [0xb4].to_s("CP866")' From a73feb12650dd474539745393c72bebdbd7c2b43 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sun, 4 Sep 2022 09:13:33 +0200 Subject: [PATCH 079/198] more tests. --- formats_rust/hello_world.ksy | 5 +++++ formats_rust/if_instances.ksy | 9 +++++++++ formats_rust/if_struct.ksy | 35 +++++++++++++++++++++++++++++++++++ formats_rust/if_values.ksy | 17 +++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100644 formats_rust/hello_world.ksy create mode 100644 formats_rust/if_instances.ksy create mode 100644 formats_rust/if_struct.ksy create mode 100644 formats_rust/if_values.ksy diff --git a/formats_rust/hello_world.ksy b/formats_rust/hello_world.ksy new file mode 100644 index 000000000..cde97cd79 --- /dev/null +++ b/formats_rust/hello_world.ksy @@ -0,0 +1,5 @@ +meta: + id: hello_world +seq: + - id: one + type: u1 diff --git a/formats_rust/if_instances.ksy b/formats_rust/if_instances.ksy new file mode 100644 index 000000000..186371466 --- /dev/null +++ b/formats_rust/if_instances.ksy @@ -0,0 +1,9 @@ +# Checks that `if` for instance protects us from doing any activity +# for instance completely, including seeks. +meta: + id: if_instances +instances: + never_happens: + pos: 100500 # does not exist in the stream + type: u1 + if: 'false' # should never happen diff --git a/formats_rust/if_struct.ksy b/formats_rust/if_struct.ksy new file mode 100644 index 000000000..79009fd3a --- /dev/null +++ b/formats_rust/if_struct.ksy @@ -0,0 +1,35 @@ +meta: + id: if_struct + endian: le +seq: + - id: op1 + type: operation + - id: op2 + type: operation + - id: op3 + type: operation +types: + operation: + seq: + - id: opcode + type: u1 + - id: arg_tuple + type: arg_tuple + if: opcode == 0x54 # "T" + - id: arg_str + type: arg_str + if: opcode == 0x53 # "S" + arg_tuple: + seq: + - id: num1 + type: u1 + - id: num2 + type: u1 + arg_str: + seq: + - id: len + type: u1 + - id: str + type: str + size: len + encoding: UTF-8 diff --git a/formats_rust/if_values.ksy b/formats_rust/if_values.ksy new file mode 100644 index 000000000..b781b3e82 --- /dev/null +++ b/formats_rust/if_values.ksy @@ -0,0 +1,17 @@ +meta: + id: if_values + endian: le +seq: + - id: codes + type: code + repeat: expr + repeat-expr: 3 +types: + code: + seq: + - id: opcode + type: u1 + instances: + half_opcode: + value: opcode / 2 + if: opcode % 2 == 0 From ab903f2774f197466862b24abd5dbef1b5c48fcd Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sun, 4 Sep 2022 13:29:47 +0200 Subject: [PATCH 080/198] index_ tests. --- formats_rust/index_sizes.ksy | 16 ++++++++++++++++ formats_rust/index_to_param_eos.ksy | 24 ++++++++++++++++++++++++ formats_rust/index_to_param_expr.ksy | 25 +++++++++++++++++++++++++ formats_rust/index_to_param_until.ksy | 25 +++++++++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 formats_rust/index_sizes.ksy create mode 100644 formats_rust/index_to_param_eos.ksy create mode 100644 formats_rust/index_to_param_expr.ksy create mode 100644 formats_rust/index_to_param_until.ksy diff --git a/formats_rust/index_sizes.ksy b/formats_rust/index_sizes.ksy new file mode 100644 index 000000000..be14289c6 --- /dev/null +++ b/formats_rust/index_sizes.ksy @@ -0,0 +1,16 @@ +meta: + id: index_sizes + endian: le + encoding: ASCII +seq: + - id: qty + type: u4 + - id: sizes + type: u4 + repeat: expr + repeat-expr: qty + - id: bufs + type: str + size: sizes[_index] + repeat: expr + repeat-expr: qty diff --git a/formats_rust/index_to_param_eos.ksy b/formats_rust/index_to_param_eos.ksy new file mode 100644 index 000000000..d8faef0e5 --- /dev/null +++ b/formats_rust/index_to_param_eos.ksy @@ -0,0 +1,24 @@ +meta: + id: index_to_param_eos + endian: le + encoding: ASCII +seq: + - id: qty + type: u4 + - id: sizes + type: u4 + repeat: expr + repeat-expr: qty + - id: blocks + type: block(_index) + repeat: eos +types: + block: + params: + - id: idx + type: s4 # NB: C# requires this to be signed + seq: + - id: buf + size: _root.sizes[idx] + type: str + encoding: ASCII diff --git a/formats_rust/index_to_param_expr.ksy b/formats_rust/index_to_param_expr.ksy new file mode 100644 index 000000000..9eed2acd2 --- /dev/null +++ b/formats_rust/index_to_param_expr.ksy @@ -0,0 +1,25 @@ +meta: + id: index_to_param_expr + endian: le + encoding: ASCII +seq: + - id: qty + type: u4 + - id: sizes + type: u4 + repeat: expr + repeat-expr: qty + - id: blocks + type: block(_index) + repeat: expr + repeat-expr: qty +types: + block: + params: + - id: idx + type: s4 # NB: C# requires this to be signed + seq: + - id: buf + size: _root.sizes[idx] + type: str + encoding: ASCII diff --git a/formats_rust/index_to_param_until.ksy b/formats_rust/index_to_param_until.ksy new file mode 100644 index 000000000..f02a97b1c --- /dev/null +++ b/formats_rust/index_to_param_until.ksy @@ -0,0 +1,25 @@ +meta: + id: index_to_param_until + endian: le + encoding: ASCII +seq: + - id: qty + type: u4 + - id: sizes + type: u4 + repeat: expr + repeat-expr: qty + - id: blocks + type: block(_index) + repeat: until + repeat-until: _io.eof +types: + block: + params: + - id: idx + type: s4 # NB: C# requires this to be signed + seq: + - id: buf + size: _root.sizes[idx] + type: str + encoding: ASCII From 817d4192f38078e3be9448244636ffb6bf78836a Mon Sep 17 00:00:00 2001 From: Vitaly Reshetyuk Date: Tue, 6 Sep 2022 21:55:13 +0200 Subject: [PATCH 081/198] workaround for `test_enum_to_i_class_border_1` --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index a147f22c0..45ea84c4c 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -91,6 +91,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs expStr = remove_ref(expStr) } finish_panic() + //TODO: correct code generation + actStr = actStr.replace("_io", "reader") + actStr = actStr.replace("(reader)?", "(&reader).expect(\"error reading\")") out.puts(s"assert_eq!($actStr, $expStr);") } From 164c180cb7a6e9df0b8e5fdbfb687cd416f23ebe Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 9 Sep 2022 14:49:40 +0200 Subject: [PATCH 082/198] repeat_until_ tests. --- formats_rust/repeat_until_calc_array_type.ksy | 22 +++++++++++++ formats_rust/repeat_until_complex.ksy | 33 +++++++++++++++++++ formats_rust/repeat_until_s4.ksy | 11 +++++++ formats_rust/repeat_until_sized.ksy | 16 +++++++++ 4 files changed, 82 insertions(+) create mode 100644 formats_rust/repeat_until_calc_array_type.ksy create mode 100644 formats_rust/repeat_until_complex.ksy create mode 100644 formats_rust/repeat_until_s4.ksy create mode 100644 formats_rust/repeat_until_sized.ksy diff --git a/formats_rust/repeat_until_calc_array_type.ksy b/formats_rust/repeat_until_calc_array_type.ksy new file mode 100644 index 000000000..9fac2664f --- /dev/null +++ b/formats_rust/repeat_until_calc_array_type.ksy @@ -0,0 +1,22 @@ +meta: + id: repeat_until_calc_array_type + endian: le +seq: + - id: records + size: 5 + type: record + repeat: until + repeat-until: _.marker == 0xaa +types: + record: + seq: + - id: marker + type: u1 + - id: body + type: u4 +instances: + recs_accessor: + value: records + + first_rec: + value: recs_accessor.first diff --git a/formats_rust/repeat_until_complex.ksy b/formats_rust/repeat_until_complex.ksy new file mode 100644 index 000000000..cf9a67c72 --- /dev/null +++ b/formats_rust/repeat_until_complex.ksy @@ -0,0 +1,33 @@ +meta: + id: repeat_until_complex + endian: le +seq: + - id: first + type: type_u1 + repeat: until + repeat-until: _.count == 0 + - id: second + type: type_u2 + repeat: until + repeat-until: _.count == 0 + - id: third + type: u1 + repeat: until + repeat-until: _ == 0 +types: + type_u1: + seq: + - id: count + type: u1 + - id: values + type: u1 + repeat: expr + repeat-expr: count + type_u2: + seq: + - id: count + type: u2 + - id: values + type: u2 + repeat: expr + repeat-expr: count diff --git a/formats_rust/repeat_until_s4.ksy b/formats_rust/repeat_until_s4.ksy new file mode 100644 index 000000000..006ee6f7a --- /dev/null +++ b/formats_rust/repeat_until_s4.ksy @@ -0,0 +1,11 @@ +meta: + id: repeat_until_s4 + endian: le +seq: + - id: entries + type: s4 + repeat: until + repeat-until: _ == -1 + - id: afterall + type: strz + encoding: ASCII diff --git a/formats_rust/repeat_until_sized.ksy b/formats_rust/repeat_until_sized.ksy new file mode 100644 index 000000000..61c4a08b4 --- /dev/null +++ b/formats_rust/repeat_until_sized.ksy @@ -0,0 +1,16 @@ +meta: + id: repeat_until_sized + endian: le +seq: + - id: records + size: 5 + type: record + repeat: until + repeat-until: _.marker == 0xaa +types: + record: + seq: + - id: marker + type: u1 + - id: body + type: u4 From 609c05a88fe92d093100d880a3eb876c1e04a102 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 15 Sep 2022 20:37:25 +0200 Subject: [PATCH 083/198] instance tests. --- formats_rust/instance_std.ksy | 9 ++++++++ formats_rust/instance_std_array.ksy | 16 +++++++++++++ spec/rust/tests/test_instance_std_array.rs | 26 ++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 formats_rust/instance_std.ksy create mode 100644 formats_rust/instance_std_array.ksy create mode 100644 spec/rust/tests/test_instance_std_array.rs diff --git a/formats_rust/instance_std.ksy b/formats_rust/instance_std.ksy new file mode 100644 index 000000000..84085d9f8 --- /dev/null +++ b/formats_rust/instance_std.ksy @@ -0,0 +1,9 @@ +meta: + id: instance_std + endian: le +instances: + header: + pos: 2 + type: str + size: 5 + encoding: ASCII diff --git a/formats_rust/instance_std_array.ksy b/formats_rust/instance_std_array.ksy new file mode 100644 index 000000000..3298e1641 --- /dev/null +++ b/formats_rust/instance_std_array.ksy @@ -0,0 +1,16 @@ +meta: + id: instance_std_array + endian: le +seq: + - id: ofs + type: u4 + - id: entry_size + type: u4 + - id: qty_entries + type: u4 +instances: + entries: + pos: ofs + repeat: expr + repeat-expr: qty_entries + size: entry_size diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs new file mode 100644 index 000000000..938266951 --- /dev/null +++ b/spec/rust/tests/test_instance_std_array.rs @@ -0,0 +1,26 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::instance_std_array::*; + + +#[test] +fn test_instance_std_array() { + let bytes = fs::read("../../src/instance_std_array.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = InstanceStdArray::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.ofs(), 16); + assert_eq!(*r.qty_entries(), 3); + assert_eq!(*r.entry_size(), 4); + assert_eq!(r.entries(&reader).unwrap().len(), 3); + assert_eq!(r.entries(&reader).unwrap()[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); + assert_eq!(r.entries(&reader).unwrap()[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); + assert_eq!(r.entries(&reader).unwrap()[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); +} From 4e05090b9fa862a3de27c207e4e34c3ea290d43d Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 16 Sep 2022 09:32:15 +0200 Subject: [PATCH 084/198] instance_user_array test. --- formats_rust/instance_user_array.ksy | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 formats_rust/instance_user_array.ksy diff --git a/formats_rust/instance_user_array.ksy b/formats_rust/instance_user_array.ksy new file mode 100644 index 000000000..479135e35 --- /dev/null +++ b/formats_rust/instance_user_array.ksy @@ -0,0 +1,25 @@ +meta: + id: instance_user_array + endian: le +seq: + - id: ofs + type: u4 + - id: entry_size + type: u4 + - id: qty_entries + type: u4 +types: + entry: + seq: + - id: word1 + type: u2 + - id: word2 + type: u2 +instances: + user_entries: + pos: ofs + repeat: expr + repeat-expr: qty_entries + size: entry_size + type: entry + if: ofs > 0 From 14da7b583a9f5c8e41c2744a4313bd5cf7e0e574 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sun, 18 Sep 2022 10:55:31 +0200 Subject: [PATCH 085/198] root arg restored for instaince methods. --- formats_rust/instance_io_user.ksy | 32 +++++++++++++++++++ spec/rust/tests/manual_str_literals.rs | 10 +++--- spec/rust/tests/test_expr_int_div.rs | 8 ++--- spec/rust/tests/test_instance_std_array.rs | 8 ++--- .../specgenerators/RustSG.scala | 2 +- 5 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 formats_rust/instance_io_user.ksy diff --git a/formats_rust/instance_io_user.ksy b/formats_rust/instance_io_user.ksy new file mode 100644 index 000000000..f5b7feeed --- /dev/null +++ b/formats_rust/instance_io_user.ksy @@ -0,0 +1,32 @@ +meta: + id: instance_io_user + endian: le +seq: + - id: qty_entries + type: u4 + - id: entries + type: entry + repeat: expr + repeat-expr: qty_entries + - id: strings + type: strings_obj + size-eos: true +types: + entry: + seq: + - id: name_ofs + type: u4 + - id: value + type: u4 + instances: + name: + io: _root.strings._io + pos: name_ofs + type: strz + encoding: UTF-8 + strings_obj: + seq: + - id: str + type: strz + encoding: UTF-8 + repeat: eos diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/manual_str_literals.rs index b012e4d8b..87082aafa 100644 --- a/spec/rust/tests/manual_str_literals.rs +++ b/spec/rust/tests/manual_str_literals.rs @@ -18,18 +18,18 @@ fn basic_parse() { assert!(res.is_ok()); } - let backslashes = r.backslashes(&reader).unwrap(); + let backslashes = r.backslashes(&reader, Some(&r)).unwrap(); assert_eq!("\u{005c}\u{005c}\u{005c}", *backslashes); - let octal_eatup = r.octal_eatup(&reader).unwrap(); + let octal_eatup = r.octal_eatup(&reader, Some(&r)).unwrap(); assert_eq!("\u{0}\u{0032}\u{0032}", *octal_eatup); - let octal_eatup2 = r.octal_eatup2(&reader).unwrap(); + let octal_eatup2 = r.octal_eatup2(&reader, Some(&r)).unwrap(); assert_eq!("\u{2}\u{32}", *octal_eatup2); - let double_quotes = r.double_quotes(&reader).unwrap(); + let double_quotes = r.double_quotes(&reader, Some(&r)).unwrap(); assert_eq!("\u{22}\u{22}\u{22}", *double_quotes); - let complex_str = r.complex_str(&reader).unwrap(); + let complex_str = r.complex_str(&reader, Some(&r)).unwrap(); assert_eq!("\u{0}\u{1}\u{2}\u{7}\u{8}\u{0a}\u{0d}\u{09}\u{0b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}", *complex_str); } \ No newline at end of file diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index e88b4b780..3bc788cdc 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -17,8 +17,8 @@ fn test_expr_int_div() { assert_eq!(*r.int_u(), 1262698832); assert_eq!(*r.int_s(), -52947); - assert_eq!(*r.div_pos_const(&reader).unwrap(), 756); - assert_eq!(*r.div_neg_const(&reader).unwrap(), -756); - assert_eq!(*r.div_pos_seq(&reader).unwrap(), 97130679); - assert_eq!(*r.div_neg_seq(&reader).unwrap(), -4072); + assert_eq!(*r.div_pos_const(&reader, Some(&r)).unwrap(), 756); + assert_eq!(*r.div_neg_const(&reader, Some(&r)).unwrap(), -756); + assert_eq!(*r.div_pos_seq(&reader, Some(&r)).unwrap(), 97130679); + assert_eq!(*r.div_neg_seq(&reader, Some(&r)).unwrap(), -4072); } diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs index 938266951..91b34866c 100644 --- a/spec/rust/tests/test_instance_std_array.rs +++ b/spec/rust/tests/test_instance_std_array.rs @@ -19,8 +19,8 @@ fn test_instance_std_array() { assert_eq!(*r.ofs(), 16); assert_eq!(*r.qty_entries(), 3); assert_eq!(*r.entry_size(), 4); - assert_eq!(r.entries(&reader).unwrap().len(), 3); - assert_eq!(r.entries(&reader).unwrap()[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); - assert_eq!(r.entries(&reader).unwrap()[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); - assert_eq!(r.entries(&reader).unwrap()[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); + assert_eq!(r.entries(&reader, Some(&r)).unwrap().len(), 3); + assert_eq!(r.entries(&reader, Some(&r)).unwrap()[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); + assert_eq!(r.entries(&reader, Some(&r)).unwrap()[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); + assert_eq!(r.entries(&reader, Some(&r)).unwrap()[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 45ea84c4c..3f2ed9a8c 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -131,7 +131,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs last = attr val found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), attr) if (found.isDefined) { - ttx2 = s"$ttx2.$attr(&reader).unwrap()${attr_full.substring(ind + 2, attr_full.length())}" + ttx2 = s"$ttx2.$attr(&reader, Some(&r)).unwrap()${attr_full.substring(ind + 2, attr_full.length())}" } else { ttx2 = s"$ttx2.$attr_full" } From b4510b6be22b374aa24de7d98acd4f094d96a023 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sun, 18 Sep 2022 17:49:50 +0200 Subject: [PATCH 086/198] integer tests. --- formats_rust/integers.ksy | 58 +++++++++++++++++++++++ formats_rust/integers_double_overflow.ksy | 34 +++++++++++++ formats_rust/integers_min_max.ksy | 44 +++++++++++++++++ 3 files changed, 136 insertions(+) create mode 100644 formats_rust/integers.ksy create mode 100644 formats_rust/integers_double_overflow.ksy create mode 100644 formats_rust/integers_min_max.ksy diff --git a/formats_rust/integers.ksy b/formats_rust/integers.ksy new file mode 100644 index 000000000..03da326fe --- /dev/null +++ b/formats_rust/integers.ksy @@ -0,0 +1,58 @@ +meta: + id: integers + endian: le +seq: + - id: magic1 + contents: 'PACK-1' + - id: uint8 + type: u1 + - id: sint8 + type: s1 + - id: magic_uint + contents: 'PACK-U-DEF' + - id: uint16 + type: u2 + - id: uint32 + type: u4 + - id: uint64 + type: u8 + - id: magic_sint + contents: 'PACK-S-DEF' + - id: sint16 + type: s2 + - id: sint32 + type: s4 + - id: sint64 + type: s8 + - id: magic_uint_le + contents: 'PACK-U-LE' + - id: uint16le + type: u2le + - id: uint32le + type: u4le + - id: uint64le + type: u8le + - id: magic_sint_le + contents: 'PACK-S-LE' + - id: sint16le + type: s2le + - id: sint32le + type: s4le + - id: sint64le + type: s8le + - id: magic_uint_be + contents: 'PACK-U-BE' + - id: uint16be + type: u2be + - id: uint32be + type: u4be + - id: uint64be + type: u8be + - id: magic_sint_be + contents: 'PACK-S-BE' + - id: sint16be + type: s2be + - id: sint32be + type: s4be + - id: sint64be + type: s8be diff --git a/formats_rust/integers_double_overflow.ksy b/formats_rust/integers_double_overflow.ksy new file mode 100644 index 000000000..6c065e762 --- /dev/null +++ b/formats_rust/integers_double_overflow.ksy @@ -0,0 +1,34 @@ +# Tests reading un/signed 64-bit integers in languages representing integers as 64-bit floats ("double"s) +# It is intended especially for JavaScript. +meta: + id: integers_double_overflow +seq: + - id: signed_safe_min_be # 0x00 + type: s8be + - id: signed_safe_min_le # 0x08 + type: s8le + - id: signed_safe_max_be # 0x10 + type: s8be + - id: signed_safe_max_le # 0x18 + type: s8le + - id: signed_unsafe_neg_be # 0x20 + type: s8be + - id: signed_unsafe_neg_le # 0x28 + type: s8le + - id: signed_unsafe_pos_be # 0x30 + type: s8be + - id: signed_unsafe_pos_le # 0x38 + type: s8le +instances: + unsigned_safe_max_be: + pos: 0x10 + type: u8be + unsigned_safe_max_le: + pos: 0x18 + type: u8le + unsigned_unsafe_pos_be: + pos: 0x30 + type: u8be + unsigned_unsafe_pos_le: + pos: 0x38 + type: u8le diff --git a/formats_rust/integers_min_max.ksy b/formats_rust/integers_min_max.ksy new file mode 100644 index 000000000..4f7b011d2 --- /dev/null +++ b/formats_rust/integers_min_max.ksy @@ -0,0 +1,44 @@ +meta: + id: integers_min_max +seq: + - id: unsigned_min + type: unsigned + - id: unsigned_max + type: unsigned + - id: signed_min + type: signed + - id: signed_max + type: signed +types: + unsigned: + seq: + - id: u1 + type: u1 + - id: u2le + type: u2le + - id: u4le + type: u4le + - id: u8le + type: u8le + - id: u2be + type: u2be + - id: u4be + type: u4be + - id: u8be + type: u8be + signed: + seq: + - id: s1 + type: s1 + - id: s2le + type: s2le + - id: s4le + type: s4le + - id: s8le + type: s8le + - id: s2be + type: s2be + - id: s4be + type: s4be + - id: s8be + type: s8be From dbc747424e67a6df59696b90b75b44591d52e271 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 22 Sep 2022 21:01:55 +0200 Subject: [PATCH 087/198] more tests. --- formats_rust/meta_tags.ksy | 7 ++++++ formats_rust/meta_xref.ksy | 6 +++++ formats_rust/multiple_use.ksy | 22 +++++++++++++++++ formats_rust/optional_id.ksy | 6 +++++ formats_rust/process_coerce_usertype1.ksy | 30 +++++++++++++++++++++++ formats_rust/process_coerce_usertype2.ksy | 30 +++++++++++++++++++++++ formats_rust/repeat_eos_struct.ksy | 14 +++++++++++ formats_rust/repeat_eos_u4.ksy | 7 ++++++ formats_rust/repeat_n_struct.ksy | 17 +++++++++++++ formats_rust/repeat_n_strz.ksy | 11 +++++++++ formats_rust/repeat_n_strz_double.ksy | 16 ++++++++++++ spec/rust/tests/test_repeat_eos_struct.rs | 24 ++++++++++++++++++ spec/rust/tests/test_repeat_n_struct.rs | 24 ++++++++++++++++++ 13 files changed, 214 insertions(+) create mode 100644 formats_rust/meta_tags.ksy create mode 100644 formats_rust/meta_xref.ksy create mode 100644 formats_rust/multiple_use.ksy create mode 100644 formats_rust/optional_id.ksy create mode 100644 formats_rust/process_coerce_usertype1.ksy create mode 100644 formats_rust/process_coerce_usertype2.ksy create mode 100644 formats_rust/repeat_eos_struct.ksy create mode 100644 formats_rust/repeat_eos_u4.ksy create mode 100644 formats_rust/repeat_n_struct.ksy create mode 100644 formats_rust/repeat_n_strz.ksy create mode 100644 formats_rust/repeat_n_strz_double.ksy create mode 100644 spec/rust/tests/test_repeat_eos_struct.rs create mode 100644 spec/rust/tests/test_repeat_n_struct.rs diff --git a/formats_rust/meta_tags.ksy b/formats_rust/meta_tags.ksy new file mode 100644 index 000000000..66bc521de --- /dev/null +++ b/formats_rust/meta_tags.ksy @@ -0,0 +1,7 @@ +# Only ksc +meta: + id: meta_tags + tags: + - foo + - bar + - baz diff --git a/formats_rust/meta_xref.ksy b/formats_rust/meta_xref.ksy new file mode 100644 index 000000000..e2531c07f --- /dev/null +++ b/formats_rust/meta_xref.ksy @@ -0,0 +1,6 @@ +# Only ksc +meta: + id: meta_xref + xref: + wikidata: foo + repo: https://example.com/ diff --git a/formats_rust/multiple_use.ksy b/formats_rust/multiple_use.ksy new file mode 100644 index 000000000..8f984ce47 --- /dev/null +++ b/formats_rust/multiple_use.ksy @@ -0,0 +1,22 @@ +meta: + id: multiple_use + endian: le +seq: + - id: t1 + type: type_1 + - id: t2 + type: type_2 +types: + multi: + seq: + - id: value + type: s4 + type_1: + seq: + - id: first_use + type: multi # parent type = type_1 + type_2: + instances: + second_use: + pos: 0 + type: multi # parent type = type_2 diff --git a/formats_rust/optional_id.ksy b/formats_rust/optional_id.ksy new file mode 100644 index 000000000..60f9bacbb --- /dev/null +++ b/formats_rust/optional_id.ksy @@ -0,0 +1,6 @@ +meta: + id: optional_id +seq: + - type: u1 + - type: u1 + - size: 5 diff --git a/formats_rust/process_coerce_usertype1.ksy b/formats_rust/process_coerce_usertype1.ksy new file mode 100644 index 000000000..15ffde784 --- /dev/null +++ b/formats_rust/process_coerce_usertype1.ksy @@ -0,0 +1,30 @@ +# Checks coercion of two user types with size (with and without processing) +meta: + id: process_coerce_usertype1 + endian: le +seq: + - id: records + type: record + repeat: expr + repeat-expr: 2 +types: + record: + seq: + - id: flag + type: u1 + - id: buf_unproc + size: 4 + type: foo + if: flag == 0 + - id: buf_proc + size: 4 + type: foo + process: xor(0xaa) + if: flag != 0 + instances: + buf: + value: 'flag == 0 ? buf_unproc : buf_proc' + foo: + seq: + - id: value + type: u4 diff --git a/formats_rust/process_coerce_usertype2.ksy b/formats_rust/process_coerce_usertype2.ksy new file mode 100644 index 000000000..07c58f9f3 --- /dev/null +++ b/formats_rust/process_coerce_usertype2.ksy @@ -0,0 +1,30 @@ +# Checks coercion of two user types: "with size and processing" vs +# "without size and processing" +meta: + id: process_coerce_usertype2 + endian: le +seq: + - id: records + type: record + repeat: expr + repeat-expr: 2 +types: + record: + seq: + - id: flag + type: u1 + - id: buf_unproc + type: foo + if: flag == 0 + - id: buf_proc + size: 4 + type: foo + process: xor(0xaa) + if: flag != 0 + instances: + buf: + value: 'flag == 0 ? buf_unproc : buf_proc' + foo: + seq: + - id: value + type: u4 diff --git a/formats_rust/repeat_eos_struct.ksy b/formats_rust/repeat_eos_struct.ksy new file mode 100644 index 000000000..940320f16 --- /dev/null +++ b/formats_rust/repeat_eos_struct.ksy @@ -0,0 +1,14 @@ +meta: + id: repeat_eos_struct + endian: le +seq: + - id: chunks + type: chunk + repeat: eos +types: + chunk: + seq: + - id: offset + type: u4 + - id: len + type: u4 diff --git a/formats_rust/repeat_eos_u4.ksy b/formats_rust/repeat_eos_u4.ksy new file mode 100644 index 000000000..dbb2b3e3b --- /dev/null +++ b/formats_rust/repeat_eos_u4.ksy @@ -0,0 +1,7 @@ +meta: + id: repeat_eos_u4 + endian: le +seq: + - id: numbers + type: u4 + repeat: eos diff --git a/formats_rust/repeat_n_struct.ksy b/formats_rust/repeat_n_struct.ksy new file mode 100644 index 000000000..1d1d89ade --- /dev/null +++ b/formats_rust/repeat_n_struct.ksy @@ -0,0 +1,17 @@ +meta: + id: repeat_n_struct + endian: le +seq: + - id: qty + type: u4 + - id: chunks + type: chunk + repeat: expr + repeat-expr: qty +types: + chunk: + seq: + - id: offset + type: u4 + - id: len + type: u4 diff --git a/formats_rust/repeat_n_strz.ksy b/formats_rust/repeat_n_strz.ksy new file mode 100644 index 000000000..ba8787d6d --- /dev/null +++ b/formats_rust/repeat_n_strz.ksy @@ -0,0 +1,11 @@ +meta: + id: repeat_n_strz + endian: le +seq: + - id: qty + type: u4 + - id: lines + type: strz + encoding: UTF-8 + repeat: expr + repeat-expr: qty diff --git a/formats_rust/repeat_n_strz_double.ksy b/formats_rust/repeat_n_strz_double.ksy new file mode 100644 index 000000000..25b123ed5 --- /dev/null +++ b/formats_rust/repeat_n_strz_double.ksy @@ -0,0 +1,16 @@ +meta: + id: repeat_n_strz_double + endian: le +seq: + - id: qty + type: u4 + - id: lines1 + type: strz + encoding: UTF-8 + repeat: expr + repeat-expr: qty / 2 + - id: lines2 + type: strz + encoding: UTF-8 + repeat: expr + repeat-expr: qty / 2 diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs new file mode 100644 index 000000000..3236ba56e --- /dev/null +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -0,0 +1,24 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::repeat_eos_struct::*; + + +#[test] +fn test_repeat_eos_struct() { + let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = RepeatEosStruct::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(r.chunks().len(), 2); + assert_eq!(*r.chunks()[0 as usize].offset(), 0); + assert_eq!(*r.chunks()[0 as usize].len(), 66); + assert_eq!(*r.chunks()[1 as usize].offset(), 66); + assert_eq!(*r.chunks()[1 as usize].len(), 2069); +} diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs new file mode 100644 index 000000000..a8f9a49c3 --- /dev/null +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -0,0 +1,24 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::repeat_n_struct::*; + + +#[test] +fn test_repeat_n_struct() { + let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = RepeatNStruct::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(r.chunks().len(), 2); + assert_eq!(*r.chunks()[0 as usize].offset(), 16); + assert_eq!(*r.chunks()[0 as usize].len(), 8312); + assert_eq!(*r.chunks()[1 as usize].offset(), 8328); + assert_eq!(*r.chunks()[1 as usize].len(), 15); +} From 5056595e566eee7863ab9a6ff854c8ab28a9fd58 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 23 Sep 2022 09:40:27 +0200 Subject: [PATCH 088/198] test_switch_repeat_expr + expr_invalid added. --- formats_rust/switch_repeat_expr.ksy | 26 ++++++++++++++++++ formats_rust/switch_repeat_expr_invalid.ksy | 27 +++++++++++++++++++ spec/rust/tests/test_switch_repeat_expr.rs | 27 +++++++++++++++++++ .../tests/test_switch_repeat_expr_invalid.rs | 27 +++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 formats_rust/switch_repeat_expr.ksy create mode 100644 formats_rust/switch_repeat_expr_invalid.ksy create mode 100644 spec/rust/tests/test_switch_repeat_expr.rs create mode 100644 spec/rust/tests/test_switch_repeat_expr_invalid.rs diff --git a/formats_rust/switch_repeat_expr.ksy b/formats_rust/switch_repeat_expr.ksy new file mode 100644 index 000000000..a9925e442 --- /dev/null +++ b/formats_rust/switch_repeat_expr.ksy @@ -0,0 +1,26 @@ +meta: + id: switch_repeat_expr + endian: le +seq: + - id: code + type: u1 + - id: size + type: u4 + - id: body + repeat: expr + repeat-expr: 1 + size: size + type: + switch-on: code + cases: + 0x11: one + 0x22: two +types: + one: + seq: + - id: first + size-eos: true + two: + seq: + - id: second + size-eos: true diff --git a/formats_rust/switch_repeat_expr_invalid.ksy b/formats_rust/switch_repeat_expr_invalid.ksy new file mode 100644 index 000000000..672b9433f --- /dev/null +++ b/formats_rust/switch_repeat_expr_invalid.ksy @@ -0,0 +1,27 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/494 +meta: + id: switch_repeat_expr_invalid + endian: le +seq: + - id: code + type: u1 + - id: size + type: u4 + - id: body + repeat: expr + repeat-expr: 1 + size: size + type: + switch-on: code + cases: + 0xff: one # there is actually 0x11 in the file + 0x22: two +types: + one: + seq: + - id: first + size-eos: true + two: + seq: + - id: second + size-eos: true diff --git a/spec/rust/tests/test_switch_repeat_expr.rs b/spec/rust/tests/test_switch_repeat_expr.rs new file mode 100644 index 000000000..26f7359a6 --- /dev/null +++ b/spec/rust/tests/test_switch_repeat_expr.rs @@ -0,0 +1,27 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_repeat_expr::*; + + +#[test] +fn test_switch_repeat_expr() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchRepeatExpr::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.code(), 17); + assert_eq!(*r.size(), 9); + + if let SwitchRepeatExpr_Body::SwitchRepeatExpr_One(b) = &r.body()[0 as usize] { + assert_eq!(b.first(), &vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); + } else { + panic!("expected enum SwitchRepeatExpr_Body"); + } +} diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs new file mode 100644 index 000000000..cb4e45787 --- /dev/null +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -0,0 +1,27 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_repeat_expr_invalid::*; + + +#[test] +fn test_switch_repeat_expr_invalid() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchRepeatExprInvalid::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.code(), 17); + assert_eq!(*r.size(), 9); + + if let SwitchRepeatExprInvalid_Body::Bytes(b) = &r.body()[0 as usize] { + assert_eq!(b, &vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); + } else { + panic!("expected enum SwitchRepeatExpr_Body"); + } +} From 7ebd02f71c1e68aea56f8f4b66fbd08e4d9fbcff Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 23 Sep 2022 09:46:27 +0200 Subject: [PATCH 089/198] no test for this ksy-file. --- formats_rust/optional_id.ksy | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 formats_rust/optional_id.ksy diff --git a/formats_rust/optional_id.ksy b/formats_rust/optional_id.ksy deleted file mode 100644 index 60f9bacbb..000000000 --- a/formats_rust/optional_id.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: optional_id -seq: - - type: u1 - - type: u1 - - size: 5 From 6a2768b395643523476992894c2cf6c010a685fa Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 23 Sep 2022 11:17:27 +0200 Subject: [PATCH 090/198] type_ternery_2nd_falsy. --- formats_rust/type_ternary_2nd_falsy.ksy | 46 +++++++++++++++++++ .../rust/tests/test_type_ternary_2nd_falsy.rs | 32 +++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 formats_rust/type_ternary_2nd_falsy.ksy create mode 100644 spec/rust/tests/test_type_ternary_2nd_falsy.rs diff --git a/formats_rust/type_ternary_2nd_falsy.ksy b/formats_rust/type_ternary_2nd_falsy.ksy new file mode 100644 index 000000000..0be95279a --- /dev/null +++ b/formats_rust/type_ternary_2nd_falsy.ksy @@ -0,0 +1,46 @@ +# Test languages without built-in ternary operator support (Lua) if they're not blindly using `cond and if_true or if_false` +# (doesn't work properly when if_true == false) +meta: + id: type_ternary_2nd_falsy +seq: + - id: int_truthy + type: u1 + - id: ut + type: foo + - id: int_array + type: u1 + repeat: expr + repeat-expr: 2 + - id: int_array_empty + type: u1 + repeat: expr + repeat-expr: 0 +types: + foo: + seq: + - id: m + type: u1 +instances: + t: + value: true + null_ut: + value: ut + if: false + v_false: + value: 't ? false : true' + v_int_zero: + value: 't ? 0 : 10' + v_int_neg_zero: + value: 't ? -0 : -20' + v_float_zero: + value: 't ? 0.0 : 3.14' + v_float_neg_zero: + value: 't ? -0.0 : -2.72' + v_str_w_zero: # "0" is falsy in PHP, might be also in other languages + value: 't ? "0" : "30"' + v_null_ut: + value: 't ? null_ut : ut' + v_str_empty: + value: 't ? "" : "kaitai"' + v_int_array_empty: + value: 't ? int_array_empty : int_array' diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs new file mode 100644 index 000000000..347fcdece --- /dev/null +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -0,0 +1,32 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::type_ternary_2nd_falsy::*; + + +#[test] +fn test_type_ternary_2nd_falsy() { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TypeTernary2ndFalsy::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.v_false(&reader, Some(&r)).unwrap(), false); + assert_eq!(*r.v_int_zero(&reader, Some(&r)).unwrap(), 0); + assert_eq!(*r.v_int_neg_zero(&reader, Some(&r)).unwrap(), 0); + assert_eq!(*r.v_float_zero(&reader, Some(&r)).unwrap(), 0.0); + assert_eq!(*r.v_float_neg_zero(&reader, Some(&r)).unwrap(), -0.0); + assert_eq!(*r.v_str_w_zero(&reader, Some(&r)).unwrap(), "0"); + assert_eq!(r.v_str_w_zero(&reader, Some(&r)).unwrap().len(), 1); + assert_eq!(*r.ut().m(), 7); + assert_eq!(*r.v_null_ut(&reader, Some(&r)).unwrap().m(), 0); + assert_eq!(*r.v_str_empty(&reader, Some(&r)).unwrap(), ""); + assert_eq!(r.v_str_empty(&reader, Some(&r)).unwrap().len(), 0); + assert_eq!(r.int_array().len(), 2); + assert_eq!(r.v_int_array_empty(&reader, Some(&r)).unwrap().len(), 0); +} From a68e8e3a304d6f25e8ef914798d9ec377281c491 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 23 Sep 2022 11:35:03 +0200 Subject: [PATCH 091/198] switch_manual_enum --- formats_rust/switch_manual_enum.ksy | 32 ++++++++++++++ spec/rust/tests/test_switch_manual_enum.rs | 50 ++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 formats_rust/switch_manual_enum.ksy create mode 100644 spec/rust/tests/test_switch_manual_enum.rs diff --git a/formats_rust/switch_manual_enum.ksy b/formats_rust/switch_manual_enum.ksy new file mode 100644 index 000000000..996e83eb1 --- /dev/null +++ b/formats_rust/switch_manual_enum.ksy @@ -0,0 +1,32 @@ +meta: + id: switch_manual_enum +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: u1 + enum: code_enum + - id: body + type: + switch-on: code + cases: + code_enum::intval: intval + code_enum::strval: strval + enums: + code_enum: + 73: intval # 'I' + 83: strval # 'S' + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs new file mode 100644 index 000000000..33729b173 --- /dev/null +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -0,0 +1,50 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_enum::*; + + +#[test] +fn test_switch_manual_enum() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualEnum::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(r.opcodes().len(), 4); + + assert_eq!(*r.opcodes()[0 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); + if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s) = r.opcodes()[0].body() { + assert_eq!(*s.value(), "foobar"); + } else { + panic!("expected enum SwitchManualEnum_Opcode_Strval"); + } + + assert_eq!(*r.opcodes()[1 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); + if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s) = r.opcodes()[1].body() { + assert_eq!(*s.value(), 66); + } else { + panic!("expected enum SwitchManualEnum_Opcode_Intval"); + } + + assert_eq!(*r.opcodes()[2 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); + if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s) = r.opcodes()[2].body() { + assert_eq!(*s.value(), 55); + } else { + panic!("expected enum SwitchManualEnum_Opcode_Intval"); + } + + assert_eq!(*r.opcodes()[3 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); + if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s) = r.opcodes()[3].body() { + assert_eq!(*s.value(), ""); + } else { + panic!("expected enum SwitchManualEnum_Opcode_Strval"); + } +} From d1bfa23de06923f52803538e873263e983ea5aa8 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 23 Sep 2022 15:02:30 +0200 Subject: [PATCH 092/198] zlib tests. --- formats_rust/zlib_surrounded.ksy | 16 ++++++++++++++++ formats_rust/zlib_with_header_78.ksy | 6 ++++++ 2 files changed, 22 insertions(+) create mode 100644 formats_rust/zlib_surrounded.ksy create mode 100644 formats_rust/zlib_with_header_78.ksy diff --git a/formats_rust/zlib_surrounded.ksy b/formats_rust/zlib_surrounded.ksy new file mode 100644 index 000000000..fb3f652a4 --- /dev/null +++ b/formats_rust/zlib_surrounded.ksy @@ -0,0 +1,16 @@ +meta: + id: zlib_surrounded +seq: + - id: pre + size: 4 + - id: zlib + size: 12 + process: zlib + type: inflated + - id: post + size: 4 +types: + inflated: + seq: + - id: num + type: s4le diff --git a/formats_rust/zlib_with_header_78.ksy b/formats_rust/zlib_with_header_78.ksy new file mode 100644 index 000000000..d23c06abd --- /dev/null +++ b/formats_rust/zlib_with_header_78.ksy @@ -0,0 +1,6 @@ +meta: + id: zlib_with_header_78 +seq: + - id: data + size-eos: true + process: zlib From ed5599ccfb016a96ef9cc4d4b860fff1a72a6680 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 24 Sep 2022 12:51:07 +0200 Subject: [PATCH 093/198] import tests. --- formats_rust/for_rel_imports/imported_1.ksy | 9 ++++++++ formats_rust/for_rel_imports/imported_2.ksy | 5 +++++ formats_rust/imports_abs_abs.ksy | 12 ++++++++++ formats_rust/imports_abs_rel.ksy | 12 ++++++++++ formats_rust/imports_rel_1.ksy | 12 ++++++++++ .../for_abs_imports/imported_and_abs.ksy | 9 ++++++++ .../for_abs_imports/imported_and_rel.ksy | 9 ++++++++ formats_rust/ks_path/imported_root.ksy | 5 +++++ spec/rust/tests/manual_imports_abs_abs.rs | 22 +++++++++++++++++++ spec/rust/tests/manual_imports_abs_rel.rs | 22 +++++++++++++++++++ 10 files changed, 117 insertions(+) create mode 100644 formats_rust/for_rel_imports/imported_1.ksy create mode 100644 formats_rust/for_rel_imports/imported_2.ksy create mode 100644 formats_rust/imports_abs_abs.ksy create mode 100644 formats_rust/imports_abs_rel.ksy create mode 100644 formats_rust/imports_rel_1.ksy create mode 100644 formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy create mode 100644 formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy create mode 100644 formats_rust/ks_path/imported_root.ksy create mode 100644 spec/rust/tests/manual_imports_abs_abs.rs create mode 100644 spec/rust/tests/manual_imports_abs_rel.rs diff --git a/formats_rust/for_rel_imports/imported_1.ksy b/formats_rust/for_rel_imports/imported_1.ksy new file mode 100644 index 000000000..1e5814261 --- /dev/null +++ b/formats_rust/for_rel_imports/imported_1.ksy @@ -0,0 +1,9 @@ +meta: + id: imported_1 + imports: + - imported_2 +seq: + - id: one + type: u1 + - id: two + type: imported_2 diff --git a/formats_rust/for_rel_imports/imported_2.ksy b/formats_rust/for_rel_imports/imported_2.ksy new file mode 100644 index 000000000..861945e99 --- /dev/null +++ b/formats_rust/for_rel_imports/imported_2.ksy @@ -0,0 +1,5 @@ +meta: + id: imported_2 +seq: + - id: one + type: u1 diff --git a/formats_rust/imports_abs_abs.ksy b/formats_rust/imports_abs_abs.ksy new file mode 100644 index 000000000..09f06422c --- /dev/null +++ b/formats_rust/imports_abs_abs.ksy @@ -0,0 +1,12 @@ +# Test chain of absolute-into-absolute imports +# +# this -> $KS_PATH/for_abs_imports/imported_and_abs -> $KS_PATH/more_abs/imported_root +meta: + id: imports_abs_abs + imports: + - /for_abs_imports/imported_and_abs +seq: + - id: one + type: u1 + - id: two + type: imported_and_abs diff --git a/formats_rust/imports_abs_rel.ksy b/formats_rust/imports_abs_rel.ksy new file mode 100644 index 000000000..7862d9f0d --- /dev/null +++ b/formats_rust/imports_abs_rel.ksy @@ -0,0 +1,12 @@ +# Test chain of absolute-into-absolute imports +# +# this -> $KS_PATH/for_abs_imports/imported_and_rel -> $KS_PATH/more_abs/imported_root +meta: + id: imports_abs_rel + imports: + - /for_abs_imports/imported_and_rel +seq: + - id: one + type: u1 + - id: two + type: imported_and_rel diff --git a/formats_rust/imports_rel_1.ksy b/formats_rust/imports_rel_1.ksy new file mode 100644 index 000000000..0bfb19ee2 --- /dev/null +++ b/formats_rust/imports_rel_1.ksy @@ -0,0 +1,12 @@ +# Test chain of relative imports +# +# this -> for_rel_imports/imported_1 -> for_rel_imports/imported_2 +meta: + id: imports_rel_1 + imports: + - for_rel_imports/imported_1 +seq: + - id: one + type: u1 + - id: two + type: imported_1 diff --git a/formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy b/formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy new file mode 100644 index 000000000..8213de54d --- /dev/null +++ b/formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy @@ -0,0 +1,9 @@ +meta: + id: imported_and_abs + imports: + - /imported_root +seq: + - id: one + type: u1 + - id: two + type: imported_root diff --git a/formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy b/formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy new file mode 100644 index 000000000..003419e18 --- /dev/null +++ b/formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy @@ -0,0 +1,9 @@ +meta: + id: imported_and_rel + imports: + - ../imported_root +seq: + - id: one + type: u1 + - id: two + type: imported_root diff --git a/formats_rust/ks_path/imported_root.ksy b/formats_rust/ks_path/imported_root.ksy new file mode 100644 index 000000000..c437309eb --- /dev/null +++ b/formats_rust/ks_path/imported_root.ksy @@ -0,0 +1,5 @@ +meta: + id: imported_root +seq: + - id: one + type: u1 diff --git a/spec/rust/tests/manual_imports_abs_abs.rs b/spec/rust/tests/manual_imports_abs_abs.rs new file mode 100644 index 000000000..a9cd22b99 --- /dev/null +++ b/spec/rust/tests/manual_imports_abs_abs.rs @@ -0,0 +1,22 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::imports_abs_abs::*; + + +#[test] +fn test_params_def() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ImportsAbsAbs::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.one(), 80); + assert_eq!(*r.two().one(), 65); + assert_eq!(*r.two().two().one(), 67); +} diff --git a/spec/rust/tests/manual_imports_abs_rel.rs b/spec/rust/tests/manual_imports_abs_rel.rs new file mode 100644 index 000000000..ce4187fcd --- /dev/null +++ b/spec/rust/tests/manual_imports_abs_rel.rs @@ -0,0 +1,22 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::imports_abs_rel::*; + + +#[test] +fn test_params_def() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ImportsAbsRel::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.one(), 80); + assert_eq!(*r.two().one(), 65); + assert_eq!(*r.two().two().one(), 67); +} From bad8a9b29a18f6e38f50bbe9fc44a5ee635ad8ba Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 24 Sep 2022 20:39:21 +0300 Subject: [PATCH 094/198] imports_circular tests. --- formats_rust/imports_circular_a.ksy | 9 ++++++++ formats_rust/imports_circular_b.ksy | 10 +++++++++ spec/rust/tests/manual_imports_abs_abs.rs | 4 ++-- spec/rust/tests/test_imports_circular_a.rs | 25 ++++++++++++++++++++++ spec/rust/tests/test_imports_rel_1.rs | 24 +++++++++++++++++++++ 5 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 formats_rust/imports_circular_a.ksy create mode 100644 formats_rust/imports_circular_b.ksy create mode 100644 spec/rust/tests/test_imports_circular_a.rs create mode 100644 spec/rust/tests/test_imports_rel_1.rs diff --git a/formats_rust/imports_circular_a.ksy b/formats_rust/imports_circular_a.ksy new file mode 100644 index 000000000..8fce0cbd5 --- /dev/null +++ b/formats_rust/imports_circular_a.ksy @@ -0,0 +1,9 @@ +meta: + id: imports_circular_a + imports: + - imports_circular_b +seq: + - id: code + type: u1 + - id: two + type: imports_circular_b diff --git a/formats_rust/imports_circular_b.ksy b/formats_rust/imports_circular_b.ksy new file mode 100644 index 000000000..85cdd885e --- /dev/null +++ b/formats_rust/imports_circular_b.ksy @@ -0,0 +1,10 @@ +meta: + id: imports_circular_b + imports: + - imports_circular_a +seq: + - id: initial + type: u1 + - id: back_ref + type: imports_circular_a + if: initial == 0x41 diff --git a/spec/rust/tests/manual_imports_abs_abs.rs b/spec/rust/tests/manual_imports_abs_abs.rs index a9cd22b99..46ae708f4 100644 --- a/spec/rust/tests/manual_imports_abs_abs.rs +++ b/spec/rust/tests/manual_imports_abs_abs.rs @@ -17,6 +17,6 @@ fn test_params_def() { } assert_eq!(*r.one(), 80); - assert_eq!(*r.two().one(), 65); - assert_eq!(*r.two().two().one(), 67); + assert_eq!(*r.two().as_ref().unwrap().one(), 65); + assert_eq!(*r.two().as_ref().unwrap().two().as_ref().unwrap().one(), 67); } diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs new file mode 100644 index 000000000..06b0123ca --- /dev/null +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -0,0 +1,25 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::imports_circular_a::*; + +use formats::imports_circular_b::*; + +#[test] +fn test_imports_circular_a() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ImportsCircularA::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.code(), 80); + assert_eq!(*r.two().as_ref().unwrap().initial(), 65); + assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().code(), 67); + assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().two().as_ref().unwrap().initial(), 75); + assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().two().as_ref().unwrap().back_ref(), None); +} diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs new file mode 100644 index 000000000..c9b085f6e --- /dev/null +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -0,0 +1,24 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::imports_rel_1::*; + +use formats::imported_1::*; +use formats::imported_2::*; + +#[test] +fn test_imports_rel_1() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ImportsRel1::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.one(), 80); + assert_eq!(*r.two().as_ref().unwrap().one(), 65); + assert_eq!(*r.two().as_ref().unwrap().two().as_ref().unwrap().one(), 67); +} From 95dce0556c143dd04f671392ed579525cb1a1000 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 24 Sep 2022 20:55:15 +0300 Subject: [PATCH 095/198] mod formats dup fixed. --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 3f2ed9a8c..e6a6747aa 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -21,7 +21,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val use_mod = if (options.unitTest) s"use crate::" else - s"mod formats;\nuse " + s"use " var imports = "" spec.extraImports.foreach{ name => imports = s"$imports\n${use_mod}formats::$name::*;" } @@ -30,6 +30,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs | |extern crate kaitai; |use self::kaitai::*; + |mod formats; |${use_mod}formats::${spec.id}::*; |$imports | From fc07a97a5e8aad6829359d0db715114b5bbea509 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 24 Sep 2022 20:56:10 +0300 Subject: [PATCH 096/198] test fixed. --- build-compiler | 2 +- spec/rust/tests/manual_imports_abs_rel.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build-compiler b/build-compiler index f40f9a17a..46e6f0ead 100755 --- a/build-compiler +++ b/build-compiler @@ -4,4 +4,4 @@ cd "$COMPILER_DIR" sbt compilerJVM/stage -sbt compile fastOptJS +#sbt compile fastOptJS diff --git a/spec/rust/tests/manual_imports_abs_rel.rs b/spec/rust/tests/manual_imports_abs_rel.rs index ce4187fcd..e496208b4 100644 --- a/spec/rust/tests/manual_imports_abs_rel.rs +++ b/spec/rust/tests/manual_imports_abs_rel.rs @@ -17,6 +17,6 @@ fn test_params_def() { } assert_eq!(*r.one(), 80); - assert_eq!(*r.two().one(), 65); - assert_eq!(*r.two().two().one(), 67); + assert_eq!(*r.two().as_ref().unwrap().one(), 65); + assert_eq!(*r.two().as_ref().unwrap().two().as_ref().unwrap().one(), 67); } From dfb69ce5f02092ad2eb8da68a1d27ccdd0061060 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 1 Oct 2022 16:32:47 +0200 Subject: [PATCH 097/198] bits tests. --- formats_rust/bcd_user_type_be.ksy | 136 ++++++++++++++++++++++ formats_rust/bcd_user_type_le.ksy | 136 ++++++++++++++++++++++ formats_rust/bits_byte_aligned.ksy | 24 ++++ formats_rust/bits_enum.ksy | 21 ++++ formats_rust/bits_seq_endian_combo.ksy | 19 +++ formats_rust/bits_shift_by_b32_le.ksy | 14 +++ formats_rust/bits_shift_by_b64_le.ksy | 14 +++ formats_rust/bits_signed_res_b32_be.ksy | 7 ++ formats_rust/bits_signed_res_b32_le.ksy | 7 ++ formats_rust/bits_signed_shift_b32_le.ksy | 11 ++ formats_rust/bits_signed_shift_b64_le.ksy | 11 ++ formats_rust/bits_simple.ksy | 42 +++++++ formats_rust/bits_simple_le.ksy | 43 +++++++ formats_rust/bits_unaligned_b32_be.ksy | 10 ++ formats_rust/bits_unaligned_b32_le.ksy | 10 ++ formats_rust/bits_unaligned_b64_be.ksy | 10 ++ formats_rust/bits_unaligned_b64_le.ksy | 10 ++ 17 files changed, 525 insertions(+) create mode 100644 formats_rust/bcd_user_type_be.ksy create mode 100644 formats_rust/bcd_user_type_le.ksy create mode 100644 formats_rust/bits_byte_aligned.ksy create mode 100644 formats_rust/bits_enum.ksy create mode 100644 formats_rust/bits_seq_endian_combo.ksy create mode 100644 formats_rust/bits_shift_by_b32_le.ksy create mode 100644 formats_rust/bits_shift_by_b64_le.ksy create mode 100644 formats_rust/bits_signed_res_b32_be.ksy create mode 100644 formats_rust/bits_signed_res_b32_le.ksy create mode 100644 formats_rust/bits_signed_shift_b32_le.ksy create mode 100644 formats_rust/bits_signed_shift_b64_le.ksy create mode 100644 formats_rust/bits_simple.ksy create mode 100644 formats_rust/bits_simple_le.ksy create mode 100644 formats_rust/bits_unaligned_b32_be.ksy create mode 100644 formats_rust/bits_unaligned_b32_le.ksy create mode 100644 formats_rust/bits_unaligned_b64_be.ksy create mode 100644 formats_rust/bits_unaligned_b64_le.ksy diff --git a/formats_rust/bcd_user_type_be.ksy b/formats_rust/bcd_user_type_be.ksy new file mode 100644 index 000000000..4b28bddf0 --- /dev/null +++ b/formats_rust/bcd_user_type_be.ksy @@ -0,0 +1,136 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/78 +meta: + id: bcd_user_type_be + endian: be + +seq: + - id: ltr + size: 4 + type: ltr_obj + - id: rtl + size: 4 + type: rtl_obj + - id: leading_zero_ltr + size: 4 + type: leading_zero_ltr_obj + +types: + ltr_obj: + seq: + - id: b1 + type: u1 + - id: b2 + type: u1 + - id: b3 + type: u1 + - id: b4 + type: u1 + + instances: + digit1: + value: (b1 & 0xF0) >> 4 + digit2: + value: (b1 & 0x0F) + digit3: + value: (b2 & 0xF0) >> 4 + digit4: + value: (b2 & 0x0F) + digit5: + value: (b3 & 0xF0) >> 4 + digit6: + value: (b3 & 0x0F) + digit7: + value: (b4 & 0xF0) >> 4 + digit8: + value: (b4 & 0x0F) + as_int: + value: digit8 * 1 + + digit7 * 10 + + digit6 * 100 + + digit5 * 1000 + + digit4 * 10000 + + digit3 * 100000 + + digit2 * 1000000 + + digit1 * 10000000 + as_str: + value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s + + rtl_obj: + seq: + - id: b1 + type: u1 + - id: b2 + type: u1 + - id: b3 + type: u1 + - id: b4 + type: u1 + + instances: + digit1: + value: (b1 & 0xF0) >> 4 + digit2: + value: (b1 & 0x0F) + digit3: + value: (b2 & 0xF0) >> 4 + digit4: + value: (b2 & 0x0F) + digit5: + value: (b3 & 0xF0) >> 4 + digit6: + value: (b3 & 0x0F) + digit7: + value: (b4 & 0xF0) >> 4 + digit8: + value: (b4 & 0x0F) + as_int: + value: digit1 * 1 + + digit2 * 10 + + digit3 * 100 + + digit4 * 1000 + + digit5 * 10000 + + digit6 * 100000 + + digit7 * 1000000 + + digit8 * 10000000 + as_str: + value: digit8.to_s + digit7.to_s + digit6.to_s + digit5.to_s + digit4.to_s + digit3.to_s + digit2.to_s + digit1.to_s + + leading_zero_ltr_obj: + seq: + - id: b1 + type: u1 + - id: b2 + type: u1 + - id: b3 + type: u1 + - id: b4 + type: u1 + + instances: + digit1: + value: (b1 & 0xF0) >> 4 + digit2: + value: (b1 & 0x0F) + digit3: + value: (b2 & 0xF0) >> 4 + digit4: + value: (b2 & 0x0F) + digit5: + value: (b3 & 0xF0) >> 4 + digit6: + value: (b3 & 0x0F) + digit7: + value: (b4 & 0xF0) >> 4 + digit8: + value: (b4 & 0x0F) + as_int: + value: digit8 * 1 + + digit7 * 10 + + digit6 * 100 + + digit5 * 1000 + + digit4 * 10000 + + digit3 * 100000 + + digit2 * 1000000 + + digit1 * 10000000 + as_str: + value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s diff --git a/formats_rust/bcd_user_type_le.ksy b/formats_rust/bcd_user_type_le.ksy new file mode 100644 index 000000000..97db59011 --- /dev/null +++ b/formats_rust/bcd_user_type_le.ksy @@ -0,0 +1,136 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/78 +meta: + id: bcd_user_type_le + endian: le + +seq: + - id: ltr + size: 4 + type: ltr_obj + - id: rtl + size: 4 + type: rtl_obj + - id: leading_zero_ltr + size: 4 + type: leading_zero_ltr_obj + +types: + ltr_obj: + seq: + - id: b1 + type: u1 + - id: b2 + type: u1 + - id: b3 + type: u1 + - id: b4 + type: u1 + + instances: + digit1: + value: (b4 & 0xF0) >> 4 + digit2: + value: (b4 & 0x0F) + digit3: + value: (b3 & 0xF0) >> 4 + digit4: + value: (b3 & 0x0F) + digit5: + value: (b2 & 0xF0) >> 4 + digit6: + value: (b2 & 0x0F) + digit7: + value: (b1 & 0xF0) >> 4 + digit8: + value: (b1 & 0x0F) + as_int: + value: digit8 * 1 + + digit7 * 10 + + digit6 * 100 + + digit5 * 1000 + + digit4 * 10000 + + digit3 * 100000 + + digit2 * 1000000 + + digit1 * 10000000 + as_str: + value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s + + rtl_obj: + seq: + - id: b1 + type: u1 + - id: b2 + type: u1 + - id: b3 + type: u1 + - id: b4 + type: u1 + + instances: + digit1: + value: (b4 & 0xF0) >> 4 + digit2: + value: (b4 & 0x0F) + digit3: + value: (b3 & 0xF0) >> 4 + digit4: + value: (b3 & 0x0F) + digit5: + value: (b2 & 0xF0) >> 4 + digit6: + value: (b2 & 0x0F) + digit7: + value: (b1 & 0xF0) >> 4 + digit8: + value: (b1 & 0x0F) + as_int: + value: digit1 * 1 + + digit2 * 10 + + digit3 * 100 + + digit4 * 1000 + + digit5 * 10000 + + digit6 * 100000 + + digit7 * 1000000 + + digit8 * 10000000 + as_str: + value: digit8.to_s + digit7.to_s + digit6.to_s + digit5.to_s + digit4.to_s + digit3.to_s + digit2.to_s + digit1.to_s + + leading_zero_ltr_obj: + seq: + - id: b1 + type: u1 + - id: b2 + type: u1 + - id: b3 + type: u1 + - id: b4 + type: u1 + + instances: + digit1: + value: (b4 & 0xF0) >> 4 + digit2: + value: (b4 & 0x0F) + digit3: + value: (b3 & 0xF0) >> 4 + digit4: + value: (b3 & 0x0F) + digit5: + value: (b2 & 0xF0) >> 4 + digit6: + value: (b2 & 0x0F) + digit7: + value: (b1 & 0xF0) >> 4 + digit8: + value: (b1 & 0x0F) + as_int: + value: digit8 * 1 + + digit7 * 10 + + digit6 * 100 + + digit5 * 1000 + + digit4 * 10000 + + digit3 * 100000 + + digit2 * 1000000 + + digit1 * 10000000 + as_str: + value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s diff --git a/formats_rust/bits_byte_aligned.ksy b/formats_rust/bits_byte_aligned.ksy new file mode 100644 index 000000000..779b5c17f --- /dev/null +++ b/formats_rust/bits_byte_aligned.ksy @@ -0,0 +1,24 @@ +meta: + id: bits_byte_aligned +seq: + - id: one + type: b6 + # skips 2 bits + - id: byte_1 + type: u1 + - id: two + type: b3 + - id: three + type: b1 + # skips 4 bits + - id: byte_2 + type: u1 + - id: four + type: b14 + # skips 2 bits + - id: byte_3 + size: 1 + - id: full_byte + type: b8 + - id: byte_4 + type: u1 diff --git a/formats_rust/bits_enum.ksy b/formats_rust/bits_enum.ksy new file mode 100644 index 000000000..6605e9b5e --- /dev/null +++ b/formats_rust/bits_enum.ksy @@ -0,0 +1,21 @@ +meta: + id: bits_enum +seq: + # byte 0 + - id: one + type: b4 + enum: animal + # byte 0-1 + - id: two + type: b8 + enum: animal + # byte 1 + - id: three + type: b1 + enum: animal +enums: + animal: + 0: cat + 1: dog + 4: horse + 5: platypus diff --git a/formats_rust/bits_seq_endian_combo.ksy b/formats_rust/bits_seq_endian_combo.ksy new file mode 100644 index 000000000..63a9760b0 --- /dev/null +++ b/formats_rust/bits_seq_endian_combo.ksy @@ -0,0 +1,19 @@ +meta: + id: bits_seq_endian_combo +seq: + - id: be1 + type: b6be + - id: be2 + type: b10be + - id: le3 + type: b8le + - id: be4 + type: b8be + - id: le5 + type: b5le + - id: le6 + type: b6le + - id: le7 + type: b5le + - id: be8 + type: b1be diff --git a/formats_rust/bits_shift_by_b32_le.ksy b/formats_rust/bits_shift_by_b32_le.ksy new file mode 100644 index 000000000..ce3cfe58e --- /dev/null +++ b/formats_rust/bits_shift_by_b32_le.ksy @@ -0,0 +1,14 @@ +# If the particular runtime library implements `read_bits_int_le()` according to the common +# algorithm introduced in https://github.com/kaitai-io/kaitai_struct/issues/949 (as all runtime +# libs should), this test will make it store `res >> (bitsNeeded: 32)` in `bits` for subsequent +# bit integers. However, the behavior of `x >> 32` is often problematic in languages with +# 32-bit operators - in JavaScript, this case has to be handled with special care. If it's not, +# this test will reveal it. +meta: + id: bits_shift_by_b32_le + bit-endian: le +seq: + - id: a + type: b32 + - id: b + type: b8 diff --git a/formats_rust/bits_shift_by_b64_le.ksy b/formats_rust/bits_shift_by_b64_le.ksy new file mode 100644 index 000000000..0eadb1268 --- /dev/null +++ b/formats_rust/bits_shift_by_b64_le.ksy @@ -0,0 +1,14 @@ +# If the particular runtime library implements `read_bits_int_le()` according to the common +# algorithm introduced in https://github.com/kaitai-io/kaitai_struct/issues/949 (as all runtime +# libs should), this test will make it store `res >> (bitsNeeded: 64)` in `bits` for subsequent +# bit integers. However, the behavior of `x >> 64` is often problematic in languages with +# 64-bit operators - this case usually has to be handled with special care. If it's not, this +# test will reveal it. +meta: + id: bits_shift_by_b64_le + bit-endian: le +seq: + - id: a + type: b64 + - id: b + type: b8 diff --git a/formats_rust/bits_signed_res_b32_be.ksy b/formats_rust/bits_signed_res_b32_be.ksy new file mode 100644 index 000000000..01d3268bb --- /dev/null +++ b/formats_rust/bits_signed_res_b32_be.ksy @@ -0,0 +1,7 @@ +# Make sure that a big-endian `b32` value is read as unsigned in JavaScript. +meta: + id: bits_signed_res_b32_be + bit-endian: be +seq: + - id: a + type: b32 diff --git a/formats_rust/bits_signed_res_b32_le.ksy b/formats_rust/bits_signed_res_b32_le.ksy new file mode 100644 index 000000000..9a18180c1 --- /dev/null +++ b/formats_rust/bits_signed_res_b32_le.ksy @@ -0,0 +1,7 @@ +# Make sure that a little-endian `b32` value is read as unsigned in JavaScript. +meta: + id: bits_signed_res_b32_le + bit-endian: le +seq: + - id: a + type: b32 diff --git a/formats_rust/bits_signed_shift_b32_le.ksy b/formats_rust/bits_signed_shift_b32_le.ksy new file mode 100644 index 000000000..b1f84b336 --- /dev/null +++ b/formats_rust/bits_signed_shift_b32_le.ksy @@ -0,0 +1,11 @@ +# Make sure that languages with 32-bit operators (JavaScript) use *unsigned* +# (aka zero-fill) right shift, not signed (sign-propagating) right shift. This +# test will fail if a signed shift is used. +meta: + id: bits_signed_shift_b32_le + bit-endian: le +seq: + - id: a + type: b31 + - id: b + type: b9 diff --git a/formats_rust/bits_signed_shift_b64_le.ksy b/formats_rust/bits_signed_shift_b64_le.ksy new file mode 100644 index 000000000..1554026ed --- /dev/null +++ b/formats_rust/bits_signed_shift_b64_le.ksy @@ -0,0 +1,11 @@ +# Make sure that languages with 64-bit operators (Java, PHP) use *unsigned* (aka +# zero-fill) right shift, not signed (sign-propagating) right shift. This test +# will fail if a signed shift is used. +meta: + id: bits_signed_shift_b64_le + bit-endian: le +seq: + - id: a + type: b63 + - id: b + type: b9 diff --git a/formats_rust/bits_simple.ksy b/formats_rust/bits_simple.ksy new file mode 100644 index 000000000..7195b2dec --- /dev/null +++ b/formats_rust/bits_simple.ksy @@ -0,0 +1,42 @@ +meta: + id: bits_simple +seq: + # byte 0 + - id: byte_1 + type: b8 + # byte 1 + - id: byte_2 + type: b8 + # byte 2 (8 bits = 1 + 3 + 4) + - id: bits_a + type: b1 + - id: bits_b + type: b3 + - id: bits_c + type: b4 + # byte 3-4-5 (24 bits = 10 + 3 + 11) + - id: large_bits_1 + type: b10 + - id: spacer + type: b3 + - id: large_bits_2 + type: b11 + # byte 6-7 + - id: normal_s2 + type: s2be + # byte 8-9-10 (24 bits) + - id: byte_8_9_10 + type: b24 + # byte 11-12-13-14 (32 bits) + - id: byte_11_to_14 + type: b32 + # byte 15-16-17-18-19 (40 bits) + - id: byte_15_to_19 + type: b40 + # byte 20-21-22-23-24-25-26-27 (64 bits) + - id: byte_20_to_27 + type: b64 +instances: + test_if_b1: + value: 123 + if: bits_a == false diff --git a/formats_rust/bits_simple_le.ksy b/formats_rust/bits_simple_le.ksy new file mode 100644 index 000000000..c897f079b --- /dev/null +++ b/formats_rust/bits_simple_le.ksy @@ -0,0 +1,43 @@ +meta: + id: bits_simple_le + bit-endian: le +seq: + # byte 0 + - id: byte_1 + type: b8 + # byte 1 + - id: byte_2 + type: b8 + # byte 2 (8 bits = 1 + 3 + 4) + - id: bits_a + type: b1 + - id: bits_b + type: b3 + - id: bits_c + type: b4 + # byte 3-4-5 (24 bits = 10 + 3 + 11) + - id: large_bits_1 + type: b10 + - id: spacer + type: b3 + - id: large_bits_2 + type: b11 + # byte 6-7 + - id: normal_s2 + type: s2be + # byte 8-9-10 (24 bits) + - id: byte_8_9_10 + type: b24 + # byte 11-12-13-14 (32 bits) + - id: byte_11_to_14 + type: b32 + # byte 15-16-17-18-19 (40 bits) + - id: byte_15_to_19 + type: b40 + # byte 20-21-22-23-24-25-26-27 (64 bits) + - id: byte_20_to_27 + type: b64 +instances: + test_if_b1: + value: 123 + if: bits_a == true diff --git a/formats_rust/bits_unaligned_b32_be.ksy b/formats_rust/bits_unaligned_b32_be.ksy new file mode 100644 index 000000000..29bc1cd70 --- /dev/null +++ b/formats_rust/bits_unaligned_b32_be.ksy @@ -0,0 +1,10 @@ +meta: + id: bits_unaligned_b32_be + bit-endian: be +seq: + - id: a + type: b1 + - id: b + type: b32 + - id: c + type: b7 diff --git a/formats_rust/bits_unaligned_b32_le.ksy b/formats_rust/bits_unaligned_b32_le.ksy new file mode 100644 index 000000000..1dc8830aa --- /dev/null +++ b/formats_rust/bits_unaligned_b32_le.ksy @@ -0,0 +1,10 @@ +meta: + id: bits_unaligned_b32_le + bit-endian: le +seq: + - id: a + type: b1 + - id: b + type: b32 + - id: c + type: b7 diff --git a/formats_rust/bits_unaligned_b64_be.ksy b/formats_rust/bits_unaligned_b64_be.ksy new file mode 100644 index 000000000..7a5aa1bd8 --- /dev/null +++ b/formats_rust/bits_unaligned_b64_be.ksy @@ -0,0 +1,10 @@ +meta: + id: bits_unaligned_b64_be + bit-endian: be +seq: + - id: a + type: b1 + - id: b + type: b64 + - id: c + type: b7 diff --git a/formats_rust/bits_unaligned_b64_le.ksy b/formats_rust/bits_unaligned_b64_le.ksy new file mode 100644 index 000000000..1c4a74138 --- /dev/null +++ b/formats_rust/bits_unaligned_b64_le.ksy @@ -0,0 +1,10 @@ +meta: + id: bits_unaligned_b64_le + bit-endian: le +seq: + - id: a + type: b1 + - id: b + type: b64 + - id: c + type: b7 From cd4d4c545db17130f727b28296f13b5d46ceb98e Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 5 Oct 2022 22:41:43 +0200 Subject: [PATCH 098/198] endian tests. --- formats_rust/default_big_endian.ksy | 6 +++ formats_rust/default_bit_endian_mod.ksy | 30 +++++++++++++ .../default_endian_expr_exception.ksy | 30 +++++++++++++ .../default_endian_expr_inherited.ksy | 42 ++++++++++++++++++ formats_rust/default_endian_expr_is_be.ksy | 40 +++++++++++++++++ formats_rust/default_endian_expr_is_le.ksy | 28 ++++++++++++ formats_rust/default_endian_mod.ksy | 28 ++++++++++++ formats_rust/expr_bits.ksy | 43 +++++++++++++++++++ 8 files changed, 247 insertions(+) create mode 100644 formats_rust/default_big_endian.ksy create mode 100644 formats_rust/default_bit_endian_mod.ksy create mode 100644 formats_rust/default_endian_expr_exception.ksy create mode 100644 formats_rust/default_endian_expr_inherited.ksy create mode 100644 formats_rust/default_endian_expr_is_be.ksy create mode 100644 formats_rust/default_endian_expr_is_le.ksy create mode 100644 formats_rust/default_endian_mod.ksy create mode 100644 formats_rust/expr_bits.ksy diff --git a/formats_rust/default_big_endian.ksy b/formats_rust/default_big_endian.ksy new file mode 100644 index 000000000..969c38563 --- /dev/null +++ b/formats_rust/default_big_endian.ksy @@ -0,0 +1,6 @@ +meta: + id: default_big_endian + endian: be +seq: + - id: one + type: u4 diff --git a/formats_rust/default_bit_endian_mod.ksy b/formats_rust/default_bit_endian_mod.ksy new file mode 100644 index 000000000..48ed70a3e --- /dev/null +++ b/formats_rust/default_bit_endian_mod.ksy @@ -0,0 +1,30 @@ +# Test proper propagation of default bit endianness in hierarchies +meta: + id: default_bit_endian_mod +seq: + - id: main + type: main_obj +types: + main_obj: + meta: + bit-endian: le + seq: + - id: one + type: b9 + - id: two + type: b15 + - id: nest + type: subnest + - id: nest_be + type: subnest_be + types: + subnest: + seq: + - id: two + type: b16 + subnest_be: + meta: + bit-endian: be + seq: + - id: two + type: b16 diff --git a/formats_rust/default_endian_expr_exception.ksy b/formats_rust/default_endian_expr_exception.ksy new file mode 100644 index 000000000..96ac0b5ee --- /dev/null +++ b/formats_rust/default_endian_expr_exception.ksy @@ -0,0 +1,30 @@ +# Parses doc[0] and doc[1], then raises an exception on doc[2] due to +# unknown endianness +meta: + id: default_endian_expr_exception +seq: + - id: docs + repeat: eos + type: doc +types: + doc: + seq: + - id: indicator + size: 2 + - id: main + type: main_obj + types: + main_obj: + meta: + endian: + switch-on: _parent.indicator + cases: + '[0x49, 0x49]': le + '[0x4d, 0x4d]': be + seq: + - id: some_int + type: u4 + - id: some_int_be + type: u2be + - id: some_int_le + type: u2le diff --git a/formats_rust/default_endian_expr_inherited.ksy b/formats_rust/default_endian_expr_inherited.ksy new file mode 100644 index 000000000..8e9455081 --- /dev/null +++ b/formats_rust/default_endian_expr_inherited.ksy @@ -0,0 +1,42 @@ +meta: + id: default_endian_expr_inherited +seq: + - id: docs + repeat: eos + type: doc +types: + doc: + seq: + - id: indicator + size: 2 + - id: main + type: main_obj + types: + main_obj: + meta: + endian: + switch-on: _parent.indicator + cases: + '[0x49, 0x49]': le + _: be + seq: + - id: insides + type: sub_obj + types: + sub_obj: + seq: + - id: some_int + type: u4 + - id: more + type: subsub_obj + types: + subsub_obj: + seq: + - id: some_int1 + type: u2 + - id: some_int2 + type: u2 + instances: + some_inst: + pos: 2 + type: u4 diff --git a/formats_rust/default_endian_expr_is_be.ksy b/formats_rust/default_endian_expr_is_be.ksy new file mode 100644 index 000000000..278da9bca --- /dev/null +++ b/formats_rust/default_endian_expr_is_be.ksy @@ -0,0 +1,40 @@ +meta: + id: default_endian_expr_is_be +seq: + - id: docs + repeat: eos + type: doc +types: + doc: + seq: + - id: indicator + size: 2 + - id: main + type: main_obj + types: + main_obj: + meta: + endian: + switch-on: _parent.indicator + cases: + '[0x4d, 0x4d]': be + _: le + seq: + - id: some_int + type: u4 + - id: some_int_be + type: u2be + - id: some_int_le + type: u2le + instances: + inst_int: + pos: 2 + type: u4 + inst_sub: + pos: 2 + type: sub_main_obj + types: + sub_main_obj: + seq: + - id: foo + type: u4 diff --git a/formats_rust/default_endian_expr_is_le.ksy b/formats_rust/default_endian_expr_is_le.ksy new file mode 100644 index 000000000..ac1848eb5 --- /dev/null +++ b/formats_rust/default_endian_expr_is_le.ksy @@ -0,0 +1,28 @@ +meta: + id: default_endian_expr_is_le +seq: + - id: docs + repeat: eos + type: doc +types: + doc: + seq: + - id: indicator + size: 2 + - id: main + type: main_obj + types: + main_obj: + meta: + endian: + switch-on: _parent.indicator + cases: + '[0x49, 0x49]': le + _: be + seq: + - id: some_int + type: u4 + - id: some_int_be + type: u2be + - id: some_int_le + type: u2le diff --git a/formats_rust/default_endian_mod.ksy b/formats_rust/default_endian_mod.ksy new file mode 100644 index 000000000..379658b80 --- /dev/null +++ b/formats_rust/default_endian_mod.ksy @@ -0,0 +1,28 @@ +# Test proper propagation of default endianness in hierarchies +meta: + id: default_endian_mod +seq: + - id: main + type: main_obj +types: + main_obj: + meta: + endian: le + seq: + - id: one + type: s4 + - id: nest + type: subnest + - id: nest_be + type: subnest_be + types: + subnest: + seq: + - id: two + type: s4 + subnest_be: + meta: + endian: be + seq: + - id: two + type: s4 diff --git a/formats_rust/expr_bits.ksy b/formats_rust/expr_bits.ksy new file mode 100644 index 000000000..608694f2e --- /dev/null +++ b/formats_rust/expr_bits.ksy @@ -0,0 +1,43 @@ +meta: + id: expr_bits +seq: + - id: enum_seq + type: b2 + enum: items + - id: a + type: b3 + - id: byte_size + size: a + - id: repeat_expr + type: s1 + repeat: expr + repeat-expr: a + - id: switch_on_type + type: + switch-on: a + cases: + 2: s1 + - id: switch_on_endian + type: endian_switch +instances: + enum_inst: + value: a + enum: items + inst_pos: + pos: a + type: s1 +types: + endian_switch: + meta: + endian: + switch-on: _parent.a + cases: + 1: le + 2: be + seq: + - id: foo + type: s2 +enums: + items: + 1: foo + 2: bar From 9d7531d8ce186238e1a0b01c45a415fe7a7d7c45 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 6 Oct 2022 20:53:36 +0200 Subject: [PATCH 099/198] debug tests. --- formats_rust/debug_0.ksy | 12 +++++++ formats_rust/debug_array_user.ksy | 17 ++++++++++ formats_rust/debug_enum_name.ksy | 37 +++++++++++++++++++++ formats_rust/debug_switch_user.ksy | 22 ++++++++++++ spec/rust/tests/manual_debug_0.rs | 11 ++++++ spec/rust/tests/manual_debug_array_user.rs | 23 +++++++++++++ spec/rust/tests/manual_debug_enum_name.rs | 10 ++++++ spec/rust/tests/manual_debug_switch_user.rs | 25 ++++++++++++++ 8 files changed, 157 insertions(+) create mode 100644 formats_rust/debug_0.ksy create mode 100644 formats_rust/debug_array_user.ksy create mode 100644 formats_rust/debug_enum_name.ksy create mode 100644 formats_rust/debug_switch_user.ksy create mode 100644 spec/rust/tests/manual_debug_0.rs create mode 100644 spec/rust/tests/manual_debug_array_user.rs create mode 100644 spec/rust/tests/manual_debug_enum_name.rs create mode 100644 spec/rust/tests/manual_debug_switch_user.rs diff --git a/formats_rust/debug_0.ksy b/formats_rust/debug_0.ksy new file mode 100644 index 000000000..2cb78decf --- /dev/null +++ b/formats_rust/debug_0.ksy @@ -0,0 +1,12 @@ +# Tests various capabilities in --debug mode +meta: + id: debug_0 + ks-debug: true +seq: + - id: one + type: u1 + - id: array_of_ints + type: u1 + repeat: expr + repeat-expr: 3 + - type: u1 # anonymous, numbered field diff --git a/formats_rust/debug_array_user.ksy b/formats_rust/debug_array_user.ksy new file mode 100644 index 000000000..84f709833 --- /dev/null +++ b/formats_rust/debug_array_user.ksy @@ -0,0 +1,17 @@ +# --debug (or actually --no-auto-read) with arrays of user types requires +# special handling to avoid spoiling whole object due to exception handler. +meta: + id: debug_array_user + ks-debug: true +seq: + - id: one_cat + type: cat + - id: array_of_cats + type: cat + repeat: expr + repeat-expr: 3 +types: + cat: + seq: + - id: meow + type: u1 diff --git a/formats_rust/debug_enum_name.ksy b/formats_rust/debug_enum_name.ksy new file mode 100644 index 000000000..0e401da61 --- /dev/null +++ b/formats_rust/debug_enum_name.ksy @@ -0,0 +1,37 @@ +# Tests enum name generation in --debug mode +meta: + id: debug_enum_name + ks-debug: true +seq: + - id: one + type: u1 + enum: test_enum1 + - id: array_of_ints + type: u1 + enum: test_enum2 + repeat: expr + repeat-expr: 1 + - id: test_type + type: test_subtype +types: + test_subtype: + seq: + - id: field1 + type: u1 + enum: inner_enum1 + - id: field2 + type: u1 + instances: + instance_field: + value: "field2 & 0xf" + enum: inner_enum2 + enums: + inner_enum1: + 67: enum_value_67 + inner_enum2: + 11: enum_value_11 +enums: + test_enum1: + 80: enum_value_80 + test_enum2: + 65: enum_value_65 diff --git a/formats_rust/debug_switch_user.ksy b/formats_rust/debug_switch_user.ksy new file mode 100644 index 000000000..563e74b7e --- /dev/null +++ b/formats_rust/debug_switch_user.ksy @@ -0,0 +1,22 @@ +meta: + id: debug_switch_user + endian: le + ks-debug: true +seq: + - id: code + type: u1 + - id: data + type: + switch-on: code + cases: + 1: one + 2: two +types: + one: + seq: + - id: val + type: s2 + two: + seq: + - id: val + type: u2 diff --git a/spec/rust/tests/manual_debug_0.rs b/spec/rust/tests/manual_debug_0.rs new file mode 100644 index 000000000..e1139ada4 --- /dev/null +++ b/spec/rust/tests/manual_debug_0.rs @@ -0,0 +1,11 @@ +#![allow(dead_code)] + +extern crate kaitai; +mod formats; +use formats::debug_0::*; + +#[test] +fn basic_parse() { + let r = Debug0::default(); + assert_eq!(*r.one(), 0); +} diff --git a/spec/rust/tests/manual_debug_array_user.rs b/spec/rust/tests/manual_debug_array_user.rs new file mode 100644 index 000000000..2e96a2893 --- /dev/null +++ b/spec/rust/tests/manual_debug_array_user.rs @@ -0,0 +1,23 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::debug_array_user::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = DebugArrayUser::default(); + { + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); + assert!(res.is_ok()); + } + + assert_eq!(*r.one_cat().meow(), 0x50); + assert_eq!(*r.array_of_cats()[0].meow(), 0x41); + assert_eq!(*r.array_of_cats()[1].meow(), 0x43); + assert_eq!(*r.array_of_cats()[2].meow(), 0x4b); + } diff --git a/spec/rust/tests/manual_debug_enum_name.rs b/spec/rust/tests/manual_debug_enum_name.rs new file mode 100644 index 000000000..bae589ce4 --- /dev/null +++ b/spec/rust/tests/manual_debug_enum_name.rs @@ -0,0 +1,10 @@ +#![allow(dead_code)] +extern crate kaitai; +mod formats; +use formats::debug_enum_name::*; + +#[test] +fn basic_parse() { + let r = DebugEnumName::default(); + assert_eq!(*r.test_type().field2(), 0); +} diff --git a/spec/rust/tests/manual_debug_switch_user.rs b/spec/rust/tests/manual_debug_switch_user.rs new file mode 100644 index 000000000..51c5afe5d --- /dev/null +++ b/spec/rust/tests/manual_debug_switch_user.rs @@ -0,0 +1,25 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::debug_switch_user::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = DebugSwitchUser::default(); + { + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); + assert!(res.is_ok()); + } + + assert_eq!(*r.code(), 1); + if let DebugSwitchUser_Data::DebugSwitchUser_One(s) = r.data() { + assert_eq!(*s.val(), -190); + } else { + panic!("expected enum DebugSwitchUser_Data"); + } +} From d5a6cb17254b73a82f6ebc375e266df9efce8e85 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 6 Oct 2022 20:53:57 +0200 Subject: [PATCH 100/198] more bit tests. --- formats_rust/repeat_eos_bit.ksy | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 formats_rust/repeat_eos_bit.ksy diff --git a/formats_rust/repeat_eos_bit.ksy b/formats_rust/repeat_eos_bit.ksy new file mode 100644 index 000000000..4bb6c70e0 --- /dev/null +++ b/formats_rust/repeat_eos_bit.ksy @@ -0,0 +1,6 @@ +meta: + id: repeat_eos_bit +seq: + - id: nibbles + type: b4 + repeat: eos From bf56de549f538f56b368166d37e9e0d39efafa58 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 6 Oct 2022 21:11:08 +0200 Subject: [PATCH 101/198] test renamed. --- .../{manual_debug_switch_user.rs => test_debug_switch_user.rs} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename spec/rust/tests/{manual_debug_switch_user.rs => test_debug_switch_user.rs} (100%) diff --git a/spec/rust/tests/manual_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs similarity index 100% rename from spec/rust/tests/manual_debug_switch_user.rs rename to spec/rust/tests/test_debug_switch_user.rs From 79fbd14ae2ccdd8bf1d7015e7360a9841d984fac Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 10 Oct 2022 14:42:24 +0200 Subject: [PATCH 102/198] more tests. --- formats_rust/fixed_struct.ksy | 91 +++++++++++++++++++++++++++++ formats_rust/non_standard.ksy | 30 ++++++++++ formats_rust/optional_id.ksy | 6 ++ spec/rust/tests/test_optional_id.rs | 24 ++++++++ 4 files changed, 151 insertions(+) create mode 100644 formats_rust/fixed_struct.ksy create mode 100644 formats_rust/non_standard.ksy create mode 100644 formats_rust/optional_id.ksy create mode 100644 spec/rust/tests/test_optional_id.rs diff --git a/formats_rust/fixed_struct.ksy b/formats_rust/fixed_struct.ksy new file mode 100644 index 000000000..d793538cf --- /dev/null +++ b/formats_rust/fixed_struct.ksy @@ -0,0 +1,91 @@ +meta: + id: fixed_struct + endian: le +types: + header: + seq: + - + id: magic1 + contents: 'PACK-1' + - + id: uint8 + type: u1 + - + id: sint8 + type: s1 + - + id: magic_uint + contents: 'PACK-U-DEF' + - + id: uint16 + type: u2 + - + id: uint32 + type: u4 + - + id: uint64 + type: u8 + - + id: magic_sint + contents: 'PACK-S-DEF' + - + id: sint16 + type: s2 + - + id: sint32 + type: s4 + - + id: sint64 + type: s8 + - + id: magic_uint_le + contents: 'PACK-U-LE' + - + id: uint16le + type: u2le + - + id: uint32le + type: u4le + - + id: uint64le + type: u8le + - + id: magic_sint_le + contents: 'PACK-S-LE' + - + id: sint16le + type: s2le + - + id: sint32le + type: s4le + - + id: sint64le + type: s8le + - + id: magic_uint_be + contents: 'PACK-U-BE' + - + id: uint16be + type: u2be + - + id: uint32be + type: u4be + - + id: uint64be + type: u8be + - + id: magic_sint_be + contents: 'PACK-S-BE' + - + id: sint16be + type: s2be + - + id: sint32be + type: s4be + - + id: sint64be + type: s8be +instances: + hdr: + pos: 0 + type: header diff --git a/formats_rust/non_standard.ksy b/formats_rust/non_standard.ksy new file mode 100644 index 000000000..7e225302f --- /dev/null +++ b/formats_rust/non_standard.ksy @@ -0,0 +1,30 @@ +meta: + id: non_standard + endian: le + -vendor-key: some value + -vendor-key2: + some: hash + with_more: values + -vendor-key3: + - foo + - bar +-vendor-key: value +seq: + - id: foo + type: u1 + -vendor-key: value + - id: bar + type: + switch-on: foo + -vendor-key: value + cases: + 42: u2 + 43: u4 +instances: + vi: + value: foo + -vendor-key: value + pi: + pos: 0 + type: u1 + -vendor-key: value diff --git a/formats_rust/optional_id.ksy b/formats_rust/optional_id.ksy new file mode 100644 index 000000000..60f9bacbb --- /dev/null +++ b/formats_rust/optional_id.ksy @@ -0,0 +1,6 @@ +meta: + id: optional_id +seq: + - type: u1 + - type: u1 + - size: 5 diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs new file mode 100644 index 000000000..eb5c77ef0 --- /dev/null +++ b/spec/rust/tests/test_optional_id.rs @@ -0,0 +1,24 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::optional_id::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + + let mut r = OptionalId::default(); + { + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); + println!("{:?}", res); + assert!(res.is_ok()); + } + + assert_eq!(*r.unnamed0(), 80); + assert_eq!(*r.unnamed1(), 65); + assert_eq!(*r.unnamed2(), vec![0x43, 0x4B, 0x2D, 0x31, 0xFF]); +} From 3b2397f214bfb90e74376a3d67d85af98087ce03 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 11 Oct 2022 14:35:29 +0200 Subject: [PATCH 103/198] process_custom tests. --- formats_rust/process_custom.ksy | 14 ++++++++++++++ formats_rust/process_custom_no_args.ksy | 6 ++++++ 2 files changed, 20 insertions(+) create mode 100644 formats_rust/process_custom.ksy create mode 100644 formats_rust/process_custom_no_args.ksy diff --git a/formats_rust/process_custom.ksy b/formats_rust/process_custom.ksy new file mode 100644 index 000000000..95edbdb48 --- /dev/null +++ b/formats_rust/process_custom.ksy @@ -0,0 +1,14 @@ +meta: + id: process_custom +seq: + - id: buf1 + size: 5 + process: my_custom_fx(7, true, [0x20, 0x30, 0x40]) + - id: buf2 + size: 5 + process: nested.deeply.custom_fx(7) + - id: key + type: u1 + - id: buf3 + size: 5 + process: my_custom_fx(key, false, [0x00]) diff --git a/formats_rust/process_custom_no_args.ksy b/formats_rust/process_custom_no_args.ksy new file mode 100644 index 000000000..7d1e24714 --- /dev/null +++ b/formats_rust/process_custom_no_args.ksy @@ -0,0 +1,6 @@ +meta: + id: process_custom_no_args +seq: + - id: buf + size: 5 + process: custom_fx_no_args From fa028be93f2a7b815d05fa7d86e8132a3e8d65e1 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 11 Oct 2022 14:35:53 +0200 Subject: [PATCH 104/198] leave custom files. --- spec/rust/build.rs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/spec/rust/build.rs b/spec/rust/build.rs index 3870dfebf..131c5b372 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -21,7 +21,13 @@ fn main() { }); } - remove_existing(destination_path).unwrap_or_else(|e| { + let except_files = vec![ + "custom_fx_no_args.rs", + "my_custom_fx.rs", + "custom_fx.rs", + ]; + + remove_existing(destination_path, except_files).unwrap_or_else(|e| { println!("Unable to remove existing files under test: {}", e.to_string()); }); @@ -32,13 +38,18 @@ fn main() { println!("cargo:rerun-if-changed={}", source_path.display().to_string()); } -fn remove_existing(destination_path: &Path) -> io::Result<()> { +fn remove_existing(destination_path: &Path, except_files: Vec<&str>) -> io::Result<()> { for entry in fs::read_dir(destination_path)? { let entry = entry?; let path = entry.path(); - - println!("cleaning {}", path.display().to_string()); - fs::remove_file(path)?; + let file_name = path.file_name().unwrap().to_os_string(); + + if except_files.iter().find(|&&x| *x == file_name).is_none() { + println!("cleaning {}", path.display().to_string()); + fs::remove_file(path)?; + } else { + println!("leaving {}", path.display().to_string()); + } } Ok(()) From 84b47b7a042f14f69b69a86f219a8888164f2212 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 11 Oct 2022 14:37:17 +0200 Subject: [PATCH 105/198] custom helper files added. --- spec/rust/tests/formats/custom_fx.rs | 24 ++++++++++++++++++ spec/rust/tests/formats/custom_fx_no_args.rs | 20 +++++++++++++++ spec/rust/tests/formats/my_custom_fx.rs | 26 ++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 spec/rust/tests/formats/custom_fx.rs create mode 100644 spec/rust/tests/formats/custom_fx_no_args.rs create mode 100644 spec/rust/tests/formats/my_custom_fx.rs diff --git a/spec/rust/tests/formats/custom_fx.rs b/spec/rust/tests/formats/custom_fx.rs new file mode 100644 index 000000000..bdd12cba6 --- /dev/null +++ b/spec/rust/tests/formats/custom_fx.rs @@ -0,0 +1,24 @@ +extern crate kaitai; +use kaitai::CustomDecoder; + +pub mod Nested { + pub mod Deeply { + pub struct CustomFx { + } + + impl CustomFx { + pub fn new(_p_key: u8) -> Self { + Self {} + } + } + + impl kaitai::CustomDecoder for CustomFx { + fn decode(&self, bytes: &[u8]) -> Vec { + let mut res = bytes.to_vec(); + res.insert(0, '_' as u8); + res.push('_' as u8); + res + } + } + } +} \ No newline at end of file diff --git a/spec/rust/tests/formats/custom_fx_no_args.rs b/spec/rust/tests/formats/custom_fx_no_args.rs new file mode 100644 index 000000000..90cc58c5f --- /dev/null +++ b/spec/rust/tests/formats/custom_fx_no_args.rs @@ -0,0 +1,20 @@ +extern crate kaitai; +use kaitai::CustomDecoder; + +pub struct CustomFxNoArgs { +} + +impl CustomFxNoArgs { + pub fn new() -> Self { + Self {} + } +} + +impl CustomDecoder for CustomFxNoArgs { + fn decode(&self, bytes: &[u8]) -> Vec { + let mut res = bytes.to_vec(); + res.insert(0, '_' as u8); + res.push('_' as u8); + res + } +} diff --git a/spec/rust/tests/formats/my_custom_fx.rs b/spec/rust/tests/formats/my_custom_fx.rs new file mode 100644 index 000000000..c01a92577 --- /dev/null +++ b/spec/rust/tests/formats/my_custom_fx.rs @@ -0,0 +1,26 @@ +extern crate kaitai; +use kaitai::CustomDecoder; + +pub struct MyCustomFx { + key: i32, +} + +impl MyCustomFx { + pub fn new(p_key: u8, p_flag :bool, _p_some_bytes: &[u8]) -> Self { + if (p_flag) { + Self { key: p_key as i32 } + } else { + Self { key: -(p_key as i32) } + } + } +} + +impl CustomDecoder for MyCustomFx { + fn decode(&self, bytes: &[u8]) -> Vec { + let mut res = bytes.to_vec(); + for i in res.iter_mut() { + *i = (*i as i32 + self.key) as u8; + } + res + } +} \ No newline at end of file From 1166801a1f2ca150e32994f5c1068c4674d5cbf5 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 11 Oct 2022 15:18:45 +0200 Subject: [PATCH 106/198] process_repeat_bytes test. --- formats_rust/process_repeat_bytes.ksy | 8 ++++++++ spec/rust/tests/test_process_repeat_bytes.rs | 21 ++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 formats_rust/process_repeat_bytes.ksy create mode 100644 spec/rust/tests/test_process_repeat_bytes.rs diff --git a/formats_rust/process_repeat_bytes.ksy b/formats_rust/process_repeat_bytes.ksy new file mode 100644 index 000000000..cdcccc8da --- /dev/null +++ b/formats_rust/process_repeat_bytes.ksy @@ -0,0 +1,8 @@ +meta: + id: process_repeat_bytes +seq: + - id: bufs + size: 5 + repeat: expr + repeat-expr: 2 + process: xor(0x9e) diff --git a/spec/rust/tests/test_process_repeat_bytes.rs b/spec/rust/tests/test_process_repeat_bytes.rs new file mode 100644 index 000000000..ff96c3b3c --- /dev/null +++ b/spec/rust/tests/test_process_repeat_bytes.rs @@ -0,0 +1,21 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::process_repeat_bytes::*; + + +#[test] +fn test_process_repeat_bytes() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = ProcessRepeatBytes::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(r.bufs()[0 as usize], vec![0x72u8, 0x25u8, 0x3du8, 0x8au8, 0x14u8]); + assert_eq!(r.bufs()[1 as usize], vec![0x4au8, 0x52u8, 0xaau8, 0x10u8, 0x44u8]); +} From a6861f117946bf112c086f0148f50ade0ec45c5e Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 11 Oct 2022 15:19:56 +0200 Subject: [PATCH 107/198] process_repeat_usertype test. --- formats_rust/process_repeat_usertype.ksy | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 formats_rust/process_repeat_usertype.ksy diff --git a/formats_rust/process_repeat_usertype.ksy b/formats_rust/process_repeat_usertype.ksy new file mode 100644 index 000000000..edbe7bdd2 --- /dev/null +++ b/formats_rust/process_repeat_usertype.ksy @@ -0,0 +1,17 @@ +meta: + id: process_repeat_usertype + endian: le +seq: + - id: blocks + size: 5 + type: block + repeat: expr + repeat-expr: 2 + process: xor(0x9e) +types: + block: + seq: + - id: a + type: s4 + - id: b + type: s1 From eceb69bd4acf2f2c71ca6a6775b58bcc1b4308d5 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 11 Oct 2022 15:58:11 +0200 Subject: [PATCH 108/198] opaque_with_param test. --- formats_rust/opaque_with_param.ksy | 6 ++++++ spec/rust/tests/manual_opaque_with_param.rs | 23 +++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 formats_rust/opaque_with_param.ksy create mode 100644 spec/rust/tests/manual_opaque_with_param.rs diff --git a/formats_rust/opaque_with_param.ksy b/formats_rust/opaque_with_param.ksy new file mode 100644 index 000000000..758b6d6f8 --- /dev/null +++ b/formats_rust/opaque_with_param.ksy @@ -0,0 +1,6 @@ +meta: + id: opaque_with_param + ks-opaque-types: true +seq: + - id: one + type: params_def(5, true) diff --git a/spec/rust/tests/manual_opaque_with_param.rs b/spec/rust/tests/manual_opaque_with_param.rs new file mode 100644 index 000000000..042a2f408 --- /dev/null +++ b/spec/rust/tests/manual_opaque_with_param.rs @@ -0,0 +1,23 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::opaque_with_param::*; + + +#[test] +fn test_params_def() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = OpaqueWithParam::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + let one = r.one(); + let p = one.as_ref().unwrap(); + assert_eq!(*p.buf(), "foo|b"); + assert_eq!(*p.trailer(), 0x61); +} From ab593f1f1ce3d5ac1ff4d1f007715da4afd1acf3 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 12 Oct 2022 15:47:36 +0200 Subject: [PATCH 109/198] enums now closer to c++-enums. --- spec/rust/tests/test_enum_for_unknown_id.rs | 9 +++++---- spec/rust/tests/test_enum_invalid.rs | 11 ++++++----- .../struct/testtranslator/specgenerators/RustSG.scala | 3 ++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/spec/rust/tests/test_enum_for_unknown_id.rs b/spec/rust/tests/test_enum_for_unknown_id.rs index 025cb3bc8..bae46909b 100644 --- a/spec/rust/tests/test_enum_for_unknown_id.rs +++ b/spec/rust/tests/test_enum_for_unknown_id.rs @@ -1,3 +1,5 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; @@ -13,10 +15,9 @@ fn test_enum_for_unknown_id() { let mut r = EnumForUnknownId::default(); if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: UnknownVariant", err); - } else { - panic!("no expected exception: UnknownVariant"); + panic!("{:?}", err); } - //assert_eq!(r.one().clone().to_owned() as u64, 80); + let i : i64 = r.one().into(); + assert_eq!(i, 80); } diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs index e310dd5e1..2aff3493d 100644 --- a/spec/rust/tests/test_enum_invalid.rs +++ b/spec/rust/tests/test_enum_invalid.rs @@ -1,3 +1,5 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; @@ -13,11 +15,10 @@ fn test_enum_invalid() { let mut r = EnumInvalid::default(); if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { - println!("expected err: {:?}, exception: UnknownVariant", err); - } else { - panic!("no expected exception: UnknownVariant"); + panic!("{:?}", err); } - // assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); - // assert_eq!(r.pet_2().clone().to_owned() as u64, 111); + assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); + let i : i64 = r.pet_2().into(); + assert_eq!(i, 111); } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index e6a6747aa..e0f19f748 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -84,7 +84,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => - actStr = s"${translator.remove_deref(actStr)}.clone().to_owned() as u64" + out.puts(s"let n : i64 = ${translator.remove_deref(actStr)}.into();") + actStr = s"n" case _ => } // fix expStr as vector From da82e61bb42ed5cf9256d14eceaa9ac06c2b1c09 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 12 Oct 2022 19:55:32 +0200 Subject: [PATCH 110/198] switch_manual_enum_invalid* tests. --- formats_rust/switch_manual_enum_invalid.ksy | 33 ++++++++++++++++ .../switch_manual_enum_invalid_else.ksy | 38 +++++++++++++++++++ .../tests/test_switch_manual_enum_invalid.rs | 28 ++++++++++++++ .../test_switch_manual_enum_invalid_else.rs | 34 +++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 formats_rust/switch_manual_enum_invalid.ksy create mode 100644 formats_rust/switch_manual_enum_invalid_else.ksy create mode 100644 spec/rust/tests/test_switch_manual_enum_invalid.rs create mode 100644 spec/rust/tests/test_switch_manual_enum_invalid_else.rs diff --git a/formats_rust/switch_manual_enum_invalid.ksy b/formats_rust/switch_manual_enum_invalid.ksy new file mode 100644 index 000000000..30a2b4126 --- /dev/null +++ b/formats_rust/switch_manual_enum_invalid.ksy @@ -0,0 +1,33 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/300 +meta: + id: switch_manual_enum_invalid +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: u1 + enum: code_enum + - id: body + type: + switch-on: code + cases: + code_enum::intval: intval + code_enum::strval: strval + enums: + code_enum: + 73: intval # 'I' + 83: strval # 'S' + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/formats_rust/switch_manual_enum_invalid_else.ksy b/formats_rust/switch_manual_enum_invalid_else.ksy new file mode 100644 index 000000000..5911655ca --- /dev/null +++ b/formats_rust/switch_manual_enum_invalid_else.ksy @@ -0,0 +1,38 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/300 +meta: + id: switch_manual_enum_invalid_else +seq: + - id: opcodes + type: opcode + repeat: eos +types: + opcode: + seq: + - id: code + type: u1 + enum: code_enum + - id: body + type: + switch-on: code + cases: + code_enum::intval: intval + code_enum::strval: strval + _: defval + enums: + code_enum: + 73: intval # 'I' + 83: strval # 'S' + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII + defval: + instances: + value: + value: 123 diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs new file mode 100644 index 000000000..78905520a --- /dev/null +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -0,0 +1,28 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_enum_invalid::*; + + +#[test] +fn test_switch_manual_enum_invalid() { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualEnumInvalid::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(r.opcodes().len(), 2); + let n : i64 = r.opcodes()[0 as usize].code().into(); + assert_eq!(n, 255); + // body is None + //assert_eq!(r.opcodes()[0 as usize].body(), 0); + let n : i64 = r.opcodes()[1 as usize].code().into(); + assert_eq!(n, 1); + // body is None + //assert_eq!(r.opcodes()[1 as usize].body(), 0); +} diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs new file mode 100644 index 000000000..8d0e917e1 --- /dev/null +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -0,0 +1,34 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::switch_manual_enum_invalid_else::*; + + +#[test] +fn test_switch_manual_enum_invalid_else() { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = SwitchManualEnumInvalidElse::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(r.opcodes().len(), 2); + let n : i64 = r.opcodes()[0 as usize].code().into(); + assert_eq!(n, 255); + if let SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s) = r.opcodes()[0].body() { + assert_eq!(*s.value(&reader, Some(&r)).unwrap(), 123); + } else { + panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); + } + let n : i64 = r.opcodes()[1 as usize].code().into(); + assert_eq!(n, 1); + if let SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s) = r.opcodes()[1].body() { + assert_eq!(*s.value(&reader, Some(&r)).unwrap(), 123); + } else { + panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); + } +} From e72f1e414f6a65fb3cfac25c71543103a09c0e06 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 13 Oct 2022 15:01:01 +0200 Subject: [PATCH 111/198] opaque tests. --- formats_rust/opaque_external_type.ksy | 6 ++++ .../opaque_external_type_02_child.ksy | 28 +++++++++++++++++++ .../opaque_external_type_02_parent.ksy | 12 ++++++++ .../rust/tests/manual_opaque_external_type.rs | 21 ++++++++++++++ .../manual_opaque_external_type_02_parent.rs | 21 ++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 formats_rust/opaque_external_type.ksy create mode 100644 formats_rust/opaque_external_type_02_child.ksy create mode 100644 formats_rust/opaque_external_type_02_parent.ksy create mode 100644 spec/rust/tests/manual_opaque_external_type.rs create mode 100644 spec/rust/tests/manual_opaque_external_type_02_parent.rs diff --git a/formats_rust/opaque_external_type.ksy b/formats_rust/opaque_external_type.ksy new file mode 100644 index 000000000..4336b88f2 --- /dev/null +++ b/formats_rust/opaque_external_type.ksy @@ -0,0 +1,6 @@ +meta: + id: opaque_external_type + ks-opaque-types: true +seq: + - id: one + type: term_strz diff --git a/formats_rust/opaque_external_type_02_child.ksy b/formats_rust/opaque_external_type_02_child.ksy new file mode 100644 index 000000000..eb18b1d8d --- /dev/null +++ b/formats_rust/opaque_external_type_02_child.ksy @@ -0,0 +1,28 @@ +# https://github.com/kaitai-io/kaitai_struct_compiler/issues/44 +meta: + id: opaque_external_type_02_child + endian: le +seq: + - id: s1 + type: str + encoding: UTF-8 + terminator: 0x7C + - id: s2 + type: str + encoding: UTF-8 + terminator: 0x7C + consume: false + - id: s3 + type: opaque_external_type_02_child_child +types: + opaque_external_type_02_child_child: + seq: + - id: s3 + type: str + encoding: UTF-8 + terminator: 0x40 + include: true + if: _root.some_method +instances: + some_method: + value: "true" diff --git a/formats_rust/opaque_external_type_02_parent.ksy b/formats_rust/opaque_external_type_02_parent.ksy new file mode 100644 index 000000000..759d54014 --- /dev/null +++ b/formats_rust/opaque_external_type_02_parent.ksy @@ -0,0 +1,12 @@ +# https://github.com/kaitai-io/kaitai_struct_compiler/issues/44 +meta: + id: opaque_external_type_02_parent + ks-opaque-types: true +seq: + - id: parent + type: parent_obj +types: + parent_obj: + seq: + - id: child + type: opaque_external_type_02_child diff --git a/spec/rust/tests/manual_opaque_external_type.rs b/spec/rust/tests/manual_opaque_external_type.rs new file mode 100644 index 000000000..b7fa78e9c --- /dev/null +++ b/spec/rust/tests/manual_opaque_external_type.rs @@ -0,0 +1,21 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::opaque_external_type::*; + +#[test] +fn test_term_strz() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = OpaqueExternalType::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.one().as_ref().unwrap().s1(), "foo"); + assert_eq!(*r.one().as_ref().unwrap().s2(), "bar"); + assert_eq!(*r.one().as_ref().unwrap().s3(), "|baz@"); +} diff --git a/spec/rust/tests/manual_opaque_external_type_02_parent.rs b/spec/rust/tests/manual_opaque_external_type_02_parent.rs new file mode 100644 index 000000000..031dc4117 --- /dev/null +++ b/spec/rust/tests/manual_opaque_external_type_02_parent.rs @@ -0,0 +1,21 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::opaque_external_type_02_parent::*; + +#[test] +fn test_term_strz() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = OpaqueExternalType02Parent::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*r.parent().child().as_ref().unwrap().s1(), "foo"); + assert_eq!(*r.parent().child().as_ref().unwrap().s2(), "bar"); + assert_eq!(*r.parent().child().as_ref().unwrap().s3().s3(), "|baz@"); +} From ed41543fa5f620bf2d33525257f43ca0fbc0112e Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sun, 16 Oct 2022 09:54:37 +0200 Subject: [PATCH 112/198] 2 more tests. --- formats_rust/type_ternary_opaque.ksy | 18 +++++++++++++++ formats_rust/user_type.ksy | 15 +++++++++++++ spec/rust/tests/manual_type_ternary_opaque.rs | 22 +++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 formats_rust/type_ternary_opaque.ksy create mode 100644 formats_rust/user_type.ksy create mode 100644 spec/rust/tests/manual_type_ternary_opaque.rs diff --git a/formats_rust/type_ternary_opaque.ksy b/formats_rust/type_ternary_opaque.ksy new file mode 100644 index 000000000..9c8416a51 --- /dev/null +++ b/formats_rust/type_ternary_opaque.ksy @@ -0,0 +1,18 @@ +meta: + id: type_ternary_opaque + ks-opaque-types: true +seq: + - id: dif_wo_hack + size: 12 + type: term_strz + if: not is_hack + - id: dif_with_hack + size: 12 + type: term_strz + process: xor(0b00000011) + if: is_hack +instances: + is_hack: + value: "false" + dif: + value: "not is_hack ? dif_wo_hack : dif_with_hack" diff --git a/formats_rust/user_type.ksy b/formats_rust/user_type.ksy new file mode 100644 index 000000000..9e56f7b9f --- /dev/null +++ b/formats_rust/user_type.ksy @@ -0,0 +1,15 @@ +# Tests very basic user-defined type functionality. A single type is +# defined in top-level class and is invoked via a seq attribute. +meta: + id: user_type + endian: le +seq: + - id: one + type: header +types: + header: + seq: + - id: width + type: u4 + - id: height + type: u4 diff --git a/spec/rust/tests/manual_type_ternary_opaque.rs b/spec/rust/tests/manual_type_ternary_opaque.rs new file mode 100644 index 000000000..f83acf69f --- /dev/null +++ b/spec/rust/tests/manual_type_ternary_opaque.rs @@ -0,0 +1,22 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::type_ternary_opaque::*; + +#[test] +fn test_term_strz() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = TypeTernaryOpaque::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + let dif = r.dif(&reader, Some(&r)).unwrap(); + assert_eq!(*dif.as_ref().unwrap().s1(), "foo"); + assert_eq!(*dif.as_ref().unwrap().s2(), "bar"); + assert_eq!(*dif.as_ref().unwrap().s3(), "|baz@"); +} From c4a5e7af54c6e6e499cecd666d3444a9c2e3de3b Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 21 Oct 2022 10:57:04 +0200 Subject: [PATCH 113/198] to_string_custom added. --- formats_rust/to_string_custom.ksy | 12 ++++++++++++ spec/rust/tests/manual_to_string_custom.rs | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 formats_rust/to_string_custom.ksy create mode 100644 spec/rust/tests/manual_to_string_custom.rs diff --git a/formats_rust/to_string_custom.ksy b/formats_rust/to_string_custom.ksy new file mode 100644 index 000000000..dd893eaca --- /dev/null +++ b/formats_rust/to_string_custom.ksy @@ -0,0 +1,12 @@ +meta: + id: to_string_custom + encoding: UTF-8 +seq: + - id: s1 + type: str + terminator: 0x7c + - id: s2 + type: str + terminator: 0x7c +to-string: | + "s1 = " + s1 + ", s2 = " + s2 diff --git a/spec/rust/tests/manual_to_string_custom.rs b/spec/rust/tests/manual_to_string_custom.rs new file mode 100644 index 000000000..1c9bc0893 --- /dev/null +++ b/spec/rust/tests/manual_to_string_custom.rs @@ -0,0 +1,21 @@ +#![allow(dead_code)] +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::to_string_custom::*; + +#[test] +fn basic_parse() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let reader = BytesReader::new(&bytes); + + let mut r = ToStringCustom::default(); + { + let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); + assert!(res.is_ok()); + } + + assert_eq!(r.to_string(), "s1 = foo, s2 = bar"); +} From cc8928958d5e95f4e41832bf16ad54e521e0644a Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 15 Nov 2022 07:40:34 +0800 Subject: [PATCH 114/198] more parent tests. --- formats_rust/nav_parent.ksy | 15 ++++++--------- formats_rust/nav_parent_false.ksy | 29 +++++++++++++++++++++++++++++ formats_rust/nav_parent_switch.ksy | 11 +++++------ formats_rust/nav_parent_test.ksy | 25 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 formats_rust/nav_parent_false.ksy create mode 100644 formats_rust/nav_parent_test.ksy diff --git a/formats_rust/nav_parent.ksy b/formats_rust/nav_parent.ksy index 87b8e010d..0516b587a 100644 --- a/formats_rust/nav_parent.ksy +++ b/formats_rust/nav_parent.ksy @@ -21,12 +21,9 @@ types: type: entry repeat: expr repeat-expr: _parent.header.qty_entries - types: - entry: - seq: - - id: filename - type: str - size: _parent._parent.header.filename_len - encoding: UTF-8 - -# this is fixed test with correct alignmnet (parent as subtypes) \ No newline at end of file + entry: + seq: + - id: filename + type: str + size: _parent._parent.header.filename_len + encoding: UTF-8 diff --git a/formats_rust/nav_parent_false.ksy b/formats_rust/nav_parent_false.ksy new file mode 100644 index 000000000..270bb0d5a --- /dev/null +++ b/formats_rust/nav_parent_false.ksy @@ -0,0 +1,29 @@ +meta: + id: nav_parent_false +seq: + - id: child_size + type: u1 + - id: element_a + type: parent_a + - id: element_b + type: parent_b +types: + parent_a: + seq: + - id: foo + type: child + - id: bar + type: parent_b + parent_b: + seq: + - id: foo + type: child + parent: false + child: + # should have only one parent of type `parent_a` + seq: + - id: code + type: u1 + - id: more + size: _parent._parent.child_size + if: code == 73 diff --git a/formats_rust/nav_parent_switch.ksy b/formats_rust/nav_parent_switch.ksy index 859c50d09..1c96073f0 100644 --- a/formats_rust/nav_parent_switch.ksy +++ b/formats_rust/nav_parent_switch.ksy @@ -15,9 +15,8 @@ types: type: u1 - id: subelement type: subelement_1 - types: - subelement_1: - seq: - - id: bar - type: u1 - if: _parent.foo == 0x42 + subelement_1: + seq: + - id: bar + type: u1 + if: _parent.foo == 0x42 diff --git a/formats_rust/nav_parent_test.ksy b/formats_rust/nav_parent_test.ksy new file mode 100644 index 000000000..e27a33cb3 --- /dev/null +++ b/formats_rust/nav_parent_test.ksy @@ -0,0 +1,25 @@ +meta: + id: nav_parent_test + endian: le +seq: + - id: qty_entries + type: u4 + - id: filename_len + type: u4 + - id: index + type: index_obj +types: + index_obj: + seq: + - id: magic + size: 4 + - id: entries + type: entry + repeat: expr + repeat-expr: _parent.qty_entries + entry: + seq: + - id: filename + type: str + size: _parent._parent.filename_len + encoding: UTF-8 From b71797d09006e3a8475b15b0b3ab542ef9fd6fef Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 16 Nov 2022 12:17:25 +0800 Subject: [PATCH 115/198] nested_types tests. --- formats_rust/nested_types2.ksy | 40 ++++++++++++++++++++++++++++++++++ formats_rust/nested_types3.ksy | 31 ++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 formats_rust/nested_types2.ksy create mode 100644 formats_rust/nested_types3.ksy diff --git a/formats_rust/nested_types2.ksy b/formats_rust/nested_types2.ksy new file mode 100644 index 000000000..203c0ee7e --- /dev/null +++ b/formats_rust/nested_types2.ksy @@ -0,0 +1,40 @@ +meta: + id: nested_types2 +seq: + - id: one + type: subtype_a + - id: two + type: subtype_b +types: + subtype_a: + seq: + - id: typed_at_root + type: subtype_b + - id: typed_here1 + type: subtype_c + - id: typed_here2 + type: subtype_cc + types: + subtype_c: + seq: + - id: value_c + type: s1 + - id: typed_here + type: subtype_d + - id: typed_parent + type: subtype_cc + - id: typed_root + type: subtype_b + types: + subtype_d: + seq: + - id: value_d + type: s1 + subtype_cc: + seq: + - id: value_cc + type: s1 + subtype_b: + seq: + - id: value_b + type: s1 diff --git a/formats_rust/nested_types3.ksy b/formats_rust/nested_types3.ksy new file mode 100644 index 000000000..0fed9bc67 --- /dev/null +++ b/formats_rust/nested_types3.ksy @@ -0,0 +1,31 @@ +# Check usage of a::b::c syntax +meta: + id: nested_types3 +seq: + - id: a_cc + type: subtype_a::subtype_cc + - id: a_c_d + type: subtype_a::subtype_c::subtype_d + - id: b + type: subtype_b +types: + subtype_a: + types: + subtype_c: + types: + subtype_d: + seq: + - id: value_d + type: s1 + subtype_cc: + seq: + - id: value_cc + type: s1 + subtype_b: + seq: + - id: value_b + type: s1 + - id: a_cc + type: subtype_a::subtype_cc + - id: a_c_d + type: subtype_a::subtype_c::subtype_d From 82ceb4bae69282ebe4d6f0885ebcbae19b628498 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 17 Nov 2022 09:57:50 +0800 Subject: [PATCH 116/198] more enum tests. --- formats_rust/combine_enum.ksy | 17 +++++++++++++++++ formats_rust/enum_import.ksy | 13 +++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 formats_rust/combine_enum.ksy create mode 100644 formats_rust/enum_import.ksy diff --git a/formats_rust/combine_enum.ksy b/formats_rust/combine_enum.ksy new file mode 100644 index 000000000..1f3c81cae --- /dev/null +++ b/formats_rust/combine_enum.ksy @@ -0,0 +1,17 @@ +meta: + id: combine_enum + endian: le +seq: + - id: enum_u4 + type: u4 + enum: animal + - id: enum_u2 + type: u2 + enum: animal +enums: + animal: + 7: pig + 12: horse +instances: + enum_u4_u2: + value: 'false ? enum_u4 : enum_u2' diff --git a/formats_rust/enum_import.ksy b/formats_rust/enum_import.ksy new file mode 100644 index 000000000..bec0bff8a --- /dev/null +++ b/formats_rust/enum_import.ksy @@ -0,0 +1,13 @@ +meta: + id: enum_import + endian: le + imports: + - enum_0 + - enum_deep +seq: + - id: pet_1 + type: u4 + enum: enum_0::animal + - id: pet_2 + type: u4 + enum: enum_deep::container1::container2::animal From ae144e5849815053be169e54f4b56c0a0e645dbf Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 18 Nov 2022 13:38:40 +0800 Subject: [PATCH 117/198] switch_manual_int_size_eos restored to original. --- formats_rust/switch_manual_int_size_eos.ksy | 47 +++++++++---------- .../tests/test_switch_manual_int_size_eos.rs | 12 ++--- 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/formats_rust/switch_manual_int_size_eos.ksy b/formats_rust/switch_manual_int_size_eos.ksy index d5fb8ae29..aaebe0907 100644 --- a/formats_rust/switch_manual_int_size_eos.ksy +++ b/formats_rust/switch_manual_int_size_eos.ksy @@ -15,29 +15,28 @@ types: - id: body size: size type: chunk_body + chunk_body: + seq: + - id: body + size-eos: true + type: + switch-on: _parent.code + cases: + 0x11: chunk_meta + 0x22: chunk_dir types: - chunk_body: + chunk_meta: + seq: + - id: title + type: strz + encoding: UTF-8 + - id: author + type: strz + encoding: UTF-8 + chunk_dir: seq: - - id: body - size-eos: true - type: - switch-on: _parent.code - cases: - 0x11: chunk_meta - 0x22: chunk_dir - types: - chunk_meta: - seq: - - id: title - type: strz - encoding: UTF-8 - - id: author - type: strz - encoding: UTF-8 - chunk_dir: - seq: - - id: entries - type: str - size: 4 - repeat: eos - encoding: UTF-8 + - id: entries + type: str + size: 4 + repeat: eos + encoding: UTF-8 diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 1493b4ad7..042ae9c91 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -19,23 +19,23 @@ fn test_switch_manual_int_size_eos() { assert_eq!(4, r.chunks().len()); assert_eq!(17, *r.chunks()[0].code()); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkMeta(s) = r.chunks()[0].body().body() { + if let SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkMeta(s) = r.chunks()[0].body().body() { assert_eq!("Stuff", s.title()); assert_eq!("Me", s.author()); } else { - panic!("expected enum SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkMeta"); + panic!("expected enum SwitchManualIntSizeEos_ChunkBody_ChunkMeta"); } assert_eq!(34, *r.chunks()[1].code()); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkDir(s) = r.chunks()[1].body().body() { + if let SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkDir(s) = r.chunks()[1].body().body() { let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); assert_eq!(strings, *s.entries()); } else { - panic!("expected enum SwitchManualIntSizeEos_Chunk_ChunkBody_ChunkDir"); + panic!("expected enum SwitchManualIntSizeEos_ChunkBody_ChunkDir"); } assert_eq!(51, *r.chunks()[2].code()); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks()[2].body().body() { + if let SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s) = r.chunks()[2].body().body() { let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s); } else { @@ -43,7 +43,7 @@ fn test_switch_manual_int_size_eos() { } assert_eq!(255, *r.chunks()[3].code()); - if let SwitchManualIntSizeEos_Chunk_ChunkBody_Body::Bytes(s) = r.chunks()[3].body().body() { + if let SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s) = r.chunks()[3].body().body() { let raw : Vec = vec![]; assert_eq!(raw, *s); } else { From 7fea25f3145e88ebe99de3f7a58823570bf9b000 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 21 Nov 2022 16:44:27 +0800 Subject: [PATCH 118/198] support of cp437 added. --- formats_rust/expr_str_encodings.ksy | 4 ++-- formats_rust/str_encodings.ksy | 2 +- formats_rust/str_encodings_default.ksy | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/formats_rust/expr_str_encodings.ksy b/formats_rust/expr_str_encodings.ksy index 34759905e..0ae2de1a0 100644 --- a/formats_rust/expr_str_encodings.ksy +++ b/formats_rust/expr_str_encodings.ksy @@ -25,7 +25,7 @@ seq: - id: str4 type: str size: len_of_4 - encoding: CP866 + encoding: CP437 instances: str1_eq: value: str1 == "Some ASCII" @@ -41,4 +41,4 @@ instances: value: str4 > "┤" # in UTF-8 "░" (U+2591) > "┤" (U+2524), # in CP437 "░" (0xB0) < "┤" (0xB4) str4_gt_str_from_bytes: - value: 'str4 > [0xb4].to_s("CP866")' + value: 'str4 > [0xb4].to_s("CP437")' diff --git a/formats_rust/str_encodings.ksy b/formats_rust/str_encodings.ksy index 4bfa31e93..96d3e07a3 100644 --- a/formats_rust/str_encodings.ksy +++ b/formats_rust/str_encodings.ksy @@ -25,4 +25,4 @@ seq: - id: str4 type: str size: len_of_4 - encoding: CP866 # CP437 + encoding: CP437 diff --git a/formats_rust/str_encodings_default.ksy b/formats_rust/str_encodings_default.ksy index be4e1ef03..06dce3070 100644 --- a/formats_rust/str_encodings_default.ksy +++ b/formats_rust/str_encodings_default.ksy @@ -29,4 +29,4 @@ types: - id: str4 type: str size: len_of_4 - encoding: CP866 # CP437 + encoding: CP437 From 9b020eb3da947186a97bdf70f78f3c16bade93e2 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 21 Nov 2022 16:45:05 +0800 Subject: [PATCH 119/198] nested_type_param test added. --- formats_rust/nested_type_param.ksy | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 formats_rust/nested_type_param.ksy diff --git a/formats_rust/nested_type_param.ksy b/formats_rust/nested_type_param.ksy new file mode 100644 index 000000000..470bb176d --- /dev/null +++ b/formats_rust/nested_type_param.ksy @@ -0,0 +1,17 @@ +meta: + id: nested_type_param +seq: + - id: main_seq + type: nested::my_type(5) +types: + nested: + types: + my_type: + params: + - id: my_len + type: u4 + seq: + - id: body + type: str + size: my_len + encoding: ASCII From 126849e1dc61d96ce6b6cde8e26883eec8520e75 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 21 Nov 2022 16:53:15 +0800 Subject: [PATCH 120/198] valid_eq_str_encodings tests. --- formats_rust/valid_eq_str_encodings.ksy | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 formats_rust/valid_eq_str_encodings.ksy diff --git a/formats_rust/valid_eq_str_encodings.ksy b/formats_rust/valid_eq_str_encodings.ksy new file mode 100644 index 000000000..1f6f57006 --- /dev/null +++ b/formats_rust/valid_eq_str_encodings.ksy @@ -0,0 +1,32 @@ +meta: + id: valid_eq_str_encodings + endian: le +seq: + - id: len_of_1 + type: u2 + - id: str1 + type: str + size: len_of_1 + encoding: ASCII + valid: '"Some ASCII"' + - id: len_of_2 + type: u2 + - id: str2 + type: str + size: len_of_2 + encoding: UTF-8 + valid: '"こんにちは"' + - id: len_of_3 + type: u2 + - id: str3 + type: str + size: len_of_3 + encoding: SJIS + valid: '"こんにちは"' + - id: len_of_4 + type: u2 + - id: str4 + type: str + size: len_of_4 + encoding: CP437 + valid: '"░▒▓"' From e135f9bd38fdc84e9cbdd81cbf8864c1085cf422 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 24 Nov 2022 14:01:39 +0800 Subject: [PATCH 121/198] cast_to_imported test added. --- formats_rust/cast_to_imported.ksy | 10 ++++++++++ spec/rust/tests/test_cast_to_imported.rs | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 formats_rust/cast_to_imported.ksy create mode 100644 spec/rust/tests/test_cast_to_imported.rs diff --git a/formats_rust/cast_to_imported.ksy b/formats_rust/cast_to_imported.ksy new file mode 100644 index 000000000..7c2aee155 --- /dev/null +++ b/formats_rust/cast_to_imported.ksy @@ -0,0 +1,10 @@ +meta: + id: cast_to_imported + imports: + - hello_world +seq: + - id: one + type: hello_world +instances: + one_casted: + value: one.as diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs new file mode 100644 index 000000000..0f3dc08ce --- /dev/null +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -0,0 +1,20 @@ +use std::fs; + +extern crate kaitai; +use self::kaitai::*; +mod formats; +use formats::cast_to_imported::*; + +#[test] +fn test_cast_to_imported() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let reader = BytesReader::new(&bytes); + let mut r = CastToImported::default(); + + if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + panic!("{:?}", err); + } + + assert_eq!(*(*(*r.one()).as_ref().unwrap()).one(), 80); + assert_eq!(*(*(*r.one_casted(&reader, Some(&r)).unwrap()).as_ref().unwrap()).one(), 80); +} From b8abb6fa8cca6cbaad7f0154bddc82309a2f6b21 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 27 Dec 2022 13:30:08 +0800 Subject: [PATCH 122/198] tests updated. --- spec/rust/tests/manual_imports_abs_rel.rs | 9 ++++++--- spec/rust/tests/manual_opaque_external_type.rs | 9 ++++++--- .../tests/manual_opaque_external_type_02_parent.rs | 9 ++++++--- spec/rust/tests/manual_type_ternary_opaque.rs | 11 +++++++---- spec/rust/tests/test_cast_to_imported.rs | 11 +++++++---- spec/rust/tests/test_imports_circular_a.rs | 11 +++++++---- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/spec/rust/tests/manual_imports_abs_rel.rs b/spec/rust/tests/manual_imports_abs_rel.rs index e496208b4..95a9139c2 100644 --- a/spec/rust/tests/manual_imports_abs_rel.rs +++ b/spec/rust/tests/manual_imports_abs_rel.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::imports_abs_rel::*; fn test_params_def() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = ImportsAbsRel::default(); + let res = ImportsAbsRel::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.one(), 80); diff --git a/spec/rust/tests/manual_opaque_external_type.rs b/spec/rust/tests/manual_opaque_external_type.rs index b7fa78e9c..a75014a3e 100644 --- a/spec/rust/tests/manual_opaque_external_type.rs +++ b/spec/rust/tests/manual_opaque_external_type.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -9,10 +9,13 @@ use formats::opaque_external_type::*; fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = OpaqueExternalType::default(); + let res = OpaqueExternalType::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.one().as_ref().unwrap().s1(), "foo"); diff --git a/spec/rust/tests/manual_opaque_external_type_02_parent.rs b/spec/rust/tests/manual_opaque_external_type_02_parent.rs index 031dc4117..446bef2d3 100644 --- a/spec/rust/tests/manual_opaque_external_type_02_parent.rs +++ b/spec/rust/tests/manual_opaque_external_type_02_parent.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -9,10 +9,13 @@ use formats::opaque_external_type_02_parent::*; fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = OpaqueExternalType02Parent::default(); + let res = OpaqueExternalType02Parent::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.parent().child().as_ref().unwrap().s1(), "foo"); diff --git a/spec/rust/tests/manual_type_ternary_opaque.rs b/spec/rust/tests/manual_type_ternary_opaque.rs index f83acf69f..70a3b172b 100644 --- a/spec/rust/tests/manual_type_ternary_opaque.rs +++ b/spec/rust/tests/manual_type_ternary_opaque.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -9,13 +9,16 @@ use formats::type_ternary_opaque::*; fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = TypeTernaryOpaque::default(); + let res = TypeTernaryOpaque::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } - let dif = r.dif(&reader, Some(&r)).unwrap(); + let dif = r.dif(&reader).unwrap(); assert_eq!(*dif.as_ref().unwrap().s1(), "foo"); assert_eq!(*dif.as_ref().unwrap().s2(), "bar"); assert_eq!(*dif.as_ref().unwrap().s3(), "|baz@"); diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index 0f3dc08ce..42a81df71 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -9,12 +9,15 @@ use formats::cast_to_imported::*; fn test_cast_to_imported() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = CastToImported::default(); + let res = CastToImported::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*(*(*r.one()).as_ref().unwrap()).one(), 80); - assert_eq!(*(*(*r.one_casted(&reader, Some(&r)).unwrap()).as_ref().unwrap()).one(), 80); + assert_eq!(*(*(*r.one_casted(&reader).unwrap()).as_ref().unwrap()).one(), 80); } diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index 06b0123ca..63e9db047 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -11,15 +11,18 @@ use formats::imports_circular_b::*; fn test_imports_circular_a() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = ImportsCircularA::default(); + let res = ImportsCircularA::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.code(), 80); assert_eq!(*r.two().as_ref().unwrap().initial(), 65); assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().code(), 67); assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().two().as_ref().unwrap().initial(), 75); - assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().two().as_ref().unwrap().back_ref(), None); + assert_eq!(r.two().as_ref().unwrap().back_ref().as_ref().unwrap().two().as_ref().unwrap().back_ref().is_none(), true); } From d1be9578791d1edec9926a4af5183d9e275e5606 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 27 Dec 2022 21:11:39 +0800 Subject: [PATCH 123/198] tests fixed. --- spec/rust/tests/manual_debug_array_user.rs | 13 ++-- spec/rust/tests/manual_imports_abs_abs.rs | 9 ++- spec/rust/tests/manual_opaque_with_param.rs | 9 ++- spec/rust/tests/manual_params_def.rs | 12 ++-- spec/rust/tests/manual_read_bytes.rs | 13 ++-- spec/rust/tests/manual_str_literals.rs | 23 +++---- spec/rust/tests/manual_str_repeat.rs | 14 ++-- spec/rust/tests/manual_switch_cast.rs | 14 ++-- spec/rust/tests/manual_switch_cast_parent.rs | 13 ++-- spec/rust/tests/manual_test_parent.rs | 14 ++-- spec/rust/tests/manual_to_string_custom.rs | 12 ++-- spec/rust/tests/test_debug_switch_user.rs | 13 ++-- spec/rust/tests/test_enum_for_unknown_id.rs | 9 ++- spec/rust/tests/test_enum_invalid.rs | 9 ++- spec/rust/tests/test_expr_int_div.rs | 17 +++-- spec/rust/tests/test_imports_rel_1.rs | 9 ++- spec/rust/tests/test_instance_std_array.rs | 17 +++-- spec/rust/tests/test_nav_parent_switch.rs | 9 ++- spec/rust/tests/test_optional_id.rs | 13 ++-- spec/rust/tests/test_process_repeat_bytes.rs | 9 ++- spec/rust/tests/test_repeat_eos_struct.rs | 9 ++- spec/rust/tests/test_repeat_n_struct.rs | 9 ++- spec/rust/tests/test_switch_bytearray.rs | 10 +-- spec/rust/tests/test_switch_else_only.rs | 12 ++-- spec/rust/tests/test_switch_manual_enum.rs | 9 ++- .../tests/test_switch_manual_enum_invalid.rs | 9 ++- .../test_switch_manual_enum_invalid_else.rs | 13 ++-- spec/rust/tests/test_switch_manual_int.rs | 10 +-- .../rust/tests/test_switch_manual_int_else.rs | 10 +-- .../rust/tests/test_switch_manual_int_size.rs | 10 +-- .../tests/test_switch_manual_int_size_else.rs | 10 +-- .../tests/test_switch_manual_int_size_eos.rs | 10 +-- spec/rust/tests/test_switch_manual_str.rs | 10 +-- .../rust/tests/test_switch_manual_str_else.rs | 10 +-- spec/rust/tests/test_switch_repeat_expr.rs | 11 ++-- .../tests/test_switch_repeat_expr_invalid.rs | 9 ++- .../rust/tests/test_type_ternary_2nd_falsy.rs | 31 +++++---- translator/project/build.properties | 2 +- .../specgenerators/RustSG.scala | 65 ++++++++++++++----- 39 files changed, 316 insertions(+), 194 deletions(-) diff --git a/spec/rust/tests/manual_debug_array_user.rs b/spec/rust/tests/manual_debug_array_user.rs index 2e96a2893..fe75ba127 100644 --- a/spec/rust/tests/manual_debug_array_user.rs +++ b/spec/rust/tests/manual_debug_array_user.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::debug_array_user::*; fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = DebugArrayUser::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - assert!(res.is_ok()); + let res = DebugArrayUser::read_into(&reader, None, None); + let r : Rc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.one_cat().meow(), 0x50); diff --git a/spec/rust/tests/manual_imports_abs_abs.rs b/spec/rust/tests/manual_imports_abs_abs.rs index 46ae708f4..5ceadc4fb 100644 --- a/spec/rust/tests/manual_imports_abs_abs.rs +++ b/spec/rust/tests/manual_imports_abs_abs.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::imports_abs_abs::*; fn test_params_def() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = ImportsAbsAbs::default(); + let res = ImportsAbsAbs::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.one(), 80); diff --git a/spec/rust/tests/manual_opaque_with_param.rs b/spec/rust/tests/manual_opaque_with_param.rs index 042a2f408..3df99f26f 100644 --- a/spec/rust/tests/manual_opaque_with_param.rs +++ b/spec/rust/tests/manual_opaque_with_param.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::opaque_with_param::*; fn test_params_def() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = OpaqueWithParam::default(); + let res = OpaqueWithParam::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } let one = r.one(); diff --git a/spec/rust/tests/manual_params_def.rs b/spec/rust/tests/manual_params_def.rs index 0cc8a1920..3db150c39 100644 --- a/spec/rust/tests/manual_params_def.rs +++ b/spec/rust/tests/manual_params_def.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,12 +10,14 @@ use formats::params_def::*; fn test_params_def() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = ParamsDef::default(); + let f = |t: &mut ParamsDef| t.set_params(5, true); + let res = ParamsDef::read_into_with_init(&reader, None, None, &f); + let r : Rc; - r.set_params(5, true); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.buf(), "foo|b"); diff --git a/spec/rust/tests/manual_read_bytes.rs b/spec/rust/tests/manual_read_bytes.rs index b6d3cf0a4..05896e47e 100644 --- a/spec/rust/tests/manual_read_bytes.rs +++ b/spec/rust/tests/manual_read_bytes.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,12 +10,13 @@ use formats::read_bytes::*; fn basic_parse() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let reader = BytesReader::new(&bytes); + let res = ReadBytes::read_into(&reader, None, None); + let r : Rc; - let mut r = ReadBytes::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - println!("{:?}", res); - assert!(res.is_ok()); + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(1, *r.len()); diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/manual_str_literals.rs index 87082aafa..d43d63276 100644 --- a/spec/rust/tests/manual_str_literals.rs +++ b/spec/rust/tests/manual_str_literals.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,26 +10,27 @@ use formats::str_literals::*; fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); + let res = StrLiterals::read_into(&reader, None, None); + let r : Rc; - let mut r = StrLiterals::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - println!("{:?}", res); - assert!(res.is_ok()); + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } - let backslashes = r.backslashes(&reader, Some(&r)).unwrap(); + let backslashes = r.backslashes(&reader).unwrap(); assert_eq!("\u{005c}\u{005c}\u{005c}", *backslashes); - let octal_eatup = r.octal_eatup(&reader, Some(&r)).unwrap(); + let octal_eatup = r.octal_eatup(&reader).unwrap(); assert_eq!("\u{0}\u{0032}\u{0032}", *octal_eatup); - let octal_eatup2 = r.octal_eatup2(&reader, Some(&r)).unwrap(); + let octal_eatup2 = r.octal_eatup2(&reader).unwrap(); assert_eq!("\u{2}\u{32}", *octal_eatup2); - let double_quotes = r.double_quotes(&reader, Some(&r)).unwrap(); + let double_quotes = r.double_quotes(&reader).unwrap(); assert_eq!("\u{22}\u{22}\u{22}", *double_quotes); - let complex_str = r.complex_str(&reader, Some(&r)).unwrap(); + let complex_str = r.complex_str(&reader).unwrap(); assert_eq!("\u{0}\u{1}\u{2}\u{7}\u{8}\u{0a}\u{0d}\u{09}\u{0b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}", *complex_str); } \ No newline at end of file diff --git a/spec/rust/tests/manual_str_repeat.rs b/spec/rust/tests/manual_str_repeat.rs index aeb6d85ed..0d3789223 100644 --- a/spec/rust/tests/manual_str_repeat.rs +++ b/spec/rust/tests/manual_str_repeat.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::str_repeat::*; fn basic_parse() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = StrRepeat::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - println!("{:?}", res); - assert!(res.is_ok()); + let res = StrRepeat::read_into(&reader, None, None); + let r : Rc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!("foo|", r.entries()[0]); diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index f4baaea5a..e7bafb217 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -11,11 +11,13 @@ fn basic_parse() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchCast::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - println!("{:?}", res); - assert!(res.is_ok()); + let res = SwitchCast::read_into(&reader, None, None); + let r : Rc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.opcodes().len()); diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs index 30754a670..26b199e4a 100644 --- a/spec/rust/tests/manual_switch_cast_parent.rs +++ b/spec/rust/tests/manual_switch_cast_parent.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,12 +10,13 @@ use formats::switch_cast_parent::*; fn basic_parse() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let reader = BytesReader::new(&bytes); + let res = SwitchCastParent::read_into(&reader, None, None); + let r : Rc; - let mut r = SwitchCastParent::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - println!("{:?}", res); - assert!(res.is_ok()); + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.opcodes().len()); diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs index 723ad3f76..2c2cc6aa9 100644 --- a/spec/rust/tests/manual_test_parent.rs +++ b/spec/rust/tests/manual_test_parent.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::test_parent::*; fn basic_parse() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = TestParent::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - println!("{:?}", res); - assert!(res.is_ok()); + let res = TestParent::read_into(&reader, None, None); + let r : Rc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(1, *r.root_byte()); diff --git a/spec/rust/tests/manual_to_string_custom.rs b/spec/rust/tests/manual_to_string_custom.rs index 1c9bc0893..1d56a92af 100644 --- a/spec/rust/tests/manual_to_string_custom.rs +++ b/spec/rust/tests/manual_to_string_custom.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::to_string_custom::*; fn basic_parse() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); + let res = ToStringCustom::read_into(&reader, None, None); + let r : Rc; - let mut r = ToStringCustom::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - assert!(res.is_ok()); + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(r.to_string(), "s1 = foo, s2 = bar"); diff --git a/spec/rust/tests/test_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs index 51c5afe5d..dd17fb557 100644 --- a/spec/rust/tests/test_debug_switch_user.rs +++ b/spec/rust/tests/test_debug_switch_user.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::debug_switch_user::*; fn basic_parse() { let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = DebugSwitchUser::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - assert!(res.is_ok()); + let res = DebugSwitchUser::read_into(&reader, None, None); + let r : Rc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.code(), 1); diff --git a/spec/rust/tests/test_enum_for_unknown_id.rs b/spec/rust/tests/test_enum_for_unknown_id.rs index bae46909b..cdbd0f900 100644 --- a/spec/rust/tests/test_enum_for_unknown_id.rs +++ b/spec/rust/tests/test_enum_for_unknown_id.rs @@ -1,6 +1,6 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -12,10 +12,13 @@ use formats::enum_for_unknown_id::*; fn test_enum_for_unknown_id() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = EnumForUnknownId::default(); + let res = EnumForUnknownId::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } let i : i64 = r.one().into(); diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs index 2aff3493d..a2eeee854 100644 --- a/spec/rust/tests/test_enum_invalid.rs +++ b/spec/rust/tests/test_enum_invalid.rs @@ -1,6 +1,6 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -12,10 +12,13 @@ use formats::enum_invalid::*; fn test_enum_invalid() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = EnumInvalid::default(); + let res = EnumInvalid::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index 3bc788cdc..9222f33ec 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -9,16 +9,19 @@ use formats::expr_int_div::*; fn test_expr_int_div() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = ExprIntDiv::default(); + let res = ExprIntDiv::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.int_u(), 1262698832); assert_eq!(*r.int_s(), -52947); - assert_eq!(*r.div_pos_const(&reader, Some(&r)).unwrap(), 756); - assert_eq!(*r.div_neg_const(&reader, Some(&r)).unwrap(), -756); - assert_eq!(*r.div_pos_seq(&reader, Some(&r)).unwrap(), 97130679); - assert_eq!(*r.div_neg_seq(&reader, Some(&r)).unwrap(), -4072); + assert_eq!(*r.div_pos_const(&reader).unwrap(), 756); + assert_eq!(*r.div_neg_const(&reader).unwrap(), -756); + assert_eq!(*r.div_pos_seq(&reader).unwrap(), 97130679); + assert_eq!(*r.div_neg_seq(&reader).unwrap(), -4072); } diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs index c9b085f6e..c652a5e0e 100644 --- a/spec/rust/tests/test_imports_rel_1.rs +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -12,10 +12,13 @@ use formats::imported_2::*; fn test_imports_rel_1() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = ImportsRel1::default(); + let res = ImportsRel1::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.one(), 80); diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs index 91b34866c..ecd6137b4 100644 --- a/spec/rust/tests/test_instance_std_array.rs +++ b/spec/rust/tests/test_instance_std_array.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,17 +10,20 @@ use formats::instance_std_array::*; fn test_instance_std_array() { let bytes = fs::read("../../src/instance_std_array.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = InstanceStdArray::default(); + let res = InstanceStdArray::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.ofs(), 16); assert_eq!(*r.qty_entries(), 3); assert_eq!(*r.entry_size(), 4); - assert_eq!(r.entries(&reader, Some(&r)).unwrap().len(), 3); - assert_eq!(r.entries(&reader, Some(&r)).unwrap()[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); - assert_eq!(r.entries(&reader, Some(&r)).unwrap()[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); - assert_eq!(r.entries(&reader, Some(&r)).unwrap()[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); + assert_eq!(r.entries(&reader).unwrap().len(), 3); + assert_eq!(r.entries(&reader).unwrap()[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); + assert_eq!(r.entries(&reader).unwrap()[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); + assert_eq!(r.entries(&reader).unwrap()[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); } diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs index a28dffed1..8e7330281 100644 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -1,6 +1,6 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -12,10 +12,13 @@ use formats::nav_parent_switch::*; fn test_nav_parent_switch() { let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = NavParentSwitch::default(); + let res = NavParentSwitch::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.category(), 1); diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs index eb5c77ef0..ef2b28d7f 100644 --- a/spec/rust/tests/test_optional_id.rs +++ b/spec/rust/tests/test_optional_id.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,12 +10,13 @@ use formats::optional_id::*; fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); + let res = OptionalId::read_into(&reader, None, None); + let r : Rc; - let mut r = OptionalId::default(); - { - let res = r.read(&reader, None, Some(KStructUnit::parent_stack())); - println!("{:?}", res); - assert!(res.is_ok()); + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.unnamed0(), 80); diff --git a/spec/rust/tests/test_process_repeat_bytes.rs b/spec/rust/tests/test_process_repeat_bytes.rs index ff96c3b3c..b9373b255 100644 --- a/spec/rust/tests/test_process_repeat_bytes.rs +++ b/spec/rust/tests/test_process_repeat_bytes.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::process_repeat_bytes::*; fn test_process_repeat_bytes() { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = ProcessRepeatBytes::default(); + let res = ProcessRepeatBytes::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(r.bufs()[0 as usize], vec![0x72u8, 0x25u8, 0x3du8, 0x8au8, 0x14u8]); diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index 3236ba56e..f23fe7d57 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::repeat_eos_struct::*; fn test_repeat_eos_struct() { let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = RepeatEosStruct::default(); + let res = RepeatEosStruct::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(r.chunks().len(), 2); diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index a8f9a49c3..d1ac4f207 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::repeat_n_struct::*; fn test_repeat_n_struct() { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = RepeatNStruct::default(); + let res = RepeatNStruct::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(r.chunks().len(), 2); diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index de8c6027c..06ef51429 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_bytearray::*; fn test_switch_bytearray() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchBytearray::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchBytearray::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.opcodes().len()); diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs index 820c31621..51eabaa3a 100644 --- a/spec/rust/tests/test_switch_else_only.rs +++ b/spec/rust/tests/test_switch_else_only.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,15 +10,17 @@ use formats::switch_else_only::*; fn test_switch_else_only() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchElseOnly::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchElseOnly::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(83, *r.opcode()); let SwitchElseOnly_PrimByte::S1(v) = r.prim_byte_enum(); - assert_eq!(102, *v); + assert_eq!(102, v); let SwitchElseOnly_Ut::SwitchElseOnly_Data(d) = r.ut(); assert_eq!(vec![0x72, 0x00, 0x49, 0x42], *d.value()); diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index 33729b173..b627dfeab 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -1,6 +1,6 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -12,10 +12,13 @@ use formats::switch_manual_enum::*; fn test_switch_manual_enum() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualEnum::default(); + let res = SwitchManualEnum::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(r.opcodes().len(), 4); diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 78905520a..31b27b957 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::switch_manual_enum_invalid::*; fn test_switch_manual_enum_invalid() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualEnumInvalid::default(); + let res = SwitchManualEnumInvalid::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(r.opcodes().len(), 2); diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index 8d0e917e1..25aa26d0b 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,24 +10,27 @@ use formats::switch_manual_enum_invalid_else::*; fn test_switch_manual_enum_invalid_else() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualEnumInvalidElse::default(); + let res = SwitchManualEnumInvalidElse::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(r.opcodes().len(), 2); let n : i64 = r.opcodes()[0 as usize].code().into(); assert_eq!(n, 255); if let SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s) = r.opcodes()[0].body() { - assert_eq!(*s.value(&reader, Some(&r)).unwrap(), 123); + assert_eq!(*s.value(&reader).unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); } let n : i64 = r.opcodes()[1 as usize].code().into(); assert_eq!(n, 1); if let SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s) = r.opcodes()[1].body() { - assert_eq!(*s.value(&reader, Some(&r)).unwrap(), 123); + assert_eq!(*s.value(&reader).unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index ac7a31904..afdd08fb1 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_manual_int::*; fn test_switch_manual_int() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualInt::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchManualInt::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(83, *r.opcodes()[0].code()); if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes()[0].body() { diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index 8806ab574..b120b276e 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_manual_int_else::*; fn test_switch_manual_int_else() { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualIntElse::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchManualIntElse::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.opcodes().len()); diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index f3599bf32..26db4809f 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_manual_int_size::*; fn test_switch_manual_int_size() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualIntSize::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchManualIntSize::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.chunks().len()); diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index 1f2cd9b4d..ba8d820f8 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_manual_int_size_else::*; fn test_switch_manual_int_size_else() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualIntSizeElse::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchManualIntSizeElse::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.chunks().len()); diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 042ae9c91..0faa9584c 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_manual_int_size_eos::*; fn test_switch_manual_int_size_eos() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualIntSizeEos::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchManualIntSizeEos::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.chunks().len()); diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 985bf1c51..8e1da4f7c 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_manual_str::*; fn test_switch_manual_str() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualStr::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchManualStr::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.opcodes().len()); diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index e2edf7a0f..e1cf3a10b 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,11 +10,13 @@ use formats::switch_manual_str_else::*; fn test_switch_manual_str_else() { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchManualStrElse::default(); - - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + let res = SwitchManualStrElse::read_into(&reader, None, None); + let r : Rc; + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(4, r.opcodes().len()); diff --git a/spec/rust/tests/test_switch_repeat_expr.rs b/spec/rust/tests/test_switch_repeat_expr.rs index 26f7359a6..db3cf2c21 100644 --- a/spec/rust/tests/test_switch_repeat_expr.rs +++ b/spec/rust/tests/test_switch_repeat_expr.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,17 +10,20 @@ use formats::switch_repeat_expr::*; fn test_switch_repeat_expr() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchRepeatExpr::default(); + let res = SwitchRepeatExpr::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.code(), 17); assert_eq!(*r.size(), 9); if let SwitchRepeatExpr_Body::SwitchRepeatExpr_One(b) = &r.body()[0 as usize] { - assert_eq!(b.first(), &vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); + assert_eq!(*b.first(), vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); } else { panic!("expected enum SwitchRepeatExpr_Body"); } diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs index cb4e45787..561f4413b 100644 --- a/spec/rust/tests/test_switch_repeat_expr_invalid.rs +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,10 +10,13 @@ use formats::switch_repeat_expr_invalid::*; fn test_switch_repeat_expr_invalid() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = SwitchRepeatExprInvalid::default(); + let res = SwitchRepeatExprInvalid::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } assert_eq!(*r.code(), 17); diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index 347fcdece..be1b9400d 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -1,4 +1,4 @@ -use std::fs; +use std::{fs, rc::Rc}; extern crate kaitai; use self::kaitai::*; @@ -10,23 +10,26 @@ use formats::type_ternary_2nd_falsy::*; fn test_type_ternary_2nd_falsy() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let reader = BytesReader::new(&bytes); - let mut r = TypeTernary2ndFalsy::default(); + let res = TypeTernary2ndFalsy::read_into(&reader, None, None); + let r : Rc; - if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) { + if let Err(err) = res { panic!("{:?}", err); + } else { + r = res.unwrap(); } - assert_eq!(*r.v_false(&reader, Some(&r)).unwrap(), false); - assert_eq!(*r.v_int_zero(&reader, Some(&r)).unwrap(), 0); - assert_eq!(*r.v_int_neg_zero(&reader, Some(&r)).unwrap(), 0); - assert_eq!(*r.v_float_zero(&reader, Some(&r)).unwrap(), 0.0); - assert_eq!(*r.v_float_neg_zero(&reader, Some(&r)).unwrap(), -0.0); - assert_eq!(*r.v_str_w_zero(&reader, Some(&r)).unwrap(), "0"); - assert_eq!(r.v_str_w_zero(&reader, Some(&r)).unwrap().len(), 1); + assert_eq!(*r.v_false(&reader).unwrap(), false); + assert_eq!(*r.v_int_zero(&reader).unwrap(), 0); + assert_eq!(*r.v_int_neg_zero(&reader).unwrap(), 0); + assert_eq!(*r.v_float_zero(&reader).unwrap(), 0.0); + assert_eq!(*r.v_float_neg_zero(&reader).unwrap(), -0.0); + assert_eq!(*r.v_str_w_zero(&reader).unwrap(), "0"); + assert_eq!(r.v_str_w_zero(&reader).unwrap().len(), 1); assert_eq!(*r.ut().m(), 7); - assert_eq!(*r.v_null_ut(&reader, Some(&r)).unwrap().m(), 0); - assert_eq!(*r.v_str_empty(&reader, Some(&r)).unwrap(), ""); - assert_eq!(r.v_str_empty(&reader, Some(&r)).unwrap().len(), 0); + assert_eq!(*r.v_null_ut(&reader).unwrap().m(), 0); + assert_eq!(*r.v_str_empty(&reader).unwrap(), ""); + assert_eq!(r.v_str_empty(&reader).unwrap().len(), 0); assert_eq!(r.int_array().len(), 2); - assert_eq!(r.v_int_array_empty(&reader, Some(&r)).unwrap().len(), 0); + assert_eq!(r.v_int_array_empty(&reader).unwrap().len(), 0); } diff --git a/translator/project/build.properties b/translator/project/build.properties index dc8f331cc..8b9a0b0ab 100644 --- a/translator/project/build.properties +++ b/translator/project/build.properties @@ -1 +1 @@ -sbt.version = 1.4.3 +sbt.version=1.8.0 diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index e0f19f748..9ffe2a9bd 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -14,6 +14,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) var do_panic = true + var do_not_deref = false override def fileName(name: String): String = s"test_$name.rs" @@ -26,7 +27,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs spec.extraImports.foreach{ name => imports = s"$imports\n${use_mod}formats::$name::*;" } val code = - s"""|use std::fs; + s"""|use std::{fs, rc::Rc}; | |extern crate kaitai; |use self::kaitai::*; @@ -38,9 +39,10 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs |fn test_${spec.id}() { | let bytes = fs::read("../../src/${spec.data}").unwrap(); | let reader = BytesReader::new(&bytes); - | let mut r = $className::default(); + | let res = $className::read_into(&reader, None, None); + | let r : Rc<$className>; | - | if let Err(err) = r.read(&reader, None, Some(KStructUnit::parent_stack())) {""".stripMargin + | if let Err(err) = res {""".stripMargin out.puts(code) out.inc } @@ -53,6 +55,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val code = s""" println!("expected err: {:?}, exception: $exception", err); | } else { + | r = res.unwrap(); // need here to help Rust with type decision | panic!("no expected exception: $exception"); | }""".stripMargin out.puts(code) @@ -64,6 +67,10 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs out.inc out.puts("panic!(\"{:?}\", err);") out.dec + out.puts("} else {") + out.inc + out.puts("r = res.unwrap();") + out.dec out.puts("}") do_panic = false } @@ -73,6 +80,18 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs out.puts("}") } + def correctIO(code: String): String = { + var s = if (!do_not_deref) { + if (code.contains("_io,") && (code.charAt(0) != '*')) s"*$code" else code + } else { + code + } + + s = s.replace("_io", "&reader") + s = s.replace(")?", ").expect(\"error reading\")") + s + } + override def simpleAssert(check: TestAssert): Unit = { val actType = translator.detectType(check.actual) var actStr = translateAct(check.actual) @@ -94,13 +113,13 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } finish_panic() //TODO: correct code generation - actStr = actStr.replace("_io", "reader") - actStr = actStr.replace("(reader)?", "(&reader).expect(\"error reading\")") + actStr = correctIO(actStr) + out.puts(s"assert_eq!($actStr, $expStr);") } override def nullAssert(actual: Ast.expr): Unit = { - val actStr = translateAct(actual) + val actStr = correctIO(translateAct(actual)) finish_panic() out.puts(s"assert_eq!($actStr, 0);") // TODO: Figure out what's meant to happen here @@ -127,16 +146,16 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs dots.drop(1).foreach { attr_full => last_full = attr_full - val ind = attr_full indexOf "()" + val ind = attr_full indexOf "(" if (ind > 0) { val attr = attr_full.substring(0, ind) last = attr - val found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), attr) - if (found.isDefined) { - ttx2 = s"$ttx2.$attr(&reader, Some(&r)).unwrap()${attr_full.substring(ind + 2, attr_full.length())}" - } else { + val found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), attr) + if (found.isDefined) { + ttx2 = s"$ttx2.$attr(&reader).unwrap()${attr_full.substring(ind + 2, attr_full.length())}" + } else { ttx2 = s"$ttx2.$attr_full" - } + } } else { ttx2 = s"$ttx2.$attr_full" } @@ -146,19 +165,33 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs var deref = true if (last == "len" || last_full.contains("[")) { deref = false + do_not_deref = true } else { val found = translator.get_attr(translator.get_top_class(classSpecs.firstSpec), last) if (found.isDefined) { deref = found.get.dataTypeComposite match { case _: SwitchType => false - case _: UserType => false - case _: BytesType => false + case _: EnumType => false + // case _: UserType => false + // case _: BytesType => false case _ => true } } else if (translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { - deref = true + deref = found.get.dataTypeComposite match { + case _: SwitchType => false + case _: EnumType => false + // case _: UserType => false + // case _: BytesType => false + case _ => true + } } else if (translator.get_param(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { - deref = true + deref = found.get.dataTypeComposite match { + case _: SwitchType => false + case _: EnumType => false + // case _: UserType => false + // case _: BytesType => false + case _ => true + } } else { deref = false } From 2cf0d5d3eaa11899ab2121defcb5c739ea739736 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 27 Dec 2022 21:23:03 +0800 Subject: [PATCH 124/198] fix need_deref func. --- .../tests/test_switch_manual_int_size_else.rs | 4 +- .../specgenerators/RustSG.scala | 42 +++++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index ba8d820f8..2cb76d40c 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -22,8 +22,8 @@ fn test_switch_manual_int_size_else() { assert_eq!(17, *r.chunks()[0].code()); if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkMeta(s) = r.chunks()[0].body() { - assert_eq!("Stuff", s.title()); - assert_eq!("Me", s.author()); + assert_eq!("Stuff", *s.title()); + assert_eq!("Me", *s.author()); } else { panic!("expected enum SwitchManualIntSizeElse_Chunk_ChunkMeta"); } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 9ffe2a9bd..f3504b9cf 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -167,7 +167,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs deref = false do_not_deref = true } else { - val found = translator.get_attr(translator.get_top_class(classSpecs.firstSpec), last) + var found = translator.get_attr(translator.get_top_class(classSpecs.firstSpec), last) if (found.isDefined) { deref = found.get.dataTypeComposite match { case _: SwitchType => false @@ -176,24 +176,30 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs // case _: BytesType => false case _ => true } - } else if (translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { - deref = found.get.dataTypeComposite match { - case _: SwitchType => false - case _: EnumType => false - // case _: UserType => false - // case _: BytesType => false - case _ => true - } - } else if (translator.get_param(translator.get_top_class(classSpecs.firstSpec), last).isDefined) { - deref = found.get.dataTypeComposite match { - case _: SwitchType => false - case _: EnumType => false - // case _: UserType => false - // case _: BytesType => false - case _ => true - } } else { - deref = false + found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last) + if (found.isDefined) { + deref = found.get.dataTypeComposite match { + case _: SwitchType => false + case _: EnumType => false + // case _: UserType => false + // case _: BytesType => false + case _ => true + } + } else { + found = translator.get_param(translator.get_top_class(classSpecs.firstSpec), last) + if (found.isDefined) { + deref = found.get.dataTypeComposite match { + case _: SwitchType => false + case _: EnumType => false + // case _: UserType => false + // case _: BytesType => false + case _ => true + } + } else { + deref = false + } + } } } if (deref) { From 56f3c5757faa360dd745ae910a94f07e4552ad60 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 31 Dec 2022 16:55:33 +0800 Subject: [PATCH 125/198] test generation fixed. --- .../testtranslator/specgenerators/RustSG.scala | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index f3504b9cf..d42c5c051 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -103,7 +103,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => - out.puts(s"let n : i64 = ${translator.remove_deref(actStr)}.into();") + out.puts(s"let n : i64 = (&$actStr).into();") actStr = s"n" case _ => } @@ -170,8 +170,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs var found = translator.get_attr(translator.get_top_class(classSpecs.firstSpec), last) if (found.isDefined) { deref = found.get.dataTypeComposite match { - case _: SwitchType => false - case _: EnumType => false + // case _: SwitchType => false + // case _: EnumType => false // case _: UserType => false // case _: BytesType => false case _ => true @@ -180,8 +180,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last) if (found.isDefined) { deref = found.get.dataTypeComposite match { - case _: SwitchType => false - case _: EnumType => false + // case _: SwitchType => false + // case _: EnumType => false // case _: UserType => false // case _: BytesType => false case _ => true @@ -190,8 +190,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs found = translator.get_param(translator.get_top_class(classSpecs.firstSpec), last) if (found.isDefined) { deref = found.get.dataTypeComposite match { - case _: SwitchType => false - case _: EnumType => false + // case _: SwitchType => false + // case _: EnumType => false // case _: UserType => false // case _: BytesType => false case _ => true From 0af9ee1e49e01c8bf9c09b225e8c9e7de5b1b881 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 4 Jan 2023 14:59:47 +0800 Subject: [PATCH 126/198] tests updated. --- spec/rust/tests/manual_params_def.rs | 2 +- spec/rust/tests/manual_switch_cast.rs | 14 +++++----- spec/rust/tests/manual_switch_cast_parent.rs | 14 +++++----- spec/rust/tests/test_debug_switch_user.rs | 4 +-- spec/rust/tests/test_enum_for_unknown_id.rs | 26 ------------------- spec/rust/tests/test_enum_invalid.rs | 2 +- spec/rust/tests/test_nav_parent_switch.rs | 10 ++++--- spec/rust/tests/test_switch_bytearray.rs | 14 +++++----- spec/rust/tests/test_switch_else_only.rs | 9 ++++--- spec/rust/tests/test_switch_manual_enum.rs | 10 +++---- .../tests/test_switch_manual_enum_invalid.rs | 4 +-- .../test_switch_manual_enum_invalid_else.rs | 12 ++++----- spec/rust/tests/test_switch_manual_int.rs | 12 ++++----- .../rust/tests/test_switch_manual_int_else.rs | 10 +++---- .../rust/tests/test_switch_manual_int_size.rs | 14 +++++----- .../tests/test_switch_manual_int_size_else.rs | 10 +++---- .../tests/test_switch_manual_int_size_eos.rs | 14 +++++----- spec/rust/tests/test_switch_manual_str.rs | 18 ++++++------- .../rust/tests/test_switch_manual_str_else.rs | 20 +++++++------- spec/rust/tests/test_switch_repeat_expr.rs | 4 +-- .../tests/test_switch_repeat_expr_invalid.rs | 4 +-- 21 files changed, 104 insertions(+), 123 deletions(-) delete mode 100644 spec/rust/tests/test_enum_for_unknown_id.rs diff --git a/spec/rust/tests/manual_params_def.rs b/spec/rust/tests/manual_params_def.rs index 3db150c39..0fa6697e7 100644 --- a/spec/rust/tests/manual_params_def.rs +++ b/spec/rust/tests/manual_params_def.rs @@ -10,7 +10,7 @@ use formats::params_def::*; fn test_params_def() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let reader = BytesReader::new(&bytes); - let f = |t: &mut ParamsDef| t.set_params(5, true); + let f = |t: &mut ParamsDef| Ok(t.set_params(5, true)); let res = ParamsDef::read_into_with_init(&reader, None, None, &f); let r : Rc; diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index e7bafb217..f154db02b 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -23,30 +23,30 @@ fn basic_parse() { assert_eq!(4, r.opcodes().len()); assert_eq!(0x53, *r.opcodes()[0].code()); - if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes()[0].body() { - assert_eq!("foobar", s.value()); + if let Some(SwitchCast_Opcode_Body::SwitchCast_Strval(s)) = r.opcodes()[0].body().as_ref() { + assert_eq!("foobar", *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); } assert_eq!(0x49, *r.opcodes()[1].code()); - if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes()[1].body() { + if let Some(SwitchCast_Opcode_Body::SwitchCast_Intval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } assert_eq!(0x49, *r.opcodes()[2].code()); - if let SwitchCast_Opcode_Body::SwitchCast_Intval(s) = r.opcodes()[2].body() { + if let Some(SwitchCast_Opcode_Body::SwitchCast_Intval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } assert_eq!(0x53, *r.opcodes()[3].code()); - if let SwitchCast_Opcode_Body::SwitchCast_Strval(s) = r.opcodes()[3].body() { - assert_eq!("", s.value()); + if let Some(SwitchCast_Opcode_Body::SwitchCast_Strval(s)) = r.opcodes()[3].body().as_ref() { + assert_eq!("", *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); - } + }; } \ No newline at end of file diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs index 26b199e4a..0299e80d3 100644 --- a/spec/rust/tests/manual_switch_cast_parent.rs +++ b/spec/rust/tests/manual_switch_cast_parent.rs @@ -22,30 +22,30 @@ fn basic_parse() { assert_eq!(4, r.opcodes().len()); assert_eq!(0x53, *r.opcodes()[0].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes()[0].body() { - assert_eq!("foobar", s.value()); + if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { + assert_eq!("foobar", *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); } assert_eq!(0x49, *r.opcodes()[1].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes()[1].body() { + if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } assert_eq!(0x49, *r.opcodes()[2].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s) = r.opcodes()[2].body() { + if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Intval"); } assert_eq!(0x53, *r.opcodes()[3].code()); - if let SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s) = r.opcodes()[3].body() { - assert_eq!("", s.value()); + if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { + assert_eq!("", *s.value()); } else { panic!("expected enum SwitchCast_Opcode_Strval"); - } + }; } \ No newline at end of file diff --git a/spec/rust/tests/test_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs index dd17fb557..8cbb7c60f 100644 --- a/spec/rust/tests/test_debug_switch_user.rs +++ b/spec/rust/tests/test_debug_switch_user.rs @@ -20,9 +20,9 @@ fn basic_parse() { } assert_eq!(*r.code(), 1); - if let DebugSwitchUser_Data::DebugSwitchUser_One(s) = r.data() { + if let DebugSwitchUser_Data::DebugSwitchUser_One(s) = r.data().as_ref().unwrap() { assert_eq!(*s.val(), -190); } else { panic!("expected enum DebugSwitchUser_Data"); - } + }; } diff --git a/spec/rust/tests/test_enum_for_unknown_id.rs b/spec/rust/tests/test_enum_for_unknown_id.rs deleted file mode 100644 index cdbd0f900..000000000 --- a/spec/rust/tests/test_enum_for_unknown_id.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::enum_for_unknown_id::*; - - -#[test] -fn test_enum_for_unknown_id() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = EnumForUnknownId::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - let i : i64 = r.one().into(); - assert_eq!(i, 80); -} diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs index a2eeee854..7fccec955 100644 --- a/spec/rust/tests/test_enum_invalid.rs +++ b/spec/rust/tests/test_enum_invalid.rs @@ -22,6 +22,6 @@ fn test_enum_invalid() { } assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); - let i : i64 = r.pet_2().into(); + let i : i64 = (&*r.pet_2()).into(); assert_eq!(i, 111); } diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs index 8e7330281..d47386fd1 100644 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -22,7 +22,11 @@ fn test_nav_parent_switch() { } assert_eq!(*r.category(), 1); - let NavParentSwitch_Content::NavParentSwitch_Element1(s) = r.content(); - assert_eq!(*s.foo(), 66); - assert_eq!(*s.subelement().bar(), 255); + let c = r.content(); + if let Some(NavParentSwitch_Content::NavParentSwitch_Element1(s)) = c.as_ref() { + assert_eq!(*s.foo(), 66); + assert_eq!(*s.subelement().bar(), 255); + } else { + panic!("expected value, got {:?}", *c); + } } diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index 06ef51429..fa56ce4cc 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -21,30 +21,30 @@ fn test_switch_bytearray() { assert_eq!(4, r.opcodes().len()); assert_eq!(vec![0x53], *r.opcodes()[0].code()); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes()[0].body() { - assert_eq!("foobar", s.value()); + if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { + assert_eq!("foobar", *s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Strval"); } assert_eq!(vec![0x49], *r.opcodes()[1].code()); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes()[1].body() { + if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Intval"); } assert_eq!(vec![0x49], *r.opcodes()[2].code()); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s) = r.opcodes()[2].body() { + if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Intval"); } assert_eq!(vec![0x53], *r.opcodes()[3].code()); - if let SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s) = r.opcodes()[3].body() { - assert_eq!("", s.value()); + if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { + assert_eq!("", *s.value()); } else { panic!("expected enum SwitchBytearray_Opcode_Strval"); - } + }; } diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs index 51eabaa3a..8d2fd859f 100644 --- a/spec/rust/tests/test_switch_else_only.rs +++ b/spec/rust/tests/test_switch_else_only.rs @@ -19,9 +19,12 @@ fn test_switch_else_only() { r = res.unwrap(); } assert_eq!(83, *r.opcode()); - let SwitchElseOnly_PrimByte::S1(v) = r.prim_byte_enum(); + let SwitchElseOnly_PrimByte::S1(v) = *r.prim_byte_enum().as_ref().unwrap(); assert_eq!(102, v); - let SwitchElseOnly_Ut::SwitchElseOnly_Data(d) = r.ut(); - assert_eq!(vec![0x72, 0x00, 0x49, 0x42], *d.value()); + if let Some(SwitchElseOnly_Ut::SwitchElseOnly_Data(d)) = (*r.ut()).clone() { + assert_eq!(vec![0x72, 0x00, 0x49, 0x42], *d.value()); + } else { + panic!("expected enum SwitchElseOnly_Ut::SwitchElseOnly_Data"); + }; } diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index b627dfeab..fc884546d 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -24,30 +24,30 @@ fn test_switch_manual_enum() { assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); - if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s) = r.opcodes()[0].body() { + if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { assert_eq!(*s.value(), "foobar"); } else { panic!("expected enum SwitchManualEnum_Opcode_Strval"); } assert_eq!(*r.opcodes()[1 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); - if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s) = r.opcodes()[1].body() { + if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(*s.value(), 66); } else { panic!("expected enum SwitchManualEnum_Opcode_Intval"); } assert_eq!(*r.opcodes()[2 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); - if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s) = r.opcodes()[2].body() { + if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(*s.value(), 55); } else { panic!("expected enum SwitchManualEnum_Opcode_Intval"); } assert_eq!(*r.opcodes()[3 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); - if let SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s) = r.opcodes()[3].body() { + if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { assert_eq!(*s.value(), ""); } else { panic!("expected enum SwitchManualEnum_Opcode_Strval"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 31b27b957..9fde1e22a 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -20,11 +20,11 @@ fn test_switch_manual_enum_invalid() { } assert_eq!(r.opcodes().len(), 2); - let n : i64 = r.opcodes()[0 as usize].code().into(); + let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); // body is None //assert_eq!(r.opcodes()[0 as usize].body(), 0); - let n : i64 = r.opcodes()[1 as usize].code().into(); + let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); // body is None //assert_eq!(r.opcodes()[1 as usize].body(), 0); diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index 25aa26d0b..be3bd5c8c 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -20,18 +20,18 @@ fn test_switch_manual_enum_invalid_else() { } assert_eq!(r.opcodes().len(), 2); - let n : i64 = r.opcodes()[0 as usize].code().into(); + let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); - if let SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s) = r.opcodes()[0].body() { + if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[0].body().as_ref() { assert_eq!(*s.value(&reader).unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); - } - let n : i64 = r.opcodes()[1 as usize].code().into(); + }; + let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); - if let SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s) = r.opcodes()[1].body() { + if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(*s.value(&reader).unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index afdd08fb1..7deed57f5 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -19,30 +19,30 @@ fn test_switch_manual_int() { r = res.unwrap(); } assert_eq!(83, *r.opcodes()[0].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes()[0].body() { - assert_eq!("foobar", s.value()); + if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { + assert_eq!("foobar", *s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); } assert_eq!(73, *r.opcodes()[1].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes()[1].body() { + if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); } assert_eq!(73, *r.opcodes()[2].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s) = r.opcodes()[2].body() { + if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); } assert_eq!(83, *r.opcodes()[3].code()); - if let SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s) = r.opcodes()[3].body() { + if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { assert_eq!("", *s.value()); } else { panic!("expected enum SwitchManualInt_Opcode_Body"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index b120b276e..cd11797b4 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -21,30 +21,30 @@ fn test_switch_manual_int_else() { assert_eq!(4, r.opcodes().len()); assert_eq!(83, *r.opcodes()[0].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Strval(s) = r.opcodes()[0].body() { + if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { assert_eq!("foo", *s.value()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Strval"); } assert_eq!(88, *r.opcodes()[1].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes()[1].body() { + if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(66, *s.filler()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); } assert_eq!(89, *r.opcodes()[2].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s) = r.opcodes()[2].body() { + if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(51966, *s.filler()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); } assert_eq!(73, *r.opcodes()[3].code()); - if let SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Intval(s) = r.opcodes()[3].body() { + if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Intval(s)) = r.opcodes()[3].body().as_ref() { assert_eq!(7, *s.value()); } else { panic!("expected enum SwitchManualIntElse_Opcode_Intval"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index 26db4809f..32a837318 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -21,15 +21,15 @@ fn test_switch_manual_int_size() { assert_eq!(4, r.chunks().len()); assert_eq!(17, *r.chunks()[0].code()); - if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkMeta(s) = r.chunks()[0].body() { - assert_eq!("Stuff", s.title()); - assert_eq!("Me", s.author()); + if let Some(SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkMeta(s)) = r.chunks()[0].body().as_ref() { + assert_eq!("Stuff", *s.title()); + assert_eq!("Me", *s.author()); } else { panic!("expected enum SwitchManualIntSize_Chunk_ChunkMeta"); } assert_eq!(34, *r.chunks()[1].code()); - if let SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkDir(s) = r.chunks()[1].body() { + if let Some(SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkDir(s)) = r.chunks()[1].body().as_ref() { let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); assert_eq!(strings, *s.entries()); } else { @@ -37,7 +37,7 @@ fn test_switch_manual_int_size() { } assert_eq!(51, *r.chunks()[2].code()); - if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks()[2].body() { + if let Some(SwitchManualIntSize_Chunk_Body::Bytes(s)) = r.chunks()[2].body().as_ref() { let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s); } else { @@ -45,10 +45,10 @@ fn test_switch_manual_int_size() { } assert_eq!(255, *r.chunks()[3].code()); - if let SwitchManualIntSize_Chunk_Body::Bytes(s) = r.chunks()[3].body() { + if let Some(SwitchManualIntSize_Chunk_Body::Bytes(s)) = r.chunks()[3].body().as_ref() { let raw : Vec = vec![]; assert_eq!(raw, *s); } else { panic!("expected enum Bytes"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index 2cb76d40c..68b28109d 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -21,7 +21,7 @@ fn test_switch_manual_int_size_else() { assert_eq!(4, r.chunks().len()); assert_eq!(17, *r.chunks()[0].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkMeta(s) = r.chunks()[0].body() { + if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkMeta(s)) = r.chunks()[0].body().as_ref() { assert_eq!("Stuff", *s.title()); assert_eq!("Me", *s.author()); } else { @@ -29,7 +29,7 @@ fn test_switch_manual_int_size_else() { } assert_eq!(34, *r.chunks()[1].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkDir(s) = r.chunks()[1].body() { + if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkDir(s)) = r.chunks()[1].body().as_ref() { let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); assert_eq!(strings, *s.entries()); } else { @@ -37,7 +37,7 @@ fn test_switch_manual_int_size_else() { } assert_eq!(51, *r.chunks()[2].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks()[2].body() { + if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s)) = r.chunks()[2].body().as_ref() { let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s.rest()); } else { @@ -45,10 +45,10 @@ fn test_switch_manual_int_size_else() { } assert_eq!(255, *r.chunks()[3].code()); - if let SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s) = r.chunks()[3].body() { + if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s)) = r.chunks()[3].body().as_ref() { let raw : Vec = vec![]; assert_eq!(raw, *s.rest()); } else { panic!("expected enum SwitchManualIntSizeElse_Chunk_Dummy"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 0faa9584c..741a49f34 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -21,15 +21,15 @@ fn test_switch_manual_int_size_eos() { assert_eq!(4, r.chunks().len()); assert_eq!(17, *r.chunks()[0].code()); - if let SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkMeta(s) = r.chunks()[0].body().body() { - assert_eq!("Stuff", s.title()); - assert_eq!("Me", s.author()); + if let Some(SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkMeta(s)) = r.chunks()[0].body().clone().body().as_ref() { + assert_eq!("Stuff", *s.title()); + assert_eq!("Me", *s.author()); } else { panic!("expected enum SwitchManualIntSizeEos_ChunkBody_ChunkMeta"); - } + }; assert_eq!(34, *r.chunks()[1].code()); - if let SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkDir(s) = r.chunks()[1].body().body() { + if let Some(SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkDir(s)) = r.chunks()[1].body().clone().body().as_ref() { let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); assert_eq!(strings, *s.entries()); } else { @@ -37,7 +37,7 @@ fn test_switch_manual_int_size_eos() { } assert_eq!(51, *r.chunks()[2].code()); - if let SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s) = r.chunks()[2].body().body() { + if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = r.chunks()[2].body().clone().body().as_ref() { let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s); } else { @@ -45,7 +45,7 @@ fn test_switch_manual_int_size_eos() { } assert_eq!(255, *r.chunks()[3].code()); - if let SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s) = r.chunks()[3].body().body() { + if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = r.chunks()[3].body().clone().body().as_ref() { let raw : Vec = vec![]; assert_eq!(raw, *s); } else { diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 8e1da4f7c..60e3eede5 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -20,31 +20,31 @@ fn test_switch_manual_str() { } assert_eq!(4, r.opcodes().len()); - assert_eq!("S", r.opcodes()[0].code()); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes()[0].body() { + assert_eq!("S", *r.opcodes()[0].code()); + if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { assert_eq!("foobar", *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Strval"); } - assert_eq!("I", r.opcodes()[1].code()); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes()[1].body() { + assert_eq!("I", *r.opcodes()[1].code()); + if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(66, *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Intval"); } - assert_eq!("I", r.opcodes()[2].code()); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s) = r.opcodes()[2].body() { + assert_eq!("I", *r.opcodes()[2].code()); + if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(55, *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Intval"); } - assert_eq!("S", r.opcodes()[3].code()); - if let SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s) = r.opcodes()[3].body() { + assert_eq!("S", *r.opcodes()[3].code()); + if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { assert_eq!("", *s.value()); } else { panic!("expected enum SwitchManualStr_Opcode_Strval"); - } + }; } diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index e1cf3a10b..1b0085723 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -20,31 +20,31 @@ fn test_switch_manual_str_else() { } assert_eq!(4, r.opcodes().len()); - assert_eq!("S", r.opcodes()[0].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Strval(s) = r.opcodes()[0].body() { - assert_eq!("foo", s.value()); + assert_eq!("S", *r.opcodes()[0].code()); + if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { + assert_eq!("foo", *s.value()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Strval"); } - assert_eq!("X", r.opcodes()[1].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes()[1].body() { + assert_eq!("X", *r.opcodes()[1].code()); + if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s)) = r.opcodes()[1].body().as_ref() { assert_eq!(66, *s.filler()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); } - assert_eq!("Y", r.opcodes()[2].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s) = r.opcodes()[2].body() { + assert_eq!("Y", *r.opcodes()[2].code()); + if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s)) = r.opcodes()[2].body().as_ref() { assert_eq!(51966, *s.filler()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); } - assert_eq!("I", r.opcodes()[3].code()); - if let SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Intval(s) = r.opcodes()[3].body() { + assert_eq!("I", *r.opcodes()[3].code()); + if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Intval(s)) = r.opcodes()[3].body().as_ref() { assert_eq!(7, *s.value()); } else { panic!("expected enum SwitchManualStrElse_Opcode_Strval"); - } + }; } diff --git a/spec/rust/tests/test_switch_repeat_expr.rs b/spec/rust/tests/test_switch_repeat_expr.rs index db3cf2c21..c392d688f 100644 --- a/spec/rust/tests/test_switch_repeat_expr.rs +++ b/spec/rust/tests/test_switch_repeat_expr.rs @@ -22,9 +22,9 @@ fn test_switch_repeat_expr() { assert_eq!(*r.code(), 17); assert_eq!(*r.size(), 9); - if let SwitchRepeatExpr_Body::SwitchRepeatExpr_One(b) = &r.body()[0 as usize] { + if let SwitchRepeatExpr_Body::SwitchRepeatExpr_One(b) = &r.body()[0 as usize] { assert_eq!(*b.first(), vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); } else { panic!("expected enum SwitchRepeatExpr_Body"); - } + }; } diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs index 561f4413b..ad17eb5aa 100644 --- a/spec/rust/tests/test_switch_repeat_expr_invalid.rs +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -22,9 +22,9 @@ fn test_switch_repeat_expr_invalid() { assert_eq!(*r.code(), 17); assert_eq!(*r.size(), 9); - if let SwitchRepeatExprInvalid_Body::Bytes(b) = &r.body()[0 as usize] { + if let SwitchRepeatExprInvalid_Body::Bytes(b) = &r.body()[0 as usize] { assert_eq!(b, &vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); } else { panic!("expected enum SwitchRepeatExpr_Body"); - } + }; } From 56cd540a373ce78ef7c03a8c2d63823be163ac2b Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 4 Jan 2023 17:54:23 +0800 Subject: [PATCH 127/198] let need_deref do all job. --- .../specgenerators/RustSG.scala | 45 +------------------ 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index d42c5c051..1bb0f4279 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -138,7 +138,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs def translate(x: Ast.expr): String = { val ttx = translator.translate(x) - // append (&reader).unwrap() to instance call val dots = ttx.split("\\.") var ttx2 = dots(0) var last = "" @@ -150,15 +149,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs if (ind > 0) { val attr = attr_full.substring(0, ind) last = attr - val found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), attr) - if (found.isDefined) { - ttx2 = s"$ttx2.$attr(&reader).unwrap()${attr_full.substring(ind + 2, attr_full.length())}" - } else { - ttx2 = s"$ttx2.$attr_full" - } - } else { - ttx2 = s"$ttx2.$attr_full" } + ttx2 = s"$ttx2.$attr_full" } // do we need to deref? if (last.nonEmpty) { @@ -167,40 +159,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs deref = false do_not_deref = true } else { - var found = translator.get_attr(translator.get_top_class(classSpecs.firstSpec), last) - if (found.isDefined) { - deref = found.get.dataTypeComposite match { - // case _: SwitchType => false - // case _: EnumType => false - // case _: UserType => false - // case _: BytesType => false - case _ => true - } - } else { - found = translator.get_instance(translator.get_top_class(classSpecs.firstSpec), last) - if (found.isDefined) { - deref = found.get.dataTypeComposite match { - // case _: SwitchType => false - // case _: EnumType => false - // case _: UserType => false - // case _: BytesType => false - case _ => true - } - } else { - found = translator.get_param(translator.get_top_class(classSpecs.firstSpec), last) - if (found.isDefined) { - deref = found.get.dataTypeComposite match { - // case _: SwitchType => false - // case _: EnumType => false - // case _: UserType => false - // case _: BytesType => false - case _ => true - } - } else { - deref = false - } - } - } + deref = translator.need_deref(last, classSpecs.firstSpec) } if (deref) { if (ttx2.charAt(0) == '*') { From 89c99abe9fec94296db1f9b6b96434d14a1f8010 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 6 Jan 2023 13:18:30 +0800 Subject: [PATCH 128/198] no useless warnings in autogenerated tests. --- spec/rust/tests/test_imports_circular_a.rs | 2 -- spec/rust/tests/test_imports_rel_1.rs | 3 --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 4 +++- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index 63e9db047..c70d15968 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -5,8 +5,6 @@ use self::kaitai::*; mod formats; use formats::imports_circular_a::*; -use formats::imports_circular_b::*; - #[test] fn test_imports_circular_a() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs index c652a5e0e..754eedd3a 100644 --- a/spec/rust/tests/test_imports_rel_1.rs +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -5,9 +5,6 @@ use self::kaitai::*; mod formats; use formats::imports_rel_1::*; -use formats::imported_1::*; -use formats::imported_2::*; - #[test] fn test_imports_rel_1() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 1bb0f4279..217b2afae 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -27,7 +27,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs spec.extraImports.foreach{ name => imports = s"$imports\n${use_mod}formats::$name::*;" } val code = - s"""|use std::{fs, rc::Rc}; + s"""|#![allow(unused_variables)] + |#![allow(unused_assignments)] + |use std::{fs, rc::Rc}; | |extern crate kaitai; |use self::kaitai::*; From 8aa4975fb13e3060350a49d6eae234df34a5dd28 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sat, 7 Jan 2023 15:33:42 +0800 Subject: [PATCH 129/198] test_debug_switch_user now autogenerated. --- spec/rust/tests/test_debug_switch_user.rs | 28 ----------------------- 1 file changed, 28 deletions(-) delete mode 100644 spec/rust/tests/test_debug_switch_user.rs diff --git a/spec/rust/tests/test_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs deleted file mode 100644 index 8cbb7c60f..000000000 --- a/spec/rust/tests/test_debug_switch_user.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::debug_switch_user::*; - -#[test] -fn basic_parse() { - let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = DebugSwitchUser::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.code(), 1); - if let DebugSwitchUser_Data::DebugSwitchUser_One(s) = r.data().as_ref().unwrap() { - assert_eq!(*s.val(), -190); - } else { - panic!("expected enum DebugSwitchUser_Data"); - }; -} From a94e37e235d6c9032dce37bedacda743f15a7688 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 10 Jan 2023 13:17:56 +0800 Subject: [PATCH 130/198] now this test autogenerated. --- spec/rust/tests/test_enum_invalid.rs | 27 ---------- spec/rust/tests/test_instance_std_array.rs | 29 ---------- spec/rust/tests/test_nav_parent_switch.rs | 32 ----------- spec/rust/tests/test_process_repeat_bytes.rs | 24 --------- spec/rust/tests/test_switch_else_only.rs | 30 ----------- .../tests/test_switch_manual_int_size_else.rs | 54 ------------------- spec/rust/tests/test_switch_repeat_expr.rs | 30 ----------- 7 files changed, 226 deletions(-) delete mode 100644 spec/rust/tests/test_enum_invalid.rs delete mode 100644 spec/rust/tests/test_instance_std_array.rs delete mode 100644 spec/rust/tests/test_nav_parent_switch.rs delete mode 100644 spec/rust/tests/test_process_repeat_bytes.rs delete mode 100644 spec/rust/tests/test_switch_else_only.rs delete mode 100644 spec/rust/tests/test_switch_manual_int_size_else.rs delete mode 100644 spec/rust/tests/test_switch_repeat_expr.rs diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs deleted file mode 100644 index 7fccec955..000000000 --- a/spec/rust/tests/test_enum_invalid.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::enum_invalid::*; - - -#[test] -fn test_enum_invalid() { - let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = EnumInvalid::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); - let i : i64 = (&*r.pet_2()).into(); - assert_eq!(i, 111); -} diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs deleted file mode 100644 index ecd6137b4..000000000 --- a/spec/rust/tests/test_instance_std_array.rs +++ /dev/null @@ -1,29 +0,0 @@ -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::instance_std_array::*; - - -#[test] -fn test_instance_std_array() { - let bytes = fs::read("../../src/instance_std_array.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = InstanceStdArray::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.ofs(), 16); - assert_eq!(*r.qty_entries(), 3); - assert_eq!(*r.entry_size(), 4); - assert_eq!(r.entries(&reader).unwrap().len(), 3); - assert_eq!(r.entries(&reader).unwrap()[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); - assert_eq!(r.entries(&reader).unwrap()[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); - assert_eq!(r.entries(&reader).unwrap()[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); -} diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs deleted file mode 100644 index d47386fd1..000000000 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ /dev/null @@ -1,32 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::nav_parent_switch::*; - - -#[test] -fn test_nav_parent_switch() { - let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = NavParentSwitch::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.category(), 1); - let c = r.content(); - if let Some(NavParentSwitch_Content::NavParentSwitch_Element1(s)) = c.as_ref() { - assert_eq!(*s.foo(), 66); - assert_eq!(*s.subelement().bar(), 255); - } else { - panic!("expected value, got {:?}", *c); - } -} diff --git a/spec/rust/tests/test_process_repeat_bytes.rs b/spec/rust/tests/test_process_repeat_bytes.rs deleted file mode 100644 index b9373b255..000000000 --- a/spec/rust/tests/test_process_repeat_bytes.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::process_repeat_bytes::*; - - -#[test] -fn test_process_repeat_bytes() { - let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ProcessRepeatBytes::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(r.bufs()[0 as usize], vec![0x72u8, 0x25u8, 0x3du8, 0x8au8, 0x14u8]); - assert_eq!(r.bufs()[1 as usize], vec![0x4au8, 0x52u8, 0xaau8, 0x10u8, 0x44u8]); -} diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs deleted file mode 100644 index 8d2fd859f..000000000 --- a/spec/rust/tests/test_switch_else_only.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_else_only::*; - -#[test] -fn test_switch_else_only() { - let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchElseOnly::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(83, *r.opcode()); - let SwitchElseOnly_PrimByte::S1(v) = *r.prim_byte_enum().as_ref().unwrap(); - assert_eq!(102, v); - - if let Some(SwitchElseOnly_Ut::SwitchElseOnly_Data(d)) = (*r.ut()).clone() { - assert_eq!(vec![0x72, 0x00, 0x49, 0x42], *d.value()); - } else { - panic!("expected enum SwitchElseOnly_Ut::SwitchElseOnly_Data"); - }; -} diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs deleted file mode 100644 index 68b28109d..000000000 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_manual_int_size_else::*; - -#[test] -fn test_switch_manual_int_size_else() { - let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualIntSizeElse::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(4, r.chunks().len()); - - assert_eq!(17, *r.chunks()[0].code()); - if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkMeta(s)) = r.chunks()[0].body().as_ref() { - assert_eq!("Stuff", *s.title()); - assert_eq!("Me", *s.author()); - } else { - panic!("expected enum SwitchManualIntSizeElse_Chunk_ChunkMeta"); - } - - assert_eq!(34, *r.chunks()[1].code()); - if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_ChunkDir(s)) = r.chunks()[1].body().as_ref() { - let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); - assert_eq!(strings, *s.entries()); - } else { - panic!("expected enum SwitchManualIntSizeElse_Chunk_ChunkDir"); - } - - assert_eq!(51, *r.chunks()[2].code()); - if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s)) = r.chunks()[2].body().as_ref() { - let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; - assert_eq!(raw, *s.rest()); - } else { - panic!("expected enum SwitchManualIntSizeElse_Chunk_Dummy"); - } - - assert_eq!(255, *r.chunks()[3].code()); - if let Some(SwitchManualIntSizeElse_Chunk_Body::SwitchManualIntSizeElse_Chunk_Dummy(s)) = r.chunks()[3].body().as_ref() { - let raw : Vec = vec![]; - assert_eq!(raw, *s.rest()); - } else { - panic!("expected enum SwitchManualIntSizeElse_Chunk_Dummy"); - }; -} diff --git a/spec/rust/tests/test_switch_repeat_expr.rs b/spec/rust/tests/test_switch_repeat_expr.rs deleted file mode 100644 index c392d688f..000000000 --- a/spec/rust/tests/test_switch_repeat_expr.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_repeat_expr::*; - - -#[test] -fn test_switch_repeat_expr() { - let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchRepeatExpr::read_into(&reader, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.code(), 17); - assert_eq!(*r.size(), 9); - - if let SwitchRepeatExpr_Body::SwitchRepeatExpr_One(b) = &r.body()[0 as usize] { - assert_eq!(*b.first(), vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); - } else { - panic!("expected enum SwitchRepeatExpr_Body"); - }; -} From 43a677c37415688ba37707d871c53a82f8e51387 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 12 Jan 2023 14:43:47 +0800 Subject: [PATCH 131/198] test generation: less warnings. --- spec/rust/tests/manual_debug_array_user.rs | 4 +-- spec/rust/tests/manual_imports_abs_abs.rs | 4 +-- spec/rust/tests/manual_imports_abs_rel.rs | 4 +-- .../rust/tests/manual_opaque_external_type.rs | 4 +-- .../manual_opaque_external_type_02_parent.rs | 4 +-- spec/rust/tests/manual_opaque_with_param.rs | 4 +-- spec/rust/tests/manual_params_def.rs | 4 +-- spec/rust/tests/manual_read_bytes.rs | 4 +-- spec/rust/tests/manual_str_literals.rs | 14 +++++----- spec/rust/tests/manual_str_repeat.rs | 4 +-- spec/rust/tests/manual_switch_cast.rs | 4 +-- spec/rust/tests/manual_switch_cast_parent.rs | 4 +-- spec/rust/tests/manual_test_parent.rs | 4 +-- spec/rust/tests/manual_to_string_custom.rs | 4 +-- spec/rust/tests/manual_type_ternary_opaque.rs | 6 ++--- spec/rust/tests/test_cast_to_imported.rs | 6 ++--- spec/rust/tests/test_expr_int_div.rs | 12 ++++----- spec/rust/tests/test_imports_circular_a.rs | 4 +-- spec/rust/tests/test_imports_rel_1.rs | 4 +-- spec/rust/tests/test_optional_id.rs | 4 +-- spec/rust/tests/test_repeat_eos_struct.rs | 4 +-- spec/rust/tests/test_repeat_n_struct.rs | 4 +-- spec/rust/tests/test_switch_bytearray.rs | 4 +-- spec/rust/tests/test_switch_manual_enum.rs | 4 +-- .../tests/test_switch_manual_enum_invalid.rs | 4 +-- .../test_switch_manual_enum_invalid_else.rs | 8 +++--- spec/rust/tests/test_switch_manual_int.rs | 4 +-- .../rust/tests/test_switch_manual_int_else.rs | 4 +-- .../rust/tests/test_switch_manual_int_size.rs | 4 +-- .../tests/test_switch_manual_int_size_eos.rs | 4 +-- spec/rust/tests/test_switch_manual_str.rs | 4 +-- .../rust/tests/test_switch_manual_str_else.rs | 4 +-- .../tests/test_switch_repeat_expr_invalid.rs | 4 +-- .../rust/tests/test_type_ternary_2nd_falsy.rs | 26 +++++++++---------- .../specgenerators/RustSG.scala | 7 +++-- 35 files changed, 95 insertions(+), 96 deletions(-) diff --git a/spec/rust/tests/manual_debug_array_user.rs b/spec/rust/tests/manual_debug_array_user.rs index fe75ba127..f9123fd26 100644 --- a/spec/rust/tests/manual_debug_array_user.rs +++ b/spec/rust/tests/manual_debug_array_user.rs @@ -9,8 +9,8 @@ use formats::debug_array_user::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = DebugArrayUser::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = DebugArrayUser::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_imports_abs_abs.rs b/spec/rust/tests/manual_imports_abs_abs.rs index 5ceadc4fb..ae0b3179c 100644 --- a/spec/rust/tests/manual_imports_abs_abs.rs +++ b/spec/rust/tests/manual_imports_abs_abs.rs @@ -9,8 +9,8 @@ use formats::imports_abs_abs::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ImportsAbsAbs::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = ImportsAbsAbs::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_imports_abs_rel.rs b/spec/rust/tests/manual_imports_abs_rel.rs index 95a9139c2..bffb5b17d 100644 --- a/spec/rust/tests/manual_imports_abs_rel.rs +++ b/spec/rust/tests/manual_imports_abs_rel.rs @@ -9,8 +9,8 @@ use formats::imports_abs_rel::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ImportsAbsRel::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = ImportsAbsRel::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_opaque_external_type.rs b/spec/rust/tests/manual_opaque_external_type.rs index a75014a3e..12686797a 100644 --- a/spec/rust/tests/manual_opaque_external_type.rs +++ b/spec/rust/tests/manual_opaque_external_type.rs @@ -8,8 +8,8 @@ use formats::opaque_external_type::*; #[test] fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = OpaqueExternalType::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = OpaqueExternalType::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_opaque_external_type_02_parent.rs b/spec/rust/tests/manual_opaque_external_type_02_parent.rs index 446bef2d3..eb69571e1 100644 --- a/spec/rust/tests/manual_opaque_external_type_02_parent.rs +++ b/spec/rust/tests/manual_opaque_external_type_02_parent.rs @@ -8,8 +8,8 @@ use formats::opaque_external_type_02_parent::*; #[test] fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = OpaqueExternalType02Parent::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = OpaqueExternalType02Parent::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_opaque_with_param.rs b/spec/rust/tests/manual_opaque_with_param.rs index 3df99f26f..1d15da3ee 100644 --- a/spec/rust/tests/manual_opaque_with_param.rs +++ b/spec/rust/tests/manual_opaque_with_param.rs @@ -9,8 +9,8 @@ use formats::opaque_with_param::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = OpaqueWithParam::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = OpaqueWithParam::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_params_def.rs b/spec/rust/tests/manual_params_def.rs index 0fa6697e7..d8694836e 100644 --- a/spec/rust/tests/manual_params_def.rs +++ b/spec/rust/tests/manual_params_def.rs @@ -9,9 +9,9 @@ use formats::params_def::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); + let _io = BytesReader::new(&bytes); let f = |t: &mut ParamsDef| Ok(t.set_params(5, true)); - let res = ParamsDef::read_into_with_init(&reader, None, None, &f); + let res = ParamsDef::read_into_with_init(&_io, None, None, &f); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_read_bytes.rs b/spec/rust/tests/manual_read_bytes.rs index 05896e47e..e7bf6f90d 100644 --- a/spec/rust/tests/manual_read_bytes.rs +++ b/spec/rust/tests/manual_read_bytes.rs @@ -9,8 +9,8 @@ use formats::read_bytes::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ReadBytes::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = ReadBytes::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/manual_str_literals.rs index d43d63276..892e55e04 100644 --- a/spec/rust/tests/manual_str_literals.rs +++ b/spec/rust/tests/manual_str_literals.rs @@ -9,8 +9,8 @@ use formats::str_literals::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = StrLiterals::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = StrLiterals::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -19,18 +19,18 @@ fn basic_parse() { r = res.unwrap(); } - let backslashes = r.backslashes(&reader).unwrap(); + let backslashes = r.backslashes(&_io).unwrap(); assert_eq!("\u{005c}\u{005c}\u{005c}", *backslashes); - let octal_eatup = r.octal_eatup(&reader).unwrap(); + let octal_eatup = r.octal_eatup(&_io).unwrap(); assert_eq!("\u{0}\u{0032}\u{0032}", *octal_eatup); - let octal_eatup2 = r.octal_eatup2(&reader).unwrap(); + let octal_eatup2 = r.octal_eatup2(&_io).unwrap(); assert_eq!("\u{2}\u{32}", *octal_eatup2); - let double_quotes = r.double_quotes(&reader).unwrap(); + let double_quotes = r.double_quotes(&_io).unwrap(); assert_eq!("\u{22}\u{22}\u{22}", *double_quotes); - let complex_str = r.complex_str(&reader).unwrap(); + let complex_str = r.complex_str(&_io).unwrap(); assert_eq!("\u{0}\u{1}\u{2}\u{7}\u{8}\u{0a}\u{0d}\u{09}\u{0b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}", *complex_str); } \ No newline at end of file diff --git a/spec/rust/tests/manual_str_repeat.rs b/spec/rust/tests/manual_str_repeat.rs index 0d3789223..f3114b4d2 100644 --- a/spec/rust/tests/manual_str_repeat.rs +++ b/spec/rust/tests/manual_str_repeat.rs @@ -9,8 +9,8 @@ use formats::str_repeat::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = StrRepeat::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = StrRepeat::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index f154db02b..0c9d045d5 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -9,9 +9,9 @@ use formats::switch_cast::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let reader = BytesReader::new(&bytes); + let _io = BytesReader::new(&bytes); - let res = SwitchCast::read_into(&reader, None, None); + let res = SwitchCast::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs index 0299e80d3..7fceb24f5 100644 --- a/spec/rust/tests/manual_switch_cast_parent.rs +++ b/spec/rust/tests/manual_switch_cast_parent.rs @@ -9,8 +9,8 @@ use formats::switch_cast_parent::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchCastParent::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchCastParent::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs index 2c2cc6aa9..11769e46c 100644 --- a/spec/rust/tests/manual_test_parent.rs +++ b/spec/rust/tests/manual_test_parent.rs @@ -9,8 +9,8 @@ use formats::test_parent::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = TestParent::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = TestParent::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_to_string_custom.rs b/spec/rust/tests/manual_to_string_custom.rs index 1d56a92af..475ff6c77 100644 --- a/spec/rust/tests/manual_to_string_custom.rs +++ b/spec/rust/tests/manual_to_string_custom.rs @@ -9,8 +9,8 @@ use formats::to_string_custom::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ToStringCustom::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = ToStringCustom::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/manual_type_ternary_opaque.rs b/spec/rust/tests/manual_type_ternary_opaque.rs index 70a3b172b..7f83df1c6 100644 --- a/spec/rust/tests/manual_type_ternary_opaque.rs +++ b/spec/rust/tests/manual_type_ternary_opaque.rs @@ -8,8 +8,8 @@ use formats::type_ternary_opaque::*; #[test] fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = TypeTernaryOpaque::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = TypeTernaryOpaque::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -18,7 +18,7 @@ fn test_term_strz() { r = res.unwrap(); } - let dif = r.dif(&reader).unwrap(); + let dif = r.dif(&_io).unwrap(); assert_eq!(*dif.as_ref().unwrap().s1(), "foo"); assert_eq!(*dif.as_ref().unwrap().s2(), "bar"); assert_eq!(*dif.as_ref().unwrap().s3(), "|baz@"); diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index 42a81df71..aef532cd0 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -8,8 +8,8 @@ use formats::cast_to_imported::*; #[test] fn test_cast_to_imported() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = CastToImported::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = CastToImported::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -19,5 +19,5 @@ fn test_cast_to_imported() { } assert_eq!(*(*(*r.one()).as_ref().unwrap()).one(), 80); - assert_eq!(*(*(*r.one_casted(&reader).unwrap()).as_ref().unwrap()).one(), 80); + assert_eq!(*(*(*r.one_casted(&_io).unwrap()).as_ref().unwrap()).one(), 80); } diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index 9222f33ec..1a92ab52c 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -8,8 +8,8 @@ use formats::expr_int_div::*; #[test] fn test_expr_int_div() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ExprIntDiv::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = ExprIntDiv::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -20,8 +20,8 @@ fn test_expr_int_div() { assert_eq!(*r.int_u(), 1262698832); assert_eq!(*r.int_s(), -52947); - assert_eq!(*r.div_pos_const(&reader).unwrap(), 756); - assert_eq!(*r.div_neg_const(&reader).unwrap(), -756); - assert_eq!(*r.div_pos_seq(&reader).unwrap(), 97130679); - assert_eq!(*r.div_neg_seq(&reader).unwrap(), -4072); + assert_eq!(*r.div_pos_const(&_io).unwrap(), 756); + assert_eq!(*r.div_neg_const(&_io).unwrap(), -756); + assert_eq!(*r.div_pos_seq(&_io).unwrap(), 97130679); + assert_eq!(*r.div_neg_seq(&_io).unwrap(), -4072); } diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index c70d15968..d174d9392 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -8,8 +8,8 @@ use formats::imports_circular_a::*; #[test] fn test_imports_circular_a() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ImportsCircularA::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = ImportsCircularA::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs index 754eedd3a..431835a69 100644 --- a/spec/rust/tests/test_imports_rel_1.rs +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -8,8 +8,8 @@ use formats::imports_rel_1::*; #[test] fn test_imports_rel_1() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = ImportsRel1::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = ImportsRel1::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs index ef2b28d7f..0df7a2833 100644 --- a/spec/rust/tests/test_optional_id.rs +++ b/spec/rust/tests/test_optional_id.rs @@ -9,8 +9,8 @@ use formats::optional_id::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = OptionalId::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = OptionalId::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index f23fe7d57..17872b194 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -9,8 +9,8 @@ use formats::repeat_eos_struct::*; #[test] fn test_repeat_eos_struct() { let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = RepeatEosStruct::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = RepeatEosStruct::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index d1ac4f207..fb404cf8a 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -9,8 +9,8 @@ use formats::repeat_n_struct::*; #[test] fn test_repeat_n_struct() { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = RepeatNStruct::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = RepeatNStruct::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index fa56ce4cc..8f1be230f 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -9,8 +9,8 @@ use formats::switch_bytearray::*; #[test] fn test_switch_bytearray() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchBytearray::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchBytearray::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index fc884546d..7532d9529 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -11,8 +11,8 @@ use formats::switch_manual_enum::*; #[test] fn test_switch_manual_enum() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualEnum::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualEnum::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 9fde1e22a..045cff106 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -9,8 +9,8 @@ use formats::switch_manual_enum_invalid::*; #[test] fn test_switch_manual_enum_invalid() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualEnumInvalid::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualEnumInvalid::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index be3bd5c8c..b91a49ed5 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -9,8 +9,8 @@ use formats::switch_manual_enum_invalid_else::*; #[test] fn test_switch_manual_enum_invalid_else() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualEnumInvalidElse::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualEnumInvalidElse::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -23,14 +23,14 @@ fn test_switch_manual_enum_invalid_else() { let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!(*s.value(&reader).unwrap(), 123); + assert_eq!(*s.value(&_io).unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); }; let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(*s.value(&reader).unwrap(), 123); + assert_eq!(*s.value(&_io).unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); }; diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index 7deed57f5..84c0ebe5d 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -9,8 +9,8 @@ use formats::switch_manual_int::*; #[test] fn test_switch_manual_int() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualInt::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualInt::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index cd11797b4..b81ac8128 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -9,8 +9,8 @@ use formats::switch_manual_int_else::*; #[test] fn test_switch_manual_int_else() { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualIntElse::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualIntElse::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index 32a837318..d849779d2 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -9,8 +9,8 @@ use formats::switch_manual_int_size::*; #[test] fn test_switch_manual_int_size() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualIntSize::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualIntSize::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 741a49f34..c2cc83317 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -9,8 +9,8 @@ use formats::switch_manual_int_size_eos::*; #[test] fn test_switch_manual_int_size_eos() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualIntSizeEos::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualIntSizeEos::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 60e3eede5..83a4fa09f 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -9,8 +9,8 @@ use formats::switch_manual_str::*; #[test] fn test_switch_manual_str() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualStr::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualStr::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index 1b0085723..c9122e61e 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -9,8 +9,8 @@ use formats::switch_manual_str_else::*; #[test] fn test_switch_manual_str_else() { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchManualStrElse::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchManualStrElse::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs index ad17eb5aa..8b64b20f4 100644 --- a/spec/rust/tests/test_switch_repeat_expr_invalid.rs +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -9,8 +9,8 @@ use formats::switch_repeat_expr_invalid::*; #[test] fn test_switch_repeat_expr_invalid() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = SwitchRepeatExprInvalid::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = SwitchRepeatExprInvalid::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index be1b9400d..7c0d937f3 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -9,8 +9,8 @@ use formats::type_ternary_2nd_falsy::*; #[test] fn test_type_ternary_2nd_falsy() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let reader = BytesReader::new(&bytes); - let res = TypeTernary2ndFalsy::read_into(&reader, None, None); + let _io = BytesReader::new(&bytes); + let res = TypeTernary2ndFalsy::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -19,17 +19,17 @@ fn test_type_ternary_2nd_falsy() { r = res.unwrap(); } - assert_eq!(*r.v_false(&reader).unwrap(), false); - assert_eq!(*r.v_int_zero(&reader).unwrap(), 0); - assert_eq!(*r.v_int_neg_zero(&reader).unwrap(), 0); - assert_eq!(*r.v_float_zero(&reader).unwrap(), 0.0); - assert_eq!(*r.v_float_neg_zero(&reader).unwrap(), -0.0); - assert_eq!(*r.v_str_w_zero(&reader).unwrap(), "0"); - assert_eq!(r.v_str_w_zero(&reader).unwrap().len(), 1); + assert_eq!(*r.v_false(&_io).unwrap(), false); + assert_eq!(*r.v_int_zero(&_io).unwrap(), 0); + assert_eq!(*r.v_int_neg_zero(&_io).unwrap(), 0); + assert_eq!(*r.v_float_zero(&_io).unwrap(), 0.0); + assert_eq!(*r.v_float_neg_zero(&_io).unwrap(), -0.0); + assert_eq!(*r.v_str_w_zero(&_io).unwrap(), "0"); + assert_eq!(r.v_str_w_zero(&_io).unwrap().len(), 1); assert_eq!(*r.ut().m(), 7); - assert_eq!(*r.v_null_ut(&reader).unwrap().m(), 0); - assert_eq!(*r.v_str_empty(&reader).unwrap(), ""); - assert_eq!(r.v_str_empty(&reader).unwrap().len(), 0); + assert_eq!(*r.v_null_ut(&_io).unwrap().m(), 0); + assert_eq!(*r.v_str_empty(&_io).unwrap(), ""); + assert_eq!(r.v_str_empty(&_io).unwrap().len(), 0); assert_eq!(r.int_array().len(), 2); - assert_eq!(r.v_int_array_empty(&reader).unwrap().len(), 0); + assert_eq!(r.v_int_array_empty(&_io).unwrap().len(), 0); } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 217b2afae..c015ec6a5 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -40,8 +40,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs |#[test] |fn test_${spec.id}() { | let bytes = fs::read("../../src/${spec.data}").unwrap(); - | let reader = BytesReader::new(&bytes); - | let res = $className::read_into(&reader, None, None); + | let _io = BytesReader::new(&bytes); + | let res: KResult> = $className::read_into(&_io, None, None); | let r : Rc<$className>; | | if let Err(err) = res {""".stripMargin @@ -57,7 +57,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val code = s""" println!("expected err: {:?}, exception: $exception", err); | } else { - | r = res.unwrap(); // need here to help Rust with type decision | panic!("no expected exception: $exception"); | }""".stripMargin out.puts(code) @@ -89,7 +88,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs code } - s = s.replace("_io", "&reader") + s = s.replace("_io", "&_io") s = s.replace(")?", ").expect(\"error reading\")") s } From 1d67954e1d2ed70b4ac6cff468a374a11e8cb5e5 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 13 Jan 2023 17:21:59 +0800 Subject: [PATCH 132/198] new autogenerated test nav_parent_vs_value_inst added. --- formats_rust/nav_parent_vs_value_inst.ksy | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 formats_rust/nav_parent_vs_value_inst.ksy diff --git a/formats_rust/nav_parent_vs_value_inst.ksy b/formats_rust/nav_parent_vs_value_inst.ksy new file mode 100644 index 000000000..b3d077055 --- /dev/null +++ b/formats_rust/nav_parent_vs_value_inst.ksy @@ -0,0 +1,18 @@ +# https://github.com/kaitai-io/kaitai_struct_compiler/issues/38#issuecomment-265525999 +meta: + id: nav_parent_vs_value_inst + endian: le + +seq: + - id: s1 + type: str + encoding: UTF-8 + terminator: 0x7C + - id: child + type: child_obj + +types: + child_obj: + instances: + do_something: + value: "_parent.s1 == 'foo' ? true : false" From 4035052d2f5efa67bffd251215df1ad3a42dde7b Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 19 Jan 2023 16:12:14 +0800 Subject: [PATCH 133/198] new tests enum_to_i_class_border_1, enum_to_i_class_border_2 added. --- formats_rust/enum_to_i_class_border_1.ksy | 29 +++++++++++++++++++++++ formats_rust/enum_to_i_class_border_2.ksy | 14 +++++++++++ 2 files changed, 43 insertions(+) create mode 100644 formats_rust/enum_to_i_class_border_1.ksy create mode 100644 formats_rust/enum_to_i_class_border_2.ksy diff --git a/formats_rust/enum_to_i_class_border_1.ksy b/formats_rust/enum_to_i_class_border_1.ksy new file mode 100644 index 000000000..7821b6f5b --- /dev/null +++ b/formats_rust/enum_to_i_class_border_1.ksy @@ -0,0 +1,29 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/552 +meta: + id: enum_to_i_class_border_1 + endian: le + imports: + - enum_to_i_class_border_2 + +seq: + - id: pet_1 + type: u4 + enum: animal + - id: pet_2 + type: u4 + enum: animal + +enums: + animal: + 4: dog + 7: cat + 12: chicken + +instances: + some_dog: + value: 4 + enum: animal + + checker: + pos: 0 + type: enum_to_i_class_border_2(_root) diff --git a/formats_rust/enum_to_i_class_border_2.ksy b/formats_rust/enum_to_i_class_border_2.ksy new file mode 100644 index 000000000..a316791ff --- /dev/null +++ b/formats_rust/enum_to_i_class_border_2.ksy @@ -0,0 +1,14 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/552 +meta: + id: enum_to_i_class_border_2 + endian: le + imports: + - enum_to_i_class_border_1 + +params: + - id: parent + type: enum_to_i_class_border_1 + +instances: + is_dog: + value: parent.some_dog.to_i == 4 From b921faa9a0227e52b5f697b59ed542a820ff90d0 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 24 Jan 2023 15:18:41 +0800 Subject: [PATCH 134/198] imports_abs test added. --- formats_rust/imports_abs.ksy | 9 +++++++++ .../struct/testtranslator/specgenerators/RustSG.scala | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 formats_rust/imports_abs.ksy diff --git a/formats_rust/imports_abs.ksy b/formats_rust/imports_abs.ksy new file mode 100644 index 000000000..873ce6a1f --- /dev/null +++ b/formats_rust/imports_abs.ksy @@ -0,0 +1,9 @@ +meta: + id: imports_abs + imports: + - /common/vlq_base128_le +seq: + - id: len + type: vlq_base128_le + - id: body + size: len.value diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index c015ec6a5..36ed3e26d 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -185,5 +185,5 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } def translateAct(x: Ast.expr): String = - translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") + translate(x).replace(s"self.${Main.INIT_OBJ_NAME}().as_ref().unwrap()", "r") } From edc7db5aae07f40d1b2451055f48654fee0c1ab9 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 24 Jan 2023 15:45:23 +0800 Subject: [PATCH 135/198] imports0 added. --- formats_rust/imports0.ksy | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 formats_rust/imports0.ksy diff --git a/formats_rust/imports0.ksy b/formats_rust/imports0.ksy new file mode 100644 index 000000000..5fb321669 --- /dev/null +++ b/formats_rust/imports0.ksy @@ -0,0 +1,12 @@ +meta: + id: imports0 + imports: + - hello_world +seq: + - id: two + type: u1 + - id: hw + type: hello_world +instances: + hw_one: + value: hw.one From 8c09d839020cd2a8fa5309c4c50c96fb514cfe5d Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 26 Jan 2023 14:02:08 +0800 Subject: [PATCH 136/198] allow(overflowing_literals) --- .../io/kaitai/struct/testtranslator/specgenerators/RustSG.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 36ed3e26d..a2a6b47a3 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -29,6 +29,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val code = s"""|#![allow(unused_variables)] |#![allow(unused_assignments)] + |#![allow(overflowing_literals)] |use std::{fs, rc::Rc}; | |extern crate kaitai; From 766378657a9a838c2c2a625bed5a2e2105e09072 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 26 Jan 2023 14:09:47 +0800 Subject: [PATCH 137/198] yaml_ints added. --- formats_rust/yaml_ints.ksy | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 formats_rust/yaml_ints.ksy diff --git a/formats_rust/yaml_ints.ksy b/formats_rust/yaml_ints.ksy new file mode 100644 index 000000000..a3c40dbdc --- /dev/null +++ b/formats_rust/yaml_ints.ksy @@ -0,0 +1,12 @@ +# Tests "forgiving" YAML KS expression parsing +meta: + id: yaml_ints +instances: + test_u4_dec: + value: 4294967295 + test_u4_hex: + value: 0xffffffff + test_u8_dec: + value: 18446744073709551615 + test_u8_hex: + value: 0xffffffffffffffff From 801e04df85726f04e713c53a6cf87906271094dc Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 26 Jan 2023 14:10:07 +0800 Subject: [PATCH 138/198] recursive_one added. --- formats_rust/recursive_one.ksy | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 formats_rust/recursive_one.ksy diff --git a/formats_rust/recursive_one.ksy b/formats_rust/recursive_one.ksy new file mode 100644 index 000000000..a88430d76 --- /dev/null +++ b/formats_rust/recursive_one.ksy @@ -0,0 +1,18 @@ +meta: + id: recursive_one +seq: + - id: one + type: u1 + - id: next + type: + switch-on: one & 3 + cases: + 0: recursive_one + 1: recursive_one + 2: recursive_one + 3: fini +types: + fini: + seq: + - id: finisher + type: u2le From b3f4b87de3bda8085eb20a2649697165ca31fe52 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 30 Jan 2023 15:17:58 +0800 Subject: [PATCH 139/198] tests updated after changes in BytesReader interface. --- spec/rust/tests/manual_debug_array_user.rs | 2 +- spec/rust/tests/manual_imports_abs_abs.rs | 2 +- spec/rust/tests/manual_imports_abs_rel.rs | 2 +- .../rust/tests/manual_opaque_external_type.rs | 2 +- .../manual_opaque_external_type_02_parent.rs | 2 +- spec/rust/tests/manual_opaque_with_param.rs | 2 +- spec/rust/tests/manual_params_def.rs | 2 +- spec/rust/tests/manual_read_bytes.rs | 2 +- spec/rust/tests/manual_str_literals.rs | 12 +++++----- spec/rust/tests/manual_str_repeat.rs | 2 +- spec/rust/tests/manual_switch_cast.rs | 2 +- spec/rust/tests/manual_switch_cast_parent.rs | 2 +- spec/rust/tests/manual_test_parent.rs | 2 +- spec/rust/tests/manual_to_string_custom.rs | 2 +- spec/rust/tests/manual_type_ternary_opaque.rs | 4 ++-- spec/rust/tests/test_cast_to_imported.rs | 4 ++-- spec/rust/tests/test_expr_int_div.rs | 10 ++++---- spec/rust/tests/test_imports_circular_a.rs | 2 +- spec/rust/tests/test_imports_rel_1.rs | 2 +- spec/rust/tests/test_optional_id.rs | 2 +- spec/rust/tests/test_repeat_eos_struct.rs | 2 +- spec/rust/tests/test_repeat_n_struct.rs | 2 +- spec/rust/tests/test_switch_bytearray.rs | 2 +- spec/rust/tests/test_switch_manual_enum.rs | 2 +- .../tests/test_switch_manual_enum_invalid.rs | 2 +- .../test_switch_manual_enum_invalid_else.rs | 6 ++--- spec/rust/tests/test_switch_manual_int.rs | 2 +- .../rust/tests/test_switch_manual_int_else.rs | 2 +- .../rust/tests/test_switch_manual_int_size.rs | 2 +- .../tests/test_switch_manual_int_size_eos.rs | 2 +- spec/rust/tests/test_switch_manual_str.rs | 2 +- .../rust/tests/test_switch_manual_str_else.rs | 2 +- .../tests/test_switch_repeat_expr_invalid.rs | 2 +- .../rust/tests/test_type_ternary_2nd_falsy.rs | 24 +++++++++---------- .../specgenerators/RustSG.scala | 2 +- 35 files changed, 59 insertions(+), 59 deletions(-) diff --git a/spec/rust/tests/manual_debug_array_user.rs b/spec/rust/tests/manual_debug_array_user.rs index f9123fd26..1ed28ad83 100644 --- a/spec/rust/tests/manual_debug_array_user.rs +++ b/spec/rust/tests/manual_debug_array_user.rs @@ -9,7 +9,7 @@ use formats::debug_array_user::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = DebugArrayUser::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_imports_abs_abs.rs b/spec/rust/tests/manual_imports_abs_abs.rs index ae0b3179c..a6b854d47 100644 --- a/spec/rust/tests/manual_imports_abs_abs.rs +++ b/spec/rust/tests/manual_imports_abs_abs.rs @@ -9,7 +9,7 @@ use formats::imports_abs_abs::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = ImportsAbsAbs::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_imports_abs_rel.rs b/spec/rust/tests/manual_imports_abs_rel.rs index bffb5b17d..446e78606 100644 --- a/spec/rust/tests/manual_imports_abs_rel.rs +++ b/spec/rust/tests/manual_imports_abs_rel.rs @@ -9,7 +9,7 @@ use formats::imports_abs_rel::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = ImportsAbsRel::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_opaque_external_type.rs b/spec/rust/tests/manual_opaque_external_type.rs index 12686797a..bded9287b 100644 --- a/spec/rust/tests/manual_opaque_external_type.rs +++ b/spec/rust/tests/manual_opaque_external_type.rs @@ -8,7 +8,7 @@ use formats::opaque_external_type::*; #[test] fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = OpaqueExternalType::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_opaque_external_type_02_parent.rs b/spec/rust/tests/manual_opaque_external_type_02_parent.rs index eb69571e1..cb33bfea5 100644 --- a/spec/rust/tests/manual_opaque_external_type_02_parent.rs +++ b/spec/rust/tests/manual_opaque_external_type_02_parent.rs @@ -8,7 +8,7 @@ use formats::opaque_external_type_02_parent::*; #[test] fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = OpaqueExternalType02Parent::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_opaque_with_param.rs b/spec/rust/tests/manual_opaque_with_param.rs index 1d15da3ee..98afb889d 100644 --- a/spec/rust/tests/manual_opaque_with_param.rs +++ b/spec/rust/tests/manual_opaque_with_param.rs @@ -9,7 +9,7 @@ use formats::opaque_with_param::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = OpaqueWithParam::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_params_def.rs b/spec/rust/tests/manual_params_def.rs index d8694836e..a4737f7f0 100644 --- a/spec/rust/tests/manual_params_def.rs +++ b/spec/rust/tests/manual_params_def.rs @@ -9,7 +9,7 @@ use formats::params_def::*; #[test] fn test_params_def() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let f = |t: &mut ParamsDef| Ok(t.set_params(5, true)); let res = ParamsDef::read_into_with_init(&_io, None, None, &f); let r : Rc; diff --git a/spec/rust/tests/manual_read_bytes.rs b/spec/rust/tests/manual_read_bytes.rs index e7bf6f90d..eea2a816b 100644 --- a/spec/rust/tests/manual_read_bytes.rs +++ b/spec/rust/tests/manual_read_bytes.rs @@ -9,7 +9,7 @@ use formats::read_bytes::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = ReadBytes::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/manual_str_literals.rs index 892e55e04..f3bceb5f1 100644 --- a/spec/rust/tests/manual_str_literals.rs +++ b/spec/rust/tests/manual_str_literals.rs @@ -9,7 +9,7 @@ use formats::str_literals::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = StrLiterals::read_into(&_io, None, None); let r : Rc; @@ -19,18 +19,18 @@ fn basic_parse() { r = res.unwrap(); } - let backslashes = r.backslashes(&_io).unwrap(); + let backslashes = r.backslashes().unwrap(); assert_eq!("\u{005c}\u{005c}\u{005c}", *backslashes); - let octal_eatup = r.octal_eatup(&_io).unwrap(); + let octal_eatup = r.octal_eatup().unwrap(); assert_eq!("\u{0}\u{0032}\u{0032}", *octal_eatup); - let octal_eatup2 = r.octal_eatup2(&_io).unwrap(); + let octal_eatup2 = r.octal_eatup2().unwrap(); assert_eq!("\u{2}\u{32}", *octal_eatup2); - let double_quotes = r.double_quotes(&_io).unwrap(); + let double_quotes = r.double_quotes().unwrap(); assert_eq!("\u{22}\u{22}\u{22}", *double_quotes); - let complex_str = r.complex_str(&_io).unwrap(); + let complex_str = r.complex_str().unwrap(); assert_eq!("\u{0}\u{1}\u{2}\u{7}\u{8}\u{0a}\u{0d}\u{09}\u{0b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}", *complex_str); } \ No newline at end of file diff --git a/spec/rust/tests/manual_str_repeat.rs b/spec/rust/tests/manual_str_repeat.rs index f3114b4d2..0d65bdf89 100644 --- a/spec/rust/tests/manual_str_repeat.rs +++ b/spec/rust/tests/manual_str_repeat.rs @@ -9,7 +9,7 @@ use formats::str_repeat::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = StrRepeat::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index 0c9d045d5..738ee7646 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -9,7 +9,7 @@ use formats::switch_cast::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchCast::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs index 7fceb24f5..756bdf7da 100644 --- a/spec/rust/tests/manual_switch_cast_parent.rs +++ b/spec/rust/tests/manual_switch_cast_parent.rs @@ -9,7 +9,7 @@ use formats::switch_cast_parent::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchCastParent::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs index 11769e46c..637e3f3af 100644 --- a/spec/rust/tests/manual_test_parent.rs +++ b/spec/rust/tests/manual_test_parent.rs @@ -9,7 +9,7 @@ use formats::test_parent::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = TestParent::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_to_string_custom.rs b/spec/rust/tests/manual_to_string_custom.rs index 475ff6c77..9b03f3c84 100644 --- a/spec/rust/tests/manual_to_string_custom.rs +++ b/spec/rust/tests/manual_to_string_custom.rs @@ -9,7 +9,7 @@ use formats::to_string_custom::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = ToStringCustom::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/manual_type_ternary_opaque.rs b/spec/rust/tests/manual_type_ternary_opaque.rs index 7f83df1c6..04c587dd7 100644 --- a/spec/rust/tests/manual_type_ternary_opaque.rs +++ b/spec/rust/tests/manual_type_ternary_opaque.rs @@ -8,7 +8,7 @@ use formats::type_ternary_opaque::*; #[test] fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = TypeTernaryOpaque::read_into(&_io, None, None); let r : Rc; @@ -18,7 +18,7 @@ fn test_term_strz() { r = res.unwrap(); } - let dif = r.dif(&_io).unwrap(); + let dif = r.dif().unwrap(); assert_eq!(*dif.as_ref().unwrap().s1(), "foo"); assert_eq!(*dif.as_ref().unwrap().s2(), "bar"); assert_eq!(*dif.as_ref().unwrap().s3(), "|baz@"); diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index aef532cd0..efa855a50 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -8,7 +8,7 @@ use formats::cast_to_imported::*; #[test] fn test_cast_to_imported() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = CastToImported::read_into(&_io, None, None); let r : Rc; @@ -19,5 +19,5 @@ fn test_cast_to_imported() { } assert_eq!(*(*(*r.one()).as_ref().unwrap()).one(), 80); - assert_eq!(*(*(*r.one_casted(&_io).unwrap()).as_ref().unwrap()).one(), 80); + assert_eq!(*(*(*r.one_casted().unwrap()).as_ref().unwrap()).one(), 80); } diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index 1a92ab52c..48cfc4ad0 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -8,7 +8,7 @@ use formats::expr_int_div::*; #[test] fn test_expr_int_div() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = ExprIntDiv::read_into(&_io, None, None); let r : Rc; @@ -20,8 +20,8 @@ fn test_expr_int_div() { assert_eq!(*r.int_u(), 1262698832); assert_eq!(*r.int_s(), -52947); - assert_eq!(*r.div_pos_const(&_io).unwrap(), 756); - assert_eq!(*r.div_neg_const(&_io).unwrap(), -756); - assert_eq!(*r.div_pos_seq(&_io).unwrap(), 97130679); - assert_eq!(*r.div_neg_seq(&_io).unwrap(), -4072); + assert_eq!(*r.div_pos_const().unwrap(), 756); + assert_eq!(*r.div_neg_const().unwrap(), -756); + assert_eq!(*r.div_pos_seq().unwrap(), 97130679); + assert_eq!(*r.div_neg_seq().unwrap(), -4072); } diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index d174d9392..b101aa909 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -8,7 +8,7 @@ use formats::imports_circular_a::*; #[test] fn test_imports_circular_a() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = ImportsCircularA::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs index 431835a69..9b86632af 100644 --- a/spec/rust/tests/test_imports_rel_1.rs +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -8,7 +8,7 @@ use formats::imports_rel_1::*; #[test] fn test_imports_rel_1() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = ImportsRel1::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs index 0df7a2833..8cd514d56 100644 --- a/spec/rust/tests/test_optional_id.rs +++ b/spec/rust/tests/test_optional_id.rs @@ -9,7 +9,7 @@ use formats::optional_id::*; #[test] fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = OptionalId::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index 17872b194..d29de6843 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -9,7 +9,7 @@ use formats::repeat_eos_struct::*; #[test] fn test_repeat_eos_struct() { let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = RepeatEosStruct::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index fb404cf8a..f264b9220 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -9,7 +9,7 @@ use formats::repeat_n_struct::*; #[test] fn test_repeat_n_struct() { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = RepeatNStruct::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index 8f1be230f..c115f4c72 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -9,7 +9,7 @@ use formats::switch_bytearray::*; #[test] fn test_switch_bytearray() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchBytearray::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index 7532d9529..ee067bb6d 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -11,7 +11,7 @@ use formats::switch_manual_enum::*; #[test] fn test_switch_manual_enum() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualEnum::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 045cff106..32ef4e378 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -9,7 +9,7 @@ use formats::switch_manual_enum_invalid::*; #[test] fn test_switch_manual_enum_invalid() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualEnumInvalid::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index b91a49ed5..0638b1610 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -9,7 +9,7 @@ use formats::switch_manual_enum_invalid_else::*; #[test] fn test_switch_manual_enum_invalid_else() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualEnumInvalidElse::read_into(&_io, None, None); let r : Rc; @@ -23,14 +23,14 @@ fn test_switch_manual_enum_invalid_else() { let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!(*s.value(&_io).unwrap(), 123); + assert_eq!(*s.value().unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); }; let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(*s.value(&_io).unwrap(), 123); + assert_eq!(*s.value().unwrap(), 123); } else { panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); }; diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index 84c0ebe5d..27c0efa86 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -9,7 +9,7 @@ use formats::switch_manual_int::*; #[test] fn test_switch_manual_int() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualInt::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index b81ac8128..eca3a19e5 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -9,7 +9,7 @@ use formats::switch_manual_int_else::*; #[test] fn test_switch_manual_int_else() { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualIntElse::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index d849779d2..12c9c5d03 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -9,7 +9,7 @@ use formats::switch_manual_int_size::*; #[test] fn test_switch_manual_int_size() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualIntSize::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index c2cc83317..27adbe2bc 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -9,7 +9,7 @@ use formats::switch_manual_int_size_eos::*; #[test] fn test_switch_manual_int_size_eos() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualIntSizeEos::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 83a4fa09f..78e77c6a1 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -9,7 +9,7 @@ use formats::switch_manual_str::*; #[test] fn test_switch_manual_str() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualStr::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index c9122e61e..ca7355343 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -9,7 +9,7 @@ use formats::switch_manual_str_else::*; #[test] fn test_switch_manual_str_else() { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchManualStrElse::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs index 8b64b20f4..02de1b4df 100644 --- a/spec/rust/tests/test_switch_repeat_expr_invalid.rs +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -9,7 +9,7 @@ use formats::switch_repeat_expr_invalid::*; #[test] fn test_switch_repeat_expr_invalid() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = SwitchRepeatExprInvalid::read_into(&_io, None, None); let r : Rc; diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index 7c0d937f3..707991312 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -9,7 +9,7 @@ use formats::type_ternary_2nd_falsy::*; #[test] fn test_type_ternary_2nd_falsy() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let _io = BytesReader::new(&bytes); + let _io = BytesReader::from(bytes); let res = TypeTernary2ndFalsy::read_into(&_io, None, None); let r : Rc; @@ -19,17 +19,17 @@ fn test_type_ternary_2nd_falsy() { r = res.unwrap(); } - assert_eq!(*r.v_false(&_io).unwrap(), false); - assert_eq!(*r.v_int_zero(&_io).unwrap(), 0); - assert_eq!(*r.v_int_neg_zero(&_io).unwrap(), 0); - assert_eq!(*r.v_float_zero(&_io).unwrap(), 0.0); - assert_eq!(*r.v_float_neg_zero(&_io).unwrap(), -0.0); - assert_eq!(*r.v_str_w_zero(&_io).unwrap(), "0"); - assert_eq!(r.v_str_w_zero(&_io).unwrap().len(), 1); + assert_eq!(*r.v_false().unwrap(), false); + assert_eq!(*r.v_int_zero().unwrap(), 0); + assert_eq!(*r.v_int_neg_zero().unwrap(), 0); + assert_eq!(*r.v_float_zero().unwrap(), 0.0); + assert_eq!(*r.v_float_neg_zero().unwrap(), -0.0); + assert_eq!(*r.v_str_w_zero().unwrap(), "0"); + assert_eq!(r.v_str_w_zero().unwrap().len(), 1); assert_eq!(*r.ut().m(), 7); - assert_eq!(*r.v_null_ut(&_io).unwrap().m(), 0); - assert_eq!(*r.v_str_empty(&_io).unwrap(), ""); - assert_eq!(r.v_str_empty(&_io).unwrap().len(), 0); + assert_eq!(*r.v_null_ut().unwrap().m(), 0); + assert_eq!(*r.v_str_empty().unwrap(), ""); + assert_eq!(r.v_str_empty().unwrap().len(), 0); assert_eq!(r.int_array().len(), 2); - assert_eq!(r.v_int_array_empty(&_io).unwrap().len(), 0); + assert_eq!(r.v_int_array_empty().unwrap().len(), 0); } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index a2a6b47a3..2f5846d48 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -41,7 +41,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs |#[test] |fn test_${spec.id}() { | let bytes = fs::read("../../src/${spec.data}").unwrap(); - | let _io = BytesReader::new(&bytes); + | let _io = BytesReader::from(bytes); | let res: KResult> = $className::read_into(&_io, None, None); | let r : Rc<$className>; | From 91f2bd7d609e581e4d729c72afa5773459dd8b4b Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 30 Jan 2023 16:20:01 +0800 Subject: [PATCH 140/198] io_local_var/io_local_var2 tests. --- formats_rust/io_local_var.ksy | 26 ++++++++++++++++++++++++++ formats_rust/io_local_var2.ksy | 20 ++++++++++++++++++++ formats_rust/nav_parent_test.ksy | 25 ------------------------- 3 files changed, 46 insertions(+), 25 deletions(-) create mode 100644 formats_rust/io_local_var.ksy create mode 100644 formats_rust/io_local_var2.ksy delete mode 100644 formats_rust/nav_parent_test.ksy diff --git a/formats_rust/io_local_var.ksy b/formats_rust/io_local_var.ksy new file mode 100644 index 000000000..1d7834c75 --- /dev/null +++ b/formats_rust/io_local_var.ksy @@ -0,0 +1,26 @@ +# https://github.com/kaitai-io/kaitai_struct/issues/536 +meta: + id: io_local_var +seq: + # [0..19] + - id: skip + size: 20 + # Invoke `mess_up` that can potentially mess up _root._io pointer +# - id: always_null +# type: u1 +# if: mess_up.as._io.pos < 0 + # Check where we are at, should consume [20] + - id: followup + type: u1 +instances: + mess_up: + io: _root._io # required to trigger `io` assignment + pos: 8 + size: 2 + type: + switch-on: 2 + cases: + 1: dummy + 2: dummy +types: + dummy: {} diff --git a/formats_rust/io_local_var2.ksy b/formats_rust/io_local_var2.ksy new file mode 100644 index 000000000..a51166945 --- /dev/null +++ b/formats_rust/io_local_var2.ksy @@ -0,0 +1,20 @@ +meta: + id: io_local_var2 +seq: + - id: some_header + size: 10 + - id: files + size: 80 + type: file_entry +types: + file_entry: + seq: + - id: ofs_body + type: u1 + - id: len_body + type: u1 + instances: + body: + io: _root._io + pos: ofs_body + size: len_body \ No newline at end of file diff --git a/formats_rust/nav_parent_test.ksy b/formats_rust/nav_parent_test.ksy deleted file mode 100644 index e27a33cb3..000000000 --- a/formats_rust/nav_parent_test.ksy +++ /dev/null @@ -1,25 +0,0 @@ -meta: - id: nav_parent_test - endian: le -seq: - - id: qty_entries - type: u4 - - id: filename_len - type: u4 - - id: index - type: index_obj -types: - index_obj: - seq: - - id: magic - size: 4 - - id: entries - type: entry - repeat: expr - repeat-expr: _parent.qty_entries - entry: - seq: - - id: filename - type: str - size: _parent._parent.filename_len - encoding: UTF-8 From f08bf9014481d9819136c72eb39700ad29d5ceed Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 1 Feb 2023 16:10:49 +0800 Subject: [PATCH 141/198] support .as --- formats_rust/io_local_var.ksy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/formats_rust/io_local_var.ksy b/formats_rust/io_local_var.ksy index 1d7834c75..68ae49aad 100644 --- a/formats_rust/io_local_var.ksy +++ b/formats_rust/io_local_var.ksy @@ -6,9 +6,9 @@ seq: - id: skip size: 20 # Invoke `mess_up` that can potentially mess up _root._io pointer -# - id: always_null -# type: u1 -# if: mess_up.as._io.pos < 0 + - id: always_null + type: u1 + if: mess_up.as._io.pos < 0 # Check where we are at, should consume [20] - id: followup type: u1 From 6f91d04835d3bc55559cfd1323fd89d4168255ce Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Wed, 1 Feb 2023 19:33:57 +0800 Subject: [PATCH 142/198] switch_cast restored to full test. --- formats_rust/switch_cast.ksy | 14 +++++++------- spec/rust/tests/manual_switch_cast.rs | 3 +++ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/formats_rust/switch_cast.ksy b/formats_rust/switch_cast.ksy index ba4b883ee..ebb267462 100644 --- a/formats_rust/switch_cast.ksy +++ b/formats_rust/switch_cast.ksy @@ -4,13 +4,13 @@ seq: - id: opcodes type: opcode repeat: eos -#instances: -# first_obj: -# value: opcodes[0].body.as -# second_val: -# value: opcodes[1].body.as.value -# err_cast: -# value: opcodes[2].body.as +instances: + first_obj: + value: opcodes[0].body.as + second_val: + value: opcodes[1].body.as.value + err_cast: + value: opcodes[2].body.as types: opcode: seq: diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index 738ee7646..6ca70fc97 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -20,6 +20,9 @@ fn basic_parse() { r = res.unwrap(); } + assert_eq!("foobar", *r.first_obj().unwrap().value()); + assert_eq!(0x42, *r.second_val().unwrap()); + assert_eq!(4, r.opcodes().len()); assert_eq!(0x53, *r.opcodes()[0].code()); From 1ee5782d2e20ec2b436215e790027f628ad36730 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 2 Feb 2023 10:36:00 +0800 Subject: [PATCH 143/198] cast_nested, cast_to_top, nav_parent2, nav_parent3. --- formats_rust/cast_nested.ksy | 36 +++++++++++++++++++++++++++++++ formats_rust/cast_to_top.ksy | 14 ++++++++++++ formats_rust/nav_parent2.ksy | 38 +++++++++++++++++++++++++++++++++ formats_rust/nav_parent3.ksy | 41 ++++++++++++++++++++++++++++++++++++ 4 files changed, 129 insertions(+) create mode 100644 formats_rust/cast_nested.ksy create mode 100644 formats_rust/cast_to_top.ksy create mode 100644 formats_rust/nav_parent2.ksy create mode 100644 formats_rust/nav_parent3.ksy diff --git a/formats_rust/cast_nested.ksy b/formats_rust/cast_nested.ksy new file mode 100644 index 000000000..7a67cd9f3 --- /dev/null +++ b/formats_rust/cast_nested.ksy @@ -0,0 +1,36 @@ +meta: + id: cast_nested +seq: + - id: opcodes + type: opcode + repeat: eos +instances: + opcodes_0_str: + value: opcodes[0].body.as + opcodes_0_str_value: + value: opcodes[0].body.as.value + opcodes_1_int: + value: opcodes[1].body.as + opcodes_1_int_value: + value: opcodes[1].body.as.value +types: + opcode: + seq: + - id: code + type: u1 + - id: body + type: + switch-on: code + cases: + 73: intval + 83: strval + types: + intval: + seq: + - id: value + type: u1 + strval: + seq: + - id: value + type: strz + encoding: ASCII diff --git a/formats_rust/cast_to_top.ksy b/formats_rust/cast_to_top.ksy new file mode 100644 index 000000000..dbf53fabb --- /dev/null +++ b/formats_rust/cast_to_top.ksy @@ -0,0 +1,14 @@ +# Simplest way to check that casting to top-level type works +meta: + id: cast_to_top +seq: + - id: code + type: u1 +instances: + header: + pos: 1 + type: cast_to_top + # This is silly and does nothing, but it checks that casting can find + # top-level type + header_casted: + value: header.as diff --git a/formats_rust/nav_parent2.ksy b/formats_rust/nav_parent2.ksy new file mode 100644 index 000000000..70de7dbb1 --- /dev/null +++ b/formats_rust/nav_parent2.ksy @@ -0,0 +1,38 @@ +meta: + id: nav_parent2 + endian: le +seq: + - id: ofs_tags + type: u4 + - id: num_tags + type: u4 + - id: tags + type: tag + repeat: expr + repeat-expr: num_tags +types: + tag: + seq: + - id: name + type: str + size: 4 + encoding: ASCII + - id: ofs + type: u4 + - id: num_items + type: u4 + types: + tag_char: + seq: + - id: content + type: str + size: _parent.num_items + encoding: ASCII + instances: + tag_content: + pos: ofs + type: + switch-on: name + cases: + '"RAHC"': tag_char + io: _root._io diff --git a/formats_rust/nav_parent3.ksy b/formats_rust/nav_parent3.ksy new file mode 100644 index 000000000..108eb0a8c --- /dev/null +++ b/formats_rust/nav_parent3.ksy @@ -0,0 +1,41 @@ +# Same as nav_parent2, but "tags" is instance and is actually positioned at ofs_tags +meta: + id: nav_parent3 + endian: le +seq: + - id: ofs_tags + type: u4 + - id: num_tags + type: u4 +types: + tag: + seq: + - id: name + type: str + size: 4 + encoding: ASCII + - id: ofs + type: u4 + - id: num_items + type: u4 + types: + tag_char: + seq: + - id: content + type: str + size: _parent.num_items + encoding: ASCII + instances: + tag_content: + pos: ofs + type: + switch-on: name + cases: + '"RAHC"': tag_char + io: _root._io +instances: + tags: + pos: ofs_tags + type: tag + repeat: expr + repeat-expr: num_tags From 79fb0f37f90b6046513af1b9707e11704c0ca0cf Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 2 Feb 2023 13:57:22 +0800 Subject: [PATCH 144/198] nav_parent_override. --- formats_rust/nav_parent_override.ksy | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 formats_rust/nav_parent_override.ksy diff --git a/formats_rust/nav_parent_override.ksy b/formats_rust/nav_parent_override.ksy new file mode 100644 index 000000000..ce8ed335e --- /dev/null +++ b/formats_rust/nav_parent_override.ksy @@ -0,0 +1,19 @@ +meta: + id: nav_parent_override +seq: + - id: child_size + type: u1 + - id: child_1 + type: child + - id: mediator_2 + type: mediator +types: + mediator: + seq: + - id: child_2 + type: child + parent: _parent + child: + seq: + - id: data + size: _parent.child_size From 4ca74bb9309f9c8e32d8773fda6f4e94cef2b589 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 2 Feb 2023 16:23:18 +0800 Subject: [PATCH 145/198] more test autogenerated. --- spec/rust/tests/test_expr_int_div.rs | 14 +++-- spec/rust/tests/test_imports_rel_1.rs | 24 --------- spec/rust/tests/test_repeat_n_struct.rs | 5 +- spec/rust/tests/test_switch_bytearray.rs | 50 ----------------- spec/rust/tests/test_switch_manual_enum.rs | 53 ------------------ .../test_switch_manual_enum_invalid_else.rs | 19 +++---- spec/rust/tests/test_switch_manual_int.rs | 48 ----------------- .../rust/tests/test_switch_manual_int_else.rs | 50 ----------------- .../rust/tests/test_switch_manual_int_size.rs | 54 ------------------- spec/rust/tests/test_switch_manual_str.rs | 50 ----------------- .../rust/tests/test_switch_manual_str_else.rs | 50 ----------------- .../tests/test_switch_repeat_expr_invalid.rs | 30 ----------- 12 files changed, 21 insertions(+), 426 deletions(-) delete mode 100644 spec/rust/tests/test_imports_rel_1.rs delete mode 100644 spec/rust/tests/test_switch_bytearray.rs delete mode 100644 spec/rust/tests/test_switch_manual_enum.rs delete mode 100644 spec/rust/tests/test_switch_manual_int.rs delete mode 100644 spec/rust/tests/test_switch_manual_int_else.rs delete mode 100644 spec/rust/tests/test_switch_manual_int_size.rs delete mode 100644 spec/rust/tests/test_switch_manual_str.rs delete mode 100644 spec/rust/tests/test_switch_manual_str_else.rs delete mode 100644 spec/rust/tests/test_switch_repeat_expr_invalid.rs diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index 48cfc4ad0..1423cc8e0 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -1,3 +1,6 @@ +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] use std::{fs, rc::Rc}; extern crate kaitai; @@ -5,11 +8,12 @@ use self::kaitai::*; mod formats; use formats::expr_int_div::*; + #[test] fn test_expr_int_div() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = ExprIntDiv::read_into(&_io, None, None); + let res: KResult> = ExprIntDiv::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -20,8 +24,8 @@ fn test_expr_int_div() { assert_eq!(*r.int_u(), 1262698832); assert_eq!(*r.int_s(), -52947); - assert_eq!(*r.div_pos_const().unwrap(), 756); - assert_eq!(*r.div_neg_const().unwrap(), -756); - assert_eq!(*r.div_pos_seq().unwrap(), 97130679); - assert_eq!(*r.div_neg_seq().unwrap(), -4072); + assert_eq!(*r.div_pos_const().expect("error reading"), 756); + assert_eq!(*r.div_neg_const().expect("error reading"), -756); + assert_eq!(*r.div_pos_seq().expect("error reading"), 97130679); + assert_eq!(*r.div_neg_seq().expect("error reading"), -4072); } diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs deleted file mode 100644 index 9b86632af..000000000 --- a/spec/rust/tests/test_imports_rel_1.rs +++ /dev/null @@ -1,24 +0,0 @@ -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::imports_rel_1::*; - -#[test] -fn test_imports_rel_1() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = ImportsRel1::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.one(), 80); - assert_eq!(*r.two().as_ref().unwrap().one(), 65); - assert_eq!(*r.two().as_ref().unwrap().two().as_ref().unwrap().one(), 67); -} diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index f264b9220..4588dba19 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -1,3 +1,6 @@ +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] use std::{fs, rc::Rc}; extern crate kaitai; @@ -10,7 +13,7 @@ use formats::repeat_n_struct::*; fn test_repeat_n_struct() { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = RepeatNStruct::read_into(&_io, None, None); + let res: KResult> = RepeatNStruct::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs deleted file mode 100644 index c115f4c72..000000000 --- a/spec/rust/tests/test_switch_bytearray.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_bytearray::*; - -#[test] -fn test_switch_bytearray() { - let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchBytearray::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(4, r.opcodes().len()); - - assert_eq!(vec![0x53], *r.opcodes()[0].code()); - if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!("foobar", *s.value()); - } else { - panic!("expected enum SwitchBytearray_Opcode_Strval"); - } - - assert_eq!(vec![0x49], *r.opcodes()[1].code()); - if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(66, *s.value()); - } else { - panic!("expected enum SwitchBytearray_Opcode_Intval"); - } - - assert_eq!(vec![0x49], *r.opcodes()[2].code()); - if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(55, *s.value()); - } else { - panic!("expected enum SwitchBytearray_Opcode_Intval"); - } - - assert_eq!(vec![0x53], *r.opcodes()[3].code()); - if let Some(SwitchBytearray_Opcode_Body::SwitchBytearray_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!("", *s.value()); - } else { - panic!("expected enum SwitchBytearray_Opcode_Strval"); - }; -} diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs deleted file mode 100644 index ee067bb6d..000000000 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ /dev/null @@ -1,53 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_manual_enum::*; - - -#[test] -fn test_switch_manual_enum() { - let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchManualEnum::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(r.opcodes().len(), 4); - - assert_eq!(*r.opcodes()[0 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); - if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!(*s.value(), "foobar"); - } else { - panic!("expected enum SwitchManualEnum_Opcode_Strval"); - } - - assert_eq!(*r.opcodes()[1 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); - if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(*s.value(), 66); - } else { - panic!("expected enum SwitchManualEnum_Opcode_Intval"); - } - - assert_eq!(*r.opcodes()[2 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); - if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(*s.value(), 55); - } else { - panic!("expected enum SwitchManualEnum_Opcode_Intval"); - } - - assert_eq!(*r.opcodes()[3 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); - if let Some(SwitchManualEnum_Opcode_Body::SwitchManualEnum_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!(*s.value(), ""); - } else { - panic!("expected enum SwitchManualEnum_Opcode_Strval"); - }; -} diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index 0638b1610..71c5f49a1 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -1,3 +1,8 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] use std::{fs, rc::Rc}; extern crate kaitai; @@ -10,7 +15,7 @@ use formats::switch_manual_enum_invalid_else::*; fn test_switch_manual_enum_invalid_else() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = SwitchManualEnumInvalidElse::read_into(&_io, None, None); + let res: KResult> = SwitchManualEnumInvalidElse::read_into(&_io, None, None); let r : Rc; if let Err(err) = res { @@ -22,16 +27,8 @@ fn test_switch_manual_enum_invalid_else() { assert_eq!(r.opcodes().len(), 2); let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); - if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!(*s.value().unwrap(), 123); - } else { - panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); - }; + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value().unwrap(), 123); let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); - if let Some(SwitchManualEnumInvalidElse_Opcode_Body::SwitchManualEnumInvalidElse_Opcode_Defval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(*s.value().unwrap(), 123); - } else { - panic!("expected enum SwitchManualEnumInvalidElse_Opcode_Defval"); - }; + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value().unwrap(), 123); } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs deleted file mode 100644 index 27c0efa86..000000000 --- a/spec/rust/tests/test_switch_manual_int.rs +++ /dev/null @@ -1,48 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_manual_int::*; - -#[test] -fn test_switch_manual_int() { - let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchManualInt::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(83, *r.opcodes()[0].code()); - if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!("foobar", *s.value()); - } else { - panic!("expected enum SwitchManualInt_Opcode_Body"); - } - - assert_eq!(73, *r.opcodes()[1].code()); - if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(66, *s.value()); - } else { - panic!("expected enum SwitchManualInt_Opcode_Body"); - } - - assert_eq!(73, *r.opcodes()[2].code()); - if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(55, *s.value()); - } else { - panic!("expected enum SwitchManualInt_Opcode_Body"); - } - - assert_eq!(83, *r.opcodes()[3].code()); - if let Some(SwitchManualInt_Opcode_Body::SwitchManualInt_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!("", *s.value()); - } else { - panic!("expected enum SwitchManualInt_Opcode_Body"); - }; -} diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs deleted file mode 100644 index eca3a19e5..000000000 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_manual_int_else::*; - -#[test] -fn test_switch_manual_int_else() { - let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchManualIntElse::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(4, r.opcodes().len()); - - assert_eq!(83, *r.opcodes()[0].code()); - if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!("foo", *s.value()); - } else { - panic!("expected enum SwitchManualIntElse_Opcode_Strval"); - } - - assert_eq!(88, *r.opcodes()[1].code()); - if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(66, *s.filler()); - } else { - panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); - } - - assert_eq!(89, *r.opcodes()[2].code()); - if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Noneval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(51966, *s.filler()); - } else { - panic!("expected enum SwitchManualIntElse_Opcode_Noneval"); - } - - assert_eq!(73, *r.opcodes()[3].code()); - if let Some(SwitchManualIntElse_Opcode_Body::SwitchManualIntElse_Opcode_Intval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!(7, *s.value()); - } else { - panic!("expected enum SwitchManualIntElse_Opcode_Intval"); - }; -} diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs deleted file mode 100644 index 12c9c5d03..000000000 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ /dev/null @@ -1,54 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_manual_int_size::*; - -#[test] -fn test_switch_manual_int_size() { - let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchManualIntSize::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(4, r.chunks().len()); - - assert_eq!(17, *r.chunks()[0].code()); - if let Some(SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkMeta(s)) = r.chunks()[0].body().as_ref() { - assert_eq!("Stuff", *s.title()); - assert_eq!("Me", *s.author()); - } else { - panic!("expected enum SwitchManualIntSize_Chunk_ChunkMeta"); - } - - assert_eq!(34, *r.chunks()[1].code()); - if let Some(SwitchManualIntSize_Chunk_Body::SwitchManualIntSize_Chunk_ChunkDir(s)) = r.chunks()[1].body().as_ref() { - let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); - assert_eq!(strings, *s.entries()); - } else { - panic!("expected enum SwitchManualIntSize_Chunk_ChunkDir"); - } - - assert_eq!(51, *r.chunks()[2].code()); - if let Some(SwitchManualIntSize_Chunk_Body::Bytes(s)) = r.chunks()[2].body().as_ref() { - let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; - assert_eq!(raw, *s); - } else { - panic!("expected enum Bytes"); - } - - assert_eq!(255, *r.chunks()[3].code()); - if let Some(SwitchManualIntSize_Chunk_Body::Bytes(s)) = r.chunks()[3].body().as_ref() { - let raw : Vec = vec![]; - assert_eq!(raw, *s); - } else { - panic!("expected enum Bytes"); - }; -} diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs deleted file mode 100644 index 78e77c6a1..000000000 --- a/spec/rust/tests/test_switch_manual_str.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_manual_str::*; - -#[test] -fn test_switch_manual_str() { - let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchManualStr::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(4, r.opcodes().len()); - - assert_eq!("S", *r.opcodes()[0].code()); - if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!("foobar", *s.value()); - } else { - panic!("expected enum SwitchManualStr_Opcode_Strval"); - } - - assert_eq!("I", *r.opcodes()[1].code()); - if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(66, *s.value()); - } else { - panic!("expected enum SwitchManualStr_Opcode_Intval"); - } - - assert_eq!("I", *r.opcodes()[2].code()); - if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(55, *s.value()); - } else { - panic!("expected enum SwitchManualStr_Opcode_Intval"); - } - - assert_eq!("S", *r.opcodes()[3].code()); - if let Some(SwitchManualStr_Opcode_Body::SwitchManualStr_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!("", *s.value()); - } else { - panic!("expected enum SwitchManualStr_Opcode_Strval"); - }; -} diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs deleted file mode 100644 index ca7355343..000000000 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_manual_str_else::*; - -#[test] -fn test_switch_manual_str_else() { - let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchManualStrElse::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - assert_eq!(4, r.opcodes().len()); - - assert_eq!("S", *r.opcodes()[0].code()); - if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!("foo", *s.value()); - } else { - panic!("expected enum SwitchManualStrElse_Opcode_Strval"); - } - - assert_eq!("X", *r.opcodes()[1].code()); - if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(66, *s.filler()); - } else { - panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); - } - - assert_eq!("Y", *r.opcodes()[2].code()); - if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Noneval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(51966, *s.filler()); - } else { - panic!("expected enum SwitchManualStrElse_Opcode_Noneval"); - } - - assert_eq!("I", *r.opcodes()[3].code()); - if let Some(SwitchManualStrElse_Opcode_Body::SwitchManualStrElse_Opcode_Intval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!(7, *s.value()); - } else { - panic!("expected enum SwitchManualStrElse_Opcode_Strval"); - }; -} diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs deleted file mode 100644 index 02de1b4df..000000000 --- a/spec/rust/tests/test_switch_repeat_expr_invalid.rs +++ /dev/null @@ -1,30 +0,0 @@ -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_repeat_expr_invalid::*; - - -#[test] -fn test_switch_repeat_expr_invalid() { - let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchRepeatExprInvalid::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.code(), 17); - assert_eq!(*r.size(), 9); - - if let SwitchRepeatExprInvalid_Body::Bytes(b) = &r.body()[0 as usize] { - assert_eq!(b, &vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); - } else { - panic!("expected enum SwitchRepeatExpr_Body"); - }; -} From 1b96b14e9b14e837e7d93c3f4170cb31372d51c8 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 2 Feb 2023 16:48:36 +0800 Subject: [PATCH 146/198] useless tests (only from formats_rust) removed. --- formats_rust/io_local_var2.ksy | 20 -------- formats_rust/read_bytes.ksy | 9 ---- formats_rust/str_repeat.ksy | 8 --- formats_rust/switch_cast_parent.ksy | 28 ----------- formats_rust/test_parent.ksy | 36 -------------- spec/rust/tests/manual_read_bytes.rs | 25 ---------- spec/rust/tests/manual_str_repeat.rs | 25 ---------- spec/rust/tests/manual_switch_cast_parent.rs | 51 -------------------- spec/rust/tests/manual_test_parent.rs | 28 ----------- 9 files changed, 230 deletions(-) delete mode 100644 formats_rust/io_local_var2.ksy delete mode 100644 formats_rust/read_bytes.ksy delete mode 100644 formats_rust/str_repeat.ksy delete mode 100644 formats_rust/switch_cast_parent.ksy delete mode 100644 formats_rust/test_parent.ksy delete mode 100644 spec/rust/tests/manual_read_bytes.rs delete mode 100644 spec/rust/tests/manual_str_repeat.rs delete mode 100644 spec/rust/tests/manual_switch_cast_parent.rs delete mode 100644 spec/rust/tests/manual_test_parent.rs diff --git a/formats_rust/io_local_var2.ksy b/formats_rust/io_local_var2.ksy deleted file mode 100644 index a51166945..000000000 --- a/formats_rust/io_local_var2.ksy +++ /dev/null @@ -1,20 +0,0 @@ -meta: - id: io_local_var2 -seq: - - id: some_header - size: 10 - - id: files - size: 80 - type: file_entry -types: - file_entry: - seq: - - id: ofs_body - type: u1 - - id: len_body - type: u1 - instances: - body: - io: _root._io - pos: ofs_body - size: len_body \ No newline at end of file diff --git a/formats_rust/read_bytes.ksy b/formats_rust/read_bytes.ksy deleted file mode 100644 index 382fba24e..000000000 --- a/formats_rust/read_bytes.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: read_bytes -seq: - - id: len - type: u1 - - id: val - size: len - - id: padding - size: 2 diff --git a/formats_rust/str_repeat.ksy b/formats_rust/str_repeat.ksy deleted file mode 100644 index 60d3681ba..000000000 --- a/formats_rust/str_repeat.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: str_repeat -seq: - - id: entries - type: str - size: 4 - repeat: eos - encoding: UTF-8 diff --git a/formats_rust/switch_cast_parent.ksy b/formats_rust/switch_cast_parent.ksy deleted file mode 100644 index 21565383a..000000000 --- a/formats_rust/switch_cast_parent.ksy +++ /dev/null @@ -1,28 +0,0 @@ -meta: - id: switch_cast_parent -seq: - - id: opcodes - type: opcode - repeat: eos - -types: - opcode: - seq: - - id: code - type: u1 - - id: body - type: - switch-on: code - cases: - 73: intval - 83: strval - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/test_parent.ksy b/formats_rust/test_parent.ksy deleted file mode 100644 index 787f24995..000000000 --- a/formats_rust/test_parent.ksy +++ /dev/null @@ -1,36 +0,0 @@ -meta: - id: test_parent -seq: - - id: root_byte - type: u1 - - id: child - type: child_struct -types: - child_struct: - seq: - - id: child_byte - type: u1 - - id: child2 - type: child2_struct - repeat: expr - repeat-expr: _root.root_byte - types: - child2_struct: - seq: - - id: child2_byte - type: u1 - repeat: expr - repeat-expr: _parent.child_byte - - id: child3_struct - type: child3_struct - repeat: expr - repeat-expr: _parent._parent.root_byte - types: - child3_struct: - seq: - - id: child3_byte - type: u1 - repeat: expr - repeat-expr: _parent._parent._parent.root_byte - - diff --git a/spec/rust/tests/manual_read_bytes.rs b/spec/rust/tests/manual_read_bytes.rs deleted file mode 100644 index eea2a816b..000000000 --- a/spec/rust/tests/manual_read_bytes.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::read_bytes::*; - -#[test] -fn basic_parse() { - let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = ReadBytes::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(1, *r.len()); - assert_eq!(vec![7], *r.val()); - assert_eq!(vec![0x2, 0x40], *r.padding()); -} diff --git a/spec/rust/tests/manual_str_repeat.rs b/spec/rust/tests/manual_str_repeat.rs deleted file mode 100644 index 0d65bdf89..000000000 --- a/spec/rust/tests/manual_str_repeat.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::str_repeat::*; - -#[test] -fn basic_parse() { - let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = StrRepeat::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!("foo|", r.entries()[0]); - assert_eq!("bar|", r.entries()[1]); - assert_eq!("baz@", r.entries()[2]); -} diff --git a/spec/rust/tests/manual_switch_cast_parent.rs b/spec/rust/tests/manual_switch_cast_parent.rs deleted file mode 100644 index 756bdf7da..000000000 --- a/spec/rust/tests/manual_switch_cast_parent.rs +++ /dev/null @@ -1,51 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::switch_cast_parent::*; - -#[test] -fn basic_parse() { - let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = SwitchCastParent::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(4, r.opcodes().len()); - - assert_eq!(0x53, *r.opcodes()[0].code()); - if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!("foobar", *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Strval"); - } - - assert_eq!(0x49, *r.opcodes()[1].code()); - if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(66, *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Intval"); - } - - assert_eq!(0x49, *r.opcodes()[2].code()); - if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Intval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(55, *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Intval"); - } - - assert_eq!(0x53, *r.opcodes()[3].code()); - if let Some(SwitchCastParent_Opcode_Body::SwitchCastParent_Opcode_Strval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!("", *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Strval"); - }; -} \ No newline at end of file diff --git a/spec/rust/tests/manual_test_parent.rs b/spec/rust/tests/manual_test_parent.rs deleted file mode 100644 index 637e3f3af..000000000 --- a/spec/rust/tests/manual_test_parent.rs +++ /dev/null @@ -1,28 +0,0 @@ -#![allow(dead_code)] -use std::{fs, rc::Rc}; - -extern crate kaitai; -use self::kaitai::*; -mod formats; -use formats::test_parent::*; - -#[test] -fn basic_parse() { - let bytes = fs::read("../../src/switch_integers.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res = TestParent::read_into(&_io, None, None); - let r : Rc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(1, *r.root_byte()); - assert_eq!(7, *r.child().child_byte()); - assert_eq!(1, r.child().child2().len()); - assert_eq!(vec![2, 64, 64, 4, 55, 19, 0], *r.child().child2()[0].child2_byte()); - assert_eq!(1, r.child().child2()[0].child3_struct().len()); - assert_eq!(vec![0], *r.child().child2()[0].child3_struct()[0].child3_byte()); -} From 0522e2ec6c3b751d84fc723a66e0b663d59b60a9 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Fri, 3 Feb 2023 12:37:11 +0800 Subject: [PATCH 147/198] use importList for global imports. --- .../specgenerators/RustSG.scala | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 2f5846d48..15a3db77d 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -23,22 +23,20 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs s"use crate::" else s"use " - var imports = "" - spec.extraImports.foreach{ name => imports = s"$imports\n${use_mod}formats::$name::*;" } + + importList.add("#![allow(unused_variables)]") + importList.add("#![allow(unused_assignments)]") + importList.add("#![allow(overflowing_literals)]") + importList.add("use std::{fs, rc::Rc};") + importList.add("extern crate kaitai;") + importList.add("use self::kaitai::*;") + importList.add("mod formats;") + importList.add(s"${use_mod}formats::${spec.id}::*;") + + spec.extraImports.foreach{ name => importList.add(s"${use_mod}formats::$name::*;") } val code = - s"""|#![allow(unused_variables)] - |#![allow(unused_assignments)] - |#![allow(overflowing_literals)] - |use std::{fs, rc::Rc}; - | - |extern crate kaitai; - |use self::kaitai::*; - |mod formats; - |${use_mod}formats::${spec.id}::*; - |$imports - | - |#[test] + s"""|#[test] |fn test_${spec.id}() { | let bytes = fs::read("../../src/${spec.data}").unwrap(); | let _io = BytesReader::from(bytes); @@ -135,6 +133,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def results: String = { "// " + AUTOGEN_COMMENT + "\n\n" + + importList.toList.mkString("", "\n", "\n") + "\n" + out.result } From a2b2421564f9b6b235b028dcc8a13ae94ec21cda Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sun, 5 Feb 2023 14:08:13 +0800 Subject: [PATCH 148/198] floating_points test fixed. --- formats_rust/floating_points.ksy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formats_rust/floating_points.ksy b/formats_rust/floating_points.ksy index a30880144..571165e0b 100644 --- a/formats_rust/floating_points.ksy +++ b/formats_rust/floating_points.ksy @@ -14,7 +14,7 @@ seq: type: f4 instances: single_value_plus_int: - value: single_value + 1.0 # float + int doesn't work on rust + value: single_value + 1 single_value_plus_float: value: single_value + 0.5 double_value_plus_float: From 0393f87c98191eb7f09e0aeda5f0e07f0896235e Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Sun, 5 Feb 2023 17:16:02 +0800 Subject: [PATCH 149/198] js_signed_right_shift added. --- formats_rust/js_signed_right_shift.ksy | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 formats_rust/js_signed_right_shift.ksy diff --git a/formats_rust/js_signed_right_shift.ksy b/formats_rust/js_signed_right_shift.ksy new file mode 100644 index 000000000..0a0fca172 --- /dev/null +++ b/formats_rust/js_signed_right_shift.ksy @@ -0,0 +1,7 @@ +meta: + id: js_signed_right_shift +instances: + should_be_40000000: + value: '0x80000000 >> 1' + should_be_a00000: + value: '0xa0000000 >> 8' From 61e52b7a641f59fc81df00726a5c78a1c20e133e Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Thu, 9 Feb 2023 14:06:40 +0800 Subject: [PATCH 150/198] Rc -> OptRc --- spec/rust/tests/manual_debug_array_user.rs | 4 ++-- spec/rust/tests/manual_debug_enum_name.rs | 10 ---------- spec/rust/tests/manual_imports_abs_abs.rs | 8 ++++---- spec/rust/tests/manual_imports_abs_rel.rs | 10 +++++----- spec/rust/tests/manual_opaque_external_type.rs | 12 ++++++------ .../tests/manual_opaque_external_type_02_parent.rs | 10 +++++----- spec/rust/tests/manual_opaque_with_param.rs | 8 ++++---- spec/rust/tests/manual_params_def.rs | 4 ++-- spec/rust/tests/manual_str_literals.rs | 4 ++-- spec/rust/tests/manual_switch_cast.rs | 4 ++-- spec/rust/tests/manual_to_string_custom.rs | 4 ++-- spec/rust/tests/manual_type_ternary_opaque.rs | 12 ++++++------ spec/rust/tests/test_cast_to_imported.rs | 8 ++++---- spec/rust/tests/test_expr_int_div.rs | 6 +++--- spec/rust/tests/test_imports_circular_a.rs | 12 ++++++------ spec/rust/tests/test_optional_id.rs | 4 ++-- spec/rust/tests/test_repeat_eos_struct.rs | 4 ++-- spec/rust/tests/test_repeat_n_struct.rs | 6 +++--- spec/rust/tests/test_switch_manual_enum_invalid.rs | 4 ++-- .../tests/test_switch_manual_enum_invalid_else.rs | 12 +++++------- spec/rust/tests/test_switch_manual_int_size_eos.rs | 4 ++-- spec/rust/tests/test_type_ternary_2nd_falsy.rs | 8 +++++--- .../testtranslator/specgenerators/RustSG.scala | 8 ++++---- 23 files changed, 78 insertions(+), 88 deletions(-) delete mode 100644 spec/rust/tests/manual_debug_enum_name.rs diff --git a/spec/rust/tests/manual_debug_array_user.rs b/spec/rust/tests/manual_debug_array_user.rs index 1ed28ad83..5df45afce 100644 --- a/spec/rust/tests/manual_debug_array_user.rs +++ b/spec/rust/tests/manual_debug_array_user.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = DebugArrayUser::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/manual_debug_enum_name.rs b/spec/rust/tests/manual_debug_enum_name.rs deleted file mode 100644 index bae589ce4..000000000 --- a/spec/rust/tests/manual_debug_enum_name.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(dead_code)] -extern crate kaitai; -mod formats; -use formats::debug_enum_name::*; - -#[test] -fn basic_parse() { - let r = DebugEnumName::default(); - assert_eq!(*r.test_type().field2(), 0); -} diff --git a/spec/rust/tests/manual_imports_abs_abs.rs b/spec/rust/tests/manual_imports_abs_abs.rs index a6b854d47..9f6d97819 100644 --- a/spec/rust/tests/manual_imports_abs_abs.rs +++ b/spec/rust/tests/manual_imports_abs_abs.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn test_params_def() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = ImportsAbsAbs::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -20,6 +20,6 @@ fn test_params_def() { } assert_eq!(*r.one(), 80); - assert_eq!(*r.two().as_ref().unwrap().one(), 65); - assert_eq!(*r.two().as_ref().unwrap().two().as_ref().unwrap().one(), 67); + assert_eq!(*r.two().one(), 65); + assert_eq!(*r.two().two().one(), 67); } diff --git a/spec/rust/tests/manual_imports_abs_rel.rs b/spec/rust/tests/manual_imports_abs_rel.rs index 446e78606..d50866599 100644 --- a/spec/rust/tests/manual_imports_abs_rel.rs +++ b/spec/rust/tests/manual_imports_abs_rel.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -7,11 +7,11 @@ use formats::imports_abs_rel::*; #[test] -fn test_params_def() { +fn test_imports_abs_rel() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = ImportsAbsRel::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -20,6 +20,6 @@ fn test_params_def() { } assert_eq!(*r.one(), 80); - assert_eq!(*r.two().as_ref().unwrap().one(), 65); - assert_eq!(*r.two().as_ref().unwrap().two().as_ref().unwrap().one(), 67); + assert_eq!(*r.two().one(), 65); + assert_eq!(*r.two().two().one(), 67); } diff --git a/spec/rust/tests/manual_opaque_external_type.rs b/spec/rust/tests/manual_opaque_external_type.rs index bded9287b..7a4a4f929 100644 --- a/spec/rust/tests/manual_opaque_external_type.rs +++ b/spec/rust/tests/manual_opaque_external_type.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -6,11 +6,11 @@ mod formats; use formats::opaque_external_type::*; #[test] -fn test_term_strz() { +fn test_opaque_external_type() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res = OpaqueExternalType::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -18,7 +18,7 @@ fn test_term_strz() { r = res.unwrap(); } - assert_eq!(*r.one().as_ref().unwrap().s1(), "foo"); - assert_eq!(*r.one().as_ref().unwrap().s2(), "bar"); - assert_eq!(*r.one().as_ref().unwrap().s3(), "|baz@"); + assert_eq!(*r.one().s1(), "foo"); + assert_eq!(*r.one().s2(), "bar"); + assert_eq!(*r.one().s3(), "|baz@"); } diff --git a/spec/rust/tests/manual_opaque_external_type_02_parent.rs b/spec/rust/tests/manual_opaque_external_type_02_parent.rs index cb33bfea5..2d5136561 100644 --- a/spec/rust/tests/manual_opaque_external_type_02_parent.rs +++ b/spec/rust/tests/manual_opaque_external_type_02_parent.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -10,7 +10,7 @@ fn test_term_strz() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res = OpaqueExternalType02Parent::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -18,7 +18,7 @@ fn test_term_strz() { r = res.unwrap(); } - assert_eq!(*r.parent().child().as_ref().unwrap().s1(), "foo"); - assert_eq!(*r.parent().child().as_ref().unwrap().s2(), "bar"); - assert_eq!(*r.parent().child().as_ref().unwrap().s3().s3(), "|baz@"); + assert_eq!(*r.parent().child().s1(), "foo"); + assert_eq!(*r.parent().child().s2(), "bar"); + assert_eq!(*r.parent().child().s3().s3(), "|baz@"); } diff --git a/spec/rust/tests/manual_opaque_with_param.rs b/spec/rust/tests/manual_opaque_with_param.rs index 98afb889d..b93f4066b 100644 --- a/spec/rust/tests/manual_opaque_with_param.rs +++ b/spec/rust/tests/manual_opaque_with_param.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -7,11 +7,11 @@ use formats::opaque_with_param::*; #[test] -fn test_params_def() { +fn test_opaque_with_param() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res = OpaqueWithParam::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -20,7 +20,7 @@ fn test_params_def() { } let one = r.one(); - let p = one.as_ref().unwrap(); + let p = one; assert_eq!(*p.buf(), "foo|b"); assert_eq!(*p.trailer(), 0x61); } diff --git a/spec/rust/tests/manual_params_def.rs b/spec/rust/tests/manual_params_def.rs index a4737f7f0..5ca854d31 100644 --- a/spec/rust/tests/manual_params_def.rs +++ b/spec/rust/tests/manual_params_def.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -12,7 +12,7 @@ fn test_params_def() { let _io = BytesReader::from(bytes); let f = |t: &mut ParamsDef| Ok(t.set_params(5, true)); let res = ParamsDef::read_into_with_init(&_io, None, None, &f); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/manual_str_literals.rs index f3bceb5f1..fd02d0a26 100644 --- a/spec/rust/tests/manual_str_literals.rs +++ b/spec/rust/tests/manual_str_literals.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = StrLiterals::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/manual_switch_cast.rs index 6ca70fc97..1d6fc972c 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/manual_switch_cast.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -12,7 +12,7 @@ fn basic_parse() { let _io = BytesReader::from(bytes); let res = SwitchCast::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/manual_to_string_custom.rs b/spec/rust/tests/manual_to_string_custom.rs index 9b03f3c84..0231d198c 100644 --- a/spec/rust/tests/manual_to_string_custom.rs +++ b/spec/rust/tests/manual_to_string_custom.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn basic_parse() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res = ToStringCustom::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/manual_type_ternary_opaque.rs b/spec/rust/tests/manual_type_ternary_opaque.rs index 04c587dd7..d9b0524b4 100644 --- a/spec/rust/tests/manual_type_ternary_opaque.rs +++ b/spec/rust/tests/manual_type_ternary_opaque.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -6,11 +6,11 @@ mod formats; use formats::type_ternary_opaque::*; #[test] -fn test_term_strz() { +fn test_type_ternary_opaque() { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res = TypeTernaryOpaque::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -19,7 +19,7 @@ fn test_term_strz() { } let dif = r.dif().unwrap(); - assert_eq!(*dif.as_ref().unwrap().s1(), "foo"); - assert_eq!(*dif.as_ref().unwrap().s2(), "bar"); - assert_eq!(*dif.as_ref().unwrap().s3(), "|baz@"); + assert_eq!(*dif.s1(), "foo"); + assert_eq!(*dif.s2(), "bar"); + assert_eq!(*dif.s3(), "|baz@"); } diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index efa855a50..1fc016e85 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -10,7 +10,7 @@ fn test_cast_to_imported() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = CastToImported::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -18,6 +18,6 @@ fn test_cast_to_imported() { r = res.unwrap(); } - assert_eq!(*(*(*r.one()).as_ref().unwrap()).one(), 80); - assert_eq!(*(*(*r.one_casted().unwrap()).as_ref().unwrap()).one(), 80); + assert_eq!(*(*(*r.one())).one(), 80); + assert_eq!(*(*(*r.one_casted().unwrap())).one(), 80); } diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index 1423cc8e0..0d4b9c482 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -1,7 +1,7 @@ #![allow(unused_variables)] #![allow(unused_assignments)] #![allow(overflowing_literals)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -13,8 +13,8 @@ use formats::expr_int_div::*; fn test_expr_int_div() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprIntDiv::read_into(&_io, None, None); - let r : Rc; + let res: KResult> = ExprIntDiv::read_into(&_io, None, None); + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index b101aa909..199323ec9 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -10,7 +10,7 @@ fn test_imports_circular_a() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = ImportsCircularA::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -19,8 +19,8 @@ fn test_imports_circular_a() { } assert_eq!(*r.code(), 80); - assert_eq!(*r.two().as_ref().unwrap().initial(), 65); - assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().code(), 67); - assert_eq!(*r.two().as_ref().unwrap().back_ref().as_ref().unwrap().two().as_ref().unwrap().initial(), 75); - assert_eq!(r.two().as_ref().unwrap().back_ref().as_ref().unwrap().two().as_ref().unwrap().back_ref().is_none(), true); + assert_eq!(*r.two().initial(), 65); + assert_eq!(*r.two().back_ref().code(), 67); + assert_eq!(*r.two().back_ref().two().initial(), 75); + assert_eq!(r.two().back_ref().two().back_ref().is_none(), true); } diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs index 8cd514d56..10b71b162 100644 --- a/spec/rust/tests/test_optional_id.rs +++ b/spec/rust/tests/test_optional_id.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn basic_parse() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = OptionalId::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index d29de6843..9ccb5a450 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn test_repeat_eos_struct() { let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res = RepeatEosStruct::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index 4588dba19..7ffd9eb64 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -1,7 +1,7 @@ #![allow(unused_variables)] #![allow(unused_assignments)] #![allow(overflowing_literals)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -13,8 +13,8 @@ use formats::repeat_n_struct::*; fn test_repeat_n_struct() { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatNStruct::read_into(&_io, None, None); - let r : Rc; + let res: KResult> = RepeatNStruct::read_into(&_io, None, None); + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 32ef4e378..884b443cf 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn test_switch_manual_enum_invalid() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); let res = SwitchManualEnumInvalid::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index 71c5f49a1..515e92333 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -1,9 +1,7 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - #![allow(unused_variables)] #![allow(unused_assignments)] #![allow(overflowing_literals)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -15,8 +13,8 @@ use formats::switch_manual_enum_invalid_else::*; fn test_switch_manual_enum_invalid_else() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualEnumInvalidElse::read_into(&_io, None, None); - let r : Rc; + let res: KResult> = SwitchManualEnumInvalidElse::read_into(&_io, None, None); + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -27,8 +25,8 @@ fn test_switch_manual_enum_invalid_else() { assert_eq!(r.opcodes().len(), 2); let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); - assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value().unwrap(), 123); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value().unwrap(), 123); let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); - assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value().unwrap(), 123); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value().unwrap(), 123); } diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 27adbe2bc..32fcaa386 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -1,5 +1,5 @@ #![allow(dead_code)] -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn test_switch_manual_int_size_eos() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let _io = BytesReader::from(bytes); let res = SwitchManualIntSizeEos::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index 707991312..5a388338c 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -1,4 +1,4 @@ -use std::{fs, rc::Rc}; +use std::fs; extern crate kaitai; use self::kaitai::*; @@ -11,7 +11,7 @@ fn test_type_ternary_2nd_falsy() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let _io = BytesReader::from(bytes); let res = TypeTernary2ndFalsy::read_into(&_io, None, None); - let r : Rc; + let r : OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -27,7 +27,9 @@ fn test_type_ternary_2nd_falsy() { assert_eq!(*r.v_str_w_zero().unwrap(), "0"); assert_eq!(r.v_str_w_zero().unwrap().len(), 1); assert_eq!(*r.ut().m(), 7); - assert_eq!(*r.v_null_ut().unwrap().m(), 0); + assert_eq!(r.v_null_ut().unwrap().is_none(), true); + // v_null_ut() always uninited + // assert_eq!(*r.v_null_ut().unwrap().m(), 0); assert_eq!(*r.v_str_empty().unwrap(), ""); assert_eq!(r.v_str_empty().unwrap().len(), 0); assert_eq!(r.int_array().len(), 2); diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 15a3db77d..e415c3710 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -27,7 +27,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs importList.add("#![allow(unused_variables)]") importList.add("#![allow(unused_assignments)]") importList.add("#![allow(overflowing_literals)]") - importList.add("use std::{fs, rc::Rc};") + importList.add("use std::fs;") importList.add("extern crate kaitai;") importList.add("use self::kaitai::*;") importList.add("mod formats;") @@ -40,8 +40,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs |fn test_${spec.id}() { | let bytes = fs::read("../../src/${spec.data}").unwrap(); | let _io = BytesReader::from(bytes); - | let res: KResult> = $className::read_into(&_io, None, None); - | let r : Rc<$className>; + | let res: KResult> = $className::read_into(&_io, None, None); + | let r : OptRc<$className>; | | if let Err(err) = res {""".stripMargin out.puts(code) @@ -185,5 +185,5 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } def translateAct(x: Ast.expr): String = - translate(x).replace(s"self.${Main.INIT_OBJ_NAME}().as_ref().unwrap()", "r") + translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") } From 86039688896d7ef9739c1b47737f021f57a5c497 Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Sat, 30 Jul 2022 11:01:36 +0100 Subject: [PATCH 151/198] Added rounding to elapsed time to 0.1s to reduce test result diffs --- aggregate/test_result.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/aggregate/test_result.rb b/aggregate/test_result.rb index 1e1e1262c..2c342b79f 100644 --- a/aggregate/test_result.rb +++ b/aggregate/test_result.rb @@ -30,7 +30,14 @@ def to_h def initialize(name, status, elapsed, failure = nil) @name = name @status = status - @elapsed = elapsed + + # intentionally rounding elapsed time to 0.1s granularity here: it + # helps to reduce diffs drastically, otherwise we're bound to have + # test results constantly jumping from 0 to 0.001 all the time, + # while in reality there were absolutely no changes in test + # execution + @elapsed = elapsed.round(1) + @failure = failure end From 708fc59ba6e7523d49359b219cadae140b782cf1 Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Mon, 1 Aug 2022 17:49:06 +0100 Subject: [PATCH 152/198] Translator: update to consume 0.11-SNAPSHOT compiler --- translator/build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translator/build.sbt b/translator/build.sbt index f063ae51b..d4b906ec1 100644 --- a/translator/build.sbt +++ b/translator/build.sbt @@ -8,7 +8,7 @@ resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repos resolvers += Resolver.sonatypeRepo("public") libraryDependencies ++= Seq( - "io.kaitai" % "kaitai-struct-compiler_2.12" % "0.10-SNAPSHOT", + "io.kaitai" % "kaitai-struct-compiler_2.12" % "0.11-SNAPSHOT", "com.github.scopt" % "scopt_2.12" % "3.7.1", "org.yaml" % "snakeyaml" % "1.16" ) From f62f0429a3a0b4a20e26f61b644f1f00c4e371e1 Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Mon, 1 Aug 2022 17:49:32 +0100 Subject: [PATCH 153/198] Translator: update with zeroCopySubstream to make compatible with modern compiler --- .../scala/io/kaitai/struct/testtranslator/TestTranslator.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index 19b99edc1..336bdff87 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -82,6 +82,7 @@ class TestTranslator(options: CLIOptions) { encoding = None, forceDebug = false, opaqueTypes = None, + zeroCopySubstream = None, imports = List() ), DocSpec.EMPTY, From 59ead5370408f25ae64b340006ba5b39efc42652 Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Sun, 7 Aug 2022 12:58:28 +0100 Subject: [PATCH 154/198] Even better nonlatin --- formats_err/meta_bad_id3.ksy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/formats_err/meta_bad_id3.ksy b/formats_err/meta_bad_id3.ksy index 306ca59ea..110628d90 100644 --- a/formats_err/meta_bad_id3.ksy +++ b/formats_err/meta_bad_id3.ksy @@ -1,5 +1,5 @@ # meta_bad_id3.ksy: /meta/id: -# error: invalid meta ID: 'all_good_but_ñòñlåtïn', expected /^[a-z][a-z0-9_]*$/ +# error: invalid meta ID: 'all_good_but_ñòńłåƫïȵ', expected /^[a-z][a-z0-9_]*$/ # meta: - id: all_good_but_ñòñlåtïn + id: all_good_but_ñòńłåƫïȵ From a4554a00f913d342f14c42ba73a83c96a16ca4ea Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Sun, 7 Aug 2022 14:04:59 +0100 Subject: [PATCH 155/198] Added many_type_validator.ksy: test multiple errors on type validation stage at once --- formats_err/many_type_validator.ksy | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 formats_err/many_type_validator.ksy diff --git a/formats_err/many_type_validator.ksy b/formats_err/many_type_validator.ksy new file mode 100644 index 000000000..53908f7d9 --- /dev/null +++ b/formats_err/many_type_validator.ksy @@ -0,0 +1,22 @@ +# many_type_validator.ksy: /seq/0/if: +# error: invalid type: expected boolean, got Int1Type(true) +# +# many_type_validator.ksy: /seq/2/if: +# error: can't use comparison operator Gt on enums +# +meta: + id: many_type_validator +seq: + - id: foo_int + type: u1 + if: 5 + - id: foo_enum + type: u1 + enum: animal + - id: bar + type: u1 + if: 'foo_enum > animal::cat' +enums: + animal: + 1: cat + 2: dog From 71fb201df3fc1e31181441e2b5517233e8480157 Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Sun, 7 Aug 2022 14:49:38 +0100 Subject: [PATCH 156/198] meta_bad_key.ksy: fix error message, adding ks-zero-copy-substream --- formats_err/meta_bad_key.ksy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formats_err/meta_bad_key.ksy b/formats_err/meta_bad_key.ksy index eaf8411f2..60a8e7367 100644 --- a/formats_err/meta_bad_key.ksy +++ b/formats_err/meta_bad_key.ksy @@ -1,5 +1,5 @@ # meta_bad_key.ksy: /meta/foo: -# error: unknown key found, expected: application, bit-endian, encoding, endian, file-extension, id, imports, ks-debug, ks-opaque-types, ks-version, license, tags, title, xref +# error: unknown key found, expected: application, bit-endian, encoding, endian, file-extension, id, imports, ks-debug, ks-opaque-types, ks-version, ks-zero-copy-substream, license, tags, title, xref # meta: id: meta_bad_key From 01f0d3f7125abcb5dab2d8025a80bf13869b3105 Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Sun, 7 Aug 2022 17:07:12 +0100 Subject: [PATCH 157/198] attr_invalid_switch_inner.ksy: should only report 1 problem on `/seq/1/size` level --- formats_err/attr_invalid_switch_inner.ksy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formats_err/attr_invalid_switch_inner.ksy b/formats_err/attr_invalid_switch_inner.ksy index c6546b16f..ef1173b33 100644 --- a/formats_err/attr_invalid_switch_inner.ksy +++ b/formats_err/attr_invalid_switch_inner.ksy @@ -1,4 +1,4 @@ -# attr_invalid_switch_inner.ksy: /seq/1/type/cases/IntNum(42)/size: +# attr_invalid_switch_inner.ksy: /seq/1/size: # error: invalid type: expected integer, got CalcBooleanType # meta: From 583d73ad9a7fe73efbb172146038f9b3450141be Mon Sep 17 00:00:00 2001 From: Mikhail Yakshin Date: Sun, 7 Aug 2022 17:08:02 +0100 Subject: [PATCH 158/198] Added type_unknown_many, showcasing several problems detected in one pass in type/enum resolution precompile step --- formats_err/type_unknown_many.ksy | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 formats_err/type_unknown_many.ksy diff --git a/formats_err/type_unknown_many.ksy b/formats_err/type_unknown_many.ksy new file mode 100644 index 000000000..f266fa4b8 --- /dev/null +++ b/formats_err/type_unknown_many.ksy @@ -0,0 +1,20 @@ +# type_unknown_many.ksy: /seq/0: +# error: unable to find type 'some_unknown_name', searching from type_unknown_many +# +# type_unknown_many.ksy: /seq/1: +# error: unable to find type 'also_unknown_name', searching from type_unknown_many +# +# type_unknown_many.ksy: /seq/2: +# error: unable to find enum 'unknown_enum', searching from type_unknown_many +# +meta: + id: type_unknown_many + ks-opaque-types: false +seq: + - id: foo + type: some_unknown_name + - id: bar + type: also_unknown_name + - id: baz + type: u1 + enum: unknown_enum From 6e1938a040f592adc21f738324afe84d74f8c9fa Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 14 Mar 2023 14:59:49 +0700 Subject: [PATCH 159/198] autogenerated rust tests added. --- .gitignore | 2 +- build-rust-formats | 19 --- build-rust-tests | 71 --------- formats_rust/bcd_user_type_be.ksy | 136 ------------------ formats_rust/bcd_user_type_le.ksy | 136 ------------------ formats_rust/bits_byte_aligned.ksy | 24 ---- formats_rust/bits_enum.ksy | 21 --- formats_rust/bits_seq_endian_combo.ksy | 19 --- formats_rust/bits_shift_by_b32_le.ksy | 14 -- formats_rust/bits_shift_by_b64_le.ksy | 14 -- formats_rust/bits_signed_res_b32_be.ksy | 7 - formats_rust/bits_signed_res_b32_le.ksy | 7 - formats_rust/bits_signed_shift_b32_le.ksy | 11 -- formats_rust/bits_signed_shift_b64_le.ksy | 11 -- formats_rust/bits_simple.ksy | 42 ------ formats_rust/bits_simple_le.ksy | 43 ------ formats_rust/bits_unaligned_b32_be.ksy | 10 -- formats_rust/bits_unaligned_b32_le.ksy | 10 -- formats_rust/bits_unaligned_b64_be.ksy | 10 -- formats_rust/bits_unaligned_b64_le.ksy | 10 -- formats_rust/buffered_struct.ksy | 23 --- formats_rust/bytes_pad_term.ksy | 18 --- formats_rust/cast_nested.ksy | 36 ----- formats_rust/cast_to_imported.ksy | 10 -- formats_rust/cast_to_top.ksy | 14 -- formats_rust/combine_bool.ksy | 10 -- formats_rust/combine_bytes.ksy | 27 ---- formats_rust/combine_enum.ksy | 17 --- formats_rust/combine_str.ksy | 44 ------ formats_rust/debug_0.ksy | 12 -- formats_rust/debug_array_user.ksy | 17 --- formats_rust/debug_enum_name.ksy | 37 ----- formats_rust/debug_switch_user.ksy | 22 --- formats_rust/default_big_endian.ksy | 6 - formats_rust/default_bit_endian_mod.ksy | 30 ---- .../default_endian_expr_exception.ksy | 30 ---- .../default_endian_expr_inherited.ksy | 42 ------ formats_rust/default_endian_expr_is_be.ksy | 40 ------ formats_rust/default_endian_expr_is_le.ksy | 28 ---- formats_rust/default_endian_mod.ksy | 28 ---- formats_rust/docstrings.ksy | 31 ---- formats_rust/docstrings_docref.ksy | 26 ---- formats_rust/docstrings_docref_multi.ksy | 7 - formats_rust/enum_0.ksy | 15 -- formats_rust/enum_1.ksy | 26 ---- formats_rust/enum_deep.ksy | 24 ---- formats_rust/enum_deep_literals.ksy | 29 ---- formats_rust/enum_fancy.ksy | 21 --- formats_rust/enum_for_unknown_id.ksy | 11 -- formats_rust/enum_if.ksy | 40 ------ formats_rust/enum_import.ksy | 13 -- formats_rust/enum_int_range_s.ksy | 21 --- formats_rust/enum_int_range_u.ksy | 17 --- formats_rust/enum_invalid.ksy | 13 -- formats_rust/enum_long_range_s.ksy | 37 ----- formats_rust/enum_long_range_u.ksy | 25 ---- formats_rust/enum_negative.ksy | 13 -- formats_rust/enum_of_value_inst.ksy | 21 --- formats_rust/enum_to_i.ksy | 26 ---- formats_rust/enum_to_i_class_border_1.ksy | 29 ---- formats_rust/enum_to_i_class_border_2.ksy | 14 -- formats_rust/eof_exception_bytes.ksy | 6 - formats_rust/eof_exception_u4.ksy | 8 -- formats_rust/eos_exception_bytes.ksy | 11 -- formats_rust/eos_exception_u4.ksy | 13 -- formats_rust/expr_0.ksy | 11 -- formats_rust/expr_1.ksy | 15 -- formats_rust/expr_2.ksy | 57 -------- formats_rust/expr_3.ksy | 31 ---- formats_rust/expr_array.ksy | 50 ------- formats_rust/expr_bits.ksy | 43 ------ formats_rust/expr_bytes_cmp.ksy | 31 ---- formats_rust/expr_bytes_non_literal.ksy | 10 -- formats_rust/expr_bytes_ops.ksy | 34 ----- formats_rust/expr_calc_array_ops.ksy | 48 ------- formats_rust/expr_enum.ksy | 22 --- formats_rust/expr_if_int_ops.ksy | 17 --- formats_rust/expr_int_div.ksy | 20 --- formats_rust/expr_io_eof.ksy | 22 --- formats_rust/expr_io_pos.ksy | 21 --- formats_rust/expr_mod.ksy | 18 --- formats_rust/expr_ops_parens.ksy | 36 ----- formats_rust/expr_sizeof_type_0.ksy | 15 -- formats_rust/expr_sizeof_type_1.ksy | 24 ---- formats_rust/expr_sizeof_value_0.ksy | 28 ---- formats_rust/expr_sizeof_value_sized.ksy | 29 ---- formats_rust/expr_str_encodings.ksy | 44 ------ formats_rust/expr_str_ops.ksy | 42 ------ formats_rust/fixed_contents.ksy | 7 - formats_rust/fixed_struct.ksy | 91 ------------ formats_rust/float_to_i.ksy | 29 ---- formats_rust/floating_points.ksy | 21 --- formats_rust/for_rel_imports/imported_1.ksy | 9 -- formats_rust/for_rel_imports/imported_2.ksy | 5 - formats_rust/hello_world.ksy | 5 - formats_rust/if_instances.ksy | 9 -- formats_rust/if_struct.ksy | 35 ----- formats_rust/if_values.ksy | 17 --- formats_rust/imports0.ksy | 12 -- formats_rust/imports_abs.ksy | 9 -- formats_rust/imports_abs_abs.ksy | 12 -- formats_rust/imports_abs_rel.ksy | 12 -- formats_rust/imports_circular_a.ksy | 9 -- formats_rust/imports_circular_b.ksy | 10 -- formats_rust/imports_rel_1.ksy | 12 -- formats_rust/index_sizes.ksy | 16 --- formats_rust/index_to_param_eos.ksy | 24 ---- formats_rust/index_to_param_expr.ksy | 25 ---- formats_rust/index_to_param_until.ksy | 25 ---- formats_rust/instance_io_user.ksy | 32 ----- formats_rust/instance_std.ksy | 9 -- formats_rust/instance_std_array.ksy | 16 --- formats_rust/instance_user_array.ksy | 25 ---- formats_rust/integers.ksy | 58 -------- formats_rust/integers_double_overflow.ksy | 34 ----- formats_rust/integers_min_max.ksy | 44 ------ formats_rust/io_local_var.ksy | 26 ---- formats_rust/js_signed_right_shift.ksy | 7 - .../for_abs_imports/imported_and_abs.ksy | 9 -- .../for_abs_imports/imported_and_rel.ksy | 9 -- formats_rust/ks_path/imported_root.ksy | 5 - formats_rust/meta_tags.ksy | 7 - formats_rust/meta_xref.ksy | 6 - formats_rust/multiple_use.ksy | 22 --- formats_rust/nav_parent.ksy | 29 ---- formats_rust/nav_parent2.ksy | 38 ----- formats_rust/nav_parent3.ksy | 41 ------ formats_rust/nav_parent_false.ksy | 29 ---- formats_rust/nav_parent_false2.ksy | 12 -- formats_rust/nav_parent_override.ksy | 19 --- formats_rust/nav_parent_switch.ksy | 22 --- formats_rust/nav_parent_vs_value_inst.ksy | 18 --- formats_rust/nav_root.ksy | 29 ---- formats_rust/nested_same_name.ksy | 23 --- formats_rust/nested_same_name2.ksy | 33 ----- formats_rust/nested_type_param.ksy | 17 --- formats_rust/nested_types.ksy | 23 --- formats_rust/nested_types2.ksy | 40 ------ formats_rust/nested_types3.ksy | 31 ---- formats_rust/non_standard.ksy | 30 ---- formats_rust/opaque_external_type.ksy | 6 - .../opaque_external_type_02_child.ksy | 28 ---- .../opaque_external_type_02_parent.ksy | 12 -- formats_rust/opaque_with_param.ksy | 6 - formats_rust/optional_id.ksy | 6 - formats_rust/params_call_extra_parens.ksy | 15 -- formats_rust/params_call_short.ksy | 31 ---- formats_rust/params_def.ksy | 16 --- formats_rust/params_enum.ksy | 22 --- formats_rust/params_pass_array_int.ksy | 20 --- formats_rust/params_pass_array_str.ksy | 21 --- formats_rust/params_pass_array_usertype.ksy | 23 --- formats_rust/params_pass_bool.ksy | 39 ----- formats_rust/params_pass_usertype.ksy | 19 --- formats_rust/position_abs.ksy | 16 --- formats_rust/position_in_seq.ksy | 17 --- formats_rust/position_to_end.ksy | 14 -- formats_rust/process_coerce_bytes.ksy | 23 --- formats_rust/process_coerce_usertype1.ksy | 30 ---- formats_rust/process_coerce_usertype2.ksy | 30 ---- formats_rust/process_custom.ksy | 14 -- formats_rust/process_custom_no_args.ksy | 6 - formats_rust/process_repeat_bytes.ksy | 8 -- formats_rust/process_repeat_usertype.ksy | 17 --- formats_rust/process_rotate.ksy | 15 -- formats_rust/process_to_user.ksy | 14 -- formats_rust/process_xor4_const.ksy | 8 -- formats_rust/process_xor4_value.ksy | 8 -- formats_rust/process_xor_const.ksy | 9 -- formats_rust/process_xor_value.ksy | 9 -- formats_rust/recursive_one.ksy | 18 --- formats_rust/repeat_eos_bit.ksy | 6 - formats_rust/repeat_eos_struct.ksy | 14 -- formats_rust/repeat_eos_u4.ksy | 7 - formats_rust/repeat_n_struct.ksy | 17 --- formats_rust/repeat_n_strz.ksy | 11 -- formats_rust/repeat_n_strz_double.ksy | 16 --- formats_rust/repeat_until_calc_array_type.ksy | 22 --- formats_rust/repeat_until_complex.ksy | 33 ----- formats_rust/repeat_until_s4.ksy | 11 -- formats_rust/repeat_until_sized.ksy | 16 --- formats_rust/str_encodings.ksy | 28 ---- formats_rust/str_encodings_default.ksy | 32 ----- formats_rust/str_encodings_utf16.ksy | 47 ------ formats_rust/str_eos.ksy | 7 - formats_rust/str_literals.ksy | 13 -- formats_rust/str_literals2.ksy | 18 --- formats_rust/str_pad_term.ksy | 24 ---- formats_rust/str_pad_term_empty.ksy | 25 ---- formats_rust/switch_bytearray.ksy | 27 ---- formats_rust/switch_cast.ksy | 33 ----- formats_rust/switch_else_only.ksy | 22 --- formats_rust/switch_integers.ksy | 20 --- formats_rust/switch_integers2.ksy | 22 --- formats_rust/switch_manual_enum.ksy | 32 ----- formats_rust/switch_manual_enum_invalid.ksy | 33 ----- .../switch_manual_enum_invalid_else.ksy | 38 ----- formats_rust/switch_manual_int.ksy | 27 ---- formats_rust/switch_manual_int_else.ksy | 33 ----- formats_rust/switch_manual_int_size.ksy | 37 ----- formats_rust/switch_manual_int_size_else.ksy | 42 ------ formats_rust/switch_manual_int_size_eos.ksy | 42 ------ formats_rust/switch_manual_str.ksy | 29 ---- formats_rust/switch_manual_str_else.ksy | 35 ----- formats_rust/switch_multi_bool_ops.ksy | 23 --- formats_rust/switch_repeat_expr.ksy | 26 ---- formats_rust/switch_repeat_expr_invalid.ksy | 27 ---- formats_rust/term_bytes.ksy | 11 -- formats_rust/term_strz.ksy | 18 --- formats_rust/term_u1_val.ksy | 12 -- formats_rust/to_string_custom.ksy | 12 -- formats_rust/ts_packet_header.ksy | 38 ----- formats_rust/type_int_unary_op.ksy | 13 -- formats_rust/type_ternary.ksy | 23 --- formats_rust/type_ternary_2nd_falsy.ksy | 46 ------ formats_rust/type_ternary_opaque.ksy | 18 --- formats_rust/user_type.ksy | 15 -- formats_rust/valid_eq_str_encodings.ksy | 32 ----- formats_rust/valid_fail_anyof_int.ksy | 15 -- formats_rust/valid_fail_contents.ksy | 5 - formats_rust/valid_fail_eq_bytes.ksy | 6 - formats_rust/valid_fail_eq_int.ksy | 6 - formats_rust/valid_fail_eq_str.ksy | 8 -- formats_rust/valid_fail_expr.ksy | 11 -- formats_rust/valid_fail_inst.ksy | 11 -- formats_rust/valid_fail_max_int.ksy | 7 - formats_rust/valid_fail_min_int.ksy | 7 - formats_rust/valid_fail_range_bytes.ksy | 8 -- formats_rust/valid_fail_range_float.ksy | 8 -- formats_rust/valid_fail_range_int.ksy | 8 -- formats_rust/valid_fail_range_str.ksy | 11 -- formats_rust/valid_long.ksy | 51 ------- formats_rust/valid_not_parsed_if.ksy | 11 -- formats_rust/valid_optional_id.ksy | 10 -- formats_rust/valid_short.ksy | 40 ------ formats_rust/valid_switch.ksy | 13 -- formats_rust/yaml_ints.ksy | 12 -- formats_rust/zlib_surrounded.ksy | 16 --- formats_rust/zlib_with_header_78.ksy | 6 - spec/rust/Cargo.toml | 4 +- spec/rust/build.rs | 10 +- spec/rust/{tests => }/formats/custom_fx.rs | 0 .../{tests => }/formats/custom_fx_no_args.rs | 0 spec/rust/{tests => }/formats/my_custom_fx.rs | 0 spec/rust/tests/test_bcd_user_type_be.rs | 31 ++++ spec/rust/tests/test_bcd_user_type_le.rs | 31 ++++ spec/rust/tests/test_bits_byte_aligned.rs | 34 +++++ spec/rust/tests/test_bits_enum.rs | 28 ++++ spec/rust/tests/test_bits_seq_endian_combo.rs | 33 +++++ spec/rust/tests/test_bits_shift_by_b32_le.rs | 27 ++++ spec/rust/tests/test_bits_shift_by_b64_le.rs | 27 ++++ .../rust/tests/test_bits_signed_res_b32_be.rs | 26 ++++ .../rust/tests/test_bits_signed_res_b32_le.rs | 26 ++++ .../tests/test_bits_signed_shift_b32_le.rs | 27 ++++ .../tests/test_bits_signed_shift_b64_le.rs | 27 ++++ spec/rust/tests/test_bits_simple.rs | 39 +++++ spec/rust/tests/test_bits_simple_le.rs | 39 +++++ spec/rust/tests/test_bits_unaligned_b32_be.rs | 28 ++++ spec/rust/tests/test_bits_unaligned_b32_le.rs | 28 ++++ spec/rust/tests/test_bits_unaligned_b64_be.rs | 28 ++++ spec/rust/tests/test_bits_unaligned_b64_le.rs | 28 ++++ spec/rust/tests/test_buffered_struct.rs | 32 +++++ spec/rust/tests/test_bytes_pad_term.rs | 29 ++++ spec/rust/tests/test_cast_nested.rs | 29 ++++ spec/rust/tests/test_cast_to_imported.rs | 2 +- spec/rust/tests/test_cast_to_top.rs | 28 ++++ spec/rust/tests/test_combine_bool.rs | 27 ++++ spec/rust/tests/test_combine_bytes.rs | 35 +++++ spec/rust/tests/test_combine_enum.rs | 28 ++++ spec/rust/tests/test_combine_str.rs | 40 ++++++ .../{manual_debug_0.rs => test_debug_0.rs} | 2 +- ...array_user.rs => test_debug_array_user.rs} | 2 +- spec/rust/tests/test_debug_switch_user.rs | 27 ++++ spec/rust/tests/test_default_big_endian.rs | 26 ++++ .../rust/tests/test_default_bit_endian_mod.rs | 29 ++++ .../test_default_endian_expr_exception.rs | 24 ++++ .../test_default_endian_expr_inherited.rs | 40 ++++++ .../tests/test_default_endian_expr_is_be.rs | 43 ++++++ .../tests/test_default_endian_expr_is_le.rs | 37 +++++ spec/rust/tests/test_default_endian_mod.rs | 28 ++++ spec/rust/tests/test_docstrings.rs | 25 ++++ spec/rust/tests/test_docstrings_docref.rs | 25 ++++ .../tests/test_docstrings_docref_multi.rs | 25 ++++ spec/rust/tests/test_enum_0.rs | 27 ++++ spec/rust/tests/test_enum_1.rs | 27 ++++ spec/rust/tests/test_enum_deep.rs | 27 ++++ spec/rust/tests/test_enum_deep_literals.rs | 27 ++++ spec/rust/tests/test_enum_fancy.rs | 27 ++++ spec/rust/tests/test_enum_for_unknown_id.rs | 27 ++++ spec/rust/tests/test_enum_if.rs | 32 +++++ spec/rust/tests/test_enum_import.rs | 29 ++++ spec/rust/tests/test_enum_int_range_s.rs | 28 ++++ spec/rust/tests/test_enum_int_range_u.rs | 27 ++++ spec/rust/tests/test_enum_invalid.rs | 28 ++++ spec/rust/tests/test_enum_long_range_s.rs | 32 +++++ spec/rust/tests/test_enum_long_range_u.rs | 29 ++++ spec/rust/tests/test_enum_negative.rs | 27 ++++ spec/rust/tests/test_enum_of_value_inst.rs | 29 ++++ spec/rust/tests/test_enum_to_i.rs | 32 +++++ .../tests/test_enum_to_i_class_border_1.rs | 29 ++++ spec/rust/tests/test_eof_exception_bytes.rs | 24 ++++ spec/rust/tests/test_eof_exception_u4.rs | 24 ++++ spec/rust/tests/test_eos_exception_bytes.rs | 24 ++++ spec/rust/tests/test_eos_exception_u4.rs | 24 ++++ spec/rust/tests/test_expr_0.rs | 27 ++++ spec/rust/tests/test_expr_1.rs | 29 ++++ spec/rust/tests/test_expr_2.rs | 42 ++++++ spec/rust/tests/test_expr_3.rs | 37 +++++ spec/rust/tests/test_expr_array.rs | 40 ++++++ spec/rust/tests/test_expr_bits.rs | 35 +++++ spec/rust/tests/test_expr_bytes_cmp.rs | 35 +++++ .../rust/tests/test_expr_bytes_non_literal.rs | 28 ++++ spec/rust/tests/test_expr_bytes_ops.rs | 41 ++++++ spec/rust/tests/test_expr_calc_array_ops.rs | 43 ++++++ spec/rust/tests/test_expr_enum.rs | 28 ++++ spec/rust/tests/test_expr_if_int_ops.rs | 27 ++++ spec/rust/tests/test_expr_int_div.rs | 2 +- spec/rust/tests/test_expr_io_eof.rs | 29 ++++ spec/rust/tests/test_expr_io_pos.rs | 31 ++++ spec/rust/tests/test_expr_mod.rs | 31 ++++ spec/rust/tests/test_expr_ops_parens.rs | 34 +++++ spec/rust/tests/test_expr_sizeof_type_0.rs | 26 ++++ spec/rust/tests/test_expr_sizeof_type_1.rs | 27 ++++ spec/rust/tests/test_expr_sizeof_value_0.rs | 30 ++++ .../tests/test_expr_sizeof_value_sized.rs | 30 ++++ spec/rust/tests/test_expr_str_encodings.rs | 32 +++++ spec/rust/tests/test_expr_str_ops.rs | 42 ++++++ spec/rust/tests/test_fixed_contents.rs | 25 ++++ spec/rust/tests/test_fixed_struct.rs | 45 ++++++ spec/rust/tests/test_float_to_i.rs | 33 +++++ spec/rust/tests/test_floating_points.rs | 33 +++++ spec/rust/tests/test_hello_world.rs | 26 ++++ spec/rust/tests/test_if_instances.rs | 26 ++++ spec/rust/tests/test_if_struct.rs | 32 +++++ spec/rust/tests/test_if_values.rs | 31 ++++ spec/rust/tests/test_imports0.rs | 29 ++++ spec/rust/tests/test_imports_abs.rs | 28 ++++ ...rts_abs_abs.rs => test_imports_abs_abs.rs} | 2 +- ...rts_abs_rel.rs => test_imports_abs_rel.rs} | 2 +- spec/rust/tests/test_imports_circular_a.rs | 2 +- spec/rust/tests/test_imports_rel_1.rs | 30 ++++ spec/rust/tests/test_index_sizes.rs | 32 +++++ spec/rust/tests/test_index_to_param_eos.rs | 32 +++++ spec/rust/tests/test_index_to_param_expr.rs | 32 +++++ spec/rust/tests/test_index_to_param_until.rs | 32 +++++ spec/rust/tests/test_instance_io_user.rs | 29 ++++ spec/rust/tests/test_instance_std.rs | 26 ++++ spec/rust/tests/test_instance_std_array.rs | 32 +++++ spec/rust/tests/test_instance_user_array.rs | 35 +++++ spec/rust/tests/test_integers.rs | 45 ++++++ .../tests/test_integers_double_overflow.rs | 33 +++++ spec/rust/tests/test_integers_min_max.rs | 53 +++++++ spec/rust/tests/test_io_local_var.rs | 27 ++++ spec/rust/tests/test_js_signed_right_shift.rs | 27 ++++ spec/rust/tests/test_meta_tags.rs | 25 ++++ spec/rust/tests/test_meta_xref.rs | 25 ++++ spec/rust/tests/test_multiple_use.rs | 27 ++++ spec/rust/tests/test_nav_parent.rs | 30 ++++ spec/rust/tests/test_nav_parent2.rs | 35 +++++ spec/rust/tests/test_nav_parent3.rs | 35 +++++ spec/rust/tests/test_nav_parent_false.rs | 30 ++++ spec/rust/tests/test_nav_parent_false2.rs | 26 ++++ spec/rust/tests/test_nav_parent_override.rs | 28 ++++ spec/rust/tests/test_nav_parent_switch.rs | 28 ++++ .../tests/test_nav_parent_vs_value_inst.rs | 26 ++++ spec/rust/tests/test_nav_root.rs | 30 ++++ spec/rust/tests/test_nested_same_name.rs | 27 ++++ spec/rust/tests/test_nested_same_name2.rs | 30 ++++ spec/rust/tests/test_nested_type_param.rs | 27 ++++ spec/rust/tests/test_nested_types.rs | 28 ++++ spec/rust/tests/test_nested_types2.rs | 32 +++++ spec/rust/tests/test_nested_types3.rs | 30 ++++ spec/rust/tests/test_non_standard.rs | 26 ++++ ...l_type.rs => test_opaque_external_type.rs} | 2 +- ...=> test_opaque_external_type_02_parent.rs} | 2 +- ...ith_param.rs => test_opaque_with_param.rs} | 2 +- spec/rust/tests/test_optional_id.rs | 2 +- .../tests/test_params_call_extra_parens.rs | 26 ++++ spec/rust/tests/test_params_call_short.rs | 28 ++++ ...anual_params_def.rs => test_params_def.rs} | 4 +- spec/rust/tests/test_params_enum.rs | 27 ++++ spec/rust/tests/test_params_pass_array_int.rs | 32 +++++ spec/rust/tests/test_params_pass_array_str.rs | 32 +++++ .../tests/test_params_pass_array_usertype.rs | 30 ++++ spec/rust/tests/test_params_pass_bool.rs | 39 +++++ spec/rust/tests/test_params_pass_usertype.rs | 27 ++++ spec/rust/tests/test_position_abs.rs | 27 ++++ spec/rust/tests/test_position_in_seq.rs | 26 ++++ spec/rust/tests/test_position_to_end.rs | 27 ++++ spec/rust/tests/test_process_coerce_bytes.rs | 29 ++++ .../tests/test_process_coerce_usertype1.rs | 29 ++++ .../tests/test_process_coerce_usertype2.rs | 29 ++++ spec/rust/tests/test_process_custom.rs | 28 ++++ .../rust/tests/test_process_custom_no_args.rs | 26 ++++ spec/rust/tests/test_process_repeat_bytes.rs | 27 ++++ .../tests/test_process_repeat_usertype.rs | 29 ++++ spec/rust/tests/test_process_rotate.rs | 28 ++++ spec/rust/tests/test_process_to_user.rs | 26 ++++ spec/rust/tests/test_process_xor4_const.rs | 27 ++++ spec/rust/tests/test_process_xor4_value.rs | 27 ++++ spec/rust/tests/test_process_xor_const.rs | 27 ++++ spec/rust/tests/test_process_xor_value.rs | 27 ++++ spec/rust/tests/test_recursive_one.rs | 29 ++++ spec/rust/tests/test_repeat_eos_bit.rs | 26 ++++ spec/rust/tests/test_repeat_eos_struct.rs | 2 +- spec/rust/tests/test_repeat_eos_u4.rs | 26 ++++ spec/rust/tests/test_repeat_n_struct.rs | 2 +- spec/rust/tests/test_repeat_n_strz.rs | 27 ++++ spec/rust/tests/test_repeat_n_strz_double.rs | 28 ++++ .../test_repeat_until_calc_array_type.rs | 32 +++++ spec/rust/tests/test_repeat_until_complex.rs | 40 ++++++ spec/rust/tests/test_repeat_until_s4.rs | 27 ++++ spec/rust/tests/test_repeat_until_sized.rs | 32 +++++ spec/rust/tests/test_str_encodings.rs | 29 ++++ spec/rust/tests/test_str_encodings_default.rs | 29 ++++ spec/rust/tests/test_str_encodings_utf16.rs | 31 ++++ spec/rust/tests/test_str_eos.rs | 26 ++++ ...l_str_literals.rs => test_str_literals.rs} | 2 +- spec/rust/tests/test_str_literals2.rs | 29 ++++ spec/rust/tests/test_str_pad_term.rs | 29 ++++ spec/rust/tests/test_str_pad_term_empty.rs | 29 ++++ spec/rust/tests/test_switch_bytearray.rs | 34 +++++ ...ual_switch_cast.rs => test_switch_cast.rs} | 2 +- spec/rust/tests/test_switch_else_only.rs | 28 ++++ spec/rust/tests/test_switch_integers.rs | 34 +++++ spec/rust/tests/test_switch_integers2.rs | 30 ++++ spec/rust/tests/test_switch_manual_enum.rs | 34 +++++ .../tests/test_switch_manual_enum_invalid.rs | 2 +- .../test_switch_manual_enum_invalid_else.rs | 2 +- spec/rust/tests/test_switch_manual_int.rs | 34 +++++ .../rust/tests/test_switch_manual_int_else.rs | 34 +++++ .../rust/tests/test_switch_manual_int_size.rs | 35 +++++ .../tests/test_switch_manual_int_size_else.rs | 35 +++++ .../tests/test_switch_manual_int_size_eos.rs | 2 +- spec/rust/tests/test_switch_manual_str.rs | 34 +++++ .../rust/tests/test_switch_manual_str_else.rs | 34 +++++ spec/rust/tests/test_switch_multi_bool_ops.rs | 34 +++++ spec/rust/tests/test_switch_repeat_expr.rs | 28 ++++ .../tests/test_switch_repeat_expr_invalid.rs | 28 ++++ spec/rust/tests/test_term_bytes.rs | 28 ++++ spec/rust/tests/test_term_strz.rs | 28 ++++ spec/rust/tests/test_term_u1_val.rs | 27 ++++ ...ing_custom.rs => test_to_string_custom.rs} | 2 +- spec/rust/tests/test_ts_packet_header.rs | 32 +++++ spec/rust/tests/test_type_int_unary_op.rs | 29 ++++ spec/rust/tests/test_type_ternary.rs | 26 ++++ .../rust/tests/test_type_ternary_2nd_falsy.rs | 2 +- ..._opaque.rs => test_type_ternary_opaque.rs} | 2 +- spec/rust/tests/test_user_type.rs | 27 ++++ .../rust/tests/test_valid_eq_str_encodings.rs | 25 ++++ spec/rust/tests/test_valid_fail_anyof_int.rs | 24 ++++ spec/rust/tests/test_valid_fail_contents.rs | 24 ++++ spec/rust/tests/test_valid_fail_eq_bytes.rs | 24 ++++ spec/rust/tests/test_valid_fail_eq_int.rs | 24 ++++ spec/rust/tests/test_valid_fail_eq_str.rs | 24 ++++ spec/rust/tests/test_valid_fail_expr.rs | 24 ++++ spec/rust/tests/test_valid_fail_inst.rs | 24 ++++ spec/rust/tests/test_valid_fail_max_int.rs | 24 ++++ spec/rust/tests/test_valid_fail_min_int.rs | 24 ++++ .../rust/tests/test_valid_fail_range_bytes.rs | 24 ++++ .../rust/tests/test_valid_fail_range_float.rs | 24 ++++ spec/rust/tests/test_valid_fail_range_int.rs | 24 ++++ spec/rust/tests/test_valid_fail_range_str.rs | 24 ++++ spec/rust/tests/test_valid_long.rs | 25 ++++ spec/rust/tests/test_valid_not_parsed_if.rs | 25 ++++ spec/rust/tests/test_valid_optional_id.rs | 25 ++++ spec/rust/tests/test_valid_short.rs | 25 ++++ spec/rust/tests/test_valid_switch.rs | 25 ++++ spec/rust/tests/test_yaml_ints.rs | 29 ++++ spec/rust/tests/test_zlib_surrounded.rs | 26 ++++ spec/rust/tests/test_zlib_with_header_78.rs | 26 ++++ .../specgenerators/RustSG.scala | 2 +- 472 files changed, 6085 insertions(+), 5361 deletions(-) delete mode 100755 build-rust-formats delete mode 100755 build-rust-tests delete mode 100644 formats_rust/bcd_user_type_be.ksy delete mode 100644 formats_rust/bcd_user_type_le.ksy delete mode 100644 formats_rust/bits_byte_aligned.ksy delete mode 100644 formats_rust/bits_enum.ksy delete mode 100644 formats_rust/bits_seq_endian_combo.ksy delete mode 100644 formats_rust/bits_shift_by_b32_le.ksy delete mode 100644 formats_rust/bits_shift_by_b64_le.ksy delete mode 100644 formats_rust/bits_signed_res_b32_be.ksy delete mode 100644 formats_rust/bits_signed_res_b32_le.ksy delete mode 100644 formats_rust/bits_signed_shift_b32_le.ksy delete mode 100644 formats_rust/bits_signed_shift_b64_le.ksy delete mode 100644 formats_rust/bits_simple.ksy delete mode 100644 formats_rust/bits_simple_le.ksy delete mode 100644 formats_rust/bits_unaligned_b32_be.ksy delete mode 100644 formats_rust/bits_unaligned_b32_le.ksy delete mode 100644 formats_rust/bits_unaligned_b64_be.ksy delete mode 100644 formats_rust/bits_unaligned_b64_le.ksy delete mode 100644 formats_rust/buffered_struct.ksy delete mode 100644 formats_rust/bytes_pad_term.ksy delete mode 100644 formats_rust/cast_nested.ksy delete mode 100644 formats_rust/cast_to_imported.ksy delete mode 100644 formats_rust/cast_to_top.ksy delete mode 100644 formats_rust/combine_bool.ksy delete mode 100644 formats_rust/combine_bytes.ksy delete mode 100644 formats_rust/combine_enum.ksy delete mode 100644 formats_rust/combine_str.ksy delete mode 100644 formats_rust/debug_0.ksy delete mode 100644 formats_rust/debug_array_user.ksy delete mode 100644 formats_rust/debug_enum_name.ksy delete mode 100644 formats_rust/debug_switch_user.ksy delete mode 100644 formats_rust/default_big_endian.ksy delete mode 100644 formats_rust/default_bit_endian_mod.ksy delete mode 100644 formats_rust/default_endian_expr_exception.ksy delete mode 100644 formats_rust/default_endian_expr_inherited.ksy delete mode 100644 formats_rust/default_endian_expr_is_be.ksy delete mode 100644 formats_rust/default_endian_expr_is_le.ksy delete mode 100644 formats_rust/default_endian_mod.ksy delete mode 100644 formats_rust/docstrings.ksy delete mode 100644 formats_rust/docstrings_docref.ksy delete mode 100644 formats_rust/docstrings_docref_multi.ksy delete mode 100644 formats_rust/enum_0.ksy delete mode 100644 formats_rust/enum_1.ksy delete mode 100644 formats_rust/enum_deep.ksy delete mode 100644 formats_rust/enum_deep_literals.ksy delete mode 100644 formats_rust/enum_fancy.ksy delete mode 100644 formats_rust/enum_for_unknown_id.ksy delete mode 100644 formats_rust/enum_if.ksy delete mode 100644 formats_rust/enum_import.ksy delete mode 100644 formats_rust/enum_int_range_s.ksy delete mode 100644 formats_rust/enum_int_range_u.ksy delete mode 100644 formats_rust/enum_invalid.ksy delete mode 100644 formats_rust/enum_long_range_s.ksy delete mode 100644 formats_rust/enum_long_range_u.ksy delete mode 100644 formats_rust/enum_negative.ksy delete mode 100644 formats_rust/enum_of_value_inst.ksy delete mode 100644 formats_rust/enum_to_i.ksy delete mode 100644 formats_rust/enum_to_i_class_border_1.ksy delete mode 100644 formats_rust/enum_to_i_class_border_2.ksy delete mode 100644 formats_rust/eof_exception_bytes.ksy delete mode 100644 formats_rust/eof_exception_u4.ksy delete mode 100644 formats_rust/eos_exception_bytes.ksy delete mode 100644 formats_rust/eos_exception_u4.ksy delete mode 100644 formats_rust/expr_0.ksy delete mode 100644 formats_rust/expr_1.ksy delete mode 100644 formats_rust/expr_2.ksy delete mode 100644 formats_rust/expr_3.ksy delete mode 100644 formats_rust/expr_array.ksy delete mode 100644 formats_rust/expr_bits.ksy delete mode 100644 formats_rust/expr_bytes_cmp.ksy delete mode 100644 formats_rust/expr_bytes_non_literal.ksy delete mode 100644 formats_rust/expr_bytes_ops.ksy delete mode 100644 formats_rust/expr_calc_array_ops.ksy delete mode 100644 formats_rust/expr_enum.ksy delete mode 100644 formats_rust/expr_if_int_ops.ksy delete mode 100644 formats_rust/expr_int_div.ksy delete mode 100644 formats_rust/expr_io_eof.ksy delete mode 100644 formats_rust/expr_io_pos.ksy delete mode 100644 formats_rust/expr_mod.ksy delete mode 100644 formats_rust/expr_ops_parens.ksy delete mode 100644 formats_rust/expr_sizeof_type_0.ksy delete mode 100644 formats_rust/expr_sizeof_type_1.ksy delete mode 100644 formats_rust/expr_sizeof_value_0.ksy delete mode 100644 formats_rust/expr_sizeof_value_sized.ksy delete mode 100644 formats_rust/expr_str_encodings.ksy delete mode 100644 formats_rust/expr_str_ops.ksy delete mode 100644 formats_rust/fixed_contents.ksy delete mode 100644 formats_rust/fixed_struct.ksy delete mode 100644 formats_rust/float_to_i.ksy delete mode 100644 formats_rust/floating_points.ksy delete mode 100644 formats_rust/for_rel_imports/imported_1.ksy delete mode 100644 formats_rust/for_rel_imports/imported_2.ksy delete mode 100644 formats_rust/hello_world.ksy delete mode 100644 formats_rust/if_instances.ksy delete mode 100644 formats_rust/if_struct.ksy delete mode 100644 formats_rust/if_values.ksy delete mode 100644 formats_rust/imports0.ksy delete mode 100644 formats_rust/imports_abs.ksy delete mode 100644 formats_rust/imports_abs_abs.ksy delete mode 100644 formats_rust/imports_abs_rel.ksy delete mode 100644 formats_rust/imports_circular_a.ksy delete mode 100644 formats_rust/imports_circular_b.ksy delete mode 100644 formats_rust/imports_rel_1.ksy delete mode 100644 formats_rust/index_sizes.ksy delete mode 100644 formats_rust/index_to_param_eos.ksy delete mode 100644 formats_rust/index_to_param_expr.ksy delete mode 100644 formats_rust/index_to_param_until.ksy delete mode 100644 formats_rust/instance_io_user.ksy delete mode 100644 formats_rust/instance_std.ksy delete mode 100644 formats_rust/instance_std_array.ksy delete mode 100644 formats_rust/instance_user_array.ksy delete mode 100644 formats_rust/integers.ksy delete mode 100644 formats_rust/integers_double_overflow.ksy delete mode 100644 formats_rust/integers_min_max.ksy delete mode 100644 formats_rust/io_local_var.ksy delete mode 100644 formats_rust/js_signed_right_shift.ksy delete mode 100644 formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy delete mode 100644 formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy delete mode 100644 formats_rust/ks_path/imported_root.ksy delete mode 100644 formats_rust/meta_tags.ksy delete mode 100644 formats_rust/meta_xref.ksy delete mode 100644 formats_rust/multiple_use.ksy delete mode 100644 formats_rust/nav_parent.ksy delete mode 100644 formats_rust/nav_parent2.ksy delete mode 100644 formats_rust/nav_parent3.ksy delete mode 100644 formats_rust/nav_parent_false.ksy delete mode 100644 formats_rust/nav_parent_false2.ksy delete mode 100644 formats_rust/nav_parent_override.ksy delete mode 100644 formats_rust/nav_parent_switch.ksy delete mode 100644 formats_rust/nav_parent_vs_value_inst.ksy delete mode 100644 formats_rust/nav_root.ksy delete mode 100644 formats_rust/nested_same_name.ksy delete mode 100644 formats_rust/nested_same_name2.ksy delete mode 100644 formats_rust/nested_type_param.ksy delete mode 100644 formats_rust/nested_types.ksy delete mode 100644 formats_rust/nested_types2.ksy delete mode 100644 formats_rust/nested_types3.ksy delete mode 100644 formats_rust/non_standard.ksy delete mode 100644 formats_rust/opaque_external_type.ksy delete mode 100644 formats_rust/opaque_external_type_02_child.ksy delete mode 100644 formats_rust/opaque_external_type_02_parent.ksy delete mode 100644 formats_rust/opaque_with_param.ksy delete mode 100644 formats_rust/optional_id.ksy delete mode 100644 formats_rust/params_call_extra_parens.ksy delete mode 100644 formats_rust/params_call_short.ksy delete mode 100644 formats_rust/params_def.ksy delete mode 100644 formats_rust/params_enum.ksy delete mode 100644 formats_rust/params_pass_array_int.ksy delete mode 100644 formats_rust/params_pass_array_str.ksy delete mode 100644 formats_rust/params_pass_array_usertype.ksy delete mode 100644 formats_rust/params_pass_bool.ksy delete mode 100644 formats_rust/params_pass_usertype.ksy delete mode 100644 formats_rust/position_abs.ksy delete mode 100644 formats_rust/position_in_seq.ksy delete mode 100644 formats_rust/position_to_end.ksy delete mode 100644 formats_rust/process_coerce_bytes.ksy delete mode 100644 formats_rust/process_coerce_usertype1.ksy delete mode 100644 formats_rust/process_coerce_usertype2.ksy delete mode 100644 formats_rust/process_custom.ksy delete mode 100644 formats_rust/process_custom_no_args.ksy delete mode 100644 formats_rust/process_repeat_bytes.ksy delete mode 100644 formats_rust/process_repeat_usertype.ksy delete mode 100644 formats_rust/process_rotate.ksy delete mode 100644 formats_rust/process_to_user.ksy delete mode 100644 formats_rust/process_xor4_const.ksy delete mode 100644 formats_rust/process_xor4_value.ksy delete mode 100644 formats_rust/process_xor_const.ksy delete mode 100644 formats_rust/process_xor_value.ksy delete mode 100644 formats_rust/recursive_one.ksy delete mode 100644 formats_rust/repeat_eos_bit.ksy delete mode 100644 formats_rust/repeat_eos_struct.ksy delete mode 100644 formats_rust/repeat_eos_u4.ksy delete mode 100644 formats_rust/repeat_n_struct.ksy delete mode 100644 formats_rust/repeat_n_strz.ksy delete mode 100644 formats_rust/repeat_n_strz_double.ksy delete mode 100644 formats_rust/repeat_until_calc_array_type.ksy delete mode 100644 formats_rust/repeat_until_complex.ksy delete mode 100644 formats_rust/repeat_until_s4.ksy delete mode 100644 formats_rust/repeat_until_sized.ksy delete mode 100644 formats_rust/str_encodings.ksy delete mode 100644 formats_rust/str_encodings_default.ksy delete mode 100644 formats_rust/str_encodings_utf16.ksy delete mode 100644 formats_rust/str_eos.ksy delete mode 100644 formats_rust/str_literals.ksy delete mode 100644 formats_rust/str_literals2.ksy delete mode 100644 formats_rust/str_pad_term.ksy delete mode 100644 formats_rust/str_pad_term_empty.ksy delete mode 100644 formats_rust/switch_bytearray.ksy delete mode 100644 formats_rust/switch_cast.ksy delete mode 100644 formats_rust/switch_else_only.ksy delete mode 100644 formats_rust/switch_integers.ksy delete mode 100644 formats_rust/switch_integers2.ksy delete mode 100644 formats_rust/switch_manual_enum.ksy delete mode 100644 formats_rust/switch_manual_enum_invalid.ksy delete mode 100644 formats_rust/switch_manual_enum_invalid_else.ksy delete mode 100644 formats_rust/switch_manual_int.ksy delete mode 100644 formats_rust/switch_manual_int_else.ksy delete mode 100644 formats_rust/switch_manual_int_size.ksy delete mode 100644 formats_rust/switch_manual_int_size_else.ksy delete mode 100644 formats_rust/switch_manual_int_size_eos.ksy delete mode 100644 formats_rust/switch_manual_str.ksy delete mode 100644 formats_rust/switch_manual_str_else.ksy delete mode 100644 formats_rust/switch_multi_bool_ops.ksy delete mode 100644 formats_rust/switch_repeat_expr.ksy delete mode 100644 formats_rust/switch_repeat_expr_invalid.ksy delete mode 100644 formats_rust/term_bytes.ksy delete mode 100644 formats_rust/term_strz.ksy delete mode 100644 formats_rust/term_u1_val.ksy delete mode 100644 formats_rust/to_string_custom.ksy delete mode 100644 formats_rust/ts_packet_header.ksy delete mode 100644 formats_rust/type_int_unary_op.ksy delete mode 100644 formats_rust/type_ternary.ksy delete mode 100644 formats_rust/type_ternary_2nd_falsy.ksy delete mode 100644 formats_rust/type_ternary_opaque.ksy delete mode 100644 formats_rust/user_type.ksy delete mode 100644 formats_rust/valid_eq_str_encodings.ksy delete mode 100644 formats_rust/valid_fail_anyof_int.ksy delete mode 100644 formats_rust/valid_fail_contents.ksy delete mode 100644 formats_rust/valid_fail_eq_bytes.ksy delete mode 100644 formats_rust/valid_fail_eq_int.ksy delete mode 100644 formats_rust/valid_fail_eq_str.ksy delete mode 100644 formats_rust/valid_fail_expr.ksy delete mode 100644 formats_rust/valid_fail_inst.ksy delete mode 100644 formats_rust/valid_fail_max_int.ksy delete mode 100644 formats_rust/valid_fail_min_int.ksy delete mode 100644 formats_rust/valid_fail_range_bytes.ksy delete mode 100644 formats_rust/valid_fail_range_float.ksy delete mode 100644 formats_rust/valid_fail_range_int.ksy delete mode 100644 formats_rust/valid_fail_range_str.ksy delete mode 100644 formats_rust/valid_long.ksy delete mode 100644 formats_rust/valid_not_parsed_if.ksy delete mode 100644 formats_rust/valid_optional_id.ksy delete mode 100644 formats_rust/valid_short.ksy delete mode 100644 formats_rust/valid_switch.ksy delete mode 100644 formats_rust/yaml_ints.ksy delete mode 100644 formats_rust/zlib_surrounded.ksy delete mode 100644 formats_rust/zlib_with_header_78.ksy rename spec/rust/{tests => }/formats/custom_fx.rs (100%) rename spec/rust/{tests => }/formats/custom_fx_no_args.rs (100%) rename spec/rust/{tests => }/formats/my_custom_fx.rs (100%) create mode 100644 spec/rust/tests/test_bcd_user_type_be.rs create mode 100644 spec/rust/tests/test_bcd_user_type_le.rs create mode 100644 spec/rust/tests/test_bits_byte_aligned.rs create mode 100644 spec/rust/tests/test_bits_enum.rs create mode 100644 spec/rust/tests/test_bits_seq_endian_combo.rs create mode 100644 spec/rust/tests/test_bits_shift_by_b32_le.rs create mode 100644 spec/rust/tests/test_bits_shift_by_b64_le.rs create mode 100644 spec/rust/tests/test_bits_signed_res_b32_be.rs create mode 100644 spec/rust/tests/test_bits_signed_res_b32_le.rs create mode 100644 spec/rust/tests/test_bits_signed_shift_b32_le.rs create mode 100644 spec/rust/tests/test_bits_signed_shift_b64_le.rs create mode 100644 spec/rust/tests/test_bits_simple.rs create mode 100644 spec/rust/tests/test_bits_simple_le.rs create mode 100644 spec/rust/tests/test_bits_unaligned_b32_be.rs create mode 100644 spec/rust/tests/test_bits_unaligned_b32_le.rs create mode 100644 spec/rust/tests/test_bits_unaligned_b64_be.rs create mode 100644 spec/rust/tests/test_bits_unaligned_b64_le.rs create mode 100644 spec/rust/tests/test_buffered_struct.rs create mode 100644 spec/rust/tests/test_bytes_pad_term.rs create mode 100644 spec/rust/tests/test_cast_nested.rs create mode 100644 spec/rust/tests/test_cast_to_top.rs create mode 100644 spec/rust/tests/test_combine_bool.rs create mode 100644 spec/rust/tests/test_combine_bytes.rs create mode 100644 spec/rust/tests/test_combine_enum.rs create mode 100644 spec/rust/tests/test_combine_str.rs rename spec/rust/tests/{manual_debug_0.rs => test_debug_0.rs} (78%) rename spec/rust/tests/{manual_debug_array_user.rs => test_debug_array_user.rs} (93%) create mode 100644 spec/rust/tests/test_debug_switch_user.rs create mode 100644 spec/rust/tests/test_default_big_endian.rs create mode 100644 spec/rust/tests/test_default_bit_endian_mod.rs create mode 100644 spec/rust/tests/test_default_endian_expr_exception.rs create mode 100644 spec/rust/tests/test_default_endian_expr_inherited.rs create mode 100644 spec/rust/tests/test_default_endian_expr_is_be.rs create mode 100644 spec/rust/tests/test_default_endian_expr_is_le.rs create mode 100644 spec/rust/tests/test_default_endian_mod.rs create mode 100644 spec/rust/tests/test_docstrings.rs create mode 100644 spec/rust/tests/test_docstrings_docref.rs create mode 100644 spec/rust/tests/test_docstrings_docref_multi.rs create mode 100644 spec/rust/tests/test_enum_0.rs create mode 100644 spec/rust/tests/test_enum_1.rs create mode 100644 spec/rust/tests/test_enum_deep.rs create mode 100644 spec/rust/tests/test_enum_deep_literals.rs create mode 100644 spec/rust/tests/test_enum_fancy.rs create mode 100644 spec/rust/tests/test_enum_for_unknown_id.rs create mode 100644 spec/rust/tests/test_enum_if.rs create mode 100644 spec/rust/tests/test_enum_import.rs create mode 100644 spec/rust/tests/test_enum_int_range_s.rs create mode 100644 spec/rust/tests/test_enum_int_range_u.rs create mode 100644 spec/rust/tests/test_enum_invalid.rs create mode 100644 spec/rust/tests/test_enum_long_range_s.rs create mode 100644 spec/rust/tests/test_enum_long_range_u.rs create mode 100644 spec/rust/tests/test_enum_negative.rs create mode 100644 spec/rust/tests/test_enum_of_value_inst.rs create mode 100644 spec/rust/tests/test_enum_to_i.rs create mode 100644 spec/rust/tests/test_enum_to_i_class_border_1.rs create mode 100644 spec/rust/tests/test_eof_exception_bytes.rs create mode 100644 spec/rust/tests/test_eof_exception_u4.rs create mode 100644 spec/rust/tests/test_eos_exception_bytes.rs create mode 100644 spec/rust/tests/test_eos_exception_u4.rs create mode 100644 spec/rust/tests/test_expr_0.rs create mode 100644 spec/rust/tests/test_expr_1.rs create mode 100644 spec/rust/tests/test_expr_2.rs create mode 100644 spec/rust/tests/test_expr_3.rs create mode 100644 spec/rust/tests/test_expr_array.rs create mode 100644 spec/rust/tests/test_expr_bits.rs create mode 100644 spec/rust/tests/test_expr_bytes_cmp.rs create mode 100644 spec/rust/tests/test_expr_bytes_non_literal.rs create mode 100644 spec/rust/tests/test_expr_bytes_ops.rs create mode 100644 spec/rust/tests/test_expr_calc_array_ops.rs create mode 100644 spec/rust/tests/test_expr_enum.rs create mode 100644 spec/rust/tests/test_expr_if_int_ops.rs create mode 100644 spec/rust/tests/test_expr_io_eof.rs create mode 100644 spec/rust/tests/test_expr_io_pos.rs create mode 100644 spec/rust/tests/test_expr_mod.rs create mode 100644 spec/rust/tests/test_expr_ops_parens.rs create mode 100644 spec/rust/tests/test_expr_sizeof_type_0.rs create mode 100644 spec/rust/tests/test_expr_sizeof_type_1.rs create mode 100644 spec/rust/tests/test_expr_sizeof_value_0.rs create mode 100644 spec/rust/tests/test_expr_sizeof_value_sized.rs create mode 100644 spec/rust/tests/test_expr_str_encodings.rs create mode 100644 spec/rust/tests/test_expr_str_ops.rs create mode 100644 spec/rust/tests/test_fixed_contents.rs create mode 100644 spec/rust/tests/test_fixed_struct.rs create mode 100644 spec/rust/tests/test_float_to_i.rs create mode 100644 spec/rust/tests/test_floating_points.rs create mode 100644 spec/rust/tests/test_hello_world.rs create mode 100644 spec/rust/tests/test_if_instances.rs create mode 100644 spec/rust/tests/test_if_struct.rs create mode 100644 spec/rust/tests/test_if_values.rs create mode 100644 spec/rust/tests/test_imports0.rs create mode 100644 spec/rust/tests/test_imports_abs.rs rename spec/rust/tests/{manual_imports_abs_abs.rs => test_imports_abs_abs.rs} (92%) rename spec/rust/tests/{manual_imports_abs_rel.rs => test_imports_abs_rel.rs} (92%) create mode 100644 spec/rust/tests/test_imports_rel_1.rs create mode 100644 spec/rust/tests/test_index_sizes.rs create mode 100644 spec/rust/tests/test_index_to_param_eos.rs create mode 100644 spec/rust/tests/test_index_to_param_expr.rs create mode 100644 spec/rust/tests/test_index_to_param_until.rs create mode 100644 spec/rust/tests/test_instance_io_user.rs create mode 100644 spec/rust/tests/test_instance_std.rs create mode 100644 spec/rust/tests/test_instance_std_array.rs create mode 100644 spec/rust/tests/test_instance_user_array.rs create mode 100644 spec/rust/tests/test_integers.rs create mode 100644 spec/rust/tests/test_integers_double_overflow.rs create mode 100644 spec/rust/tests/test_integers_min_max.rs create mode 100644 spec/rust/tests/test_io_local_var.rs create mode 100644 spec/rust/tests/test_js_signed_right_shift.rs create mode 100644 spec/rust/tests/test_meta_tags.rs create mode 100644 spec/rust/tests/test_meta_xref.rs create mode 100644 spec/rust/tests/test_multiple_use.rs create mode 100644 spec/rust/tests/test_nav_parent.rs create mode 100644 spec/rust/tests/test_nav_parent2.rs create mode 100644 spec/rust/tests/test_nav_parent3.rs create mode 100644 spec/rust/tests/test_nav_parent_false.rs create mode 100644 spec/rust/tests/test_nav_parent_false2.rs create mode 100644 spec/rust/tests/test_nav_parent_override.rs create mode 100644 spec/rust/tests/test_nav_parent_switch.rs create mode 100644 spec/rust/tests/test_nav_parent_vs_value_inst.rs create mode 100644 spec/rust/tests/test_nav_root.rs create mode 100644 spec/rust/tests/test_nested_same_name.rs create mode 100644 spec/rust/tests/test_nested_same_name2.rs create mode 100644 spec/rust/tests/test_nested_type_param.rs create mode 100644 spec/rust/tests/test_nested_types.rs create mode 100644 spec/rust/tests/test_nested_types2.rs create mode 100644 spec/rust/tests/test_nested_types3.rs create mode 100644 spec/rust/tests/test_non_standard.rs rename spec/rust/tests/{manual_opaque_external_type.rs => test_opaque_external_type.rs} (92%) rename spec/rust/tests/{manual_opaque_external_type_02_parent.rs => test_opaque_external_type_02_parent.rs} (93%) rename spec/rust/tests/{manual_opaque_with_param.rs => test_opaque_with_param.rs} (92%) create mode 100644 spec/rust/tests/test_params_call_extra_parens.rs create mode 100644 spec/rust/tests/test_params_call_short.rs rename spec/rust/tests/{manual_params_def.rs => test_params_def.rs} (92%) create mode 100644 spec/rust/tests/test_params_enum.rs create mode 100644 spec/rust/tests/test_params_pass_array_int.rs create mode 100644 spec/rust/tests/test_params_pass_array_str.rs create mode 100644 spec/rust/tests/test_params_pass_array_usertype.rs create mode 100644 spec/rust/tests/test_params_pass_bool.rs create mode 100644 spec/rust/tests/test_params_pass_usertype.rs create mode 100644 spec/rust/tests/test_position_abs.rs create mode 100644 spec/rust/tests/test_position_in_seq.rs create mode 100644 spec/rust/tests/test_position_to_end.rs create mode 100644 spec/rust/tests/test_process_coerce_bytes.rs create mode 100644 spec/rust/tests/test_process_coerce_usertype1.rs create mode 100644 spec/rust/tests/test_process_coerce_usertype2.rs create mode 100644 spec/rust/tests/test_process_custom.rs create mode 100644 spec/rust/tests/test_process_custom_no_args.rs create mode 100644 spec/rust/tests/test_process_repeat_bytes.rs create mode 100644 spec/rust/tests/test_process_repeat_usertype.rs create mode 100644 spec/rust/tests/test_process_rotate.rs create mode 100644 spec/rust/tests/test_process_to_user.rs create mode 100644 spec/rust/tests/test_process_xor4_const.rs create mode 100644 spec/rust/tests/test_process_xor4_value.rs create mode 100644 spec/rust/tests/test_process_xor_const.rs create mode 100644 spec/rust/tests/test_process_xor_value.rs create mode 100644 spec/rust/tests/test_recursive_one.rs create mode 100644 spec/rust/tests/test_repeat_eos_bit.rs create mode 100644 spec/rust/tests/test_repeat_eos_u4.rs create mode 100644 spec/rust/tests/test_repeat_n_strz.rs create mode 100644 spec/rust/tests/test_repeat_n_strz_double.rs create mode 100644 spec/rust/tests/test_repeat_until_calc_array_type.rs create mode 100644 spec/rust/tests/test_repeat_until_complex.rs create mode 100644 spec/rust/tests/test_repeat_until_s4.rs create mode 100644 spec/rust/tests/test_repeat_until_sized.rs create mode 100644 spec/rust/tests/test_str_encodings.rs create mode 100644 spec/rust/tests/test_str_encodings_default.rs create mode 100644 spec/rust/tests/test_str_encodings_utf16.rs create mode 100644 spec/rust/tests/test_str_eos.rs rename spec/rust/tests/{manual_str_literals.rs => test_str_literals.rs} (95%) create mode 100644 spec/rust/tests/test_str_literals2.rs create mode 100644 spec/rust/tests/test_str_pad_term.rs create mode 100644 spec/rust/tests/test_str_pad_term_empty.rs create mode 100644 spec/rust/tests/test_switch_bytearray.rs rename spec/rust/tests/{manual_switch_cast.rs => test_switch_cast.rs} (97%) create mode 100644 spec/rust/tests/test_switch_else_only.rs create mode 100644 spec/rust/tests/test_switch_integers.rs create mode 100644 spec/rust/tests/test_switch_integers2.rs create mode 100644 spec/rust/tests/test_switch_manual_enum.rs create mode 100644 spec/rust/tests/test_switch_manual_int.rs create mode 100644 spec/rust/tests/test_switch_manual_int_else.rs create mode 100644 spec/rust/tests/test_switch_manual_int_size.rs create mode 100644 spec/rust/tests/test_switch_manual_int_size_else.rs create mode 100644 spec/rust/tests/test_switch_manual_str.rs create mode 100644 spec/rust/tests/test_switch_manual_str_else.rs create mode 100644 spec/rust/tests/test_switch_multi_bool_ops.rs create mode 100644 spec/rust/tests/test_switch_repeat_expr.rs create mode 100644 spec/rust/tests/test_switch_repeat_expr_invalid.rs create mode 100644 spec/rust/tests/test_term_bytes.rs create mode 100644 spec/rust/tests/test_term_strz.rs create mode 100644 spec/rust/tests/test_term_u1_val.rs rename spec/rust/tests/{manual_to_string_custom.rs => test_to_string_custom.rs} (91%) create mode 100644 spec/rust/tests/test_ts_packet_header.rs create mode 100644 spec/rust/tests/test_type_int_unary_op.rs create mode 100644 spec/rust/tests/test_type_ternary.rs rename spec/rust/tests/{manual_type_ternary_opaque.rs => test_type_ternary_opaque.rs} (93%) create mode 100644 spec/rust/tests/test_user_type.rs create mode 100644 spec/rust/tests/test_valid_eq_str_encodings.rs create mode 100644 spec/rust/tests/test_valid_fail_anyof_int.rs create mode 100644 spec/rust/tests/test_valid_fail_contents.rs create mode 100644 spec/rust/tests/test_valid_fail_eq_bytes.rs create mode 100644 spec/rust/tests/test_valid_fail_eq_int.rs create mode 100644 spec/rust/tests/test_valid_fail_eq_str.rs create mode 100644 spec/rust/tests/test_valid_fail_expr.rs create mode 100644 spec/rust/tests/test_valid_fail_inst.rs create mode 100644 spec/rust/tests/test_valid_fail_max_int.rs create mode 100644 spec/rust/tests/test_valid_fail_min_int.rs create mode 100644 spec/rust/tests/test_valid_fail_range_bytes.rs create mode 100644 spec/rust/tests/test_valid_fail_range_float.rs create mode 100644 spec/rust/tests/test_valid_fail_range_int.rs create mode 100644 spec/rust/tests/test_valid_fail_range_str.rs create mode 100644 spec/rust/tests/test_valid_long.rs create mode 100644 spec/rust/tests/test_valid_not_parsed_if.rs create mode 100644 spec/rust/tests/test_valid_optional_id.rs create mode 100644 spec/rust/tests/test_valid_short.rs create mode 100644 spec/rust/tests/test_valid_switch.rs create mode 100644 spec/rust/tests/test_yaml_ints.rs create mode 100644 spec/rust/tests/test_zlib_surrounded.rs create mode 100644 spec/rust/tests/test_zlib_with_header_78.rs diff --git a/.gitignore b/.gitignore index 5dba3e907..801d6734f 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,4 @@ spec/nim/bin # Rust compiled code, cargo and rls data spec/rust/Cargo.lock spec/rust/target/ -spec/rust/tests/formats/ +spec/rust/formats/ diff --git a/build-rust-formats b/build-rust-formats deleted file mode 100755 index fe23874e7..000000000 --- a/build-rust-formats +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh - -. ./config - -FORMATS_COMPILED_DIR=$FORMATS_COMPILED_DIR/rust - -rm -rf "$FORMATS_COMPILED_DIR" -mkdir -p "$FORMATS_COMPILED_DIR" -"$COMPILER_DIR/jvm/target/universal/stage/bin/kaitai-struct-compiler" -- \ - -t rust -d "$FORMATS_COMPILED_DIR" \ - --ksc-exceptions \ - --import-path "$FORMATS_REPO_DIR" \ - --import-path "$FORMATS_KSY_DIR/ks_path" \ - --java-package io.kaitai.struct.testformats \ - --php-namespace 'Kaitai\Struct\Tests' \ - --go-package test_formats \ - --nim-module "kaitai_struct_nim_runtime" \ - --nim-opaque "../../tests/spec/nim/opaque/" \ - "$FORMATS_KSY_DIR"/*.ksy || : diff --git a/build-rust-tests b/build-rust-tests deleted file mode 100755 index f378b5350..000000000 --- a/build-rust-tests +++ /dev/null @@ -1,71 +0,0 @@ -#!/bin/bash -e - -. ./config - -LANG=rust -LANG_EXT=rs - -# existing tests -EXIST_TESTS_DIR="spec/$LANG/tests" - -# kst-file for test generation -KS_DIR="spec/ks" - -# formats dir -FORMATS_DIR=$FORMATS_KSY_DIR - -# build compiler -pushd $COMPILER_DIR -sbt publishLocal -popd - -# generate tests only for exist formats only -# ksy -> rs -# but also check if correspond kst-file exist -FORMATS= -FORMATS_ONLY_RUST= -KEEPING_TESTS= -for fn in $FORMATS_DIR/*.ksy; do - f=$(basename -- ${fn%%.*}) - - # regenerate tests only if there no such test exist - if [ ! -f "$EXIST_TESTS_DIR/test_$f.$LANG_EXT" ]; then - if [ -f "$KS_DIR/$f.kst" ]; then - FORMATS_FILES="${FORMATS_FILES} $f" - else - FORMATS_FILES_ONLY_RUST="${FORMATS_FILES_ONLY_RUST} $f" - fi - else - KEEPING_TESTS="${KEEPING_TESTS} test_$f.$LANG_EXT" - fi -done - -if [ ! -z "$KEEPING_TESTS" ]; then - echo "Keeping (edited) tests: $KEEPING_TESTS" -fi - -if [ -z "$FORMATS_FILES" ]; then - echo "No new tests were generated." - echo "Please delete selected (or all) tests (test_*.$LANG_EXT) from $EXIST_TESTS_DIR." - echo "And rerun this script to make a new." -else - echo generating tests for $LANG: - echo $FORMATS_FILES - - ./spec_kst_to_all -f ../$EXIST_TESTS_DIR -t $LANG $FORMATS_FILES -fi - -# check for manual tests -if [ ! -z "$FORMATS_FILES_ONLY_RUST" ]; then - echo - echo "!!! This tests exist only for rust (manual tests):" - for f in ${FORMATS_FILES_ONLY_RUST[*]}; do - if ! [ -f "$EXIST_TESTS_DIR/manual_$f.$LANG_EXT" ]; then - echo "!!! $FORMATS_DIR/$f.ksy detected without correspond kst-file, please put manual test $EXIST_TESTS_DIR/manual_$f.$LANG_EXT" - else - echo "$EXIST_TESTS_DIR/manual_$f.$LANG_EXT" - fi - done - echo "!!! Please, update them manually !!!" - echo -fi diff --git a/formats_rust/bcd_user_type_be.ksy b/formats_rust/bcd_user_type_be.ksy deleted file mode 100644 index 4b28bddf0..000000000 --- a/formats_rust/bcd_user_type_be.ksy +++ /dev/null @@ -1,136 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/78 -meta: - id: bcd_user_type_be - endian: be - -seq: - - id: ltr - size: 4 - type: ltr_obj - - id: rtl - size: 4 - type: rtl_obj - - id: leading_zero_ltr - size: 4 - type: leading_zero_ltr_obj - -types: - ltr_obj: - seq: - - id: b1 - type: u1 - - id: b2 - type: u1 - - id: b3 - type: u1 - - id: b4 - type: u1 - - instances: - digit1: - value: (b1 & 0xF0) >> 4 - digit2: - value: (b1 & 0x0F) - digit3: - value: (b2 & 0xF0) >> 4 - digit4: - value: (b2 & 0x0F) - digit5: - value: (b3 & 0xF0) >> 4 - digit6: - value: (b3 & 0x0F) - digit7: - value: (b4 & 0xF0) >> 4 - digit8: - value: (b4 & 0x0F) - as_int: - value: digit8 * 1 + - digit7 * 10 + - digit6 * 100 + - digit5 * 1000 + - digit4 * 10000 + - digit3 * 100000 + - digit2 * 1000000 + - digit1 * 10000000 - as_str: - value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s - - rtl_obj: - seq: - - id: b1 - type: u1 - - id: b2 - type: u1 - - id: b3 - type: u1 - - id: b4 - type: u1 - - instances: - digit1: - value: (b1 & 0xF0) >> 4 - digit2: - value: (b1 & 0x0F) - digit3: - value: (b2 & 0xF0) >> 4 - digit4: - value: (b2 & 0x0F) - digit5: - value: (b3 & 0xF0) >> 4 - digit6: - value: (b3 & 0x0F) - digit7: - value: (b4 & 0xF0) >> 4 - digit8: - value: (b4 & 0x0F) - as_int: - value: digit1 * 1 + - digit2 * 10 + - digit3 * 100 + - digit4 * 1000 + - digit5 * 10000 + - digit6 * 100000 + - digit7 * 1000000 + - digit8 * 10000000 - as_str: - value: digit8.to_s + digit7.to_s + digit6.to_s + digit5.to_s + digit4.to_s + digit3.to_s + digit2.to_s + digit1.to_s - - leading_zero_ltr_obj: - seq: - - id: b1 - type: u1 - - id: b2 - type: u1 - - id: b3 - type: u1 - - id: b4 - type: u1 - - instances: - digit1: - value: (b1 & 0xF0) >> 4 - digit2: - value: (b1 & 0x0F) - digit3: - value: (b2 & 0xF0) >> 4 - digit4: - value: (b2 & 0x0F) - digit5: - value: (b3 & 0xF0) >> 4 - digit6: - value: (b3 & 0x0F) - digit7: - value: (b4 & 0xF0) >> 4 - digit8: - value: (b4 & 0x0F) - as_int: - value: digit8 * 1 + - digit7 * 10 + - digit6 * 100 + - digit5 * 1000 + - digit4 * 10000 + - digit3 * 100000 + - digit2 * 1000000 + - digit1 * 10000000 - as_str: - value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s diff --git a/formats_rust/bcd_user_type_le.ksy b/formats_rust/bcd_user_type_le.ksy deleted file mode 100644 index 97db59011..000000000 --- a/formats_rust/bcd_user_type_le.ksy +++ /dev/null @@ -1,136 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/78 -meta: - id: bcd_user_type_le - endian: le - -seq: - - id: ltr - size: 4 - type: ltr_obj - - id: rtl - size: 4 - type: rtl_obj - - id: leading_zero_ltr - size: 4 - type: leading_zero_ltr_obj - -types: - ltr_obj: - seq: - - id: b1 - type: u1 - - id: b2 - type: u1 - - id: b3 - type: u1 - - id: b4 - type: u1 - - instances: - digit1: - value: (b4 & 0xF0) >> 4 - digit2: - value: (b4 & 0x0F) - digit3: - value: (b3 & 0xF0) >> 4 - digit4: - value: (b3 & 0x0F) - digit5: - value: (b2 & 0xF0) >> 4 - digit6: - value: (b2 & 0x0F) - digit7: - value: (b1 & 0xF0) >> 4 - digit8: - value: (b1 & 0x0F) - as_int: - value: digit8 * 1 + - digit7 * 10 + - digit6 * 100 + - digit5 * 1000 + - digit4 * 10000 + - digit3 * 100000 + - digit2 * 1000000 + - digit1 * 10000000 - as_str: - value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s - - rtl_obj: - seq: - - id: b1 - type: u1 - - id: b2 - type: u1 - - id: b3 - type: u1 - - id: b4 - type: u1 - - instances: - digit1: - value: (b4 & 0xF0) >> 4 - digit2: - value: (b4 & 0x0F) - digit3: - value: (b3 & 0xF0) >> 4 - digit4: - value: (b3 & 0x0F) - digit5: - value: (b2 & 0xF0) >> 4 - digit6: - value: (b2 & 0x0F) - digit7: - value: (b1 & 0xF0) >> 4 - digit8: - value: (b1 & 0x0F) - as_int: - value: digit1 * 1 + - digit2 * 10 + - digit3 * 100 + - digit4 * 1000 + - digit5 * 10000 + - digit6 * 100000 + - digit7 * 1000000 + - digit8 * 10000000 - as_str: - value: digit8.to_s + digit7.to_s + digit6.to_s + digit5.to_s + digit4.to_s + digit3.to_s + digit2.to_s + digit1.to_s - - leading_zero_ltr_obj: - seq: - - id: b1 - type: u1 - - id: b2 - type: u1 - - id: b3 - type: u1 - - id: b4 - type: u1 - - instances: - digit1: - value: (b4 & 0xF0) >> 4 - digit2: - value: (b4 & 0x0F) - digit3: - value: (b3 & 0xF0) >> 4 - digit4: - value: (b3 & 0x0F) - digit5: - value: (b2 & 0xF0) >> 4 - digit6: - value: (b2 & 0x0F) - digit7: - value: (b1 & 0xF0) >> 4 - digit8: - value: (b1 & 0x0F) - as_int: - value: digit8 * 1 + - digit7 * 10 + - digit6 * 100 + - digit5 * 1000 + - digit4 * 10000 + - digit3 * 100000 + - digit2 * 1000000 + - digit1 * 10000000 - as_str: - value: digit1.to_s + digit2.to_s + digit3.to_s + digit4.to_s + digit5.to_s + digit6.to_s + digit7.to_s + digit8.to_s diff --git a/formats_rust/bits_byte_aligned.ksy b/formats_rust/bits_byte_aligned.ksy deleted file mode 100644 index 779b5c17f..000000000 --- a/formats_rust/bits_byte_aligned.ksy +++ /dev/null @@ -1,24 +0,0 @@ -meta: - id: bits_byte_aligned -seq: - - id: one - type: b6 - # skips 2 bits - - id: byte_1 - type: u1 - - id: two - type: b3 - - id: three - type: b1 - # skips 4 bits - - id: byte_2 - type: u1 - - id: four - type: b14 - # skips 2 bits - - id: byte_3 - size: 1 - - id: full_byte - type: b8 - - id: byte_4 - type: u1 diff --git a/formats_rust/bits_enum.ksy b/formats_rust/bits_enum.ksy deleted file mode 100644 index 6605e9b5e..000000000 --- a/formats_rust/bits_enum.ksy +++ /dev/null @@ -1,21 +0,0 @@ -meta: - id: bits_enum -seq: - # byte 0 - - id: one - type: b4 - enum: animal - # byte 0-1 - - id: two - type: b8 - enum: animal - # byte 1 - - id: three - type: b1 - enum: animal -enums: - animal: - 0: cat - 1: dog - 4: horse - 5: platypus diff --git a/formats_rust/bits_seq_endian_combo.ksy b/formats_rust/bits_seq_endian_combo.ksy deleted file mode 100644 index 63a9760b0..000000000 --- a/formats_rust/bits_seq_endian_combo.ksy +++ /dev/null @@ -1,19 +0,0 @@ -meta: - id: bits_seq_endian_combo -seq: - - id: be1 - type: b6be - - id: be2 - type: b10be - - id: le3 - type: b8le - - id: be4 - type: b8be - - id: le5 - type: b5le - - id: le6 - type: b6le - - id: le7 - type: b5le - - id: be8 - type: b1be diff --git a/formats_rust/bits_shift_by_b32_le.ksy b/formats_rust/bits_shift_by_b32_le.ksy deleted file mode 100644 index ce3cfe58e..000000000 --- a/formats_rust/bits_shift_by_b32_le.ksy +++ /dev/null @@ -1,14 +0,0 @@ -# If the particular runtime library implements `read_bits_int_le()` according to the common -# algorithm introduced in https://github.com/kaitai-io/kaitai_struct/issues/949 (as all runtime -# libs should), this test will make it store `res >> (bitsNeeded: 32)` in `bits` for subsequent -# bit integers. However, the behavior of `x >> 32` is often problematic in languages with -# 32-bit operators - in JavaScript, this case has to be handled with special care. If it's not, -# this test will reveal it. -meta: - id: bits_shift_by_b32_le - bit-endian: le -seq: - - id: a - type: b32 - - id: b - type: b8 diff --git a/formats_rust/bits_shift_by_b64_le.ksy b/formats_rust/bits_shift_by_b64_le.ksy deleted file mode 100644 index 0eadb1268..000000000 --- a/formats_rust/bits_shift_by_b64_le.ksy +++ /dev/null @@ -1,14 +0,0 @@ -# If the particular runtime library implements `read_bits_int_le()` according to the common -# algorithm introduced in https://github.com/kaitai-io/kaitai_struct/issues/949 (as all runtime -# libs should), this test will make it store `res >> (bitsNeeded: 64)` in `bits` for subsequent -# bit integers. However, the behavior of `x >> 64` is often problematic in languages with -# 64-bit operators - this case usually has to be handled with special care. If it's not, this -# test will reveal it. -meta: - id: bits_shift_by_b64_le - bit-endian: le -seq: - - id: a - type: b64 - - id: b - type: b8 diff --git a/formats_rust/bits_signed_res_b32_be.ksy b/formats_rust/bits_signed_res_b32_be.ksy deleted file mode 100644 index 01d3268bb..000000000 --- a/formats_rust/bits_signed_res_b32_be.ksy +++ /dev/null @@ -1,7 +0,0 @@ -# Make sure that a big-endian `b32` value is read as unsigned in JavaScript. -meta: - id: bits_signed_res_b32_be - bit-endian: be -seq: - - id: a - type: b32 diff --git a/formats_rust/bits_signed_res_b32_le.ksy b/formats_rust/bits_signed_res_b32_le.ksy deleted file mode 100644 index 9a18180c1..000000000 --- a/formats_rust/bits_signed_res_b32_le.ksy +++ /dev/null @@ -1,7 +0,0 @@ -# Make sure that a little-endian `b32` value is read as unsigned in JavaScript. -meta: - id: bits_signed_res_b32_le - bit-endian: le -seq: - - id: a - type: b32 diff --git a/formats_rust/bits_signed_shift_b32_le.ksy b/formats_rust/bits_signed_shift_b32_le.ksy deleted file mode 100644 index b1f84b336..000000000 --- a/formats_rust/bits_signed_shift_b32_le.ksy +++ /dev/null @@ -1,11 +0,0 @@ -# Make sure that languages with 32-bit operators (JavaScript) use *unsigned* -# (aka zero-fill) right shift, not signed (sign-propagating) right shift. This -# test will fail if a signed shift is used. -meta: - id: bits_signed_shift_b32_le - bit-endian: le -seq: - - id: a - type: b31 - - id: b - type: b9 diff --git a/formats_rust/bits_signed_shift_b64_le.ksy b/formats_rust/bits_signed_shift_b64_le.ksy deleted file mode 100644 index 1554026ed..000000000 --- a/formats_rust/bits_signed_shift_b64_le.ksy +++ /dev/null @@ -1,11 +0,0 @@ -# Make sure that languages with 64-bit operators (Java, PHP) use *unsigned* (aka -# zero-fill) right shift, not signed (sign-propagating) right shift. This test -# will fail if a signed shift is used. -meta: - id: bits_signed_shift_b64_le - bit-endian: le -seq: - - id: a - type: b63 - - id: b - type: b9 diff --git a/formats_rust/bits_simple.ksy b/formats_rust/bits_simple.ksy deleted file mode 100644 index 7195b2dec..000000000 --- a/formats_rust/bits_simple.ksy +++ /dev/null @@ -1,42 +0,0 @@ -meta: - id: bits_simple -seq: - # byte 0 - - id: byte_1 - type: b8 - # byte 1 - - id: byte_2 - type: b8 - # byte 2 (8 bits = 1 + 3 + 4) - - id: bits_a - type: b1 - - id: bits_b - type: b3 - - id: bits_c - type: b4 - # byte 3-4-5 (24 bits = 10 + 3 + 11) - - id: large_bits_1 - type: b10 - - id: spacer - type: b3 - - id: large_bits_2 - type: b11 - # byte 6-7 - - id: normal_s2 - type: s2be - # byte 8-9-10 (24 bits) - - id: byte_8_9_10 - type: b24 - # byte 11-12-13-14 (32 bits) - - id: byte_11_to_14 - type: b32 - # byte 15-16-17-18-19 (40 bits) - - id: byte_15_to_19 - type: b40 - # byte 20-21-22-23-24-25-26-27 (64 bits) - - id: byte_20_to_27 - type: b64 -instances: - test_if_b1: - value: 123 - if: bits_a == false diff --git a/formats_rust/bits_simple_le.ksy b/formats_rust/bits_simple_le.ksy deleted file mode 100644 index c897f079b..000000000 --- a/formats_rust/bits_simple_le.ksy +++ /dev/null @@ -1,43 +0,0 @@ -meta: - id: bits_simple_le - bit-endian: le -seq: - # byte 0 - - id: byte_1 - type: b8 - # byte 1 - - id: byte_2 - type: b8 - # byte 2 (8 bits = 1 + 3 + 4) - - id: bits_a - type: b1 - - id: bits_b - type: b3 - - id: bits_c - type: b4 - # byte 3-4-5 (24 bits = 10 + 3 + 11) - - id: large_bits_1 - type: b10 - - id: spacer - type: b3 - - id: large_bits_2 - type: b11 - # byte 6-7 - - id: normal_s2 - type: s2be - # byte 8-9-10 (24 bits) - - id: byte_8_9_10 - type: b24 - # byte 11-12-13-14 (32 bits) - - id: byte_11_to_14 - type: b32 - # byte 15-16-17-18-19 (40 bits) - - id: byte_15_to_19 - type: b40 - # byte 20-21-22-23-24-25-26-27 (64 bits) - - id: byte_20_to_27 - type: b64 -instances: - test_if_b1: - value: 123 - if: bits_a == true diff --git a/formats_rust/bits_unaligned_b32_be.ksy b/formats_rust/bits_unaligned_b32_be.ksy deleted file mode 100644 index 29bc1cd70..000000000 --- a/formats_rust/bits_unaligned_b32_be.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: bits_unaligned_b32_be - bit-endian: be -seq: - - id: a - type: b1 - - id: b - type: b32 - - id: c - type: b7 diff --git a/formats_rust/bits_unaligned_b32_le.ksy b/formats_rust/bits_unaligned_b32_le.ksy deleted file mode 100644 index 1dc8830aa..000000000 --- a/formats_rust/bits_unaligned_b32_le.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: bits_unaligned_b32_le - bit-endian: le -seq: - - id: a - type: b1 - - id: b - type: b32 - - id: c - type: b7 diff --git a/formats_rust/bits_unaligned_b64_be.ksy b/formats_rust/bits_unaligned_b64_be.ksy deleted file mode 100644 index 7a5aa1bd8..000000000 --- a/formats_rust/bits_unaligned_b64_be.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: bits_unaligned_b64_be - bit-endian: be -seq: - - id: a - type: b1 - - id: b - type: b64 - - id: c - type: b7 diff --git a/formats_rust/bits_unaligned_b64_le.ksy b/formats_rust/bits_unaligned_b64_le.ksy deleted file mode 100644 index 1c4a74138..000000000 --- a/formats_rust/bits_unaligned_b64_le.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: bits_unaligned_b64_le - bit-endian: le -seq: - - id: a - type: b1 - - id: b - type: b64 - - id: c - type: b7 diff --git a/formats_rust/buffered_struct.ksy b/formats_rust/buffered_struct.ksy deleted file mode 100644 index 39212f0fe..000000000 --- a/formats_rust/buffered_struct.ksy +++ /dev/null @@ -1,23 +0,0 @@ -meta: - id: buffered_struct - endian: le -seq: - - id: len1 - type: u4 - - id: block1 - type: block - size: len1 - - id: len2 - type: u4 - - id: block2 - type: block - size: len2 - - id: finisher - type: u4 -types: - block: - seq: - - id: number1 - type: u4 - - id: number2 - type: u4 diff --git a/formats_rust/bytes_pad_term.ksy b/formats_rust/bytes_pad_term.ksy deleted file mode 100644 index 139a00737..000000000 --- a/formats_rust/bytes_pad_term.ksy +++ /dev/null @@ -1,18 +0,0 @@ -# Tests "pad-right" and "terminator" functionality in fixed-length byte arrays -meta: - id: bytes_pad_term -seq: - - id: str_pad - size: 20 - pad-right: 0x40 - - id: str_term - size: 20 - terminator: 0x40 - - id: str_term_and_pad - size: 20 - terminator: 0x40 - pad-right: 0x2b - - id: str_term_include - size: 20 - terminator: 0x40 - include: true diff --git a/formats_rust/cast_nested.ksy b/formats_rust/cast_nested.ksy deleted file mode 100644 index 7a67cd9f3..000000000 --- a/formats_rust/cast_nested.ksy +++ /dev/null @@ -1,36 +0,0 @@ -meta: - id: cast_nested -seq: - - id: opcodes - type: opcode - repeat: eos -instances: - opcodes_0_str: - value: opcodes[0].body.as - opcodes_0_str_value: - value: opcodes[0].body.as.value - opcodes_1_int: - value: opcodes[1].body.as - opcodes_1_int_value: - value: opcodes[1].body.as.value -types: - opcode: - seq: - - id: code - type: u1 - - id: body - type: - switch-on: code - cases: - 73: intval - 83: strval - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/cast_to_imported.ksy b/formats_rust/cast_to_imported.ksy deleted file mode 100644 index 7c2aee155..000000000 --- a/formats_rust/cast_to_imported.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: cast_to_imported - imports: - - hello_world -seq: - - id: one - type: hello_world -instances: - one_casted: - value: one.as diff --git a/formats_rust/cast_to_top.ksy b/formats_rust/cast_to_top.ksy deleted file mode 100644 index dbf53fabb..000000000 --- a/formats_rust/cast_to_top.ksy +++ /dev/null @@ -1,14 +0,0 @@ -# Simplest way to check that casting to top-level type works -meta: - id: cast_to_top -seq: - - id: code - type: u1 -instances: - header: - pos: 1 - type: cast_to_top - # This is silly and does nothing, but it checks that casting can find - # top-level type - header_casted: - value: header.as diff --git a/formats_rust/combine_bool.ksy b/formats_rust/combine_bool.ksy deleted file mode 100644 index 496026c6a..000000000 --- a/formats_rust/combine_bool.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: combine_bool -seq: - - id: bool_bit - type: b1 -instances: - bool_calc: - value: false - bool_calc_bit: - value: 'true ? bool_calc : bool_bit' diff --git a/formats_rust/combine_bytes.ksy b/formats_rust/combine_bytes.ksy deleted file mode 100644 index 00256370e..000000000 --- a/formats_rust/combine_bytes.ksy +++ /dev/null @@ -1,27 +0,0 @@ -meta: - id: combine_bytes -seq: - - id: bytes_term - terminator: 0x7c - - id: bytes_limit - size: 4 - - id: bytes_eos - size-eos: true -instances: - bytes_calc: - value: '[0x52, 0x6e, 0x44]' - - term_or_limit: - value: 'true ? bytes_term : bytes_limit' - term_or_eos: - value: 'false ? bytes_term : bytes_eos' - term_or_calc: - value: 'true ? bytes_term : bytes_calc' - - limit_or_eos: - value: 'true ? bytes_limit : bytes_eos' - limit_or_calc: - value: 'false ? bytes_limit : bytes_calc' - - eos_or_calc: - value: 'true ? bytes_eos : bytes_calc' diff --git a/formats_rust/combine_enum.ksy b/formats_rust/combine_enum.ksy deleted file mode 100644 index 1f3c81cae..000000000 --- a/formats_rust/combine_enum.ksy +++ /dev/null @@ -1,17 +0,0 @@ -meta: - id: combine_enum - endian: le -seq: - - id: enum_u4 - type: u4 - enum: animal - - id: enum_u2 - type: u2 - enum: animal -enums: - animal: - 7: pig - 12: horse -instances: - enum_u4_u2: - value: 'false ? enum_u4 : enum_u2' diff --git a/formats_rust/combine_str.ksy b/formats_rust/combine_str.ksy deleted file mode 100644 index aa3cd2860..000000000 --- a/formats_rust/combine_str.ksy +++ /dev/null @@ -1,44 +0,0 @@ -meta: - id: combine_str - encoding: ASCII -seq: - - id: str_term - type: str - terminator: 0x7c - - id: str_limit - type: str - size: 4 - - id: str_eos - type: str - size-eos: true -instances: - str_calc: - value: '"bar"' - calc_bytes: - value: '[0x62, 0x61, 0x7a]' - str_calc_bytes: - value: 'calc_bytes.to_s("ASCII")' - - term_or_limit: - value: 'true ? str_term : str_limit' - term_or_eos: - value: 'false ? str_term : str_eos' - term_or_calc: - value: 'true ? str_term : str_calc' - term_or_calc_bytes: - value: 'false ? str_term : str_calc_bytes' - - limit_or_eos: - value: 'true ? str_limit : str_eos' - limit_or_calc: - value: 'false ? str_limit : str_calc' - limit_or_calc_bytes: - value: 'true ? str_limit : str_calc_bytes' - - eos_or_calc: - value: 'false ? str_eos : str_calc' - eos_or_calc_bytes: - value: 'true ? str_eos : str_calc_bytes' - - calc_or_calc_bytes: - value: 'false ? str_calc : str_calc_bytes' diff --git a/formats_rust/debug_0.ksy b/formats_rust/debug_0.ksy deleted file mode 100644 index 2cb78decf..000000000 --- a/formats_rust/debug_0.ksy +++ /dev/null @@ -1,12 +0,0 @@ -# Tests various capabilities in --debug mode -meta: - id: debug_0 - ks-debug: true -seq: - - id: one - type: u1 - - id: array_of_ints - type: u1 - repeat: expr - repeat-expr: 3 - - type: u1 # anonymous, numbered field diff --git a/formats_rust/debug_array_user.ksy b/formats_rust/debug_array_user.ksy deleted file mode 100644 index 84f709833..000000000 --- a/formats_rust/debug_array_user.ksy +++ /dev/null @@ -1,17 +0,0 @@ -# --debug (or actually --no-auto-read) with arrays of user types requires -# special handling to avoid spoiling whole object due to exception handler. -meta: - id: debug_array_user - ks-debug: true -seq: - - id: one_cat - type: cat - - id: array_of_cats - type: cat - repeat: expr - repeat-expr: 3 -types: - cat: - seq: - - id: meow - type: u1 diff --git a/formats_rust/debug_enum_name.ksy b/formats_rust/debug_enum_name.ksy deleted file mode 100644 index 0e401da61..000000000 --- a/formats_rust/debug_enum_name.ksy +++ /dev/null @@ -1,37 +0,0 @@ -# Tests enum name generation in --debug mode -meta: - id: debug_enum_name - ks-debug: true -seq: - - id: one - type: u1 - enum: test_enum1 - - id: array_of_ints - type: u1 - enum: test_enum2 - repeat: expr - repeat-expr: 1 - - id: test_type - type: test_subtype -types: - test_subtype: - seq: - - id: field1 - type: u1 - enum: inner_enum1 - - id: field2 - type: u1 - instances: - instance_field: - value: "field2 & 0xf" - enum: inner_enum2 - enums: - inner_enum1: - 67: enum_value_67 - inner_enum2: - 11: enum_value_11 -enums: - test_enum1: - 80: enum_value_80 - test_enum2: - 65: enum_value_65 diff --git a/formats_rust/debug_switch_user.ksy b/formats_rust/debug_switch_user.ksy deleted file mode 100644 index 563e74b7e..000000000 --- a/formats_rust/debug_switch_user.ksy +++ /dev/null @@ -1,22 +0,0 @@ -meta: - id: debug_switch_user - endian: le - ks-debug: true -seq: - - id: code - type: u1 - - id: data - type: - switch-on: code - cases: - 1: one - 2: two -types: - one: - seq: - - id: val - type: s2 - two: - seq: - - id: val - type: u2 diff --git a/formats_rust/default_big_endian.ksy b/formats_rust/default_big_endian.ksy deleted file mode 100644 index 969c38563..000000000 --- a/formats_rust/default_big_endian.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: default_big_endian - endian: be -seq: - - id: one - type: u4 diff --git a/formats_rust/default_bit_endian_mod.ksy b/formats_rust/default_bit_endian_mod.ksy deleted file mode 100644 index 48ed70a3e..000000000 --- a/formats_rust/default_bit_endian_mod.ksy +++ /dev/null @@ -1,30 +0,0 @@ -# Test proper propagation of default bit endianness in hierarchies -meta: - id: default_bit_endian_mod -seq: - - id: main - type: main_obj -types: - main_obj: - meta: - bit-endian: le - seq: - - id: one - type: b9 - - id: two - type: b15 - - id: nest - type: subnest - - id: nest_be - type: subnest_be - types: - subnest: - seq: - - id: two - type: b16 - subnest_be: - meta: - bit-endian: be - seq: - - id: two - type: b16 diff --git a/formats_rust/default_endian_expr_exception.ksy b/formats_rust/default_endian_expr_exception.ksy deleted file mode 100644 index 96ac0b5ee..000000000 --- a/formats_rust/default_endian_expr_exception.ksy +++ /dev/null @@ -1,30 +0,0 @@ -# Parses doc[0] and doc[1], then raises an exception on doc[2] due to -# unknown endianness -meta: - id: default_endian_expr_exception -seq: - - id: docs - repeat: eos - type: doc -types: - doc: - seq: - - id: indicator - size: 2 - - id: main - type: main_obj - types: - main_obj: - meta: - endian: - switch-on: _parent.indicator - cases: - '[0x49, 0x49]': le - '[0x4d, 0x4d]': be - seq: - - id: some_int - type: u4 - - id: some_int_be - type: u2be - - id: some_int_le - type: u2le diff --git a/formats_rust/default_endian_expr_inherited.ksy b/formats_rust/default_endian_expr_inherited.ksy deleted file mode 100644 index 8e9455081..000000000 --- a/formats_rust/default_endian_expr_inherited.ksy +++ /dev/null @@ -1,42 +0,0 @@ -meta: - id: default_endian_expr_inherited -seq: - - id: docs - repeat: eos - type: doc -types: - doc: - seq: - - id: indicator - size: 2 - - id: main - type: main_obj - types: - main_obj: - meta: - endian: - switch-on: _parent.indicator - cases: - '[0x49, 0x49]': le - _: be - seq: - - id: insides - type: sub_obj - types: - sub_obj: - seq: - - id: some_int - type: u4 - - id: more - type: subsub_obj - types: - subsub_obj: - seq: - - id: some_int1 - type: u2 - - id: some_int2 - type: u2 - instances: - some_inst: - pos: 2 - type: u4 diff --git a/formats_rust/default_endian_expr_is_be.ksy b/formats_rust/default_endian_expr_is_be.ksy deleted file mode 100644 index 278da9bca..000000000 --- a/formats_rust/default_endian_expr_is_be.ksy +++ /dev/null @@ -1,40 +0,0 @@ -meta: - id: default_endian_expr_is_be -seq: - - id: docs - repeat: eos - type: doc -types: - doc: - seq: - - id: indicator - size: 2 - - id: main - type: main_obj - types: - main_obj: - meta: - endian: - switch-on: _parent.indicator - cases: - '[0x4d, 0x4d]': be - _: le - seq: - - id: some_int - type: u4 - - id: some_int_be - type: u2be - - id: some_int_le - type: u2le - instances: - inst_int: - pos: 2 - type: u4 - inst_sub: - pos: 2 - type: sub_main_obj - types: - sub_main_obj: - seq: - - id: foo - type: u4 diff --git a/formats_rust/default_endian_expr_is_le.ksy b/formats_rust/default_endian_expr_is_le.ksy deleted file mode 100644 index ac1848eb5..000000000 --- a/formats_rust/default_endian_expr_is_le.ksy +++ /dev/null @@ -1,28 +0,0 @@ -meta: - id: default_endian_expr_is_le -seq: - - id: docs - repeat: eos - type: doc -types: - doc: - seq: - - id: indicator - size: 2 - - id: main - type: main_obj - types: - main_obj: - meta: - endian: - switch-on: _parent.indicator - cases: - '[0x49, 0x49]': le - _: be - seq: - - id: some_int - type: u4 - - id: some_int_be - type: u2be - - id: some_int_le - type: u2le diff --git a/formats_rust/default_endian_mod.ksy b/formats_rust/default_endian_mod.ksy deleted file mode 100644 index 379658b80..000000000 --- a/formats_rust/default_endian_mod.ksy +++ /dev/null @@ -1,28 +0,0 @@ -# Test proper propagation of default endianness in hierarchies -meta: - id: default_endian_mod -seq: - - id: main - type: main_obj -types: - main_obj: - meta: - endian: le - seq: - - id: one - type: s4 - - id: nest - type: subnest - - id: nest_be - type: subnest_be - types: - subnest: - seq: - - id: two - type: s4 - subnest_be: - meta: - endian: be - seq: - - id: two - type: s4 diff --git a/formats_rust/docstrings.ksy b/formats_rust/docstrings.ksy deleted file mode 100644 index 9edbbb0b5..000000000 --- a/formats_rust/docstrings.ksy +++ /dev/null @@ -1,31 +0,0 @@ -meta: - id: docstrings -doc: One-liner description of a type. -seq: - - id: one - type: u1 - doc: A pretty verbose description for sequence attribute "one" -types: - complex_subtype: - doc: | - This subtype is never used, yet has a very long description - that spans multiple lines. It should be formatted accordingly, - even in languages that have single-line comments for - docstrings. Actually, there's even a MarkDown-style list here - with several bullets: - - * one - * two - * three - - And the text continues after that. Here's a MarkDown-style link: - [woohoo](http://example.com) - one day it will be supported as - well. -instances: - two: - pos: 0 - type: u1 - doc: Another description for parse instance "two" - three: - value: 0x42 - doc: And yet another one for value instance "three" diff --git a/formats_rust/docstrings_docref.ksy b/formats_rust/docstrings_docref.ksy deleted file mode 100644 index f4aadf20d..000000000 --- a/formats_rust/docstrings_docref.ksy +++ /dev/null @@ -1,26 +0,0 @@ -meta: - id: docstrings_docref -doc: Another one-liner -doc-ref: http://www.example.com/some/path/?even_with=query&more=2 -seq: - - id: one - type: u1 - doc-ref: Plain text description of doc ref, page 42 - - id: two - type: u1 - doc: Both doc and doc-ref are defined - doc-ref: http://www.example.com/with/url/again - - id: three - type: u1 - doc-ref: http://www.example.com/three Documentation name -instances: - foo: - doc-ref: Doc ref for instance, a plain one - value: true - parse_inst: - pos: 0 - type: u1 - doc-ref: | - Now this is a really - long document ref that - spans multiple lines. diff --git a/formats_rust/docstrings_docref_multi.ksy b/formats_rust/docstrings_docref_multi.ksy deleted file mode 100644 index 7a3bc642b..000000000 --- a/formats_rust/docstrings_docref_multi.ksy +++ /dev/null @@ -1,7 +0,0 @@ -meta: - id: docstrings_docref_multi -doc: Sample docstring -doc-ref: - - Plain text description of doc ref, page 42 - - http://www.example.com/some/path/?even_with=query&more=2 - - http://www.example.com/three Documentation name diff --git a/formats_rust/enum_0.ksy b/formats_rust/enum_0.ksy deleted file mode 100644 index 8f9162d57..000000000 --- a/formats_rust/enum_0.ksy +++ /dev/null @@ -1,15 +0,0 @@ -meta: - id: enum_0 - endian: le -seq: - - id: pet_1 - type: u4 - enum: animal - - id: pet_2 - type: u4 - enum: animal -enums: - animal: - 4: dog - 7: cat - 12: chicken diff --git a/formats_rust/enum_1.ksy b/formats_rust/enum_1.ksy deleted file mode 100644 index cce503952..000000000 --- a/formats_rust/enum_1.ksy +++ /dev/null @@ -1,26 +0,0 @@ -# Enum declared in top-level type, used in subtype -meta: - id: enum_1 - endian: le -seq: - - id: main - type: main_obj -types: - main_obj: - seq: - - id: submain - type: submain_obj - types: - submain_obj: - seq: - - id: pet_1 - type: u4 - enum: animal - - id: pet_2 - type: u4 - enum: animal - enums: - animal: - 4: dog - 7: cat - 12: chicken diff --git a/formats_rust/enum_deep.ksy b/formats_rust/enum_deep.ksy deleted file mode 100644 index 29503ca91..000000000 --- a/formats_rust/enum_deep.ksy +++ /dev/null @@ -1,24 +0,0 @@ -meta: - id: enum_deep - endian: le -seq: - - id: pet_1 - type: u4 - enum: container1::animal - - id: pet_2 - type: u4 - enum: container1::container2::animal -types: - container1: - enums: - animal: - 4: dog - 7: cat - 12: chicken - types: - container2: - enums: - animal: - 4: canary - 7: turtle - 12: hare diff --git a/formats_rust/enum_deep_literals.ksy b/formats_rust/enum_deep_literals.ksy deleted file mode 100644 index f3b44ef14..000000000 --- a/formats_rust/enum_deep_literals.ksy +++ /dev/null @@ -1,29 +0,0 @@ -meta: - id: enum_deep_literals - endian: le -seq: - - id: pet_1 - type: u4 - enum: container1::animal - - id: pet_2 - type: u4 - enum: container1::container2::animal -instances: - is_pet_1_ok: - value: pet_1 == container1::animal::cat - is_pet_2_ok: - value: pet_2 == container1::container2::animal::hare -types: - container1: - enums: - animal: - 4: dog - 7: cat - 12: chicken - types: - container2: - enums: - animal: - 4: canary - 7: turtle - 12: hare diff --git a/formats_rust/enum_fancy.ksy b/formats_rust/enum_fancy.ksy deleted file mode 100644 index e6b899eb2..000000000 --- a/formats_rust/enum_fancy.ksy +++ /dev/null @@ -1,21 +0,0 @@ -meta: - id: enum_fancy - endian: le -seq: - - id: pet_1 - type: u4 - enum: animal - - id: pet_2 - type: u4 - enum: animal -enums: - animal: - 4: - id: dog - doc: A member of genus Canis. - -orig-id: MH_CANINE - 7: - id: cat - doc: Small, typically furry, carnivorous mammal. - -orig-id: MH_FELINE - 12: chicken diff --git a/formats_rust/enum_for_unknown_id.ksy b/formats_rust/enum_for_unknown_id.ksy deleted file mode 100644 index fce1630e9..000000000 --- a/formats_rust/enum_for_unknown_id.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: enum_for_unknown_id -seq: - - id: one - type: u1 - enum: animal -enums: - animal: - 4: dog - 7: cat - 12: chicken diff --git a/formats_rust/enum_if.ksy b/formats_rust/enum_if.ksy deleted file mode 100644 index 26d0b0098..000000000 --- a/formats_rust/enum_if.ksy +++ /dev/null @@ -1,40 +0,0 @@ -meta: - id: enum_if - endian: le -seq: - - id: op1 - type: operation - - id: op2 - type: operation - - id: op3 - type: operation -types: - operation: - seq: - - id: opcode - type: u1 - enum: opcodes - - id: arg_tuple - type: arg_tuple - if: opcode == opcodes::a_tuple - - id: arg_str - type: arg_str - if: opcode == opcodes::a_string - arg_tuple: - seq: - - id: num1 - type: u1 - - id: num2 - type: u1 - arg_str: - seq: - - id: len - type: u1 - - id: str - type: str - size: len - encoding: UTF-8 -enums: - opcodes: - 0x53: a_string - 0x54: a_tuple diff --git a/formats_rust/enum_import.ksy b/formats_rust/enum_import.ksy deleted file mode 100644 index bec0bff8a..000000000 --- a/formats_rust/enum_import.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: enum_import - endian: le - imports: - - enum_0 - - enum_deep -seq: - - id: pet_1 - type: u4 - enum: enum_0::animal - - id: pet_2 - type: u4 - enum: enum_deep::container1::container2::animal diff --git a/formats_rust/enum_int_range_s.ksy b/formats_rust/enum_int_range_s.ksy deleted file mode 100644 index a72c03bb9..000000000 --- a/formats_rust/enum_int_range_s.ksy +++ /dev/null @@ -1,21 +0,0 @@ -# Assert that enum id's can handle values in Int's range -meta: - id: enum_int_range_s - endian: be - -enums: - constants: - -2147483648: int_min - 0: zero - 2147483647: int_max - -seq: - - id: f1 - type: s4 - enum: constants - - id: f2 - type: s4 - enum: constants - - id: f3 - type: s4 - enum: constants diff --git a/formats_rust/enum_int_range_u.ksy b/formats_rust/enum_int_range_u.ksy deleted file mode 100644 index 120b3a1f8..000000000 --- a/formats_rust/enum_int_range_u.ksy +++ /dev/null @@ -1,17 +0,0 @@ -# Assert that enum id's can handle values in Int's range -meta: - id: enum_int_range_u - endian: be - -enums: - constants: - 0: zero - 4294967295: int_max - -seq: - - id: f1 - type: u4 - enum: constants - - id: f2 - type: u4 - enum: constants diff --git a/formats_rust/enum_invalid.ksy b/formats_rust/enum_invalid.ksy deleted file mode 100644 index bace37da8..000000000 --- a/formats_rust/enum_invalid.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: enum_invalid -seq: - - id: pet_1 - type: u1 - enum: animal - - id: pet_2 - type: u1 - enum: animal -enums: - animal: - 0x66: dog - 0x7c: cat diff --git a/formats_rust/enum_long_range_s.ksy b/formats_rust/enum_long_range_s.ksy deleted file mode 100644 index 17e025817..000000000 --- a/formats_rust/enum_long_range_s.ksy +++ /dev/null @@ -1,37 +0,0 @@ -# Assert that enum id's can handle values in Long's range -meta: - id: enum_long_range_s - endian: be - -enums: - constants: - -9223372036854775808: long_min - -2147483649: int_below_min - -2147483648: int_min - 0: zero - 2147483647: int_max - 2147483648: int_over_max - 9223372036854775807: long_max - -seq: - - id: f1 - type: s8 - enum: constants - - id: f2 - type: s8 - enum: constants - - id: f3 - type: s8 - enum: constants - - id: f4 - type: s8 - enum: constants - - id: f5 - type: s8 - enum: constants - - id: f6 - type: s8 - enum: constants - - id: f7 - type: s8 - enum: constants diff --git a/formats_rust/enum_long_range_u.ksy b/formats_rust/enum_long_range_u.ksy deleted file mode 100644 index 453dc0856..000000000 --- a/formats_rust/enum_long_range_u.ksy +++ /dev/null @@ -1,25 +0,0 @@ -# Assert that enum id's can handle values in Long's range -meta: - id: enum_long_range_u - endian: be - -enums: - constants: - 0: zero - 4294967295: int_max - 4294967296: int_over_max - 9223372036854775807: long_max # todo with `9223372036854775807` generator will fail with `io.kaitai.struct.format.YAMLParseException: /enums/constants: expected int, got 18446744073709551615 (class java.math.BigInteger)` - -seq: - - id: f1 - type: u8 - enum: constants - - id: f2 - type: u8 - enum: constants - - id: f3 - type: u8 - enum: constants - - id: f4 - type: u8 - enum: constants diff --git a/formats_rust/enum_negative.ksy b/formats_rust/enum_negative.ksy deleted file mode 100644 index ea7142c2a..000000000 --- a/formats_rust/enum_negative.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: enum_negative -enums: - constants: - -1: negative_one - 1: positive_one -seq: - - id: f1 - type: s1 - enum: constants - - id: f2 - type: s1 - enum: constants diff --git a/formats_rust/enum_of_value_inst.ksy b/formats_rust/enum_of_value_inst.ksy deleted file mode 100644 index c3e24a908..000000000 --- a/formats_rust/enum_of_value_inst.ksy +++ /dev/null @@ -1,21 +0,0 @@ -meta: - id: enum_of_value_inst - endian: le -seq: - - id: pet_1 - type: u4 - enum: animal - - id: pet_2 - type: u4 - enum: animal -enums: - animal: - 4: dog - 7: cat - 12: chicken -instances: - pet_3: - value: "pet_1 == animal::cat ? 4 : 12" - enum: animal - pet_4: - value: "pet_1 == animal::cat ? animal::dog : animal::chicken" diff --git a/formats_rust/enum_to_i.ksy b/formats_rust/enum_to_i.ksy deleted file mode 100644 index 3de13f6a0..000000000 --- a/formats_rust/enum_to_i.ksy +++ /dev/null @@ -1,26 +0,0 @@ -meta: - id: enum_to_i - endian: le -seq: - - id: pet_1 - type: u4 - enum: animal - - id: pet_2 - type: u4 - enum: animal -enums: - animal: - 4: dog - 7: cat - 12: chicken -instances: - pet_1_i: - value: pet_1.to_i - pet_1_mod: - value: pet_1.to_i + 0x8000 - one_lt_two: - value: pet_1.to_i < pet_2.to_i - pet_1_eq_int: - value: pet_1.to_i == 7 - pet_2_eq_int: - value: pet_2.to_i == 5 diff --git a/formats_rust/enum_to_i_class_border_1.ksy b/formats_rust/enum_to_i_class_border_1.ksy deleted file mode 100644 index 7821b6f5b..000000000 --- a/formats_rust/enum_to_i_class_border_1.ksy +++ /dev/null @@ -1,29 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/552 -meta: - id: enum_to_i_class_border_1 - endian: le - imports: - - enum_to_i_class_border_2 - -seq: - - id: pet_1 - type: u4 - enum: animal - - id: pet_2 - type: u4 - enum: animal - -enums: - animal: - 4: dog - 7: cat - 12: chicken - -instances: - some_dog: - value: 4 - enum: animal - - checker: - pos: 0 - type: enum_to_i_class_border_2(_root) diff --git a/formats_rust/enum_to_i_class_border_2.ksy b/formats_rust/enum_to_i_class_border_2.ksy deleted file mode 100644 index a316791ff..000000000 --- a/formats_rust/enum_to_i_class_border_2.ksy +++ /dev/null @@ -1,14 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/552 -meta: - id: enum_to_i_class_border_2 - endian: le - imports: - - enum_to_i_class_border_1 - -params: - - id: parent - type: enum_to_i_class_border_1 - -instances: - is_dog: - value: parent.some_dog.to_i == 4 diff --git a/formats_rust/eof_exception_bytes.ksy b/formats_rust/eof_exception_bytes.ksy deleted file mode 100644 index 22f5ff876..000000000 --- a/formats_rust/eof_exception_bytes.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: eof_exception_bytes -seq: - - id: buf - # only 12 bytes available, should fail with EOF exception - size: 13 diff --git a/formats_rust/eof_exception_u4.ksy b/formats_rust/eof_exception_u4.ksy deleted file mode 100644 index 2a0e7c97c..000000000 --- a/formats_rust/eof_exception_u4.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: eof_exception_u4 -seq: - # only 12 bytes available, should fail with EOF exception - - id: prebuf - size: 9 - - id: fail_int - type: u4le diff --git a/formats_rust/eos_exception_bytes.ksy b/formats_rust/eos_exception_bytes.ksy deleted file mode 100644 index ca7e7a452..000000000 --- a/formats_rust/eos_exception_bytes.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: eos_exception_bytes -seq: - - id: envelope - type: data - size: 6 -types: - data: - seq: - - id: buf - size: 7 diff --git a/formats_rust/eos_exception_u4.ksy b/formats_rust/eos_exception_u4.ksy deleted file mode 100644 index e3cd4a153..000000000 --- a/formats_rust/eos_exception_u4.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: eos_exception_u4 -seq: - - id: envelope - type: data - size: 6 -types: - data: - seq: - - id: prebuf - size: 3 - - id: fail_int - type: u4le diff --git a/formats_rust/expr_0.ksy b/formats_rust/expr_0.ksy deleted file mode 100644 index 3fbd61e76..000000000 --- a/formats_rust/expr_0.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: expr_0 - endian: le -seq: - - id: len_of_1 - type: u2 -instances: - must_be_f7: - value: 7 + 0xf0 - must_be_abc123: - value: '"abc" + "123"' diff --git a/formats_rust/expr_1.ksy b/formats_rust/expr_1.ksy deleted file mode 100644 index 6b2921094..000000000 --- a/formats_rust/expr_1.ksy +++ /dev/null @@ -1,15 +0,0 @@ -meta: - id: expr_1 - endian: le -seq: - - id: len_of_1 - type: u2 - - id: str1 - type: str - size: len_of_1_mod - encoding: ASCII -instances: - len_of_1_mod: - value: len_of_1 - 2 - str1_len: - value: str1.length diff --git a/formats_rust/expr_2.ksy b/formats_rust/expr_2.ksy deleted file mode 100644 index 1158b346d..000000000 --- a/formats_rust/expr_2.ksy +++ /dev/null @@ -1,57 +0,0 @@ -meta: - id: expr_2 - endian: le -seq: - - id: str1 - type: mod_str - - id: str2 - type: mod_str -types: - mod_str: - seq: - - id: len_orig - type: u2 - - id: str - type: str - size: len_mod - encoding: UTF-8 - - id: rest - type: tuple - size: 3 - instances: - len_mod: - value: len_orig - 3 - char5: - pos: 5 - type: str - size: 1 - encoding: ASCII - tuple5: - pos: 5 - type: tuple - tuple: - seq: - - id: byte0 - type: u1 - - id: byte1 - type: u1 - - id: byte2 - type: u1 - instances: - avg: - value: (byte1 + byte2) / 2 -instances: - str1_len: - value: str1.str.length - str1_len_mod: - value: str1.len_mod - str1_byte1: - value: str1.rest.byte1 - str1_avg: - value: str1.rest.avg - str1_char5: - value: str1.char5 - str1_tuple5: - value: str1.tuple5 - str2_tuple5: - value: str2.tuple5 diff --git a/formats_rust/expr_3.ksy b/formats_rust/expr_3.ksy deleted file mode 100644 index e0b63ed12..000000000 --- a/formats_rust/expr_3.ksy +++ /dev/null @@ -1,31 +0,0 @@ -# Tests string concat, comparisons and boolean instance results -meta: - id: expr_3 -seq: - - id: one - type: u1 - - id: two - type: str - encoding: ASCII - size: 3 -instances: - three: - value: '"@" + two' - four: - value: '"_" + two + "_"' - is_str_eq: - value: two == "ACK" - is_str_ne: - value: two != "ACK" - is_str_lt: - value: two < "ACK2" - is_str_gt: - value: two > "ACK2" - is_str_le: - value: two <= "ACK2" - is_str_ge: - value: two >= "ACK2" - is_str_lt2: - value: three < two - test_not: - value: not false diff --git a/formats_rust/expr_array.ksy b/formats_rust/expr_array.ksy deleted file mode 100644 index af08b8e91..000000000 --- a/formats_rust/expr_array.ksy +++ /dev/null @@ -1,50 +0,0 @@ -meta: - id: expr_array - endian: le - encoding: UTF-8 -seq: - - id: aint - type: u4 - repeat: expr - repeat-expr: 4 - - id: afloat - type: f8 - repeat: expr - repeat-expr: 3 - - id: astr - type: strz - repeat: expr - repeat-expr: 3 -instances: - aint_size: - value: aint.size - aint_first: - value: aint.first - aint_last: - value: aint.last - aint_min: - value: aint.min - aint_max: - value: aint.max - - afloat_size: - value: afloat.size - afloat_first: - value: afloat.first - afloat_last: - value: afloat.last - afloat_min: - value: afloat.min - afloat_max: - value: afloat.max - - astr_size: - value: astr.size - astr_first: - value: astr.first - astr_last: - value: astr.last - astr_min: - value: astr.min - astr_max: - value: astr.max diff --git a/formats_rust/expr_bits.ksy b/formats_rust/expr_bits.ksy deleted file mode 100644 index 608694f2e..000000000 --- a/formats_rust/expr_bits.ksy +++ /dev/null @@ -1,43 +0,0 @@ -meta: - id: expr_bits -seq: - - id: enum_seq - type: b2 - enum: items - - id: a - type: b3 - - id: byte_size - size: a - - id: repeat_expr - type: s1 - repeat: expr - repeat-expr: a - - id: switch_on_type - type: - switch-on: a - cases: - 2: s1 - - id: switch_on_endian - type: endian_switch -instances: - enum_inst: - value: a - enum: items - inst_pos: - pos: a - type: s1 -types: - endian_switch: - meta: - endian: - switch-on: _parent.a - cases: - 1: le - 2: be - seq: - - id: foo - type: s2 -enums: - items: - 1: foo - 2: bar diff --git a/formats_rust/expr_bytes_cmp.ksy b/formats_rust/expr_bytes_cmp.ksy deleted file mode 100644 index 5233b58ac..000000000 --- a/formats_rust/expr_bytes_cmp.ksy +++ /dev/null @@ -1,31 +0,0 @@ -# Tests bytearray comparisons -meta: - id: expr_bytes_cmp -seq: - - id: one - size: 1 - - id: two - size: 3 -instances: - ack: - value: '[65, 67, 75]' - ack2: - value: '[65, 67, 75, 50]' - hi_val: - value: '[0x90, 67]' - is_eq: - value: two == ack - is_ne: - value: two != ack - is_lt: - value: two < ack2 - is_gt: - value: two > ack2 - is_le: - value: two <= ack2 - is_ge: - value: two >= ack2 - is_lt2: - value: one < two - is_gt2: - value: hi_val > two diff --git a/formats_rust/expr_bytes_non_literal.ksy b/formats_rust/expr_bytes_non_literal.ksy deleted file mode 100644 index 5f1ba49bf..000000000 --- a/formats_rust/expr_bytes_non_literal.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: expr_bytes_non_literal -seq: - - id: one - type: u1 - - id: two - type: u1 -instances: - calc_bytes: - value: '[one, two].as' diff --git a/formats_rust/expr_bytes_ops.ksy b/formats_rust/expr_bytes_ops.ksy deleted file mode 100644 index 5c7ad8e08..000000000 --- a/formats_rust/expr_bytes_ops.ksy +++ /dev/null @@ -1,34 +0,0 @@ -meta: - id: expr_bytes_ops -seq: - - id: one - size: 3 -instances: - two: - value: '[0x41, 0xff, 0x4b]' - - one_size: - value: one.size - one_first: - value: one.first - one_mid: - value: one[1] - one_last: - value: one.last - one_min: - value: one.min - one_max: - value: one.max - - two_size: - value: two.size - two_first: - value: two.first - two_mid: - value: two[1] - two_last: - value: two.last - two_min: - value: two.min - two_max: - value: two.max diff --git a/formats_rust/expr_calc_array_ops.ksy b/formats_rust/expr_calc_array_ops.ksy deleted file mode 100644 index 693555dd6..000000000 --- a/formats_rust/expr_calc_array_ops.ksy +++ /dev/null @@ -1,48 +0,0 @@ -meta: - id: expr_calc_array_ops -instances: - int_array: - value: '[10, 25, 50, 100, 200, 500, 1000]' - double_array: - value: '[10.0, 25.0, 50.0, 100.0, 3.14159]' - str_array: - value: '["un", "deux", "trois", "quatre"]' - - int_array_size: - value: int_array.size - int_array_first: - value: int_array.first - int_array_mid: - value: int_array[1] - int_array_last: - value: int_array.last - int_array_min: - value: int_array.min - int_array_max: - value: int_array.max - - double_array_size: - value: double_array.size - double_array_first: - value: double_array.first - double_array_mid: - value: double_array[1] - double_array_last: - value: double_array.last - double_array_min: - value: double_array.min - double_array_max: - value: double_array.max - - str_array_size: - value: str_array.size - str_array_first: - value: str_array.first - str_array_mid: - value: str_array[1] - str_array_last: - value: str_array.last - str_array_min: - value: str_array.min - str_array_max: - value: str_array.max diff --git a/formats_rust/expr_enum.ksy b/formats_rust/expr_enum.ksy deleted file mode 100644 index 793949db8..000000000 --- a/formats_rust/expr_enum.ksy +++ /dev/null @@ -1,22 +0,0 @@ -# Tests enum for value instances -meta: - id: expr_enum -seq: - - id: one - type: u1 -instances: - const_dog: - value: 4 - enum: animal - derived_boom: - value: one - enum: animal - derived_dog: - value: one - 98 - enum: animal -enums: - animal: - 4: dog - 7: cat - 12: chicken - 0x66: boom diff --git a/formats_rust/expr_if_int_ops.ksy b/formats_rust/expr_if_int_ops.ksy deleted file mode 100644 index 8fbc48c42..000000000 --- a/formats_rust/expr_if_int_ops.ksy +++ /dev/null @@ -1,17 +0,0 @@ -meta: - id: expr_if_int_ops - endian: le -seq: - - id: skip - size: 2 - - id: it - type: s2 - if: true - - id: boxed - type: s2 - if: true -instances: - is_eq_prim: - value: it == 0x4141 - is_eq_boxed: - value: it == boxed diff --git a/formats_rust/expr_int_div.ksy b/formats_rust/expr_int_div.ksy deleted file mode 100644 index 31b690948..000000000 --- a/formats_rust/expr_int_div.ksy +++ /dev/null @@ -1,20 +0,0 @@ -# Tests division operation, both positive and negative -# See https://github.com/kaitai-io/kaitai_struct/issues/746 -# => the KS division operation `a / b` should do `floor(a / b)` -meta: - id: expr_int_div - endian: le -seq: - - id: int_u - type: u4 - - id: int_s - type: s4 -instances: - div_pos_const: - value: 9837 / 13 - div_neg_const: - value: -9837 / 13 - div_pos_seq: - value: int_u / 13 - div_neg_seq: - value: int_s / 13 diff --git a/formats_rust/expr_io_eof.ksy b/formats_rust/expr_io_eof.ksy deleted file mode 100644 index d27f1847c..000000000 --- a/formats_rust/expr_io_eof.ksy +++ /dev/null @@ -1,22 +0,0 @@ -# Tests _io.eof operation -meta: - id: expr_io_eof - endian: le -seq: - - id: substream1 - size: 4 - type: one_or_two - - id: substream2 - size: 8 - type: one_or_two -types: - one_or_two: - seq: - - id: one - type: u4 - - id: two - type: u4 - if: not _io.eof - instances: - reflect_eof: - value: _io.eof diff --git a/formats_rust/expr_io_pos.ksy b/formats_rust/expr_io_pos.ksy deleted file mode 100644 index 247478a6e..000000000 --- a/formats_rust/expr_io_pos.ksy +++ /dev/null @@ -1,21 +0,0 @@ -# Tests _io.pos operation -meta: - id: expr_io_pos - endian: le -seq: - - id: substream1 - size: 16 - type: all_plus_number - - id: substream2 - size: 14 - type: all_plus_number -types: - all_plus_number: - seq: - - id: my_str - type: strz - encoding: UTF-8 - - id: body - size: _io.size - _io.pos - 2 - - id: number - type: u2 diff --git a/formats_rust/expr_mod.ksy b/formats_rust/expr_mod.ksy deleted file mode 100644 index bd218a7ee..000000000 --- a/formats_rust/expr_mod.ksy +++ /dev/null @@ -1,18 +0,0 @@ -# Tests modulo operation, both positive and negative -meta: - id: expr_mod - endian: le -seq: - - id: int_u - type: u4 - - id: int_s - type: s4 -instances: - mod_pos_const: - value: 9837 % 13 - mod_neg_const: - value: -9837 % 13 - mod_pos_seq: - value: int_u % 13 - mod_neg_seq: - value: int_s % 13 diff --git a/formats_rust/expr_ops_parens.ksy b/formats_rust/expr_ops_parens.ksy deleted file mode 100644 index 1ed344356..000000000 --- a/formats_rust/expr_ops_parens.ksy +++ /dev/null @@ -1,36 +0,0 @@ -meta: - id: expr_ops_parens -instances: - i_42: - value: 42 - i_m13: - value: -13 - i_sum_to_str: - value: (i_42 + i_m13).to_s - - f_2pi: - value: 6.28 - f_e: - value: 2.72 - f_sum_to_int: - value: (f_2pi + f_e).to_i - - str_0_to_4: - value: '"01234"' - str_5_to_9: - value: '"56789"' - str_concat_len: - value: (str_0_to_4 + str_5_to_9).length - str_concat_rev: - value: (str_0_to_4 + str_5_to_9).reverse - str_concat_substr_2_to_7: - value: (str_0_to_4 + str_5_to_9).substring(2, 7) - str_concat_to_i: - value: (str_0_to_4 + str_5_to_9).to_i - - bool_eq: - value: (false == true).to_i - bool_and: - value: (false and true).to_i - bool_or: - value: (not false or false).to_i diff --git a/formats_rust/expr_sizeof_type_0.ksy b/formats_rust/expr_sizeof_type_0.ksy deleted file mode 100644 index 1bdd2f6d0..000000000 --- a/formats_rust/expr_sizeof_type_0.ksy +++ /dev/null @@ -1,15 +0,0 @@ -meta: - id: expr_sizeof_type_0 - endian: le -types: - block: - seq: - - id: a - type: u1 - - id: b - type: u4 - - id: c - size: 2 -instances: - sizeof_block: - value: sizeof diff --git a/formats_rust/expr_sizeof_type_1.ksy b/formats_rust/expr_sizeof_type_1.ksy deleted file mode 100644 index 98aeb04b1..000000000 --- a/formats_rust/expr_sizeof_type_1.ksy +++ /dev/null @@ -1,24 +0,0 @@ -meta: - id: expr_sizeof_type_1 - endian: le -types: - block: - seq: - - id: a - type: u1 - - id: b - type: u4 - - id: c - size: 2 - - id: d - type: subblock - types: - subblock: - seq: - - id: a - size: 4 -instances: - sizeof_block: - value: sizeof - sizeof_subblock: - value: sizeof diff --git a/formats_rust/expr_sizeof_value_0.ksy b/formats_rust/expr_sizeof_value_0.ksy deleted file mode 100644 index 977aa3601..000000000 --- a/formats_rust/expr_sizeof_value_0.ksy +++ /dev/null @@ -1,28 +0,0 @@ -meta: - id: expr_sizeof_value_0 - endian: le -types: - block: - seq: - - id: a - type: u1 - - id: b - type: u4 - - id: c - size: 2 -seq: - - id: block1 - type: block - - id: more - type: u2 -instances: - self_sizeof: - value: _sizeof - sizeof_block: - value: block1._sizeof - sizeof_block_a: - value: block1.a._sizeof - sizeof_block_b: - value: block1.b._sizeof - sizeof_block_c: - value: block1.c._sizeof diff --git a/formats_rust/expr_sizeof_value_sized.ksy b/formats_rust/expr_sizeof_value_sized.ksy deleted file mode 100644 index ad07613fd..000000000 --- a/formats_rust/expr_sizeof_value_sized.ksy +++ /dev/null @@ -1,29 +0,0 @@ -meta: - id: expr_sizeof_value_sized - endian: le -types: - block: - seq: - - id: a - type: u1 - - id: b - type: u4 - - id: c - size: 2 -seq: - - id: block1 - type: block - size: 12 - - id: more - type: u2 -instances: - self_sizeof: - value: _sizeof - sizeof_block: - value: block1._sizeof - sizeof_block_a: - value: block1.a._sizeof - sizeof_block_b: - value: block1.b._sizeof - sizeof_block_c: - value: block1.c._sizeof diff --git a/formats_rust/expr_str_encodings.ksy b/formats_rust/expr_str_encodings.ksy deleted file mode 100644 index 0ae2de1a0..000000000 --- a/formats_rust/expr_str_encodings.ksy +++ /dev/null @@ -1,44 +0,0 @@ -meta: - id: expr_str_encodings - endian: le -seq: - - id: len_of_1 - type: u2 - - id: str1 - type: str - size: len_of_1 - encoding: ASCII - - id: len_of_2 - type: u2 - - id: str2 - type: str - size: len_of_2 - encoding: UTF-8 - - id: len_of_3 - type: u2 - - id: str3 - type: str - size: len_of_3 - encoding: SJIS - - id: len_of_4 - type: u2 - - id: str4 - type: str - size: len_of_4 - encoding: CP437 -instances: - str1_eq: - value: str1 == "Some ASCII" - str2_eq: - value: str2 == "こんにちは" - str3_eq: - value: str3 == "こんにちは" - str3_eq_str2: - value: str3 == str2 - str4_eq: - value: str4 == "░▒▓" - str4_gt_str_calc: - value: str4 > "┤" # in UTF-8 "░" (U+2591) > "┤" (U+2524), - # in CP437 "░" (0xB0) < "┤" (0xB4) - str4_gt_str_from_bytes: - value: 'str4 > [0xb4].to_s("CP437")' diff --git a/formats_rust/expr_str_ops.ksy b/formats_rust/expr_str_ops.ksy deleted file mode 100644 index 6337bd6ae..000000000 --- a/formats_rust/expr_str_ops.ksy +++ /dev/null @@ -1,42 +0,0 @@ -meta: - id: expr_str_ops - encoding: ASCII -seq: - - id: one - type: str - size: 5 -instances: - one_len: - value: one.length - one_rev: - value: one.reverse - one_substr_0_to_3: - value: one.substring(0, 3) - one_substr_2_to_5: - value: one.substring(2, 5) - one_substr_3_to_3: - value: one.substring(3, 3) - - two: - value: '"0123456789"' - two_len: - value: two.length - two_rev: - value: two.reverse - two_substr_0_to_7: - value: two.substring(0, 7) - two_substr_4_to_10: - value: two.substring(4, 10) - two_substr_0_to_10: - value: two.substring(0, 10) - - to_i_attr: - value: '"9173".to_i' - to_i_r10: - value: '"-072".to_i(10)' - to_i_r2: - value: '"1010110".to_i(2)' - to_i_r8: - value: '"721".to_i(8)' - to_i_r16: - value: '"47cf".to_i(16)' diff --git a/formats_rust/fixed_contents.ksy b/formats_rust/fixed_contents.ksy deleted file mode 100644 index 249a8eb29..000000000 --- a/formats_rust/fixed_contents.ksy +++ /dev/null @@ -1,7 +0,0 @@ -meta: - id: fixed_contents -seq: - - id: normal - contents: 'PACK-1' - - id: high_bit_8 - contents: [0xff, 0xff] diff --git a/formats_rust/fixed_struct.ksy b/formats_rust/fixed_struct.ksy deleted file mode 100644 index d793538cf..000000000 --- a/formats_rust/fixed_struct.ksy +++ /dev/null @@ -1,91 +0,0 @@ -meta: - id: fixed_struct - endian: le -types: - header: - seq: - - - id: magic1 - contents: 'PACK-1' - - - id: uint8 - type: u1 - - - id: sint8 - type: s1 - - - id: magic_uint - contents: 'PACK-U-DEF' - - - id: uint16 - type: u2 - - - id: uint32 - type: u4 - - - id: uint64 - type: u8 - - - id: magic_sint - contents: 'PACK-S-DEF' - - - id: sint16 - type: s2 - - - id: sint32 - type: s4 - - - id: sint64 - type: s8 - - - id: magic_uint_le - contents: 'PACK-U-LE' - - - id: uint16le - type: u2le - - - id: uint32le - type: u4le - - - id: uint64le - type: u8le - - - id: magic_sint_le - contents: 'PACK-S-LE' - - - id: sint16le - type: s2le - - - id: sint32le - type: s4le - - - id: sint64le - type: s8le - - - id: magic_uint_be - contents: 'PACK-U-BE' - - - id: uint16be - type: u2be - - - id: uint32be - type: u4be - - - id: uint64be - type: u8be - - - id: magic_sint_be - contents: 'PACK-S-BE' - - - id: sint16be - type: s2be - - - id: sint32be - type: s4be - - - id: sint64be - type: s8be -instances: - hdr: - pos: 0 - type: header diff --git a/formats_rust/float_to_i.ksy b/formats_rust/float_to_i.ksy deleted file mode 100644 index 6370838af..000000000 --- a/formats_rust/float_to_i.ksy +++ /dev/null @@ -1,29 +0,0 @@ -meta: - id: float_to_i - endian: le -seq: - - id: single_value - type: f4 - - id: double_value - type: f8 -instances: - calc_float1: - value: 1.234 - calc_float2: - value: 1.5 - calc_float3: - value: 1.9 - calc_float4: - value: -2.7 - single_i: - value: single_value.to_i - double_i: - value: double_value.to_i - float1_i: - value: calc_float1.to_i - float2_i: - value: calc_float2.to_i - float3_i: - value: calc_float3.to_i - float4_i: - value: calc_float4.to_i diff --git a/formats_rust/floating_points.ksy b/formats_rust/floating_points.ksy deleted file mode 100644 index 571165e0b..000000000 --- a/formats_rust/floating_points.ksy +++ /dev/null @@ -1,21 +0,0 @@ -meta: - id: floating_points - endian: le -seq: - - id: single_value - type: f4 - - id: double_value - type: f8 - - id: single_value_be - type: f4be - - id: double_value_be - type: f8be - - id: approximate_value - type: f4 -instances: - single_value_plus_int: - value: single_value + 1 - single_value_plus_float: - value: single_value + 0.5 - double_value_plus_float: - value: double_value + 0.05 diff --git a/formats_rust/for_rel_imports/imported_1.ksy b/formats_rust/for_rel_imports/imported_1.ksy deleted file mode 100644 index 1e5814261..000000000 --- a/formats_rust/for_rel_imports/imported_1.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: imported_1 - imports: - - imported_2 -seq: - - id: one - type: u1 - - id: two - type: imported_2 diff --git a/formats_rust/for_rel_imports/imported_2.ksy b/formats_rust/for_rel_imports/imported_2.ksy deleted file mode 100644 index 861945e99..000000000 --- a/formats_rust/for_rel_imports/imported_2.ksy +++ /dev/null @@ -1,5 +0,0 @@ -meta: - id: imported_2 -seq: - - id: one - type: u1 diff --git a/formats_rust/hello_world.ksy b/formats_rust/hello_world.ksy deleted file mode 100644 index cde97cd79..000000000 --- a/formats_rust/hello_world.ksy +++ /dev/null @@ -1,5 +0,0 @@ -meta: - id: hello_world -seq: - - id: one - type: u1 diff --git a/formats_rust/if_instances.ksy b/formats_rust/if_instances.ksy deleted file mode 100644 index 186371466..000000000 --- a/formats_rust/if_instances.ksy +++ /dev/null @@ -1,9 +0,0 @@ -# Checks that `if` for instance protects us from doing any activity -# for instance completely, including seeks. -meta: - id: if_instances -instances: - never_happens: - pos: 100500 # does not exist in the stream - type: u1 - if: 'false' # should never happen diff --git a/formats_rust/if_struct.ksy b/formats_rust/if_struct.ksy deleted file mode 100644 index 79009fd3a..000000000 --- a/formats_rust/if_struct.ksy +++ /dev/null @@ -1,35 +0,0 @@ -meta: - id: if_struct - endian: le -seq: - - id: op1 - type: operation - - id: op2 - type: operation - - id: op3 - type: operation -types: - operation: - seq: - - id: opcode - type: u1 - - id: arg_tuple - type: arg_tuple - if: opcode == 0x54 # "T" - - id: arg_str - type: arg_str - if: opcode == 0x53 # "S" - arg_tuple: - seq: - - id: num1 - type: u1 - - id: num2 - type: u1 - arg_str: - seq: - - id: len - type: u1 - - id: str - type: str - size: len - encoding: UTF-8 diff --git a/formats_rust/if_values.ksy b/formats_rust/if_values.ksy deleted file mode 100644 index b781b3e82..000000000 --- a/formats_rust/if_values.ksy +++ /dev/null @@ -1,17 +0,0 @@ -meta: - id: if_values - endian: le -seq: - - id: codes - type: code - repeat: expr - repeat-expr: 3 -types: - code: - seq: - - id: opcode - type: u1 - instances: - half_opcode: - value: opcode / 2 - if: opcode % 2 == 0 diff --git a/formats_rust/imports0.ksy b/formats_rust/imports0.ksy deleted file mode 100644 index 5fb321669..000000000 --- a/formats_rust/imports0.ksy +++ /dev/null @@ -1,12 +0,0 @@ -meta: - id: imports0 - imports: - - hello_world -seq: - - id: two - type: u1 - - id: hw - type: hello_world -instances: - hw_one: - value: hw.one diff --git a/formats_rust/imports_abs.ksy b/formats_rust/imports_abs.ksy deleted file mode 100644 index 873ce6a1f..000000000 --- a/formats_rust/imports_abs.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: imports_abs - imports: - - /common/vlq_base128_le -seq: - - id: len - type: vlq_base128_le - - id: body - size: len.value diff --git a/formats_rust/imports_abs_abs.ksy b/formats_rust/imports_abs_abs.ksy deleted file mode 100644 index 09f06422c..000000000 --- a/formats_rust/imports_abs_abs.ksy +++ /dev/null @@ -1,12 +0,0 @@ -# Test chain of absolute-into-absolute imports -# -# this -> $KS_PATH/for_abs_imports/imported_and_abs -> $KS_PATH/more_abs/imported_root -meta: - id: imports_abs_abs - imports: - - /for_abs_imports/imported_and_abs -seq: - - id: one - type: u1 - - id: two - type: imported_and_abs diff --git a/formats_rust/imports_abs_rel.ksy b/formats_rust/imports_abs_rel.ksy deleted file mode 100644 index 7862d9f0d..000000000 --- a/formats_rust/imports_abs_rel.ksy +++ /dev/null @@ -1,12 +0,0 @@ -# Test chain of absolute-into-absolute imports -# -# this -> $KS_PATH/for_abs_imports/imported_and_rel -> $KS_PATH/more_abs/imported_root -meta: - id: imports_abs_rel - imports: - - /for_abs_imports/imported_and_rel -seq: - - id: one - type: u1 - - id: two - type: imported_and_rel diff --git a/formats_rust/imports_circular_a.ksy b/formats_rust/imports_circular_a.ksy deleted file mode 100644 index 8fce0cbd5..000000000 --- a/formats_rust/imports_circular_a.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: imports_circular_a - imports: - - imports_circular_b -seq: - - id: code - type: u1 - - id: two - type: imports_circular_b diff --git a/formats_rust/imports_circular_b.ksy b/formats_rust/imports_circular_b.ksy deleted file mode 100644 index 85cdd885e..000000000 --- a/formats_rust/imports_circular_b.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: imports_circular_b - imports: - - imports_circular_a -seq: - - id: initial - type: u1 - - id: back_ref - type: imports_circular_a - if: initial == 0x41 diff --git a/formats_rust/imports_rel_1.ksy b/formats_rust/imports_rel_1.ksy deleted file mode 100644 index 0bfb19ee2..000000000 --- a/formats_rust/imports_rel_1.ksy +++ /dev/null @@ -1,12 +0,0 @@ -# Test chain of relative imports -# -# this -> for_rel_imports/imported_1 -> for_rel_imports/imported_2 -meta: - id: imports_rel_1 - imports: - - for_rel_imports/imported_1 -seq: - - id: one - type: u1 - - id: two - type: imported_1 diff --git a/formats_rust/index_sizes.ksy b/formats_rust/index_sizes.ksy deleted file mode 100644 index be14289c6..000000000 --- a/formats_rust/index_sizes.ksy +++ /dev/null @@ -1,16 +0,0 @@ -meta: - id: index_sizes - endian: le - encoding: ASCII -seq: - - id: qty - type: u4 - - id: sizes - type: u4 - repeat: expr - repeat-expr: qty - - id: bufs - type: str - size: sizes[_index] - repeat: expr - repeat-expr: qty diff --git a/formats_rust/index_to_param_eos.ksy b/formats_rust/index_to_param_eos.ksy deleted file mode 100644 index d8faef0e5..000000000 --- a/formats_rust/index_to_param_eos.ksy +++ /dev/null @@ -1,24 +0,0 @@ -meta: - id: index_to_param_eos - endian: le - encoding: ASCII -seq: - - id: qty - type: u4 - - id: sizes - type: u4 - repeat: expr - repeat-expr: qty - - id: blocks - type: block(_index) - repeat: eos -types: - block: - params: - - id: idx - type: s4 # NB: C# requires this to be signed - seq: - - id: buf - size: _root.sizes[idx] - type: str - encoding: ASCII diff --git a/formats_rust/index_to_param_expr.ksy b/formats_rust/index_to_param_expr.ksy deleted file mode 100644 index 9eed2acd2..000000000 --- a/formats_rust/index_to_param_expr.ksy +++ /dev/null @@ -1,25 +0,0 @@ -meta: - id: index_to_param_expr - endian: le - encoding: ASCII -seq: - - id: qty - type: u4 - - id: sizes - type: u4 - repeat: expr - repeat-expr: qty - - id: blocks - type: block(_index) - repeat: expr - repeat-expr: qty -types: - block: - params: - - id: idx - type: s4 # NB: C# requires this to be signed - seq: - - id: buf - size: _root.sizes[idx] - type: str - encoding: ASCII diff --git a/formats_rust/index_to_param_until.ksy b/formats_rust/index_to_param_until.ksy deleted file mode 100644 index f02a97b1c..000000000 --- a/formats_rust/index_to_param_until.ksy +++ /dev/null @@ -1,25 +0,0 @@ -meta: - id: index_to_param_until - endian: le - encoding: ASCII -seq: - - id: qty - type: u4 - - id: sizes - type: u4 - repeat: expr - repeat-expr: qty - - id: blocks - type: block(_index) - repeat: until - repeat-until: _io.eof -types: - block: - params: - - id: idx - type: s4 # NB: C# requires this to be signed - seq: - - id: buf - size: _root.sizes[idx] - type: str - encoding: ASCII diff --git a/formats_rust/instance_io_user.ksy b/formats_rust/instance_io_user.ksy deleted file mode 100644 index f5b7feeed..000000000 --- a/formats_rust/instance_io_user.ksy +++ /dev/null @@ -1,32 +0,0 @@ -meta: - id: instance_io_user - endian: le -seq: - - id: qty_entries - type: u4 - - id: entries - type: entry - repeat: expr - repeat-expr: qty_entries - - id: strings - type: strings_obj - size-eos: true -types: - entry: - seq: - - id: name_ofs - type: u4 - - id: value - type: u4 - instances: - name: - io: _root.strings._io - pos: name_ofs - type: strz - encoding: UTF-8 - strings_obj: - seq: - - id: str - type: strz - encoding: UTF-8 - repeat: eos diff --git a/formats_rust/instance_std.ksy b/formats_rust/instance_std.ksy deleted file mode 100644 index 84085d9f8..000000000 --- a/formats_rust/instance_std.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: instance_std - endian: le -instances: - header: - pos: 2 - type: str - size: 5 - encoding: ASCII diff --git a/formats_rust/instance_std_array.ksy b/formats_rust/instance_std_array.ksy deleted file mode 100644 index 3298e1641..000000000 --- a/formats_rust/instance_std_array.ksy +++ /dev/null @@ -1,16 +0,0 @@ -meta: - id: instance_std_array - endian: le -seq: - - id: ofs - type: u4 - - id: entry_size - type: u4 - - id: qty_entries - type: u4 -instances: - entries: - pos: ofs - repeat: expr - repeat-expr: qty_entries - size: entry_size diff --git a/formats_rust/instance_user_array.ksy b/formats_rust/instance_user_array.ksy deleted file mode 100644 index 479135e35..000000000 --- a/formats_rust/instance_user_array.ksy +++ /dev/null @@ -1,25 +0,0 @@ -meta: - id: instance_user_array - endian: le -seq: - - id: ofs - type: u4 - - id: entry_size - type: u4 - - id: qty_entries - type: u4 -types: - entry: - seq: - - id: word1 - type: u2 - - id: word2 - type: u2 -instances: - user_entries: - pos: ofs - repeat: expr - repeat-expr: qty_entries - size: entry_size - type: entry - if: ofs > 0 diff --git a/formats_rust/integers.ksy b/formats_rust/integers.ksy deleted file mode 100644 index 03da326fe..000000000 --- a/formats_rust/integers.ksy +++ /dev/null @@ -1,58 +0,0 @@ -meta: - id: integers - endian: le -seq: - - id: magic1 - contents: 'PACK-1' - - id: uint8 - type: u1 - - id: sint8 - type: s1 - - id: magic_uint - contents: 'PACK-U-DEF' - - id: uint16 - type: u2 - - id: uint32 - type: u4 - - id: uint64 - type: u8 - - id: magic_sint - contents: 'PACK-S-DEF' - - id: sint16 - type: s2 - - id: sint32 - type: s4 - - id: sint64 - type: s8 - - id: magic_uint_le - contents: 'PACK-U-LE' - - id: uint16le - type: u2le - - id: uint32le - type: u4le - - id: uint64le - type: u8le - - id: magic_sint_le - contents: 'PACK-S-LE' - - id: sint16le - type: s2le - - id: sint32le - type: s4le - - id: sint64le - type: s8le - - id: magic_uint_be - contents: 'PACK-U-BE' - - id: uint16be - type: u2be - - id: uint32be - type: u4be - - id: uint64be - type: u8be - - id: magic_sint_be - contents: 'PACK-S-BE' - - id: sint16be - type: s2be - - id: sint32be - type: s4be - - id: sint64be - type: s8be diff --git a/formats_rust/integers_double_overflow.ksy b/formats_rust/integers_double_overflow.ksy deleted file mode 100644 index 6c065e762..000000000 --- a/formats_rust/integers_double_overflow.ksy +++ /dev/null @@ -1,34 +0,0 @@ -# Tests reading un/signed 64-bit integers in languages representing integers as 64-bit floats ("double"s) -# It is intended especially for JavaScript. -meta: - id: integers_double_overflow -seq: - - id: signed_safe_min_be # 0x00 - type: s8be - - id: signed_safe_min_le # 0x08 - type: s8le - - id: signed_safe_max_be # 0x10 - type: s8be - - id: signed_safe_max_le # 0x18 - type: s8le - - id: signed_unsafe_neg_be # 0x20 - type: s8be - - id: signed_unsafe_neg_le # 0x28 - type: s8le - - id: signed_unsafe_pos_be # 0x30 - type: s8be - - id: signed_unsafe_pos_le # 0x38 - type: s8le -instances: - unsigned_safe_max_be: - pos: 0x10 - type: u8be - unsigned_safe_max_le: - pos: 0x18 - type: u8le - unsigned_unsafe_pos_be: - pos: 0x30 - type: u8be - unsigned_unsafe_pos_le: - pos: 0x38 - type: u8le diff --git a/formats_rust/integers_min_max.ksy b/formats_rust/integers_min_max.ksy deleted file mode 100644 index 4f7b011d2..000000000 --- a/formats_rust/integers_min_max.ksy +++ /dev/null @@ -1,44 +0,0 @@ -meta: - id: integers_min_max -seq: - - id: unsigned_min - type: unsigned - - id: unsigned_max - type: unsigned - - id: signed_min - type: signed - - id: signed_max - type: signed -types: - unsigned: - seq: - - id: u1 - type: u1 - - id: u2le - type: u2le - - id: u4le - type: u4le - - id: u8le - type: u8le - - id: u2be - type: u2be - - id: u4be - type: u4be - - id: u8be - type: u8be - signed: - seq: - - id: s1 - type: s1 - - id: s2le - type: s2le - - id: s4le - type: s4le - - id: s8le - type: s8le - - id: s2be - type: s2be - - id: s4be - type: s4be - - id: s8be - type: s8be diff --git a/formats_rust/io_local_var.ksy b/formats_rust/io_local_var.ksy deleted file mode 100644 index 68ae49aad..000000000 --- a/formats_rust/io_local_var.ksy +++ /dev/null @@ -1,26 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/536 -meta: - id: io_local_var -seq: - # [0..19] - - id: skip - size: 20 - # Invoke `mess_up` that can potentially mess up _root._io pointer - - id: always_null - type: u1 - if: mess_up.as._io.pos < 0 - # Check where we are at, should consume [20] - - id: followup - type: u1 -instances: - mess_up: - io: _root._io # required to trigger `io` assignment - pos: 8 - size: 2 - type: - switch-on: 2 - cases: - 1: dummy - 2: dummy -types: - dummy: {} diff --git a/formats_rust/js_signed_right_shift.ksy b/formats_rust/js_signed_right_shift.ksy deleted file mode 100644 index 0a0fca172..000000000 --- a/formats_rust/js_signed_right_shift.ksy +++ /dev/null @@ -1,7 +0,0 @@ -meta: - id: js_signed_right_shift -instances: - should_be_40000000: - value: '0x80000000 >> 1' - should_be_a00000: - value: '0xa0000000 >> 8' diff --git a/formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy b/formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy deleted file mode 100644 index 8213de54d..000000000 --- a/formats_rust/ks_path/for_abs_imports/imported_and_abs.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: imported_and_abs - imports: - - /imported_root -seq: - - id: one - type: u1 - - id: two - type: imported_root diff --git a/formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy b/formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy deleted file mode 100644 index 003419e18..000000000 --- a/formats_rust/ks_path/for_abs_imports/imported_and_rel.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: imported_and_rel - imports: - - ../imported_root -seq: - - id: one - type: u1 - - id: two - type: imported_root diff --git a/formats_rust/ks_path/imported_root.ksy b/formats_rust/ks_path/imported_root.ksy deleted file mode 100644 index c437309eb..000000000 --- a/formats_rust/ks_path/imported_root.ksy +++ /dev/null @@ -1,5 +0,0 @@ -meta: - id: imported_root -seq: - - id: one - type: u1 diff --git a/formats_rust/meta_tags.ksy b/formats_rust/meta_tags.ksy deleted file mode 100644 index 66bc521de..000000000 --- a/formats_rust/meta_tags.ksy +++ /dev/null @@ -1,7 +0,0 @@ -# Only ksc -meta: - id: meta_tags - tags: - - foo - - bar - - baz diff --git a/formats_rust/meta_xref.ksy b/formats_rust/meta_xref.ksy deleted file mode 100644 index e2531c07f..000000000 --- a/formats_rust/meta_xref.ksy +++ /dev/null @@ -1,6 +0,0 @@ -# Only ksc -meta: - id: meta_xref - xref: - wikidata: foo - repo: https://example.com/ diff --git a/formats_rust/multiple_use.ksy b/formats_rust/multiple_use.ksy deleted file mode 100644 index 8f984ce47..000000000 --- a/formats_rust/multiple_use.ksy +++ /dev/null @@ -1,22 +0,0 @@ -meta: - id: multiple_use - endian: le -seq: - - id: t1 - type: type_1 - - id: t2 - type: type_2 -types: - multi: - seq: - - id: value - type: s4 - type_1: - seq: - - id: first_use - type: multi # parent type = type_1 - type_2: - instances: - second_use: - pos: 0 - type: multi # parent type = type_2 diff --git a/formats_rust/nav_parent.ksy b/formats_rust/nav_parent.ksy deleted file mode 100644 index 0516b587a..000000000 --- a/formats_rust/nav_parent.ksy +++ /dev/null @@ -1,29 +0,0 @@ -meta: - id: nav_parent - endian: le -seq: - - id: header - type: header_obj - - id: index - type: index_obj -types: - header_obj: - seq: - - id: qty_entries - type: u4 - - id: filename_len - type: u4 - index_obj: - seq: - - id: magic - size: 4 - - id: entries - type: entry - repeat: expr - repeat-expr: _parent.header.qty_entries - entry: - seq: - - id: filename - type: str - size: _parent._parent.header.filename_len - encoding: UTF-8 diff --git a/formats_rust/nav_parent2.ksy b/formats_rust/nav_parent2.ksy deleted file mode 100644 index 70de7dbb1..000000000 --- a/formats_rust/nav_parent2.ksy +++ /dev/null @@ -1,38 +0,0 @@ -meta: - id: nav_parent2 - endian: le -seq: - - id: ofs_tags - type: u4 - - id: num_tags - type: u4 - - id: tags - type: tag - repeat: expr - repeat-expr: num_tags -types: - tag: - seq: - - id: name - type: str - size: 4 - encoding: ASCII - - id: ofs - type: u4 - - id: num_items - type: u4 - types: - tag_char: - seq: - - id: content - type: str - size: _parent.num_items - encoding: ASCII - instances: - tag_content: - pos: ofs - type: - switch-on: name - cases: - '"RAHC"': tag_char - io: _root._io diff --git a/formats_rust/nav_parent3.ksy b/formats_rust/nav_parent3.ksy deleted file mode 100644 index 108eb0a8c..000000000 --- a/formats_rust/nav_parent3.ksy +++ /dev/null @@ -1,41 +0,0 @@ -# Same as nav_parent2, but "tags" is instance and is actually positioned at ofs_tags -meta: - id: nav_parent3 - endian: le -seq: - - id: ofs_tags - type: u4 - - id: num_tags - type: u4 -types: - tag: - seq: - - id: name - type: str - size: 4 - encoding: ASCII - - id: ofs - type: u4 - - id: num_items - type: u4 - types: - tag_char: - seq: - - id: content - type: str - size: _parent.num_items - encoding: ASCII - instances: - tag_content: - pos: ofs - type: - switch-on: name - cases: - '"RAHC"': tag_char - io: _root._io -instances: - tags: - pos: ofs_tags - type: tag - repeat: expr - repeat-expr: num_tags diff --git a/formats_rust/nav_parent_false.ksy b/formats_rust/nav_parent_false.ksy deleted file mode 100644 index 270bb0d5a..000000000 --- a/formats_rust/nav_parent_false.ksy +++ /dev/null @@ -1,29 +0,0 @@ -meta: - id: nav_parent_false -seq: - - id: child_size - type: u1 - - id: element_a - type: parent_a - - id: element_b - type: parent_b -types: - parent_a: - seq: - - id: foo - type: child - - id: bar - type: parent_b - parent_b: - seq: - - id: foo - type: child - parent: false - child: - # should have only one parent of type `parent_a` - seq: - - id: code - type: u1 - - id: more - size: _parent._parent.child_size - if: code == 73 diff --git a/formats_rust/nav_parent_false2.ksy b/formats_rust/nav_parent_false2.ksy deleted file mode 100644 index f69bc2a85..000000000 --- a/formats_rust/nav_parent_false2.ksy +++ /dev/null @@ -1,12 +0,0 @@ -meta: - id: nav_parent_false2 -seq: - - id: parentless - type: child - parent: false -types: - child: - # should have no parents - seq: - - id: foo - type: u1 diff --git a/formats_rust/nav_parent_override.ksy b/formats_rust/nav_parent_override.ksy deleted file mode 100644 index ce8ed335e..000000000 --- a/formats_rust/nav_parent_override.ksy +++ /dev/null @@ -1,19 +0,0 @@ -meta: - id: nav_parent_override -seq: - - id: child_size - type: u1 - - id: child_1 - type: child - - id: mediator_2 - type: mediator -types: - mediator: - seq: - - id: child_2 - type: child - parent: _parent - child: - seq: - - id: data - size: _parent.child_size diff --git a/formats_rust/nav_parent_switch.ksy b/formats_rust/nav_parent_switch.ksy deleted file mode 100644 index 1c96073f0..000000000 --- a/formats_rust/nav_parent_switch.ksy +++ /dev/null @@ -1,22 +0,0 @@ -meta: - id: nav_parent_switch -seq: - - id: category - type: u1 - - id: content - type: - switch-on: category - cases: - 1: element_1 -types: - element_1: - seq: - - id: foo - type: u1 - - id: subelement - type: subelement_1 - subelement_1: - seq: - - id: bar - type: u1 - if: _parent.foo == 0x42 diff --git a/formats_rust/nav_parent_vs_value_inst.ksy b/formats_rust/nav_parent_vs_value_inst.ksy deleted file mode 100644 index b3d077055..000000000 --- a/formats_rust/nav_parent_vs_value_inst.ksy +++ /dev/null @@ -1,18 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct_compiler/issues/38#issuecomment-265525999 -meta: - id: nav_parent_vs_value_inst - endian: le - -seq: - - id: s1 - type: str - encoding: UTF-8 - terminator: 0x7C - - id: child - type: child_obj - -types: - child_obj: - instances: - do_something: - value: "_parent.s1 == 'foo' ? true : false" diff --git a/formats_rust/nav_root.ksy b/formats_rust/nav_root.ksy deleted file mode 100644 index 2072e6993..000000000 --- a/formats_rust/nav_root.ksy +++ /dev/null @@ -1,29 +0,0 @@ -meta: - id: nav_root - endian: le -seq: - - id: header - type: header_obj - - id: index - type: index_obj -types: - header_obj: - seq: - - id: qty_entries - type: u4 - - id: filename_len - type: u4 - index_obj: - seq: - - id: magic - size: 4 - - id: entries - type: entry - repeat: expr - repeat-expr: _root.header.qty_entries - entry: - seq: - - id: filename - type: str - size: _root.header.filename_len - encoding: UTF-8 diff --git a/formats_rust/nested_same_name.ksy b/formats_rust/nested_same_name.ksy deleted file mode 100644 index 0603b4cd0..000000000 --- a/formats_rust/nested_same_name.ksy +++ /dev/null @@ -1,23 +0,0 @@ -meta: - id: nested_same_name - endian: le -seq: - - id: main_data - type: main - - id: dummy - type: dummy_obj -types: - main: - seq: - - id: main_size - type: s4 - - id: foo - type: foo_obj - types: - foo_obj: - seq: - - id: data - size: '_parent.main_size * 2' - dummy_obj: - types: - foo: {} diff --git a/formats_rust/nested_same_name2.ksy b/formats_rust/nested_same_name2.ksy deleted file mode 100644 index 39a53a5e9..000000000 --- a/formats_rust/nested_same_name2.ksy +++ /dev/null @@ -1,33 +0,0 @@ -meta: - id: nested_same_name2 - endian: le -seq: - - id: version - type: u4 - - id: main_data - type: main - - id: dummy - type: dummy_obj -types: - main: - seq: - - id: main_size - type: s4 - - id: foo - type: foo_obj - types: - foo_obj: - seq: - - id: data1 - size: _parent.main_size * 2 - dummy_obj: - seq: - - id: dummy_size - type: s4 - - id: foo - type: foo_obj - types: - foo_obj: - seq: - - id: data2 - size: _parent.dummy_size * 2 diff --git a/formats_rust/nested_type_param.ksy b/formats_rust/nested_type_param.ksy deleted file mode 100644 index 470bb176d..000000000 --- a/formats_rust/nested_type_param.ksy +++ /dev/null @@ -1,17 +0,0 @@ -meta: - id: nested_type_param -seq: - - id: main_seq - type: nested::my_type(5) -types: - nested: - types: - my_type: - params: - - id: my_len - type: u4 - seq: - - id: body - type: str - size: my_len - encoding: ASCII diff --git a/formats_rust/nested_types.ksy b/formats_rust/nested_types.ksy deleted file mode 100644 index 9254555a5..000000000 --- a/formats_rust/nested_types.ksy +++ /dev/null @@ -1,23 +0,0 @@ -meta: - id: nested_types -seq: - - id: one - type: subtype_a - - id: two - type: subtype_b -types: - subtype_a: - seq: - - id: typed_at_root - type: subtype_b - - id: typed_here - type: subtype_c - types: - subtype_c: - seq: - - id: value_c - type: s1 - subtype_b: - seq: - - id: value_b - type: s1 diff --git a/formats_rust/nested_types2.ksy b/formats_rust/nested_types2.ksy deleted file mode 100644 index 203c0ee7e..000000000 --- a/formats_rust/nested_types2.ksy +++ /dev/null @@ -1,40 +0,0 @@ -meta: - id: nested_types2 -seq: - - id: one - type: subtype_a - - id: two - type: subtype_b -types: - subtype_a: - seq: - - id: typed_at_root - type: subtype_b - - id: typed_here1 - type: subtype_c - - id: typed_here2 - type: subtype_cc - types: - subtype_c: - seq: - - id: value_c - type: s1 - - id: typed_here - type: subtype_d - - id: typed_parent - type: subtype_cc - - id: typed_root - type: subtype_b - types: - subtype_d: - seq: - - id: value_d - type: s1 - subtype_cc: - seq: - - id: value_cc - type: s1 - subtype_b: - seq: - - id: value_b - type: s1 diff --git a/formats_rust/nested_types3.ksy b/formats_rust/nested_types3.ksy deleted file mode 100644 index 0fed9bc67..000000000 --- a/formats_rust/nested_types3.ksy +++ /dev/null @@ -1,31 +0,0 @@ -# Check usage of a::b::c syntax -meta: - id: nested_types3 -seq: - - id: a_cc - type: subtype_a::subtype_cc - - id: a_c_d - type: subtype_a::subtype_c::subtype_d - - id: b - type: subtype_b -types: - subtype_a: - types: - subtype_c: - types: - subtype_d: - seq: - - id: value_d - type: s1 - subtype_cc: - seq: - - id: value_cc - type: s1 - subtype_b: - seq: - - id: value_b - type: s1 - - id: a_cc - type: subtype_a::subtype_cc - - id: a_c_d - type: subtype_a::subtype_c::subtype_d diff --git a/formats_rust/non_standard.ksy b/formats_rust/non_standard.ksy deleted file mode 100644 index 7e225302f..000000000 --- a/formats_rust/non_standard.ksy +++ /dev/null @@ -1,30 +0,0 @@ -meta: - id: non_standard - endian: le - -vendor-key: some value - -vendor-key2: - some: hash - with_more: values - -vendor-key3: - - foo - - bar --vendor-key: value -seq: - - id: foo - type: u1 - -vendor-key: value - - id: bar - type: - switch-on: foo - -vendor-key: value - cases: - 42: u2 - 43: u4 -instances: - vi: - value: foo - -vendor-key: value - pi: - pos: 0 - type: u1 - -vendor-key: value diff --git a/formats_rust/opaque_external_type.ksy b/formats_rust/opaque_external_type.ksy deleted file mode 100644 index 4336b88f2..000000000 --- a/formats_rust/opaque_external_type.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: opaque_external_type - ks-opaque-types: true -seq: - - id: one - type: term_strz diff --git a/formats_rust/opaque_external_type_02_child.ksy b/formats_rust/opaque_external_type_02_child.ksy deleted file mode 100644 index eb18b1d8d..000000000 --- a/formats_rust/opaque_external_type_02_child.ksy +++ /dev/null @@ -1,28 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct_compiler/issues/44 -meta: - id: opaque_external_type_02_child - endian: le -seq: - - id: s1 - type: str - encoding: UTF-8 - terminator: 0x7C - - id: s2 - type: str - encoding: UTF-8 - terminator: 0x7C - consume: false - - id: s3 - type: opaque_external_type_02_child_child -types: - opaque_external_type_02_child_child: - seq: - - id: s3 - type: str - encoding: UTF-8 - terminator: 0x40 - include: true - if: _root.some_method -instances: - some_method: - value: "true" diff --git a/formats_rust/opaque_external_type_02_parent.ksy b/formats_rust/opaque_external_type_02_parent.ksy deleted file mode 100644 index 759d54014..000000000 --- a/formats_rust/opaque_external_type_02_parent.ksy +++ /dev/null @@ -1,12 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct_compiler/issues/44 -meta: - id: opaque_external_type_02_parent - ks-opaque-types: true -seq: - - id: parent - type: parent_obj -types: - parent_obj: - seq: - - id: child - type: opaque_external_type_02_child diff --git a/formats_rust/opaque_with_param.ksy b/formats_rust/opaque_with_param.ksy deleted file mode 100644 index 758b6d6f8..000000000 --- a/formats_rust/opaque_with_param.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: opaque_with_param - ks-opaque-types: true -seq: - - id: one - type: params_def(5, true) diff --git a/formats_rust/optional_id.ksy b/formats_rust/optional_id.ksy deleted file mode 100644 index 60f9bacbb..000000000 --- a/formats_rust/optional_id.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: optional_id -seq: - - type: u1 - - type: u1 - - size: 5 diff --git a/formats_rust/params_call_extra_parens.ksy b/formats_rust/params_call_extra_parens.ksy deleted file mode 100644 index e17ea1b21..000000000 --- a/formats_rust/params_call_extra_parens.ksy +++ /dev/null @@ -1,15 +0,0 @@ -meta: - id: params_call_extra_parens -seq: - - id: buf1 - type: my_str1((5)) -types: - my_str1: - params: - - id: len - type: u4 - seq: - - id: body - type: str - size: len - encoding: UTF-8 diff --git a/formats_rust/params_call_short.ksy b/formats_rust/params_call_short.ksy deleted file mode 100644 index 07be4ceaa..000000000 --- a/formats_rust/params_call_short.ksy +++ /dev/null @@ -1,31 +0,0 @@ -meta: - id: params_call_short -seq: - - id: buf1 - type: my_str1(5) - - id: buf2 - type: my_str2(2 + 3, true) -types: - my_str1: - params: - - id: len - type: u4 - seq: - - id: body - type: str - size: len - encoding: UTF-8 - my_str2: - params: - - id: len - type: u4 - - id: has_trailer - type: bool - seq: - - id: body - type: str - size: len - encoding: UTF-8 - - id: trailer - type: u1 - if: has_trailer diff --git a/formats_rust/params_def.ksy b/formats_rust/params_def.ksy deleted file mode 100644 index dd674cd1f..000000000 --- a/formats_rust/params_def.ksy +++ /dev/null @@ -1,16 +0,0 @@ -meta: - id: params_def - endian: le -params: - - id: len - type: u4 - - id: has_trailer - type: bool -seq: - - id: buf - type: str - size: len - encoding: UTF-8 - - id: trailer - type: u1 - if: has_trailer diff --git a/formats_rust/params_enum.ksy b/formats_rust/params_enum.ksy deleted file mode 100644 index 291391365..000000000 --- a/formats_rust/params_enum.ksy +++ /dev/null @@ -1,22 +0,0 @@ -meta: - id: params_enum -enums: - animal: - 4: dog - 7: cat - 12: chicken -seq: - - id: one - type: u1 - enum: animal - - id: invoke_with_param - type: with_param(one) -types: - with_param: - params: - - id: enumerated_one - type: u1 - enum: animal - instances: - is_cat: - value: enumerated_one == animal::cat # would break if there's a bug diff --git a/formats_rust/params_pass_array_int.ksy b/formats_rust/params_pass_array_int.ksy deleted file mode 100644 index 7d065cf64..000000000 --- a/formats_rust/params_pass_array_int.ksy +++ /dev/null @@ -1,20 +0,0 @@ -meta: - id: params_pass_array_int - endian: le -seq: - - id: ints - type: u2 - repeat: expr - repeat-expr: 3 - - id: pass_ints - type: wants_ints(ints) - - id: pass_ints_calc - type: wants_ints(ints_calc) -types: - wants_ints: - params: - - id: nums - type: u2[] -instances: - ints_calc: - value: '[27643, 7].as' diff --git a/formats_rust/params_pass_array_str.ksy b/formats_rust/params_pass_array_str.ksy deleted file mode 100644 index 2caaa811d..000000000 --- a/formats_rust/params_pass_array_str.ksy +++ /dev/null @@ -1,21 +0,0 @@ -meta: - id: params_pass_array_str - encoding: ascii -seq: - - id: str_array - type: str - size: 2 - repeat: expr - repeat-expr: 3 - - id: pass_str_array - type: wants_strs(str_array) - - id: pass_str_array_calc - type: wants_strs(str_array_calc) -types: - wants_strs: - params: - - id: strs - type: str[] -instances: - str_array_calc: - value: '["aB", "Cd"]' diff --git a/formats_rust/params_pass_array_usertype.ksy b/formats_rust/params_pass_array_usertype.ksy deleted file mode 100644 index e3e71eed2..000000000 --- a/formats_rust/params_pass_array_usertype.ksy +++ /dev/null @@ -1,23 +0,0 @@ -meta: - id: params_pass_array_usertype -seq: - - id: blocks - type: block - repeat: expr - repeat-expr: 2 - - id: pass_blocks - type: param_type(blocks) -types: - block: - seq: - - id: foo - type: u1 - param_type: - params: - - id: bar - type: block[] - seq: - - id: one - size: bar[0].foo - - id: two - size: bar[1].foo diff --git a/formats_rust/params_pass_bool.ksy b/formats_rust/params_pass_bool.ksy deleted file mode 100644 index 7d2b986f1..000000000 --- a/formats_rust/params_pass_bool.ksy +++ /dev/null @@ -1,39 +0,0 @@ -meta: - id: params_pass_bool -seq: - - id: s_false - type: b1 - - id: s_true - type: b1 - - id: seq_b1 - type: param_type_b1(s_true) - - id: seq_bool - type: param_type_bool(s_false) - - id: literal_b1 - type: param_type_b1(false) - - id: literal_bool - type: param_type_bool(true) - - id: inst_b1 - type: param_type_b1(v_true) - - id: inst_bool - type: param_type_bool(v_false) -instances: - v_false: - value: false - v_true: - value: true -types: - param_type_b1: - params: - - id: arg - type: b1 - seq: - - id: foo - size: 'arg ? 1 : 2' - param_type_bool: - params: - - id: arg - type: bool - seq: - - id: foo - size: 'arg ? 1 : 2' diff --git a/formats_rust/params_pass_usertype.ksy b/formats_rust/params_pass_usertype.ksy deleted file mode 100644 index 8fa7b2747..000000000 --- a/formats_rust/params_pass_usertype.ksy +++ /dev/null @@ -1,19 +0,0 @@ -meta: - id: params_pass_usertype -seq: - - id: first - type: block - - id: one - type: param_type(first) -types: - block: - seq: - - id: foo - type: u1 - param_type: - params: - - id: foo - type: block - seq: - - id: buf - size: foo.foo diff --git a/formats_rust/position_abs.ksy b/formats_rust/position_abs.ksy deleted file mode 100644 index e4e877f1c..000000000 --- a/formats_rust/position_abs.ksy +++ /dev/null @@ -1,16 +0,0 @@ -meta: - id: position_abs - endian: le -seq: - - id: index_offset - type: u4 -types: - index_obj: - seq: - - id: entry - type: strz - encoding: UTF-8 -instances: - index: - pos: index_offset - type: index_obj diff --git a/formats_rust/position_in_seq.ksy b/formats_rust/position_in_seq.ksy deleted file mode 100644 index 51a229e9c..000000000 --- a/formats_rust/position_in_seq.ksy +++ /dev/null @@ -1,17 +0,0 @@ -meta: - id: position_in_seq - endian: le -seq: - - id: numbers - type: u1 - repeat: expr - repeat-expr: header.qty_numbers -types: - header_obj: - seq: - - id: qty_numbers - type: u4 -instances: - header: - pos: 0x10 - type: header_obj diff --git a/formats_rust/position_to_end.ksy b/formats_rust/position_to_end.ksy deleted file mode 100644 index 3651796f3..000000000 --- a/formats_rust/position_to_end.ksy +++ /dev/null @@ -1,14 +0,0 @@ -meta: - id: position_to_end - endian: le -instances: - index: - pos: _io.size - 8 - type: index_obj -types: - index_obj: - seq: - - id: foo - type: u4 - - id: bar - type: u4 diff --git a/formats_rust/process_coerce_bytes.ksy b/formats_rust/process_coerce_bytes.ksy deleted file mode 100644 index 05a100b49..000000000 --- a/formats_rust/process_coerce_bytes.ksy +++ /dev/null @@ -1,23 +0,0 @@ -# Checks coercion of two different byte arrays (with and without processing) -meta: - id: process_coerce_bytes -seq: - - id: records - type: record - repeat: expr - repeat-expr: 2 -types: - record: - seq: - - id: flag - type: u1 - - id: buf_unproc - size: 4 - if: flag == 0 - - id: buf_proc - size: 4 - process: xor(0xaa) - if: flag != 0 - instances: - buf: - value: 'flag == 0 ? buf_unproc : buf_proc' diff --git a/formats_rust/process_coerce_usertype1.ksy b/formats_rust/process_coerce_usertype1.ksy deleted file mode 100644 index 15ffde784..000000000 --- a/formats_rust/process_coerce_usertype1.ksy +++ /dev/null @@ -1,30 +0,0 @@ -# Checks coercion of two user types with size (with and without processing) -meta: - id: process_coerce_usertype1 - endian: le -seq: - - id: records - type: record - repeat: expr - repeat-expr: 2 -types: - record: - seq: - - id: flag - type: u1 - - id: buf_unproc - size: 4 - type: foo - if: flag == 0 - - id: buf_proc - size: 4 - type: foo - process: xor(0xaa) - if: flag != 0 - instances: - buf: - value: 'flag == 0 ? buf_unproc : buf_proc' - foo: - seq: - - id: value - type: u4 diff --git a/formats_rust/process_coerce_usertype2.ksy b/formats_rust/process_coerce_usertype2.ksy deleted file mode 100644 index 07c58f9f3..000000000 --- a/formats_rust/process_coerce_usertype2.ksy +++ /dev/null @@ -1,30 +0,0 @@ -# Checks coercion of two user types: "with size and processing" vs -# "without size and processing" -meta: - id: process_coerce_usertype2 - endian: le -seq: - - id: records - type: record - repeat: expr - repeat-expr: 2 -types: - record: - seq: - - id: flag - type: u1 - - id: buf_unproc - type: foo - if: flag == 0 - - id: buf_proc - size: 4 - type: foo - process: xor(0xaa) - if: flag != 0 - instances: - buf: - value: 'flag == 0 ? buf_unproc : buf_proc' - foo: - seq: - - id: value - type: u4 diff --git a/formats_rust/process_custom.ksy b/formats_rust/process_custom.ksy deleted file mode 100644 index 95edbdb48..000000000 --- a/formats_rust/process_custom.ksy +++ /dev/null @@ -1,14 +0,0 @@ -meta: - id: process_custom -seq: - - id: buf1 - size: 5 - process: my_custom_fx(7, true, [0x20, 0x30, 0x40]) - - id: buf2 - size: 5 - process: nested.deeply.custom_fx(7) - - id: key - type: u1 - - id: buf3 - size: 5 - process: my_custom_fx(key, false, [0x00]) diff --git a/formats_rust/process_custom_no_args.ksy b/formats_rust/process_custom_no_args.ksy deleted file mode 100644 index 7d1e24714..000000000 --- a/formats_rust/process_custom_no_args.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: process_custom_no_args -seq: - - id: buf - size: 5 - process: custom_fx_no_args diff --git a/formats_rust/process_repeat_bytes.ksy b/formats_rust/process_repeat_bytes.ksy deleted file mode 100644 index cdcccc8da..000000000 --- a/formats_rust/process_repeat_bytes.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: process_repeat_bytes -seq: - - id: bufs - size: 5 - repeat: expr - repeat-expr: 2 - process: xor(0x9e) diff --git a/formats_rust/process_repeat_usertype.ksy b/formats_rust/process_repeat_usertype.ksy deleted file mode 100644 index edbe7bdd2..000000000 --- a/formats_rust/process_repeat_usertype.ksy +++ /dev/null @@ -1,17 +0,0 @@ -meta: - id: process_repeat_usertype - endian: le -seq: - - id: blocks - size: 5 - type: block - repeat: expr - repeat-expr: 2 - process: xor(0x9e) -types: - block: - seq: - - id: a - type: s4 - - id: b - type: s1 diff --git a/formats_rust/process_rotate.ksy b/formats_rust/process_rotate.ksy deleted file mode 100644 index 7afaebc3f..000000000 --- a/formats_rust/process_rotate.ksy +++ /dev/null @@ -1,15 +0,0 @@ -meta: - id: process_rotate - endian: le -seq: - - id: buf1 - size: 5 - process: rol(3) - - id: buf2 - size: 5 - process: ror(3) - - id: key - type: u1 - - id: buf3 - size: 5 - process: rol(key) diff --git a/formats_rust/process_to_user.ksy b/formats_rust/process_to_user.ksy deleted file mode 100644 index 8cf658066..000000000 --- a/formats_rust/process_to_user.ksy +++ /dev/null @@ -1,14 +0,0 @@ -meta: - id: process_to_user -seq: - - id: buf1 - size: 5 - process: rol(3) - type: just_str -types: - just_str: - seq: - - id: str - type: str - encoding: UTF-8 - size-eos: true diff --git a/formats_rust/process_xor4_const.ksy b/formats_rust/process_xor4_const.ksy deleted file mode 100644 index c090ee93d..000000000 --- a/formats_rust/process_xor4_const.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: process_xor4_const -seq: - - id: key - size: 4 - - id: buf - size-eos: true - process: xor([0xec, 0xbb, 0xa3, 0x14]) diff --git a/formats_rust/process_xor4_value.ksy b/formats_rust/process_xor4_value.ksy deleted file mode 100644 index 19d812c0d..000000000 --- a/formats_rust/process_xor4_value.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: process_xor4_value -seq: - - id: key - size: 4 - - id: buf - size-eos: true - process: xor(key) diff --git a/formats_rust/process_xor_const.ksy b/formats_rust/process_xor_const.ksy deleted file mode 100644 index 549ecd697..000000000 --- a/formats_rust/process_xor_const.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: process_xor_const - endian: le -seq: - - id: key - type: u1 - - id: buf - size-eos: true - process: xor(0xff) diff --git a/formats_rust/process_xor_value.ksy b/formats_rust/process_xor_value.ksy deleted file mode 100644 index e27e48cc1..000000000 --- a/formats_rust/process_xor_value.ksy +++ /dev/null @@ -1,9 +0,0 @@ -meta: - id: process_xor_value - endian: le -seq: - - id: key - type: u1 - - id: buf - size-eos: true - process: xor(key) diff --git a/formats_rust/recursive_one.ksy b/formats_rust/recursive_one.ksy deleted file mode 100644 index a88430d76..000000000 --- a/formats_rust/recursive_one.ksy +++ /dev/null @@ -1,18 +0,0 @@ -meta: - id: recursive_one -seq: - - id: one - type: u1 - - id: next - type: - switch-on: one & 3 - cases: - 0: recursive_one - 1: recursive_one - 2: recursive_one - 3: fini -types: - fini: - seq: - - id: finisher - type: u2le diff --git a/formats_rust/repeat_eos_bit.ksy b/formats_rust/repeat_eos_bit.ksy deleted file mode 100644 index 4bb6c70e0..000000000 --- a/formats_rust/repeat_eos_bit.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: repeat_eos_bit -seq: - - id: nibbles - type: b4 - repeat: eos diff --git a/formats_rust/repeat_eos_struct.ksy b/formats_rust/repeat_eos_struct.ksy deleted file mode 100644 index 940320f16..000000000 --- a/formats_rust/repeat_eos_struct.ksy +++ /dev/null @@ -1,14 +0,0 @@ -meta: - id: repeat_eos_struct - endian: le -seq: - - id: chunks - type: chunk - repeat: eos -types: - chunk: - seq: - - id: offset - type: u4 - - id: len - type: u4 diff --git a/formats_rust/repeat_eos_u4.ksy b/formats_rust/repeat_eos_u4.ksy deleted file mode 100644 index dbb2b3e3b..000000000 --- a/formats_rust/repeat_eos_u4.ksy +++ /dev/null @@ -1,7 +0,0 @@ -meta: - id: repeat_eos_u4 - endian: le -seq: - - id: numbers - type: u4 - repeat: eos diff --git a/formats_rust/repeat_n_struct.ksy b/formats_rust/repeat_n_struct.ksy deleted file mode 100644 index 1d1d89ade..000000000 --- a/formats_rust/repeat_n_struct.ksy +++ /dev/null @@ -1,17 +0,0 @@ -meta: - id: repeat_n_struct - endian: le -seq: - - id: qty - type: u4 - - id: chunks - type: chunk - repeat: expr - repeat-expr: qty -types: - chunk: - seq: - - id: offset - type: u4 - - id: len - type: u4 diff --git a/formats_rust/repeat_n_strz.ksy b/formats_rust/repeat_n_strz.ksy deleted file mode 100644 index ba8787d6d..000000000 --- a/formats_rust/repeat_n_strz.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: repeat_n_strz - endian: le -seq: - - id: qty - type: u4 - - id: lines - type: strz - encoding: UTF-8 - repeat: expr - repeat-expr: qty diff --git a/formats_rust/repeat_n_strz_double.ksy b/formats_rust/repeat_n_strz_double.ksy deleted file mode 100644 index 25b123ed5..000000000 --- a/formats_rust/repeat_n_strz_double.ksy +++ /dev/null @@ -1,16 +0,0 @@ -meta: - id: repeat_n_strz_double - endian: le -seq: - - id: qty - type: u4 - - id: lines1 - type: strz - encoding: UTF-8 - repeat: expr - repeat-expr: qty / 2 - - id: lines2 - type: strz - encoding: UTF-8 - repeat: expr - repeat-expr: qty / 2 diff --git a/formats_rust/repeat_until_calc_array_type.ksy b/formats_rust/repeat_until_calc_array_type.ksy deleted file mode 100644 index 9fac2664f..000000000 --- a/formats_rust/repeat_until_calc_array_type.ksy +++ /dev/null @@ -1,22 +0,0 @@ -meta: - id: repeat_until_calc_array_type - endian: le -seq: - - id: records - size: 5 - type: record - repeat: until - repeat-until: _.marker == 0xaa -types: - record: - seq: - - id: marker - type: u1 - - id: body - type: u4 -instances: - recs_accessor: - value: records - - first_rec: - value: recs_accessor.first diff --git a/formats_rust/repeat_until_complex.ksy b/formats_rust/repeat_until_complex.ksy deleted file mode 100644 index cf9a67c72..000000000 --- a/formats_rust/repeat_until_complex.ksy +++ /dev/null @@ -1,33 +0,0 @@ -meta: - id: repeat_until_complex - endian: le -seq: - - id: first - type: type_u1 - repeat: until - repeat-until: _.count == 0 - - id: second - type: type_u2 - repeat: until - repeat-until: _.count == 0 - - id: third - type: u1 - repeat: until - repeat-until: _ == 0 -types: - type_u1: - seq: - - id: count - type: u1 - - id: values - type: u1 - repeat: expr - repeat-expr: count - type_u2: - seq: - - id: count - type: u2 - - id: values - type: u2 - repeat: expr - repeat-expr: count diff --git a/formats_rust/repeat_until_s4.ksy b/formats_rust/repeat_until_s4.ksy deleted file mode 100644 index 006ee6f7a..000000000 --- a/formats_rust/repeat_until_s4.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: repeat_until_s4 - endian: le -seq: - - id: entries - type: s4 - repeat: until - repeat-until: _ == -1 - - id: afterall - type: strz - encoding: ASCII diff --git a/formats_rust/repeat_until_sized.ksy b/formats_rust/repeat_until_sized.ksy deleted file mode 100644 index 61c4a08b4..000000000 --- a/formats_rust/repeat_until_sized.ksy +++ /dev/null @@ -1,16 +0,0 @@ -meta: - id: repeat_until_sized - endian: le -seq: - - id: records - size: 5 - type: record - repeat: until - repeat-until: _.marker == 0xaa -types: - record: - seq: - - id: marker - type: u1 - - id: body - type: u4 diff --git a/formats_rust/str_encodings.ksy b/formats_rust/str_encodings.ksy deleted file mode 100644 index 96d3e07a3..000000000 --- a/formats_rust/str_encodings.ksy +++ /dev/null @@ -1,28 +0,0 @@ -meta: - id: str_encodings - endian: le -seq: - - id: len_of_1 - type: u2 - - id: str1 - type: str - size: len_of_1 - encoding: ASCII - - id: len_of_2 - type: u2 - - id: str2 - type: str - size: len_of_2 - encoding: UTF-8 - - id: len_of_3 - type: u2 - - id: str3 - type: str - size: len_of_3 - encoding: SJIS - - id: len_of_4 - type: u2 - - id: str4 - type: str - size: len_of_4 - encoding: CP437 diff --git a/formats_rust/str_encodings_default.ksy b/formats_rust/str_encodings_default.ksy deleted file mode 100644 index 06dce3070..000000000 --- a/formats_rust/str_encodings_default.ksy +++ /dev/null @@ -1,32 +0,0 @@ -meta: - id: str_encodings_default - endian: le - encoding: UTF-8 -seq: - - id: len_of_1 - type: u2 - - id: str1 - type: str - size: len_of_1 - - id: rest - type: subtype -types: - subtype: - seq: - - id: len_of_2 - type: u2 - - id: str2 - type: str - size: len_of_2 - - id: len_of_3 - type: u2 - - id: str3 - type: str - size: len_of_3 - encoding: SJIS - - id: len_of_4 - type: u2 - - id: str4 - type: str - size: len_of_4 - encoding: CP437 diff --git a/formats_rust/str_encodings_utf16.ksy b/formats_rust/str_encodings_utf16.ksy deleted file mode 100644 index 3945951f0..000000000 --- a/formats_rust/str_encodings_utf16.ksy +++ /dev/null @@ -1,47 +0,0 @@ -meta: - id: str_encodings_utf16 - endian: le -seq: - - id: len_be - type: u4 - - id: be_bom_removed - size: len_be - type: str_be_bom_removed - - - id: len_le - type: u4 - - id: le_bom_removed - size: len_le - type: str_le_bom_removed - -# instances: -# be_with_bom: -# pos: 4 -# size: len_be -# type: str -# encoding: UTF-16 - -# le_with_bom: -# pos: 4 + len_be + 4 -# size: len_le -# type: str -# encoding: UTF-16 - -types: - str_be_bom_removed: - seq: - - id: bom - type: u2be - - id: str - size-eos: true - type: str - encoding: UTF-16BE - - str_le_bom_removed: - seq: - - id: bom - type: u2le - - id: str - size-eos: true - type: str - encoding: UTF-16LE diff --git a/formats_rust/str_eos.ksy b/formats_rust/str_eos.ksy deleted file mode 100644 index cd192334e..000000000 --- a/formats_rust/str_eos.ksy +++ /dev/null @@ -1,7 +0,0 @@ -meta: - id: str_eos -seq: - - id: str - type: str - size-eos: true - encoding: UTF-8 diff --git a/formats_rust/str_literals.ksy b/formats_rust/str_literals.ksy deleted file mode 100644 index 1901813a8..000000000 --- a/formats_rust/str_literals.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: str_literals -instances: - complex_str: - value: '"\0\1\2\a\b\n\r\t\v\f\e\75\7\u000a\u0024\u263b"' - double_quotes: - value: '"\"\u0022\42"' - backslashes: - value: '"\\\u005c\134"' - octal_eatup: - value: '"\0\62\62"' - octal_eatup2: - value: '"\2\62"' diff --git a/formats_rust/str_literals2.ksy b/formats_rust/str_literals2.ksy deleted file mode 100644 index 3cf6b0881..000000000 --- a/formats_rust/str_literals2.ksy +++ /dev/null @@ -1,18 +0,0 @@ -# Tests double-quoted interpolation variables used in various -# languages. None of this should be actually processed as interpolated -# variables, all should be escaped properly in relevant translators. -meta: - id: str_literals2 -instances: - # PHP, Perl - dollar1: - value: '"$foo"' - # PHP, Perl - dollar2: - value: '"${foo}"' - # Ruby - hash: - value: '"#{foo}"' - # Perl - at_sign: - value: '"@foo"' diff --git a/formats_rust/str_pad_term.ksy b/formats_rust/str_pad_term.ksy deleted file mode 100644 index 1996d359b..000000000 --- a/formats_rust/str_pad_term.ksy +++ /dev/null @@ -1,24 +0,0 @@ -# Tests "pad-right" and "terminator" functionality in fixed-length strings ("str" with "size") -meta: - id: str_pad_term - encoding: UTF-8 -seq: - - id: str_pad - type: str - size: 20 - pad-right: 0x40 - - id: str_term - type: str - size: 20 - terminator: 0x40 - - id: str_term_and_pad - type: str - size: 20 - terminator: 0x40 - pad-right: 0x2b - - id: str_term_include - type: str - size: 20 - terminator: 0x40 - include: true - # "consume" is pointless to test: it will be always consumed anyway, as we have a fixed-length string diff --git a/formats_rust/str_pad_term_empty.ksy b/formats_rust/str_pad_term_empty.ksy deleted file mode 100644 index 12a2d194d..000000000 --- a/formats_rust/str_pad_term_empty.ksy +++ /dev/null @@ -1,25 +0,0 @@ -# Same as "str_pad_term", but used with different input file that is -# meant to test fully empty strings -meta: - id: str_pad_term_empty - encoding: UTF-8 -seq: - - id: str_pad - type: str - size: 20 - pad-right: 0x40 - - id: str_term - type: str - size: 20 - terminator: 0x40 - - id: str_term_and_pad - type: str - size: 20 - terminator: 0x40 - pad-right: 0x2b - - id: str_term_include - type: str - size: 20 - terminator: 0x40 - include: true - # "consume" is pointless to test: it will be always consumed anyway, as we have a fixed-length string diff --git a/formats_rust/switch_bytearray.ksy b/formats_rust/switch_bytearray.ksy deleted file mode 100644 index a9db63a6b..000000000 --- a/formats_rust/switch_bytearray.ksy +++ /dev/null @@ -1,27 +0,0 @@ -meta: - id: switch_bytearray -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - size: 1 - - id: body - type: - switch-on: code - cases: - '[73]': intval - '[83]': strval - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/switch_cast.ksy b/formats_rust/switch_cast.ksy deleted file mode 100644 index ebb267462..000000000 --- a/formats_rust/switch_cast.ksy +++ /dev/null @@ -1,33 +0,0 @@ -meta: - id: switch_cast -seq: - - id: opcodes - type: opcode - repeat: eos -instances: - first_obj: - value: opcodes[0].body.as - second_val: - value: opcodes[1].body.as.value - err_cast: - value: opcodes[2].body.as -types: - opcode: - seq: - - id: code - type: u1 - - id: body - type: - switch-on: code - cases: - 73: intval - 83: strval - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/switch_else_only.ksy b/formats_rust/switch_else_only.ksy deleted file mode 100644 index 199ffd085..000000000 --- a/formats_rust/switch_else_only.ksy +++ /dev/null @@ -1,22 +0,0 @@ -meta: - id: switch_else_only -seq: - - id: opcode - type: s1 - - id: prim_byte - type: - switch-on: opcode - cases: - _: s1 - - id: indicator - size: 4 - - id: ut - type: - switch-on: indicator - cases: - _: data -types: - data: - seq: - - id: value - size: 4 diff --git a/formats_rust/switch_integers.ksy b/formats_rust/switch_integers.ksy deleted file mode 100644 index 647bdb640..000000000 --- a/formats_rust/switch_integers.ksy +++ /dev/null @@ -1,20 +0,0 @@ -meta: - id: switch_integers - endian: le -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: u1 - - id: body - type: - switch-on: code - cases: - 1: u1 - 2: u2 - 4: u4 - 8: u8 diff --git a/formats_rust/switch_integers2.ksy b/formats_rust/switch_integers2.ksy deleted file mode 100644 index 8f33f40f4..000000000 --- a/formats_rust/switch_integers2.ksy +++ /dev/null @@ -1,22 +0,0 @@ -meta: - id: switch_integers2 - endian: le -seq: - - id: code - type: u1 - - id: len - type: - switch-on: code - cases: - 1: u1 - 2: u2 - 4: u4 - 8: u8 - - id: ham - size: len - - id: padding - type: u1 - if: len > 3 -instances: - len_mod_str: - value: (len * 2 - 1).to_s diff --git a/formats_rust/switch_manual_enum.ksy b/formats_rust/switch_manual_enum.ksy deleted file mode 100644 index 996e83eb1..000000000 --- a/formats_rust/switch_manual_enum.ksy +++ /dev/null @@ -1,32 +0,0 @@ -meta: - id: switch_manual_enum -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: u1 - enum: code_enum - - id: body - type: - switch-on: code - cases: - code_enum::intval: intval - code_enum::strval: strval - enums: - code_enum: - 73: intval # 'I' - 83: strval # 'S' - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/switch_manual_enum_invalid.ksy b/formats_rust/switch_manual_enum_invalid.ksy deleted file mode 100644 index 30a2b4126..000000000 --- a/formats_rust/switch_manual_enum_invalid.ksy +++ /dev/null @@ -1,33 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/300 -meta: - id: switch_manual_enum_invalid -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: u1 - enum: code_enum - - id: body - type: - switch-on: code - cases: - code_enum::intval: intval - code_enum::strval: strval - enums: - code_enum: - 73: intval # 'I' - 83: strval # 'S' - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/switch_manual_enum_invalid_else.ksy b/formats_rust/switch_manual_enum_invalid_else.ksy deleted file mode 100644 index 5911655ca..000000000 --- a/formats_rust/switch_manual_enum_invalid_else.ksy +++ /dev/null @@ -1,38 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/300 -meta: - id: switch_manual_enum_invalid_else -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: u1 - enum: code_enum - - id: body - type: - switch-on: code - cases: - code_enum::intval: intval - code_enum::strval: strval - _: defval - enums: - code_enum: - 73: intval # 'I' - 83: strval # 'S' - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII - defval: - instances: - value: - value: 123 diff --git a/formats_rust/switch_manual_int.ksy b/formats_rust/switch_manual_int.ksy deleted file mode 100644 index a62208c0e..000000000 --- a/formats_rust/switch_manual_int.ksy +++ /dev/null @@ -1,27 +0,0 @@ -meta: - id: switch_manual_int -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: u1 - - id: body - type: - switch-on: code - cases: - 73: intval - 83: strval - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/switch_manual_int_else.ksy b/formats_rust/switch_manual_int_else.ksy deleted file mode 100644 index a1ffe3590..000000000 --- a/formats_rust/switch_manual_int_else.ksy +++ /dev/null @@ -1,33 +0,0 @@ -meta: - id: switch_manual_int_else - endian: le -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: u1 - - id: body - type: - switch-on: code - cases: - 73: intval - 83: strval - _: noneval - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII - noneval: - seq: - - id: filler - type: u4 diff --git a/formats_rust/switch_manual_int_size.ksy b/formats_rust/switch_manual_int_size.ksy deleted file mode 100644 index 535c73fbb..000000000 --- a/formats_rust/switch_manual_int_size.ksy +++ /dev/null @@ -1,37 +0,0 @@ -meta: - id: switch_manual_int_size - endian: le -seq: - - id: chunks - type: chunk - repeat: eos -types: - chunk: - seq: - - id: code - type: u1 - - id: size - type: u4 - - id: body - size: size - type: - switch-on: code - cases: - 0x11: chunk_meta - 0x22: chunk_dir - types: - chunk_meta: - seq: - - id: title - type: strz - encoding: UTF-8 - - id: author - type: strz - encoding: UTF-8 - chunk_dir: - seq: - - id: entries - type: str - size: 4 - repeat: eos - encoding: UTF-8 diff --git a/formats_rust/switch_manual_int_size_else.ksy b/formats_rust/switch_manual_int_size_else.ksy deleted file mode 100644 index 9f108374f..000000000 --- a/formats_rust/switch_manual_int_size_else.ksy +++ /dev/null @@ -1,42 +0,0 @@ -meta: - id: switch_manual_int_size_else - endian: le -seq: - - id: chunks - type: chunk - repeat: eos -types: - chunk: - seq: - - id: code - type: u1 - - id: size - type: u4 - - id: body - size: size - type: - switch-on: code - cases: - 0x11: chunk_meta - 0x22: chunk_dir - _: dummy - types: - chunk_meta: - seq: - - id: title - type: strz - encoding: UTF-8 - - id: author - type: strz - encoding: UTF-8 - chunk_dir: - seq: - - id: entries - type: str - size: 4 - repeat: eos - encoding: UTF-8 - dummy: - seq: - - id: rest - size-eos: true diff --git a/formats_rust/switch_manual_int_size_eos.ksy b/formats_rust/switch_manual_int_size_eos.ksy deleted file mode 100644 index aaebe0907..000000000 --- a/formats_rust/switch_manual_int_size_eos.ksy +++ /dev/null @@ -1,42 +0,0 @@ -meta: - id: switch_manual_int_size_eos - endian: le -seq: - - id: chunks - type: chunk - repeat: eos -types: - chunk: - seq: - - id: code - type: u1 - - id: size - type: u4 - - id: body - size: size - type: chunk_body - chunk_body: - seq: - - id: body - size-eos: true - type: - switch-on: _parent.code - cases: - 0x11: chunk_meta - 0x22: chunk_dir - types: - chunk_meta: - seq: - - id: title - type: strz - encoding: UTF-8 - - id: author - type: strz - encoding: UTF-8 - chunk_dir: - seq: - - id: entries - type: str - size: 4 - repeat: eos - encoding: UTF-8 diff --git a/formats_rust/switch_manual_str.ksy b/formats_rust/switch_manual_str.ksy deleted file mode 100644 index 5e244eeac..000000000 --- a/formats_rust/switch_manual_str.ksy +++ /dev/null @@ -1,29 +0,0 @@ -meta: - id: switch_manual_str -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: str - size: 1 - encoding: ASCII - - id: body - type: - switch-on: code - cases: - '"I"': intval - '"S"': strval - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII diff --git a/formats_rust/switch_manual_str_else.ksy b/formats_rust/switch_manual_str_else.ksy deleted file mode 100644 index 24c409754..000000000 --- a/formats_rust/switch_manual_str_else.ksy +++ /dev/null @@ -1,35 +0,0 @@ -meta: - id: switch_manual_str_else - endian: le -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: str - size: 1 - encoding: ASCII - - id: body - type: - switch-on: code - cases: - '"I"': intval - '"S"': strval - _: noneval - types: - intval: - seq: - - id: value - type: u1 - strval: - seq: - - id: value - type: strz - encoding: ASCII - noneval: - seq: - - id: filler - type: u4 diff --git a/formats_rust/switch_multi_bool_ops.ksy b/formats_rust/switch_multi_bool_ops.ksy deleted file mode 100644 index 38ffbb448..000000000 --- a/formats_rust/switch_multi_bool_ops.ksy +++ /dev/null @@ -1,23 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct_compiler/issues/39 -meta: - id: switch_multi_bool_ops - endian: le -seq: - - id: opcodes - type: opcode - repeat: eos -types: - opcode: - seq: - - id: code - type: u1 - - id: body - type: - switch-on: "( (code > 0) and - (code <= 8) and - ((code != 10) ? true : false)) ? code : 0" - cases: - 1: u1 - 2: u2 - 4: u4 - 8: u8 diff --git a/formats_rust/switch_repeat_expr.ksy b/formats_rust/switch_repeat_expr.ksy deleted file mode 100644 index a9925e442..000000000 --- a/formats_rust/switch_repeat_expr.ksy +++ /dev/null @@ -1,26 +0,0 @@ -meta: - id: switch_repeat_expr - endian: le -seq: - - id: code - type: u1 - - id: size - type: u4 - - id: body - repeat: expr - repeat-expr: 1 - size: size - type: - switch-on: code - cases: - 0x11: one - 0x22: two -types: - one: - seq: - - id: first - size-eos: true - two: - seq: - - id: second - size-eos: true diff --git a/formats_rust/switch_repeat_expr_invalid.ksy b/formats_rust/switch_repeat_expr_invalid.ksy deleted file mode 100644 index 672b9433f..000000000 --- a/formats_rust/switch_repeat_expr_invalid.ksy +++ /dev/null @@ -1,27 +0,0 @@ -# https://github.com/kaitai-io/kaitai_struct/issues/494 -meta: - id: switch_repeat_expr_invalid - endian: le -seq: - - id: code - type: u1 - - id: size - type: u4 - - id: body - repeat: expr - repeat-expr: 1 - size: size - type: - switch-on: code - cases: - 0xff: one # there is actually 0x11 in the file - 0x22: two -types: - one: - seq: - - id: first - size-eos: true - two: - seq: - - id: second - size-eos: true diff --git a/formats_rust/term_bytes.ksy b/formats_rust/term_bytes.ksy deleted file mode 100644 index a5f4e3e3a..000000000 --- a/formats_rust/term_bytes.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: term_bytes -seq: - - id: s1 - terminator: 0x7c - - id: s2 - terminator: 0x7c - consume: false - - id: s3 - terminator: 0x40 - include: true diff --git a/formats_rust/term_strz.ksy b/formats_rust/term_strz.ksy deleted file mode 100644 index e434f5f9b..000000000 --- a/formats_rust/term_strz.ksy +++ /dev/null @@ -1,18 +0,0 @@ -meta: - id: term_strz - endian: le -seq: - - id: s1 - type: str - encoding: UTF-8 - terminator: 0x7c - - id: s2 - type: str - encoding: UTF-8 - terminator: 0x7c - consume: false - - id: s3 - type: str - encoding: UTF-8 - terminator: 0x40 - include: true diff --git a/formats_rust/term_u1_val.ksy b/formats_rust/term_u1_val.ksy deleted file mode 100644 index 2f8d2f455..000000000 --- a/formats_rust/term_u1_val.ksy +++ /dev/null @@ -1,12 +0,0 @@ -# Test if unsigned values in `terminator` work -meta: - id: term_u1_val -seq: - - id: foo - terminator: 0xe3 - consume: false - - id: bar - type: str - encoding: UTF-8 - terminator: 0xab - include: true diff --git a/formats_rust/to_string_custom.ksy b/formats_rust/to_string_custom.ksy deleted file mode 100644 index dd893eaca..000000000 --- a/formats_rust/to_string_custom.ksy +++ /dev/null @@ -1,12 +0,0 @@ -meta: - id: to_string_custom - encoding: UTF-8 -seq: - - id: s1 - type: str - terminator: 0x7c - - id: s2 - type: str - terminator: 0x7c -to-string: | - "s1 = " + s1 + ", s2 = " + s2 diff --git a/formats_rust/ts_packet_header.ksy b/formats_rust/ts_packet_header.ksy deleted file mode 100644 index e5902b25c..000000000 --- a/formats_rust/ts_packet_header.ksy +++ /dev/null @@ -1,38 +0,0 @@ -# Transport stream packet -# see H.222.0 F.1.1 - -# |7,6,5,4,2,1,0|7,6,5,4,3,2,1,0|7,6,5,4,3,2,1,0|7,6,5,4,3,2,1,0| -# | sync_byte | , , ,<-------pid------------->| ,afc,<-cc-->| - -meta: - id: ts_packet_header - endian: le -doc: > - describes the first 4 header bytes of a TS Packet header -seq: - - id: sync_byte - type: u1 - #contents: [0x47] - - id: transport_error_indicator - type: b1 - - id: payload_unit_start_indicator - type: b1 - - id: transport_priority - type: b1 - - id: pid - type: b13 - - id: transport_scrambling_control - type: b2 - - id: adaptation_field_control - type: b2 - enum: adaptation_field_control_enum - - id: continuity_counter - type: b4 - - id: ts_packet_remain - size: 184 -enums: - adaptation_field_control_enum: - 0x0: reserved - 0x1: payload_only - 0x2: adaptation_field_only - 0x3: adaptation_field_and_payload diff --git a/formats_rust/type_int_unary_op.ksy b/formats_rust/type_int_unary_op.ksy deleted file mode 100644 index c9a3c7e74..000000000 --- a/formats_rust/type_int_unary_op.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: type_int_unary_op - endian: le -seq: - - id: value_s2 - type: s2 - - id: value_s8 - type: s8 -instances: - unary_s2: - value: -value_s2 - unary_s8: - value: -value_s8 diff --git a/formats_rust/type_ternary.ksy b/formats_rust/type_ternary.ksy deleted file mode 100644 index e93637e8b..000000000 --- a/formats_rust/type_ternary.ksy +++ /dev/null @@ -1,23 +0,0 @@ -meta: - id: type_ternary -seq: - - id: dif_wo_hack - size: 1 - type: dummy - if: not is_hack - - id: dif_with_hack - size: 1 - type: dummy - process: xor(0b00000011) -types: - dummy: - seq: - - id: value - type: u1 -instances: - is_hack: - value: "true" - dif: - value: "not is_hack ? dif_wo_hack : dif_with_hack" - dif_value: - value: dif.value diff --git a/formats_rust/type_ternary_2nd_falsy.ksy b/formats_rust/type_ternary_2nd_falsy.ksy deleted file mode 100644 index 0be95279a..000000000 --- a/formats_rust/type_ternary_2nd_falsy.ksy +++ /dev/null @@ -1,46 +0,0 @@ -# Test languages without built-in ternary operator support (Lua) if they're not blindly using `cond and if_true or if_false` -# (doesn't work properly when if_true == false) -meta: - id: type_ternary_2nd_falsy -seq: - - id: int_truthy - type: u1 - - id: ut - type: foo - - id: int_array - type: u1 - repeat: expr - repeat-expr: 2 - - id: int_array_empty - type: u1 - repeat: expr - repeat-expr: 0 -types: - foo: - seq: - - id: m - type: u1 -instances: - t: - value: true - null_ut: - value: ut - if: false - v_false: - value: 't ? false : true' - v_int_zero: - value: 't ? 0 : 10' - v_int_neg_zero: - value: 't ? -0 : -20' - v_float_zero: - value: 't ? 0.0 : 3.14' - v_float_neg_zero: - value: 't ? -0.0 : -2.72' - v_str_w_zero: # "0" is falsy in PHP, might be also in other languages - value: 't ? "0" : "30"' - v_null_ut: - value: 't ? null_ut : ut' - v_str_empty: - value: 't ? "" : "kaitai"' - v_int_array_empty: - value: 't ? int_array_empty : int_array' diff --git a/formats_rust/type_ternary_opaque.ksy b/formats_rust/type_ternary_opaque.ksy deleted file mode 100644 index 9c8416a51..000000000 --- a/formats_rust/type_ternary_opaque.ksy +++ /dev/null @@ -1,18 +0,0 @@ -meta: - id: type_ternary_opaque - ks-opaque-types: true -seq: - - id: dif_wo_hack - size: 12 - type: term_strz - if: not is_hack - - id: dif_with_hack - size: 12 - type: term_strz - process: xor(0b00000011) - if: is_hack -instances: - is_hack: - value: "false" - dif: - value: "not is_hack ? dif_wo_hack : dif_with_hack" diff --git a/formats_rust/user_type.ksy b/formats_rust/user_type.ksy deleted file mode 100644 index 9e56f7b9f..000000000 --- a/formats_rust/user_type.ksy +++ /dev/null @@ -1,15 +0,0 @@ -# Tests very basic user-defined type functionality. A single type is -# defined in top-level class and is invoked via a seq attribute. -meta: - id: user_type - endian: le -seq: - - id: one - type: header -types: - header: - seq: - - id: width - type: u4 - - id: height - type: u4 diff --git a/formats_rust/valid_eq_str_encodings.ksy b/formats_rust/valid_eq_str_encodings.ksy deleted file mode 100644 index 1f6f57006..000000000 --- a/formats_rust/valid_eq_str_encodings.ksy +++ /dev/null @@ -1,32 +0,0 @@ -meta: - id: valid_eq_str_encodings - endian: le -seq: - - id: len_of_1 - type: u2 - - id: str1 - type: str - size: len_of_1 - encoding: ASCII - valid: '"Some ASCII"' - - id: len_of_2 - type: u2 - - id: str2 - type: str - size: len_of_2 - encoding: UTF-8 - valid: '"こんにちは"' - - id: len_of_3 - type: u2 - - id: str3 - type: str - size: len_of_3 - encoding: SJIS - valid: '"こんにちは"' - - id: len_of_4 - type: u2 - - id: str4 - type: str - size: len_of_4 - encoding: CP437 - valid: '"░▒▓"' diff --git a/formats_rust/valid_fail_anyof_int.ksy b/formats_rust/valid_fail_anyof_int.ksy deleted file mode 100644 index 645007dec..000000000 --- a/formats_rust/valid_fail_anyof_int.ksy +++ /dev/null @@ -1,15 +0,0 @@ -meta: - id: valid_fail_anyof_int -seq: - - id: foo - type: u1 - valid: # there is actually 0x50 in the file - any-of: - - 5 - - 6 - - 7 - - 8 - - 10 - - 11 - - 12 - - 47 diff --git a/formats_rust/valid_fail_contents.ksy b/formats_rust/valid_fail_contents.ksy deleted file mode 100644 index e06ce0f02..000000000 --- a/formats_rust/valid_fail_contents.ksy +++ /dev/null @@ -1,5 +0,0 @@ -meta: - id: valid_fail_contents -seq: - - id: foo - contents: [0x51, 0x41] # there is actually [0x50, 0x41] in the file diff --git a/formats_rust/valid_fail_eq_bytes.ksy b/formats_rust/valid_fail_eq_bytes.ksy deleted file mode 100644 index 9582dcd30..000000000 --- a/formats_rust/valid_fail_eq_bytes.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: valid_fail_eq_bytes -seq: - - id: foo - size: 2 - valid: '[0x51, 0x41]' # there is actually [0x50, 0x41] in the file diff --git a/formats_rust/valid_fail_eq_int.ksy b/formats_rust/valid_fail_eq_int.ksy deleted file mode 100644 index 924e6f5b1..000000000 --- a/formats_rust/valid_fail_eq_int.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: valid_fail_eq_int -seq: - - id: foo - type: u1 - valid: 123 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_eq_str.ksy b/formats_rust/valid_fail_eq_str.ksy deleted file mode 100644 index 50a72e9cc..000000000 --- a/formats_rust/valid_fail_eq_str.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: valid_fail_eq_str - encoding: ASCII -seq: - - id: foo - size: 4 - type: str - valid: '"BACK"' # there is actually "PACK" in the file diff --git a/formats_rust/valid_fail_expr.ksy b/formats_rust/valid_fail_expr.ksy deleted file mode 100644 index 444eb0795..000000000 --- a/formats_rust/valid_fail_expr.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: valid_fail_expr -seq: - - id: foo - type: u1 - valid: # should pass - expr: _ == 1 - - id: bar - type: s2le - valid: # there's actually -190 in the file - expr: _ < -190 or _ > -190 diff --git a/formats_rust/valid_fail_inst.ksy b/formats_rust/valid_fail_inst.ksy deleted file mode 100644 index c993514f4..000000000 --- a/formats_rust/valid_fail_inst.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: valid_fail_inst -seq: - - id: a - type: u1 - if: inst >= 0 # invoke instance -instances: - inst: - pos: 5 - type: u1 - valid: 0x50 # there is actually 0x31 in the file diff --git a/formats_rust/valid_fail_max_int.ksy b/formats_rust/valid_fail_max_int.ksy deleted file mode 100644 index 7ba628d22..000000000 --- a/formats_rust/valid_fail_max_int.ksy +++ /dev/null @@ -1,7 +0,0 @@ -meta: - id: valid_fail_max_int -seq: - - id: foo - type: u1 - valid: - max: 12 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_min_int.ksy b/formats_rust/valid_fail_min_int.ksy deleted file mode 100644 index bafc45595..000000000 --- a/formats_rust/valid_fail_min_int.ksy +++ /dev/null @@ -1,7 +0,0 @@ -meta: - id: valid_fail_min_int -seq: - - id: foo - type: u1 - valid: - min: 123 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_range_bytes.ksy b/formats_rust/valid_fail_range_bytes.ksy deleted file mode 100644 index 06025b4a1..000000000 --- a/formats_rust/valid_fail_range_bytes.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: valid_fail_range_bytes -seq: - - id: foo - size: 2 - valid: - min: '[80]' - max: '[80, 49]' # there is actually [80, 65] in the file diff --git a/formats_rust/valid_fail_range_float.ksy b/formats_rust/valid_fail_range_float.ksy deleted file mode 100644 index f058db5b6..000000000 --- a/formats_rust/valid_fail_range_float.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: valid_fail_range_float -seq: - - id: foo - type: f4le - valid: - min: 0.2 - max: 0.4 # there is actually 0.5 in the file diff --git a/formats_rust/valid_fail_range_int.ksy b/formats_rust/valid_fail_range_int.ksy deleted file mode 100644 index 71dd2dafc..000000000 --- a/formats_rust/valid_fail_range_int.ksy +++ /dev/null @@ -1,8 +0,0 @@ -meta: - id: valid_fail_range_int -seq: - - id: foo - type: u1 - valid: - min: 5 - max: 10 # there is actually 0x50 in the file diff --git a/formats_rust/valid_fail_range_str.ksy b/formats_rust/valid_fail_range_str.ksy deleted file mode 100644 index 755f23f99..000000000 --- a/formats_rust/valid_fail_range_str.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: valid_fail_range_str - encoding: ASCII -seq: - - id: foo - size: 2 - type: str - # there is actually [80, 65] ("PA") in the file - valid: - min: '"P"' # [80] - max: '"P1"' # [80, 49] diff --git a/formats_rust/valid_long.ksy b/formats_rust/valid_long.ksy deleted file mode 100644 index 3a328a61f..000000000 --- a/formats_rust/valid_long.ksy +++ /dev/null @@ -1,51 +0,0 @@ -meta: - id: valid_long - encoding: utf-8 - endian: le -seq: - - id: magic1 - size: 6 - valid: - eq: '[0x50, 0x41, 0x43, 0x4b, 0x2d, 0x31]' - - id: uint8 - type: u1 - valid: - eq: 255 - - id: sint8 - type: s1 - valid: - eq: -1 - - id: magic_uint - type: str - size: 10 - valid: - eq: '"PACK-U-DEF"' - - id: uint16 - type: u2 - valid: - eq: 65535 - - id: uint32 - type: u4 - valid: - eq: 4294967295 - - id: uint64 - type: u8 - valid: - eq: 18446744073709551615 - - id: magic_sint - type: str - size: 10 - valid: - eq: '"PACK-S-DEF"' - - id: sint16 - type: s2 - valid: - eq: -1 - - id: sint32 - type: s4 - valid: - eq: -1 - - id: sint64 - type: s8 - valid: - eq: -1 diff --git a/formats_rust/valid_not_parsed_if.ksy b/formats_rust/valid_not_parsed_if.ksy deleted file mode 100644 index f693e7018..000000000 --- a/formats_rust/valid_not_parsed_if.ksy +++ /dev/null @@ -1,11 +0,0 @@ -meta: - id: valid_not_parsed_if -seq: - - id: not_parsed - if: false - type: u1 - valid: 42 - - id: parsed - if: true - type: u1 - valid: 0x50 diff --git a/formats_rust/valid_optional_id.ksy b/formats_rust/valid_optional_id.ksy deleted file mode 100644 index 0751358a5..000000000 --- a/formats_rust/valid_optional_id.ksy +++ /dev/null @@ -1,10 +0,0 @@ -meta: - id: valid_optional_id -seq: - - contents: 'PACK-1' - - type: u1 - valid: - eq: 0xff - - type: s1 - valid: - expr: _ == -1 diff --git a/formats_rust/valid_short.ksy b/formats_rust/valid_short.ksy deleted file mode 100644 index 259284ad6..000000000 --- a/formats_rust/valid_short.ksy +++ /dev/null @@ -1,40 +0,0 @@ -meta: - id: valid_short - encoding: utf-8 - endian: le -seq: - - id: magic1 - size: 6 - valid: '[0x50, 0x41, 0x43, 0x4b, 0x2d, 0x31]' - - id: uint8 - type: u1 - valid: 255 - - id: sint8 - type: s1 - valid: -1 - - id: magic_uint - type: str - size: 10 - valid: '"PACK-U-DEF"' - - id: uint16 - type: u2 - valid: 65535 - - id: uint32 - type: u4 - valid: 4294967295 - - id: uint64 - type: u8 - valid: 18446744073709551615 - - id: magic_sint - type: str - size: 10 - valid: '"PACK-S-DEF"' - - id: sint16 - type: s2 - valid: -1 - - id: sint32 - type: s4 - valid: -1 - - id: sint64 - type: s8 - valid: -1 diff --git a/formats_rust/valid_switch.ksy b/formats_rust/valid_switch.ksy deleted file mode 100644 index c17c02542..000000000 --- a/formats_rust/valid_switch.ksy +++ /dev/null @@ -1,13 +0,0 @@ -meta: - id: valid_switch -seq: - - id: a - type: u1 - valid: 0x50 - - id: b - type: - switch-on: a - cases: - 0x50: u2le - _: u2be - valid: 0x4341 diff --git a/formats_rust/yaml_ints.ksy b/formats_rust/yaml_ints.ksy deleted file mode 100644 index a3c40dbdc..000000000 --- a/formats_rust/yaml_ints.ksy +++ /dev/null @@ -1,12 +0,0 @@ -# Tests "forgiving" YAML KS expression parsing -meta: - id: yaml_ints -instances: - test_u4_dec: - value: 4294967295 - test_u4_hex: - value: 0xffffffff - test_u8_dec: - value: 18446744073709551615 - test_u8_hex: - value: 0xffffffffffffffff diff --git a/formats_rust/zlib_surrounded.ksy b/formats_rust/zlib_surrounded.ksy deleted file mode 100644 index fb3f652a4..000000000 --- a/formats_rust/zlib_surrounded.ksy +++ /dev/null @@ -1,16 +0,0 @@ -meta: - id: zlib_surrounded -seq: - - id: pre - size: 4 - - id: zlib - size: 12 - process: zlib - type: inflated - - id: post - size: 4 -types: - inflated: - seq: - - id: num - type: s4le diff --git a/formats_rust/zlib_with_header_78.ksy b/formats_rust/zlib_with_header_78.ksy deleted file mode 100644 index d23c06abd..000000000 --- a/formats_rust/zlib_with_header_78.ksy +++ /dev/null @@ -1,6 +0,0 @@ -meta: - id: zlib_with_header_78 -seq: - - id: data - size-eos: true - process: zlib diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index ac81dd53d..74664a9e4 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "rust" version = "0.1.0" -authors = ["Connor Wood "] -edition = "2021" +authors = ["Aon"] +edition = "2018" build = "build.rs" [dependencies] diff --git a/spec/rust/build.rs b/spec/rust/build.rs index 131c5b372..c7ecaaddb 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -4,7 +4,7 @@ use std::{ prelude::* }, fs, - path::Path + path::Path, ffi::OsStr }; pub fn path_exists(path: &Path) -> bool { @@ -12,8 +12,8 @@ pub fn path_exists(path: &Path) -> bool { } fn main() { - let source_path = Path::new("../../compiled/rust"); - let destination_path = Path::new("./tests/formats"); + let source_path = Path::new("../../compiled"); + let destination_path = Path::new("./formats"); if !path_exists(destination_path) { fs::create_dir(destination_path).unwrap_or_else(|e| { @@ -65,6 +65,10 @@ fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { let entry = entry?; let path = entry.path(); + if path.extension().unwrap_or(&OsStr::new("")) != "rs" { + continue; + } + if let Some(file_name) = path.file_name() { fs::copy(path.clone(), destination_path.join(file_name))?; println!("copying {} to {}", path.as_path().display().to_string(), diff --git a/spec/rust/tests/formats/custom_fx.rs b/spec/rust/formats/custom_fx.rs similarity index 100% rename from spec/rust/tests/formats/custom_fx.rs rename to spec/rust/formats/custom_fx.rs diff --git a/spec/rust/tests/formats/custom_fx_no_args.rs b/spec/rust/formats/custom_fx_no_args.rs similarity index 100% rename from spec/rust/tests/formats/custom_fx_no_args.rs rename to spec/rust/formats/custom_fx_no_args.rs diff --git a/spec/rust/tests/formats/my_custom_fx.rs b/spec/rust/formats/my_custom_fx.rs similarity index 100% rename from spec/rust/tests/formats/my_custom_fx.rs rename to spec/rust/formats/my_custom_fx.rs diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs new file mode 100644 index 000000000..ec8a3cde0 --- /dev/null +++ b/spec/rust/tests/test_bcd_user_type_be.rs @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bcd_user_type_be::*; + +#[test] +fn test_bcd_user_type_be() { + let bytes = fs::read("../../src/bcd_user_type_be.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BcdUserTypeBe::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.ltr().as_int().expect("error reading"), 12345678); + assert_eq!(*r.ltr().as_str().expect("error reading"), "12345678"); + assert_eq!(*r.rtl().as_int().expect("error reading"), 87654321); + assert_eq!(*r.rtl().as_str().expect("error reading"), "87654321"); + assert_eq!(*r.leading_zero_ltr().as_int().expect("error reading"), 123456); + assert_eq!(*r.leading_zero_ltr().as_str().expect("error reading"), "00123456"); +} diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs new file mode 100644 index 000000000..31cb98dcf --- /dev/null +++ b/spec/rust/tests/test_bcd_user_type_le.rs @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bcd_user_type_le::*; + +#[test] +fn test_bcd_user_type_le() { + let bytes = fs::read("../../src/bcd_user_type_le.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BcdUserTypeLe::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.ltr().as_int().expect("error reading"), 12345678); + assert_eq!(*r.ltr().as_str().expect("error reading"), "12345678"); + assert_eq!(*r.rtl().as_int().expect("error reading"), 87654321); + assert_eq!(*r.rtl().as_str().expect("error reading"), "87654321"); + assert_eq!(*r.leading_zero_ltr().as_int().expect("error reading"), 123456); + assert_eq!(*r.leading_zero_ltr().as_str().expect("error reading"), "00123456"); +} diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs new file mode 100644 index 000000000..f41c1dd2f --- /dev/null +++ b/spec/rust/tests/test_bits_byte_aligned.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_byte_aligned::*; + +#[test] +fn test_bits_byte_aligned() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsByteAligned::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), 20); + assert_eq!(*r.byte_1(), 65); + assert_eq!(*r.two(), 2); + assert_eq!(*r.three(), false); + assert_eq!(*r.byte_2(), 75); + assert_eq!(*r.four(), 2892); + assert_eq!(*r.byte_3(), vec![0xffu8]); + assert_eq!(*r.full_byte(), 255); + assert_eq!(*r.byte_4(), 80); +} diff --git a/spec/rust/tests/test_bits_enum.rs b/spec/rust/tests/test_bits_enum.rs new file mode 100644 index 000000000..c430e9e51 --- /dev/null +++ b/spec/rust/tests/test_bits_enum.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_enum::*; + +#[test] +fn test_bits_enum() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsEnum::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), BitsEnum_Animal::Platypus); + assert_eq!(*r.two(), BitsEnum_Animal::Horse); + assert_eq!(*r.three(), BitsEnum_Animal::Cat); +} diff --git a/spec/rust/tests/test_bits_seq_endian_combo.rs b/spec/rust/tests/test_bits_seq_endian_combo.rs new file mode 100644 index 000000000..50f1a76ce --- /dev/null +++ b/spec/rust/tests/test_bits_seq_endian_combo.rs @@ -0,0 +1,33 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_seq_endian_combo::*; + +#[test] +fn test_bits_seq_endian_combo() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsSeqEndianCombo::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.be1(), 59); + assert_eq!(*r.be2(), 187); + assert_eq!(*r.le3(), 163); + assert_eq!(*r.be4(), 20); + assert_eq!(*r.le5(), 10); + assert_eq!(*r.le6(), 36); + assert_eq!(*r.le7(), 26); + assert_eq!(*r.be8(), true); +} diff --git a/spec/rust/tests/test_bits_shift_by_b32_le.rs b/spec/rust/tests/test_bits_shift_by_b32_le.rs new file mode 100644 index 000000000..5c512eba2 --- /dev/null +++ b/spec/rust/tests/test_bits_shift_by_b32_le.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_shift_by_b32_le::*; + +#[test] +fn test_bits_shift_by_b32_le() { + let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsShiftByB32Le::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), 4294967295); + assert_eq!(*r.b(), 0); +} diff --git a/spec/rust/tests/test_bits_shift_by_b64_le.rs b/spec/rust/tests/test_bits_shift_by_b64_le.rs new file mode 100644 index 000000000..725891fef --- /dev/null +++ b/spec/rust/tests/test_bits_shift_by_b64_le.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_shift_by_b64_le::*; + +#[test] +fn test_bits_shift_by_b64_le() { + let bytes = fs::read("../../src/bits_shift_by_b64_le.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsShiftByB64Le::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), 18446744073709551615); + assert_eq!(*r.b(), 0); +} diff --git a/spec/rust/tests/test_bits_signed_res_b32_be.rs b/spec/rust/tests/test_bits_signed_res_b32_be.rs new file mode 100644 index 000000000..64e1ab349 --- /dev/null +++ b/spec/rust/tests/test_bits_signed_res_b32_be.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_signed_res_b32_be::*; + +#[test] +fn test_bits_signed_res_b32_be() { + let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsSignedResB32Be::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), 4294967295); +} diff --git a/spec/rust/tests/test_bits_signed_res_b32_le.rs b/spec/rust/tests/test_bits_signed_res_b32_le.rs new file mode 100644 index 000000000..59560ae6f --- /dev/null +++ b/spec/rust/tests/test_bits_signed_res_b32_le.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_signed_res_b32_le::*; + +#[test] +fn test_bits_signed_res_b32_le() { + let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsSignedResB32Le::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), 4294967295); +} diff --git a/spec/rust/tests/test_bits_signed_shift_b32_le.rs b/spec/rust/tests/test_bits_signed_shift_b32_le.rs new file mode 100644 index 000000000..70089eabe --- /dev/null +++ b/spec/rust/tests/test_bits_signed_shift_b32_le.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_signed_shift_b32_le::*; + +#[test] +fn test_bits_signed_shift_b32_le() { + let bytes = fs::read("../../src/bits_signed_shift_b32_le.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsSignedShiftB32Le::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), 0); + assert_eq!(*r.b(), 255); +} diff --git a/spec/rust/tests/test_bits_signed_shift_b64_le.rs b/spec/rust/tests/test_bits_signed_shift_b64_le.rs new file mode 100644 index 000000000..4b72a1500 --- /dev/null +++ b/spec/rust/tests/test_bits_signed_shift_b64_le.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_signed_shift_b64_le::*; + +#[test] +fn test_bits_signed_shift_b64_le() { + let bytes = fs::read("../../src/bits_signed_shift_b64_le.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsSignedShiftB64Le::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), 0); + assert_eq!(*r.b(), 255); +} diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs new file mode 100644 index 000000000..503f1abdb --- /dev/null +++ b/spec/rust/tests/test_bits_simple.rs @@ -0,0 +1,39 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_simple::*; + +#[test] +fn test_bits_simple() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsSimple::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.byte_1(), 80); + assert_eq!(*r.byte_2(), 65); + assert_eq!(*r.bits_a(), false); + assert_eq!(*r.bits_b(), 4); + assert_eq!(*r.bits_c(), 3); + assert_eq!(*r.large_bits_1(), 300); + assert_eq!(*r.spacer(), 5); + assert_eq!(*r.large_bits_2(), 1329); + assert_eq!(*r.normal_s2(), -1); + assert_eq!(*r.byte_8_9_10(), 5259587); + assert_eq!(*r.byte_11_to_14(), 1261262125); + assert_eq!(*r.byte_15_to_19(), 293220057087); + assert_eq!(*r.byte_20_to_27(), 18446744073709551615); + assert_eq!(*r.test_if_b1().expect("error reading"), 123); +} diff --git a/spec/rust/tests/test_bits_simple_le.rs b/spec/rust/tests/test_bits_simple_le.rs new file mode 100644 index 000000000..ad5e77b94 --- /dev/null +++ b/spec/rust/tests/test_bits_simple_le.rs @@ -0,0 +1,39 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_simple_le::*; + +#[test] +fn test_bits_simple_le() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsSimpleLe::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.byte_1(), 80); + assert_eq!(*r.byte_2(), 65); + assert_eq!(*r.bits_a(), true); + assert_eq!(*r.bits_b(), 1); + assert_eq!(*r.bits_c(), 4); + assert_eq!(*r.large_bits_1(), 331); + assert_eq!(*r.spacer(), 3); + assert_eq!(*r.large_bits_2(), 393); + assert_eq!(*r.normal_s2(), -1); + assert_eq!(*r.byte_8_9_10(), 4407632); + assert_eq!(*r.byte_11_to_14(), 760556875); + assert_eq!(*r.byte_15_to_19(), 1099499455812); + assert_eq!(*r.byte_20_to_27(), 18446744073709551615); + assert_eq!(*r.test_if_b1().expect("error reading"), 123); +} diff --git a/spec/rust/tests/test_bits_unaligned_b32_be.rs b/spec/rust/tests/test_bits_unaligned_b32_be.rs new file mode 100644 index 000000000..8ace1910e --- /dev/null +++ b/spec/rust/tests/test_bits_unaligned_b32_be.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_unaligned_b32_be::*; + +#[test] +fn test_bits_unaligned_b32_be() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsUnalignedB32Be::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), true); + assert_eq!(*r.b(), 3648472617); + assert_eq!(*r.c(), 10); +} diff --git a/spec/rust/tests/test_bits_unaligned_b32_le.rs b/spec/rust/tests/test_bits_unaligned_b32_le.rs new file mode 100644 index 000000000..b0bb52c14 --- /dev/null +++ b/spec/rust/tests/test_bits_unaligned_b32_le.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_unaligned_b32_le::*; + +#[test] +fn test_bits_unaligned_b32_le() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsUnalignedB32Le::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), false); + assert_eq!(*r.b(), 173137398); + assert_eq!(*r.c(), 69); +} diff --git a/spec/rust/tests/test_bits_unaligned_b64_be.rs b/spec/rust/tests/test_bits_unaligned_b64_be.rs new file mode 100644 index 000000000..1abdcbbf5 --- /dev/null +++ b/spec/rust/tests/test_bits_unaligned_b64_be.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_unaligned_b64_be::*; + +#[test] +fn test_bits_unaligned_b64_be() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsUnalignedB64Be::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), true); + assert_eq!(*r.b(), 15670070570729969769); + assert_eq!(*r.c(), 14); +} diff --git a/spec/rust/tests/test_bits_unaligned_b64_le.rs b/spec/rust/tests/test_bits_unaligned_b64_le.rs new file mode 100644 index 000000000..de9e9d1bd --- /dev/null +++ b/spec/rust/tests/test_bits_unaligned_b64_le.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bits_unaligned_b64_le::*; + +#[test] +fn test_bits_unaligned_b64_le() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BitsUnalignedB64Le::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), false); + assert_eq!(*r.b(), 1902324737369038326); + assert_eq!(*r.c(), 71); +} diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs new file mode 100644 index 000000000..4507be3db --- /dev/null +++ b/spec/rust/tests/test_buffered_struct.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::buffered_struct::*; + +#[test] +fn test_buffered_struct() { + let bytes = fs::read("../../src/buffered_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BufferedStruct::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.len1(), 16); + assert_eq!(*r.block1().number1(), 66); + assert_eq!(*r.block1().number2(), 67); + assert_eq!(*r.len2(), 8); + assert_eq!(*r.block2().number1(), 68); + assert_eq!(*r.block2().number2(), 69); + assert_eq!(*r.finisher(), 238); +} diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs new file mode 100644 index 000000000..f05f9619d --- /dev/null +++ b/spec/rust/tests/test_bytes_pad_term.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::bytes_pad_term::*; + +#[test] +fn test_bytes_pad_term() { + let bytes = fs::read("../../src/str_pad_term.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = BytesPadTerm::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str_pad(), vec![0x73u8, 0x74u8, 0x72u8, 0x31u8]); + assert_eq!(*r.str_term(), vec![0x73u8, 0x74u8, 0x72u8, 0x32u8, 0x66u8, 0x6fu8, 0x6fu8]); + assert_eq!(*r.str_term_and_pad(), vec![0x73u8, 0x74u8, 0x72u8, 0x2bu8, 0x2bu8, 0x2bu8, 0x33u8, 0x62u8, 0x61u8, 0x72u8, 0x2bu8, 0x2bu8, 0x2bu8]); + assert_eq!(*r.str_term_include(), vec![0x73u8, 0x74u8, 0x72u8, 0x34u8, 0x62u8, 0x61u8, 0x7au8, 0x40u8]); +} diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs new file mode 100644 index 000000000..bf53842bd --- /dev/null +++ b/spec/rust/tests/test_cast_nested.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::cast_nested::*; + +#[test] +fn test_cast_nested() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = CastNested::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.opcodes_0_str().expect("error reading").value(), "foobar"); + assert_eq!(*r.opcodes_0_str_value().expect("error reading"), "foobar"); + assert_eq!(*r.opcodes_1_int().expect("error reading").value(), 66); + assert_eq!(*r.opcodes_1_int_value().expect("error reading"), 66); +} diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index 1fc016e85..eaba76385 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::cast_to_imported::*; #[test] diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs new file mode 100644 index 000000000..10a561763 --- /dev/null +++ b/spec/rust/tests/test_cast_to_top.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::cast_to_top::*; + +#[test] +fn test_cast_to_top() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = CastToTop::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.code(), 80); + assert_eq!(*r.header().expect("error reading").code(), 65); + assert_eq!(*r.header_casted().expect("error reading").code(), 65); +} diff --git a/spec/rust/tests/test_combine_bool.rs b/spec/rust/tests/test_combine_bool.rs new file mode 100644 index 000000000..21ac62517 --- /dev/null +++ b/spec/rust/tests/test_combine_bool.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::combine_bool::*; + +#[test] +fn test_combine_bool() { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = CombineBool::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.bool_bit(), true); + assert_eq!(*r.bool_calc_bit().expect("error reading"), false); +} diff --git a/spec/rust/tests/test_combine_bytes.rs b/spec/rust/tests/test_combine_bytes.rs new file mode 100644 index 000000000..a06322f08 --- /dev/null +++ b/spec/rust/tests/test_combine_bytes.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::combine_bytes::*; + +#[test] +fn test_combine_bytes() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = CombineBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.bytes_term(), vec![0x66u8, 0x6fu8, 0x6fu8]); + assert_eq!(*r.bytes_limit(), vec![0x62u8, 0x61u8, 0x72u8, 0x7cu8]); + assert_eq!(*r.bytes_eos(), vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); + assert_eq!(*r.bytes_calc().expect("error reading"), vec![0x52u8, 0x6eu8, 0x44u8]); + assert_eq!(*r.term_or_limit().expect("error reading"), vec![0x66u8, 0x6fu8, 0x6fu8]); + assert_eq!(*r.term_or_eos().expect("error reading"), vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); + assert_eq!(*r.term_or_calc().expect("error reading"), vec![0x66u8, 0x6fu8, 0x6fu8]); + assert_eq!(*r.limit_or_eos().expect("error reading"), vec![0x62u8, 0x61u8, 0x72u8, 0x7cu8]); + assert_eq!(*r.limit_or_calc().expect("error reading"), vec![0x52u8, 0x6eu8, 0x44u8]); + assert_eq!(*r.eos_or_calc().expect("error reading"), vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); +} diff --git a/spec/rust/tests/test_combine_enum.rs b/spec/rust/tests/test_combine_enum.rs new file mode 100644 index 000000000..771534f90 --- /dev/null +++ b/spec/rust/tests/test_combine_enum.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::combine_enum::*; + +#[test] +fn test_combine_enum() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = CombineEnum::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.enum_u4(), CombineEnum_Animal::Pig); + assert_eq!(*r.enum_u2(), CombineEnum_Animal::Horse); + assert_eq!(*r.enum_u4_u2().expect("error reading"), CombineEnum_Animal::Horse); +} diff --git a/spec/rust/tests/test_combine_str.rs b/spec/rust/tests/test_combine_str.rs new file mode 100644 index 000000000..3d3ea2d52 --- /dev/null +++ b/spec/rust/tests/test_combine_str.rs @@ -0,0 +1,40 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::combine_str::*; + +#[test] +fn test_combine_str() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = CombineStr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str_term(), "foo"); + assert_eq!(*r.str_limit(), "bar|"); + assert_eq!(*r.str_eos(), "baz@"); + assert_eq!(*r.str_calc().expect("error reading"), "bar"); + assert_eq!(*r.str_calc_bytes().expect("error reading"), "baz"); + assert_eq!(*r.term_or_limit().expect("error reading"), "foo"); + assert_eq!(*r.term_or_eos().expect("error reading"), "baz@"); + assert_eq!(*r.term_or_calc().expect("error reading"), "foo"); + assert_eq!(*r.term_or_calc_bytes().expect("error reading"), "baz"); + assert_eq!(*r.limit_or_eos().expect("error reading"), "bar|"); + assert_eq!(*r.limit_or_calc().expect("error reading"), "bar"); + assert_eq!(*r.limit_or_calc_bytes().expect("error reading"), "bar|"); + assert_eq!(*r.eos_or_calc().expect("error reading"), "bar"); + assert_eq!(*r.eos_or_calc_bytes().expect("error reading"), "baz@"); + assert_eq!(*r.calc_or_calc_bytes().expect("error reading"), "baz"); +} diff --git a/spec/rust/tests/manual_debug_0.rs b/spec/rust/tests/test_debug_0.rs similarity index 78% rename from spec/rust/tests/manual_debug_0.rs rename to spec/rust/tests/test_debug_0.rs index e1139ada4..0ca392ee3 100644 --- a/spec/rust/tests/manual_debug_0.rs +++ b/spec/rust/tests/test_debug_0.rs @@ -1,7 +1,7 @@ #![allow(dead_code)] extern crate kaitai; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::debug_0::*; #[test] diff --git a/spec/rust/tests/manual_debug_array_user.rs b/spec/rust/tests/test_debug_array_user.rs similarity index 93% rename from spec/rust/tests/manual_debug_array_user.rs rename to spec/rust/tests/test_debug_array_user.rs index 5df45afce..fb7b0f254 100644 --- a/spec/rust/tests/manual_debug_array_user.rs +++ b/spec/rust/tests/test_debug_array_user.rs @@ -3,7 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::debug_array_user::*; #[test] diff --git a/spec/rust/tests/test_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs new file mode 100644 index 000000000..203a73a27 --- /dev/null +++ b/spec/rust/tests/test_debug_switch_user.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::debug_switch_user::*; + +#[test] +fn test_debug_switch_user() { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DebugSwitchUser::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.code(), 1); + assert_eq!(*Into::>::into(&*r.data().as_ref().unwrap()).val(), -190); +} diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs new file mode 100644 index 000000000..c762e1a08 --- /dev/null +++ b/spec/rust/tests/test_default_big_endian.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::default_big_endian::*; + +#[test] +fn test_default_big_endian() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DefaultBigEndian::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), 117440512); +} diff --git a/spec/rust/tests/test_default_bit_endian_mod.rs b/spec/rust/tests/test_default_bit_endian_mod.rs new file mode 100644 index 000000000..a4cde8693 --- /dev/null +++ b/spec/rust/tests/test_default_bit_endian_mod.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::default_bit_endian_mod::*; + +#[test] +fn test_default_bit_endian_mod() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DefaultBitEndianMod::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.main().one(), 336); + assert_eq!(*r.main().two(), 8608); + assert_eq!(*r.main().nest().two(), 11595); + assert_eq!(*r.main().nest_be().two(), 12799); +} diff --git a/spec/rust/tests/test_default_endian_expr_exception.rs b/spec/rust/tests/test_default_endian_expr_exception.rs new file mode 100644 index 000000000..8873a096a --- /dev/null +++ b/spec/rust/tests/test_default_endian_expr_exception.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::default_endian_expr_exception::*; + +#[test] +fn test_default_endian_expr_exception() { + let bytes = fs::read("../../src/endian_expr.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DefaultEndianExprException::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: UndecidedEndiannessError", err); + } else { + panic!("no expected exception: UndecidedEndiannessError"); + } +} diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs new file mode 100644 index 000000000..83a2bcdaa --- /dev/null +++ b/spec/rust/tests/test_default_endian_expr_inherited.rs @@ -0,0 +1,40 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::default_endian_expr_inherited::*; + +#[test] +fn test_default_endian_expr_inherited() { + let bytes = fs::read("../../src/endian_expr.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DefaultEndianExprInherited::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]); + assert_eq!(*r.docs()[0 as usize].main().insides().some_int(), 66); + assert_eq!(*r.docs()[0 as usize].main().insides().more().some_int1(), 16896); + assert_eq!(*r.docs()[0 as usize].main().insides().more().some_int2(), 66); + assert_eq!(*r.docs()[0 as usize].main().insides().more().some_inst().expect("error reading"), 66); + assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]); + assert_eq!(*r.docs()[1 as usize].main().insides().some_int(), 66); + assert_eq!(*r.docs()[1 as usize].main().insides().more().some_int1(), 66); + assert_eq!(*r.docs()[1 as usize].main().insides().more().some_int2(), 16896); + assert_eq!(*r.docs()[1 as usize].main().insides().more().some_inst().expect("error reading"), 1107296256); + assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]); + assert_eq!(*r.docs()[2 as usize].main().insides().some_int(), 66); + assert_eq!(*r.docs()[2 as usize].main().insides().more().some_int1(), 66); + assert_eq!(*r.docs()[2 as usize].main().insides().more().some_int2(), 16896); + assert_eq!(*r.docs()[2 as usize].main().insides().more().some_inst().expect("error reading"), 1107296256); +} diff --git a/spec/rust/tests/test_default_endian_expr_is_be.rs b/spec/rust/tests/test_default_endian_expr_is_be.rs new file mode 100644 index 000000000..fc6553a31 --- /dev/null +++ b/spec/rust/tests/test_default_endian_expr_is_be.rs @@ -0,0 +1,43 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::default_endian_expr_is_be::*; + +#[test] +fn test_default_endian_expr_is_be() { + let bytes = fs::read("../../src/endian_expr.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DefaultEndianExprIsBe::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]); + assert_eq!(*r.docs()[0 as usize].main().some_int(), 66); + assert_eq!(*r.docs()[0 as usize].main().some_int_be(), 66); + assert_eq!(*r.docs()[0 as usize].main().some_int_le(), 66); + assert_eq!(*r.docs()[0 as usize].main().inst_int().expect("error reading"), 66); + assert_eq!(*r.docs()[0 as usize].main().inst_sub().expect("error reading").foo(), 66); + assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]); + assert_eq!(*r.docs()[1 as usize].main().some_int(), 66); + assert_eq!(*r.docs()[1 as usize].main().some_int_be(), 66); + assert_eq!(*r.docs()[1 as usize].main().some_int_le(), 66); + assert_eq!(*r.docs()[1 as usize].main().inst_int().expect("error reading"), 1107296256); + assert_eq!(*r.docs()[1 as usize].main().inst_sub().expect("error reading").foo(), 1107296256); + assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]); + assert_eq!(*r.docs()[2 as usize].main().some_int(), 1107296256); + assert_eq!(*r.docs()[2 as usize].main().some_int_be(), 66); + assert_eq!(*r.docs()[2 as usize].main().some_int_le(), 66); + assert_eq!(*r.docs()[2 as usize].main().inst_int().expect("error reading"), 66); + assert_eq!(*r.docs()[2 as usize].main().inst_sub().expect("error reading").foo(), 66); +} diff --git a/spec/rust/tests/test_default_endian_expr_is_le.rs b/spec/rust/tests/test_default_endian_expr_is_le.rs new file mode 100644 index 000000000..e7eaf39fb --- /dev/null +++ b/spec/rust/tests/test_default_endian_expr_is_le.rs @@ -0,0 +1,37 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::default_endian_expr_is_le::*; + +#[test] +fn test_default_endian_expr_is_le() { + let bytes = fs::read("../../src/endian_expr.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DefaultEndianExprIsLe::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]); + assert_eq!(*r.docs()[0 as usize].main().some_int(), 66); + assert_eq!(*r.docs()[0 as usize].main().some_int_be(), 66); + assert_eq!(*r.docs()[0 as usize].main().some_int_le(), 66); + assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]); + assert_eq!(*r.docs()[1 as usize].main().some_int(), 66); + assert_eq!(*r.docs()[1 as usize].main().some_int_be(), 66); + assert_eq!(*r.docs()[1 as usize].main().some_int_le(), 66); + assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]); + assert_eq!(*r.docs()[2 as usize].main().some_int(), 66); + assert_eq!(*r.docs()[2 as usize].main().some_int_be(), 66); + assert_eq!(*r.docs()[2 as usize].main().some_int_le(), 66); +} diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs new file mode 100644 index 000000000..8db211865 --- /dev/null +++ b/spec/rust/tests/test_default_endian_mod.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::default_endian_mod::*; + +#[test] +fn test_default_endian_mod() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DefaultEndianMod::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.main().one(), 1262698832); + assert_eq!(*r.main().nest().two(), -52947); + assert_eq!(*r.main().nest_be().two(), 1346454347); +} diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs new file mode 100644 index 000000000..a7d3d78b4 --- /dev/null +++ b/spec/rust/tests/test_docstrings.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::docstrings::*; + +#[test] +fn test_docstrings() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Docstrings::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs new file mode 100644 index 000000000..af461dd81 --- /dev/null +++ b/spec/rust/tests/test_docstrings_docref.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::docstrings_docref::*; + +#[test] +fn test_docstrings_docref() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DocstringsDocref::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_docstrings_docref_multi.rs b/spec/rust/tests/test_docstrings_docref_multi.rs new file mode 100644 index 000000000..2767da3f5 --- /dev/null +++ b/spec/rust/tests/test_docstrings_docref_multi.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::docstrings_docref_multi::*; + +#[test] +fn test_docstrings_docref_multi() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = DocstringsDocrefMulti::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs new file mode 100644 index 000000000..06cbcd4f3 --- /dev/null +++ b/spec/rust/tests/test_enum_0.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_0::*; + +#[test] +fn test_enum_0() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Enum0::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), Enum0_Animal::Cat); + assert_eq!(*r.pet_2(), Enum0_Animal::Chicken); +} diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs new file mode 100644 index 000000000..01fbd78a2 --- /dev/null +++ b/spec/rust/tests/test_enum_1.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_1::*; + +#[test] +fn test_enum_1() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Enum1::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.main().submain().pet_1(), Enum1_MainObj_Animal::Cat); + assert_eq!(*r.main().submain().pet_2(), Enum1_MainObj_Animal::Chicken); +} diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs new file mode 100644 index 000000000..3e77f5212 --- /dev/null +++ b/spec/rust/tests/test_enum_deep.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_deep::*; + +#[test] +fn test_enum_deep() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumDeep::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), EnumDeep_Container1_Animal::Cat); + assert_eq!(*r.pet_2(), EnumDeep_Container1_Container2_Animal::Hare); +} diff --git a/spec/rust/tests/test_enum_deep_literals.rs b/spec/rust/tests/test_enum_deep_literals.rs new file mode 100644 index 000000000..a90b9c5d3 --- /dev/null +++ b/spec/rust/tests/test_enum_deep_literals.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_deep_literals::*; + +#[test] +fn test_enum_deep_literals() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumDeepLiterals::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.is_pet_1_ok().expect("error reading"), true); + assert_eq!(*r.is_pet_2_ok().expect("error reading"), true); +} diff --git a/spec/rust/tests/test_enum_fancy.rs b/spec/rust/tests/test_enum_fancy.rs new file mode 100644 index 000000000..5296a3147 --- /dev/null +++ b/spec/rust/tests/test_enum_fancy.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_fancy::*; + +#[test] +fn test_enum_fancy() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumFancy::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), EnumFancy_Animal::Cat); + assert_eq!(*r.pet_2(), EnumFancy_Animal::Chicken); +} diff --git a/spec/rust/tests/test_enum_for_unknown_id.rs b/spec/rust/tests/test_enum_for_unknown_id.rs new file mode 100644 index 000000000..2c4dd2411 --- /dev/null +++ b/spec/rust/tests/test_enum_for_unknown_id.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_for_unknown_id::*; + +#[test] +fn test_enum_for_unknown_id() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumForUnknownId::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + let n : i64 = (&*r.one()).into(); + assert_eq!(n, 80); +} diff --git a/spec/rust/tests/test_enum_if.rs b/spec/rust/tests/test_enum_if.rs new file mode 100644 index 000000000..8aee100a7 --- /dev/null +++ b/spec/rust/tests/test_enum_if.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_if::*; + +#[test] +fn test_enum_if() { + let bytes = fs::read("../../src/if_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumIf::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.op1().opcode(), EnumIf_Opcodes::AString); + assert_eq!(*r.op1().arg_str().str(), "foo"); + assert_eq!(*r.op2().opcode(), EnumIf_Opcodes::ATuple); + assert_eq!(*r.op2().arg_tuple().num1(), 66); + assert_eq!(*r.op2().arg_tuple().num2(), 67); + assert_eq!(*r.op3().opcode(), EnumIf_Opcodes::AString); + assert_eq!(*r.op3().arg_str().str(), "bar"); +} diff --git a/spec/rust/tests/test_enum_import.rs b/spec/rust/tests/test_enum_import.rs new file mode 100644 index 000000000..825b9225b --- /dev/null +++ b/spec/rust/tests/test_enum_import.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_import::*; +use formats::enum_0::*; +use formats::enum_deep::*; + +#[test] +fn test_enum_import() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumImport::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), Enum0_Animal::Cat); + assert_eq!(*r.pet_2(), EnumDeep_Container1_Container2_Animal::Hare); +} diff --git a/spec/rust/tests/test_enum_int_range_s.rs b/spec/rust/tests/test_enum_int_range_s.rs new file mode 100644 index 000000000..438ab69ce --- /dev/null +++ b/spec/rust/tests/test_enum_int_range_s.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_int_range_s::*; + +#[test] +fn test_enum_int_range_s() { + let bytes = fs::read("../../src/enum_int_range_s.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumIntRangeS::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.f1(), EnumIntRangeS_Constants::IntMin); + assert_eq!(*r.f2(), EnumIntRangeS_Constants::Zero); + assert_eq!(*r.f3(), EnumIntRangeS_Constants::IntMax); +} diff --git a/spec/rust/tests/test_enum_int_range_u.rs b/spec/rust/tests/test_enum_int_range_u.rs new file mode 100644 index 000000000..99a40a48d --- /dev/null +++ b/spec/rust/tests/test_enum_int_range_u.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_int_range_u::*; + +#[test] +fn test_enum_int_range_u() { + let bytes = fs::read("../../src/enum_int_range_u.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumIntRangeU::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.f1(), EnumIntRangeU_Constants::Zero); + assert_eq!(*r.f2(), EnumIntRangeU_Constants::IntMax); +} diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs new file mode 100644 index 000000000..b791a7b1b --- /dev/null +++ b/spec/rust/tests/test_enum_invalid.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_invalid::*; + +#[test] +fn test_enum_invalid() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumInvalid::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); + let n : i64 = (&*r.pet_2()).into(); + assert_eq!(n, 111); +} diff --git a/spec/rust/tests/test_enum_long_range_s.rs b/spec/rust/tests/test_enum_long_range_s.rs new file mode 100644 index 000000000..824d3bd51 --- /dev/null +++ b/spec/rust/tests/test_enum_long_range_s.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_long_range_s::*; + +#[test] +fn test_enum_long_range_s() { + let bytes = fs::read("../../src/enum_long_range_s.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumLongRangeS::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.f1(), EnumLongRangeS_Constants::LongMin); + assert_eq!(*r.f2(), EnumLongRangeS_Constants::IntBelowMin); + assert_eq!(*r.f3(), EnumLongRangeS_Constants::IntMin); + assert_eq!(*r.f4(), EnumLongRangeS_Constants::Zero); + assert_eq!(*r.f5(), EnumLongRangeS_Constants::IntMax); + assert_eq!(*r.f6(), EnumLongRangeS_Constants::IntOverMax); + assert_eq!(*r.f7(), EnumLongRangeS_Constants::LongMax); +} diff --git a/spec/rust/tests/test_enum_long_range_u.rs b/spec/rust/tests/test_enum_long_range_u.rs new file mode 100644 index 000000000..9ffa9a978 --- /dev/null +++ b/spec/rust/tests/test_enum_long_range_u.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_long_range_u::*; + +#[test] +fn test_enum_long_range_u() { + let bytes = fs::read("../../src/enum_long_range_u.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumLongRangeU::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.f1(), EnumLongRangeU_Constants::Zero); + assert_eq!(*r.f2(), EnumLongRangeU_Constants::IntMax); + assert_eq!(*r.f3(), EnumLongRangeU_Constants::IntOverMax); + assert_eq!(*r.f4(), EnumLongRangeU_Constants::LongMax); +} diff --git a/spec/rust/tests/test_enum_negative.rs b/spec/rust/tests/test_enum_negative.rs new file mode 100644 index 000000000..d22658c3c --- /dev/null +++ b/spec/rust/tests/test_enum_negative.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_negative::*; + +#[test] +fn test_enum_negative() { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumNegative::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.f1(), EnumNegative_Constants::NegativeOne); + assert_eq!(*r.f2(), EnumNegative_Constants::PositiveOne); +} diff --git a/spec/rust/tests/test_enum_of_value_inst.rs b/spec/rust/tests/test_enum_of_value_inst.rs new file mode 100644 index 000000000..25e98eb65 --- /dev/null +++ b/spec/rust/tests/test_enum_of_value_inst.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_of_value_inst::*; + +#[test] +fn test_enum_of_value_inst() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumOfValueInst::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), EnumOfValueInst_Animal::Cat); + assert_eq!(*r.pet_2(), EnumOfValueInst_Animal::Chicken); + assert_eq!(*r.pet_3().expect("error reading"), EnumOfValueInst_Animal::Dog); + assert_eq!(*r.pet_4().expect("error reading"), EnumOfValueInst_Animal::Dog); +} diff --git a/spec/rust/tests/test_enum_to_i.rs b/spec/rust/tests/test_enum_to_i.rs new file mode 100644 index 000000000..cb2239090 --- /dev/null +++ b/spec/rust/tests/test_enum_to_i.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_to_i::*; + +#[test] +fn test_enum_to_i() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumToI::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), EnumToI_Animal::Cat); + assert_eq!(*r.pet_2(), EnumToI_Animal::Chicken); + assert_eq!(*r.pet_1_i().expect("error reading"), 7); + assert_eq!(*r.pet_1_mod().expect("error reading"), 32775); + assert_eq!(*r.one_lt_two().expect("error reading"), true); + assert_eq!(*r.pet_1_eq_int().expect("error reading"), true); + assert_eq!(*r.pet_2_eq_int().expect("error reading"), false); +} diff --git a/spec/rust/tests/test_enum_to_i_class_border_1.rs b/spec/rust/tests/test_enum_to_i_class_border_1.rs new file mode 100644 index 000000000..cab37ab4e --- /dev/null +++ b/spec/rust/tests/test_enum_to_i_class_border_1.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::enum_to_i_class_border_1::*; +use formats::enum_to_i_class_border_2::*; + +#[test] +fn test_enum_to_i_class_border_1() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EnumToIClassBorder1::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.pet_1(), EnumToIClassBorder1_Animal::Cat); + assert_eq!(*r.pet_2(), EnumToIClassBorder1_Animal::Chicken); + assert_eq!(*r.checker().expect("error reading").is_dog().expect("error reading"), true); +} diff --git a/spec/rust/tests/test_eof_exception_bytes.rs b/spec/rust/tests/test_eof_exception_bytes.rs new file mode 100644 index 000000000..239542414 --- /dev/null +++ b/spec/rust/tests/test_eof_exception_bytes.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::eof_exception_bytes::*; + +#[test] +fn test_eof_exception_bytes() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EofExceptionBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: EndOfStreamError", err); + } else { + panic!("no expected exception: EndOfStreamError"); + } +} diff --git a/spec/rust/tests/test_eof_exception_u4.rs b/spec/rust/tests/test_eof_exception_u4.rs new file mode 100644 index 000000000..9f8e1befd --- /dev/null +++ b/spec/rust/tests/test_eof_exception_u4.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::eof_exception_u4::*; + +#[test] +fn test_eof_exception_u4() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EofExceptionU4::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: EndOfStreamError", err); + } else { + panic!("no expected exception: EndOfStreamError"); + } +} diff --git a/spec/rust/tests/test_eos_exception_bytes.rs b/spec/rust/tests/test_eos_exception_bytes.rs new file mode 100644 index 000000000..4673a4424 --- /dev/null +++ b/spec/rust/tests/test_eos_exception_bytes.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::eos_exception_bytes::*; + +#[test] +fn test_eos_exception_bytes() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EosExceptionBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: EndOfStreamError", err); + } else { + panic!("no expected exception: EndOfStreamError"); + } +} diff --git a/spec/rust/tests/test_eos_exception_u4.rs b/spec/rust/tests/test_eos_exception_u4.rs new file mode 100644 index 000000000..8d1b543cf --- /dev/null +++ b/spec/rust/tests/test_eos_exception_u4.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::eos_exception_u4::*; + +#[test] +fn test_eos_exception_u4() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EosExceptionU4::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: EndOfStreamError", err); + } else { + panic!("no expected exception: EndOfStreamError"); + } +} diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs new file mode 100644 index 000000000..6b6c740f3 --- /dev/null +++ b/spec/rust/tests/test_expr_0.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_0::*; + +#[test] +fn test_expr_0() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Expr0::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.must_be_f7().expect("error reading"), 247); + assert_eq!(*r.must_be_abc123().expect("error reading"), "abc123"); +} diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs new file mode 100644 index 000000000..ed60bd31e --- /dev/null +++ b/spec/rust/tests/test_expr_1.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_1::*; + +#[test] +fn test_expr_1() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Expr1::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.len_of_1(), 10); + assert_eq!(*r.len_of_1_mod().expect("error reading"), 8); + assert_eq!(*r.str1(), "Some ASC"); + assert_eq!(*r.str1_len().expect("error reading"), 8); +} diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs new file mode 100644 index 000000000..40905743e --- /dev/null +++ b/spec/rust/tests/test_expr_2.rs @@ -0,0 +1,42 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_2::*; + +#[test] +fn test_expr_2() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Expr2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str1().len_orig(), 10); + assert_eq!(*r.str1().len_mod().expect("error reading"), 7); + assert_eq!(*r.str1().str(), "Some AS"); + assert_eq!(*r.str1_len().expect("error reading"), 7); + assert_eq!(*r.str1_len_mod().expect("error reading"), 7); + assert_eq!(*r.str1_byte1().expect("error reading"), 73); + assert_eq!(*r.str1_avg().expect("error reading"), 73); + assert_eq!(*r.str1_char5().expect("error reading"), "e"); + assert_eq!(*r.str1_tuple5().expect("error reading").byte0(), 101); + assert_eq!(*r.str1_tuple5().expect("error reading").byte0(), 101); + assert_eq!(*r.str1_tuple5().expect("error reading").byte1(), 32); + assert_eq!(*r.str1_tuple5().expect("error reading").byte2(), 65); + assert_eq!(*r.str1_tuple5().expect("error reading").avg().expect("error reading"), 48); + assert_eq!(*r.str2_tuple5().expect("error reading").byte0(), 101); + assert_eq!(*r.str2_tuple5().expect("error reading").byte1(), 32); + assert_eq!(*r.str2_tuple5().expect("error reading").byte2(), 65); + assert_eq!(*r.str2_tuple5().expect("error reading").avg().expect("error reading"), 48); +} diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs new file mode 100644 index 000000000..c4471a04d --- /dev/null +++ b/spec/rust/tests/test_expr_3.rs @@ -0,0 +1,37 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_3::*; + +#[test] +fn test_expr_3() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Expr3::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), 80); + assert_eq!(*r.two(), "ACK"); + assert_eq!(*r.three().expect("error reading"), "@ACK"); + assert_eq!(*r.four().expect("error reading"), "_ACK_"); + assert_eq!(*r.is_str_eq().expect("error reading"), true); + assert_eq!(*r.is_str_ne().expect("error reading"), false); + assert_eq!(*r.is_str_lt().expect("error reading"), true); + assert_eq!(*r.is_str_gt().expect("error reading"), false); + assert_eq!(*r.is_str_le().expect("error reading"), true); + assert_eq!(*r.is_str_ge().expect("error reading"), false); + assert_eq!(*r.is_str_lt2().expect("error reading"), true); + assert_eq!(*r.test_not().expect("error reading"), true); +} diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs new file mode 100644 index 000000000..054002a38 --- /dev/null +++ b/spec/rust/tests/test_expr_array.rs @@ -0,0 +1,40 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_array::*; + +#[test] +fn test_expr_array() { + let bytes = fs::read("../../src/expr_array.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprArray::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.aint_size().expect("error reading"), 4); + assert_eq!(*r.aint_first().expect("error reading"), 7657765); + assert_eq!(*r.aint_last().expect("error reading"), 16272640); + assert_eq!(*r.aint_min().expect("error reading"), 49185); + assert_eq!(*r.aint_max().expect("error reading"), 1123362332); + assert_eq!(*r.afloat_size().expect("error reading"), 3); + assert_eq!(*r.afloat_first().expect("error reading"), -2.6839530254859364E-121); + assert_eq!(*r.afloat_last().expect("error reading"), -1.1103359815095273E-175); + assert_eq!(*r.afloat_min().expect("error reading"), -8.754689149998834E+288); + assert_eq!(*r.afloat_max().expect("error reading"), -1.1103359815095273E-175); + assert_eq!(*r.astr_size().expect("error reading"), 3); + assert_eq!(*r.astr_first().expect("error reading"), "foo"); + assert_eq!(*r.astr_last().expect("error reading"), "baz"); + assert_eq!(*r.astr_min().expect("error reading"), "bar"); + assert_eq!(*r.astr_max().expect("error reading"), "foo"); +} diff --git a/spec/rust/tests/test_expr_bits.rs b/spec/rust/tests/test_expr_bits.rs new file mode 100644 index 000000000..23bdbea0c --- /dev/null +++ b/spec/rust/tests/test_expr_bits.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_bits::*; + +#[test] +fn test_expr_bits() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprBits::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a(), 2); + assert_eq!(*r.enum_seq(), ExprBits_Items::Foo); + assert_eq!(*r.byte_size(), vec![0x66u8, 0x6fu8]); + assert_eq!(r.repeat_expr().len(), 2); + assert_eq!(r.repeat_expr()[0 as usize], 111); + assert_eq!(r.repeat_expr()[1 as usize], 98); + assert_eq!(r.switch_on_type(), 97); + assert_eq!(*r.switch_on_endian().foo(), 29184); + assert_eq!(*r.enum_inst().expect("error reading"), ExprBits_Items::Bar); + assert_eq!(*r.inst_pos().expect("error reading"), 111); +} diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs new file mode 100644 index 000000000..b777679cb --- /dev/null +++ b/spec/rust/tests/test_expr_bytes_cmp.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_bytes_cmp::*; + +#[test] +fn test_expr_bytes_cmp() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprBytesCmp::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), vec![0x50u8]); + assert_eq!(*r.two(), vec![0x41u8, 0x43u8, 0x4bu8]); + assert_eq!(*r.is_eq().expect("error reading"), true); + assert_eq!(*r.is_ne().expect("error reading"), false); + assert_eq!(*r.is_lt().expect("error reading"), true); + assert_eq!(*r.is_gt().expect("error reading"), false); + assert_eq!(*r.is_le().expect("error reading"), true); + assert_eq!(*r.is_ge().expect("error reading"), false); + assert_eq!(*r.is_lt2().expect("error reading"), false); + assert_eq!(*r.is_gt2().expect("error reading"), true); +} diff --git a/spec/rust/tests/test_expr_bytes_non_literal.rs b/spec/rust/tests/test_expr_bytes_non_literal.rs new file mode 100644 index 000000000..5c5a0ac4d --- /dev/null +++ b/spec/rust/tests/test_expr_bytes_non_literal.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_bytes_non_literal::*; + +#[test] +fn test_expr_bytes_non_literal() { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprBytesNonLiteral::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.calc_bytes().expect("error reading").len(), 2); + assert_eq!(r.calc_bytes().expect("error reading")[0 as usize], 255); + assert_eq!(r.calc_bytes().expect("error reading")[1 as usize], 1); +} diff --git a/spec/rust/tests/test_expr_bytes_ops.rs b/spec/rust/tests/test_expr_bytes_ops.rs new file mode 100644 index 000000000..f62ec1230 --- /dev/null +++ b/spec/rust/tests/test_expr_bytes_ops.rs @@ -0,0 +1,41 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_bytes_ops::*; + +#[test] +fn test_expr_bytes_ops() { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprBytesOps::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one_size().expect("error reading"), 3); + assert_eq!(*r.one_first().expect("error reading"), 1); + assert_eq!(*r.one_mid().expect("error reading"), 66); + assert_eq!(*r.one_last().expect("error reading"), 255); + assert_eq!(r.one_last().expect("error reading").to_string(), "255"); + assert_eq!(*r.one_min().expect("error reading"), 1); + assert_eq!(*r.one_max().expect("error reading"), 255); + assert_eq!(r.one_max().expect("error reading").to_string(), "255"); + assert_eq!(*r.two_size().expect("error reading"), 3); + assert_eq!(*r.two_first().expect("error reading"), 65); + assert_eq!(*r.two_mid().expect("error reading"), 255); + assert_eq!(r.two_mid().expect("error reading").to_string(), "255"); + assert_eq!(*r.two_last().expect("error reading"), 75); + assert_eq!(*r.two_min().expect("error reading"), 65); + assert_eq!(*r.two_max().expect("error reading"), 255); + assert_eq!(r.two_max().expect("error reading").to_string(), "255"); +} diff --git a/spec/rust/tests/test_expr_calc_array_ops.rs b/spec/rust/tests/test_expr_calc_array_ops.rs new file mode 100644 index 000000000..92c6ebb6a --- /dev/null +++ b/spec/rust/tests/test_expr_calc_array_ops.rs @@ -0,0 +1,43 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_calc_array_ops::*; + +#[test] +fn test_expr_calc_array_ops() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprCalcArrayOps::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.int_array_size().expect("error reading"), 7); + assert_eq!(*r.int_array_first().expect("error reading"), 10); + assert_eq!(*r.int_array_mid().expect("error reading"), 25); + assert_eq!(*r.int_array_last().expect("error reading"), 1000); + assert_eq!(*r.int_array_min().expect("error reading"), 10); + assert_eq!(*r.int_array_max().expect("error reading"), 1000); + assert_eq!(*r.double_array_size().expect("error reading"), 5); + assert_eq!(*r.double_array_first().expect("error reading"), 10.0); + assert_eq!(*r.double_array_mid().expect("error reading"), 25.0); + assert_eq!(*r.double_array_last().expect("error reading"), 3.14159); + assert_eq!(*r.double_array_min().expect("error reading"), 3.14159); + assert_eq!(*r.double_array_max().expect("error reading"), 100.0); + assert_eq!(*r.str_array_size().expect("error reading"), 4); + assert_eq!(*r.str_array_first().expect("error reading"), "un"); + assert_eq!(*r.str_array_mid().expect("error reading"), "deux"); + assert_eq!(*r.str_array_last().expect("error reading"), "quatre"); + assert_eq!(*r.str_array_min().expect("error reading"), "deux"); + assert_eq!(*r.str_array_max().expect("error reading"), "un"); +} diff --git a/spec/rust/tests/test_expr_enum.rs b/spec/rust/tests/test_expr_enum.rs new file mode 100644 index 000000000..c8310b137 --- /dev/null +++ b/spec/rust/tests/test_expr_enum.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_enum::*; + +#[test] +fn test_expr_enum() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprEnum::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.const_dog().expect("error reading"), ExprEnum_Animal::Dog); + assert_eq!(*r.derived_boom().expect("error reading"), ExprEnum_Animal::Boom); + assert_eq!(*r.derived_dog().expect("error reading"), ExprEnum_Animal::Dog); +} diff --git a/spec/rust/tests/test_expr_if_int_ops.rs b/spec/rust/tests/test_expr_if_int_ops.rs new file mode 100644 index 000000000..7a263285e --- /dev/null +++ b/spec/rust/tests/test_expr_if_int_ops.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_if_int_ops::*; + +#[test] +fn test_expr_if_int_ops() { + let bytes = fs::read("../../src/process_coerce_switch.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprIfIntOps::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.is_eq_prim().expect("error reading"), true); + assert_eq!(*r.is_eq_boxed().expect("error reading"), true); +} diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index 0d4b9c482..7f5c048f2 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -5,7 +5,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::expr_int_div::*; diff --git a/spec/rust/tests/test_expr_io_eof.rs b/spec/rust/tests/test_expr_io_eof.rs new file mode 100644 index 000000000..5f61befa0 --- /dev/null +++ b/spec/rust/tests/test_expr_io_eof.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_io_eof::*; + +#[test] +fn test_expr_io_eof() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprIoEof::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.substream1().one(), 1262698832); + assert_eq!(*r.substream1().two(), 0); + assert_eq!(*r.substream2().one(), 4294914349); + assert_eq!(*r.substream2().two(), 1262698832); +} diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs new file mode 100644 index 000000000..0a800b047 --- /dev/null +++ b/spec/rust/tests/test_expr_io_pos.rs @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_io_pos::*; + +#[test] +fn test_expr_io_pos() { + let bytes = fs::read("../../src/expr_io_pos.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprIoPos::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.substream1().my_str(), "CURIOSITY"); + assert_eq!(*r.substream1().body(), vec![0x11u8, 0x22u8, 0x33u8, 0x44u8]); + assert_eq!(*r.substream1().number(), 66); + assert_eq!(*r.substream2().my_str(), "KILLED"); + assert_eq!(*r.substream2().body(), vec![0x61u8, 0x20u8, 0x63u8, 0x61u8, 0x74u8]); + assert_eq!(*r.substream2().number(), 103); +} diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs new file mode 100644 index 000000000..6daa02c33 --- /dev/null +++ b/spec/rust/tests/test_expr_mod.rs @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_mod::*; + +#[test] +fn test_expr_mod() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprMod::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.int_u(), 1262698832); + assert_eq!(*r.int_s(), -52947); + assert_eq!(*r.mod_pos_const().expect("error reading"), 9); + assert_eq!(*r.mod_neg_const().expect("error reading"), 4); + assert_eq!(*r.mod_pos_seq().expect("error reading"), 5); + assert_eq!(*r.mod_neg_seq().expect("error reading"), 2); +} diff --git a/spec/rust/tests/test_expr_ops_parens.rs b/spec/rust/tests/test_expr_ops_parens.rs new file mode 100644 index 000000000..6c8829ee6 --- /dev/null +++ b/spec/rust/tests/test_expr_ops_parens.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_ops_parens::*; + +#[test] +fn test_expr_ops_parens() { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprOpsParens::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.i_sum_to_str().expect("error reading"), "29"); + assert_eq!(*r.f_sum_to_int().expect("error reading"), 9); + assert_eq!(*r.str_concat_len().expect("error reading"), 10); + assert_eq!(*r.str_concat_rev().expect("error reading"), "9876543210"); + assert_eq!(*r.str_concat_substr_2_to_7().expect("error reading"), "23456"); + assert_eq!(*r.str_concat_to_i().expect("error reading"), 123456789); + assert_eq!(*r.bool_eq().expect("error reading"), 0); + assert_eq!(*r.bool_and().expect("error reading"), 0); + assert_eq!(*r.bool_or().expect("error reading"), 1); +} diff --git a/spec/rust/tests/test_expr_sizeof_type_0.rs b/spec/rust/tests/test_expr_sizeof_type_0.rs new file mode 100644 index 000000000..0d8952ee8 --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_type_0.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_sizeof_type_0::*; + +#[test] +fn test_expr_sizeof_type_0() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprSizeofType0::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.sizeof_block().expect("error reading"), (((1 + 4) as i32) + (2 as i32))); +} diff --git a/spec/rust/tests/test_expr_sizeof_type_1.rs b/spec/rust/tests/test_expr_sizeof_type_1.rs new file mode 100644 index 000000000..6d36d5ce4 --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_type_1.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_sizeof_type_1::*; + +#[test] +fn test_expr_sizeof_type_1() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprSizeofType1::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.sizeof_block().expect("error reading"), (((((1 + 4) as i32) + (2 as i32)) as i32) + (4 as i32))); + assert_eq!(*r.sizeof_subblock().expect("error reading"), 4); +} diff --git a/spec/rust/tests/test_expr_sizeof_value_0.rs b/spec/rust/tests/test_expr_sizeof_value_0.rs new file mode 100644 index 000000000..cf35930a4 --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_value_0.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_sizeof_value_0::*; + +#[test] +fn test_expr_sizeof_value_0() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprSizeofValue0::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.self_sizeof().expect("error reading"), (((((1 + 4) as i32) + (2 as i32)) as i32) + (2 as i32))); + assert_eq!(*r.sizeof_block().expect("error reading"), (((1 + 4) as i32) + (2 as i32))); + assert_eq!(*r.sizeof_block_a().expect("error reading"), 1); + assert_eq!(*r.sizeof_block_b().expect("error reading"), 4); + assert_eq!(*r.sizeof_block_c().expect("error reading"), 2); +} diff --git a/spec/rust/tests/test_expr_sizeof_value_sized.rs b/spec/rust/tests/test_expr_sizeof_value_sized.rs new file mode 100644 index 000000000..c765521de --- /dev/null +++ b/spec/rust/tests/test_expr_sizeof_value_sized.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_sizeof_value_sized::*; + +#[test] +fn test_expr_sizeof_value_sized() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprSizeofValueSized::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.self_sizeof().expect("error reading"), (12 + 2)); + assert_eq!(*r.sizeof_block().expect("error reading"), 12); + assert_eq!(*r.sizeof_block_a().expect("error reading"), 1); + assert_eq!(*r.sizeof_block_b().expect("error reading"), 4); + assert_eq!(*r.sizeof_block_c().expect("error reading"), 2); +} diff --git a/spec/rust/tests/test_expr_str_encodings.rs b/spec/rust/tests/test_expr_str_encodings.rs new file mode 100644 index 000000000..f86784c73 --- /dev/null +++ b/spec/rust/tests/test_expr_str_encodings.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_str_encodings::*; + +#[test] +fn test_expr_str_encodings() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprStrEncodings::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str1_eq().expect("error reading"), true); + assert_eq!(*r.str2_eq().expect("error reading"), true); + assert_eq!(*r.str3_eq().expect("error reading"), true); + assert_eq!(*r.str3_eq_str2().expect("error reading"), true); + assert_eq!(*r.str4_eq().expect("error reading"), true); + assert_eq!(*r.str4_gt_str_calc().expect("error reading"), true); + assert_eq!(*r.str4_gt_str_from_bytes().expect("error reading"), true); +} diff --git a/spec/rust/tests/test_expr_str_ops.rs b/spec/rust/tests/test_expr_str_ops.rs new file mode 100644 index 000000000..6bf8727c1 --- /dev/null +++ b/spec/rust/tests/test_expr_str_ops.rs @@ -0,0 +1,42 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::expr_str_ops::*; + +#[test] +fn test_expr_str_ops() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ExprStrOps::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), "foo|b"); + assert_eq!(*r.one_len().expect("error reading"), 5); + assert_eq!(*r.one_rev().expect("error reading"), "b|oof"); + assert_eq!(*r.one_substr_0_to_3().expect("error reading"), "foo"); + assert_eq!(*r.one_substr_2_to_5().expect("error reading"), "o|b"); + assert_eq!(*r.one_substr_3_to_3().expect("error reading"), ""); + assert_eq!(*r.two().expect("error reading"), "0123456789"); + assert_eq!(*r.two_len().expect("error reading"), 10); + assert_eq!(*r.two_rev().expect("error reading"), "9876543210"); + assert_eq!(*r.two_substr_0_to_7().expect("error reading"), "0123456"); + assert_eq!(*r.two_substr_4_to_10().expect("error reading"), "456789"); + assert_eq!(*r.two_substr_0_to_10().expect("error reading"), "0123456789"); + assert_eq!(*r.to_i_attr().expect("error reading"), 9173); + assert_eq!(*r.to_i_r10().expect("error reading"), -72); + assert_eq!(*r.to_i_r2().expect("error reading"), 86); + assert_eq!(*r.to_i_r8().expect("error reading"), 465); + assert_eq!(*r.to_i_r16().expect("error reading"), 18383); +} diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs new file mode 100644 index 000000000..35570ad47 --- /dev/null +++ b/spec/rust/tests/test_fixed_contents.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::fixed_contents::*; + +#[test] +fn test_fixed_contents() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = FixedContents::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs new file mode 100644 index 000000000..716e12a1c --- /dev/null +++ b/spec/rust/tests/test_fixed_struct.rs @@ -0,0 +1,45 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::fixed_struct::*; + +#[test] +fn test_fixed_struct() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = FixedStruct::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.hdr().expect("error reading").uint8(), 255); + assert_eq!(*r.hdr().expect("error reading").uint16(), 65535); + assert_eq!(*r.hdr().expect("error reading").uint32(), 4294967295); + assert_eq!(*r.hdr().expect("error reading").uint64(), 18446744073709551615); + assert_eq!(*r.hdr().expect("error reading").sint8(), -1); + assert_eq!(*r.hdr().expect("error reading").sint16(), -1); + assert_eq!(*r.hdr().expect("error reading").sint32(), -1); + assert_eq!(*r.hdr().expect("error reading").sint64(), -1); + assert_eq!(*r.hdr().expect("error reading").uint16le(), 66); + assert_eq!(*r.hdr().expect("error reading").uint32le(), 66); + assert_eq!(*r.hdr().expect("error reading").uint64le(), 66); + assert_eq!(*r.hdr().expect("error reading").sint16le(), -66); + assert_eq!(*r.hdr().expect("error reading").sint32le(), -66); + assert_eq!(*r.hdr().expect("error reading").sint64le(), -66); + assert_eq!(*r.hdr().expect("error reading").uint16be(), 66); + assert_eq!(*r.hdr().expect("error reading").uint32be(), 66); + assert_eq!(*r.hdr().expect("error reading").uint64be(), 66); + assert_eq!(*r.hdr().expect("error reading").sint16be(), -66); + assert_eq!(*r.hdr().expect("error reading").sint32be(), -66); + assert_eq!(*r.hdr().expect("error reading").sint64be(), -66); +} diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs new file mode 100644 index 000000000..95b82bd6c --- /dev/null +++ b/spec/rust/tests/test_float_to_i.rs @@ -0,0 +1,33 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::float_to_i::*; + +#[test] +fn test_float_to_i() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = FloatToI::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.single_value(), 0.5); + assert_eq!(*r.double_value(), 0.25); + assert_eq!(*r.single_i().expect("error reading"), 0); + assert_eq!(*r.double_i().expect("error reading"), 0); + assert_eq!(*r.float1_i().expect("error reading"), 1); + assert_eq!(*r.float2_i().expect("error reading"), 1); + assert_eq!(*r.float3_i().expect("error reading"), 1); + assert_eq!(*r.float4_i().expect("error reading"), -2); +} diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs new file mode 100644 index 000000000..ff084a725 --- /dev/null +++ b/spec/rust/tests/test_floating_points.rs @@ -0,0 +1,33 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::floating_points::*; + +#[test] +fn test_floating_points() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = FloatingPoints::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.single_value(), (0.5 as f32)); + assert_eq!(*r.single_value_be(), (0.5 as f32)); + assert_eq!(*r.double_value(), 0.25); + assert_eq!(*r.double_value_be(), 0.25); + assert_eq!(*r.approximate_value(), 1.2345); + assert_eq!(*r.single_value_plus_int().expect("error reading"), 1.5); + assert_eq!(*r.single_value_plus_float().expect("error reading"), 1.0); + assert_eq!(*r.double_value_plus_float().expect("error reading"), 0.3); +} diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs new file mode 100644 index 000000000..c7aa6220a --- /dev/null +++ b/spec/rust/tests/test_hello_world.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::hello_world::*; + +#[test] +fn test_hello_world() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = HelloWorld::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), 80); +} diff --git a/spec/rust/tests/test_if_instances.rs b/spec/rust/tests/test_if_instances.rs new file mode 100644 index 000000000..04d889232 --- /dev/null +++ b/spec/rust/tests/test_if_instances.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::if_instances::*; + +#[test] +fn test_if_instances() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IfInstances::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.never_happens().expect("error reading"), 0); +} diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs new file mode 100644 index 000000000..0e78aa648 --- /dev/null +++ b/spec/rust/tests/test_if_struct.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::if_struct::*; + +#[test] +fn test_if_struct() { + let bytes = fs::read("../../src/if_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IfStruct::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.op1().opcode(), 83); + assert_eq!(*r.op1().arg_str().str(), "foo"); + assert_eq!(*r.op2().opcode(), 84); + assert_eq!(*r.op2().arg_tuple().num1(), 66); + assert_eq!(*r.op2().arg_tuple().num2(), 67); + assert_eq!(*r.op3().opcode(), 83); + assert_eq!(*r.op3().arg_str().str(), "bar"); +} diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs new file mode 100644 index 000000000..81957fe01 --- /dev/null +++ b/spec/rust/tests/test_if_values.rs @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::if_values::*; + +#[test] +fn test_if_values() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IfValues::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.codes()[0 as usize].opcode(), 80); + assert_eq!(*r.codes()[0 as usize].half_opcode().expect("error reading"), 40); + assert_eq!(*r.codes()[1 as usize].opcode(), 65); + assert_eq!(*r.codes()[1 as usize].half_opcode().expect("error reading"), 0); + assert_eq!(*r.codes()[2 as usize].opcode(), 67); + assert_eq!(*r.codes()[2 as usize].half_opcode().expect("error reading"), 0); +} diff --git a/spec/rust/tests/test_imports0.rs b/spec/rust/tests/test_imports0.rs new file mode 100644 index 000000000..6250ff12c --- /dev/null +++ b/spec/rust/tests/test_imports0.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::imports0::*; +use formats::hello_world::*; + +#[test] +fn test_imports0() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Imports0::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.two(), 80); + assert_eq!(*r.hw().one(), 65); + assert_eq!(*r.hw_one().expect("error reading"), 65); +} diff --git a/spec/rust/tests/test_imports_abs.rs b/spec/rust/tests/test_imports_abs.rs new file mode 100644 index 000000000..3f2a60665 --- /dev/null +++ b/spec/rust/tests/test_imports_abs.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::imports_abs::*; +use formats::vlq_base128_le::*; + +#[test] +fn test_imports_abs() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ImportsAbs::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.len().value().expect("error reading"), 80); + assert_eq!(r.body().len(), 80); +} diff --git a/spec/rust/tests/manual_imports_abs_abs.rs b/spec/rust/tests/test_imports_abs_abs.rs similarity index 92% rename from spec/rust/tests/manual_imports_abs_abs.rs rename to spec/rust/tests/test_imports_abs_abs.rs index 9f6d97819..c8278ebbc 100644 --- a/spec/rust/tests/manual_imports_abs_abs.rs +++ b/spec/rust/tests/test_imports_abs_abs.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::imports_abs_abs::*; diff --git a/spec/rust/tests/manual_imports_abs_rel.rs b/spec/rust/tests/test_imports_abs_rel.rs similarity index 92% rename from spec/rust/tests/manual_imports_abs_rel.rs rename to spec/rust/tests/test_imports_abs_rel.rs index d50866599..96008056d 100644 --- a/spec/rust/tests/manual_imports_abs_rel.rs +++ b/spec/rust/tests/test_imports_abs_rel.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::imports_abs_rel::*; diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index 199323ec9..95df4d275 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::imports_circular_a::*; #[test] diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs new file mode 100644 index 000000000..9c455ef66 --- /dev/null +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::imports_rel_1::*; +use formats::imported_1::*; +use formats::imported_2::*; + +#[test] +fn test_imports_rel_1() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ImportsRel1::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), 80); + assert_eq!(*r.two().one(), 65); + assert_eq!(*r.two().two().one(), 67); +} diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs new file mode 100644 index 000000000..0e7e60b75 --- /dev/null +++ b/spec/rust/tests/test_index_sizes.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::index_sizes::*; + +#[test] +fn test_index_sizes() { + let bytes = fs::read("../../src/index_sizes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IndexSizes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.qty(), 3); + assert_eq!(r.sizes()[0 as usize], 1); + assert_eq!(r.sizes()[1 as usize], 8); + assert_eq!(r.sizes()[2 as usize], 4); + assert_eq!(r.bufs()[0 as usize], "A"); + assert_eq!(r.bufs()[1 as usize], "BBBBBBBB"); + assert_eq!(r.bufs()[2 as usize], "CCCC"); +} diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs new file mode 100644 index 000000000..1ac5c578b --- /dev/null +++ b/spec/rust/tests/test_index_to_param_eos.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::index_to_param_eos::*; + +#[test] +fn test_index_to_param_eos() { + let bytes = fs::read("../../src/index_sizes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IndexToParamEos::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.qty(), 3); + assert_eq!(r.sizes()[0 as usize], 1); + assert_eq!(r.sizes()[1 as usize], 8); + assert_eq!(r.sizes()[2 as usize], 4); + assert_eq!(*r.blocks()[0 as usize].buf(), "A"); + assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB"); + assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC"); +} diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs new file mode 100644 index 000000000..ea9e4c098 --- /dev/null +++ b/spec/rust/tests/test_index_to_param_expr.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::index_to_param_expr::*; + +#[test] +fn test_index_to_param_expr() { + let bytes = fs::read("../../src/index_sizes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IndexToParamExpr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.qty(), 3); + assert_eq!(r.sizes()[0 as usize], 1); + assert_eq!(r.sizes()[1 as usize], 8); + assert_eq!(r.sizes()[2 as usize], 4); + assert_eq!(*r.blocks()[0 as usize].buf(), "A"); + assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB"); + assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC"); +} diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs new file mode 100644 index 000000000..a73ac96cd --- /dev/null +++ b/spec/rust/tests/test_index_to_param_until.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::index_to_param_until::*; + +#[test] +fn test_index_to_param_until() { + let bytes = fs::read("../../src/index_sizes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IndexToParamUntil::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.qty(), 3); + assert_eq!(r.sizes()[0 as usize], 1); + assert_eq!(r.sizes()[1 as usize], 8); + assert_eq!(r.sizes()[2 as usize], 4); + assert_eq!(*r.blocks()[0 as usize].buf(), "A"); + assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB"); + assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC"); +} diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs new file mode 100644 index 000000000..2c3dde723 --- /dev/null +++ b/spec/rust/tests/test_instance_io_user.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::instance_io_user::*; + +#[test] +fn test_instance_io_user() { + let bytes = fs::read("../../src/instance_io.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = InstanceIoUser::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.qty_entries(), 3); + assert_eq!(*r.entries()[0 as usize].name().expect("error reading"), "the"); + assert_eq!(*r.entries()[1 as usize].name().expect("error reading"), "rainy"); + assert_eq!(*r.entries()[2 as usize].name().expect("error reading"), "day it is"); +} diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs new file mode 100644 index 000000000..14d6e54d6 --- /dev/null +++ b/spec/rust/tests/test_instance_std.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::instance_std::*; + +#[test] +fn test_instance_std() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = InstanceStd::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.header().expect("error reading"), "Some "); +} diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs new file mode 100644 index 000000000..8274fe565 --- /dev/null +++ b/spec/rust/tests/test_instance_std_array.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::instance_std_array::*; + +#[test] +fn test_instance_std_array() { + let bytes = fs::read("../../src/instance_std_array.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = InstanceStdArray::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.ofs(), 16); + assert_eq!(*r.qty_entries(), 3); + assert_eq!(*r.entry_size(), 4); + assert_eq!(r.entries().expect("error reading").len(), 3); + assert_eq!(r.entries().expect("error reading")[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); + assert_eq!(r.entries().expect("error reading")[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); + assert_eq!(r.entries().expect("error reading")[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); +} diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs new file mode 100644 index 000000000..7c0f87f9e --- /dev/null +++ b/spec/rust/tests/test_instance_user_array.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::instance_user_array::*; + +#[test] +fn test_instance_user_array() { + let bytes = fs::read("../../src/instance_std_array.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = InstanceUserArray::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.ofs(), 16); + assert_eq!(*r.qty_entries(), 3); + assert_eq!(*r.entry_size(), 4); + assert_eq!(r.user_entries().expect("error reading").len(), 3); + assert_eq!(*r.user_entries().expect("error reading")[0 as usize].word1(), 4369); + assert_eq!(*r.user_entries().expect("error reading")[0 as usize].word2(), 4369); + assert_eq!(*r.user_entries().expect("error reading")[1 as usize].word1(), 8738); + assert_eq!(*r.user_entries().expect("error reading")[1 as usize].word2(), 8738); + assert_eq!(*r.user_entries().expect("error reading")[2 as usize].word1(), 13107); + assert_eq!(*r.user_entries().expect("error reading")[2 as usize].word2(), 13107); +} diff --git a/spec/rust/tests/test_integers.rs b/spec/rust/tests/test_integers.rs new file mode 100644 index 000000000..a58c95772 --- /dev/null +++ b/spec/rust/tests/test_integers.rs @@ -0,0 +1,45 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::integers::*; + +#[test] +fn test_integers() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = Integers::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.uint8(), 255); + assert_eq!(*r.uint16(), 65535); + assert_eq!(*r.uint32(), 4294967295); + assert_eq!(*r.uint64(), 18446744073709551615); + assert_eq!(*r.sint8(), -1); + assert_eq!(*r.sint16(), -1); + assert_eq!(*r.sint32(), -1); + assert_eq!(*r.sint64(), -1); + assert_eq!(*r.uint16le(), 66); + assert_eq!(*r.uint32le(), 66); + assert_eq!(*r.uint64le(), 66); + assert_eq!(*r.sint16le(), -66); + assert_eq!(*r.sint32le(), -66); + assert_eq!(*r.sint64le(), -66); + assert_eq!(*r.uint16be(), 66); + assert_eq!(*r.uint32be(), 66); + assert_eq!(*r.uint64be(), 66); + assert_eq!(*r.sint16be(), -66); + assert_eq!(*r.sint32be(), -66); + assert_eq!(*r.sint64be(), -66); +} diff --git a/spec/rust/tests/test_integers_double_overflow.rs b/spec/rust/tests/test_integers_double_overflow.rs new file mode 100644 index 000000000..4e59a742e --- /dev/null +++ b/spec/rust/tests/test_integers_double_overflow.rs @@ -0,0 +1,33 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::integers_double_overflow::*; + +#[test] +fn test_integers_double_overflow() { + let bytes = fs::read("../../src/integers_double_overflow.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IntegersDoubleOverflow::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.signed_safe_min_be(), -9007199254740991); + assert_eq!(*r.signed_safe_min_le(), -9007199254740991); + assert_eq!(*r.signed_safe_max_be(), 9007199254740991); + assert_eq!(*r.signed_safe_max_le(), 9007199254740991); + assert_eq!(r.signed_unsafe_neg_be().to_string(), "-9007199254740993"); + assert_eq!(r.signed_unsafe_neg_le().to_string(), "-9007199254740993"); + assert_eq!(r.signed_unsafe_pos_be().to_string(), "9007199254740993"); + assert_eq!(r.signed_unsafe_pos_be().to_string(), "9007199254740993"); +} diff --git a/spec/rust/tests/test_integers_min_max.rs b/spec/rust/tests/test_integers_min_max.rs new file mode 100644 index 000000000..e98206a32 --- /dev/null +++ b/spec/rust/tests/test_integers_min_max.rs @@ -0,0 +1,53 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::integers_min_max::*; + +#[test] +fn test_integers_min_max() { + let bytes = fs::read("../../src/integers_min_max.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IntegersMinMax::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.unsigned_min().u1(), 0); + assert_eq!(*r.unsigned_min().u2le(), 0); + assert_eq!(*r.unsigned_min().u4le(), 0); + assert_eq!(*r.unsigned_min().u8le(), 0); + assert_eq!(*r.unsigned_min().u2be(), 0); + assert_eq!(*r.unsigned_min().u4be(), 0); + assert_eq!(*r.unsigned_min().u8be(), 0); + assert_eq!(*r.unsigned_max().u1(), 255); + assert_eq!(*r.unsigned_max().u2le(), 65535); + assert_eq!(*r.unsigned_max().u4le(), 4294967295); + assert_eq!(*r.unsigned_max().u8le(), 18446744073709551615); + assert_eq!(*r.unsigned_max().u2be(), 65535); + assert_eq!(*r.unsigned_max().u4be(), 4294967295); + assert_eq!(*r.unsigned_max().u8be(), 18446744073709551615); + assert_eq!(*r.signed_min().s1(), -128); + assert_eq!(*r.signed_min().s2le(), -32768); + assert_eq!(*r.signed_min().s4le(), -2147483648); + assert_eq!(*r.signed_min().s8le(), -9223372036854775808); + assert_eq!(*r.signed_min().s2be(), -32768); + assert_eq!(*r.signed_min().s4be(), -2147483648); + assert_eq!(*r.signed_min().s8be(), -9223372036854775808); + assert_eq!(*r.signed_max().s1(), 127); + assert_eq!(*r.signed_max().s2le(), 32767); + assert_eq!(*r.signed_max().s4le(), 2147483647); + assert_eq!(*r.signed_max().s8le(), 9223372036854775807); + assert_eq!(*r.signed_max().s2be(), 32767); + assert_eq!(*r.signed_max().s4be(), 2147483647); + assert_eq!(*r.signed_max().s8be(), 9223372036854775807); +} diff --git a/spec/rust/tests/test_io_local_var.rs b/spec/rust/tests/test_io_local_var.rs new file mode 100644 index 000000000..6745ed738 --- /dev/null +++ b/spec/rust/tests/test_io_local_var.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::io_local_var::*; + +#[test] +fn test_io_local_var() { + let bytes = fs::read("../../src/full256.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = IoLocalVar::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.skip(), vec![0x0u8, 0x1u8, 0x2u8, 0x3u8, 0x4u8, 0x5u8, 0x6u8, 0x7u8, 0x8u8, 0x9u8, 0xau8, 0xbu8, 0xcu8, 0xdu8, 0xeu8, 0xfu8, 0x10u8, 0x11u8, 0x12u8, 0x13u8]); + assert_eq!(*r.followup(), 20); +} diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs new file mode 100644 index 000000000..9aa5e946f --- /dev/null +++ b/spec/rust/tests/test_js_signed_right_shift.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::js_signed_right_shift::*; + +#[test] +fn test_js_signed_right_shift() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = JsSignedRightShift::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.should_be_40000000().expect("error reading"), 1073741824); + assert_eq!(*r.should_be_a00000().expect("error reading"), 10485760); +} diff --git a/spec/rust/tests/test_meta_tags.rs b/spec/rust/tests/test_meta_tags.rs new file mode 100644 index 000000000..a45bf71ec --- /dev/null +++ b/spec/rust/tests/test_meta_tags.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::meta_tags::*; + +#[test] +fn test_meta_tags() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = MetaTags::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs new file mode 100644 index 000000000..368aa3911 --- /dev/null +++ b/spec/rust/tests/test_meta_xref.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::meta_xref::*; + +#[test] +fn test_meta_xref() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = MetaXref::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs new file mode 100644 index 000000000..c96f7e895 --- /dev/null +++ b/spec/rust/tests/test_multiple_use.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::multiple_use::*; + +#[test] +fn test_multiple_use() { + let bytes = fs::read("../../src/position_abs.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = MultipleUse::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.t1().first_use().value(), 32); + assert_eq!(*r.t2().second_use().expect("error reading").value(), 32); +} diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs new file mode 100644 index 000000000..889836b54 --- /dev/null +++ b/spec/rust/tests/test_nav_parent.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent::*; + +#[test] +fn test_nav_parent() { + let bytes = fs::read("../../src/nav.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParent::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.header().qty_entries(), 2); + assert_eq!(*r.header().filename_len(), 8); + assert_eq!(r.index().entries().len(), 2); + assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); + assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); +} diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs new file mode 100644 index 000000000..f1ec1d3a0 --- /dev/null +++ b/spec/rust/tests/test_nav_parent2.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent2::*; + +#[test] +fn test_nav_parent2() { + let bytes = fs::read("../../src/nav_parent2.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParent2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.ofs_tags(), 8); + assert_eq!(*r.num_tags(), 2); + assert_eq!(*r.tags()[0 as usize].name(), "RAHC"); + assert_eq!(*r.tags()[0 as usize].ofs(), 32); + assert_eq!(*r.tags()[0 as usize].num_items(), 3); + assert_eq!(*r.tags()[0 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "foo"); + assert_eq!(*r.tags()[1 as usize].name(), "RAHC"); + assert_eq!(*r.tags()[1 as usize].ofs(), 35); + assert_eq!(*r.tags()[1 as usize].num_items(), 6); + assert_eq!(*r.tags()[1 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "barbaz"); +} diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs new file mode 100644 index 000000000..ffed2619e --- /dev/null +++ b/spec/rust/tests/test_nav_parent3.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent3::*; + +#[test] +fn test_nav_parent3() { + let bytes = fs::read("../../src/nav_parent2.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParent3::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.ofs_tags(), 8); + assert_eq!(*r.num_tags(), 2); + assert_eq!(*r.tags().expect("error reading")[0 as usize].name(), "RAHC"); + assert_eq!(*r.tags().expect("error reading")[0 as usize].ofs(), 32); + assert_eq!(*r.tags().expect("error reading")[0 as usize].num_items(), 3); + assert_eq!(*r.tags().expect("error reading")[0 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "foo"); + assert_eq!(*r.tags().expect("error reading")[1 as usize].name(), "RAHC"); + assert_eq!(*r.tags().expect("error reading")[1 as usize].ofs(), 35); + assert_eq!(*r.tags().expect("error reading")[1 as usize].num_items(), 6); + assert_eq!(*r.tags().expect("error reading")[1 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "barbaz"); +} diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs new file mode 100644 index 000000000..39c5cf356 --- /dev/null +++ b/spec/rust/tests/test_nav_parent_false.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent_false::*; + +#[test] +fn test_nav_parent_false() { + let bytes = fs::read("../../src/nav_parent_codes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParentFalse::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.child_size(), 3); + assert_eq!(*r.element_a().foo().code(), 73); + assert_eq!(*r.element_a().foo().more(), vec![0x31u8, 0x32u8, 0x33u8]); + assert_eq!(*r.element_a().bar().foo().code(), 66); + assert_eq!(*r.element_b().foo().code(), 98); +} diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs new file mode 100644 index 000000000..cd4db64f8 --- /dev/null +++ b/spec/rust/tests/test_nav_parent_false2.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent_false2::*; + +#[test] +fn test_nav_parent_false2() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParentFalse2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.parentless().foo(), 80); +} diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs new file mode 100644 index 000000000..dbeade0de --- /dev/null +++ b/spec/rust/tests/test_nav_parent_override.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent_override::*; + +#[test] +fn test_nav_parent_override() { + let bytes = fs::read("../../src/nav_parent_codes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParentOverride::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.child_size(), 3); + assert_eq!(*r.child_1().data(), vec![0x49u8, 0x31u8, 0x32u8]); + assert_eq!(*r.mediator_2().child_2().data(), vec![0x33u8, 0x42u8, 0x62u8]); +} diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs new file mode 100644 index 000000000..fe907e451 --- /dev/null +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent_switch::*; + +#[test] +fn test_nav_parent_switch() { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParentSwitch::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.category(), 1); + assert_eq!(*Into::>::into(&*r.content().as_ref().unwrap()).foo(), 66); + assert_eq!(*Into::>::into(&*r.content().as_ref().unwrap()).subelement().bar(), 255); +} diff --git a/spec/rust/tests/test_nav_parent_vs_value_inst.rs b/spec/rust/tests/test_nav_parent_vs_value_inst.rs new file mode 100644 index 000000000..9aa41ad7b --- /dev/null +++ b/spec/rust/tests/test_nav_parent_vs_value_inst.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_parent_vs_value_inst::*; + +#[test] +fn test_nav_parent_vs_value_inst() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavParentVsValueInst::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.s1(), "foo"); +} diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs new file mode 100644 index 000000000..1f07b6087 --- /dev/null +++ b/spec/rust/tests/test_nav_root.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nav_root::*; + +#[test] +fn test_nav_root() { + let bytes = fs::read("../../src/nav.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NavRoot::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.header().qty_entries(), 2); + assert_eq!(*r.header().filename_len(), 8); + assert_eq!(r.index().entries().len(), 2); + assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); + assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); +} diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs new file mode 100644 index 000000000..ee4d18a45 --- /dev/null +++ b/spec/rust/tests/test_nested_same_name.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nested_same_name::*; + +#[test] +fn test_nested_same_name() { + let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NestedSameName::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.main_data().main_size(), 2); + assert_eq!(*r.main_data().foo().data(), vec![0x10u8, 0x0u8, 0x0u8, 0x0u8]); +} diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs new file mode 100644 index 000000000..e3fe7530a --- /dev/null +++ b/spec/rust/tests/test_nested_same_name2.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nested_same_name2::*; + +#[test] +fn test_nested_same_name2() { + let bytes = fs::read("../../src/nested_same_name2.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NestedSameName2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.version(), 66); + assert_eq!(*r.main_data().main_size(), 2); + assert_eq!(*r.main_data().foo().data1(), vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); + assert_eq!(*r.dummy().dummy_size(), 3); + assert_eq!(*r.dummy().foo().data2(), vec![0x22u8, 0x22u8, 0x22u8, 0x22u8, 0x22u8, 0x22u8]); +} diff --git a/spec/rust/tests/test_nested_type_param.rs b/spec/rust/tests/test_nested_type_param.rs new file mode 100644 index 000000000..502eeb85a --- /dev/null +++ b/spec/rust/tests/test_nested_type_param.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nested_type_param::*; + +#[test] +fn test_nested_type_param() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NestedTypeParam::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.main_seq().my_len(), 5); + assert_eq!(*r.main_seq().body(), "foo|b"); +} diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs new file mode 100644 index 000000000..9ea721e1c --- /dev/null +++ b/spec/rust/tests/test_nested_types.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nested_types::*; + +#[test] +fn test_nested_types() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NestedTypes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one().typed_at_root().value_b(), 80); + assert_eq!(*r.one().typed_here().value_c(), 65); + assert_eq!(*r.two().value_b(), 67); +} diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs new file mode 100644 index 000000000..346bb51cf --- /dev/null +++ b/spec/rust/tests/test_nested_types2.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nested_types2::*; + +#[test] +fn test_nested_types2() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NestedTypes2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one().typed_at_root().value_b(), 80); + assert_eq!(*r.one().typed_here1().value_c(), 65); + assert_eq!(*r.one().typed_here1().typed_here().value_d(), 67); + assert_eq!(*r.one().typed_here1().typed_parent().value_cc(), 75); + assert_eq!(*r.one().typed_here1().typed_root().value_b(), 45); + assert_eq!(*r.one().typed_here2().value_cc(), 49); + assert_eq!(*r.two().value_b(), -1); +} diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs new file mode 100644 index 000000000..655cded42 --- /dev/null +++ b/spec/rust/tests/test_nested_types3.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::nested_types3::*; + +#[test] +fn test_nested_types3() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NestedTypes3::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.a_cc().value_cc(), 80); + assert_eq!(*r.a_c_d().value_d(), 65); + assert_eq!(*r.b().value_b(), 67); + assert_eq!(*r.b().a_cc().value_cc(), 75); + assert_eq!(*r.b().a_c_d().value_d(), 45); +} diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs new file mode 100644 index 000000000..4e886cac1 --- /dev/null +++ b/spec/rust/tests/test_non_standard.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::non_standard::*; + +#[test] +fn test_non_standard() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = NonStandard::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.foo(), 80); +} diff --git a/spec/rust/tests/manual_opaque_external_type.rs b/spec/rust/tests/test_opaque_external_type.rs similarity index 92% rename from spec/rust/tests/manual_opaque_external_type.rs rename to spec/rust/tests/test_opaque_external_type.rs index 7a4a4f929..07dde7e63 100644 --- a/spec/rust/tests/manual_opaque_external_type.rs +++ b/spec/rust/tests/test_opaque_external_type.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::opaque_external_type::*; #[test] diff --git a/spec/rust/tests/manual_opaque_external_type_02_parent.rs b/spec/rust/tests/test_opaque_external_type_02_parent.rs similarity index 93% rename from spec/rust/tests/manual_opaque_external_type_02_parent.rs rename to spec/rust/tests/test_opaque_external_type_02_parent.rs index 2d5136561..efe7d93c5 100644 --- a/spec/rust/tests/manual_opaque_external_type_02_parent.rs +++ b/spec/rust/tests/test_opaque_external_type_02_parent.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::opaque_external_type_02_parent::*; #[test] diff --git a/spec/rust/tests/manual_opaque_with_param.rs b/spec/rust/tests/test_opaque_with_param.rs similarity index 92% rename from spec/rust/tests/manual_opaque_with_param.rs rename to spec/rust/tests/test_opaque_with_param.rs index b93f4066b..9f584a9ab 100644 --- a/spec/rust/tests/manual_opaque_with_param.rs +++ b/spec/rust/tests/test_opaque_with_param.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::opaque_with_param::*; diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs index 10b71b162..8475c366d 100644 --- a/spec/rust/tests/test_optional_id.rs +++ b/spec/rust/tests/test_optional_id.rs @@ -3,7 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::optional_id::*; #[test] diff --git a/spec/rust/tests/test_params_call_extra_parens.rs b/spec/rust/tests/test_params_call_extra_parens.rs new file mode 100644 index 000000000..2c64da2a8 --- /dev/null +++ b/spec/rust/tests/test_params_call_extra_parens.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_call_extra_parens::*; + +#[test] +fn test_params_call_extra_parens() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsCallExtraParens::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.buf1().body(), "foo|b"); +} diff --git a/spec/rust/tests/test_params_call_short.rs b/spec/rust/tests/test_params_call_short.rs new file mode 100644 index 000000000..29e08d148 --- /dev/null +++ b/spec/rust/tests/test_params_call_short.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_call_short::*; + +#[test] +fn test_params_call_short() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsCallShort::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.buf1().body(), "foo|b"); + assert_eq!(*r.buf2().body(), "ar|ba"); + assert_eq!(*r.buf2().trailer(), 122); +} diff --git a/spec/rust/tests/manual_params_def.rs b/spec/rust/tests/test_params_def.rs similarity index 92% rename from spec/rust/tests/manual_params_def.rs rename to spec/rust/tests/test_params_def.rs index 5ca854d31..7bbe11b26 100644 --- a/spec/rust/tests/manual_params_def.rs +++ b/spec/rust/tests/test_params_def.rs @@ -2,9 +2,9 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; -use formats::params_def::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_def::*; #[test] fn test_params_def() { diff --git a/spec/rust/tests/test_params_enum.rs b/spec/rust/tests/test_params_enum.rs new file mode 100644 index 000000000..185c7ed67 --- /dev/null +++ b/spec/rust/tests/test_params_enum.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_enum::*; + +#[test] +fn test_params_enum() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsEnum::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), ParamsEnum_Animal::Cat); + assert_eq!(*r.invoke_with_param().is_cat().expect("error reading"), true); +} diff --git a/spec/rust/tests/test_params_pass_array_int.rs b/spec/rust/tests/test_params_pass_array_int.rs new file mode 100644 index 000000000..c3a60b452 --- /dev/null +++ b/spec/rust/tests/test_params_pass_array_int.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_pass_array_int::*; + +#[test] +fn test_params_pass_array_int() { + let bytes = fs::read("../../src/position_to_end.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsPassArrayInt::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.pass_ints().nums().len(), 3); + assert_eq!(r.pass_ints().nums()[0 as usize], 513); + assert_eq!(r.pass_ints().nums()[1 as usize], 1027); + assert_eq!(r.pass_ints().nums()[2 as usize], 1541); + assert_eq!(r.pass_ints_calc().nums().len(), 2); + assert_eq!(r.pass_ints_calc().nums()[0 as usize], 27643); + assert_eq!(r.pass_ints_calc().nums()[1 as usize], 7); +} diff --git a/spec/rust/tests/test_params_pass_array_str.rs b/spec/rust/tests/test_params_pass_array_str.rs new file mode 100644 index 000000000..073d06312 --- /dev/null +++ b/spec/rust/tests/test_params_pass_array_str.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_pass_array_str::*; + +#[test] +fn test_params_pass_array_str() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsPassArrayStr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.pass_str_array().strs().len(), 3); + assert_eq!(r.pass_str_array().strs()[0 as usize], "fo"); + assert_eq!(r.pass_str_array().strs()[1 as usize], "o|"); + assert_eq!(r.pass_str_array().strs()[2 as usize], "ba"); + assert_eq!(r.pass_str_array_calc().strs().len(), 2); + assert_eq!(r.pass_str_array_calc().strs()[0 as usize], "aB"); + assert_eq!(r.pass_str_array_calc().strs()[1 as usize], "Cd"); +} diff --git a/spec/rust/tests/test_params_pass_array_usertype.rs b/spec/rust/tests/test_params_pass_array_usertype.rs new file mode 100644 index 000000000..0b99a4ace --- /dev/null +++ b/spec/rust/tests/test_params_pass_array_usertype.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_pass_array_usertype::*; + +#[test] +fn test_params_pass_array_usertype() { + let bytes = fs::read("../../src/position_to_end.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsPassArrayUsertype::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.pass_blocks().bar().len(), 2); + assert_eq!(*r.pass_blocks().bar()[0 as usize].foo(), 1); + assert_eq!(*r.pass_blocks().bar()[1 as usize].foo(), 2); + assert_eq!(*r.pass_blocks().one(), vec![0x3u8]); + assert_eq!(*r.pass_blocks().two(), vec![0x4u8, 0x5u8]); +} diff --git a/spec/rust/tests/test_params_pass_bool.rs b/spec/rust/tests/test_params_pass_bool.rs new file mode 100644 index 000000000..85068c8ea --- /dev/null +++ b/spec/rust/tests/test_params_pass_bool.rs @@ -0,0 +1,39 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_pass_bool::*; + +#[test] +fn test_params_pass_bool() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsPassBool::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.s_false(), false); + assert_eq!(*r.s_true(), true); + assert_eq!(*r.seq_b1().arg(), true); + assert_eq!(r.seq_b1().foo().len(), 1); + assert_eq!(*r.seq_bool().arg(), false); + assert_eq!(r.seq_bool().foo().len(), 2); + assert_eq!(*r.literal_b1().arg(), false); + assert_eq!(r.literal_b1().foo().len(), 2); + assert_eq!(*r.literal_bool().arg(), true); + assert_eq!(r.literal_bool().foo().len(), 1); + assert_eq!(*r.inst_b1().arg(), true); + assert_eq!(r.inst_b1().foo().len(), 1); + assert_eq!(*r.inst_bool().arg(), false); + assert_eq!(r.inst_bool().foo().len(), 2); +} diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs new file mode 100644 index 000000000..c17440a15 --- /dev/null +++ b/spec/rust/tests/test_params_pass_usertype.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::params_pass_usertype::*; + +#[test] +fn test_params_pass_usertype() { + let bytes = fs::read("../../src/position_in_seq.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ParamsPassUsertype::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.first().foo(), 1); + assert_eq!(*r.one().buf(), vec![0x2u8]); +} diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs new file mode 100644 index 000000000..5c360ef65 --- /dev/null +++ b/spec/rust/tests/test_position_abs.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::position_abs::*; + +#[test] +fn test_position_abs() { + let bytes = fs::read("../../src/position_abs.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = PositionAbs::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.index_offset(), 32); + assert_eq!(*r.index().expect("error reading").entry(), "foo"); +} diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs new file mode 100644 index 000000000..37e141575 --- /dev/null +++ b/spec/rust/tests/test_position_in_seq.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::position_in_seq::*; + +#[test] +fn test_position_in_seq() { + let bytes = fs::read("../../src/position_in_seq.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = PositionInSeq::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.numbers(), vec![(0 + 1), 2, 3]); +} diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs new file mode 100644 index 000000000..8d2fdf8a9 --- /dev/null +++ b/spec/rust/tests/test_position_to_end.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::position_to_end::*; + +#[test] +fn test_position_to_end() { + let bytes = fs::read("../../src/position_to_end.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = PositionToEnd::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.index().expect("error reading").foo(), 66); + assert_eq!(*r.index().expect("error reading").bar(), 4660); +} diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs new file mode 100644 index 000000000..5ae1eaea8 --- /dev/null +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_coerce_bytes::*; + +#[test] +fn test_process_coerce_bytes() { + let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessCoerceBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.records()[0 as usize].flag(), 0); + assert_eq!(*r.records()[0 as usize].buf().expect("error reading"), vec![0x41u8, 0x41u8, 0x41u8, 0x41u8]); + assert_eq!(*r.records()[1 as usize].flag(), 1); + assert_eq!(*r.records()[1 as usize].buf().expect("error reading"), vec![0x42u8, 0x42u8, 0x42u8, 0x42u8]); +} diff --git a/spec/rust/tests/test_process_coerce_usertype1.rs b/spec/rust/tests/test_process_coerce_usertype1.rs new file mode 100644 index 000000000..3eddbe44b --- /dev/null +++ b/spec/rust/tests/test_process_coerce_usertype1.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_coerce_usertype1::*; + +#[test] +fn test_process_coerce_usertype1() { + let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessCoerceUsertype1::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.records()[0 as usize].flag(), 0); + assert_eq!(*r.records()[0 as usize].buf().expect("error reading").value(), 1094795585); + assert_eq!(*r.records()[1 as usize].flag(), 1); + assert_eq!(*r.records()[1 as usize].buf().expect("error reading").value(), 1111638594); +} diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs new file mode 100644 index 000000000..df19b3a53 --- /dev/null +++ b/spec/rust/tests/test_process_coerce_usertype2.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_coerce_usertype2::*; + +#[test] +fn test_process_coerce_usertype2() { + let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessCoerceUsertype2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.records()[0 as usize].flag(), 0); + assert_eq!(*r.records()[0 as usize].buf().expect("error reading").value(), 1094795585); + assert_eq!(*r.records()[1 as usize].flag(), 1); + assert_eq!(*r.records()[1 as usize].buf().expect("error reading").value(), 1111638594); +} diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs new file mode 100644 index 000000000..afdcfca16 --- /dev/null +++ b/spec/rust/tests/test_process_custom.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_custom::*; + +#[test] +fn test_process_custom() { + let bytes = fs::read("../../src/process_rotate.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessCustom::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.buf1(), vec![0x10u8, 0xb3u8, 0x94u8, 0x94u8, 0xf4u8]); + assert_eq!(*r.buf2(), vec![0x5fu8, 0xbau8, 0x7bu8, 0x93u8, 0x63u8, 0x23u8, 0x5fu8]); + assert_eq!(*r.buf3(), vec![0x29u8, 0x33u8, 0xb1u8, 0x38u8, 0xb1u8]); +} diff --git a/spec/rust/tests/test_process_custom_no_args.rs b/spec/rust/tests/test_process_custom_no_args.rs new file mode 100644 index 000000000..d132f18f9 --- /dev/null +++ b/spec/rust/tests/test_process_custom_no_args.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_custom_no_args::*; + +#[test] +fn test_process_custom_no_args() { + let bytes = fs::read("../../src/process_rotate.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessCustomNoArgs::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.buf(), vec![0x5fu8, 0x9u8, 0xacu8, 0x8du8, 0x8du8, 0xedu8, 0x5fu8]); +} diff --git a/spec/rust/tests/test_process_repeat_bytes.rs b/spec/rust/tests/test_process_repeat_bytes.rs new file mode 100644 index 000000000..2918be66b --- /dev/null +++ b/spec/rust/tests/test_process_repeat_bytes.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_repeat_bytes::*; + +#[test] +fn test_process_repeat_bytes() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessRepeatBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.bufs()[0 as usize], vec![0x72u8, 0x25u8, 0x3du8, 0x8au8, 0x14u8]); + assert_eq!(r.bufs()[1 as usize], vec![0x4au8, 0x52u8, 0xaau8, 0x10u8, 0x44u8]); +} diff --git a/spec/rust/tests/test_process_repeat_usertype.rs b/spec/rust/tests/test_process_repeat_usertype.rs new file mode 100644 index 000000000..3a9f6df35 --- /dev/null +++ b/spec/rust/tests/test_process_repeat_usertype.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_repeat_usertype::*; + +#[test] +fn test_process_repeat_usertype() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessRepeatUsertype::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.blocks()[0 as usize].a(), -1975704206); + assert_eq!(*r.blocks()[0 as usize].b(), 20); + assert_eq!(*r.blocks()[1 as usize].a(), 279597642); + assert_eq!(*r.blocks()[1 as usize].b(), 68); +} diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs new file mode 100644 index 000000000..2ba7c39de --- /dev/null +++ b/spec/rust/tests/test_process_rotate.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_rotate::*; + +#[test] +fn test_process_rotate() { + let bytes = fs::read("../../src/process_rotate.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessRotate::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.buf1(), vec![0x48u8, 0x65u8, 0x6cu8, 0x6cu8, 0x6fu8]); + assert_eq!(*r.buf2(), vec![0x57u8, 0x6fu8, 0x72u8, 0x6cu8, 0x64u8]); + assert_eq!(*r.buf3(), vec![0x54u8, 0x68u8, 0x65u8, 0x72u8, 0x65u8]); +} diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs new file mode 100644 index 000000000..321958c20 --- /dev/null +++ b/spec/rust/tests/test_process_to_user.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_to_user::*; + +#[test] +fn test_process_to_user() { + let bytes = fs::read("../../src/process_rotate.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessToUser::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.buf1().str(), "Hello"); +} diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs new file mode 100644 index 000000000..1ced0d220 --- /dev/null +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_xor4_const::*; + +#[test] +fn test_process_xor4_const() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessXor4Const::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.key(), vec![0xecu8, 0xbbu8, 0xa3u8, 0x14u8]); + assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); +} diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs new file mode 100644 index 000000000..0b198e9c0 --- /dev/null +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_xor4_value::*; + +#[test] +fn test_process_xor4_value() { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessXor4Value::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.key(), vec![0xecu8, 0xbbu8, 0xa3u8, 0x14u8]); + assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); +} diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs new file mode 100644 index 000000000..5ec145e88 --- /dev/null +++ b/spec/rust/tests/test_process_xor_const.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_xor_const::*; + +#[test] +fn test_process_xor_const() { + let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessXorConst::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.key(), 255); + assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); +} diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs new file mode 100644 index 000000000..4414d53d3 --- /dev/null +++ b/spec/rust/tests/test_process_xor_value.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::process_xor_value::*; + +#[test] +fn test_process_xor_value() { + let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ProcessXorValue::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.key(), 255); + assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); +} diff --git a/spec/rust/tests/test_recursive_one.rs b/spec/rust/tests/test_recursive_one.rs new file mode 100644 index 000000000..b4ce408d3 --- /dev/null +++ b/spec/rust/tests/test_recursive_one.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::recursive_one::*; + +#[test] +fn test_recursive_one() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RecursiveOne::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one(), 80); + assert_eq!(*Into::>::into(&*r.next().as_ref().unwrap()).one(), 65); + assert_eq!(*Into::>::into(&*Into::>::into(&*r.next().as_ref().unwrap()).next().as_ref().unwrap()).one(), 67); + assert_eq!(*Into::>::into(&*Into::>::into(&*Into::>::into(&*r.next().as_ref().unwrap()).next().as_ref().unwrap()).next().as_ref().unwrap()).finisher(), 11595); +} diff --git a/spec/rust/tests/test_repeat_eos_bit.rs b/spec/rust/tests/test_repeat_eos_bit.rs new file mode 100644 index 000000000..a9fc58dfe --- /dev/null +++ b/spec/rust/tests/test_repeat_eos_bit.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_eos_bit::*; + +#[test] +fn test_repeat_eos_bit() { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatEosBit::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.nibbles().len(), 16); +} diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index 9ccb5a450..08b00053a 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::repeat_eos_struct::*; diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs new file mode 100644 index 000000000..a82954901 --- /dev/null +++ b/spec/rust/tests/test_repeat_eos_u4.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_eos_u4::*; + +#[test] +fn test_repeat_eos_u4() { + let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatEosU4::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.numbers(), vec![0, 66, 66, 2069]); +} diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index 7ffd9eb64..54e794f5f 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -5,7 +5,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::repeat_n_struct::*; diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs new file mode 100644 index 000000000..b2c2e19b8 --- /dev/null +++ b/spec/rust/tests/test_repeat_n_strz.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_n_strz::*; + +#[test] +fn test_repeat_n_strz() { + let bytes = fs::read("../../src/repeat_n_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatNStrz::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.qty(), 2); + assert_eq!(*r.lines(), vec!["foo".to_string(), "bar".to_string()]); +} diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs new file mode 100644 index 000000000..27d26e465 --- /dev/null +++ b/spec/rust/tests/test_repeat_n_strz_double.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_n_strz_double::*; + +#[test] +fn test_repeat_n_strz_double() { + let bytes = fs::read("../../src/repeat_n_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatNStrzDouble::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.qty(), 2); + assert_eq!(*r.lines1(), vec!["foo".to_string()]); + assert_eq!(*r.lines2(), vec!["bar".to_string()]); +} diff --git a/spec/rust/tests/test_repeat_until_calc_array_type.rs b/spec/rust/tests/test_repeat_until_calc_array_type.rs new file mode 100644 index 000000000..629b597fc --- /dev/null +++ b/spec/rust/tests/test_repeat_until_calc_array_type.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_until_calc_array_type::*; + +#[test] +fn test_repeat_until_calc_array_type() { + let bytes = fs::read("../../src/repeat_until_process.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatUntilCalcArrayType::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.records().len(), 3); + assert_eq!(*r.records()[0 as usize].marker(), 232); + assert_eq!(*r.records()[0 as usize].body(), 2863311546); + assert_eq!(*r.records()[1 as usize].marker(), 250); + assert_eq!(*r.records()[1 as usize].body(), 2863315102); + assert_eq!(*r.records()[2 as usize].marker(), 170); + assert_eq!(*r.records()[2 as usize].body(), 1431655765); +} diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs new file mode 100644 index 000000000..273510461 --- /dev/null +++ b/spec/rust/tests/test_repeat_until_complex.rs @@ -0,0 +1,40 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_until_complex::*; + +#[test] +fn test_repeat_until_complex() { + let bytes = fs::read("../../src/repeat_until_complex.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatUntilComplex::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.first().len(), 3); + assert_eq!(*r.first()[0 as usize].count(), 4); + assert_eq!(*r.first()[0 as usize].values(), vec![(0 + 1), 2, 3, 4]); + assert_eq!(*r.first()[1 as usize].count(), 2); + assert_eq!(*r.first()[1 as usize].values(), vec![(0 + 1), 2]); + assert_eq!(*r.first()[2 as usize].count(), 0); + assert_eq!(r.second().len(), 4); + assert_eq!(*r.second()[0 as usize].count(), 6); + assert_eq!(*r.second()[0 as usize].values(), vec![(0 + 1), 2, 3, 4, 5, 6]); + assert_eq!(*r.second()[1 as usize].count(), 3); + assert_eq!(*r.second()[1 as usize].values(), vec![(0 + 1), 2, 3]); + assert_eq!(*r.second()[2 as usize].count(), 4); + assert_eq!(*r.second()[2 as usize].values(), vec![(0 + 1), 2, 3, 4]); + assert_eq!(*r.second()[3 as usize].count(), 0); + assert_eq!(*r.third(), vec![(0 + 102), 111, 111, 98, 97, 114, 0]); +} diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs new file mode 100644 index 000000000..e0a947310 --- /dev/null +++ b/spec/rust/tests/test_repeat_until_s4.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_until_s4::*; + +#[test] +fn test_repeat_until_s4() { + let bytes = fs::read("../../src/repeat_until_s4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatUntilS4::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.entries(), vec![66, 4919, -251658241, -1]); + assert_eq!(*r.afterall(), "foobar"); +} diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs new file mode 100644 index 000000000..33a2ce980 --- /dev/null +++ b/spec/rust/tests/test_repeat_until_sized.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::repeat_until_sized::*; + +#[test] +fn test_repeat_until_sized() { + let bytes = fs::read("../../src/repeat_until_process.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = RepeatUntilSized::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.records().len(), 3); + assert_eq!(*r.records()[0 as usize].marker(), 232); + assert_eq!(*r.records()[0 as usize].body(), 2863311546); + assert_eq!(*r.records()[1 as usize].marker(), 250); + assert_eq!(*r.records()[1 as usize].body(), 2863315102); + assert_eq!(*r.records()[2 as usize].marker(), 170); + assert_eq!(*r.records()[2 as usize].body(), 1431655765); +} diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs new file mode 100644 index 000000000..f5f2372ed --- /dev/null +++ b/spec/rust/tests/test_str_encodings.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::str_encodings::*; + +#[test] +fn test_str_encodings() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = StrEncodings::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str1(), "Some ASCII"); + assert_eq!(*r.str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(*r.str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(*r.str4(), "\u{2591}\u{2592}\u{2593}"); +} diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs new file mode 100644 index 000000000..0f8605afa --- /dev/null +++ b/spec/rust/tests/test_str_encodings_default.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::str_encodings_default::*; + +#[test] +fn test_str_encodings_default() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = StrEncodingsDefault::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str1(), "Some ASCII"); + assert_eq!(*r.rest().str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(*r.rest().str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(*r.rest().str4(), "\u{2591}\u{2592}\u{2593}"); +} diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs new file mode 100644 index 000000000..3452bc660 --- /dev/null +++ b/spec/rust/tests/test_str_encodings_utf16.rs @@ -0,0 +1,31 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::str_encodings_utf16::*; + +#[test] +fn test_str_encodings_utf16() { + let bytes = fs::read("../../src/str_encodings_utf16.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = StrEncodingsUtf16::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.len_be(), 12); + assert_eq!(*r.be_bom_removed().bom(), 65279); + assert_eq!(*r.be_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + assert_eq!(*r.len_le(), 12); + assert_eq!(*r.le_bom_removed().bom(), 65279); + assert_eq!(*r.le_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); +} diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs new file mode 100644 index 000000000..a0532fac5 --- /dev/null +++ b/spec/rust/tests/test_str_eos.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::str_eos::*; + +#[test] +fn test_str_eos() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = StrEos::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str(), "foo|bar|baz@"); +} diff --git a/spec/rust/tests/manual_str_literals.rs b/spec/rust/tests/test_str_literals.rs similarity index 95% rename from spec/rust/tests/manual_str_literals.rs rename to spec/rust/tests/test_str_literals.rs index fd02d0a26..fa6e9984a 100644 --- a/spec/rust/tests/manual_str_literals.rs +++ b/spec/rust/tests/test_str_literals.rs @@ -3,7 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::str_literals::*; #[test] diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs new file mode 100644 index 000000000..ff8270262 --- /dev/null +++ b/spec/rust/tests/test_str_literals2.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::str_literals2::*; + +#[test] +fn test_str_literals2() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = StrLiterals2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.dollar1().expect("error reading"), "$foo"); + assert_eq!(*r.dollar2().expect("error reading"), "${foo}"); + assert_eq!(*r.hash().expect("error reading"), "#{foo}"); + assert_eq!(*r.at_sign().expect("error reading"), "@foo"); +} diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs new file mode 100644 index 000000000..7591b3161 --- /dev/null +++ b/spec/rust/tests/test_str_pad_term.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::str_pad_term::*; + +#[test] +fn test_str_pad_term() { + let bytes = fs::read("../../src/str_pad_term.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = StrPadTerm::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str_pad(), "str1"); + assert_eq!(*r.str_term(), "str2foo"); + assert_eq!(*r.str_term_and_pad(), "str+++3bar+++"); + assert_eq!(*r.str_term_include(), "str4baz@"); +} diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs new file mode 100644 index 000000000..8bc4281ba --- /dev/null +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::str_pad_term_empty::*; + +#[test] +fn test_str_pad_term_empty() { + let bytes = fs::read("../../src/str_pad_term_empty.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = StrPadTermEmpty::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.str_pad(), ""); + assert_eq!(*r.str_term(), ""); + assert_eq!(*r.str_term_and_pad(), ""); + assert_eq!(*r.str_term_include(), "@"); +} diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs new file mode 100644 index 000000000..521c57e16 --- /dev/null +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_bytearray::*; + +#[test] +fn test_switch_bytearray() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchBytearray::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), vec![0x53u8]); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foobar"); + assert_eq!(*r.opcodes()[1 as usize].code(), vec![0x49u8]); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value(), 66); + assert_eq!(*r.opcodes()[2 as usize].code(), vec![0x49u8]); + assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); + assert_eq!(*r.opcodes()[3 as usize].code(), vec![0x53u8]); + assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); +} diff --git a/spec/rust/tests/manual_switch_cast.rs b/spec/rust/tests/test_switch_cast.rs similarity index 97% rename from spec/rust/tests/manual_switch_cast.rs rename to spec/rust/tests/test_switch_cast.rs index 1d6fc972c..713632b34 100644 --- a/spec/rust/tests/manual_switch_cast.rs +++ b/spec/rust/tests/test_switch_cast.rs @@ -3,7 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::switch_cast::*; #[test] diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs new file mode 100644 index 000000000..1158ec441 --- /dev/null +++ b/spec/rust/tests/test_switch_else_only.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_else_only::*; + +#[test] +fn test_switch_else_only() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchElseOnly::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.opcode(), 83); + assert_eq!(r.prim_byte(), 102); + assert_eq!(*r.ut().as_ref().unwrap().value(), vec![0x72u8, 0x0u8, 0x49u8, 0x42u8]); +} diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs new file mode 100644 index 000000000..eb9def5f4 --- /dev/null +++ b/spec/rust/tests/test_switch_integers.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_integers::*; + +#[test] +fn test_switch_integers() { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchIntegers::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), 1); + assert_eq!(r.opcodes()[0 as usize].body(), 7); + assert_eq!(*r.opcodes()[1 as usize].code(), 2); + assert_eq!(r.opcodes()[1 as usize].body(), 16448); + assert_eq!(*r.opcodes()[2 as usize].code(), 4); + assert_eq!(r.opcodes()[2 as usize].body(), 4919); + assert_eq!(*r.opcodes()[3 as usize].code(), 8); + assert_eq!(r.opcodes()[3 as usize].body(), 4919); +} diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs new file mode 100644 index 000000000..4a61e7e50 --- /dev/null +++ b/spec/rust/tests/test_switch_integers2.rs @@ -0,0 +1,30 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_integers2::*; + +#[test] +fn test_switch_integers2() { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchIntegers2::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.code(), 1); + assert_eq!(r.len(), 7); + assert_eq!(*r.ham(), vec![0x2u8, 0x40u8, 0x40u8, 0x4u8, 0x37u8, 0x13u8, 0x0u8]); + assert_eq!(*r.padding(), 0); + assert_eq!(*r.len_mod_str().expect("error reading"), "13"); +} diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs new file mode 100644 index 000000000..2e8927095 --- /dev/null +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_manual_enum::*; + +#[test] +fn test_switch_manual_enum() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchManualEnum::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foobar"); + assert_eq!(*r.opcodes()[1 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value(), 66); + assert_eq!(*r.opcodes()[2 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Intval); + assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); + assert_eq!(*r.opcodes()[3 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); + assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); +} diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 884b443cf..11e9d6ccf 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::switch_manual_enum_invalid::*; diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index 515e92333..d6f917596 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -5,7 +5,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::switch_manual_enum_invalid_else::*; diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs new file mode 100644 index 000000000..cee675073 --- /dev/null +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_manual_int::*; + +#[test] +fn test_switch_manual_int() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchManualInt::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), 83); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foobar"); + assert_eq!(*r.opcodes()[1 as usize].code(), 73); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value(), 66); + assert_eq!(*r.opcodes()[2 as usize].code(), 73); + assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); + assert_eq!(*r.opcodes()[3 as usize].code(), 83); + assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); +} diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs new file mode 100644 index 000000000..41ab540cf --- /dev/null +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_manual_int_else::*; + +#[test] +fn test_switch_manual_int_else() { + let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchManualIntElse::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), 83); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foo"); + assert_eq!(*r.opcodes()[1 as usize].code(), 88); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).filler(), 66); + assert_eq!(*r.opcodes()[2 as usize].code(), 89); + assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).filler(), 51966); + assert_eq!(*r.opcodes()[3 as usize].code(), 73); + assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), 7); +} diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs new file mode 100644 index 000000000..3b21618ec --- /dev/null +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_manual_int_size::*; + +#[test] +fn test_switch_manual_int_size() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchManualIntSize::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.chunks().len(), 4); + assert_eq!(*r.chunks()[0 as usize].code(), 17); + assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().as_ref().unwrap()).title(), "Stuff"); + assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().as_ref().unwrap()).author(), "Me"); + assert_eq!(*r.chunks()[1 as usize].code(), 34); + assert_eq!(*Into::>::into(&*r.chunks()[1 as usize].body().as_ref().unwrap()).entries(), vec!["AAAA".to_string(), "BBBB".to_string(), "CCCC".to_string()]); + assert_eq!(*r.chunks()[2 as usize].code(), 51); + assert_eq!(Into::>::into(&*r.chunks()[2 as usize].body().as_ref().unwrap()), vec![0x10u8, 0x20u8, 0x30u8, 0x40u8, 0x50u8, 0x60u8, 0x70u8, 0x80u8]); + assert_eq!(*r.chunks()[3 as usize].code(), 255); + assert_eq!(Into::>::into(&*r.chunks()[3 as usize].body().as_ref().unwrap()), vec![]); +} diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs new file mode 100644 index 000000000..c3c7f5cdb --- /dev/null +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -0,0 +1,35 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_manual_int_size_else::*; + +#[test] +fn test_switch_manual_int_size_else() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchManualIntSizeElse::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.chunks().len(), 4); + assert_eq!(*r.chunks()[0 as usize].code(), 17); + assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().as_ref().unwrap()).title(), "Stuff"); + assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().as_ref().unwrap()).author(), "Me"); + assert_eq!(*r.chunks()[1 as usize].code(), 34); + assert_eq!(*Into::>::into(&*r.chunks()[1 as usize].body().as_ref().unwrap()).entries(), vec!["AAAA".to_string(), "BBBB".to_string(), "CCCC".to_string()]); + assert_eq!(*r.chunks()[2 as usize].code(), 51); + assert_eq!(*Into::>::into(&*r.chunks()[2 as usize].body().as_ref().unwrap()).rest(), vec![0x10u8, 0x20u8, 0x30u8, 0x40u8, 0x50u8, 0x60u8, 0x70u8, 0x80u8]); + assert_eq!(*r.chunks()[3 as usize].code(), 255); + assert_eq!(*Into::>::into(&*r.chunks()[3 as usize].body().as_ref().unwrap()).rest(), vec![]); +} diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 32fcaa386..5a02b6384 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -3,7 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::switch_manual_int_size_eos::*; #[test] diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs new file mode 100644 index 000000000..e9c7af6bc --- /dev/null +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_manual_str::*; + +#[test] +fn test_switch_manual_str() { + let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchManualStr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), "S"); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foobar"); + assert_eq!(*r.opcodes()[1 as usize].code(), "I"); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value(), 66); + assert_eq!(*r.opcodes()[2 as usize].code(), "I"); + assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); + assert_eq!(*r.opcodes()[3 as usize].code(), "S"); + assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); +} diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs new file mode 100644 index 000000000..6ad6cbd31 --- /dev/null +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_manual_str_else::*; + +#[test] +fn test_switch_manual_str_else() { + let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchManualStrElse::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), "S"); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value(), "foo"); + assert_eq!(*r.opcodes()[1 as usize].code(), "X"); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).filler(), 66); + assert_eq!(*r.opcodes()[2 as usize].code(), "Y"); + assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).filler(), 51966); + assert_eq!(*r.opcodes()[3 as usize].code(), "I"); + assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), 7); +} diff --git a/spec/rust/tests/test_switch_multi_bool_ops.rs b/spec/rust/tests/test_switch_multi_bool_ops.rs new file mode 100644 index 000000000..c5b4b63b2 --- /dev/null +++ b/spec/rust/tests/test_switch_multi_bool_ops.rs @@ -0,0 +1,34 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_multi_bool_ops::*; + +#[test] +fn test_switch_multi_bool_ops() { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchMultiBoolOps::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(r.opcodes().len(), 4); + assert_eq!(*r.opcodes()[0 as usize].code(), 1); + assert_eq!(r.opcodes()[0 as usize].body(), 7); + assert_eq!(*r.opcodes()[1 as usize].code(), 2); + assert_eq!(r.opcodes()[1 as usize].body(), 16448); + assert_eq!(*r.opcodes()[2 as usize].code(), 4); + assert_eq!(r.opcodes()[2 as usize].body(), 4919); + assert_eq!(*r.opcodes()[3 as usize].code(), 8); + assert_eq!(r.opcodes()[3 as usize].body(), 4919); +} diff --git a/spec/rust/tests/test_switch_repeat_expr.rs b/spec/rust/tests/test_switch_repeat_expr.rs new file mode 100644 index 000000000..263dbd1c7 --- /dev/null +++ b/spec/rust/tests/test_switch_repeat_expr.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_repeat_expr::*; + +#[test] +fn test_switch_repeat_expr() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchRepeatExpr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.code(), 17); + assert_eq!(*r.size(), 9); + assert_eq!(*Into::>::into(&r.body()[0 as usize]).first(), vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); +} diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs new file mode 100644 index 000000000..26f62bf5b --- /dev/null +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::switch_repeat_expr_invalid::*; + +#[test] +fn test_switch_repeat_expr_invalid() { + let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = SwitchRepeatExprInvalid::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.code(), 17); + assert_eq!(*r.size(), 9); + assert_eq!(Into::>::into(&r.body()[0 as usize]), vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); +} diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs new file mode 100644 index 000000000..e3a6a4670 --- /dev/null +++ b/spec/rust/tests/test_term_bytes.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::term_bytes::*; + +#[test] +fn test_term_bytes() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = TermBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.s1(), vec![0x66u8, 0x6fu8, 0x6fu8]); + assert_eq!(*r.s2(), vec![0x62u8, 0x61u8, 0x72u8]); + assert_eq!(*r.s3(), vec![0x7cu8, 0x62u8, 0x61u8, 0x7au8, 0x40u8]); +} diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs new file mode 100644 index 000000000..d88425f68 --- /dev/null +++ b/spec/rust/tests/test_term_strz.rs @@ -0,0 +1,28 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::term_strz::*; + +#[test] +fn test_term_strz() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = TermStrz::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.s1(), "foo"); + assert_eq!(*r.s2(), "bar"); + assert_eq!(*r.s3(), "|baz@"); +} diff --git a/spec/rust/tests/test_term_u1_val.rs b/spec/rust/tests/test_term_u1_val.rs new file mode 100644 index 000000000..3c4318634 --- /dev/null +++ b/spec/rust/tests/test_term_u1_val.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::term_u1_val::*; + +#[test] +fn test_term_u1_val() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = TermU1Val::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.foo(), vec![0xau8, 0x0u8, 0x53u8, 0x6fu8, 0x6du8, 0x65u8, 0x20u8, 0x41u8, 0x53u8, 0x43u8, 0x49u8, 0x49u8, 0xfu8, 0x0u8]); + assert_eq!(*r.bar(), "\u{3053}\u{3093}\u{306b}"); +} diff --git a/spec/rust/tests/manual_to_string_custom.rs b/spec/rust/tests/test_to_string_custom.rs similarity index 91% rename from spec/rust/tests/manual_to_string_custom.rs rename to spec/rust/tests/test_to_string_custom.rs index 0231d198c..0b70960d4 100644 --- a/spec/rust/tests/manual_to_string_custom.rs +++ b/spec/rust/tests/test_to_string_custom.rs @@ -3,7 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::to_string_custom::*; #[test] diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs new file mode 100644 index 000000000..0307b3c3a --- /dev/null +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -0,0 +1,32 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::ts_packet_header::*; + +#[test] +fn test_ts_packet_header() { + let bytes = fs::read("../../src/ts_packet.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = TsPacketHeader::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.sync_byte(), 71); + assert_eq!(*r.transport_error_indicator(), false); + assert_eq!(*r.payload_unit_start_indicator(), false); + assert_eq!(*r.transport_priority(), true); + assert_eq!(*r.pid(), 33); + assert_eq!(*r.transport_scrambling_control(), 0); + assert_eq!(*r.adaptation_field_control(), TsPacketHeader_AdaptationFieldControlEnum::PayloadOnly); +} diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs new file mode 100644 index 000000000..ab39d26f3 --- /dev/null +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::type_int_unary_op::*; + +#[test] +fn test_type_int_unary_op() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = TypeIntUnaryOp::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.value_s2(), 16720); + assert_eq!(*r.value_s8(), 4706543082108963651); + assert_eq!(*r.unary_s2().expect("error reading"), -16720); + assert_eq!(*r.unary_s8().expect("error reading"), -4706543082108963651); +} diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs new file mode 100644 index 000000000..cd0c5166c --- /dev/null +++ b/spec/rust/tests/test_type_ternary.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::type_ternary::*; + +#[test] +fn test_type_ternary() { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = TypeTernary::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.dif().expect("error reading").value(), 101); +} diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index 5a388338c..6f4524c97 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::type_ternary_2nd_falsy::*; diff --git a/spec/rust/tests/manual_type_ternary_opaque.rs b/spec/rust/tests/test_type_ternary_opaque.rs similarity index 93% rename from spec/rust/tests/manual_type_ternary_opaque.rs rename to spec/rust/tests/test_type_ternary_opaque.rs index d9b0524b4..a29bf52ea 100644 --- a/spec/rust/tests/manual_type_ternary_opaque.rs +++ b/spec/rust/tests/test_type_ternary_opaque.rs @@ -2,7 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -mod formats; +#[path = "../formats/mod.rs"] mod formats; use formats::type_ternary_opaque::*; #[test] diff --git a/spec/rust/tests/test_user_type.rs b/spec/rust/tests/test_user_type.rs new file mode 100644 index 000000000..7ae72848f --- /dev/null +++ b/spec/rust/tests/test_user_type.rs @@ -0,0 +1,27 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::user_type::*; + +#[test] +fn test_user_type() { + let bytes = fs::read("../../src/repeat_until_s4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = UserType::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.one().width(), 66); + assert_eq!(*r.one().height(), 4919); +} diff --git a/spec/rust/tests/test_valid_eq_str_encodings.rs b/spec/rust/tests/test_valid_eq_str_encodings.rs new file mode 100644 index 000000000..0b071ca7f --- /dev/null +++ b/spec/rust/tests/test_valid_eq_str_encodings.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_eq_str_encodings::*; + +#[test] +fn test_valid_eq_str_encodings() { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidEqStrEncodings::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_valid_fail_anyof_int.rs b/spec/rust/tests/test_valid_fail_anyof_int.rs new file mode 100644 index 000000000..f801cd382 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_anyof_int.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_anyof_int::*; + +#[test] +fn test_valid_fail_anyof_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailAnyofInt::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationNotAnyOfError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationNotAnyOfError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_contents.rs b/spec/rust/tests/test_valid_fail_contents.rs new file mode 100644 index 000000000..1dcf626b6 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_contents.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_contents::*; + +#[test] +fn test_valid_fail_contents() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailContents::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); + } else { + panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); + } +} diff --git a/spec/rust/tests/test_valid_fail_eq_bytes.rs b/spec/rust/tests/test_valid_fail_eq_bytes.rs new file mode 100644 index 000000000..5c0c5f25c --- /dev/null +++ b/spec/rust/tests/test_valid_fail_eq_bytes.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_eq_bytes::*; + +#[test] +fn test_valid_fail_eq_bytes() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailEqBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); + } else { + panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); + } +} diff --git a/spec/rust/tests/test_valid_fail_eq_int.rs b/spec/rust/tests/test_valid_fail_eq_int.rs new file mode 100644 index 000000000..8834583b2 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_eq_int.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_eq_int::*; + +#[test] +fn test_valid_fail_eq_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailEqInt::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_eq_str.rs b/spec/rust/tests/test_valid_fail_eq_str.rs new file mode 100644 index 000000000..3b0610989 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_eq_str.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_eq_str::*; + +#[test] +fn test_valid_fail_eq_str() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailEqStr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationNotEqualError(CalcStrType)", err); + } else { + panic!("no expected exception: ValidationNotEqualError(CalcStrType)"); + } +} diff --git a/spec/rust/tests/test_valid_fail_expr.rs b/spec/rust/tests/test_valid_fail_expr.rs new file mode 100644 index 000000000..8170755fd --- /dev/null +++ b/spec/rust/tests/test_valid_fail_expr.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_expr::*; + +#[test] +fn test_valid_fail_expr() { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailExpr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationExprError(IntMultiType(true,Width2,None))", err); + } else { + panic!("no expected exception: ValidationExprError(IntMultiType(true,Width2,None))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_inst.rs b/spec/rust/tests/test_valid_fail_inst.rs new file mode 100644 index 000000000..941f2409b --- /dev/null +++ b/spec/rust/tests/test_valid_fail_inst.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_inst::*; + +#[test] +fn test_valid_fail_inst() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailInst::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_max_int.rs b/spec/rust/tests/test_valid_fail_max_int.rs new file mode 100644 index 000000000..47e1555ba --- /dev/null +++ b/spec/rust/tests/test_valid_fail_max_int.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_max_int::*; + +#[test] +fn test_valid_fail_max_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailMaxInt::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_min_int.rs b/spec/rust/tests/test_valid_fail_min_int.rs new file mode 100644 index 000000000..e314cd2b9 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_min_int.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_min_int::*; + +#[test] +fn test_valid_fail_min_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailMinInt::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationLessThanError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationLessThanError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_bytes.rs b/spec/rust/tests/test_valid_fail_range_bytes.rs new file mode 100644 index 000000000..e5222a89a --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_bytes.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_range_bytes::*; + +#[test] +fn test_valid_fail_range_bytes() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRangeBytes::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcBytesType)", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(CalcBytesType)"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_float.rs b/spec/rust/tests/test_valid_fail_range_float.rs new file mode 100644 index 000000000..eeae233c4 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_float.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_range_float::*; + +#[test] +fn test_valid_fail_range_float() { + let bytes = fs::read("../../src/floating_points.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRangeFloat::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationGreaterThanError(FloatMultiType(Width4,None))", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(FloatMultiType(Width4,None))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_int.rs b/spec/rust/tests/test_valid_fail_range_int.rs new file mode 100644 index 000000000..bdd7f5f9c --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_int.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_range_int::*; + +#[test] +fn test_valid_fail_range_int() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRangeInt::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); + } +} diff --git a/spec/rust/tests/test_valid_fail_range_str.rs b/spec/rust/tests/test_valid_fail_range_str.rs new file mode 100644 index 000000000..3cae89cf1 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_range_str.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_fail_range_str::*; + +#[test] +fn test_valid_fail_range_str() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRangeStr::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcStrType)", err); + } else { + panic!("no expected exception: ValidationGreaterThanError(CalcStrType)"); + } +} diff --git a/spec/rust/tests/test_valid_long.rs b/spec/rust/tests/test_valid_long.rs new file mode 100644 index 000000000..53c13e509 --- /dev/null +++ b/spec/rust/tests/test_valid_long.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_long::*; + +#[test] +fn test_valid_long() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidLong::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_valid_not_parsed_if.rs b/spec/rust/tests/test_valid_not_parsed_if.rs new file mode 100644 index 000000000..d9c4788b3 --- /dev/null +++ b/spec/rust/tests/test_valid_not_parsed_if.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_not_parsed_if::*; + +#[test] +fn test_valid_not_parsed_if() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidNotParsedIf::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_valid_optional_id.rs b/spec/rust/tests/test_valid_optional_id.rs new file mode 100644 index 000000000..55413fc32 --- /dev/null +++ b/spec/rust/tests/test_valid_optional_id.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_optional_id::*; + +#[test] +fn test_valid_optional_id() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidOptionalId::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_valid_short.rs b/spec/rust/tests/test_valid_short.rs new file mode 100644 index 000000000..ae9aea5d4 --- /dev/null +++ b/spec/rust/tests/test_valid_short.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_short::*; + +#[test] +fn test_valid_short() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidShort::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_valid_switch.rs b/spec/rust/tests/test_valid_switch.rs new file mode 100644 index 000000000..f12731749 --- /dev/null +++ b/spec/rust/tests/test_valid_switch.rs @@ -0,0 +1,25 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::valid_switch::*; + +#[test] +fn test_valid_switch() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidSwitch::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + +} diff --git a/spec/rust/tests/test_yaml_ints.rs b/spec/rust/tests/test_yaml_ints.rs new file mode 100644 index 000000000..ba10756d5 --- /dev/null +++ b/spec/rust/tests/test_yaml_ints.rs @@ -0,0 +1,29 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::yaml_ints::*; + +#[test] +fn test_yaml_ints() { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = YamlInts::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.test_u4_dec().expect("error reading"), 4294967295); + assert_eq!(*r.test_u4_hex().expect("error reading"), 4294967295); + assert_eq!(*r.test_u8_dec().expect("error reading"), 18446744073709551615); + assert_eq!(*r.test_u8_hex().expect("error reading"), 18446744073709551615); +} diff --git a/spec/rust/tests/test_zlib_surrounded.rs b/spec/rust/tests/test_zlib_surrounded.rs new file mode 100644 index 000000000..aec9cbda0 --- /dev/null +++ b/spec/rust/tests/test_zlib_surrounded.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::zlib_surrounded::*; + +#[test] +fn test_zlib_surrounded() { + let bytes = fs::read("../../src/zlib_surrounded.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ZlibSurrounded::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.zlib().num(), -1); +} diff --git a/spec/rust/tests/test_zlib_with_header_78.rs b/spec/rust/tests/test_zlib_with_header_78.rs new file mode 100644 index 000000000..1c1d20df7 --- /dev/null +++ b/spec/rust/tests/test_zlib_with_header_78.rs @@ -0,0 +1,26 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; +extern crate kaitai; +use self::kaitai::*; +#[path = "../formats/mod.rs"] mod formats; +use formats::zlib_with_header_78::*; + +#[test] +fn test_zlib_with_header_78() { + let bytes = fs::read("../../src/zlib_with_header_78.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ZlibWithHeader78::read_into(&_io, None, None); + let r : OptRc; + + if let Err(err) = res { + panic!("{:?}", err); + } else { + r = res.unwrap(); + } + + assert_eq!(*r.data(), vec![0x61u8, 0x20u8, 0x71u8, 0x75u8, 0x69u8, 0x63u8, 0x6bu8, 0x20u8, 0x62u8, 0x72u8, 0x6fu8, 0x77u8, 0x6eu8, 0x20u8, 0x66u8, 0x6fu8, 0x78u8, 0x20u8, 0x6au8, 0x75u8, 0x6du8, 0x70u8, 0x73u8, 0x20u8, 0x6fu8, 0x76u8, 0x65u8, 0x72u8]); +} diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index e415c3710..e783422c1 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -30,7 +30,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs importList.add("use std::fs;") importList.add("extern crate kaitai;") importList.add("use self::kaitai::*;") - importList.add("mod formats;") + importList.add("#[path = \"../formats/mod.rs\"] mod formats;") importList.add(s"${use_mod}formats::${spec.id}::*;") spec.extraImports.foreach{ name => importList.add(s"${use_mod}formats::$name::*;") } From 80ae4f285a78633126d9a02089e4cb10425faefc Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 14 Mar 2023 15:07:17 +0700 Subject: [PATCH 160/198] use formats that's generated by script. --- config | 2 +- spec/rust/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config b/config index bc4f01596..793344dd1 100644 --- a/config +++ b/config @@ -1,5 +1,5 @@ COMPILER_DIR=../compiler -FORMATS_KSY_DIR=formats_rust +FORMATS_KSY_DIR=formats FORMATS_COMPILED_DIR=compiled FORMATS_REPO_DIR=../formats diff --git a/spec/rust/build.rs b/spec/rust/build.rs index c7ecaaddb..376d424b0 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -12,7 +12,7 @@ pub fn path_exists(path: &Path) -> bool { } fn main() { - let source_path = Path::new("../../compiled"); + let source_path = Path::new("../../compiled/rust"); let destination_path = Path::new("./formats"); if !path_exists(destination_path) { From 8208031e719935153cc229ab15229d775a024c9c Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 14 Mar 2023 16:31:17 +0700 Subject: [PATCH 161/198] don't copy generated formats, that we don't support yet. --- spec/rust/build.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/spec/rust/build.rs b/spec/rust/build.rs index 376d424b0..21908c6a6 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -21,17 +21,25 @@ fn main() { }); } - let except_files = vec![ + let rm_except_files = vec![ "custom_fx_no_args.rs", "my_custom_fx.rs", "custom_fx.rs", ]; - remove_existing(destination_path, except_files).unwrap_or_else(|e| { + // we don't support this tests yet + let copy_except_files = vec![ + "nav_parent_switch_cast.rs", + "params_pass_array_struct.rs", + "params_pass_struct.rs", + "process_coerce_switch.rs", + ]; + + remove_existing(destination_path, rm_except_files).unwrap_or_else(|e| { println!("Unable to remove existing files under test: {}", e.to_string()); }); - copy_new(source_path, destination_path).unwrap_or_else(|e| { + copy_new(source_path, destination_path, copy_except_files).unwrap_or_else(|e| { println!("Unable to copy new files under test: {}", e.to_string()); }); @@ -55,7 +63,7 @@ fn remove_existing(destination_path: &Path, except_files: Vec<&str>) -> io::Resu Ok(()) } -fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { +fn copy_new(source_path: &Path, destination_path: &Path, except_files: Vec<&str>) -> io::Result<()> { let mut librs = fs::File::create(destination_path.join("mod.rs"))?; write!(librs, "#![allow(unused_parens)]\n")?; @@ -69,14 +77,17 @@ fn copy_new(source_path: &Path, destination_path: &Path) -> io::Result<()> { continue; } - if let Some(file_name) = path.file_name() { - fs::copy(path.clone(), destination_path.join(file_name))?; + let file_name = path.file_name().unwrap().to_os_string(); + if except_files.iter().find(|&&x| *x == file_name).is_none() { + fs::copy(path.clone(), destination_path.join(file_name.clone()))?; println!("copying {} to {}", path.as_path().display().to_string(), - destination_path.join(file_name).as_path().display().to_string()); + destination_path.join(file_name.clone()).as_path().display().to_string()); write!(librs, "pub mod {};\n", path.file_stem().unwrap().to_str().unwrap())?; println!("updating lib.rs with {}", path.file_stem().unwrap().to_str().unwrap()); + } else { + println!("skipping (not yet supported) {}", path.display().to_string()); } } From aa1d4edc0a0a45a8f38f64cd4479dce1745bf5ef Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 14 Mar 2023 16:33:20 +0700 Subject: [PATCH 162/198] revert. --- build-compiler | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-compiler b/build-compiler index 46e6f0ead..f40f9a17a 100755 --- a/build-compiler +++ b/build-compiler @@ -4,4 +4,4 @@ cd "$COMPILER_DIR" sbt compilerJVM/stage -#sbt compile fastOptJS +sbt compile fastOptJS From da1ffc107f4674c3389002feabe7ea9a35cc5014 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Tue, 19 Dec 2023 18:53:37 +0700 Subject: [PATCH 163/198] rust formats dir moved. More clean and correct way to use declarations. --- .gitignore | 3 +- spec/rust/build.rs | 66 ++++++++++++------- spec/rust/{formats => src}/custom_fx.rs | 8 +-- .../{formats => src}/custom_fx_no_args.rs | 0 spec/rust/src/lib.rs | 6 +- spec/rust/{formats => src}/my_custom_fx.rs | 10 +-- spec/rust/tests/test_bcd_user_type_be.rs | 3 +- spec/rust/tests/test_bcd_user_type_le.rs | 3 +- spec/rust/tests/test_bits_byte_aligned.rs | 3 +- spec/rust/tests/test_bits_enum.rs | 3 +- spec/rust/tests/test_bits_seq_endian_combo.rs | 3 +- spec/rust/tests/test_bits_shift_by_b32_le.rs | 3 +- spec/rust/tests/test_bits_shift_by_b64_le.rs | 3 +- .../rust/tests/test_bits_signed_res_b32_be.rs | 3 +- .../rust/tests/test_bits_signed_res_b32_le.rs | 3 +- .../tests/test_bits_signed_shift_b32_le.rs | 3 +- .../tests/test_bits_signed_shift_b64_le.rs | 3 +- spec/rust/tests/test_bits_simple.rs | 3 +- spec/rust/tests/test_bits_simple_le.rs | 3 +- spec/rust/tests/test_bits_unaligned_b32_be.rs | 3 +- spec/rust/tests/test_bits_unaligned_b32_le.rs | 3 +- spec/rust/tests/test_bits_unaligned_b64_be.rs | 3 +- spec/rust/tests/test_bits_unaligned_b64_le.rs | 3 +- spec/rust/tests/test_buffered_struct.rs | 3 +- spec/rust/tests/test_bytes_pad_term.rs | 3 +- spec/rust/tests/test_cast_nested.rs | 3 +- spec/rust/tests/test_cast_to_imported.rs | 16 +++-- spec/rust/tests/test_cast_to_top.rs | 3 +- spec/rust/tests/test_combine_bool.rs | 3 +- spec/rust/tests/test_combine_bytes.rs | 3 +- spec/rust/tests/test_combine_enum.rs | 3 +- spec/rust/tests/test_combine_str.rs | 3 +- spec/rust/tests/test_debug_0.rs | 3 +- spec/rust/tests/test_debug_array_user.rs | 3 +- spec/rust/tests/test_debug_switch_user.rs | 3 +- spec/rust/tests/test_default_big_endian.rs | 3 +- .../rust/tests/test_default_bit_endian_mod.rs | 3 +- .../test_default_endian_expr_exception.rs | 3 +- .../test_default_endian_expr_inherited.rs | 3 +- .../tests/test_default_endian_expr_is_be.rs | 3 +- .../tests/test_default_endian_expr_is_le.rs | 3 +- spec/rust/tests/test_default_endian_mod.rs | 3 +- spec/rust/tests/test_docstrings.rs | 3 +- spec/rust/tests/test_docstrings_docref.rs | 3 +- .../tests/test_docstrings_docref_multi.rs | 3 +- spec/rust/tests/test_enum_0.rs | 3 +- spec/rust/tests/test_enum_1.rs | 3 +- spec/rust/tests/test_enum_deep.rs | 3 +- spec/rust/tests/test_enum_deep_literals.rs | 3 +- spec/rust/tests/test_enum_fancy.rs | 3 +- spec/rust/tests/test_enum_for_unknown_id.rs | 3 +- spec/rust/tests/test_enum_if.rs | 3 +- spec/rust/tests/test_enum_import.rs | 7 +- spec/rust/tests/test_enum_int_range_s.rs | 3 +- spec/rust/tests/test_enum_int_range_u.rs | 3 +- spec/rust/tests/test_enum_invalid.rs | 3 +- spec/rust/tests/test_enum_long_range_s.rs | 3 +- spec/rust/tests/test_enum_long_range_u.rs | 3 +- spec/rust/tests/test_enum_negative.rs | 3 +- spec/rust/tests/test_enum_of_value_inst.rs | 3 +- spec/rust/tests/test_enum_to_i.rs | 3 +- .../tests/test_enum_to_i_class_border_1.rs | 5 +- spec/rust/tests/test_eof_exception_bytes.rs | 3 +- spec/rust/tests/test_eof_exception_u4.rs | 3 +- spec/rust/tests/test_eos_exception_bytes.rs | 3 +- spec/rust/tests/test_eos_exception_u4.rs | 3 +- spec/rust/tests/test_expr_0.rs | 3 +- spec/rust/tests/test_expr_1.rs | 3 +- spec/rust/tests/test_expr_2.rs | 3 +- spec/rust/tests/test_expr_3.rs | 3 +- spec/rust/tests/test_expr_array.rs | 3 +- spec/rust/tests/test_expr_bits.rs | 3 +- spec/rust/tests/test_expr_bytes_cmp.rs | 3 +- .../rust/tests/test_expr_bytes_non_literal.rs | 3 +- spec/rust/tests/test_expr_bytes_ops.rs | 3 +- spec/rust/tests/test_expr_calc_array_ops.rs | 3 +- spec/rust/tests/test_expr_enum.rs | 3 +- spec/rust/tests/test_expr_if_int_ops.rs | 3 +- spec/rust/tests/test_expr_int_div.rs | 7 +- spec/rust/tests/test_expr_io_eof.rs | 3 +- spec/rust/tests/test_expr_io_pos.rs | 3 +- spec/rust/tests/test_expr_mod.rs | 3 +- spec/rust/tests/test_expr_ops_parens.rs | 3 +- spec/rust/tests/test_expr_sizeof_type_0.rs | 3 +- spec/rust/tests/test_expr_sizeof_type_1.rs | 3 +- spec/rust/tests/test_expr_sizeof_value_0.rs | 3 +- .../tests/test_expr_sizeof_value_sized.rs | 3 +- spec/rust/tests/test_expr_str_encodings.rs | 3 +- spec/rust/tests/test_expr_str_ops.rs | 3 +- spec/rust/tests/test_fixed_contents.rs | 3 +- spec/rust/tests/test_fixed_struct.rs | 3 +- spec/rust/tests/test_float_to_i.rs | 3 +- spec/rust/tests/test_floating_points.rs | 3 +- spec/rust/tests/test_hello_world.rs | 3 +- spec/rust/tests/test_if_instances.rs | 3 +- spec/rust/tests/test_if_struct.rs | 3 +- spec/rust/tests/test_if_values.rs | 3 +- spec/rust/tests/test_imports0.rs | 5 +- spec/rust/tests/test_imports_abs.rs | 5 +- spec/rust/tests/test_imports_abs_abs.rs | 4 +- spec/rust/tests/test_imports_abs_rel.rs | 4 +- spec/rust/tests/test_imports_circular_a.rs | 12 ++-- spec/rust/tests/test_imports_rel_1.rs | 7 +- spec/rust/tests/test_index_sizes.rs | 3 +- spec/rust/tests/test_index_to_param_eos.rs | 3 +- spec/rust/tests/test_index_to_param_expr.rs | 3 +- spec/rust/tests/test_index_to_param_until.rs | 3 +- spec/rust/tests/test_instance_io_user.rs | 3 +- spec/rust/tests/test_instance_std.rs | 3 +- spec/rust/tests/test_instance_std_array.rs | 3 +- spec/rust/tests/test_instance_user_array.rs | 3 +- spec/rust/tests/test_integers.rs | 3 +- .../tests/test_integers_double_overflow.rs | 3 +- spec/rust/tests/test_integers_min_max.rs | 3 +- spec/rust/tests/test_io_local_var.rs | 3 +- spec/rust/tests/test_js_signed_right_shift.rs | 3 +- spec/rust/tests/test_meta_tags.rs | 3 +- spec/rust/tests/test_meta_xref.rs | 3 +- spec/rust/tests/test_multiple_use.rs | 3 +- spec/rust/tests/test_nav_parent.rs | 3 +- spec/rust/tests/test_nav_parent2.rs | 3 +- spec/rust/tests/test_nav_parent3.rs | 3 +- spec/rust/tests/test_nav_parent_false.rs | 3 +- spec/rust/tests/test_nav_parent_false2.rs | 3 +- spec/rust/tests/test_nav_parent_override.rs | 3 +- spec/rust/tests/test_nav_parent_switch.rs | 3 +- .../tests/test_nav_parent_vs_value_inst.rs | 3 +- spec/rust/tests/test_nav_root.rs | 3 +- spec/rust/tests/test_nested_same_name.rs | 3 +- spec/rust/tests/test_nested_same_name2.rs | 3 +- spec/rust/tests/test_nested_type_param.rs | 3 +- spec/rust/tests/test_nested_types.rs | 3 +- spec/rust/tests/test_nested_types2.rs | 3 +- spec/rust/tests/test_nested_types3.rs | 3 +- spec/rust/tests/test_non_standard.rs | 3 +- spec/rust/tests/test_opaque_external_type.rs | 3 +- .../test_opaque_external_type_02_parent.rs | 3 +- spec/rust/tests/test_opaque_with_param.rs | 4 +- spec/rust/tests/test_optional_id.rs | 3 +- .../tests/test_params_call_extra_parens.rs | 3 +- spec/rust/tests/test_params_call_short.rs | 3 +- spec/rust/tests/test_params_def.rs | 4 +- spec/rust/tests/test_params_enum.rs | 3 +- spec/rust/tests/test_params_pass_array_int.rs | 3 +- spec/rust/tests/test_params_pass_array_str.rs | 3 +- .../tests/test_params_pass_array_usertype.rs | 3 +- spec/rust/tests/test_params_pass_bool.rs | 3 +- spec/rust/tests/test_params_pass_usertype.rs | 3 +- spec/rust/tests/test_position_abs.rs | 3 +- spec/rust/tests/test_position_in_seq.rs | 3 +- spec/rust/tests/test_position_to_end.rs | 3 +- spec/rust/tests/test_process_coerce_bytes.rs | 3 +- .../tests/test_process_coerce_usertype1.rs | 3 +- .../tests/test_process_coerce_usertype2.rs | 3 +- spec/rust/tests/test_process_custom.rs | 3 +- .../rust/tests/test_process_custom_no_args.rs | 3 +- spec/rust/tests/test_process_repeat_bytes.rs | 3 +- .../tests/test_process_repeat_usertype.rs | 3 +- spec/rust/tests/test_process_rotate.rs | 3 +- spec/rust/tests/test_process_to_user.rs | 3 +- spec/rust/tests/test_process_xor4_const.rs | 3 +- spec/rust/tests/test_process_xor4_value.rs | 3 +- spec/rust/tests/test_process_xor_const.rs | 3 +- spec/rust/tests/test_process_xor_value.rs | 3 +- spec/rust/tests/test_recursive_one.rs | 3 +- spec/rust/tests/test_repeat_eos_bit.rs | 3 +- spec/rust/tests/test_repeat_eos_struct.rs | 12 ++-- spec/rust/tests/test_repeat_eos_u4.rs | 3 +- spec/rust/tests/test_repeat_n_struct.rs | 9 ++- spec/rust/tests/test_repeat_n_strz.rs | 3 +- spec/rust/tests/test_repeat_n_strz_double.rs | 3 +- .../test_repeat_until_calc_array_type.rs | 3 +- spec/rust/tests/test_repeat_until_complex.rs | 3 +- spec/rust/tests/test_repeat_until_s4.rs | 3 +- spec/rust/tests/test_repeat_until_sized.rs | 3 +- spec/rust/tests/test_str_encodings.rs | 3 +- spec/rust/tests/test_str_encodings_default.rs | 3 +- spec/rust/tests/test_str_encodings_utf16.rs | 3 +- spec/rust/tests/test_str_eos.rs | 3 +- spec/rust/tests/test_str_literals.rs | 3 +- spec/rust/tests/test_str_literals2.rs | 3 +- spec/rust/tests/test_str_pad_term.rs | 3 +- spec/rust/tests/test_str_pad_term_empty.rs | 3 +- spec/rust/tests/test_switch_bytearray.rs | 3 +- spec/rust/tests/test_switch_cast.rs | 3 +- spec/rust/tests/test_switch_else_only.rs | 3 +- spec/rust/tests/test_switch_integers.rs | 3 +- spec/rust/tests/test_switch_integers2.rs | 3 +- spec/rust/tests/test_switch_manual_enum.rs | 3 +- .../tests/test_switch_manual_enum_invalid.rs | 25 +++---- .../test_switch_manual_enum_invalid_else.rs | 32 ++++++--- spec/rust/tests/test_switch_manual_int.rs | 3 +- .../rust/tests/test_switch_manual_int_else.rs | 3 +- .../rust/tests/test_switch_manual_int_size.rs | 3 +- .../tests/test_switch_manual_int_size_else.rs | 3 +- .../tests/test_switch_manual_int_size_eos.rs | 53 +++++++++------ spec/rust/tests/test_switch_manual_str.rs | 3 +- .../rust/tests/test_switch_manual_str_else.rs | 3 +- spec/rust/tests/test_switch_multi_bool_ops.rs | 3 +- spec/rust/tests/test_switch_repeat_expr.rs | 3 +- .../tests/test_switch_repeat_expr_invalid.rs | 3 +- spec/rust/tests/test_term_bytes.rs | 3 +- spec/rust/tests/test_term_strz.rs | 3 +- spec/rust/tests/test_term_u1_val.rs | 3 +- spec/rust/tests/test_to_string_custom.rs | 3 +- spec/rust/tests/test_ts_packet_header.rs | 3 +- spec/rust/tests/test_type_int_unary_op.rs | 3 +- spec/rust/tests/test_type_ternary.rs | 3 +- .../rust/tests/test_type_ternary_2nd_falsy.rs | 38 +++++------ spec/rust/tests/test_type_ternary_opaque.rs | 3 +- spec/rust/tests/test_user_type.rs | 3 +- .../rust/tests/test_valid_eq_str_encodings.rs | 3 +- spec/rust/tests/test_valid_fail_anyof_int.rs | 3 +- spec/rust/tests/test_valid_fail_contents.rs | 3 +- spec/rust/tests/test_valid_fail_eq_bytes.rs | 3 +- spec/rust/tests/test_valid_fail_eq_int.rs | 3 +- spec/rust/tests/test_valid_fail_eq_str.rs | 3 +- spec/rust/tests/test_valid_fail_expr.rs | 3 +- spec/rust/tests/test_valid_fail_inst.rs | 3 +- spec/rust/tests/test_valid_fail_max_int.rs | 3 +- spec/rust/tests/test_valid_fail_min_int.rs | 3 +- .../rust/tests/test_valid_fail_range_bytes.rs | 3 +- .../rust/tests/test_valid_fail_range_float.rs | 3 +- spec/rust/tests/test_valid_fail_range_int.rs | 3 +- spec/rust/tests/test_valid_fail_range_str.rs | 3 +- spec/rust/tests/test_valid_long.rs | 3 +- spec/rust/tests/test_valid_not_parsed_if.rs | 3 +- spec/rust/tests/test_valid_optional_id.rs | 3 +- spec/rust/tests/test_valid_short.rs | 3 +- spec/rust/tests/test_valid_switch.rs | 3 +- spec/rust/tests/test_yaml_ints.rs | 3 +- spec/rust/tests/test_zlib_surrounded.rs | 3 +- spec/rust/tests/test_zlib_with_header_78.rs | 3 +- .../specgenerators/RustSG.scala | 5 +- 234 files changed, 402 insertions(+), 572 deletions(-) rename spec/rust/{formats => src}/custom_fx.rs (87%) rename spec/rust/{formats => src}/custom_fx_no_args.rs (100%) rename spec/rust/{formats => src}/my_custom_fx.rs (72%) diff --git a/.gitignore b/.gitignore index 801d6734f..e207b22bc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ spec/nim/bin # Rust compiled code, cargo and rls data spec/rust/Cargo.lock spec/rust/target/ -spec/rust/formats/ +spec/rust/src/formats/ +spec/rust/.vscode diff --git a/spec/rust/build.rs b/spec/rust/build.rs index 21908c6a6..eb023ba60 100644 --- a/spec/rust/build.rs +++ b/spec/rust/build.rs @@ -1,10 +1,8 @@ use std::{ - io::{ - self, - prelude::* - }, + ffi::OsStr, fs, - path::Path, ffi::OsStr + io::{self, prelude::*}, + path::Path, }; pub fn path_exists(path: &Path) -> bool { @@ -13,7 +11,7 @@ pub fn path_exists(path: &Path) -> bool { fn main() { let source_path = Path::new("../../compiled/rust"); - let destination_path = Path::new("./formats"); + let destination_path = Path::new("./src/formats"); if !path_exists(destination_path) { fs::create_dir(destination_path).unwrap_or_else(|e| { @@ -21,11 +19,7 @@ fn main() { }); } - let rm_except_files = vec![ - "custom_fx_no_args.rs", - "my_custom_fx.rs", - "custom_fx.rs", - ]; + let rm_except_files = vec![]; // we don't support this tests yet let copy_except_files = vec![ @@ -36,14 +30,20 @@ fn main() { ]; remove_existing(destination_path, rm_except_files).unwrap_or_else(|e| { - println!("Unable to remove existing files under test: {}", e.to_string()); + println!( + "Unable to remove existing files under test: {}", + e.to_string() + ); }); copy_new(source_path, destination_path, copy_except_files).unwrap_or_else(|e| { println!("Unable to copy new files under test: {}", e.to_string()); }); - println!("cargo:rerun-if-changed={}", source_path.display().to_string()); + println!( + "cargo:rerun-if-changed={}", + source_path.display().to_string() + ); } fn remove_existing(destination_path: &Path, except_files: Vec<&str>) -> io::Result<()> { @@ -59,11 +59,15 @@ fn remove_existing(destination_path: &Path, except_files: Vec<&str>) -> io::Resu println!("leaving {}", path.display().to_string()); } } - + Ok(()) } -fn copy_new(source_path: &Path, destination_path: &Path, except_files: Vec<&str>) -> io::Result<()> { +fn copy_new( + source_path: &Path, + destination_path: &Path, + except_files: Vec<&str>, +) -> io::Result<()> { let mut librs = fs::File::create(destination_path.join("mod.rs"))?; write!(librs, "#![allow(unused_parens)]\n")?; @@ -80,16 +84,32 @@ fn copy_new(source_path: &Path, destination_path: &Path, except_files: Vec<&str> let file_name = path.file_name().unwrap().to_os_string(); if except_files.iter().find(|&&x| *x == file_name).is_none() { fs::copy(path.clone(), destination_path.join(file_name.clone()))?; - println!("copying {} to {}", path.as_path().display().to_string(), - destination_path.join(file_name.clone()).as_path().display().to_string()); - - write!(librs, "pub mod {};\n", - path.file_stem().unwrap().to_str().unwrap())?; - println!("updating lib.rs with {}", path.file_stem().unwrap().to_str().unwrap()); + println!( + "copying {} to {}", + path.as_path().display().to_string(), + destination_path + .join(file_name.clone()) + .as_path() + .display() + .to_string() + ); + + write!( + librs, + "pub mod {};\n", + path.file_stem().unwrap().to_str().unwrap() + )?; + println!( + "updating lib.rs with {}", + path.file_stem().unwrap().to_str().unwrap() + ); } else { - println!("skipping (not yet supported) {}", path.display().to_string()); + println!( + "skipping (not yet supported) {}", + path.display().to_string() + ); } } - + Ok(()) } diff --git a/spec/rust/formats/custom_fx.rs b/spec/rust/src/custom_fx.rs similarity index 87% rename from spec/rust/formats/custom_fx.rs rename to spec/rust/src/custom_fx.rs index bdd12cba6..d4d218fc3 100644 --- a/spec/rust/formats/custom_fx.rs +++ b/spec/rust/src/custom_fx.rs @@ -1,10 +1,10 @@ extern crate kaitai; -use kaitai::CustomDecoder; + +#[allow(non_snake_case)] pub mod Nested { pub mod Deeply { - pub struct CustomFx { - } + pub struct CustomFx {} impl CustomFx { pub fn new(_p_key: u8) -> Self { @@ -21,4 +21,4 @@ pub mod Nested { } } } -} \ No newline at end of file +} diff --git a/spec/rust/formats/custom_fx_no_args.rs b/spec/rust/src/custom_fx_no_args.rs similarity index 100% rename from spec/rust/formats/custom_fx_no_args.rs rename to spec/rust/src/custom_fx_no_args.rs diff --git a/spec/rust/src/lib.rs b/spec/rust/src/lib.rs index 8b1a39374..825626cd9 100644 --- a/spec/rust/src/lib.rs +++ b/spec/rust/src/lib.rs @@ -1 +1,5 @@ -// empty +pub mod formats; + +pub mod my_custom_fx; +pub mod custom_fx; +pub mod custom_fx_no_args; diff --git a/spec/rust/formats/my_custom_fx.rs b/spec/rust/src/my_custom_fx.rs similarity index 72% rename from spec/rust/formats/my_custom_fx.rs rename to spec/rust/src/my_custom_fx.rs index c01a92577..787d33020 100644 --- a/spec/rust/formats/my_custom_fx.rs +++ b/spec/rust/src/my_custom_fx.rs @@ -6,11 +6,13 @@ pub struct MyCustomFx { } impl MyCustomFx { - pub fn new(p_key: u8, p_flag :bool, _p_some_bytes: &[u8]) -> Self { - if (p_flag) { + pub fn new(p_key: u8, p_flag: bool, _p_some_bytes: &[u8]) -> Self { + if p_flag { Self { key: p_key as i32 } } else { - Self { key: -(p_key as i32) } + Self { + key: -(p_key as i32), + } } } } @@ -23,4 +25,4 @@ impl CustomDecoder for MyCustomFx { } res } -} \ No newline at end of file +} diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs index ec8a3cde0..d114b5669 100644 --- a/spec/rust/tests/test_bcd_user_type_be.rs +++ b/spec/rust/tests/test_bcd_user_type_be.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bcd_user_type_be::*; +use rust::formats::bcd_user_type_be::*; #[test] fn test_bcd_user_type_be() { diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs index 31cb98dcf..badd13343 100644 --- a/spec/rust/tests/test_bcd_user_type_le.rs +++ b/spec/rust/tests/test_bcd_user_type_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bcd_user_type_le::*; +use rust::formats::bcd_user_type_le::*; #[test] fn test_bcd_user_type_le() { diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs index f41c1dd2f..2653cfbb0 100644 --- a/spec/rust/tests/test_bits_byte_aligned.rs +++ b/spec/rust/tests/test_bits_byte_aligned.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_byte_aligned::*; +use rust::formats::bits_byte_aligned::*; #[test] fn test_bits_byte_aligned() { diff --git a/spec/rust/tests/test_bits_enum.rs b/spec/rust/tests/test_bits_enum.rs index c430e9e51..531d0a1c8 100644 --- a/spec/rust/tests/test_bits_enum.rs +++ b/spec/rust/tests/test_bits_enum.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_enum::*; +use rust::formats::bits_enum::*; #[test] fn test_bits_enum() { diff --git a/spec/rust/tests/test_bits_seq_endian_combo.rs b/spec/rust/tests/test_bits_seq_endian_combo.rs index 50f1a76ce..5e931f5c5 100644 --- a/spec/rust/tests/test_bits_seq_endian_combo.rs +++ b/spec/rust/tests/test_bits_seq_endian_combo.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_seq_endian_combo::*; +use rust::formats::bits_seq_endian_combo::*; #[test] fn test_bits_seq_endian_combo() { diff --git a/spec/rust/tests/test_bits_shift_by_b32_le.rs b/spec/rust/tests/test_bits_shift_by_b32_le.rs index 5c512eba2..8e06f6461 100644 --- a/spec/rust/tests/test_bits_shift_by_b32_le.rs +++ b/spec/rust/tests/test_bits_shift_by_b32_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_shift_by_b32_le::*; +use rust::formats::bits_shift_by_b32_le::*; #[test] fn test_bits_shift_by_b32_le() { diff --git a/spec/rust/tests/test_bits_shift_by_b64_le.rs b/spec/rust/tests/test_bits_shift_by_b64_le.rs index 725891fef..014a0cc08 100644 --- a/spec/rust/tests/test_bits_shift_by_b64_le.rs +++ b/spec/rust/tests/test_bits_shift_by_b64_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_shift_by_b64_le::*; +use rust::formats::bits_shift_by_b64_le::*; #[test] fn test_bits_shift_by_b64_le() { diff --git a/spec/rust/tests/test_bits_signed_res_b32_be.rs b/spec/rust/tests/test_bits_signed_res_b32_be.rs index 64e1ab349..7843874c2 100644 --- a/spec/rust/tests/test_bits_signed_res_b32_be.rs +++ b/spec/rust/tests/test_bits_signed_res_b32_be.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_signed_res_b32_be::*; +use rust::formats::bits_signed_res_b32_be::*; #[test] fn test_bits_signed_res_b32_be() { diff --git a/spec/rust/tests/test_bits_signed_res_b32_le.rs b/spec/rust/tests/test_bits_signed_res_b32_le.rs index 59560ae6f..8ac7bb3ba 100644 --- a/spec/rust/tests/test_bits_signed_res_b32_le.rs +++ b/spec/rust/tests/test_bits_signed_res_b32_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_signed_res_b32_le::*; +use rust::formats::bits_signed_res_b32_le::*; #[test] fn test_bits_signed_res_b32_le() { diff --git a/spec/rust/tests/test_bits_signed_shift_b32_le.rs b/spec/rust/tests/test_bits_signed_shift_b32_le.rs index 70089eabe..337cccec6 100644 --- a/spec/rust/tests/test_bits_signed_shift_b32_le.rs +++ b/spec/rust/tests/test_bits_signed_shift_b32_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_signed_shift_b32_le::*; +use rust::formats::bits_signed_shift_b32_le::*; #[test] fn test_bits_signed_shift_b32_le() { diff --git a/spec/rust/tests/test_bits_signed_shift_b64_le.rs b/spec/rust/tests/test_bits_signed_shift_b64_le.rs index 4b72a1500..d216a6be6 100644 --- a/spec/rust/tests/test_bits_signed_shift_b64_le.rs +++ b/spec/rust/tests/test_bits_signed_shift_b64_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_signed_shift_b64_le::*; +use rust::formats::bits_signed_shift_b64_le::*; #[test] fn test_bits_signed_shift_b64_le() { diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs index 503f1abdb..e7af2c3bd 100644 --- a/spec/rust/tests/test_bits_simple.rs +++ b/spec/rust/tests/test_bits_simple.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_simple::*; +use rust::formats::bits_simple::*; #[test] fn test_bits_simple() { diff --git a/spec/rust/tests/test_bits_simple_le.rs b/spec/rust/tests/test_bits_simple_le.rs index ad5e77b94..333075207 100644 --- a/spec/rust/tests/test_bits_simple_le.rs +++ b/spec/rust/tests/test_bits_simple_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_simple_le::*; +use rust::formats::bits_simple_le::*; #[test] fn test_bits_simple_le() { diff --git a/spec/rust/tests/test_bits_unaligned_b32_be.rs b/spec/rust/tests/test_bits_unaligned_b32_be.rs index 8ace1910e..0fe8bd1a1 100644 --- a/spec/rust/tests/test_bits_unaligned_b32_be.rs +++ b/spec/rust/tests/test_bits_unaligned_b32_be.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_unaligned_b32_be::*; +use rust::formats::bits_unaligned_b32_be::*; #[test] fn test_bits_unaligned_b32_be() { diff --git a/spec/rust/tests/test_bits_unaligned_b32_le.rs b/spec/rust/tests/test_bits_unaligned_b32_le.rs index b0bb52c14..6fa6571f5 100644 --- a/spec/rust/tests/test_bits_unaligned_b32_le.rs +++ b/spec/rust/tests/test_bits_unaligned_b32_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_unaligned_b32_le::*; +use rust::formats::bits_unaligned_b32_le::*; #[test] fn test_bits_unaligned_b32_le() { diff --git a/spec/rust/tests/test_bits_unaligned_b64_be.rs b/spec/rust/tests/test_bits_unaligned_b64_be.rs index 1abdcbbf5..72570ceb4 100644 --- a/spec/rust/tests/test_bits_unaligned_b64_be.rs +++ b/spec/rust/tests/test_bits_unaligned_b64_be.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_unaligned_b64_be::*; +use rust::formats::bits_unaligned_b64_be::*; #[test] fn test_bits_unaligned_b64_be() { diff --git a/spec/rust/tests/test_bits_unaligned_b64_le.rs b/spec/rust/tests/test_bits_unaligned_b64_le.rs index de9e9d1bd..3552ab70d 100644 --- a/spec/rust/tests/test_bits_unaligned_b64_le.rs +++ b/spec/rust/tests/test_bits_unaligned_b64_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bits_unaligned_b64_le::*; +use rust::formats::bits_unaligned_b64_le::*; #[test] fn test_bits_unaligned_b64_le() { diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs index 4507be3db..f86817ee9 100644 --- a/spec/rust/tests/test_buffered_struct.rs +++ b/spec/rust/tests/test_buffered_struct.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::buffered_struct::*; +use rust::formats::buffered_struct::*; #[test] fn test_buffered_struct() { diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs index f05f9619d..0bb96dffc 100644 --- a/spec/rust/tests/test_bytes_pad_term.rs +++ b/spec/rust/tests/test_bytes_pad_term.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::bytes_pad_term::*; +use rust::formats::bytes_pad_term::*; #[test] fn test_bytes_pad_term() { diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs index bf53842bd..64c5fad32 100644 --- a/spec/rust/tests/test_cast_nested.rs +++ b/spec/rust/tests/test_cast_nested.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::cast_nested::*; +use rust::formats::cast_nested::*; #[test] fn test_cast_nested() { diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs index eaba76385..748311cec 100644 --- a/spec/rust/tests/test_cast_to_imported.rs +++ b/spec/rust/tests/test_cast_to_imported.rs @@ -1,15 +1,19 @@ -use std::fs; +// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::cast_to_imported::*; +use rust::formats::cast_to_imported::*; +use rust::formats::hello_world::*; #[test] fn test_cast_to_imported() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = CastToImported::read_into(&_io, None, None); + let res: KResult> = CastToImported::read_into(&_io, None, None); let r : OptRc; if let Err(err) = res { @@ -18,6 +22,6 @@ fn test_cast_to_imported() { r = res.unwrap(); } - assert_eq!(*(*(*r.one())).one(), 80); - assert_eq!(*(*(*r.one_casted().unwrap())).one(), 80); + assert_eq!(*r.one().one(), 80); + assert_eq!(*r.one_casted().expect("error reading").one(), 80); } diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs index 10a561763..6efa0635f 100644 --- a/spec/rust/tests/test_cast_to_top.rs +++ b/spec/rust/tests/test_cast_to_top.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::cast_to_top::*; +use rust::formats::cast_to_top::*; #[test] fn test_cast_to_top() { diff --git a/spec/rust/tests/test_combine_bool.rs b/spec/rust/tests/test_combine_bool.rs index 21ac62517..308c2da95 100644 --- a/spec/rust/tests/test_combine_bool.rs +++ b/spec/rust/tests/test_combine_bool.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::combine_bool::*; +use rust::formats::combine_bool::*; #[test] fn test_combine_bool() { diff --git a/spec/rust/tests/test_combine_bytes.rs b/spec/rust/tests/test_combine_bytes.rs index a06322f08..69b7aa78a 100644 --- a/spec/rust/tests/test_combine_bytes.rs +++ b/spec/rust/tests/test_combine_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::combine_bytes::*; +use rust::formats::combine_bytes::*; #[test] fn test_combine_bytes() { diff --git a/spec/rust/tests/test_combine_enum.rs b/spec/rust/tests/test_combine_enum.rs index 771534f90..09dc3fd90 100644 --- a/spec/rust/tests/test_combine_enum.rs +++ b/spec/rust/tests/test_combine_enum.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::combine_enum::*; +use rust::formats::combine_enum::*; #[test] fn test_combine_enum() { diff --git a/spec/rust/tests/test_combine_str.rs b/spec/rust/tests/test_combine_str.rs index 3d3ea2d52..e8bd4433b 100644 --- a/spec/rust/tests/test_combine_str.rs +++ b/spec/rust/tests/test_combine_str.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::combine_str::*; +use rust::formats::combine_str::*; #[test] fn test_combine_str() { diff --git a/spec/rust/tests/test_debug_0.rs b/spec/rust/tests/test_debug_0.rs index 0ca392ee3..30af7751d 100644 --- a/spec/rust/tests/test_debug_0.rs +++ b/spec/rust/tests/test_debug_0.rs @@ -1,8 +1,7 @@ #![allow(dead_code)] extern crate kaitai; -#[path = "../formats/mod.rs"] mod formats; -use formats::debug_0::*; +use rust::formats::debug_0::*; #[test] fn basic_parse() { diff --git a/spec/rust/tests/test_debug_array_user.rs b/spec/rust/tests/test_debug_array_user.rs index fb7b0f254..219ef080c 100644 --- a/spec/rust/tests/test_debug_array_user.rs +++ b/spec/rust/tests/test_debug_array_user.rs @@ -3,8 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::debug_array_user::*; +use rust::formats::debug_array_user::*; #[test] fn basic_parse() { diff --git a/spec/rust/tests/test_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs index 203a73a27..7ab2c6f01 100644 --- a/spec/rust/tests/test_debug_switch_user.rs +++ b/spec/rust/tests/test_debug_switch_user.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::debug_switch_user::*; +use rust::formats::debug_switch_user::*; #[test] fn test_debug_switch_user() { diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs index c762e1a08..0d0501b39 100644 --- a/spec/rust/tests/test_default_big_endian.rs +++ b/spec/rust/tests/test_default_big_endian.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::default_big_endian::*; +use rust::formats::default_big_endian::*; #[test] fn test_default_big_endian() { diff --git a/spec/rust/tests/test_default_bit_endian_mod.rs b/spec/rust/tests/test_default_bit_endian_mod.rs index a4cde8693..51e2665e6 100644 --- a/spec/rust/tests/test_default_bit_endian_mod.rs +++ b/spec/rust/tests/test_default_bit_endian_mod.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::default_bit_endian_mod::*; +use rust::formats::default_bit_endian_mod::*; #[test] fn test_default_bit_endian_mod() { diff --git a/spec/rust/tests/test_default_endian_expr_exception.rs b/spec/rust/tests/test_default_endian_expr_exception.rs index 8873a096a..55bc99e37 100644 --- a/spec/rust/tests/test_default_endian_expr_exception.rs +++ b/spec/rust/tests/test_default_endian_expr_exception.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::default_endian_expr_exception::*; +use rust::formats::default_endian_expr_exception::*; #[test] fn test_default_endian_expr_exception() { diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs index 83a2bcdaa..144c8a165 100644 --- a/spec/rust/tests/test_default_endian_expr_inherited.rs +++ b/spec/rust/tests/test_default_endian_expr_inherited.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::default_endian_expr_inherited::*; +use rust::formats::default_endian_expr_inherited::*; #[test] fn test_default_endian_expr_inherited() { diff --git a/spec/rust/tests/test_default_endian_expr_is_be.rs b/spec/rust/tests/test_default_endian_expr_is_be.rs index fc6553a31..256cec078 100644 --- a/spec/rust/tests/test_default_endian_expr_is_be.rs +++ b/spec/rust/tests/test_default_endian_expr_is_be.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::default_endian_expr_is_be::*; +use rust::formats::default_endian_expr_is_be::*; #[test] fn test_default_endian_expr_is_be() { diff --git a/spec/rust/tests/test_default_endian_expr_is_le.rs b/spec/rust/tests/test_default_endian_expr_is_le.rs index e7eaf39fb..70a473c39 100644 --- a/spec/rust/tests/test_default_endian_expr_is_le.rs +++ b/spec/rust/tests/test_default_endian_expr_is_le.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::default_endian_expr_is_le::*; +use rust::formats::default_endian_expr_is_le::*; #[test] fn test_default_endian_expr_is_le() { diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs index 8db211865..bbfdf7e2a 100644 --- a/spec/rust/tests/test_default_endian_mod.rs +++ b/spec/rust/tests/test_default_endian_mod.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::default_endian_mod::*; +use rust::formats::default_endian_mod::*; #[test] fn test_default_endian_mod() { diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs index a7d3d78b4..177a2d09f 100644 --- a/spec/rust/tests/test_docstrings.rs +++ b/spec/rust/tests/test_docstrings.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::docstrings::*; +use rust::formats::docstrings::*; #[test] fn test_docstrings() { diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs index af461dd81..dfa7b840f 100644 --- a/spec/rust/tests/test_docstrings_docref.rs +++ b/spec/rust/tests/test_docstrings_docref.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::docstrings_docref::*; +use rust::formats::docstrings_docref::*; #[test] fn test_docstrings_docref() { diff --git a/spec/rust/tests/test_docstrings_docref_multi.rs b/spec/rust/tests/test_docstrings_docref_multi.rs index 2767da3f5..416ec7854 100644 --- a/spec/rust/tests/test_docstrings_docref_multi.rs +++ b/spec/rust/tests/test_docstrings_docref_multi.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::docstrings_docref_multi::*; +use rust::formats::docstrings_docref_multi::*; #[test] fn test_docstrings_docref_multi() { diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs index 06cbcd4f3..a3bb16aed 100644 --- a/spec/rust/tests/test_enum_0.rs +++ b/spec/rust/tests/test_enum_0.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_0::*; +use rust::formats::enum_0::*; #[test] fn test_enum_0() { diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs index 01fbd78a2..fd94aef43 100644 --- a/spec/rust/tests/test_enum_1.rs +++ b/spec/rust/tests/test_enum_1.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_1::*; +use rust::formats::enum_1::*; #[test] fn test_enum_1() { diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs index 3e77f5212..60b34b861 100644 --- a/spec/rust/tests/test_enum_deep.rs +++ b/spec/rust/tests/test_enum_deep.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_deep::*; +use rust::formats::enum_deep::*; #[test] fn test_enum_deep() { diff --git a/spec/rust/tests/test_enum_deep_literals.rs b/spec/rust/tests/test_enum_deep_literals.rs index a90b9c5d3..fc3fae705 100644 --- a/spec/rust/tests/test_enum_deep_literals.rs +++ b/spec/rust/tests/test_enum_deep_literals.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_deep_literals::*; +use rust::formats::enum_deep_literals::*; #[test] fn test_enum_deep_literals() { diff --git a/spec/rust/tests/test_enum_fancy.rs b/spec/rust/tests/test_enum_fancy.rs index 5296a3147..4ce265c29 100644 --- a/spec/rust/tests/test_enum_fancy.rs +++ b/spec/rust/tests/test_enum_fancy.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_fancy::*; +use rust::formats::enum_fancy::*; #[test] fn test_enum_fancy() { diff --git a/spec/rust/tests/test_enum_for_unknown_id.rs b/spec/rust/tests/test_enum_for_unknown_id.rs index 2c4dd2411..6794267e4 100644 --- a/spec/rust/tests/test_enum_for_unknown_id.rs +++ b/spec/rust/tests/test_enum_for_unknown_id.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_for_unknown_id::*; +use rust::formats::enum_for_unknown_id::*; #[test] fn test_enum_for_unknown_id() { diff --git a/spec/rust/tests/test_enum_if.rs b/spec/rust/tests/test_enum_if.rs index 8aee100a7..408a7a3c3 100644 --- a/spec/rust/tests/test_enum_if.rs +++ b/spec/rust/tests/test_enum_if.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_if::*; +use rust::formats::enum_if::*; #[test] fn test_enum_if() { diff --git a/spec/rust/tests/test_enum_import.rs b/spec/rust/tests/test_enum_import.rs index 825b9225b..925beb8a8 100644 --- a/spec/rust/tests/test_enum_import.rs +++ b/spec/rust/tests/test_enum_import.rs @@ -6,10 +6,9 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_import::*; -use formats::enum_0::*; -use formats::enum_deep::*; +use rust::formats::enum_import::*; +use rust::formats::enum_0::*; +use rust::formats::enum_deep::*; #[test] fn test_enum_import() { diff --git a/spec/rust/tests/test_enum_int_range_s.rs b/spec/rust/tests/test_enum_int_range_s.rs index 438ab69ce..6aea1a474 100644 --- a/spec/rust/tests/test_enum_int_range_s.rs +++ b/spec/rust/tests/test_enum_int_range_s.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_int_range_s::*; +use rust::formats::enum_int_range_s::*; #[test] fn test_enum_int_range_s() { diff --git a/spec/rust/tests/test_enum_int_range_u.rs b/spec/rust/tests/test_enum_int_range_u.rs index 99a40a48d..f1ff0fea7 100644 --- a/spec/rust/tests/test_enum_int_range_u.rs +++ b/spec/rust/tests/test_enum_int_range_u.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_int_range_u::*; +use rust::formats::enum_int_range_u::*; #[test] fn test_enum_int_range_u() { diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs index b791a7b1b..f29ac1471 100644 --- a/spec/rust/tests/test_enum_invalid.rs +++ b/spec/rust/tests/test_enum_invalid.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_invalid::*; +use rust::formats::enum_invalid::*; #[test] fn test_enum_invalid() { diff --git a/spec/rust/tests/test_enum_long_range_s.rs b/spec/rust/tests/test_enum_long_range_s.rs index 824d3bd51..35accae52 100644 --- a/spec/rust/tests/test_enum_long_range_s.rs +++ b/spec/rust/tests/test_enum_long_range_s.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_long_range_s::*; +use rust::formats::enum_long_range_s::*; #[test] fn test_enum_long_range_s() { diff --git a/spec/rust/tests/test_enum_long_range_u.rs b/spec/rust/tests/test_enum_long_range_u.rs index 9ffa9a978..e4b9290d4 100644 --- a/spec/rust/tests/test_enum_long_range_u.rs +++ b/spec/rust/tests/test_enum_long_range_u.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_long_range_u::*; +use rust::formats::enum_long_range_u::*; #[test] fn test_enum_long_range_u() { diff --git a/spec/rust/tests/test_enum_negative.rs b/spec/rust/tests/test_enum_negative.rs index d22658c3c..7ff31a2cb 100644 --- a/spec/rust/tests/test_enum_negative.rs +++ b/spec/rust/tests/test_enum_negative.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_negative::*; +use rust::formats::enum_negative::*; #[test] fn test_enum_negative() { diff --git a/spec/rust/tests/test_enum_of_value_inst.rs b/spec/rust/tests/test_enum_of_value_inst.rs index 25e98eb65..aea61a179 100644 --- a/spec/rust/tests/test_enum_of_value_inst.rs +++ b/spec/rust/tests/test_enum_of_value_inst.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_of_value_inst::*; +use rust::formats::enum_of_value_inst::*; #[test] fn test_enum_of_value_inst() { diff --git a/spec/rust/tests/test_enum_to_i.rs b/spec/rust/tests/test_enum_to_i.rs index cb2239090..598aee8bc 100644 --- a/spec/rust/tests/test_enum_to_i.rs +++ b/spec/rust/tests/test_enum_to_i.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_to_i::*; +use rust::formats::enum_to_i::*; #[test] fn test_enum_to_i() { diff --git a/spec/rust/tests/test_enum_to_i_class_border_1.rs b/spec/rust/tests/test_enum_to_i_class_border_1.rs index cab37ab4e..76fe238bf 100644 --- a/spec/rust/tests/test_enum_to_i_class_border_1.rs +++ b/spec/rust/tests/test_enum_to_i_class_border_1.rs @@ -6,9 +6,8 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::enum_to_i_class_border_1::*; -use formats::enum_to_i_class_border_2::*; +use rust::formats::enum_to_i_class_border_1::*; +use rust::formats::enum_to_i_class_border_2::*; #[test] fn test_enum_to_i_class_border_1() { diff --git a/spec/rust/tests/test_eof_exception_bytes.rs b/spec/rust/tests/test_eof_exception_bytes.rs index 239542414..916a858b1 100644 --- a/spec/rust/tests/test_eof_exception_bytes.rs +++ b/spec/rust/tests/test_eof_exception_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::eof_exception_bytes::*; +use rust::formats::eof_exception_bytes::*; #[test] fn test_eof_exception_bytes() { diff --git a/spec/rust/tests/test_eof_exception_u4.rs b/spec/rust/tests/test_eof_exception_u4.rs index 9f8e1befd..9f9c67963 100644 --- a/spec/rust/tests/test_eof_exception_u4.rs +++ b/spec/rust/tests/test_eof_exception_u4.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::eof_exception_u4::*; +use rust::formats::eof_exception_u4::*; #[test] fn test_eof_exception_u4() { diff --git a/spec/rust/tests/test_eos_exception_bytes.rs b/spec/rust/tests/test_eos_exception_bytes.rs index 4673a4424..aaa5b80f3 100644 --- a/spec/rust/tests/test_eos_exception_bytes.rs +++ b/spec/rust/tests/test_eos_exception_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::eos_exception_bytes::*; +use rust::formats::eos_exception_bytes::*; #[test] fn test_eos_exception_bytes() { diff --git a/spec/rust/tests/test_eos_exception_u4.rs b/spec/rust/tests/test_eos_exception_u4.rs index 8d1b543cf..c5519254d 100644 --- a/spec/rust/tests/test_eos_exception_u4.rs +++ b/spec/rust/tests/test_eos_exception_u4.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::eos_exception_u4::*; +use rust::formats::eos_exception_u4::*; #[test] fn test_eos_exception_u4() { diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index 6b6c740f3..201797888 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_0::*; +use rust::formats::expr_0::*; #[test] fn test_expr_0() { diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index ed60bd31e..f6e5f6b0b 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_1::*; +use rust::formats::expr_1::*; #[test] fn test_expr_1() { diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs index 40905743e..9ec82a8c2 100644 --- a/spec/rust/tests/test_expr_2.rs +++ b/spec/rust/tests/test_expr_2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_2::*; +use rust::formats::expr_2::*; #[test] fn test_expr_2() { diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs index c4471a04d..3e8c583ac 100644 --- a/spec/rust/tests/test_expr_3.rs +++ b/spec/rust/tests/test_expr_3.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_3::*; +use rust::formats::expr_3::*; #[test] fn test_expr_3() { diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs index 054002a38..f47d882c3 100644 --- a/spec/rust/tests/test_expr_array.rs +++ b/spec/rust/tests/test_expr_array.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_array::*; +use rust::formats::expr_array::*; #[test] fn test_expr_array() { diff --git a/spec/rust/tests/test_expr_bits.rs b/spec/rust/tests/test_expr_bits.rs index 23bdbea0c..72eca5d1c 100644 --- a/spec/rust/tests/test_expr_bits.rs +++ b/spec/rust/tests/test_expr_bits.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_bits::*; +use rust::formats::expr_bits::*; #[test] fn test_expr_bits() { diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs index b777679cb..53b4c725c 100644 --- a/spec/rust/tests/test_expr_bytes_cmp.rs +++ b/spec/rust/tests/test_expr_bytes_cmp.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_bytes_cmp::*; +use rust::formats::expr_bytes_cmp::*; #[test] fn test_expr_bytes_cmp() { diff --git a/spec/rust/tests/test_expr_bytes_non_literal.rs b/spec/rust/tests/test_expr_bytes_non_literal.rs index 5c5a0ac4d..3b9fcbc5f 100644 --- a/spec/rust/tests/test_expr_bytes_non_literal.rs +++ b/spec/rust/tests/test_expr_bytes_non_literal.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_bytes_non_literal::*; +use rust::formats::expr_bytes_non_literal::*; #[test] fn test_expr_bytes_non_literal() { diff --git a/spec/rust/tests/test_expr_bytes_ops.rs b/spec/rust/tests/test_expr_bytes_ops.rs index f62ec1230..6115755ae 100644 --- a/spec/rust/tests/test_expr_bytes_ops.rs +++ b/spec/rust/tests/test_expr_bytes_ops.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_bytes_ops::*; +use rust::formats::expr_bytes_ops::*; #[test] fn test_expr_bytes_ops() { diff --git a/spec/rust/tests/test_expr_calc_array_ops.rs b/spec/rust/tests/test_expr_calc_array_ops.rs index 92c6ebb6a..91666ec7f 100644 --- a/spec/rust/tests/test_expr_calc_array_ops.rs +++ b/spec/rust/tests/test_expr_calc_array_ops.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_calc_array_ops::*; +use rust::formats::expr_calc_array_ops::*; #[test] fn test_expr_calc_array_ops() { diff --git a/spec/rust/tests/test_expr_enum.rs b/spec/rust/tests/test_expr_enum.rs index c8310b137..cab4f31a4 100644 --- a/spec/rust/tests/test_expr_enum.rs +++ b/spec/rust/tests/test_expr_enum.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_enum::*; +use rust::formats::expr_enum::*; #[test] fn test_expr_enum() { diff --git a/spec/rust/tests/test_expr_if_int_ops.rs b/spec/rust/tests/test_expr_if_int_ops.rs index 7a263285e..d43225e67 100644 --- a/spec/rust/tests/test_expr_if_int_ops.rs +++ b/spec/rust/tests/test_expr_if_int_ops.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_if_int_ops::*; +use rust::formats::expr_if_int_ops::*; #[test] fn test_expr_if_int_ops() { diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index 7f5c048f2..e9c34832b 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -2,19 +2,16 @@ #![allow(unused_assignments)] #![allow(overflowing_literals)] use std::fs; - extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_int_div::*; - +use rust::formats::expr_int_div::*; #[test] fn test_expr_int_div() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ExprIntDiv::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_expr_io_eof.rs b/spec/rust/tests/test_expr_io_eof.rs index 5f61befa0..d8c2bc93d 100644 --- a/spec/rust/tests/test_expr_io_eof.rs +++ b/spec/rust/tests/test_expr_io_eof.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_io_eof::*; +use rust::formats::expr_io_eof::*; #[test] fn test_expr_io_eof() { diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs index 0a800b047..492e3f82e 100644 --- a/spec/rust/tests/test_expr_io_pos.rs +++ b/spec/rust/tests/test_expr_io_pos.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_io_pos::*; +use rust::formats::expr_io_pos::*; #[test] fn test_expr_io_pos() { diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs index 6daa02c33..f538a8edf 100644 --- a/spec/rust/tests/test_expr_mod.rs +++ b/spec/rust/tests/test_expr_mod.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_mod::*; +use rust::formats::expr_mod::*; #[test] fn test_expr_mod() { diff --git a/spec/rust/tests/test_expr_ops_parens.rs b/spec/rust/tests/test_expr_ops_parens.rs index 6c8829ee6..a1c74288d 100644 --- a/spec/rust/tests/test_expr_ops_parens.rs +++ b/spec/rust/tests/test_expr_ops_parens.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_ops_parens::*; +use rust::formats::expr_ops_parens::*; #[test] fn test_expr_ops_parens() { diff --git a/spec/rust/tests/test_expr_sizeof_type_0.rs b/spec/rust/tests/test_expr_sizeof_type_0.rs index 0d8952ee8..7d3a52ee4 100644 --- a/spec/rust/tests/test_expr_sizeof_type_0.rs +++ b/spec/rust/tests/test_expr_sizeof_type_0.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_sizeof_type_0::*; +use rust::formats::expr_sizeof_type_0::*; #[test] fn test_expr_sizeof_type_0() { diff --git a/spec/rust/tests/test_expr_sizeof_type_1.rs b/spec/rust/tests/test_expr_sizeof_type_1.rs index 6d36d5ce4..4b1a87c13 100644 --- a/spec/rust/tests/test_expr_sizeof_type_1.rs +++ b/spec/rust/tests/test_expr_sizeof_type_1.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_sizeof_type_1::*; +use rust::formats::expr_sizeof_type_1::*; #[test] fn test_expr_sizeof_type_1() { diff --git a/spec/rust/tests/test_expr_sizeof_value_0.rs b/spec/rust/tests/test_expr_sizeof_value_0.rs index cf35930a4..593f6b49c 100644 --- a/spec/rust/tests/test_expr_sizeof_value_0.rs +++ b/spec/rust/tests/test_expr_sizeof_value_0.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_sizeof_value_0::*; +use rust::formats::expr_sizeof_value_0::*; #[test] fn test_expr_sizeof_value_0() { diff --git a/spec/rust/tests/test_expr_sizeof_value_sized.rs b/spec/rust/tests/test_expr_sizeof_value_sized.rs index c765521de..452727e78 100644 --- a/spec/rust/tests/test_expr_sizeof_value_sized.rs +++ b/spec/rust/tests/test_expr_sizeof_value_sized.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_sizeof_value_sized::*; +use rust::formats::expr_sizeof_value_sized::*; #[test] fn test_expr_sizeof_value_sized() { diff --git a/spec/rust/tests/test_expr_str_encodings.rs b/spec/rust/tests/test_expr_str_encodings.rs index f86784c73..c659b93cb 100644 --- a/spec/rust/tests/test_expr_str_encodings.rs +++ b/spec/rust/tests/test_expr_str_encodings.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_str_encodings::*; +use rust::formats::expr_str_encodings::*; #[test] fn test_expr_str_encodings() { diff --git a/spec/rust/tests/test_expr_str_ops.rs b/spec/rust/tests/test_expr_str_ops.rs index 6bf8727c1..910b7cd54 100644 --- a/spec/rust/tests/test_expr_str_ops.rs +++ b/spec/rust/tests/test_expr_str_ops.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::expr_str_ops::*; +use rust::formats::expr_str_ops::*; #[test] fn test_expr_str_ops() { diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs index 35570ad47..550f9d28a 100644 --- a/spec/rust/tests/test_fixed_contents.rs +++ b/spec/rust/tests/test_fixed_contents.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::fixed_contents::*; +use rust::formats::fixed_contents::*; #[test] fn test_fixed_contents() { diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs index 716e12a1c..888694047 100644 --- a/spec/rust/tests/test_fixed_struct.rs +++ b/spec/rust/tests/test_fixed_struct.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::fixed_struct::*; +use rust::formats::fixed_struct::*; #[test] fn test_fixed_struct() { diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs index 95b82bd6c..58aede007 100644 --- a/spec/rust/tests/test_float_to_i.rs +++ b/spec/rust/tests/test_float_to_i.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::float_to_i::*; +use rust::formats::float_to_i::*; #[test] fn test_float_to_i() { diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs index ff084a725..5904e494c 100644 --- a/spec/rust/tests/test_floating_points.rs +++ b/spec/rust/tests/test_floating_points.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::floating_points::*; +use rust::formats::floating_points::*; #[test] fn test_floating_points() { diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs index c7aa6220a..45d836956 100644 --- a/spec/rust/tests/test_hello_world.rs +++ b/spec/rust/tests/test_hello_world.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::hello_world::*; +use rust::formats::hello_world::*; #[test] fn test_hello_world() { diff --git a/spec/rust/tests/test_if_instances.rs b/spec/rust/tests/test_if_instances.rs index 04d889232..ad5ff4228 100644 --- a/spec/rust/tests/test_if_instances.rs +++ b/spec/rust/tests/test_if_instances.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::if_instances::*; +use rust::formats::if_instances::*; #[test] fn test_if_instances() { diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs index 0e78aa648..613b5a40f 100644 --- a/spec/rust/tests/test_if_struct.rs +++ b/spec/rust/tests/test_if_struct.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::if_struct::*; +use rust::formats::if_struct::*; #[test] fn test_if_struct() { diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs index 81957fe01..672a83f8e 100644 --- a/spec/rust/tests/test_if_values.rs +++ b/spec/rust/tests/test_if_values.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::if_values::*; +use rust::formats::if_values::*; #[test] fn test_if_values() { diff --git a/spec/rust/tests/test_imports0.rs b/spec/rust/tests/test_imports0.rs index 6250ff12c..4540d040b 100644 --- a/spec/rust/tests/test_imports0.rs +++ b/spec/rust/tests/test_imports0.rs @@ -6,9 +6,8 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::imports0::*; -use formats::hello_world::*; +use rust::formats::imports0::*; +use rust::formats::hello_world::*; #[test] fn test_imports0() { diff --git a/spec/rust/tests/test_imports_abs.rs b/spec/rust/tests/test_imports_abs.rs index 3f2a60665..4d09fb5d1 100644 --- a/spec/rust/tests/test_imports_abs.rs +++ b/spec/rust/tests/test_imports_abs.rs @@ -6,9 +6,8 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::imports_abs::*; -use formats::vlq_base128_le::*; +use rust::formats::imports_abs::*; +use rust::formats::vlq_base128_le::*; #[test] fn test_imports_abs() { diff --git a/spec/rust/tests/test_imports_abs_abs.rs b/spec/rust/tests/test_imports_abs_abs.rs index c8278ebbc..ed6d90692 100644 --- a/spec/rust/tests/test_imports_abs_abs.rs +++ b/spec/rust/tests/test_imports_abs_abs.rs @@ -2,9 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::imports_abs_abs::*; - +use rust::formats::imports_abs_abs::*; #[test] fn test_params_def() { diff --git a/spec/rust/tests/test_imports_abs_rel.rs b/spec/rust/tests/test_imports_abs_rel.rs index 96008056d..16b48c175 100644 --- a/spec/rust/tests/test_imports_abs_rel.rs +++ b/spec/rust/tests/test_imports_abs_rel.rs @@ -2,9 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::imports_abs_rel::*; - +use rust::formats::imports_abs_rel::*; #[test] fn test_imports_abs_rel() { diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index 95df4d275..63df1a334 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -1,16 +1,18 @@ +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] use std::fs; - extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::imports_circular_a::*; +use rust::formats::imports_circular_a::*; +use rust::formats::imports_circular_b::*; #[test] fn test_imports_circular_a() { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = ImportsCircularA::read_into(&_io, None, None); - let r : OptRc; + let res: KResult> = ImportsCircularA::read_into(&_io, None, None); + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs index 9c455ef66..d62d7ca66 100644 --- a/spec/rust/tests/test_imports_rel_1.rs +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -6,10 +6,9 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::imports_rel_1::*; -use formats::imported_1::*; -use formats::imported_2::*; +use rust::formats::imports_rel_1::*; +use rust::formats::imported_1::*; +use rust::formats::imported_2::*; #[test] fn test_imports_rel_1() { diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs index 0e7e60b75..acfad6f1c 100644 --- a/spec/rust/tests/test_index_sizes.rs +++ b/spec/rust/tests/test_index_sizes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::index_sizes::*; +use rust::formats::index_sizes::*; #[test] fn test_index_sizes() { diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs index 1ac5c578b..425fd1453 100644 --- a/spec/rust/tests/test_index_to_param_eos.rs +++ b/spec/rust/tests/test_index_to_param_eos.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::index_to_param_eos::*; +use rust::formats::index_to_param_eos::*; #[test] fn test_index_to_param_eos() { diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs index ea9e4c098..33148c8f1 100644 --- a/spec/rust/tests/test_index_to_param_expr.rs +++ b/spec/rust/tests/test_index_to_param_expr.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::index_to_param_expr::*; +use rust::formats::index_to_param_expr::*; #[test] fn test_index_to_param_expr() { diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs index a73ac96cd..86ceac65e 100644 --- a/spec/rust/tests/test_index_to_param_until.rs +++ b/spec/rust/tests/test_index_to_param_until.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::index_to_param_until::*; +use rust::formats::index_to_param_until::*; #[test] fn test_index_to_param_until() { diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs index 2c3dde723..c2df78bdb 100644 --- a/spec/rust/tests/test_instance_io_user.rs +++ b/spec/rust/tests/test_instance_io_user.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::instance_io_user::*; +use rust::formats::instance_io_user::*; #[test] fn test_instance_io_user() { diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs index 14d6e54d6..497087a88 100644 --- a/spec/rust/tests/test_instance_std.rs +++ b/spec/rust/tests/test_instance_std.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::instance_std::*; +use rust::formats::instance_std::*; #[test] fn test_instance_std() { diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs index 8274fe565..2389cf179 100644 --- a/spec/rust/tests/test_instance_std_array.rs +++ b/spec/rust/tests/test_instance_std_array.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::instance_std_array::*; +use rust::formats::instance_std_array::*; #[test] fn test_instance_std_array() { diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs index 7c0f87f9e..63f789250 100644 --- a/spec/rust/tests/test_instance_user_array.rs +++ b/spec/rust/tests/test_instance_user_array.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::instance_user_array::*; +use rust::formats::instance_user_array::*; #[test] fn test_instance_user_array() { diff --git a/spec/rust/tests/test_integers.rs b/spec/rust/tests/test_integers.rs index a58c95772..1a99eee95 100644 --- a/spec/rust/tests/test_integers.rs +++ b/spec/rust/tests/test_integers.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::integers::*; +use rust::formats::integers::*; #[test] fn test_integers() { diff --git a/spec/rust/tests/test_integers_double_overflow.rs b/spec/rust/tests/test_integers_double_overflow.rs index 4e59a742e..bcca77203 100644 --- a/spec/rust/tests/test_integers_double_overflow.rs +++ b/spec/rust/tests/test_integers_double_overflow.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::integers_double_overflow::*; +use rust::formats::integers_double_overflow::*; #[test] fn test_integers_double_overflow() { diff --git a/spec/rust/tests/test_integers_min_max.rs b/spec/rust/tests/test_integers_min_max.rs index e98206a32..cd2549d04 100644 --- a/spec/rust/tests/test_integers_min_max.rs +++ b/spec/rust/tests/test_integers_min_max.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::integers_min_max::*; +use rust::formats::integers_min_max::*; #[test] fn test_integers_min_max() { diff --git a/spec/rust/tests/test_io_local_var.rs b/spec/rust/tests/test_io_local_var.rs index 6745ed738..92ba49634 100644 --- a/spec/rust/tests/test_io_local_var.rs +++ b/spec/rust/tests/test_io_local_var.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::io_local_var::*; +use rust::formats::io_local_var::*; #[test] fn test_io_local_var() { diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs index 9aa5e946f..5e88306da 100644 --- a/spec/rust/tests/test_js_signed_right_shift.rs +++ b/spec/rust/tests/test_js_signed_right_shift.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::js_signed_right_shift::*; +use rust::formats::js_signed_right_shift::*; #[test] fn test_js_signed_right_shift() { diff --git a/spec/rust/tests/test_meta_tags.rs b/spec/rust/tests/test_meta_tags.rs index a45bf71ec..56faed93d 100644 --- a/spec/rust/tests/test_meta_tags.rs +++ b/spec/rust/tests/test_meta_tags.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::meta_tags::*; +use rust::formats::meta_tags::*; #[test] fn test_meta_tags() { diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs index 368aa3911..ce314b75e 100644 --- a/spec/rust/tests/test_meta_xref.rs +++ b/spec/rust/tests/test_meta_xref.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::meta_xref::*; +use rust::formats::meta_xref::*; #[test] fn test_meta_xref() { diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs index c96f7e895..99ba7a8cc 100644 --- a/spec/rust/tests/test_multiple_use.rs +++ b/spec/rust/tests/test_multiple_use.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::multiple_use::*; +use rust::formats::multiple_use::*; #[test] fn test_multiple_use() { diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs index 889836b54..37fbad468 100644 --- a/spec/rust/tests/test_nav_parent.rs +++ b/spec/rust/tests/test_nav_parent.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent::*; +use rust::formats::nav_parent::*; #[test] fn test_nav_parent() { diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs index f1ec1d3a0..f1b0f4612 100644 --- a/spec/rust/tests/test_nav_parent2.rs +++ b/spec/rust/tests/test_nav_parent2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent2::*; +use rust::formats::nav_parent2::*; #[test] fn test_nav_parent2() { diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs index ffed2619e..4bd165de2 100644 --- a/spec/rust/tests/test_nav_parent3.rs +++ b/spec/rust/tests/test_nav_parent3.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent3::*; +use rust::formats::nav_parent3::*; #[test] fn test_nav_parent3() { diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs index 39c5cf356..f97644f8b 100644 --- a/spec/rust/tests/test_nav_parent_false.rs +++ b/spec/rust/tests/test_nav_parent_false.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent_false::*; +use rust::formats::nav_parent_false::*; #[test] fn test_nav_parent_false() { diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs index cd4db64f8..c80954022 100644 --- a/spec/rust/tests/test_nav_parent_false2.rs +++ b/spec/rust/tests/test_nav_parent_false2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent_false2::*; +use rust::formats::nav_parent_false2::*; #[test] fn test_nav_parent_false2() { diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs index dbeade0de..7777e4269 100644 --- a/spec/rust/tests/test_nav_parent_override.rs +++ b/spec/rust/tests/test_nav_parent_override.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent_override::*; +use rust::formats::nav_parent_override::*; #[test] fn test_nav_parent_override() { diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs index fe907e451..572494665 100644 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent_switch::*; +use rust::formats::nav_parent_switch::*; #[test] fn test_nav_parent_switch() { diff --git a/spec/rust/tests/test_nav_parent_vs_value_inst.rs b/spec/rust/tests/test_nav_parent_vs_value_inst.rs index 9aa41ad7b..f598d5a93 100644 --- a/spec/rust/tests/test_nav_parent_vs_value_inst.rs +++ b/spec/rust/tests/test_nav_parent_vs_value_inst.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_parent_vs_value_inst::*; +use rust::formats::nav_parent_vs_value_inst::*; #[test] fn test_nav_parent_vs_value_inst() { diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs index 1f07b6087..2b3ecd8ea 100644 --- a/spec/rust/tests/test_nav_root.rs +++ b/spec/rust/tests/test_nav_root.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nav_root::*; +use rust::formats::nav_root::*; #[test] fn test_nav_root() { diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs index ee4d18a45..af758c3ee 100644 --- a/spec/rust/tests/test_nested_same_name.rs +++ b/spec/rust/tests/test_nested_same_name.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nested_same_name::*; +use rust::formats::nested_same_name::*; #[test] fn test_nested_same_name() { diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs index e3fe7530a..cfb684d86 100644 --- a/spec/rust/tests/test_nested_same_name2.rs +++ b/spec/rust/tests/test_nested_same_name2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nested_same_name2::*; +use rust::formats::nested_same_name2::*; #[test] fn test_nested_same_name2() { diff --git a/spec/rust/tests/test_nested_type_param.rs b/spec/rust/tests/test_nested_type_param.rs index 502eeb85a..4a8934aae 100644 --- a/spec/rust/tests/test_nested_type_param.rs +++ b/spec/rust/tests/test_nested_type_param.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nested_type_param::*; +use rust::formats::nested_type_param::*; #[test] fn test_nested_type_param() { diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs index 9ea721e1c..30e716be8 100644 --- a/spec/rust/tests/test_nested_types.rs +++ b/spec/rust/tests/test_nested_types.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nested_types::*; +use rust::formats::nested_types::*; #[test] fn test_nested_types() { diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs index 346bb51cf..b7ac1b456 100644 --- a/spec/rust/tests/test_nested_types2.rs +++ b/spec/rust/tests/test_nested_types2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nested_types2::*; +use rust::formats::nested_types2::*; #[test] fn test_nested_types2() { diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs index 655cded42..41d6f6139 100644 --- a/spec/rust/tests/test_nested_types3.rs +++ b/spec/rust/tests/test_nested_types3.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::nested_types3::*; +use rust::formats::nested_types3::*; #[test] fn test_nested_types3() { diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs index 4e886cac1..3eb325303 100644 --- a/spec/rust/tests/test_non_standard.rs +++ b/spec/rust/tests/test_non_standard.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::non_standard::*; +use rust::formats::non_standard::*; #[test] fn test_non_standard() { diff --git a/spec/rust/tests/test_opaque_external_type.rs b/spec/rust/tests/test_opaque_external_type.rs index 07dde7e63..3871c8f34 100644 --- a/spec/rust/tests/test_opaque_external_type.rs +++ b/spec/rust/tests/test_opaque_external_type.rs @@ -2,8 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::opaque_external_type::*; +use rust::formats::opaque_external_type::*; #[test] fn test_opaque_external_type() { diff --git a/spec/rust/tests/test_opaque_external_type_02_parent.rs b/spec/rust/tests/test_opaque_external_type_02_parent.rs index efe7d93c5..d19972f29 100644 --- a/spec/rust/tests/test_opaque_external_type_02_parent.rs +++ b/spec/rust/tests/test_opaque_external_type_02_parent.rs @@ -2,8 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::opaque_external_type_02_parent::*; +use rust::formats::opaque_external_type_02_parent::*; #[test] fn test_term_strz() { diff --git a/spec/rust/tests/test_opaque_with_param.rs b/spec/rust/tests/test_opaque_with_param.rs index 9f584a9ab..577f10032 100644 --- a/spec/rust/tests/test_opaque_with_param.rs +++ b/spec/rust/tests/test_opaque_with_param.rs @@ -2,9 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::opaque_with_param::*; - +use rust::formats::opaque_with_param::*; #[test] fn test_opaque_with_param() { diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs index 8475c366d..113d49cb3 100644 --- a/spec/rust/tests/test_optional_id.rs +++ b/spec/rust/tests/test_optional_id.rs @@ -3,8 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::optional_id::*; +use rust::formats::optional_id::*; #[test] fn basic_parse() { diff --git a/spec/rust/tests/test_params_call_extra_parens.rs b/spec/rust/tests/test_params_call_extra_parens.rs index 2c64da2a8..9d526d666 100644 --- a/spec/rust/tests/test_params_call_extra_parens.rs +++ b/spec/rust/tests/test_params_call_extra_parens.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_call_extra_parens::*; +use rust::formats::params_call_extra_parens::*; #[test] fn test_params_call_extra_parens() { diff --git a/spec/rust/tests/test_params_call_short.rs b/spec/rust/tests/test_params_call_short.rs index 29e08d148..440171fee 100644 --- a/spec/rust/tests/test_params_call_short.rs +++ b/spec/rust/tests/test_params_call_short.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_call_short::*; +use rust::formats::params_call_short::*; #[test] fn test_params_call_short() { diff --git a/spec/rust/tests/test_params_def.rs b/spec/rust/tests/test_params_def.rs index 7bbe11b26..30b525f9f 100644 --- a/spec/rust/tests/test_params_def.rs +++ b/spec/rust/tests/test_params_def.rs @@ -2,9 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; - -#[path = "../formats/mod.rs"] mod formats; -use formats::params_def::*; +use rust::formats::params_def::*; #[test] fn test_params_def() { diff --git a/spec/rust/tests/test_params_enum.rs b/spec/rust/tests/test_params_enum.rs index 185c7ed67..24750dc1c 100644 --- a/spec/rust/tests/test_params_enum.rs +++ b/spec/rust/tests/test_params_enum.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_enum::*; +use rust::formats::params_enum::*; #[test] fn test_params_enum() { diff --git a/spec/rust/tests/test_params_pass_array_int.rs b/spec/rust/tests/test_params_pass_array_int.rs index c3a60b452..7808e6ee2 100644 --- a/spec/rust/tests/test_params_pass_array_int.rs +++ b/spec/rust/tests/test_params_pass_array_int.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_pass_array_int::*; +use rust::formats::params_pass_array_int::*; #[test] fn test_params_pass_array_int() { diff --git a/spec/rust/tests/test_params_pass_array_str.rs b/spec/rust/tests/test_params_pass_array_str.rs index 073d06312..679d2e7e0 100644 --- a/spec/rust/tests/test_params_pass_array_str.rs +++ b/spec/rust/tests/test_params_pass_array_str.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_pass_array_str::*; +use rust::formats::params_pass_array_str::*; #[test] fn test_params_pass_array_str() { diff --git a/spec/rust/tests/test_params_pass_array_usertype.rs b/spec/rust/tests/test_params_pass_array_usertype.rs index 0b99a4ace..291a9ce05 100644 --- a/spec/rust/tests/test_params_pass_array_usertype.rs +++ b/spec/rust/tests/test_params_pass_array_usertype.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_pass_array_usertype::*; +use rust::formats::params_pass_array_usertype::*; #[test] fn test_params_pass_array_usertype() { diff --git a/spec/rust/tests/test_params_pass_bool.rs b/spec/rust/tests/test_params_pass_bool.rs index 85068c8ea..5f0af8868 100644 --- a/spec/rust/tests/test_params_pass_bool.rs +++ b/spec/rust/tests/test_params_pass_bool.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_pass_bool::*; +use rust::formats::params_pass_bool::*; #[test] fn test_params_pass_bool() { diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs index c17440a15..aa1d103af 100644 --- a/spec/rust/tests/test_params_pass_usertype.rs +++ b/spec/rust/tests/test_params_pass_usertype.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::params_pass_usertype::*; +use rust::formats::params_pass_usertype::*; #[test] fn test_params_pass_usertype() { diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs index 5c360ef65..3e5d50cef 100644 --- a/spec/rust/tests/test_position_abs.rs +++ b/spec/rust/tests/test_position_abs.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::position_abs::*; +use rust::formats::position_abs::*; #[test] fn test_position_abs() { diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs index 37e141575..ce26f15c7 100644 --- a/spec/rust/tests/test_position_in_seq.rs +++ b/spec/rust/tests/test_position_in_seq.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::position_in_seq::*; +use rust::formats::position_in_seq::*; #[test] fn test_position_in_seq() { diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs index 8d2fdf8a9..6f31b5120 100644 --- a/spec/rust/tests/test_position_to_end.rs +++ b/spec/rust/tests/test_position_to_end.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::position_to_end::*; +use rust::formats::position_to_end::*; #[test] fn test_position_to_end() { diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index 5ae1eaea8..e7dbe6940 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_coerce_bytes::*; +use rust::formats::process_coerce_bytes::*; #[test] fn test_process_coerce_bytes() { diff --git a/spec/rust/tests/test_process_coerce_usertype1.rs b/spec/rust/tests/test_process_coerce_usertype1.rs index 3eddbe44b..ed5cf8f3b 100644 --- a/spec/rust/tests/test_process_coerce_usertype1.rs +++ b/spec/rust/tests/test_process_coerce_usertype1.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_coerce_usertype1::*; +use rust::formats::process_coerce_usertype1::*; #[test] fn test_process_coerce_usertype1() { diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs index df19b3a53..d1a06f0f5 100644 --- a/spec/rust/tests/test_process_coerce_usertype2.rs +++ b/spec/rust/tests/test_process_coerce_usertype2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_coerce_usertype2::*; +use rust::formats::process_coerce_usertype2::*; #[test] fn test_process_coerce_usertype2() { diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs index afdcfca16..f72332f77 100644 --- a/spec/rust/tests/test_process_custom.rs +++ b/spec/rust/tests/test_process_custom.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_custom::*; +use rust::formats::process_custom::*; #[test] fn test_process_custom() { diff --git a/spec/rust/tests/test_process_custom_no_args.rs b/spec/rust/tests/test_process_custom_no_args.rs index d132f18f9..07e3a4dec 100644 --- a/spec/rust/tests/test_process_custom_no_args.rs +++ b/spec/rust/tests/test_process_custom_no_args.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_custom_no_args::*; +use rust::formats::process_custom_no_args::*; #[test] fn test_process_custom_no_args() { diff --git a/spec/rust/tests/test_process_repeat_bytes.rs b/spec/rust/tests/test_process_repeat_bytes.rs index 2918be66b..7c4f78240 100644 --- a/spec/rust/tests/test_process_repeat_bytes.rs +++ b/spec/rust/tests/test_process_repeat_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_repeat_bytes::*; +use rust::formats::process_repeat_bytes::*; #[test] fn test_process_repeat_bytes() { diff --git a/spec/rust/tests/test_process_repeat_usertype.rs b/spec/rust/tests/test_process_repeat_usertype.rs index 3a9f6df35..f991f121b 100644 --- a/spec/rust/tests/test_process_repeat_usertype.rs +++ b/spec/rust/tests/test_process_repeat_usertype.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_repeat_usertype::*; +use rust::formats::process_repeat_usertype::*; #[test] fn test_process_repeat_usertype() { diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs index 2ba7c39de..7688f1472 100644 --- a/spec/rust/tests/test_process_rotate.rs +++ b/spec/rust/tests/test_process_rotate.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_rotate::*; +use rust::formats::process_rotate::*; #[test] fn test_process_rotate() { diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs index 321958c20..0ad672686 100644 --- a/spec/rust/tests/test_process_to_user.rs +++ b/spec/rust/tests/test_process_to_user.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_to_user::*; +use rust::formats::process_to_user::*; #[test] fn test_process_to_user() { diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs index 1ced0d220..ecda57953 100644 --- a/spec/rust/tests/test_process_xor4_const.rs +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_xor4_const::*; +use rust::formats::process_xor4_const::*; #[test] fn test_process_xor4_const() { diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs index 0b198e9c0..e231e8b88 100644 --- a/spec/rust/tests/test_process_xor4_value.rs +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_xor4_value::*; +use rust::formats::process_xor4_value::*; #[test] fn test_process_xor4_value() { diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 5ec145e88..31b8cf45e 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_xor_const::*; +use rust::formats::process_xor_const::*; #[test] fn test_process_xor_const() { diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index 4414d53d3..c53850d57 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::process_xor_value::*; +use rust::formats::process_xor_value::*; #[test] fn test_process_xor_value() { diff --git a/spec/rust/tests/test_recursive_one.rs b/spec/rust/tests/test_recursive_one.rs index b4ce408d3..af7f206f2 100644 --- a/spec/rust/tests/test_recursive_one.rs +++ b/spec/rust/tests/test_recursive_one.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::recursive_one::*; +use rust::formats::recursive_one::*; #[test] fn test_recursive_one() { diff --git a/spec/rust/tests/test_repeat_eos_bit.rs b/spec/rust/tests/test_repeat_eos_bit.rs index a9fc58dfe..944ea9850 100644 --- a/spec/rust/tests/test_repeat_eos_bit.rs +++ b/spec/rust/tests/test_repeat_eos_bit.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_eos_bit::*; +use rust::formats::repeat_eos_bit::*; #[test] fn test_repeat_eos_bit() { diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index 08b00053a..eff5f57e7 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -1,17 +1,17 @@ +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] use std::fs; - extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_eos_struct::*; - +use rust::formats::repeat_eos_struct::*; #[test] fn test_repeat_eos_struct() { let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = RepeatEosStruct::read_into(&_io, None, None); - let r : OptRc; + let res: KResult> = RepeatEosStruct::read_into(&_io, None, None); + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs index a82954901..bc18d03a8 100644 --- a/spec/rust/tests/test_repeat_eos_u4.rs +++ b/spec/rust/tests/test_repeat_eos_u4.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_eos_u4::*; +use rust::formats::repeat_eos_u4::*; #[test] fn test_repeat_eos_u4() { diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index 54e794f5f..80ee009c6 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -1,20 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + #![allow(unused_variables)] #![allow(unused_assignments)] #![allow(overflowing_literals)] use std::fs; - extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_n_struct::*; - +use rust::formats::repeat_n_struct::*; #[test] fn test_repeat_n_struct() { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = RepeatNStruct::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs index b2c2e19b8..5618fde38 100644 --- a/spec/rust/tests/test_repeat_n_strz.rs +++ b/spec/rust/tests/test_repeat_n_strz.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_n_strz::*; +use rust::formats::repeat_n_strz::*; #[test] fn test_repeat_n_strz() { diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs index 27d26e465..e29267fe8 100644 --- a/spec/rust/tests/test_repeat_n_strz_double.rs +++ b/spec/rust/tests/test_repeat_n_strz_double.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_n_strz_double::*; +use rust::formats::repeat_n_strz_double::*; #[test] fn test_repeat_n_strz_double() { diff --git a/spec/rust/tests/test_repeat_until_calc_array_type.rs b/spec/rust/tests/test_repeat_until_calc_array_type.rs index 629b597fc..95ef28f6a 100644 --- a/spec/rust/tests/test_repeat_until_calc_array_type.rs +++ b/spec/rust/tests/test_repeat_until_calc_array_type.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_until_calc_array_type::*; +use rust::formats::repeat_until_calc_array_type::*; #[test] fn test_repeat_until_calc_array_type() { diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs index 273510461..516735752 100644 --- a/spec/rust/tests/test_repeat_until_complex.rs +++ b/spec/rust/tests/test_repeat_until_complex.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_until_complex::*; +use rust::formats::repeat_until_complex::*; #[test] fn test_repeat_until_complex() { diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs index e0a947310..381dd463e 100644 --- a/spec/rust/tests/test_repeat_until_s4.rs +++ b/spec/rust/tests/test_repeat_until_s4.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_until_s4::*; +use rust::formats::repeat_until_s4::*; #[test] fn test_repeat_until_s4() { diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs index 33a2ce980..e6e196dfa 100644 --- a/spec/rust/tests/test_repeat_until_sized.rs +++ b/spec/rust/tests/test_repeat_until_sized.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::repeat_until_sized::*; +use rust::formats::repeat_until_sized::*; #[test] fn test_repeat_until_sized() { diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs index f5f2372ed..a5a2361dd 100644 --- a/spec/rust/tests/test_str_encodings.rs +++ b/spec/rust/tests/test_str_encodings.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_encodings::*; +use rust::formats::str_encodings::*; #[test] fn test_str_encodings() { diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs index 0f8605afa..6be824e87 100644 --- a/spec/rust/tests/test_str_encodings_default.rs +++ b/spec/rust/tests/test_str_encodings_default.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_encodings_default::*; +use rust::formats::str_encodings_default::*; #[test] fn test_str_encodings_default() { diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs index 3452bc660..2101ed834 100644 --- a/spec/rust/tests/test_str_encodings_utf16.rs +++ b/spec/rust/tests/test_str_encodings_utf16.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_encodings_utf16::*; +use rust::formats::str_encodings_utf16::*; #[test] fn test_str_encodings_utf16() { diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs index a0532fac5..84d809774 100644 --- a/spec/rust/tests/test_str_eos.rs +++ b/spec/rust/tests/test_str_eos.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_eos::*; +use rust::formats::str_eos::*; #[test] fn test_str_eos() { diff --git a/spec/rust/tests/test_str_literals.rs b/spec/rust/tests/test_str_literals.rs index fa6e9984a..822a6bae4 100644 --- a/spec/rust/tests/test_str_literals.rs +++ b/spec/rust/tests/test_str_literals.rs @@ -3,8 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_literals::*; +use rust::formats::str_literals::*; #[test] fn basic_parse() { diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs index ff8270262..4f33e61d7 100644 --- a/spec/rust/tests/test_str_literals2.rs +++ b/spec/rust/tests/test_str_literals2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_literals2::*; +use rust::formats::str_literals2::*; #[test] fn test_str_literals2() { diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs index 7591b3161..acf8fa41a 100644 --- a/spec/rust/tests/test_str_pad_term.rs +++ b/spec/rust/tests/test_str_pad_term.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_pad_term::*; +use rust::formats::str_pad_term::*; #[test] fn test_str_pad_term() { diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index 8bc4281ba..bcb97bff1 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::str_pad_term_empty::*; +use rust::formats::str_pad_term_empty::*; #[test] fn test_str_pad_term_empty() { diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index 521c57e16..4ca5e4adc 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_bytearray::*; +use rust::formats::switch_bytearray::*; #[test] fn test_switch_bytearray() { diff --git a/spec/rust/tests/test_switch_cast.rs b/spec/rust/tests/test_switch_cast.rs index 713632b34..85615b350 100644 --- a/spec/rust/tests/test_switch_cast.rs +++ b/spec/rust/tests/test_switch_cast.rs @@ -3,8 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_cast::*; +use rust::formats::switch_cast::*; #[test] fn basic_parse() { diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs index 1158ec441..c06a82e20 100644 --- a/spec/rust/tests/test_switch_else_only.rs +++ b/spec/rust/tests/test_switch_else_only.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_else_only::*; +use rust::formats::switch_else_only::*; #[test] fn test_switch_else_only() { diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index eb9def5f4..296cbbf08 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_integers::*; +use rust::formats::switch_integers::*; #[test] fn test_switch_integers() { diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index 4a61e7e50..c446d874c 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_integers2::*; +use rust::formats::switch_integers2::*; #[test] fn test_switch_integers2() { diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index 2e8927095..5d435f87f 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_enum::*; +use rust::formats::switch_manual_enum::*; #[test] fn test_switch_manual_enum() { diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 11e9d6ccf..d3724bb2b 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -1,17 +1,20 @@ -use std::fs; +// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_enum_invalid::*; - +use rust::formats::switch_manual_enum_invalid::*; #[test] fn test_switch_manual_enum_invalid() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = SwitchManualEnumInvalid::read_into(&_io, None, None); - let r : OptRc; + let res: KResult> = + SwitchManualEnumInvalid::read_into(&_io, None, None); + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -20,12 +23,10 @@ fn test_switch_manual_enum_invalid() { } assert_eq!(r.opcodes().len(), 2); - let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); + let n: i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); - // body is None - //assert_eq!(r.opcodes()[0 as usize].body(), 0); - let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); + assert_eq!(r.opcodes()[0 as usize].body().is_none(), true); + let n: i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); - // body is None - //assert_eq!(r.opcodes()[1 as usize].body(), 0); + assert_eq!(r.opcodes()[1 as usize].body().is_none(), true); } diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index d6f917596..2baa18772 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -2,19 +2,17 @@ #![allow(unused_assignments)] #![allow(overflowing_literals)] use std::fs; - extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_enum_invalid_else::*; - +use rust::formats::switch_manual_enum_invalid_else::*; #[test] fn test_switch_manual_enum_invalid_else() { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualEnumInvalidElse::read_into(&_io, None, None); - let r : OptRc; + let res: KResult> = + SwitchManualEnumInvalidElse::read_into(&_io, None, None); + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -23,10 +21,24 @@ fn test_switch_manual_enum_invalid_else() { } assert_eq!(r.opcodes().len(), 2); - let n : i64 = (&*r.opcodes()[0 as usize].code()).into(); + let n: i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); - assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value().unwrap(), 123); - let n : i64 = (&*r.opcodes()[1 as usize].code()).into(); + assert_eq!( + *Into::>::into( + &*r.opcodes()[0 as usize].body().as_ref().unwrap() + ) + .value() + .unwrap(), + 123 + ); + let n: i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); - assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value().unwrap(), 123); + assert_eq!( + *Into::>::into( + &*r.opcodes()[1 as usize].body().as_ref().unwrap() + ) + .value() + .unwrap(), + 123 + ); } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index cee675073..b80400d31 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_int::*; +use rust::formats::switch_manual_int::*; #[test] fn test_switch_manual_int() { diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index 41ab540cf..8fcbf4bc1 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_int_else::*; +use rust::formats::switch_manual_int_else::*; #[test] fn test_switch_manual_int_else() { diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index 3b21618ec..ce7f20487 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_int_size::*; +use rust::formats::switch_manual_int_size::*; #[test] fn test_switch_manual_int_size() { diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index c3c7f5cdb..d21acbafd 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_int_size_else::*; +use rust::formats::switch_manual_int_size_else::*; #[test] fn test_switch_manual_int_size_else() { diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index 5a02b6384..c985776d9 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -1,52 +1,63 @@ -#![allow(dead_code)] +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] use std::fs; - extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_int_size_eos::*; +use rust::formats::switch_manual_int_size_eos::*; #[test] fn test_switch_manual_int_size_eos() { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = SwitchManualIntSizeEos::read_into(&_io, None, None); - let r : OptRc; + let res: KResult> = + SwitchManualIntSizeEos::read_into(&_io, None, None); + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); } else { r = res.unwrap(); } - assert_eq!(4, r.chunks().len()); - assert_eq!(17, *r.chunks()[0].code()); - if let Some(SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkMeta(s)) = r.chunks()[0].body().clone().body().as_ref() { + assert_eq!(r.chunks().len(), 4); + assert_eq!(*r.chunks()[0 as usize].code(), 17); + if let Some( + SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkMeta(s), + ) = r.chunks()[0].body().clone().body().as_ref() + { assert_eq!("Stuff", *s.title()); assert_eq!("Me", *s.author()); } else { panic!("expected enum SwitchManualIntSizeEos_ChunkBody_ChunkMeta"); }; - - assert_eq!(34, *r.chunks()[1].code()); - if let Some(SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkDir(s)) = r.chunks()[1].body().clone().body().as_ref() { - let strings : Vec = vec!["AAAA", "BBBB", "CCCC"].iter().map(|&s| s.to_string() ).collect(); + assert_eq!(*r.chunks()[1 as usize].code(), 34); + if let Some(SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkDir( + s, + )) = r.chunks()[1].body().clone().body().as_ref() + { + let strings: Vec = vec!["AAAA", "BBBB", "CCCC"] + .iter() + .map(|&s| s.to_string()) + .collect(); assert_eq!(strings, *s.entries()); } else { panic!("expected enum SwitchManualIntSizeEos_ChunkBody_ChunkDir"); } - - assert_eq!(51, *r.chunks()[2].code()); - if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = r.chunks()[2].body().clone().body().as_ref() { - let raw : Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; + assert_eq!(*r.chunks()[2 as usize].code(), 51); + if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = + r.chunks()[2].body().clone().body().as_ref() + { + let raw: Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; assert_eq!(raw, *s); } else { panic!("expected enum Bytes"); } - - assert_eq!(255, *r.chunks()[3].code()); - if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = r.chunks()[3].body().clone().body().as_ref() { - let raw : Vec = vec![]; + assert_eq!(*r.chunks()[3 as usize].code(), 255); + if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = + r.chunks()[3].body().clone().body().as_ref() + { + let raw: Vec = vec![]; assert_eq!(raw, *s); } else { panic!("expected enum Bytes"); diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index e9c7af6bc..1a9e481c7 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_str::*; +use rust::formats::switch_manual_str::*; #[test] fn test_switch_manual_str() { diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index 6ad6cbd31..703cf7e1f 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_manual_str_else::*; +use rust::formats::switch_manual_str_else::*; #[test] fn test_switch_manual_str_else() { diff --git a/spec/rust/tests/test_switch_multi_bool_ops.rs b/spec/rust/tests/test_switch_multi_bool_ops.rs index c5b4b63b2..9469f4015 100644 --- a/spec/rust/tests/test_switch_multi_bool_ops.rs +++ b/spec/rust/tests/test_switch_multi_bool_ops.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_multi_bool_ops::*; +use rust::formats::switch_multi_bool_ops::*; #[test] fn test_switch_multi_bool_ops() { diff --git a/spec/rust/tests/test_switch_repeat_expr.rs b/spec/rust/tests/test_switch_repeat_expr.rs index 263dbd1c7..b823b5385 100644 --- a/spec/rust/tests/test_switch_repeat_expr.rs +++ b/spec/rust/tests/test_switch_repeat_expr.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_repeat_expr::*; +use rust::formats::switch_repeat_expr::*; #[test] fn test_switch_repeat_expr() { diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs index 26f62bf5b..1ae381fda 100644 --- a/spec/rust/tests/test_switch_repeat_expr_invalid.rs +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::switch_repeat_expr_invalid::*; +use rust::formats::switch_repeat_expr_invalid::*; #[test] fn test_switch_repeat_expr_invalid() { diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs index e3a6a4670..f1c3c98e6 100644 --- a/spec/rust/tests/test_term_bytes.rs +++ b/spec/rust/tests/test_term_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::term_bytes::*; +use rust::formats::term_bytes::*; #[test] fn test_term_bytes() { diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs index d88425f68..c3e770612 100644 --- a/spec/rust/tests/test_term_strz.rs +++ b/spec/rust/tests/test_term_strz.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::term_strz::*; +use rust::formats::term_strz::*; #[test] fn test_term_strz() { diff --git a/spec/rust/tests/test_term_u1_val.rs b/spec/rust/tests/test_term_u1_val.rs index 3c4318634..b90ec2d79 100644 --- a/spec/rust/tests/test_term_u1_val.rs +++ b/spec/rust/tests/test_term_u1_val.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::term_u1_val::*; +use rust::formats::term_u1_val::*; #[test] fn test_term_u1_val() { diff --git a/spec/rust/tests/test_to_string_custom.rs b/spec/rust/tests/test_to_string_custom.rs index 0b70960d4..2f5810e42 100644 --- a/spec/rust/tests/test_to_string_custom.rs +++ b/spec/rust/tests/test_to_string_custom.rs @@ -3,8 +3,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::to_string_custom::*; +use rust::formats::to_string_custom::*; #[test] fn basic_parse() { diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs index 0307b3c3a..dd8094bcd 100644 --- a/spec/rust/tests/test_ts_packet_header.rs +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::ts_packet_header::*; +use rust::formats::ts_packet_header::*; #[test] fn test_ts_packet_header() { diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index ab39d26f3..a8496a766 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::type_int_unary_op::*; +use rust::formats::type_int_unary_op::*; #[test] fn test_type_int_unary_op() { diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs index cd0c5166c..0e1c1a924 100644 --- a/spec/rust/tests/test_type_ternary.rs +++ b/spec/rust/tests/test_type_ternary.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::type_ternary::*; +use rust::formats::type_ternary::*; #[test] fn test_type_ternary() { diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index 6f4524c97..48669a0da 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -1,17 +1,19 @@ -use std::fs; +// Autogenerated from KST: please remove this line if doing any edits by hand! +#![allow(unused_variables)] +#![allow(unused_assignments)] +#![allow(overflowing_literals)] +use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::type_ternary_2nd_falsy::*; - +use rust::formats::type_ternary_2nd_falsy::*; #[test] fn test_type_ternary_2nd_falsy() { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = TypeTernary2ndFalsy::read_into(&_io, None, None); - let r : OptRc; + let res: KResult> = TypeTernary2ndFalsy::read_into(&_io, None, None); + let r: OptRc; if let Err(err) = res { panic!("{:?}", err); @@ -19,19 +21,17 @@ fn test_type_ternary_2nd_falsy() { r = res.unwrap(); } - assert_eq!(*r.v_false().unwrap(), false); - assert_eq!(*r.v_int_zero().unwrap(), 0); - assert_eq!(*r.v_int_neg_zero().unwrap(), 0); - assert_eq!(*r.v_float_zero().unwrap(), 0.0); - assert_eq!(*r.v_float_neg_zero().unwrap(), -0.0); - assert_eq!(*r.v_str_w_zero().unwrap(), "0"); - assert_eq!(r.v_str_w_zero().unwrap().len(), 1); + assert_eq!(*r.v_false().expect("error reading"), false); + assert_eq!(*r.v_int_zero().expect("error reading"), 0); + assert_eq!(*r.v_int_neg_zero().expect("error reading"), 0); + assert_eq!(*r.v_float_zero().expect("error reading"), 0.0); + assert_eq!(*r.v_float_neg_zero().expect("error reading"), -0.0); + assert_eq!(*r.v_str_w_zero().expect("error reading"), "0"); + assert_eq!(r.v_str_w_zero().expect("error reading").len(), 1); assert_eq!(*r.ut().m(), 7); - assert_eq!(r.v_null_ut().unwrap().is_none(), true); - // v_null_ut() always uninited - // assert_eq!(*r.v_null_ut().unwrap().m(), 0); - assert_eq!(*r.v_str_empty().unwrap(), ""); - assert_eq!(r.v_str_empty().unwrap().len(), 0); + assert_eq!(r.v_null_ut().expect("error reading").is_none(), true); + assert_eq!(*r.v_str_empty().expect("error reading"), ""); + assert_eq!(r.v_str_empty().expect("error reading").len(), 0); assert_eq!(r.int_array().len(), 2); - assert_eq!(r.v_int_array_empty().unwrap().len(), 0); + assert_eq!(r.v_int_array_empty().expect("error reading").len(), 0); } diff --git a/spec/rust/tests/test_type_ternary_opaque.rs b/spec/rust/tests/test_type_ternary_opaque.rs index a29bf52ea..2a9e21b88 100644 --- a/spec/rust/tests/test_type_ternary_opaque.rs +++ b/spec/rust/tests/test_type_ternary_opaque.rs @@ -2,8 +2,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::type_ternary_opaque::*; +use rust::formats::type_ternary_opaque::*; #[test] fn test_type_ternary_opaque() { diff --git a/spec/rust/tests/test_user_type.rs b/spec/rust/tests/test_user_type.rs index 7ae72848f..9bb269651 100644 --- a/spec/rust/tests/test_user_type.rs +++ b/spec/rust/tests/test_user_type.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::user_type::*; +use rust::formats::user_type::*; #[test] fn test_user_type() { diff --git a/spec/rust/tests/test_valid_eq_str_encodings.rs b/spec/rust/tests/test_valid_eq_str_encodings.rs index 0b071ca7f..fea4f8f98 100644 --- a/spec/rust/tests/test_valid_eq_str_encodings.rs +++ b/spec/rust/tests/test_valid_eq_str_encodings.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_eq_str_encodings::*; +use rust::formats::valid_eq_str_encodings::*; #[test] fn test_valid_eq_str_encodings() { diff --git a/spec/rust/tests/test_valid_fail_anyof_int.rs b/spec/rust/tests/test_valid_fail_anyof_int.rs index f801cd382..ae790f840 100644 --- a/spec/rust/tests/test_valid_fail_anyof_int.rs +++ b/spec/rust/tests/test_valid_fail_anyof_int.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_anyof_int::*; +use rust::formats::valid_fail_anyof_int::*; #[test] fn test_valid_fail_anyof_int() { diff --git a/spec/rust/tests/test_valid_fail_contents.rs b/spec/rust/tests/test_valid_fail_contents.rs index 1dcf626b6..c7d96430d 100644 --- a/spec/rust/tests/test_valid_fail_contents.rs +++ b/spec/rust/tests/test_valid_fail_contents.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_contents::*; +use rust::formats::valid_fail_contents::*; #[test] fn test_valid_fail_contents() { diff --git a/spec/rust/tests/test_valid_fail_eq_bytes.rs b/spec/rust/tests/test_valid_fail_eq_bytes.rs index 5c0c5f25c..9d08e70f7 100644 --- a/spec/rust/tests/test_valid_fail_eq_bytes.rs +++ b/spec/rust/tests/test_valid_fail_eq_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_eq_bytes::*; +use rust::formats::valid_fail_eq_bytes::*; #[test] fn test_valid_fail_eq_bytes() { diff --git a/spec/rust/tests/test_valid_fail_eq_int.rs b/spec/rust/tests/test_valid_fail_eq_int.rs index 8834583b2..a9ef983a6 100644 --- a/spec/rust/tests/test_valid_fail_eq_int.rs +++ b/spec/rust/tests/test_valid_fail_eq_int.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_eq_int::*; +use rust::formats::valid_fail_eq_int::*; #[test] fn test_valid_fail_eq_int() { diff --git a/spec/rust/tests/test_valid_fail_eq_str.rs b/spec/rust/tests/test_valid_fail_eq_str.rs index 3b0610989..431831e92 100644 --- a/spec/rust/tests/test_valid_fail_eq_str.rs +++ b/spec/rust/tests/test_valid_fail_eq_str.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_eq_str::*; +use rust::formats::valid_fail_eq_str::*; #[test] fn test_valid_fail_eq_str() { diff --git a/spec/rust/tests/test_valid_fail_expr.rs b/spec/rust/tests/test_valid_fail_expr.rs index 8170755fd..a03ba538a 100644 --- a/spec/rust/tests/test_valid_fail_expr.rs +++ b/spec/rust/tests/test_valid_fail_expr.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_expr::*; +use rust::formats::valid_fail_expr::*; #[test] fn test_valid_fail_expr() { diff --git a/spec/rust/tests/test_valid_fail_inst.rs b/spec/rust/tests/test_valid_fail_inst.rs index 941f2409b..3fa055470 100644 --- a/spec/rust/tests/test_valid_fail_inst.rs +++ b/spec/rust/tests/test_valid_fail_inst.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_inst::*; +use rust::formats::valid_fail_inst::*; #[test] fn test_valid_fail_inst() { diff --git a/spec/rust/tests/test_valid_fail_max_int.rs b/spec/rust/tests/test_valid_fail_max_int.rs index 47e1555ba..136127319 100644 --- a/spec/rust/tests/test_valid_fail_max_int.rs +++ b/spec/rust/tests/test_valid_fail_max_int.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_max_int::*; +use rust::formats::valid_fail_max_int::*; #[test] fn test_valid_fail_max_int() { diff --git a/spec/rust/tests/test_valid_fail_min_int.rs b/spec/rust/tests/test_valid_fail_min_int.rs index e314cd2b9..cc7b35243 100644 --- a/spec/rust/tests/test_valid_fail_min_int.rs +++ b/spec/rust/tests/test_valid_fail_min_int.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_min_int::*; +use rust::formats::valid_fail_min_int::*; #[test] fn test_valid_fail_min_int() { diff --git a/spec/rust/tests/test_valid_fail_range_bytes.rs b/spec/rust/tests/test_valid_fail_range_bytes.rs index e5222a89a..3da2b7e26 100644 --- a/spec/rust/tests/test_valid_fail_range_bytes.rs +++ b/spec/rust/tests/test_valid_fail_range_bytes.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_range_bytes::*; +use rust::formats::valid_fail_range_bytes::*; #[test] fn test_valid_fail_range_bytes() { diff --git a/spec/rust/tests/test_valid_fail_range_float.rs b/spec/rust/tests/test_valid_fail_range_float.rs index eeae233c4..37ca849cb 100644 --- a/spec/rust/tests/test_valid_fail_range_float.rs +++ b/spec/rust/tests/test_valid_fail_range_float.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_range_float::*; +use rust::formats::valid_fail_range_float::*; #[test] fn test_valid_fail_range_float() { diff --git a/spec/rust/tests/test_valid_fail_range_int.rs b/spec/rust/tests/test_valid_fail_range_int.rs index bdd7f5f9c..66fc83c60 100644 --- a/spec/rust/tests/test_valid_fail_range_int.rs +++ b/spec/rust/tests/test_valid_fail_range_int.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_range_int::*; +use rust::formats::valid_fail_range_int::*; #[test] fn test_valid_fail_range_int() { diff --git a/spec/rust/tests/test_valid_fail_range_str.rs b/spec/rust/tests/test_valid_fail_range_str.rs index 3cae89cf1..b8cecd1c4 100644 --- a/spec/rust/tests/test_valid_fail_range_str.rs +++ b/spec/rust/tests/test_valid_fail_range_str.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_fail_range_str::*; +use rust::formats::valid_fail_range_str::*; #[test] fn test_valid_fail_range_str() { diff --git a/spec/rust/tests/test_valid_long.rs b/spec/rust/tests/test_valid_long.rs index 53c13e509..b3f42442a 100644 --- a/spec/rust/tests/test_valid_long.rs +++ b/spec/rust/tests/test_valid_long.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_long::*; +use rust::formats::valid_long::*; #[test] fn test_valid_long() { diff --git a/spec/rust/tests/test_valid_not_parsed_if.rs b/spec/rust/tests/test_valid_not_parsed_if.rs index d9c4788b3..9c5a0de70 100644 --- a/spec/rust/tests/test_valid_not_parsed_if.rs +++ b/spec/rust/tests/test_valid_not_parsed_if.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_not_parsed_if::*; +use rust::formats::valid_not_parsed_if::*; #[test] fn test_valid_not_parsed_if() { diff --git a/spec/rust/tests/test_valid_optional_id.rs b/spec/rust/tests/test_valid_optional_id.rs index 55413fc32..80bae03f9 100644 --- a/spec/rust/tests/test_valid_optional_id.rs +++ b/spec/rust/tests/test_valid_optional_id.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_optional_id::*; +use rust::formats::valid_optional_id::*; #[test] fn test_valid_optional_id() { diff --git a/spec/rust/tests/test_valid_short.rs b/spec/rust/tests/test_valid_short.rs index ae9aea5d4..ca3fdcdf8 100644 --- a/spec/rust/tests/test_valid_short.rs +++ b/spec/rust/tests/test_valid_short.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_short::*; +use rust::formats::valid_short::*; #[test] fn test_valid_short() { diff --git a/spec/rust/tests/test_valid_switch.rs b/spec/rust/tests/test_valid_switch.rs index f12731749..073421f30 100644 --- a/spec/rust/tests/test_valid_switch.rs +++ b/spec/rust/tests/test_valid_switch.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::valid_switch::*; +use rust::formats::valid_switch::*; #[test] fn test_valid_switch() { diff --git a/spec/rust/tests/test_yaml_ints.rs b/spec/rust/tests/test_yaml_ints.rs index ba10756d5..ab9ca6170 100644 --- a/spec/rust/tests/test_yaml_ints.rs +++ b/spec/rust/tests/test_yaml_ints.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::yaml_ints::*; +use rust::formats::yaml_ints::*; #[test] fn test_yaml_ints() { diff --git a/spec/rust/tests/test_zlib_surrounded.rs b/spec/rust/tests/test_zlib_surrounded.rs index aec9cbda0..5d8ff4f0c 100644 --- a/spec/rust/tests/test_zlib_surrounded.rs +++ b/spec/rust/tests/test_zlib_surrounded.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::zlib_surrounded::*; +use rust::formats::zlib_surrounded::*; #[test] fn test_zlib_surrounded() { diff --git a/spec/rust/tests/test_zlib_with_header_78.rs b/spec/rust/tests/test_zlib_with_header_78.rs index 1c1d20df7..5b8098287 100644 --- a/spec/rust/tests/test_zlib_with_header_78.rs +++ b/spec/rust/tests/test_zlib_with_header_78.rs @@ -6,8 +6,7 @@ use std::fs; extern crate kaitai; use self::kaitai::*; -#[path = "../formats/mod.rs"] mod formats; -use formats::zlib_with_header_78::*; +use rust::formats::zlib_with_header_78::*; #[test] fn test_zlib_with_header_78() { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index e783422c1..be02734af 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -30,10 +30,9 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs importList.add("use std::fs;") importList.add("extern crate kaitai;") importList.add("use self::kaitai::*;") - importList.add("#[path = \"../formats/mod.rs\"] mod formats;") - importList.add(s"${use_mod}formats::${spec.id}::*;") + importList.add(s"${use_mod}rust::formats::${spec.id}::*;") - spec.extraImports.foreach{ name => importList.add(s"${use_mod}formats::$name::*;") } + spec.extraImports.foreach{ name => importList.add(s"${use_mod}rust::formats::$name::*;") } val code = s"""|#[test] From 90f6893a5323b830455d784d6bcad345a4992e1e Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 17 Apr 2024 22:15:51 +0200 Subject: [PATCH 164/198] Revert "`--force` stores value in `config.outDir`" This reverts commit 1377aafa1fc012e600c5b07d0c5d2f166ed66fea. I don't see any reason for this change. I think the old behavior of `-f` not taking any argument is sufficient for all purposes. --- .../src/main/scala/io/kaitai/struct/testtranslator/Main.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala index e1f72f7f7..ac03f2851 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala @@ -83,8 +83,8 @@ object Main extends App { c.copy(srcFiles = list.toSeq) } text("process all KST files available") - opt[String]('f', "force") action { (x, c) => - c.copy(outDir = x) + opt[Unit]('f', "force") action { (x, c) => + c.copy(outDir = specDir) } text(s"force overwrite specs in production spec dirs (default: generate in $defaultOutDir)") checkConfig( From 37194001f714e8bfbbf7d271af8591bd29c48bad Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 17 Apr 2024 22:25:34 +0200 Subject: [PATCH 165/198] Revert "add `CLIOptions::unitTest`", remove its use This reverts commit b5d369fe63ce8d11c8d9ca51273ed4c93baa7ad4. I have no idea what this `unitTest` option was intended for (what is meant by "generate unit tests (not integration tests)" in context of Kaitai Struct?), but for all I can see it is pointless at the moment. Moreover, it's apparently unreachable since 4a90df8287a701b097ccff319d59e058a0bb8818, which removed the support for the `-u / --unit-test` option (so `unitTest` always defaults `false` and cannot be changed externally). --- .../scala/io/kaitai/struct/testtranslator/Main.scala | 11 +++++------ .../struct/testtranslator/specgenerators/RustSG.scala | 9 ++------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala index ac03f2851..4ceff3708 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala @@ -8,9 +8,9 @@ object Main extends App { var baseDir = ".." val specDir = s"$baseDir/spec" def specKsDir = s"$baseDir/spec/ks" - def specKsDir_=(v:String): Unit = { specKsDir = v } + def specKsDir_=(v:String) { specKsDir = v } def formatsDir = s"$baseDir/formats" - def formatsDir_=(v:String): Unit = { formatsDir = v } + def formatsDir_=(v:String) { formatsDir = v } val defaultOutDir = s"$specKsDir/out" val importsDir = s"$baseDir/../formats" @@ -39,8 +39,7 @@ object Main extends App { case class CLIOptions( srcFiles: Seq[String] = Seq(), targets: Seq[String] = Seq(), - outDir: String = defaultOutDir, - unitTest: Boolean = false, + outDir: String = defaultOutDir ) // Stupid ksc build-time issue: no simple way to get that generated constant @@ -59,7 +58,7 @@ object Main extends App { x } c.copy(srcFiles = c.srcFiles :+ testName) - } text "source test names (.kst)" + } text("source test names (.kst)") opt[String]('t', "target").unbounded().valueName("").action { (x, c) => if (x == "all") { @@ -67,7 +66,7 @@ object Main extends App { } else { c.copy(targets = c.targets :+ x) } - } text s"target languages (${ALL_LANGS.mkString(", ")}, default: all)" validate { x => + } text(s"target languages (${ALL_LANGS.mkString(", ")}, default: all)") validate { x => if (ALL_LANGS.contains(x) || x == "all") { success } else { diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index b837f239c..34844279f 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -21,20 +21,15 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def fileName(name: String): String = s"test_$name.rs" override def header(): Unit = { - val use_mod = if (options.unitTest) - s"use crate::" - else - s"use " - importList.add("#![allow(unused_variables)]") importList.add("#![allow(unused_assignments)]") importList.add("#![allow(overflowing_literals)]") importList.add("use std::fs;") importList.add("extern crate kaitai;") importList.add("use self::kaitai::*;") - importList.add(s"${use_mod}rust::formats::${spec.id}::*;") + importList.add(s"use rust::formats::${spec.id}::*;") - spec.extraImports.foreach{ name => importList.add(s"${use_mod}rust::formats::$name::*;") } + spec.extraImports.foreach{ name => importList.add(s"use rust::formats::$name::*;") } val code = s"""|#[test] From c188652b7182562a74afb929d0dd090dd91a3613 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 17 Apr 2024 22:44:51 +0200 Subject: [PATCH 166/198] Revert "doTestSpec(..., options: CLIOptions), remove some warnings" This reverts commit 26ae9b67cbe53cd507548196b5b2b5636bd445fa. --- .../testtranslator/TestTranslator.scala | 21 +++++++++---------- .../specgenerators/RustSG.scala | 3 +-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index 3260adce4..cd21ecddb 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -19,28 +19,27 @@ class TestTranslator(options: CLIOptions) { def run(): Unit = { if(options.srcFiles.length == 1) { - val path = Path.of(options.srcFiles.head) + val path = Path.of(options.srcFiles(0)); - if (path.isAbsolute) { + if (path.isAbsolute()) { val specKs = specKsDir.split('/').drop(1).mkString("/") - val parent = path.getParent.toString.replace('\\', '/') + val parent = path.getParent().toString().replace('\\', '/') assert(parent.endsWith(specKs)) baseDir = parent.replace(specKs, "") } } + val exactOutDir = (options.outDir != defaultOutDir) options.srcFiles.foreach(testName => - doTestSpec(testName, options.targets, options) + doTestSpec(testName, options.targets, options.outDir, exactOutDir) ) } - def doTestSpec(ts: String, langs: Seq[String], options: CLIOptions): Unit = { + def doTestSpec(ts: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { Console.println(s"Translating: $ts") - val outDir = options.outDir - val exactOutDir = options.outDir != defaultOutDir val path = Path.of(ts) - val testName = if(path.isAbsolute) { path.getFileName.toString } else { ts } + val testName = if(path.isAbsolute()) { path.getFileName().toString() } else { ts } val testSpec = loadTestSpec(testName) val classSpecs = loadClassSpecs(testName) @@ -48,7 +47,7 @@ class TestTranslator(options: CLIOptions) { val provider = new ClassTypeProvider(classSpecs, initObj) langs.foreach(langName => { - val sg = getSG(langName, testSpec, provider, classSpecs, options) + val sg = getSG(langName, testSpec, provider, classSpecs) try { val outFile = if(exactOutDir) { s"$outDir/${sg.fileName(testName)}" } else { s"$outDir/$langName/${sg.fileName(testName)}" } Console.println(s"... generating $outFile") @@ -128,7 +127,7 @@ class TestTranslator(options: CLIOptions) { origSpecs } - def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs, options: CLIOptions): BaseGenerator = lang match { + def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs): BaseGenerator = lang match { case "construct" => new ConstructSG(testSpec, provider) case "cpp_stl_98" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp98()) case "cpp_stl_11" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp11()) @@ -142,6 +141,6 @@ class TestTranslator(options: CLIOptions) { case "php" => new PHPSG(testSpec, provider) case "python" => new PythonSG(testSpec, provider) case "ruby" => new RubySG(testSpec, provider) - case "rust" => new RustSG(testSpec, provider, classSpecs, options) + case "rust" => new RustSG(testSpec, provider, classSpecs) } } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 34844279f..90130ec28 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -8,10 +8,9 @@ import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestEquals, Tes import _root_.io.kaitai.struct.translators.RustTranslator import _root_.io.kaitai.struct.datatype.DataType.{ArrayType, BooleanType, BytesType, EnumType, IntType, SwitchType, UserType} import _root_.io.kaitai.struct.format.ClassSpecs -import io.kaitai.struct.testtranslator.Main.CLIOptions import io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} -class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs, options: CLIOptions) extends BaseGenerator(spec) { +class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs) extends BaseGenerator(spec) { val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) val compiler = new RustCompiler(provider, RuntimeConfig()) From 0ad016981b1a1dcabc7faa0d1c0a8c41f95323d5 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 17 Apr 2024 22:46:46 +0200 Subject: [PATCH 167/198] Revert "if source path isAbsolute() modify `baseDir`" This reverts commit af7572877867ae090f8c0c6242a9a962ed7d2c95. --- .../testtranslator/TestTranslator.scala | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index cd21ecddb..2817b370d 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -8,9 +8,7 @@ import io.kaitai.struct.formats.JavaKSYParser import io.kaitai.struct.problems.ProblemSeverity import io.kaitai.struct.testtranslator.Main.{CLIOptions, defaultOutDir} import io.kaitai.struct.testtranslator.specgenerators._ -import io.kaitai.struct.{ClassTypeProvider, CppRuntimeConfig, RuntimeConfig} - -import java.nio.file.Path +import io.kaitai.struct.{ClassTypeProvider, CppRuntimeConfig} import scala.collection.immutable.SortedMap @@ -18,28 +16,13 @@ class TestTranslator(options: CLIOptions) { import Main._ def run(): Unit = { - if(options.srcFiles.length == 1) { - val path = Path.of(options.srcFiles(0)); - - if (path.isAbsolute()) { - val specKs = specKsDir.split('/').drop(1).mkString("/") - val parent = path.getParent().toString().replace('\\', '/') - assert(parent.endsWith(specKs)) - baseDir = parent.replace(specKs, "") - } - } - - val exactOutDir = (options.outDir != defaultOutDir) options.srcFiles.foreach(testName => - doTestSpec(testName, options.targets, options.outDir, exactOutDir) + doTestSpec(testName, options.targets, options.outDir, options.outDir != defaultOutDir) ) } - def doTestSpec(ts: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { - Console.println(s"Translating: $ts") - - val path = Path.of(ts) - val testName = if(path.isAbsolute()) { path.getFileName().toString() } else { ts } + def doTestSpec(testName: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { + Console.println(s"Translating: $testName") val testSpec = loadTestSpec(testName) val classSpecs = loadClassSpecs(testName) @@ -71,9 +54,8 @@ class TestTranslator(options: CLIOptions) { fw.close() } - def loadTestSpec(testName: String): TestSpec = { + def loadTestSpec(testName: String): TestSpec = TestSpec.fromFile(s"$specKsDir/$testName.kst") - } def loadClassSpecs(testName: String): ClassSpecs = { val cliConfig = CLIConfig(importPaths = Seq(importsDir)) From 2f3c1a5a37e49c370cf8b873c52ccc7160fc2bdd Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 17 Apr 2024 22:48:28 +0200 Subject: [PATCH 168/198] Revert "`doTestSpec(..., exactOutDir: Boolean)`" This reverts commit 80deccf926d2cd01062ec9fa0b63d5106360e755. --- .../io/kaitai/struct/testtranslator/TestTranslator.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index 2817b370d..3efc9a5ca 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -6,7 +6,7 @@ import io.kaitai.struct.datatype.DataType.UserTypeInstream import io.kaitai.struct.format._ import io.kaitai.struct.formats.JavaKSYParser import io.kaitai.struct.problems.ProblemSeverity -import io.kaitai.struct.testtranslator.Main.{CLIOptions, defaultOutDir} +import io.kaitai.struct.testtranslator.Main.CLIOptions import io.kaitai.struct.testtranslator.specgenerators._ import io.kaitai.struct.{ClassTypeProvider, CppRuntimeConfig} @@ -17,11 +17,11 @@ class TestTranslator(options: CLIOptions) { def run(): Unit = { options.srcFiles.foreach(testName => - doTestSpec(testName, options.targets, options.outDir, options.outDir != defaultOutDir) + doTestSpec(testName, options.targets, options.outDir) ) } - def doTestSpec(testName: String, langs: Seq[String], outDir: String, exactOutDir: Boolean): Unit = { + def doTestSpec(testName: String, langs: Seq[String], outDir: String): Unit = { Console.println(s"Translating: $testName") val testSpec = loadTestSpec(testName) @@ -32,7 +32,7 @@ class TestTranslator(options: CLIOptions) { langs.foreach(langName => { val sg = getSG(langName, testSpec, provider, classSpecs) try { - val outFile = if(exactOutDir) { s"$outDir/${sg.fileName(testName)}" } else { s"$outDir/$langName/${sg.fileName(testName)}" } + val outFile = s"$outDir/$langName/${sg.fileName(testName)}" Console.println(s"... generating $outFile") sg.run() writeFile(outFile, sg.results) From 0ce1363dbf17a36e38ce9db94a3c6996615e3b3b Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 17 Apr 2024 22:50:49 +0200 Subject: [PATCH 169/198] Revert "make specKsDir and formatsDir fields" This reverts commit fe40ee2f1740a749f27188da2adb432f44182576. --- .../scala/io/kaitai/struct/testtranslator/Main.scala | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala index 4ceff3708..99e8f77f1 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/Main.scala @@ -1,16 +1,15 @@ package io.kaitai.struct.testtranslator import java.io.File + import _root_.io.kaitai.struct.format._ import io.kaitai.struct.Version object Main extends App { - var baseDir = ".." + val baseDir = ".." val specDir = s"$baseDir/spec" - def specKsDir = s"$baseDir/spec/ks" - def specKsDir_=(v:String) { specKsDir = v } - def formatsDir = s"$baseDir/formats" - def formatsDir_=(v:String) { formatsDir = v } + val specKsDir = s"$baseDir/spec/ks" + val formatsDir = s"$baseDir/formats" val defaultOutDir = s"$specKsDir/out" val importsDir = s"$baseDir/../formats" From 5cd20211455cc1ecb57c5ea8ffeec92df70db89a Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 17 Apr 2024 23:14:46 +0200 Subject: [PATCH 170/198] RustSG: generate into `spec/rust/tests/` to match existing specs --- .../io/kaitai/struct/testtranslator/specgenerators/RustSG.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 90130ec28..1484bdc33 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -17,7 +17,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs var do_panic = true var do_not_deref = false - override def fileName(name: String): String = s"test_$name.rs" + override def fileName(name: String): String = s"tests/test_$name.rs" override def header(): Unit = { importList.add("#![allow(unused_variables)]") From 2cdfecb4a69b5c48bb801aede4e039e786c32d51 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Thu, 18 Apr 2024 14:41:46 +0200 Subject: [PATCH 171/198] translator/project/build.properties: fix missing final newline --- translator/project/build.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translator/project/build.properties b/translator/project/build.properties index 331a838c9..b19d4e1ed 100644 --- a/translator/project/build.properties +++ b/translator/project/build.properties @@ -1 +1 @@ -sbt.version = 1.9.7 \ No newline at end of file +sbt.version = 1.9.7 From b2b942f7c56641c59fe78acf33d69d9c917519a3 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 21 Apr 2024 10:20:48 +0200 Subject: [PATCH 172/198] partial_builder: change `create_project` to return `Array` --- builder/cpp_builder.rb | 2 +- builder/csharp_builder.rb | 2 +- builder/java_builder.rb | 2 +- builder/partial_builder.rb | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builder/cpp_builder.rb b/builder/cpp_builder.rb index c1e5f1d47..01817575f 100644 --- a/builder/cpp_builder.rb +++ b/builder/cpp_builder.rb @@ -85,7 +85,7 @@ def create_project(mand_files, disp_files) (mand_files + disp_files).each { |l| f.puts(l) } f.puts(")") } - @disposable_cmake + [@disposable_cmake] end def build_project(log_file) diff --git a/builder/csharp_builder.rb b/builder/csharp_builder.rb index b09def5d5..0dd128a68 100644 --- a/builder/csharp_builder.rb +++ b/builder/csharp_builder.rb @@ -82,7 +82,7 @@ def create_project(mand_files, disp_files) files_xml = (mand_files + disp_files).map { |x| " " }.join("\n") project = tmpl.gsub(/%%%FILES%%%/, files_xml) File.write(@project_file, project) - @project_file + [@project_file] end def build_project(log_file) diff --git a/builder/java_builder.rb b/builder/java_builder.rb index 237555432..67ac4b790 100644 --- a/builder/java_builder.rb +++ b/builder/java_builder.rb @@ -40,7 +40,7 @@ def create_project(mand_files, disp_files) File.open(@project_file, 'w') { |f| (mand_files + disp_files).each { |l| f.puts "\"#{l}\"" } } - @project_file + [@project_file] end def build_project(log_file) diff --git a/builder/partial_builder.rb b/builder/partial_builder.rb index 6626da384..3cbd5ac31 100644 --- a/builder/partial_builder.rb +++ b/builder/partial_builder.rb @@ -33,8 +33,8 @@ def command_line(arg) l1 = list_mandatory_files l2 = list_disposable_files log "creating project with #{(l1 + l2).size} files" - fn = create_project(l1, l2) - log "project file created: #{fn.inspect}" + fns = create_project(l1, l2) + log "project files created: #{fns.inspect}" elsif arg == ['--once'] @max_attempts = 1 exit run @@ -78,8 +78,8 @@ def partial_build attempt_str = @max_attempts ? "#{attempt}/#{@max_attempts}" : attempt log "creating project with #{disp_files.size}/#{orig_size} files" - fn = create_project(mand_files, disp_files) - log "project file created: #{fn.inspect}" + fns = create_project(mand_files, disp_files) + log "project files created: #{fns.inspect}" build_log = "#{@test_out_dir}/build-#{attempt}.log" log "build attempt #{attempt_str} (log: #{build_log})" @@ -215,7 +215,7 @@ def list_disposable_files # Creates a project file, given a list of disposable and mandatory # files to include in it. - # @return [String] project file name created + # @return [Array] project file names created def create_project(mand_files, disp_files) raise NotImplementedError end From 5e25ef06962db7c9abe50ef63747bddba5873976 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 5 May 2024 12:28:20 +0200 Subject: [PATCH 173/198] Rust: add partial builder, fully implement ci-rust As mentioned in https://github.com/kaitai-io/kaitai_struct_tests/pull/43#issuecomment-414091763, the necessity of `build.rs` was questionable, because it was just a long-winded `cp compiled/rust/*.rs spec/rust/src/formats/` with the creation of `spec/rust/src/formats/mod.rs` with a list of the `compiled/rust/*.rs` basenames. The copying was replaced by a symlink at `spec/rust/src/formats` pointing to `compiled/rust`, which practically means that all `compiled/rust/*` files transparently appear in `spec/rust/src/formats/` without effort. Rust now uses the `PartialBuilder` framework just like C++, C# or Java - see `builder/rust_builder.rb`. To allow excluding those `compiled/rust/*.rs` files with errors from the build, `spec/rust/src/formats.rs` is auto-generated and contains `pub mod {format};` lines for good `spec/rust/src/formats/*.rs` files (which are effectively `compiled/rust/*.rs` files) - this is very similar to what `build.rs` was doing. To allow excluding bad `spec/rust/tests/test_*.rs` files (which `build.rs` didn't deal with at all), the [auto-discovery](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#target-auto-discovery) of integration test targets has been disabled and we now have only one integration test called `spec`. This allows us to use the same approach for excluding bad tests as we used for formats, simply by auto-generating a list of good test modules in `spec/rust/tests/spec.rs`. Having only one integration test instead of a bunch of integration tests is supposedly also more efficient, see https://doc.rust-lang.org/cargo/reference/cargo-targets.html#integration-tests: > Each integration test results in a separate executable binary, and > `cargo test` will run them serially. In some cases this can be > inefficient, as it can take longer to compile, and may not make full > use of multiple CPUs when running the tests. > If you have a lot of integration tests, you may want to consider > creating a single integration test, and split the tests into multiple > modules. The libtest harness will automatically find all of the > `#[test]` annotated functions and run them in parallel. `RustBuilder` uses `cargo check` to find out a subset of formats and test specs without build errors. Then we basically want `cargo test` to build everything and run the tests, but `cargo test` in stable Rust can't generate machine-readable test reports (nightly Rust has an option to generate JSON reports, but it's an unstable feature), so we're using `cargo nextest run` instead of `cargo test`. This requires the `cargo-nextest` crate - see https://nexte.st/. This library generates JUnit XML reports for us. --- .gitignore | 10 +- aggregate/convert_to_json | 10 +- aggregate/junit_xml_parser.rb | 3 + builder/partial_builder.rb | 2 + builder/rust_builder.rb | 215 +++++++++++++++++++++++++++++++++ ci-rust | 10 +- kst-adoption-report | 5 + run-rust | 11 +- spec/rust/.config/nextest.toml | 12 ++ spec/rust/Cargo.toml | 5 +- spec/rust/build.rs | 115 ------------------ spec/rust/src/formats | 1 + 12 files changed, 263 insertions(+), 136 deletions(-) create mode 100644 builder/rust_builder.rb create mode 100644 spec/rust/.config/nextest.toml delete mode 100644 spec/rust/build.rs create mode 120000 spec/rust/src/formats diff --git a/.gitignore b/.gitignore index ac08fd45a..3ef97d4b3 100644 --- a/.gitignore +++ b/.gitignore @@ -12,8 +12,12 @@ __pycache__/ _* spec/nim/bin -# Rust compiled code, cargo and rls data +# Rust + +## Cargo lockfile and build cache spec/rust/Cargo.lock spec/rust/target/ -spec/rust/src/formats/ -spec/rust/.vscode + +## Files auto-generated by builder/rust_builder.rb +spec/rust/tests/spec.rs +spec/rust/src/formats.rs diff --git a/aggregate/convert_to_json b/aggregate/convert_to_json index faae9488f..0b49120e9 100755 --- a/aggregate/convert_to_json +++ b/aggregate/convert_to_json @@ -80,13 +80,19 @@ when 'java' ), infile ) +when 'rust' + add_kst_adoption( + add_fails( + JUnitXMLParser.new("#{infile}/report.xml").to_h, + BuildFailedParser.new("#{infile}/build_failed_tests.txt").to_h + ), + infile + ) when 'lua', 'nim' add_kst_adoption( JUnitXMLParser.new("#{infile}/report.xml").to_h, infile ) -when 'rust' - JUnitXMLParser.new(infile).to_h when 'go', 'perl', 'python', 'construct' add_kst_adoption( JUnitXMLParser.new("#{infile}/report.xml").to_h, diff --git a/aggregate/junit_xml_parser.rb b/aggregate/junit_xml_parser.rb index 0059120ca..05b9c5271 100644 --- a/aggregate/junit_xml_parser.rb +++ b/aggregate/junit_xml_parser.rb @@ -33,6 +33,9 @@ def each_test elsif name =~ /^t(?!est)(.*?)$/ # Nim output name = underscore_to_ucamelcase($1) + elsif name =~ /^test_.*::test_(.*?)$/ + # Rust output + name = underscore_to_ucamelcase($1) else raise "Unable to parse name: \"#{name}\"" unless name =~ /^[Tt]est(.*?)$/ if $1[0] == '_' diff --git a/builder/partial_builder.rb b/builder/partial_builder.rb index 3cbd5ac31..e3c8273d2 100644 --- a/builder/partial_builder.rb +++ b/builder/partial_builder.rb @@ -215,6 +215,8 @@ def list_disposable_files # Creates a project file, given a list of disposable and mandatory # files to include in it. + # @param mand_files [Enumerable] collection of mandatory files + # @param disp_files [Enumerable] collection of disposable files # @return [Array] project file names created def create_project(mand_files, disp_files) raise NotImplementedError diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb new file mode 100644 index 000000000..5e7cbbd93 --- /dev/null +++ b/builder/rust_builder.rb @@ -0,0 +1,215 @@ +require 'fileutils' +require 'set' +require 'json' + +require_relative 'partial_builder' +require_relative 'shellconfig' + +class RustBuilder < PartialBuilder + def initialize + super + + base_spec_dir = 'spec/rust' + @base_spec_dir = File.absolute_path(base_spec_dir) + + @spec_dir = File.join(@base_spec_dir, 'tests') + @formats_dir = File.join(@base_spec_dir, 'src/formats') + @spec_list_file = File.join(@base_spec_dir, 'tests/spec.rs') + @formats_list_file = File.join(@base_spec_dir, 'src/formats.rs') + + test_out_dir = File.join(@config['TEST_OUT_DIR'], 'rust') + @test_out_dir = File.absolute_path(test_out_dir) + end + + def list_mandatory_files + [] + end + + def list_disposable_files + spec_basenames = Dir.glob('test_*.rs', base: @spec_dir) + format_basenames = Dir.glob('*.rs', base: @formats_dir) + + spec_basenames.map { |fn| File.join(@spec_dir, fn) } + + format_basenames.map { |fn| File.join(@formats_dir, fn) } + end + + def create_project(mand_files, disp_files) + grouped_files = mand_files.chain(disp_files).group_by { |fn| file_to_kind(fn) } + if grouped_files.key?(nil) + raise "unexpected files that are neither ':spec' or ':format': #{grouped_files[nil].inspect}" + end + + File.open(@spec_list_file, 'w') { |f| + grouped_files[:spec].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" } + } + File.open(@formats_list_file, 'w') { |f| + f.puts '#![allow(unused_parens)]' + f.puts '#![allow(dead_code)]' + grouped_files[:format].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" } + } + [@spec_list_file, @formats_list_file] + end + + def build_project(log_file) + Dir.chdir(@base_spec_dir) do + cli = %w[cargo check --test spec --message-format json] + run_cargo_build({}, cli, log_file).exitstatus + end + end + + def parse_failed_build(log_file) + list = [] + + File.open(log_file, 'r') { |f| + f.each_line { |line| + line.chomp! + # See https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages + cargo_msg = JSON.parse(line) + + # See https://doc.rust-lang.org/cargo/reference/external-tools.html#build-finished: + # > The "build-finished" message is emitted at the end of the build. + # + # > This message can be helpful for tools to know when to stop reading JSON messages. + break if cargo_msg['reason'] == 'build-finished' + + next unless cargo_msg['reason'] == 'compiler-message' + + # See https://doc.rust-lang.org/rustc/json.html + rustc_msg = cargo_msg['message'] + next unless rustc_msg['$message_type'] == 'diagnostic' + next unless rustc_msg['level'] == 'error' + + files = + rustc_msg['spans'] + .select { |span| span['is_primary'] } + .map { |span| File.absolute_path(span['file_name'], @base_spec_dir) } + + list.concat(files) + } + } + + list + end + + def file_to_test(path) + kind = file_to_kind(path) + basename = File.basename(path, '.rs') + test_name = kind == :spec ? basename.delete_prefix('test_') : basename + [kind, underscore_to_ucamelcase(test_name)] + end + + def run_tests + Dir.chdir(@base_spec_dir) do + # We specify `--cargo-quiet` twice "for no Cargo output at all" (see + # https://nexte.st/book/running?highlight=--cargo-quiet#options-and-arguments). + # The point is that the `build_project` method has already run + # `cargo check`, recovered from errors and printed all warnings, so + # there's no need to see the same warnings again. + cli = %w[cargo nextest run --test spec --cargo-quiet --cargo-quiet] + out_log = File.join(@test_out_dir, 'test_run.stdout') + run_and_tee({}, cli, out_log) + + # See spec/rust/.config/nextest.toml + src_path = File.join(@base_spec_dir, 'target/nextest/default/junit.xml') + dest_path = File.join(@test_out_dir, 'report.xml') + FileUtils.copy_file(src_path, dest_path) + true + end + end + + private + + def file_to_kind(path) + if path_directly_in_dir?(path, @spec_dir) + :spec + elsif path_directly_in_dir?(path, @formats_dir) + :format + end + end + + def run_cargo_build(environment, cmd, stdout_file) + log "running command: #{cmd.inspect}, log: #{stdout_file.inspect}" + process_status = nil + FileUtils.mkdir_p(File.dirname(stdout_file)) + File.open(stdout_file, 'w') { |f| + Open3.popen3(environment, *cmd) { |_stdin, stdout, _stderr, wait_thread| + while (line = stdout.gets) + line.chomp! + line_summary = summarize_cargo_json_line(line) + puts line_summary unless line_summary.nil? + f.puts line + end + process_status = wait_thread.value + } + } + log "process_status: #{process_status.inspect}" + process_status + end + + def summarize_cargo_json_line(line) + begin + # See https://doc.rust-lang.org/cargo/reference/external-tools.html#json-messages + cargo_msg = JSON.parse(line) + rescue JSON::ParserError => e + warn e.full_message + return line + end + reason = cargo_msg['reason'] + + case reason + when 'compiler-message' + # See https://doc.rust-lang.org/rustc/json.html + rustc_msg = cargo_msg['message'] + + if rustc_msg['$message_type'] == 'diagnostic' + files = + rustc_msg['spans'] + .select { |span| span['is_primary'] } + .uniq { |span| span['file_name'] } + .map { |span| "#{span['file_name']}:#{span['line_start']}:#{span['column_start']}" } + code_appendix = rustc_msg['code'].nil? ? '' : "[#{rustc_msg['code']['code']}]" + files_prefix = + if files.empty? + '' + else + "#{files.join(', ')}: " + end + "#{files_prefix}#{rustc_msg['level']}#{code_appendix}: #{rustc_msg['message']}" + else + line + end + when 'compiler-artifact', 'build-script-executed' + # "[#{reason}] #{cargo_msg['package_id']}" + nil + when 'build-finished' + "[#{reason}] success: #{cargo_msg['success']}" + else + line + end + end + + # Returns +true+ if +path+ is directly contained in the +dir_abs_path+ directory, and + # +false+ otherwise. + # + # The +dir_abs_path+ argument is expected to be normalized as if returned by + # the +File.absolute_path+ method, i.e. directory parts in path separated only + # by +File::SEPARATOR+ (forward slash +/+ on all platforms) and never + # +File::ALT_SEPARATOR+ (backslash +\+ on Windows), multiple consecutive + # slashes collapsed into one, no useless dots (+./+ or +../+ parts), no + # trailing slash, etc. + # @param path [String] relative (to the current directory) or absolute path + # @param dir_abs_path [String] normalized absolute path of the directory + def path_directly_in_dir?(path, dir_abs_path) + abs_path = File.absolute_path(path) + dir_abs_path += File::SEPARATOR + return false unless abs_path.start_with?(dir_abs_path) + + path_rel_to_dir = abs_path.delete_prefix(dir_abs_path) + path_basename = File.basename(abs_path) + path_rel_to_dir == path_basename + end + + def underscore_to_ucamelcase(s) + s.split(/_/).map { |x| x.capitalize }.join + end +end diff --git a/ci-rust b/ci-rust index 6afe5c4e7..14ddd4bdb 100755 --- a/ci-rust +++ b/ci-rust @@ -2,11 +2,7 @@ . ./config -mkdir -p "$TEST_OUT_DIR/rust" +./run-rust -cd spec/rust -mkdir src -touch src/lib.rs -cargo build -cargo test-junit \ - --name "../../$TEST_OUT_DIR/rust/results.xml" +./kst-adoption-report rust +aggregate/convert_to_json rust "$TEST_OUT_DIR/rust" "$TEST_OUT_DIR/rust/ci.json" diff --git a/kst-adoption-report b/kst-adoption-report index 571869ae0..4adba64ec 100755 --- a/kst-adoption-report +++ b/kst-adoption-report @@ -34,6 +34,8 @@ def glob_spec_files(lang) Dir.glob('spec/construct/**/test_*.py') when 'ruby' Dir.glob('spec/ruby/**/*_spec.rb') + when 'rust' + Dir.glob('spec/rust/tests/test_*.rs') else raise "Unable to handle language #{@lang.inspect}" end @@ -74,6 +76,9 @@ def spec_file_to_test_name(lang, fn) when 'ruby' raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^(.*?)_spec\.rb$/ underscore_to_ucamelcase($1) + when 'rust' + raise "Unable to extract test name from #{fn.inspect}" unless fn =~ /^test_(.*?)\.rs$/ + underscore_to_ucamelcase($1) else raise "Unable to handle language #{lang.inspect}" end diff --git a/run-rust b/run-rust index 25d24bb74..5189618ad 100755 --- a/run-rust +++ b/run-rust @@ -1,9 +1,4 @@ -#!/bin/sh +#!/usr/bin/env ruby -. ./config - -mkdir -p "$TEST_OUT_DIR/rust" - -cd spec/rust -cargo build -cargo test +require_relative 'builder/rust_builder' +RustBuilder.new.command_line(ARGV) diff --git a/spec/rust/.config/nextest.toml b/spec/rust/.config/nextest.toml new file mode 100644 index 000000000..c02e26555 --- /dev/null +++ b/spec/rust/.config/nextest.toml @@ -0,0 +1,12 @@ +# See https://nexte.st/book/configuration#profiles +[profile.default] +# Print out output for failing tests as soon as they fail, and also at the end +# of the run (for easy scrollability). +failure-output = "immediate-final" +# Do not cancel the test run on the first failure. +fail-fast = false + +# See https://nexte.st/book/junit +[profile.default.junit] +# a JUnit report will be written out to spec/rust/target/nextest/default/junit.xml +path = "junit.xml" diff --git a/spec/rust/Cargo.toml b/spec/rust/Cargo.toml index 74664a9e4..a33527d9c 100644 --- a/spec/rust/Cargo.toml +++ b/spec/rust/Cargo.toml @@ -3,7 +3,10 @@ name = "rust" version = "0.1.0" authors = ["Aon"] edition = "2018" -build = "build.rs" +autotests = false [dependencies] kaitai = { path = "../../../runtime/rust" } + +[[test]] +name = "spec" diff --git a/spec/rust/build.rs b/spec/rust/build.rs deleted file mode 100644 index eb023ba60..000000000 --- a/spec/rust/build.rs +++ /dev/null @@ -1,115 +0,0 @@ -use std::{ - ffi::OsStr, - fs, - io::{self, prelude::*}, - path::Path, -}; - -pub fn path_exists(path: &Path) -> bool { - fs::metadata(path).is_ok() -} - -fn main() { - let source_path = Path::new("../../compiled/rust"); - let destination_path = Path::new("./src/formats"); - - if !path_exists(destination_path) { - fs::create_dir(destination_path).unwrap_or_else(|e| { - println!("Unable to create dir: {}", e.to_string()); - }); - } - - let rm_except_files = vec![]; - - // we don't support this tests yet - let copy_except_files = vec![ - "nav_parent_switch_cast.rs", - "params_pass_array_struct.rs", - "params_pass_struct.rs", - "process_coerce_switch.rs", - ]; - - remove_existing(destination_path, rm_except_files).unwrap_or_else(|e| { - println!( - "Unable to remove existing files under test: {}", - e.to_string() - ); - }); - - copy_new(source_path, destination_path, copy_except_files).unwrap_or_else(|e| { - println!("Unable to copy new files under test: {}", e.to_string()); - }); - - println!( - "cargo:rerun-if-changed={}", - source_path.display().to_string() - ); -} - -fn remove_existing(destination_path: &Path, except_files: Vec<&str>) -> io::Result<()> { - for entry in fs::read_dir(destination_path)? { - let entry = entry?; - let path = entry.path(); - let file_name = path.file_name().unwrap().to_os_string(); - - if except_files.iter().find(|&&x| *x == file_name).is_none() { - println!("cleaning {}", path.display().to_string()); - fs::remove_file(path)?; - } else { - println!("leaving {}", path.display().to_string()); - } - } - - Ok(()) -} - -fn copy_new( - source_path: &Path, - destination_path: &Path, - except_files: Vec<&str>, -) -> io::Result<()> { - let mut librs = fs::File::create(destination_path.join("mod.rs"))?; - - write!(librs, "#![allow(unused_parens)]\n")?; - write!(librs, "#![allow(dead_code)]\n")?; - - for entry in fs::read_dir(source_path)? { - let entry = entry?; - let path = entry.path(); - - if path.extension().unwrap_or(&OsStr::new("")) != "rs" { - continue; - } - - let file_name = path.file_name().unwrap().to_os_string(); - if except_files.iter().find(|&&x| *x == file_name).is_none() { - fs::copy(path.clone(), destination_path.join(file_name.clone()))?; - println!( - "copying {} to {}", - path.as_path().display().to_string(), - destination_path - .join(file_name.clone()) - .as_path() - .display() - .to_string() - ); - - write!( - librs, - "pub mod {};\n", - path.file_stem().unwrap().to_str().unwrap() - )?; - println!( - "updating lib.rs with {}", - path.file_stem().unwrap().to_str().unwrap() - ); - } else { - println!( - "skipping (not yet supported) {}", - path.display().to_string() - ); - } - } - - Ok(()) -} diff --git a/spec/rust/src/formats b/spec/rust/src/formats new file mode 120000 index 000000000..22b964e74 --- /dev/null +++ b/spec/rust/src/formats @@ -0,0 +1 @@ +../../../compiled/rust \ No newline at end of file From 6825a33e1d70f7496249545e15972c41597d9487 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 6 May 2024 11:49:58 +0200 Subject: [PATCH 174/198] rust_builder: don't use `--cargo-quiet` when building tests We probably shouldn't try to be "smart" here. The assumption that all diagnostic messages (errors, warnings) were already resolved in the `cargo check` (so we can losslessly suppress any Cargo output) might not always hold, see : > Some diagnostics and errors are only emitted during code generation, > so they inherently won't be reported with `cargo check`. --- builder/rust_builder.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb index 5e7cbbd93..48ad2b80e 100644 --- a/builder/rust_builder.rb +++ b/builder/rust_builder.rb @@ -100,12 +100,7 @@ def file_to_test(path) def run_tests Dir.chdir(@base_spec_dir) do - # We specify `--cargo-quiet` twice "for no Cargo output at all" (see - # https://nexte.st/book/running?highlight=--cargo-quiet#options-and-arguments). - # The point is that the `build_project` method has already run - # `cargo check`, recovered from errors and printed all warnings, so - # there's no need to see the same warnings again. - cli = %w[cargo nextest run --test spec --cargo-quiet --cargo-quiet] + cli = %w[cargo nextest run --test spec] out_log = File.join(@test_out_dir, 'test_run.stdout') run_and_tee({}, cli, out_log) From 1e0517be4224e9b2637aca31f0c5df20069a67a4 Mon Sep 17 00:00:00 2001 From: Oleg Dolgov Date: Mon, 24 Jun 2024 12:50:18 +0200 Subject: [PATCH 175/198] move generated tests from base dir to tests subdir. --- builder/rust_builder.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb index 48ad2b80e..46d95c102 100644 --- a/builder/rust_builder.rb +++ b/builder/rust_builder.rb @@ -13,6 +13,12 @@ def initialize @base_spec_dir = File.absolute_path(base_spec_dir) @spec_dir = File.join(@base_spec_dir, 'tests') + FileUtils.mkdir_p(@spec_dir) + + # move generated tests from base dir to tests subdir + spec_files = Dir.glob('test_*.rs', base: @base_spec_dir) + spec_files.map { |fn| FileUtils.mv(File.join(@base_spec_dir, fn), @spec_dir) } + @formats_dir = File.join(@base_spec_dir, 'src/formats') @spec_list_file = File.join(@base_spec_dir, 'tests/spec.rs') @formats_list_file = File.join(@base_spec_dir, 'src/formats.rs') From 58aff8e191d679801ac79dc7d37d5441003722a7 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sat, 31 Aug 2024 18:21:02 +0200 Subject: [PATCH 176/198] Revert "move generated tests from base dir to tests subdir." This reverts commit 1e0517be4224e9b2637aca31f0c5df20069a67a4. --- builder/rust_builder.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb index 46d95c102..48ad2b80e 100644 --- a/builder/rust_builder.rb +++ b/builder/rust_builder.rb @@ -13,12 +13,6 @@ def initialize @base_spec_dir = File.absolute_path(base_spec_dir) @spec_dir = File.join(@base_spec_dir, 'tests') - FileUtils.mkdir_p(@spec_dir) - - # move generated tests from base dir to tests subdir - spec_files = Dir.glob('test_*.rs', base: @base_spec_dir) - spec_files.map { |fn| FileUtils.mv(File.join(@base_spec_dir, fn), @spec_dir) } - @formats_dir = File.join(@base_spec_dir, 'src/formats') @spec_list_file = File.join(@base_spec_dir, 'tests/spec.rs') @formats_list_file = File.join(@base_spec_dir, 'src/formats.rs') From 17f73ff7d30914561430f6cf2a16e7e9aa83c618 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 6 May 2024 14:47:03 +0200 Subject: [PATCH 177/198] Rust: delete misplaced `spec/rust/*.rs` files --- spec/rust/test_enum_import_literals.rs | 17 ------------ spec/rust/test_enum_to_i.rs | 22 --------------- spec/rust/test_expr_fstring_0.rs | 23 ---------------- spec/rust/test_expr_io_ternary.rs | 17 ------------ .../test_imports_params_def_enum_imported.rs | 18 ------------- spec/rust/test_nested_types_import.rs | 17 ------------ spec/rust/test_params_call.rs | 27 ------------------- 7 files changed, 141 deletions(-) delete mode 100644 spec/rust/test_enum_import_literals.rs delete mode 100644 spec/rust/test_enum_to_i.rs delete mode 100644 spec/rust/test_expr_fstring_0.rs delete mode 100644 spec/rust/test_expr_io_ternary.rs delete mode 100644 spec/rust/test_imports_params_def_enum_imported.rs delete mode 100644 spec/rust/test_nested_types_import.rs delete mode 100644 spec/rust/test_params_call.rs diff --git a/spec/rust/test_enum_import_literals.rs b/spec/rust/test_enum_import_literals.rs deleted file mode 100644 index 000c6dcf4..000000000 --- a/spec/rust/test_enum_import_literals.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumImportLiterals; - -#[test] -fn test_enum_import_literals() { - if let Ok(r) = EnumImportLiterals::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1_to_i, 7); - assert_eq!(r.pet_1_eq, true); - assert_eq!(r.pet_2, EnumDeep__Container1__Container2__Animal::HARE); - } -} diff --git a/spec/rust/test_enum_to_i.rs b/spec/rust/test_enum_to_i.rs deleted file mode 100644 index 6ed2bb37e..000000000 --- a/spec/rust/test_enum_to_i.rs +++ /dev/null @@ -1,22 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::EnumToI; - -#[test] -fn test_enum_to_i() { - if let Ok(r) = EnumToI::from_file("src/enum_0.bin") { - - assert_eq!(r.pet_1, EnumToI__Animal::CAT); - assert_eq!(r.pet_2, EnumToI__Animal::CHICKEN); - assert_eq!(r.pet_1_i, 7); - assert_eq!(r.pet_1_i_to_s, "7"); - assert_eq!(r.pet_1_mod, 32775); - assert_eq!(r.one_lt_two, true); - assert_eq!(r.pet_1_eq_int, true); - assert_eq!(r.pet_2_eq_int, false); - } -} diff --git a/spec/rust/test_expr_fstring_0.rs b/spec/rust/test_expr_fstring_0.rs deleted file mode 100644 index 7552f02d4..000000000 --- a/spec/rust/test_expr_fstring_0.rs +++ /dev/null @@ -1,23 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprFstring0; - -#[test] -fn test_expr_fstring_0() { - if let Ok(r) = ExprFstring0::from_file("src/term_strz.bin") { - - assert_eq!(r.seq_str, "foo|b"); - assert_eq!(r.seq_int, 97); - assert_eq!(r.empty, ""); - assert_eq!(r.literal, "abc"); - assert_eq!(r.literal_with_escapes, "abc\n\tt"); - assert_eq!(r.head_and_int_literal, "abc=123"); - assert_eq!(r.head_and_str_literal, "abc=foo"); - assert_eq!(r.head_and_int, "abc=97"); - assert_eq!(r.head_and_str, "abc=foo|b"); - } -} diff --git a/spec/rust/test_expr_io_ternary.rs b/spec/rust/test_expr_io_ternary.rs deleted file mode 100644 index 5fc6c9715..000000000 --- a/spec/rust/test_expr_io_ternary.rs +++ /dev/null @@ -1,17 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ExprIoTernary; - -#[test] -fn test_expr_io_ternary() { - if let Ok(r) = ExprIoTernary::from_file("src/if_struct.bin") { - - assert_eq!(r.one_or_two_io_size1, 8); - assert_eq!(r.one_or_two_io_size2, 8); - assert_eq!(r.one_or_two_io_size_add_3, 11); - } -} diff --git a/spec/rust/test_imports_params_def_enum_imported.rs b/spec/rust/test_imports_params_def_enum_imported.rs deleted file mode 100644 index 9e22015b1..000000000 --- a/spec/rust/test_imports_params_def_enum_imported.rs +++ /dev/null @@ -1,18 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::ImportsParamsDefEnumImported; - -#[test] -fn test_imports_params_def_enum_imported() { - if let Ok(r) = ImportsParamsDefEnumImported::from_file("src/enum_0.bin") { - - assert_eq!(r.one.pet_1, Enum0__Animal::CAT); - assert_eq!(r.one.pet_2, EnumDeep__Container1__Container2__Animal::HARE); - assert_eq!(r.two.pet_1_param, Enum0__Animal::CAT); - assert_eq!(r.two.pet_2_param, EnumDeep__Container1__Container2__Animal::HARE); - } -} diff --git a/spec/rust/test_nested_types_import.rs b/spec/rust/test_nested_types_import.rs deleted file mode 100644 index e37060a8d..000000000 --- a/spec/rust/test_nested_types_import.rs +++ /dev/null @@ -1,17 +0,0 @@ -extern crate kaitai_struct; -extern crate rust; - -use kaitai_struct::KaitaiStruct; -use rust::NestedTypesImport; - -#[test] -fn test_nested_types_import() { - if let Ok(r) = NestedTypesImport::from_file("src/fixed_struct.bin") { - - assert_eq!(r.a_cc.value_cc, 80); - assert_eq!(r.a_c_d.value_d, 65); - assert_eq!(r.b.value_b, 67); - assert_eq!(r.b.a_cc.value_cc, 75); - assert_eq!(r.b.a_c_d.value_d, 45); - } -} diff --git a/spec/rust/test_params_call.rs b/spec/rust/test_params_call.rs deleted file mode 100644 index 28349dde2..000000000 --- a/spec/rust/test_params_call.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] -use std::fs; -extern crate kaitai; -use self::kaitai::*; -use rust::formats::params_call::*; - -#[test] -fn test_params_call() { - let bytes = fs::read("../../src/term_strz.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res: KResult> = ParamsCall::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.buf1().body(), "foo|b"); - assert_eq!(*r.buf2().body(), "ar|ba"); - assert_eq!(*r.buf2().trailer(), 122); -} From 64aaeedc01747de2ec8bb2bba5e22f16a48e2261 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 8 May 2024 15:31:54 +0200 Subject: [PATCH 178/198] rust_builder: add test for errors in macro expansions See `builder/spec/rust/rust_builder_spec.rb` for more details. This test currently fails: ```console $ rspec builder/spec/rust/rust_builder_spec.rb #### RustBuilder: initialized F Failures: 1) RustBuilder macro_expansion #parse_failed_build parses failed build information Failure/Error: expect(@builder.parse_failed_build('test_out/rust/build-1.log')).to eq [ test_nested_path, test_nested_path, ] expected: ["/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs", "/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs"] got: ["/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs", "/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs"] (compared using ==) # ./builder/spec/rust/rust_builder_spec.rb:70:in `block (4 levels) in ' Finished in 0.03102 seconds (files took 0.14634 seconds to load) 1 example, 1 failure Failed examples: rspec ./builder/spec/rust/rust_builder_spec.rb:68 # RustBuilder macro_expansion #parse_failed_build parses failed build information ``` It will be fixed in the following commit by implementing the missing logic in `builder/rust_builder.rb`. --- builder/spec/rust/.gitignore | 3 + builder/spec/rust/macro_expansion/config | 1 + .../rust/macro_expansion/spec/rust/Cargo.toml | 9 +++ .../macro_expansion/spec/rust/src/formats.rs | 3 + .../spec/rust/src/formats/empty.rs | 0 .../macro_expansion/spec/rust/src/helpers.rs | 2 + .../rust/macro_expansion/spec/rust/src/lib.rs | 2 + .../macro_expansion/spec/rust/tests/spec.rs | 1 + .../spec/rust/tests/test_nested.rs | 8 ++ .../macro_expansion/test_out/rust/build-1.log | 7 ++ builder/spec/rust/rust_builder_spec.rb | 77 +++++++++++++++++++ 11 files changed, 113 insertions(+) create mode 100644 builder/spec/rust/.gitignore create mode 100644 builder/spec/rust/macro_expansion/config create mode 100644 builder/spec/rust/macro_expansion/spec/rust/Cargo.toml create mode 100644 builder/spec/rust/macro_expansion/spec/rust/src/formats.rs create mode 100644 builder/spec/rust/macro_expansion/spec/rust/src/formats/empty.rs create mode 100644 builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs create mode 100644 builder/spec/rust/macro_expansion/spec/rust/src/lib.rs create mode 100644 builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs create mode 100644 builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs create mode 100644 builder/spec/rust/macro_expansion/test_out/rust/build-1.log create mode 100644 builder/spec/rust/rust_builder_spec.rb diff --git a/builder/spec/rust/.gitignore b/builder/spec/rust/.gitignore new file mode 100644 index 000000000..e4b9ffa4b --- /dev/null +++ b/builder/spec/rust/.gitignore @@ -0,0 +1,3 @@ +## Cargo lockfile and build cache +*/spec/rust/Cargo.lock +*/spec/rust/target/ diff --git a/builder/spec/rust/macro_expansion/config b/builder/spec/rust/macro_expansion/config new file mode 100644 index 000000000..ddf89ece9 --- /dev/null +++ b/builder/spec/rust/macro_expansion/config @@ -0,0 +1 @@ +TEST_OUT_DIR=test_out diff --git a/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml b/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml new file mode 100644 index 000000000..e81cde3f0 --- /dev/null +++ b/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rust" +edition = "2018" +autotests = false + +[dependencies] + +[[test]] +name = "spec" diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/formats.rs b/builder/spec/rust/macro_expansion/spec/rust/src/formats.rs new file mode 100644 index 000000000..ddbd86e1d --- /dev/null +++ b/builder/spec/rust/macro_expansion/spec/rust/src/formats.rs @@ -0,0 +1,3 @@ +#![allow(unused_parens)] +#![allow(dead_code)] +pub mod empty; diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/formats/empty.rs b/builder/spec/rust/macro_expansion/spec/rust/src/formats/empty.rs new file mode 100644 index 000000000..e69de29bb diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs b/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs new file mode 100644 index 000000000..87a6eeeec --- /dev/null +++ b/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs @@ -0,0 +1,2 @@ +#[macro_export] +macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } } diff --git a/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs b/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs new file mode 100644 index 000000000..a3e9c547e --- /dev/null +++ b/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs @@ -0,0 +1,2 @@ +pub mod formats; +mod helpers; diff --git a/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs b/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs new file mode 100644 index 000000000..d2338d315 --- /dev/null +++ b/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs @@ -0,0 +1 @@ +pub mod test_nested; diff --git a/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs b/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs new file mode 100644 index 000000000..4d9dc7021 --- /dev/null +++ b/builder/spec/rust/macro_expansion/spec/rust/tests/test_nested.rs @@ -0,0 +1,8 @@ +use rust::our_assert_eq_wrapper; + +#[test] +fn test_nested() { + // NOTE: This line intentionally triggers a "can't compare `{integer}` with `{float}`" + // error to check if RustBuilder recovers from it. + our_assert_eq_wrapper!(4, 2.5); +} diff --git a/builder/spec/rust/macro_expansion/test_out/rust/build-1.log b/builder/spec/rust/macro_expansion/test_out/rust/build-1.log new file mode 100644 index 000000000..1d89fdd62 --- /dev/null +++ b/builder/spec/rust/macro_expansion/test_out/rust/build-1.log @@ -0,0 +1,7 @@ +{"reason":"compiler-artifact","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["lib"],"crate_types":["lib"],"name":"rust","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/lib.rs","edition":"2018","doc":true,"doctest":true,"test":true},"profile":{"opt_level":"0","debuginfo":2,"debug_assertions":true,"overflow_checks":true,"test":false},"features":[],"filenames":["/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/target/debug/deps/librust-5cc6c6ffe0c910dd.rmeta"],"executable":null,"fresh":false} +{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"error[E0277]: can't compare `{integer}` with `{float}`\n --> tests/test_nested.rs:7:5\n |\n7 | our_assert_eq_wrapper!(4, 2.5);\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no implementation for `{integer} == {float}`\n |\n = help: the trait `PartialEq<{float}>` is not implemented for `{integer}`\n = help: the following other types implement trait `PartialEq`:\n isize\n i8\n i16\n i32\n i64\n i128\n usize\n u8\n and 6 others\n = note: this error originates in the macro `assert_eq` which comes from the expansion of the macro `our_assert_eq_wrapper` (in Nightly builds, run with -Z macro-backtrace for more info)\n\n","$message_type":"diagnostic","children":[{"children":[],"code":null,"level":"help","message":"the trait `PartialEq<{float}>` is not implemented for `{integer}`","rendered":null,"spans":[]},{"children":[],"code":null,"level":"help","message":"the following other types implement trait `PartialEq`:\n isize\n i8\n i16\n i32\n i64\n i128\n usize\n u8\nand 6 others","rendered":null,"spans":[]}],"code":{"code":"E0277","explanation":"You tried to use a type which doesn't implement some trait in a place which\nexpected that trait.\n\nErroneous code example:\n\n```compile_fail,E0277\n// here we declare the Foo trait with a bar method\ntrait Foo {\n fn bar(&self);\n}\n\n// we now declare a function which takes an object implementing the Foo trait\nfn some_func(foo: T) {\n foo.bar();\n}\n\nfn main() {\n // we now call the method with the i32 type, which doesn't implement\n // the Foo trait\n some_func(5i32); // error: the trait bound `i32 : Foo` is not satisfied\n}\n```\n\nIn order to fix this error, verify that the type you're using does implement\nthe trait. Example:\n\n```\ntrait Foo {\n fn bar(&self);\n}\n\n// we implement the trait on the i32 type\nimpl Foo for i32 {\n fn bar(&self) {}\n}\n\nfn some_func(foo: T) {\n foo.bar(); // we can now use this method since i32 implements the\n // Foo trait\n}\n\nfn main() {\n some_func(5i32); // ok!\n}\n```\n\nOr in a generic context, an erroneous code example would look like:\n\n```compile_fail,E0277\nfn some_func(foo: T) {\n println!(\"{:?}\", foo); // error: the trait `core::fmt::Debug` is not\n // implemented for the type `T`\n}\n\nfn main() {\n // We now call the method with the i32 type,\n // which *does* implement the Debug trait.\n some_func(5i32);\n}\n```\n\nNote that the error here is in the definition of the generic function. Although\nwe only call it with a parameter that does implement `Debug`, the compiler\nstill rejects the function. It must work with all possible input types. In\norder to make this example compile, we need to restrict the generic type we're\naccepting:\n\n```\nuse std::fmt;\n\n// Restrict the input type to types that implement Debug.\nfn some_func(foo: T) {\n println!(\"{:?}\", foo);\n}\n\nfn main() {\n // Calling the method is still fine, as i32 implements Debug.\n some_func(5i32);\n\n // This would fail to compile now:\n // struct WithoutDebug;\n // some_func(WithoutDebug);\n}\n```\n\nRust only looks at the signature of the called function, as such it must\nalready specify all requirements that will be used for every type parameter.\n"},"level":"error","message":"can't compare `{integer}` with `{float}`","spans":[{"byte_end":1242,"byte_start":1240,"column_end":34,"column_start":32,"expansion":{"def_site_span":{"byte_end":1092,"byte_start":1070,"column_end":23,"column_start":1,"expansion":null,"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":false,"label":null,"line_end":36,"line_start":36,"suggested_replacement":null,"suggestion_applicability":null,"text":[]},"macro_decl_name":"assert_eq!","span":{"byte_end":95,"byte_start":77,"column_end":80,"column_start":62,"expansion":{"def_site_span":{"byte_end":50,"byte_start":16,"column_end":35,"column_start":1,"expansion":null,"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":1,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]},"macro_decl_name":"our_assert_eq_wrapper!","span":{"byte_end":243,"byte_start":213,"column_end":35,"column_start":5,"expansion":null,"file_name":"tests/test_nested.rs","is_primary":false,"label":null,"line_end":7,"line_start":7,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":5,"text":" our_assert_eq_wrapper!(4, 2.5);"}]}},"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":80,"highlight_start":62,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]}},"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":true,"label":"no implementation for `{integer} == {float}`","line_end":40,"line_start":40,"suggested_replacement":null,"suggestion_applicability":null,"text":[]}]}} +{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"error[E0308]: mismatched types\n --> tests/test_nested.rs:7:5\n |\n7 | our_assert_eq_wrapper!(4, 2.5);\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected integer, found floating-point number\n |\n = note: this error originates in the macro `assert_eq` which comes from the expansion of the macro `our_assert_eq_wrapper` (in Nightly builds, run with -Z macro-backtrace for more info)\n\n","$message_type":"diagnostic","children":[],"code":{"code":"E0308","explanation":"Expected type did not match the received type.\n\nErroneous code examples:\n\n```compile_fail,E0308\nfn plus_one(x: i32) -> i32 {\n x + 1\n}\n\nplus_one(\"Not a number\");\n// ^^^^^^^^^^^^^^ expected `i32`, found `&str`\n\nif \"Not a bool\" {\n// ^^^^^^^^^^^^ expected `bool`, found `&str`\n}\n\nlet x: f32 = \"Not a float\";\n// --- ^^^^^^^^^^^^^ expected `f32`, found `&str`\n// |\n// expected due to this\n```\n\nThis error occurs when an expression was used in a place where the compiler\nexpected an expression of a different type. It can occur in several cases, the\nmost common being when calling a function and passing an argument which has a\ndifferent type than the matching type in the function declaration.\n"},"level":"error","message":"mismatched types","spans":[{"byte_end":1253,"byte_start":1243,"column_end":45,"column_start":35,"expansion":{"def_site_span":{"byte_end":1092,"byte_start":1070,"column_end":23,"column_start":1,"expansion":null,"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":false,"label":null,"line_end":36,"line_start":36,"suggested_replacement":null,"suggestion_applicability":null,"text":[]},"macro_decl_name":"assert_eq!","span":{"byte_end":95,"byte_start":77,"column_end":80,"column_start":62,"expansion":{"def_site_span":{"byte_end":50,"byte_start":16,"column_end":35,"column_start":1,"expansion":null,"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":1,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]},"macro_decl_name":"our_assert_eq_wrapper!","span":{"byte_end":243,"byte_start":213,"column_end":35,"column_start":5,"expansion":null,"file_name":"tests/test_nested.rs","is_primary":false,"label":null,"line_end":7,"line_start":7,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":35,"highlight_start":5,"text":" our_assert_eq_wrapper!(4, 2.5);"}]}},"file_name":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs","is_primary":false,"label":null,"line_end":2,"line_start":2,"suggested_replacement":null,"suggestion_applicability":null,"text":[{"highlight_end":80,"highlight_start":62,"text":"macro_rules! our_assert_eq_wrapper { ($l:expr, $r:expr) => { assert_eq!($l, $r) } }"}]}},"file_name":"/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs","is_primary":true,"label":"expected integer, found floating-point number","line_end":40,"line_start":40,"suggested_replacement":null,"suggestion_applicability":null,"text":[]}]}} +{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"error: aborting due to 2 previous errors\n\n","$message_type":"diagnostic","children":[],"code":null,"level":"error","message":"aborting due to 2 previous errors","spans":[]}} +{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"Some errors have detailed explanations: E0277, E0308.\n","$message_type":"diagnostic","children":[],"code":null,"level":"failure-note","message":"Some errors have detailed explanations: E0277, E0308.","spans":[]}} +{"reason":"compiler-message","package_id":"path+file:///mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust#0.0.0","manifest_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/Cargo.toml","target":{"kind":["test"],"crate_types":["bin"],"name":"spec","src_path":"/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/tests/spec.rs","edition":"2018","doc":false,"doctest":false,"test":true},"message":{"rendered":"For more information about an error, try `rustc --explain E0277`.\n","$message_type":"diagnostic","children":[],"code":null,"level":"failure-note","message":"For more information about an error, try `rustc --explain E0277`.","spans":[]}} +{"reason":"build-finished","success":false} diff --git a/builder/spec/rust/rust_builder_spec.rb b/builder/spec/rust/rust_builder_spec.rb new file mode 100644 index 000000000..8cdd90c9b --- /dev/null +++ b/builder/spec/rust/rust_builder_spec.rb @@ -0,0 +1,77 @@ +require_relative '../../rust_builder' + +# From https://stackoverflow.com/a/64278755 +RSpec.configure do |rspec| + rspec.expect_with :rspec do |c| + c.max_formatted_output_length = nil + end +end + +RSpec.describe RustBuilder do + before :context do + @spec_dir = File.dirname(__FILE__) + end + + # This case tests that RustBuilder can correctly identify the bad test file if + # it triggers a compile error via macro expansion. For example, the use of + # `assert_eq!` with incompatible types in a test spec will be expanded to a + # `==` operation in the `library/core/src/macros/mod.rs` file, which `rustc` + # will report as the primary error location in the JSON output of the build. + # However, we want the file name of the test spec that called the `assert_eq!` + # macro so we can exclude it from future builds. Therefore, RustBuilder must + # descend deeper into the JSON to get the location of the outermost macro + # invocation, which should be in the offending test spec. + # + # To demonstrate the recursive nature of the problem, + # `spec/rust/tests/test_nested.rs` doesn't use `assert_eq!` directly but via + # another `our_assert_eq_wrapper!` macro (this is obviously contrived, but we + # can't rule out that such scenario could happen in practice, so RustBuilder + # should support it). This means that we apply the descend step + # `span["expansion"]["span"]` twice to get the test spec name, since the JSON + # output looks like this (simplified): + # + # ```json + # "message": { + # "$message_type": "diagnostic", + # "level": "error", + # "message": "can't compare `{integer}` with `{float}`", + # "spans": [ + # { + # "expansion": { + # "macro_decl_name": "assert_eq!", + # "span": { + # "expansion": { + # "macro_decl_name": "our_assert_eq_wrapper!", + # "span": { + # "expansion": null, + # "file_name": "tests/test_nested.rs", + # "is_primary": false + # } + # }, + # "file_name": "/mnt/c/temp/kaitai_struct/tests/builder/spec/rust/macro_expansion/spec/rust/src/helpers.rs", + # "is_primary": false + # } + # }, + # "file_name": "/rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/macros/mod.rs", + # "is_primary": true + # } + # ] + # } + # ``` + context 'macro_expansion' do + before :context do + Dir.chdir("#{@spec_dir}/macro_expansion") + @builder = RustBuilder.new + end + + describe '#parse_failed_build' do + it 'parses failed build information' do + test_nested_path = File.absolute_path('spec/rust/tests/test_nested.rs') + expect(@builder.parse_failed_build('test_out/rust/build-1.log')).to eq [ + test_nested_path, + test_nested_path, + ] + end + end + end +end From dcf7f0cecc2b319610d81664490a3a9d1be0d09a Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Wed, 8 May 2024 15:48:44 +0200 Subject: [PATCH 179/198] rust_builder: fix error location detection w.r.t. macro expansion This change fixes the test added in the previous commit: ```console $ rspec builder/spec/rust/rust_builder_spec.rb #### RustBuilder: initialized . Finished in 0.023 seconds (files took 0.49077 seconds to load) 1 example, 0 failures ``` --- builder/rust_builder.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb index 48ad2b80e..641c71f2b 100644 --- a/builder/rust_builder.rb +++ b/builder/rust_builder.rb @@ -80,8 +80,7 @@ def parse_failed_build(log_file) next unless rustc_msg['level'] == 'error' files = - rustc_msg['spans'] - .select { |span| span['is_primary'] } + select_rustc_msg_culprit_spans(rustc_msg['spans']) .map { |span| File.absolute_path(span['file_name'], @base_spec_dir) } list.concat(files) @@ -114,6 +113,17 @@ def run_tests private + def select_rustc_msg_culprit_spans(spans) + primary_spans = + spans + .select { |span| span['is_primary'] } + .map do |span| + span = span['expansion']['span'] until span['expansion'].nil? + span + end + primary_spans.uniq { |span| span['file_name'] } + end + def file_to_kind(path) if path_directly_in_dir?(path, @spec_dir) :spec @@ -158,9 +168,7 @@ def summarize_cargo_json_line(line) if rustc_msg['$message_type'] == 'diagnostic' files = - rustc_msg['spans'] - .select { |span| span['is_primary'] } - .uniq { |span| span['file_name'] } + select_rustc_msg_culprit_spans(rustc_msg['spans']) .map { |span| "#{span['file_name']}:#{span['line_start']}:#{span['column_start']}" } code_appendix = rustc_msg['code'].nil? ? '' : "[#{rustc_msg['code']['code']}]" files_prefix = From d3aecb85da82567b12ae4fc1732bdee6b0dc5f4e Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Thu, 9 May 2024 00:10:30 +0200 Subject: [PATCH 180/198] RustSG: simplify by adding support for `?` to handle errors See https://doc.rust-lang.org/rust-by-example/testing/unit_testing.html#tests-and- --- .../specgenerators/RustSG.scala | 53 ++++++------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 1484bdc33..658b05a6c 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -14,7 +14,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) val compiler = new RustCompiler(provider, RuntimeConfig()) - var do_panic = true var do_not_deref = false override def fileName(name: String): String = s"tests/test_$name.rs" @@ -30,47 +29,33 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs spec.extraImports.foreach{ name => importList.add(s"use rust::formats::$name::*;") } - val code = - s"""|#[test] - |fn test_${spec.id}() { - | let bytes = fs::read("../../src/${spec.data}").unwrap(); - | let _io = BytesReader::from(bytes); - | let res: KResult> = $className::read_into(&_io, None, None); - | let r : OptRc<$className>; - | - | if let Err(err) = res {""".stripMargin - out.puts(code) + out.puts("#[test]") + out.puts(s"fn test_${spec.id}() -> KResult<()> {") out.inc + out.puts(s"""let bytes = fs::read("../../src/${spec.data}").unwrap();""") + out.puts("let _io = BytesReader::from(bytes);") } override def runParse(): Unit = { - finish_panic() + out.puts(s"let r: OptRc<$className> = $className::read_into(&_io, None, None)?;") } override def runParseExpectError(exception: KSError): Unit = { - val code = - s""" println!("expected err: {:?}, exception: $exception", err); - | } else { - | panic!("no expected exception: $exception"); - | }""".stripMargin - out.puts(code) - do_panic = false + out.puts(s"let res: KResult> = $className::read_into(&_io, None, None);") + out.puts + out.puts(s"if let Err(err) = res {") + out.inc + out.puts(s"""println!("expected err: {:?}, exception: $exception", err);""") + out.dec + out.puts("} else {") + out.inc + out.puts(s"""panic!("no expected exception: $exception");""") + out.dec + out.puts("}") } - def finish_panic(): Unit = { - if (do_panic) { - out.inc - out.puts("panic!(\"{:?}\", err);") - out.dec - out.puts("} else {") - out.inc - out.puts("r = res.unwrap();") - out.dec - out.puts("}") - do_panic = false - } - } override def footer(): Unit = { + out.puts("Ok(())") out.dec out.puts("}") } @@ -83,7 +68,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } s = s.replace("_io", "&_io") - s = s.replace(")?", ").expect(\"error reading\")") s } @@ -106,7 +90,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs if (actStr.charAt(0) == '*' && expStr.startsWith("&vec![")) { expStr = remove_ref(expStr) } - finish_panic() //TODO: correct code generation actStr = correctIO(actStr) out.puts(s"assert_eq!($actStr, $expStr);") @@ -114,7 +97,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def nullAssert(actual: Ast.expr): Unit = { val actStr = correctIO(translateAct(actual)) - finish_panic() out.puts(s"assert_eq!($actStr, 0);") // TODO: Figure out what's meant to happen here } @@ -125,7 +107,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def testException(actual: Ast.expr, exception: KSError): Unit = { val s = translator.remove_deref(correctIO(translateAct(actual).replace(")?", ").unwrap_err()"))) - finish_panic() out.puts(s"assert_eq!($s, ${compiler.ksErrorName(exception)});") } From 8bdfd0c0547b28f97d730ac6b567664ca3fa6a3e Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sat, 29 Jun 2024 14:42:18 +0200 Subject: [PATCH 181/198] RustSG: fix nullAssert() --- .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 658b05a6c..a1cb3b78b 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -96,9 +96,8 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } override def nullAssert(actual: Ast.expr): Unit = { - val actStr = correctIO(translateAct(actual)) - out.puts(s"assert_eq!($actStr, 0);") - // TODO: Figure out what's meant to happen here + val actStr = translator.remove_deref(correctIO(translateAct(actual))) + out.puts(s"assert!($actStr.is_none());") } override def trueArrayEquality(check: TestEquals, elType: DataType, elts: Seq[Ast.expr]): Unit = { From 496dd50a7a0ec62e310ed011df17450780c81461 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Thu, 9 May 2024 11:54:26 +0200 Subject: [PATCH 182/198] RustSG: fix whitespace in generated specs --- .../io/kaitai/struct/testtranslator/specgenerators/RustSG.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index a1cb3b78b..f5af56c9a 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -82,7 +82,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs case (at: EnumType, et: BooleanType) => expStr = remove_ref(expStr) case (at: EnumType, et: IntType) => - out.puts(s"let n : i64 = (&$actStr).into();") + out.puts(s"let n: i64 = (&$actStr).into();") actStr = s"n" case _ => } From b7550ee05fb256da17fea34eb34bd1c9822c6903 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 1 Jul 2024 13:41:52 +0200 Subject: [PATCH 183/198] RustSG: stop generating `allow` attrs, move them to `spec.rs` --- builder/rust_builder.rb | 3 +++ .../kaitai/struct/testtranslator/specgenerators/RustSG.scala | 5 +---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb index 641c71f2b..26b12731f 100644 --- a/builder/rust_builder.rb +++ b/builder/rust_builder.rb @@ -40,6 +40,9 @@ def create_project(mand_files, disp_files) end File.open(@spec_list_file, 'w') { |f| + f.puts '#![allow(unused_variables)]' + f.puts '#![allow(unused_assignments)]' + f.puts '#![allow(overflowing_literals)]' grouped_files[:spec].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" } } File.open(@formats_list_file, 'w') { |f| diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index f5af56c9a..fe4b6a1f3 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -19,15 +19,12 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs override def fileName(name: String): String = s"tests/test_$name.rs" override def header(): Unit = { - importList.add("#![allow(unused_variables)]") - importList.add("#![allow(unused_assignments)]") - importList.add("#![allow(overflowing_literals)]") importList.add("use std::fs;") importList.add("extern crate kaitai;") importList.add("use self::kaitai::*;") importList.add(s"use rust::formats::${spec.id}::*;") - spec.extraImports.foreach{ name => importList.add(s"use rust::formats::$name::*;") } + spec.extraImports.foreach(entry => importList.add(s"use rust::formats::$entry::*;")) out.puts("#[test]") out.puts(s"fn test_${spec.id}() -> KResult<()> {") From b0bd33ed5fabd859d3fd66eb04b527584df606bf Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 2 Jul 2024 14:03:57 +0200 Subject: [PATCH 184/198] RustSG: remove unused and flawed text replacements --- .../testtranslator/TestTranslator.scala | 6 +- .../specgenerators/RustSG.scala | 80 ++----------------- 2 files changed, 8 insertions(+), 78 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala index 07bd63dda..3a0cc1e84 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/TestTranslator.scala @@ -30,7 +30,7 @@ class TestTranslator(options: CLIOptions) { val provider = new ClassTypeProvider(classSpecs, initObj) langs.foreach(langName => { - val sg = getSG(langName, testSpec, provider, classSpecs) + val sg = getSG(langName, testSpec, provider) try { val outFile = s"$outDir/$langName/${sg.fileName(testName)}" Console.println(s"... generating $outFile") @@ -109,7 +109,7 @@ class TestTranslator(options: CLIOptions) { origSpecs } - def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs): BaseGenerator = lang match { + def getSG(lang: String, testSpec: TestSpec, provider: ClassTypeProvider): BaseGenerator = lang match { case "construct" => new ConstructSG(testSpec, provider) case "cpp_stl_98" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp98()) case "cpp_stl_11" => new CppStlSG(testSpec, provider, CppRuntimeConfig().copyAsCpp11()) @@ -124,6 +124,6 @@ class TestTranslator(options: CLIOptions) { case "php" => new PHPSG(testSpec, provider) case "python" => new PythonSG(testSpec, provider) case "ruby" => new RubySG(testSpec, provider) - case "rust" => new RustSG(testSpec, provider, classSpecs) + case "rust" => new RustSG(testSpec, provider) } } diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index fe4b6a1f3..532ace2c4 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -7,14 +7,12 @@ import _root_.io.kaitai.struct.languages.RustCompiler import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestEquals, TestSpec} import _root_.io.kaitai.struct.translators.RustTranslator import _root_.io.kaitai.struct.datatype.DataType.{ArrayType, BooleanType, BytesType, EnumType, IntType, SwitchType, UserType} -import _root_.io.kaitai.struct.format.ClassSpecs import io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} -class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs) extends BaseGenerator(spec) { +class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(spec) { val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) val compiler = new RustCompiler(provider, RuntimeConfig()) - var do_not_deref = false override def fileName(name: String): String = s"tests/test_$name.rs" @@ -57,43 +55,22 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs out.puts("}") } - def correctIO(code: String): String = { - var s = if (!do_not_deref) { - if (code.contains("_io,") && (code.charAt(0) != '*')) s"*$code" else code - } else { - code - } - - s = s.replace("_io", "&_io") - s - } - override def simpleEquality(check: TestEquals): Unit = { val actType = translator.detectType(check.actual) var actStr = translateAct(check.actual) val expType = translator.detectType(check.expected) var expStr = translator.translate(check.expected) (actType, expType) match { - case (at: EnumType, et: EnumType) => - expStr = remove_ref(expStr) - case (at: EnumType, et: BooleanType) => - expStr = remove_ref(expStr) - case (at: EnumType, et: IntType) => + case (_: EnumType, _: IntType) => out.puts(s"let n: i64 = (&$actStr).into();") actStr = s"n" case _ => } - // fix expStr as vector - if (actStr.charAt(0) == '*' && expStr.startsWith("&vec![")) { - expStr = remove_ref(expStr) - } - //TODO: correct code generation - actStr = correctIO(actStr) out.puts(s"assert_eq!($actStr, $expStr);") } override def nullAssert(actual: Ast.expr): Unit = { - val actStr = translator.remove_deref(correctIO(translateAct(actual))) + val actStr = translator.remove_deref(translateAct(actual)) out.puts(s"assert!($actStr.is_none());") } @@ -102,7 +79,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs } override def testException(actual: Ast.expr, exception: KSError): Unit = { - val s = translator.remove_deref(correctIO(translateAct(actual).replace(")?", ").unwrap_err()"))) + val s = translator.remove_deref(translateAct(actual).replace(")?", ").unwrap_err()")) out.puts(s"assert_eq!($s, ${compiler.ksErrorName(exception)});") } @@ -114,53 +91,6 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider, classSpecs: ClassSpecs out.result } - def translate(x: Ast.expr): String = { - val ttx = translator.translate(x) - val dots = ttx.split("\\.") - var ttx2 = dots(0) - var last = "" - var last_full = "" - dots.drop(1).foreach { - attr_full => - last_full = attr_full - val ind = attr_full indexOf "(" - if (ind > 0) { - val attr = attr_full.substring(0, ind) - last = attr - } - ttx2 = s"$ttx2.$attr_full" - } - // do we need to deref? - if (last.nonEmpty) { - var deref = true - if (last == "len" || last_full.contains("[")) { - deref = false - do_not_deref = true - } else { - deref = translator.need_deref(last, classSpecs.firstSpec) - } - if (deref) { - if (ttx2.charAt(0) == '*') { - ttx2 - } else { - s"*$ttx2" - } - } else { - s"${translator.remove_deref(ttx2)}" - } - } else { - ttx - } - } - - def remove_ref(s: String): String = { - if (s.charAt(0) == '&') { - s.substring(1) - } else { - s - } - } - def translateAct(x: Ast.expr): String = - translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") + translator.translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") } From b338273cfa7db6309ab54fbd878bfe364b30ca31 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 30 Jun 2024 21:38:15 +0200 Subject: [PATCH 185/198] Rust: remove incorrect "Autogenerated" comments --- spec/rust/tests/test_switch_manual_enum_invalid.rs | 2 -- spec/rust/tests/test_type_ternary_2nd_falsy.rs | 2 -- 2 files changed, 4 deletions(-) diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index d3724bb2b..257a5ffcf 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -1,5 +1,3 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - #![allow(unused_variables)] #![allow(unused_assignments)] #![allow(overflowing_literals)] diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index 48669a0da..4e741b889 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -1,5 +1,3 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - #![allow(unused_variables)] #![allow(unused_assignments)] #![allow(overflowing_literals)] From 16d44c9c1177abd72fcfb8ffd9d17e0b86801397 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Fri, 10 May 2024 22:05:00 +0200 Subject: [PATCH 186/198] Rust: regen positive tests from KST --- spec/rust/tests/test_bcd_user_type_be.rs | 27 +++------ spec/rust/tests/test_bcd_user_type_le.rs | 27 +++------ spec/rust/tests/test_bits_byte_aligned.rs | 15 +---- spec/rust/tests/test_bits_enum.rs | 15 +---- spec/rust/tests/test_bits_seq_endian_combo.rs | 15 +---- spec/rust/tests/test_bits_shift_by_b32_le.rs | 15 +---- spec/rust/tests/test_bits_shift_by_b64_le.rs | 15 +---- .../rust/tests/test_bits_signed_res_b32_be.rs | 15 +---- .../rust/tests/test_bits_signed_res_b32_le.rs | 15 +---- .../tests/test_bits_signed_shift_b32_le.rs | 15 +---- .../tests/test_bits_signed_shift_b64_le.rs | 15 +---- spec/rust/tests/test_bits_simple.rs | 17 ++---- spec/rust/tests/test_bits_simple_le.rs | 17 ++---- spec/rust/tests/test_bits_unaligned_b32_be.rs | 15 +---- spec/rust/tests/test_bits_unaligned_b32_le.rs | 15 +---- spec/rust/tests/test_bits_unaligned_b64_be.rs | 15 +---- spec/rust/tests/test_bits_unaligned_b64_le.rs | 15 +---- spec/rust/tests/test_buffered_struct.rs | 15 +---- spec/rust/tests/test_bytes_pad_term.rs | 15 +---- spec/rust/tests/test_cast_nested.rs | 23 +++---- spec/rust/tests/test_cast_to_top.rs | 19 ++---- spec/rust/tests/test_combine_bool.rs | 17 ++---- spec/rust/tests/test_combine_bytes.rs | 29 ++++----- spec/rust/tests/test_combine_enum.rs | 17 ++---- spec/rust/tests/test_combine_str.rs | 39 +++++------- spec/rust/tests/test_debug_switch_user.rs | 15 +---- spec/rust/tests/test_default_big_endian.rs | 15 +---- .../rust/tests/test_default_bit_endian_mod.rs | 15 +---- .../test_default_endian_expr_inherited.rs | 21 ++----- .../tests/test_default_endian_expr_is_be.rs | 27 +++------ .../tests/test_default_endian_expr_is_le.rs | 15 +---- spec/rust/tests/test_default_endian_mod.rs | 15 +---- spec/rust/tests/test_docstrings.rs | 15 +---- spec/rust/tests/test_docstrings_docref.rs | 15 +---- .../tests/test_docstrings_docref_multi.rs | 15 +---- spec/rust/tests/test_enum_0.rs | 15 +---- spec/rust/tests/test_enum_1.rs | 15 +---- spec/rust/tests/test_enum_deep.rs | 15 +---- spec/rust/tests/test_enum_deep_literals.rs | 19 ++---- spec/rust/tests/test_enum_fancy.rs | 15 +---- spec/rust/tests/test_enum_if.rs | 15 +---- spec/rust/tests/test_enum_int_range_s.rs | 15 +---- spec/rust/tests/test_enum_int_range_u.rs | 15 +---- spec/rust/tests/test_enum_invalid.rs | 17 ++---- spec/rust/tests/test_enum_long_range_s.rs | 15 +---- spec/rust/tests/test_enum_long_range_u.rs | 15 +---- spec/rust/tests/test_enum_negative.rs | 15 +---- spec/rust/tests/test_enum_of_value_inst.rs | 19 ++---- spec/rust/tests/test_enum_to_i.rs | 26 +++----- .../tests/test_enum_to_i_class_border_1.rs | 18 ++---- spec/rust/tests/test_enum_to_i_invalid.rs | 29 ++++----- spec/rust/tests/test_expr_0.rs | 19 ++---- spec/rust/tests/test_expr_1.rs | 19 ++---- spec/rust/tests/test_expr_2.rs | 45 ++++++-------- spec/rust/tests/test_expr_3.rs | 35 ++++------- spec/rust/tests/test_expr_array.rs | 45 ++++++-------- spec/rust/tests/test_expr_bits.rs | 19 ++---- spec/rust/tests/test_expr_bytes_cmp.rs | 31 ++++------ .../rust/tests/test_expr_bytes_non_literal.rs | 21 ++----- spec/rust/tests/test_expr_bytes_ops.rs | 47 ++++++--------- spec/rust/tests/test_expr_calc_array_ops.rs | 51 +++++++--------- spec/rust/tests/test_expr_enum.rs | 21 ++----- spec/rust/tests/test_expr_if_int_ops.rs | 19 ++---- spec/rust/tests/test_expr_int_div.rs | 25 +++----- spec/rust/tests/test_expr_io_eof.rs | 17 ++---- spec/rust/tests/test_expr_io_pos.rs | 15 +---- spec/rust/tests/test_expr_mod.rs | 23 +++---- spec/rust/tests/test_expr_ops_parens.rs | 33 ++++------ spec/rust/tests/test_expr_sizeof_type_0.rs | 17 ++---- spec/rust/tests/test_expr_sizeof_type_1.rs | 19 ++---- spec/rust/tests/test_expr_sizeof_value_0.rs | 25 +++----- .../tests/test_expr_sizeof_value_sized.rs | 25 +++----- spec/rust/tests/test_expr_str_encodings.rs | 29 ++++----- spec/rust/tests/test_expr_str_ops.rs | 48 +++++++-------- spec/rust/tests/test_expr_to_i_trailing.rs | 17 ++---- spec/rust/tests/test_fixed_contents.rs | 15 +---- spec/rust/tests/test_fixed_struct.rs | 55 +++++++---------- spec/rust/tests/test_float_to_i.rs | 27 +++------ spec/rust/tests/test_floating_points.rs | 21 ++----- spec/rust/tests/test_hello_world.rs | 15 +---- spec/rust/tests/test_if_instances.rs | 17 ++---- spec/rust/tests/test_if_struct.rs | 15 +---- spec/rust/tests/test_if_values.rs | 21 ++----- spec/rust/tests/test_imports0.rs | 18 ++---- spec/rust/tests/test_imports_abs.rs | 18 ++---- spec/rust/tests/test_imports_abs_abs.rs | 15 ++--- spec/rust/tests/test_imports_abs_rel.rs | 15 ++--- spec/rust/tests/test_imports_circular_a.rs | 20 ++----- spec/rust/tests/test_imports_rel_1.rs | 17 +----- spec/rust/tests/test_index_sizes.rs | 15 +---- spec/rust/tests/test_index_to_param_eos.rs | 15 +---- spec/rust/tests/test_index_to_param_expr.rs | 15 +---- spec/rust/tests/test_index_to_param_until.rs | 15 +---- spec/rust/tests/test_instance_io_user.rs | 21 ++----- spec/rust/tests/test_instance_std.rs | 17 ++---- spec/rust/tests/test_instance_std_array.rs | 23 +++---- spec/rust/tests/test_instance_user_array.rs | 29 ++++----- spec/rust/tests/test_integers.rs | 15 +---- .../tests/test_integers_double_overflow.rs | 15 +---- spec/rust/tests/test_integers_min_max.rs | 15 +---- spec/rust/tests/test_io_local_var.rs | 15 +---- spec/rust/tests/test_js_signed_right_shift.rs | 19 ++---- spec/rust/tests/test_meta_tags.rs | 15 +---- spec/rust/tests/test_meta_xref.rs | 15 +---- spec/rust/tests/test_multiple_use.rs | 17 ++---- spec/rust/tests/test_nav_parent.rs | 15 +---- spec/rust/tests/test_nav_parent2.rs | 19 ++---- spec/rust/tests/test_nav_parent3.rs | 31 ++++------ spec/rust/tests/test_nav_parent_false.rs | 15 +---- spec/rust/tests/test_nav_parent_false2.rs | 15 +---- spec/rust/tests/test_nav_parent_override.rs | 15 +---- spec/rust/tests/test_nav_parent_switch.rs | 15 +---- .../tests/test_nav_parent_vs_value_inst.rs | 15 +---- spec/rust/tests/test_nav_root.rs | 15 +---- spec/rust/tests/test_nested_same_name.rs | 15 +---- spec/rust/tests/test_nested_same_name2.rs | 15 +---- spec/rust/tests/test_nested_type_param.rs | 15 +---- spec/rust/tests/test_nested_types.rs | 15 +---- spec/rust/tests/test_nested_types2.rs | 15 +---- spec/rust/tests/test_nested_types3.rs | 15 +---- spec/rust/tests/test_non_standard.rs | 15 +---- .../tests/test_params_call_extra_parens.rs | 15 +---- spec/rust/tests/test_params_enum.rs | 17 ++---- spec/rust/tests/test_params_pass_array_int.rs | 15 +---- spec/rust/tests/test_params_pass_array_str.rs | 15 +---- .../tests/test_params_pass_array_usertype.rs | 15 +---- spec/rust/tests/test_params_pass_bool.rs | 15 +---- spec/rust/tests/test_params_pass_usertype.rs | 15 +---- spec/rust/tests/test_position_abs.rs | 17 ++---- spec/rust/tests/test_position_in_seq.rs | 15 +---- spec/rust/tests/test_position_to_end.rs | 19 ++---- spec/rust/tests/test_process_coerce_bytes.rs | 19 ++---- .../tests/test_process_coerce_usertype1.rs | 19 ++---- .../tests/test_process_coerce_usertype2.rs | 19 ++---- spec/rust/tests/test_process_custom.rs | 15 +---- .../rust/tests/test_process_custom_no_args.rs | 15 +---- spec/rust/tests/test_process_repeat_bytes.rs | 15 +---- .../tests/test_process_repeat_usertype.rs | 15 +---- spec/rust/tests/test_process_rotate.rs | 15 +---- spec/rust/tests/test_process_to_user.rs | 15 +---- spec/rust/tests/test_process_xor4_const.rs | 15 +---- spec/rust/tests/test_process_xor4_value.rs | 15 +---- spec/rust/tests/test_process_xor_const.rs | 15 +---- spec/rust/tests/test_process_xor_value.rs | 15 +---- spec/rust/tests/test_recursive_one.rs | 15 +---- spec/rust/tests/test_repeat_eos_bit.rs | 15 +---- spec/rust/tests/test_repeat_eos_struct.rs | 17 ++---- spec/rust/tests/test_repeat_eos_u4.rs | 15 +---- spec/rust/tests/test_repeat_n_struct.rs | 15 +---- spec/rust/tests/test_repeat_n_strz.rs | 15 +---- spec/rust/tests/test_repeat_n_strz_double.rs | 15 +---- .../test_repeat_until_calc_array_type.rs | 15 +---- spec/rust/tests/test_repeat_until_complex.rs | 15 +---- spec/rust/tests/test_repeat_until_s4.rs | 15 +---- spec/rust/tests/test_repeat_until_sized.rs | 15 +---- spec/rust/tests/test_str_encodings.rs | 15 +---- spec/rust/tests/test_str_encodings_default.rs | 15 +---- spec/rust/tests/test_str_encodings_utf16.rs | 15 +---- spec/rust/tests/test_str_eos.rs | 15 +---- spec/rust/tests/test_str_literals2.rs | 23 +++---- spec/rust/tests/test_str_pad_term.rs | 15 +---- spec/rust/tests/test_str_pad_term_empty.rs | 15 +---- spec/rust/tests/test_switch_bytearray.rs | 15 +---- spec/rust/tests/test_switch_else_only.rs | 15 +---- spec/rust/tests/test_switch_integers.rs | 15 +---- spec/rust/tests/test_switch_integers2.rs | 17 ++---- spec/rust/tests/test_switch_manual_enum.rs | 15 +---- .../test_switch_manual_enum_invalid_else.rs | 36 +++-------- spec/rust/tests/test_switch_manual_int.rs | 15 +---- .../rust/tests/test_switch_manual_int_else.rs | 15 +---- .../rust/tests/test_switch_manual_int_size.rs | 15 +---- .../tests/test_switch_manual_int_size_else.rs | 15 +---- .../tests/test_switch_manual_int_size_eos.rs | 60 ++++--------------- spec/rust/tests/test_switch_manual_str.rs | 15 +---- .../rust/tests/test_switch_manual_str_else.rs | 15 +---- spec/rust/tests/test_switch_multi_bool_ops.rs | 15 +---- spec/rust/tests/test_switch_repeat_expr.rs | 15 +---- .../tests/test_switch_repeat_expr_invalid.rs | 15 +---- spec/rust/tests/test_term_bytes.rs | 15 +---- spec/rust/tests/test_term_strz.rs | 15 +---- spec/rust/tests/test_term_u1_val.rs | 15 +---- spec/rust/tests/test_ts_packet_header.rs | 15 +---- spec/rust/tests/test_type_int_unary_op.rs | 19 ++---- spec/rust/tests/test_type_ternary.rs | 17 ++---- .../rust/tests/test_type_ternary_2nd_falsy.rs | 39 +++++------- spec/rust/tests/test_user_type.rs | 15 +---- .../rust/tests/test_valid_eq_str_encodings.rs | 15 +---- spec/rust/tests/test_valid_long.rs | 15 +---- spec/rust/tests/test_valid_not_parsed_if.rs | 15 +---- spec/rust/tests/test_valid_optional_id.rs | 15 +---- spec/rust/tests/test_valid_short.rs | 15 +---- spec/rust/tests/test_valid_switch.rs | 15 +---- spec/rust/tests/test_yaml_ints.rs | 23 +++---- spec/rust/tests/test_zlib_surrounded.rs | 15 +---- spec/rust/tests/test_zlib_with_header_78.rs | 15 +---- 195 files changed, 926 insertions(+), 2713 deletions(-) diff --git a/spec/rust/tests/test_bcd_user_type_be.rs b/spec/rust/tests/test_bcd_user_type_be.rs index d114b5669..56580f5d6 100644 --- a/spec/rust/tests/test_bcd_user_type_be.rs +++ b/spec/rust/tests/test_bcd_user_type_be.rs @@ -1,30 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bcd_user_type_be::*; #[test] -fn test_bcd_user_type_be() { +fn test_bcd_user_type_be() -> KResult<()> { let bytes = fs::read("../../src/bcd_user_type_be.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BcdUserTypeBe::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = BcdUserTypeBe::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.ltr().as_int().expect("error reading"), 12345678); - assert_eq!(*r.ltr().as_str().expect("error reading"), "12345678"); - assert_eq!(*r.rtl().as_int().expect("error reading"), 87654321); - assert_eq!(*r.rtl().as_str().expect("error reading"), "87654321"); - assert_eq!(*r.leading_zero_ltr().as_int().expect("error reading"), 123456); - assert_eq!(*r.leading_zero_ltr().as_str().expect("error reading"), "00123456"); + assert_eq!(*r.ltr().as_int()?, 12345678); + assert_eq!(*r.ltr().as_str()?, "12345678"); + assert_eq!(*r.rtl().as_int()?, 87654321); + assert_eq!(*r.rtl().as_str()?, "87654321"); + assert_eq!(*r.leading_zero_ltr().as_int()?, 123456); + assert_eq!(*r.leading_zero_ltr().as_str()?, "00123456"); + Ok(()) } diff --git a/spec/rust/tests/test_bcd_user_type_le.rs b/spec/rust/tests/test_bcd_user_type_le.rs index badd13343..e368eb7ea 100644 --- a/spec/rust/tests/test_bcd_user_type_le.rs +++ b/spec/rust/tests/test_bcd_user_type_le.rs @@ -1,30 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bcd_user_type_le::*; #[test] -fn test_bcd_user_type_le() { +fn test_bcd_user_type_le() -> KResult<()> { let bytes = fs::read("../../src/bcd_user_type_le.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BcdUserTypeLe::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = BcdUserTypeLe::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.ltr().as_int().expect("error reading"), 12345678); - assert_eq!(*r.ltr().as_str().expect("error reading"), "12345678"); - assert_eq!(*r.rtl().as_int().expect("error reading"), 87654321); - assert_eq!(*r.rtl().as_str().expect("error reading"), "87654321"); - assert_eq!(*r.leading_zero_ltr().as_int().expect("error reading"), 123456); - assert_eq!(*r.leading_zero_ltr().as_str().expect("error reading"), "00123456"); + assert_eq!(*r.ltr().as_int()?, 12345678); + assert_eq!(*r.ltr().as_str()?, "12345678"); + assert_eq!(*r.rtl().as_int()?, 87654321); + assert_eq!(*r.rtl().as_str()?, "87654321"); + assert_eq!(*r.leading_zero_ltr().as_int()?, 123456); + assert_eq!(*r.leading_zero_ltr().as_str()?, "00123456"); + Ok(()) } diff --git a/spec/rust/tests/test_bits_byte_aligned.rs b/spec/rust/tests/test_bits_byte_aligned.rs index 2653cfbb0..b2d0fa08a 100644 --- a/spec/rust/tests/test_bits_byte_aligned.rs +++ b/spec/rust/tests/test_bits_byte_aligned.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_byte_aligned::*; #[test] -fn test_bits_byte_aligned() { +fn test_bits_byte_aligned() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsByteAligned::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsByteAligned::read_into(&_io, None, None)?; assert_eq!(*r.one(), 20); assert_eq!(*r.byte_1(), 65); @@ -30,4 +20,5 @@ fn test_bits_byte_aligned() { assert_eq!(*r.byte_3(), vec![0xffu8]); assert_eq!(*r.full_byte(), 255); assert_eq!(*r.byte_4(), 80); + Ok(()) } diff --git a/spec/rust/tests/test_bits_enum.rs b/spec/rust/tests/test_bits_enum.rs index 531d0a1c8..5e0980071 100644 --- a/spec/rust/tests/test_bits_enum.rs +++ b/spec/rust/tests/test_bits_enum.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_enum::*; #[test] -fn test_bits_enum() { +fn test_bits_enum() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsEnum::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsEnum::read_into(&_io, None, None)?; assert_eq!(*r.one(), BitsEnum_Animal::Platypus); assert_eq!(*r.two(), BitsEnum_Animal::Horse); assert_eq!(*r.three(), BitsEnum_Animal::Cat); + Ok(()) } diff --git a/spec/rust/tests/test_bits_seq_endian_combo.rs b/spec/rust/tests/test_bits_seq_endian_combo.rs index 5e931f5c5..85c0aa469 100644 --- a/spec/rust/tests/test_bits_seq_endian_combo.rs +++ b/spec/rust/tests/test_bits_seq_endian_combo.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_seq_endian_combo::*; #[test] -fn test_bits_seq_endian_combo() { +fn test_bits_seq_endian_combo() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsSeqEndianCombo::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsSeqEndianCombo::read_into(&_io, None, None)?; assert_eq!(*r.be1(), 59); assert_eq!(*r.be2(), 187); @@ -29,4 +19,5 @@ fn test_bits_seq_endian_combo() { assert_eq!(*r.le6(), 36); assert_eq!(*r.le7(), 26); assert_eq!(*r.be8(), true); + Ok(()) } diff --git a/spec/rust/tests/test_bits_shift_by_b32_le.rs b/spec/rust/tests/test_bits_shift_by_b32_le.rs index 8e06f6461..6fe70947d 100644 --- a/spec/rust/tests/test_bits_shift_by_b32_le.rs +++ b/spec/rust/tests/test_bits_shift_by_b32_le.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_shift_by_b32_le::*; #[test] -fn test_bits_shift_by_b32_le() { +fn test_bits_shift_by_b32_le() -> KResult<()> { let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsShiftByB32Le::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsShiftByB32Le::read_into(&_io, None, None)?; assert_eq!(*r.a(), 4294967295); assert_eq!(*r.b(), 0); + Ok(()) } diff --git a/spec/rust/tests/test_bits_shift_by_b64_le.rs b/spec/rust/tests/test_bits_shift_by_b64_le.rs index 014a0cc08..3349e8b8e 100644 --- a/spec/rust/tests/test_bits_shift_by_b64_le.rs +++ b/spec/rust/tests/test_bits_shift_by_b64_le.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_shift_by_b64_le::*; #[test] -fn test_bits_shift_by_b64_le() { +fn test_bits_shift_by_b64_le() -> KResult<()> { let bytes = fs::read("../../src/bits_shift_by_b64_le.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsShiftByB64Le::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsShiftByB64Le::read_into(&_io, None, None)?; assert_eq!(*r.a(), 18446744073709551615); assert_eq!(*r.b(), 0); + Ok(()) } diff --git a/spec/rust/tests/test_bits_signed_res_b32_be.rs b/spec/rust/tests/test_bits_signed_res_b32_be.rs index 7843874c2..6d9416cce 100644 --- a/spec/rust/tests/test_bits_signed_res_b32_be.rs +++ b/spec/rust/tests/test_bits_signed_res_b32_be.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_signed_res_b32_be::*; #[test] -fn test_bits_signed_res_b32_be() { +fn test_bits_signed_res_b32_be() -> KResult<()> { let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsSignedResB32Be::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsSignedResB32Be::read_into(&_io, None, None)?; assert_eq!(*r.a(), 4294967295); + Ok(()) } diff --git a/spec/rust/tests/test_bits_signed_res_b32_le.rs b/spec/rust/tests/test_bits_signed_res_b32_le.rs index 8ac7bb3ba..1d277e33b 100644 --- a/spec/rust/tests/test_bits_signed_res_b32_le.rs +++ b/spec/rust/tests/test_bits_signed_res_b32_le.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_signed_res_b32_le::*; #[test] -fn test_bits_signed_res_b32_le() { +fn test_bits_signed_res_b32_le() -> KResult<()> { let bytes = fs::read("../../src/bits_shift_by_b32_le.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsSignedResB32Le::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsSignedResB32Le::read_into(&_io, None, None)?; assert_eq!(*r.a(), 4294967295); + Ok(()) } diff --git a/spec/rust/tests/test_bits_signed_shift_b32_le.rs b/spec/rust/tests/test_bits_signed_shift_b32_le.rs index 337cccec6..e925c956d 100644 --- a/spec/rust/tests/test_bits_signed_shift_b32_le.rs +++ b/spec/rust/tests/test_bits_signed_shift_b32_le.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_signed_shift_b32_le::*; #[test] -fn test_bits_signed_shift_b32_le() { +fn test_bits_signed_shift_b32_le() -> KResult<()> { let bytes = fs::read("../../src/bits_signed_shift_b32_le.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsSignedShiftB32Le::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsSignedShiftB32Le::read_into(&_io, None, None)?; assert_eq!(*r.a(), 0); assert_eq!(*r.b(), 255); + Ok(()) } diff --git a/spec/rust/tests/test_bits_signed_shift_b64_le.rs b/spec/rust/tests/test_bits_signed_shift_b64_le.rs index d216a6be6..ef3999e13 100644 --- a/spec/rust/tests/test_bits_signed_shift_b64_le.rs +++ b/spec/rust/tests/test_bits_signed_shift_b64_le.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_signed_shift_b64_le::*; #[test] -fn test_bits_signed_shift_b64_le() { +fn test_bits_signed_shift_b64_le() -> KResult<()> { let bytes = fs::read("../../src/bits_signed_shift_b64_le.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsSignedShiftB64Le::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsSignedShiftB64Le::read_into(&_io, None, None)?; assert_eq!(*r.a(), 0); assert_eq!(*r.b(), 255); + Ok(()) } diff --git a/spec/rust/tests/test_bits_simple.rs b/spec/rust/tests/test_bits_simple.rs index e7af2c3bd..6f529bfae 100644 --- a/spec/rust/tests/test_bits_simple.rs +++ b/spec/rust/tests/test_bits_simple.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_simple::*; #[test] -fn test_bits_simple() { +fn test_bits_simple() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsSimple::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsSimple::read_into(&_io, None, None)?; assert_eq!(*r.byte_1(), 80); assert_eq!(*r.byte_2(), 65); @@ -34,5 +24,6 @@ fn test_bits_simple() { assert_eq!(*r.byte_11_to_14(), 1261262125); assert_eq!(*r.byte_15_to_19(), 293220057087); assert_eq!(*r.byte_20_to_27(), 18446744073709551615); - assert_eq!(*r.test_if_b1().expect("error reading"), 123); + assert_eq!(*r.test_if_b1()?, 123); + Ok(()) } diff --git a/spec/rust/tests/test_bits_simple_le.rs b/spec/rust/tests/test_bits_simple_le.rs index 333075207..424c46aba 100644 --- a/spec/rust/tests/test_bits_simple_le.rs +++ b/spec/rust/tests/test_bits_simple_le.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_simple_le::*; #[test] -fn test_bits_simple_le() { +fn test_bits_simple_le() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsSimpleLe::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsSimpleLe::read_into(&_io, None, None)?; assert_eq!(*r.byte_1(), 80); assert_eq!(*r.byte_2(), 65); @@ -34,5 +24,6 @@ fn test_bits_simple_le() { assert_eq!(*r.byte_11_to_14(), 760556875); assert_eq!(*r.byte_15_to_19(), 1099499455812); assert_eq!(*r.byte_20_to_27(), 18446744073709551615); - assert_eq!(*r.test_if_b1().expect("error reading"), 123); + assert_eq!(*r.test_if_b1()?, 123); + Ok(()) } diff --git a/spec/rust/tests/test_bits_unaligned_b32_be.rs b/spec/rust/tests/test_bits_unaligned_b32_be.rs index 0fe8bd1a1..761e27ec5 100644 --- a/spec/rust/tests/test_bits_unaligned_b32_be.rs +++ b/spec/rust/tests/test_bits_unaligned_b32_be.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_unaligned_b32_be::*; #[test] -fn test_bits_unaligned_b32_be() { +fn test_bits_unaligned_b32_be() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsUnalignedB32Be::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsUnalignedB32Be::read_into(&_io, None, None)?; assert_eq!(*r.a(), true); assert_eq!(*r.b(), 3648472617); assert_eq!(*r.c(), 10); + Ok(()) } diff --git a/spec/rust/tests/test_bits_unaligned_b32_le.rs b/spec/rust/tests/test_bits_unaligned_b32_le.rs index 6fa6571f5..8e57c1cae 100644 --- a/spec/rust/tests/test_bits_unaligned_b32_le.rs +++ b/spec/rust/tests/test_bits_unaligned_b32_le.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_unaligned_b32_le::*; #[test] -fn test_bits_unaligned_b32_le() { +fn test_bits_unaligned_b32_le() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsUnalignedB32Le::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsUnalignedB32Le::read_into(&_io, None, None)?; assert_eq!(*r.a(), false); assert_eq!(*r.b(), 173137398); assert_eq!(*r.c(), 69); + Ok(()) } diff --git a/spec/rust/tests/test_bits_unaligned_b64_be.rs b/spec/rust/tests/test_bits_unaligned_b64_be.rs index 72570ceb4..3e1f97844 100644 --- a/spec/rust/tests/test_bits_unaligned_b64_be.rs +++ b/spec/rust/tests/test_bits_unaligned_b64_be.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_unaligned_b64_be::*; #[test] -fn test_bits_unaligned_b64_be() { +fn test_bits_unaligned_b64_be() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsUnalignedB64Be::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsUnalignedB64Be::read_into(&_io, None, None)?; assert_eq!(*r.a(), true); assert_eq!(*r.b(), 15670070570729969769); assert_eq!(*r.c(), 14); + Ok(()) } diff --git a/spec/rust/tests/test_bits_unaligned_b64_le.rs b/spec/rust/tests/test_bits_unaligned_b64_le.rs index 3552ab70d..2dac88bce 100644 --- a/spec/rust/tests/test_bits_unaligned_b64_le.rs +++ b/spec/rust/tests/test_bits_unaligned_b64_le.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bits_unaligned_b64_le::*; #[test] -fn test_bits_unaligned_b64_le() { +fn test_bits_unaligned_b64_le() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BitsUnalignedB64Le::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BitsUnalignedB64Le::read_into(&_io, None, None)?; assert_eq!(*r.a(), false); assert_eq!(*r.b(), 1902324737369038326); assert_eq!(*r.c(), 71); + Ok(()) } diff --git a/spec/rust/tests/test_buffered_struct.rs b/spec/rust/tests/test_buffered_struct.rs index f86817ee9..e298de3fc 100644 --- a/spec/rust/tests/test_buffered_struct.rs +++ b/spec/rust/tests/test_buffered_struct.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::buffered_struct::*; #[test] -fn test_buffered_struct() { +fn test_buffered_struct() -> KResult<()> { let bytes = fs::read("../../src/buffered_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BufferedStruct::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BufferedStruct::read_into(&_io, None, None)?; assert_eq!(*r.len1(), 16); assert_eq!(*r.block1().number1(), 66); @@ -28,4 +18,5 @@ fn test_buffered_struct() { assert_eq!(*r.block2().number1(), 68); assert_eq!(*r.block2().number2(), 69); assert_eq!(*r.finisher(), 238); + Ok(()) } diff --git a/spec/rust/tests/test_bytes_pad_term.rs b/spec/rust/tests/test_bytes_pad_term.rs index 0bb96dffc..c05f43821 100644 --- a/spec/rust/tests/test_bytes_pad_term.rs +++ b/spec/rust/tests/test_bytes_pad_term.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::bytes_pad_term::*; #[test] -fn test_bytes_pad_term() { +fn test_bytes_pad_term() -> KResult<()> { let bytes = fs::read("../../src/str_pad_term.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = BytesPadTerm::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = BytesPadTerm::read_into(&_io, None, None)?; assert_eq!(*r.str_pad(), vec![0x73u8, 0x74u8, 0x72u8, 0x31u8]); assert_eq!(*r.str_term(), vec![0x73u8, 0x74u8, 0x72u8, 0x32u8, 0x66u8, 0x6fu8, 0x6fu8]); assert_eq!(*r.str_term_and_pad(), vec![0x73u8, 0x74u8, 0x72u8, 0x2bu8, 0x2bu8, 0x2bu8, 0x33u8, 0x62u8, 0x61u8, 0x72u8, 0x2bu8, 0x2bu8, 0x2bu8]); assert_eq!(*r.str_term_include(), vec![0x73u8, 0x74u8, 0x72u8, 0x34u8, 0x62u8, 0x61u8, 0x7au8, 0x40u8]); + Ok(()) } diff --git a/spec/rust/tests/test_cast_nested.rs b/spec/rust/tests/test_cast_nested.rs index 64c5fad32..6bcd94a62 100644 --- a/spec/rust/tests/test_cast_nested.rs +++ b/spec/rust/tests/test_cast_nested.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::cast_nested::*; #[test] -fn test_cast_nested() { +fn test_cast_nested() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = CastNested::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = CastNested::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.opcodes_0_str().expect("error reading").value(), "foobar"); - assert_eq!(*r.opcodes_0_str_value().expect("error reading"), "foobar"); - assert_eq!(*r.opcodes_1_int().expect("error reading").value(), 66); - assert_eq!(*r.opcodes_1_int_value().expect("error reading"), 66); + assert_eq!(*r.opcodes_0_str()?.value(), "foobar"); + assert_eq!(*r.opcodes_0_str_value()?, "foobar"); + assert_eq!(*r.opcodes_1_int()?.value(), 66); + assert_eq!(*r.opcodes_1_int_value()?, 66); + Ok(()) } diff --git a/spec/rust/tests/test_cast_to_top.rs b/spec/rust/tests/test_cast_to_top.rs index 6efa0635f..bee130a0d 100644 --- a/spec/rust/tests/test_cast_to_top.rs +++ b/spec/rust/tests/test_cast_to_top.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::cast_to_top::*; #[test] -fn test_cast_to_top() { +fn test_cast_to_top() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = CastToTop::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = CastToTop::read_into(&_io, None, None)?; assert_eq!(*r.code(), 80); - assert_eq!(*r.header().expect("error reading").code(), 65); - assert_eq!(*r.header_casted().expect("error reading").code(), 65); + assert_eq!(*r.header()?.code(), 65); + assert_eq!(*r.header_casted()?.code(), 65); + Ok(()) } diff --git a/spec/rust/tests/test_combine_bool.rs b/spec/rust/tests/test_combine_bool.rs index 308c2da95..8aed9f1f0 100644 --- a/spec/rust/tests/test_combine_bool.rs +++ b/spec/rust/tests/test_combine_bool.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::combine_bool::*; #[test] -fn test_combine_bool() { +fn test_combine_bool() -> KResult<()> { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = CombineBool::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = CombineBool::read_into(&_io, None, None)?; assert_eq!(*r.bool_bit(), true); - assert_eq!(*r.bool_calc_bit().expect("error reading"), false); + assert_eq!(*r.bool_calc_bit()?, false); + Ok(()) } diff --git a/spec/rust/tests/test_combine_bytes.rs b/spec/rust/tests/test_combine_bytes.rs index 69b7aa78a..9d4dad51b 100644 --- a/spec/rust/tests/test_combine_bytes.rs +++ b/spec/rust/tests/test_combine_bytes.rs @@ -1,34 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::combine_bytes::*; #[test] -fn test_combine_bytes() { +fn test_combine_bytes() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = CombineBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = CombineBytes::read_into(&_io, None, None)?; assert_eq!(*r.bytes_term(), vec![0x66u8, 0x6fu8, 0x6fu8]); assert_eq!(*r.bytes_limit(), vec![0x62u8, 0x61u8, 0x72u8, 0x7cu8]); assert_eq!(*r.bytes_eos(), vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); - assert_eq!(*r.bytes_calc().expect("error reading"), vec![0x52u8, 0x6eu8, 0x44u8]); - assert_eq!(*r.term_or_limit().expect("error reading"), vec![0x66u8, 0x6fu8, 0x6fu8]); - assert_eq!(*r.term_or_eos().expect("error reading"), vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); - assert_eq!(*r.term_or_calc().expect("error reading"), vec![0x66u8, 0x6fu8, 0x6fu8]); - assert_eq!(*r.limit_or_eos().expect("error reading"), vec![0x62u8, 0x61u8, 0x72u8, 0x7cu8]); - assert_eq!(*r.limit_or_calc().expect("error reading"), vec![0x52u8, 0x6eu8, 0x44u8]); - assert_eq!(*r.eos_or_calc().expect("error reading"), vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); + assert_eq!(*r.bytes_calc()?, vec![0x52u8, 0x6eu8, 0x44u8]); + assert_eq!(*r.term_or_limit()?, vec![0x66u8, 0x6fu8, 0x6fu8]); + assert_eq!(*r.term_or_eos()?, vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); + assert_eq!(*r.term_or_calc()?, vec![0x66u8, 0x6fu8, 0x6fu8]); + assert_eq!(*r.limit_or_eos()?, vec![0x62u8, 0x61u8, 0x72u8, 0x7cu8]); + assert_eq!(*r.limit_or_calc()?, vec![0x52u8, 0x6eu8, 0x44u8]); + assert_eq!(*r.eos_or_calc()?, vec![0x62u8, 0x61u8, 0x7au8, 0x40u8]); + Ok(()) } diff --git a/spec/rust/tests/test_combine_enum.rs b/spec/rust/tests/test_combine_enum.rs index 09dc3fd90..ec19095ef 100644 --- a/spec/rust/tests/test_combine_enum.rs +++ b/spec/rust/tests/test_combine_enum.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::combine_enum::*; #[test] -fn test_combine_enum() { +fn test_combine_enum() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = CombineEnum::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = CombineEnum::read_into(&_io, None, None)?; assert_eq!(*r.enum_u4(), CombineEnum_Animal::Pig); assert_eq!(*r.enum_u2(), CombineEnum_Animal::Horse); - assert_eq!(*r.enum_u4_u2().expect("error reading"), CombineEnum_Animal::Horse); + assert_eq!(*r.enum_u4_u2()?, CombineEnum_Animal::Horse); + Ok(()) } diff --git a/spec/rust/tests/test_combine_str.rs b/spec/rust/tests/test_combine_str.rs index e8bd4433b..0fc1a1a90 100644 --- a/spec/rust/tests/test_combine_str.rs +++ b/spec/rust/tests/test_combine_str.rs @@ -1,39 +1,30 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::combine_str::*; #[test] -fn test_combine_str() { +fn test_combine_str() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = CombineStr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = CombineStr::read_into(&_io, None, None)?; assert_eq!(*r.str_term(), "foo"); assert_eq!(*r.str_limit(), "bar|"); assert_eq!(*r.str_eos(), "baz@"); - assert_eq!(*r.str_calc().expect("error reading"), "bar"); - assert_eq!(*r.str_calc_bytes().expect("error reading"), "baz"); - assert_eq!(*r.term_or_limit().expect("error reading"), "foo"); - assert_eq!(*r.term_or_eos().expect("error reading"), "baz@"); - assert_eq!(*r.term_or_calc().expect("error reading"), "foo"); - assert_eq!(*r.term_or_calc_bytes().expect("error reading"), "baz"); - assert_eq!(*r.limit_or_eos().expect("error reading"), "bar|"); - assert_eq!(*r.limit_or_calc().expect("error reading"), "bar"); - assert_eq!(*r.limit_or_calc_bytes().expect("error reading"), "bar|"); - assert_eq!(*r.eos_or_calc().expect("error reading"), "bar"); - assert_eq!(*r.eos_or_calc_bytes().expect("error reading"), "baz@"); - assert_eq!(*r.calc_or_calc_bytes().expect("error reading"), "baz"); + assert_eq!(*r.str_calc()?, "bar"); + assert_eq!(*r.str_calc_bytes()?, "baz"); + assert_eq!(*r.term_or_limit()?, "foo"); + assert_eq!(*r.term_or_eos()?, "baz@"); + assert_eq!(*r.term_or_calc()?, "foo"); + assert_eq!(*r.term_or_calc_bytes()?, "baz"); + assert_eq!(*r.limit_or_eos()?, "bar|"); + assert_eq!(*r.limit_or_calc()?, "bar"); + assert_eq!(*r.limit_or_calc_bytes()?, "bar|"); + assert_eq!(*r.eos_or_calc()?, "bar"); + assert_eq!(*r.eos_or_calc_bytes()?, "baz@"); + assert_eq!(*r.calc_or_calc_bytes()?, "baz"); + Ok(()) } diff --git a/spec/rust/tests/test_debug_switch_user.rs b/spec/rust/tests/test_debug_switch_user.rs index 7ab2c6f01..9332bec41 100644 --- a/spec/rust/tests/test_debug_switch_user.rs +++ b/spec/rust/tests/test_debug_switch_user.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::debug_switch_user::*; #[test] -fn test_debug_switch_user() { +fn test_debug_switch_user() -> KResult<()> { let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DebugSwitchUser::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DebugSwitchUser::read_into(&_io, None, None)?; assert_eq!(*r.code(), 1); assert_eq!(*Into::>::into(&*r.data().as_ref().unwrap()).val(), -190); + Ok(()) } diff --git a/spec/rust/tests/test_default_big_endian.rs b/spec/rust/tests/test_default_big_endian.rs index 0d0501b39..9caf51944 100644 --- a/spec/rust/tests/test_default_big_endian.rs +++ b/spec/rust/tests/test_default_big_endian.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::default_big_endian::*; #[test] -fn test_default_big_endian() { +fn test_default_big_endian() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DefaultBigEndian::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DefaultBigEndian::read_into(&_io, None, None)?; assert_eq!(*r.one(), 117440512); + Ok(()) } diff --git a/spec/rust/tests/test_default_bit_endian_mod.rs b/spec/rust/tests/test_default_bit_endian_mod.rs index 51e2665e6..55aa156ff 100644 --- a/spec/rust/tests/test_default_bit_endian_mod.rs +++ b/spec/rust/tests/test_default_bit_endian_mod.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::default_bit_endian_mod::*; #[test] -fn test_default_bit_endian_mod() { +fn test_default_bit_endian_mod() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DefaultBitEndianMod::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DefaultBitEndianMod::read_into(&_io, None, None)?; assert_eq!(*r.main().one(), 336); assert_eq!(*r.main().two(), 8608); assert_eq!(*r.main().nest().two(), 11595); assert_eq!(*r.main().nest_be().two(), 12799); + Ok(()) } diff --git a/spec/rust/tests/test_default_endian_expr_inherited.rs b/spec/rust/tests/test_default_endian_expr_inherited.rs index 144c8a165..a6959e186 100644 --- a/spec/rust/tests/test_default_endian_expr_inherited.rs +++ b/spec/rust/tests/test_default_endian_expr_inherited.rs @@ -1,39 +1,30 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::default_endian_expr_inherited::*; #[test] -fn test_default_endian_expr_inherited() { +fn test_default_endian_expr_inherited() -> KResult<()> { let bytes = fs::read("../../src/endian_expr.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DefaultEndianExprInherited::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DefaultEndianExprInherited::read_into(&_io, None, None)?; assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]); assert_eq!(*r.docs()[0 as usize].main().insides().some_int(), 66); assert_eq!(*r.docs()[0 as usize].main().insides().more().some_int1(), 16896); assert_eq!(*r.docs()[0 as usize].main().insides().more().some_int2(), 66); - assert_eq!(*r.docs()[0 as usize].main().insides().more().some_inst().expect("error reading"), 66); + assert_eq!(*r.docs()[0 as usize].main().insides().more().some_inst()?, 66); assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]); assert_eq!(*r.docs()[1 as usize].main().insides().some_int(), 66); assert_eq!(*r.docs()[1 as usize].main().insides().more().some_int1(), 66); assert_eq!(*r.docs()[1 as usize].main().insides().more().some_int2(), 16896); - assert_eq!(*r.docs()[1 as usize].main().insides().more().some_inst().expect("error reading"), 1107296256); + assert_eq!(*r.docs()[1 as usize].main().insides().more().some_inst()?, 1107296256); assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]); assert_eq!(*r.docs()[2 as usize].main().insides().some_int(), 66); assert_eq!(*r.docs()[2 as usize].main().insides().more().some_int1(), 66); assert_eq!(*r.docs()[2 as usize].main().insides().more().some_int2(), 16896); - assert_eq!(*r.docs()[2 as usize].main().insides().more().some_inst().expect("error reading"), 1107296256); + assert_eq!(*r.docs()[2 as usize].main().insides().more().some_inst()?, 1107296256); + Ok(()) } diff --git a/spec/rust/tests/test_default_endian_expr_is_be.rs b/spec/rust/tests/test_default_endian_expr_is_be.rs index 256cec078..35be8e9fc 100644 --- a/spec/rust/tests/test_default_endian_expr_is_be.rs +++ b/spec/rust/tests/test_default_endian_expr_is_be.rs @@ -1,42 +1,33 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::default_endian_expr_is_be::*; #[test] -fn test_default_endian_expr_is_be() { +fn test_default_endian_expr_is_be() -> KResult<()> { let bytes = fs::read("../../src/endian_expr.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DefaultEndianExprIsBe::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DefaultEndianExprIsBe::read_into(&_io, None, None)?; assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]); assert_eq!(*r.docs()[0 as usize].main().some_int(), 66); assert_eq!(*r.docs()[0 as usize].main().some_int_be(), 66); assert_eq!(*r.docs()[0 as usize].main().some_int_le(), 66); - assert_eq!(*r.docs()[0 as usize].main().inst_int().expect("error reading"), 66); - assert_eq!(*r.docs()[0 as usize].main().inst_sub().expect("error reading").foo(), 66); + assert_eq!(*r.docs()[0 as usize].main().inst_int()?, 66); + assert_eq!(*r.docs()[0 as usize].main().inst_sub()?.foo(), 66); assert_eq!(*r.docs()[1 as usize].indicator(), vec![0x4du8, 0x4du8]); assert_eq!(*r.docs()[1 as usize].main().some_int(), 66); assert_eq!(*r.docs()[1 as usize].main().some_int_be(), 66); assert_eq!(*r.docs()[1 as usize].main().some_int_le(), 66); - assert_eq!(*r.docs()[1 as usize].main().inst_int().expect("error reading"), 1107296256); - assert_eq!(*r.docs()[1 as usize].main().inst_sub().expect("error reading").foo(), 1107296256); + assert_eq!(*r.docs()[1 as usize].main().inst_int()?, 1107296256); + assert_eq!(*r.docs()[1 as usize].main().inst_sub()?.foo(), 1107296256); assert_eq!(*r.docs()[2 as usize].indicator(), vec![0x58u8, 0x58u8]); assert_eq!(*r.docs()[2 as usize].main().some_int(), 1107296256); assert_eq!(*r.docs()[2 as usize].main().some_int_be(), 66); assert_eq!(*r.docs()[2 as usize].main().some_int_le(), 66); - assert_eq!(*r.docs()[2 as usize].main().inst_int().expect("error reading"), 66); - assert_eq!(*r.docs()[2 as usize].main().inst_sub().expect("error reading").foo(), 66); + assert_eq!(*r.docs()[2 as usize].main().inst_int()?, 66); + assert_eq!(*r.docs()[2 as usize].main().inst_sub()?.foo(), 66); + Ok(()) } diff --git a/spec/rust/tests/test_default_endian_expr_is_le.rs b/spec/rust/tests/test_default_endian_expr_is_le.rs index 70a473c39..881a656cb 100644 --- a/spec/rust/tests/test_default_endian_expr_is_le.rs +++ b/spec/rust/tests/test_default_endian_expr_is_le.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::default_endian_expr_is_le::*; #[test] -fn test_default_endian_expr_is_le() { +fn test_default_endian_expr_is_le() -> KResult<()> { let bytes = fs::read("../../src/endian_expr.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DefaultEndianExprIsLe::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DefaultEndianExprIsLe::read_into(&_io, None, None)?; assert_eq!(*r.docs()[0 as usize].indicator(), vec![0x49u8, 0x49u8]); assert_eq!(*r.docs()[0 as usize].main().some_int(), 66); @@ -33,4 +23,5 @@ fn test_default_endian_expr_is_le() { assert_eq!(*r.docs()[2 as usize].main().some_int(), 66); assert_eq!(*r.docs()[2 as usize].main().some_int_be(), 66); assert_eq!(*r.docs()[2 as usize].main().some_int_le(), 66); + Ok(()) } diff --git a/spec/rust/tests/test_default_endian_mod.rs b/spec/rust/tests/test_default_endian_mod.rs index bbfdf7e2a..7361a6b06 100644 --- a/spec/rust/tests/test_default_endian_mod.rs +++ b/spec/rust/tests/test_default_endian_mod.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::default_endian_mod::*; #[test] -fn test_default_endian_mod() { +fn test_default_endian_mod() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DefaultEndianMod::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DefaultEndianMod::read_into(&_io, None, None)?; assert_eq!(*r.main().one(), 1262698832); assert_eq!(*r.main().nest().two(), -52947); assert_eq!(*r.main().nest_be().two(), 1346454347); + Ok(()) } diff --git a/spec/rust/tests/test_docstrings.rs b/spec/rust/tests/test_docstrings.rs index 177a2d09f..18f5d48e0 100644 --- a/spec/rust/tests/test_docstrings.rs +++ b/spec/rust/tests/test_docstrings.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::docstrings::*; #[test] -fn test_docstrings() { +fn test_docstrings() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Docstrings::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Docstrings::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_docstrings_docref.rs b/spec/rust/tests/test_docstrings_docref.rs index dfa7b840f..06b5817e0 100644 --- a/spec/rust/tests/test_docstrings_docref.rs +++ b/spec/rust/tests/test_docstrings_docref.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::docstrings_docref::*; #[test] -fn test_docstrings_docref() { +fn test_docstrings_docref() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DocstringsDocref::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DocstringsDocref::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_docstrings_docref_multi.rs b/spec/rust/tests/test_docstrings_docref_multi.rs index 416ec7854..5e32f8f71 100644 --- a/spec/rust/tests/test_docstrings_docref_multi.rs +++ b/spec/rust/tests/test_docstrings_docref_multi.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::docstrings_docref_multi::*; #[test] -fn test_docstrings_docref_multi() { +fn test_docstrings_docref_multi() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = DocstringsDocrefMulti::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DocstringsDocrefMulti::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_enum_0.rs b/spec/rust/tests/test_enum_0.rs index a3bb16aed..93ab85e68 100644 --- a/spec/rust/tests/test_enum_0.rs +++ b/spec/rust/tests/test_enum_0.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_0::*; #[test] -fn test_enum_0() { +fn test_enum_0() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Enum0::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Enum0::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), Enum0_Animal::Cat); assert_eq!(*r.pet_2(), Enum0_Animal::Chicken); + Ok(()) } diff --git a/spec/rust/tests/test_enum_1.rs b/spec/rust/tests/test_enum_1.rs index fd94aef43..9f0681564 100644 --- a/spec/rust/tests/test_enum_1.rs +++ b/spec/rust/tests/test_enum_1.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_1::*; #[test] -fn test_enum_1() { +fn test_enum_1() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Enum1::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Enum1::read_into(&_io, None, None)?; assert_eq!(*r.main().submain().pet_1(), Enum1_MainObj_Animal::Cat); assert_eq!(*r.main().submain().pet_2(), Enum1_MainObj_Animal::Chicken); + Ok(()) } diff --git a/spec/rust/tests/test_enum_deep.rs b/spec/rust/tests/test_enum_deep.rs index 60b34b861..ac0d15274 100644 --- a/spec/rust/tests/test_enum_deep.rs +++ b/spec/rust/tests/test_enum_deep.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_deep::*; #[test] -fn test_enum_deep() { +fn test_enum_deep() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumDeep::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumDeep::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), EnumDeep_Container1_Animal::Cat); assert_eq!(*r.pet_2(), EnumDeep_Container1_Container2_Animal::Hare); + Ok(()) } diff --git a/spec/rust/tests/test_enum_deep_literals.rs b/spec/rust/tests/test_enum_deep_literals.rs index fc3fae705..b407c716d 100644 --- a/spec/rust/tests/test_enum_deep_literals.rs +++ b/spec/rust/tests/test_enum_deep_literals.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_deep_literals::*; #[test] -fn test_enum_deep_literals() { +fn test_enum_deep_literals() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumDeepLiterals::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = EnumDeepLiterals::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.is_pet_1_ok().expect("error reading"), true); - assert_eq!(*r.is_pet_2_ok().expect("error reading"), true); + assert_eq!(*r.is_pet_1_ok()?, true); + assert_eq!(*r.is_pet_2_ok()?, true); + Ok(()) } diff --git a/spec/rust/tests/test_enum_fancy.rs b/spec/rust/tests/test_enum_fancy.rs index 4ce265c29..abf186cee 100644 --- a/spec/rust/tests/test_enum_fancy.rs +++ b/spec/rust/tests/test_enum_fancy.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_fancy::*; #[test] -fn test_enum_fancy() { +fn test_enum_fancy() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumFancy::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumFancy::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), EnumFancy_Animal::Cat); assert_eq!(*r.pet_2(), EnumFancy_Animal::Chicken); + Ok(()) } diff --git a/spec/rust/tests/test_enum_if.rs b/spec/rust/tests/test_enum_if.rs index 408a7a3c3..e94b7957a 100644 --- a/spec/rust/tests/test_enum_if.rs +++ b/spec/rust/tests/test_enum_if.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_if::*; #[test] -fn test_enum_if() { +fn test_enum_if() -> KResult<()> { let bytes = fs::read("../../src/if_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumIf::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumIf::read_into(&_io, None, None)?; assert_eq!(*r.op1().opcode(), EnumIf_Opcodes::AString); assert_eq!(*r.op1().arg_str().str(), "foo"); @@ -28,4 +18,5 @@ fn test_enum_if() { assert_eq!(*r.op2().arg_tuple().num2(), 67); assert_eq!(*r.op3().opcode(), EnumIf_Opcodes::AString); assert_eq!(*r.op3().arg_str().str(), "bar"); + Ok(()) } diff --git a/spec/rust/tests/test_enum_int_range_s.rs b/spec/rust/tests/test_enum_int_range_s.rs index 6aea1a474..3f4dc8276 100644 --- a/spec/rust/tests/test_enum_int_range_s.rs +++ b/spec/rust/tests/test_enum_int_range_s.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_int_range_s::*; #[test] -fn test_enum_int_range_s() { +fn test_enum_int_range_s() -> KResult<()> { let bytes = fs::read("../../src/enum_int_range_s.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumIntRangeS::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumIntRangeS::read_into(&_io, None, None)?; assert_eq!(*r.f1(), EnumIntRangeS_Constants::IntMin); assert_eq!(*r.f2(), EnumIntRangeS_Constants::Zero); assert_eq!(*r.f3(), EnumIntRangeS_Constants::IntMax); + Ok(()) } diff --git a/spec/rust/tests/test_enum_int_range_u.rs b/spec/rust/tests/test_enum_int_range_u.rs index f1ff0fea7..1559ce9f1 100644 --- a/spec/rust/tests/test_enum_int_range_u.rs +++ b/spec/rust/tests/test_enum_int_range_u.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_int_range_u::*; #[test] -fn test_enum_int_range_u() { +fn test_enum_int_range_u() -> KResult<()> { let bytes = fs::read("../../src/enum_int_range_u.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumIntRangeU::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumIntRangeU::read_into(&_io, None, None)?; assert_eq!(*r.f1(), EnumIntRangeU_Constants::Zero); assert_eq!(*r.f2(), EnumIntRangeU_Constants::IntMax); + Ok(()) } diff --git a/spec/rust/tests/test_enum_invalid.rs b/spec/rust/tests/test_enum_invalid.rs index f29ac1471..30a63169b 100644 --- a/spec/rust/tests/test_enum_invalid.rs +++ b/spec/rust/tests/test_enum_invalid.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_invalid::*; #[test] -fn test_enum_invalid() { +fn test_enum_invalid() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumInvalid::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumInvalid::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), EnumInvalid_Animal::Dog); - let n : i64 = (&*r.pet_2()).into(); + let n: i64 = (&*r.pet_2()).into(); assert_eq!(n, 111); + Ok(()) } diff --git a/spec/rust/tests/test_enum_long_range_s.rs b/spec/rust/tests/test_enum_long_range_s.rs index 35accae52..a91369b4e 100644 --- a/spec/rust/tests/test_enum_long_range_s.rs +++ b/spec/rust/tests/test_enum_long_range_s.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_long_range_s::*; #[test] -fn test_enum_long_range_s() { +fn test_enum_long_range_s() -> KResult<()> { let bytes = fs::read("../../src/enum_long_range_s.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumLongRangeS::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumLongRangeS::read_into(&_io, None, None)?; assert_eq!(*r.f1(), EnumLongRangeS_Constants::LongMin); assert_eq!(*r.f2(), EnumLongRangeS_Constants::IntBelowMin); @@ -28,4 +18,5 @@ fn test_enum_long_range_s() { assert_eq!(*r.f5(), EnumLongRangeS_Constants::IntMax); assert_eq!(*r.f6(), EnumLongRangeS_Constants::IntOverMax); assert_eq!(*r.f7(), EnumLongRangeS_Constants::LongMax); + Ok(()) } diff --git a/spec/rust/tests/test_enum_long_range_u.rs b/spec/rust/tests/test_enum_long_range_u.rs index e4b9290d4..f5e40d48a 100644 --- a/spec/rust/tests/test_enum_long_range_u.rs +++ b/spec/rust/tests/test_enum_long_range_u.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_long_range_u::*; #[test] -fn test_enum_long_range_u() { +fn test_enum_long_range_u() -> KResult<()> { let bytes = fs::read("../../src/enum_long_range_u.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumLongRangeU::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumLongRangeU::read_into(&_io, None, None)?; assert_eq!(*r.f1(), EnumLongRangeU_Constants::Zero); assert_eq!(*r.f2(), EnumLongRangeU_Constants::IntMax); assert_eq!(*r.f3(), EnumLongRangeU_Constants::IntOverMax); assert_eq!(*r.f4(), EnumLongRangeU_Constants::LongMax); + Ok(()) } diff --git a/spec/rust/tests/test_enum_negative.rs b/spec/rust/tests/test_enum_negative.rs index 7ff31a2cb..58cd60012 100644 --- a/spec/rust/tests/test_enum_negative.rs +++ b/spec/rust/tests/test_enum_negative.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_negative::*; #[test] -fn test_enum_negative() { +fn test_enum_negative() -> KResult<()> { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumNegative::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumNegative::read_into(&_io, None, None)?; assert_eq!(*r.f1(), EnumNegative_Constants::NegativeOne); assert_eq!(*r.f2(), EnumNegative_Constants::PositiveOne); + Ok(()) } diff --git a/spec/rust/tests/test_enum_of_value_inst.rs b/spec/rust/tests/test_enum_of_value_inst.rs index aea61a179..568d021e6 100644 --- a/spec/rust/tests/test_enum_of_value_inst.rs +++ b/spec/rust/tests/test_enum_of_value_inst.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_of_value_inst::*; #[test] -fn test_enum_of_value_inst() { +fn test_enum_of_value_inst() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumOfValueInst::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumOfValueInst::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), EnumOfValueInst_Animal::Cat); assert_eq!(*r.pet_2(), EnumOfValueInst_Animal::Chicken); - assert_eq!(*r.pet_3().expect("error reading"), EnumOfValueInst_Animal::Dog); - assert_eq!(*r.pet_4().expect("error reading"), EnumOfValueInst_Animal::Dog); + assert_eq!(*r.pet_3()?, EnumOfValueInst_Animal::Dog); + assert_eq!(*r.pet_4()?, EnumOfValueInst_Animal::Dog); + Ok(()) } diff --git a/spec/rust/tests/test_enum_to_i.rs b/spec/rust/tests/test_enum_to_i.rs index 598aee8bc..a477f8a48 100644 --- a/spec/rust/tests/test_enum_to_i.rs +++ b/spec/rust/tests/test_enum_to_i.rs @@ -1,31 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_to_i::*; #[test] -fn test_enum_to_i() { +fn test_enum_to_i() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumToI::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumToI::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), EnumToI_Animal::Cat); assert_eq!(*r.pet_2(), EnumToI_Animal::Chicken); - assert_eq!(*r.pet_1_i().expect("error reading"), 7); - assert_eq!(*r.pet_1_mod().expect("error reading"), 32775); - assert_eq!(*r.one_lt_two().expect("error reading"), true); - assert_eq!(*r.pet_1_eq_int().expect("error reading"), true); - assert_eq!(*r.pet_2_eq_int().expect("error reading"), false); + assert_eq!(*r.pet_1_i()?, 7); + assert_eq!(*r.pet_1_i_to_s()?, "7"); + assert_eq!(*r.pet_1_mod()?, 32775); + assert_eq!(*r.one_lt_two()?, true); + assert_eq!(*r.pet_1_eq_int()?, true); + assert_eq!(*r.pet_2_eq_int()?, false); + Ok(()) } diff --git a/spec/rust/tests/test_enum_to_i_class_border_1.rs b/spec/rust/tests/test_enum_to_i_class_border_1.rs index 76fe238bf..f67646a02 100644 --- a/spec/rust/tests/test_enum_to_i_class_border_1.rs +++ b/spec/rust/tests/test_enum_to_i_class_border_1.rs @@ -1,28 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_to_i_class_border_1::*; -use rust::formats::enum_to_i_class_border_2::*; #[test] -fn test_enum_to_i_class_border_1() { +fn test_enum_to_i_class_border_1() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumToIClassBorder1::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumToIClassBorder1::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), EnumToIClassBorder1_Animal::Cat); assert_eq!(*r.pet_2(), EnumToIClassBorder1_Animal::Chicken); - assert_eq!(*r.checker().expect("error reading").is_dog().expect("error reading"), true); + assert_eq!(*r.checker()?.is_dog()?, true); + Ok(()) } diff --git a/spec/rust/tests/test_enum_to_i_invalid.rs b/spec/rust/tests/test_enum_to_i_invalid.rs index dc5d74a1a..3a1054dd5 100644 --- a/spec/rust/tests/test_enum_to_i_invalid.rs +++ b/spec/rust/tests/test_enum_to_i_invalid.rs @@ -1,33 +1,24 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::enum_to_i_invalid::*; #[test] -fn test_enum_to_i_invalid() { +fn test_enum_to_i_invalid() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = EnumToIInvalid::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = EnumToIInvalid::read_into(&_io, None, None)?; assert_eq!(*r.pet_1(), EnumToIInvalid_Animal::Dog); - let n : i64 = (&*r.pet_2()).into(); + let n: i64 = (&*r.pet_2()).into(); assert_eq!(n, 111); - assert_eq!(*r.pet_2_i().expect("error reading"), 111); - assert_eq!(*r.pet_2_i_to_s().expect("error reading"), "111"); - assert_eq!(*r.pet_2_mod().expect("error reading"), 32879); - assert_eq!(*r.one_lt_two().expect("error reading"), true); - assert_eq!(*r.pet_2_eq_int_t().expect("error reading"), true); - assert_eq!(*r.pet_2_eq_int_f().expect("error reading"), false); + assert_eq!(*r.pet_2_i()?, 111); + assert_eq!(*r.pet_2_i_to_s()?, "111"); + assert_eq!(*r.pet_2_mod()?, 32879); + assert_eq!(*r.one_lt_two()?, true); + assert_eq!(*r.pet_2_eq_int_t()?, true); + assert_eq!(*r.pet_2_eq_int_f()?, false); + Ok(()) } diff --git a/spec/rust/tests/test_expr_0.rs b/spec/rust/tests/test_expr_0.rs index 201797888..8aabe6a58 100644 --- a/spec/rust/tests/test_expr_0.rs +++ b/spec/rust/tests/test_expr_0.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_0::*; #[test] -fn test_expr_0() { +fn test_expr_0() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Expr0::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = Expr0::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.must_be_f7().expect("error reading"), 247); - assert_eq!(*r.must_be_abc123().expect("error reading"), "abc123"); + assert_eq!(*r.must_be_f7()?, 247); + assert_eq!(*r.must_be_abc123()?, "abc123"); + Ok(()) } diff --git a/spec/rust/tests/test_expr_1.rs b/spec/rust/tests/test_expr_1.rs index f6e5f6b0b..25119966c 100644 --- a/spec/rust/tests/test_expr_1.rs +++ b/spec/rust/tests/test_expr_1.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_1::*; #[test] -fn test_expr_1() { +fn test_expr_1() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Expr1::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Expr1::read_into(&_io, None, None)?; assert_eq!(*r.len_of_1(), 10); - assert_eq!(*r.len_of_1_mod().expect("error reading"), 8); + assert_eq!(*r.len_of_1_mod()?, 8); assert_eq!(*r.str1(), "Some ASC"); - assert_eq!(*r.str1_len().expect("error reading"), 8); + assert_eq!(*r.str1_len()?, 8); + Ok(()) } diff --git a/spec/rust/tests/test_expr_2.rs b/spec/rust/tests/test_expr_2.rs index 9ec82a8c2..e028d9e50 100644 --- a/spec/rust/tests/test_expr_2.rs +++ b/spec/rust/tests/test_expr_2.rs @@ -1,41 +1,32 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_2::*; #[test] -fn test_expr_2() { +fn test_expr_2() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Expr2::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Expr2::read_into(&_io, None, None)?; assert_eq!(*r.str1().len_orig(), 10); - assert_eq!(*r.str1().len_mod().expect("error reading"), 7); + assert_eq!(*r.str1().len_mod()?, 7); assert_eq!(*r.str1().str(), "Some AS"); - assert_eq!(*r.str1_len().expect("error reading"), 7); - assert_eq!(*r.str1_len_mod().expect("error reading"), 7); - assert_eq!(*r.str1_byte1().expect("error reading"), 73); - assert_eq!(*r.str1_avg().expect("error reading"), 73); - assert_eq!(*r.str1_char5().expect("error reading"), "e"); - assert_eq!(*r.str1_tuple5().expect("error reading").byte0(), 101); - assert_eq!(*r.str1_tuple5().expect("error reading").byte0(), 101); - assert_eq!(*r.str1_tuple5().expect("error reading").byte1(), 32); - assert_eq!(*r.str1_tuple5().expect("error reading").byte2(), 65); - assert_eq!(*r.str1_tuple5().expect("error reading").avg().expect("error reading"), 48); - assert_eq!(*r.str2_tuple5().expect("error reading").byte0(), 101); - assert_eq!(*r.str2_tuple5().expect("error reading").byte1(), 32); - assert_eq!(*r.str2_tuple5().expect("error reading").byte2(), 65); - assert_eq!(*r.str2_tuple5().expect("error reading").avg().expect("error reading"), 48); + assert_eq!(*r.str1_len()?, 7); + assert_eq!(*r.str1_len_mod()?, 7); + assert_eq!(*r.str1_byte1()?, 73); + assert_eq!(*r.str1_avg()?, 73); + assert_eq!(*r.str1_char5()?, "e"); + assert_eq!(*r.str1_tuple5()?.byte0(), 101); + assert_eq!(*r.str1_tuple5()?.byte0(), 101); + assert_eq!(*r.str1_tuple5()?.byte1(), 32); + assert_eq!(*r.str1_tuple5()?.byte2(), 65); + assert_eq!(*r.str1_tuple5()?.avg()?, 48); + assert_eq!(*r.str2_tuple5()?.byte0(), 101); + assert_eq!(*r.str2_tuple5()?.byte1(), 32); + assert_eq!(*r.str2_tuple5()?.byte2(), 65); + assert_eq!(*r.str2_tuple5()?.avg()?, 48); + Ok(()) } diff --git a/spec/rust/tests/test_expr_3.rs b/spec/rust/tests/test_expr_3.rs index 3e8c583ac..2e82e518b 100644 --- a/spec/rust/tests/test_expr_3.rs +++ b/spec/rust/tests/test_expr_3.rs @@ -1,36 +1,27 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_3::*; #[test] -fn test_expr_3() { +fn test_expr_3() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Expr3::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Expr3::read_into(&_io, None, None)?; assert_eq!(*r.one(), 80); assert_eq!(*r.two(), "ACK"); - assert_eq!(*r.three().expect("error reading"), "@ACK"); - assert_eq!(*r.four().expect("error reading"), "_ACK_"); - assert_eq!(*r.is_str_eq().expect("error reading"), true); - assert_eq!(*r.is_str_ne().expect("error reading"), false); - assert_eq!(*r.is_str_lt().expect("error reading"), true); - assert_eq!(*r.is_str_gt().expect("error reading"), false); - assert_eq!(*r.is_str_le().expect("error reading"), true); - assert_eq!(*r.is_str_ge().expect("error reading"), false); - assert_eq!(*r.is_str_lt2().expect("error reading"), true); - assert_eq!(*r.test_not().expect("error reading"), true); + assert_eq!(*r.three()?, "@ACK"); + assert_eq!(*r.four()?, "_ACK_"); + assert_eq!(*r.is_str_eq()?, true); + assert_eq!(*r.is_str_ne()?, false); + assert_eq!(*r.is_str_lt()?, true); + assert_eq!(*r.is_str_gt()?, false); + assert_eq!(*r.is_str_le()?, true); + assert_eq!(*r.is_str_ge()?, false); + assert_eq!(*r.is_str_lt2()?, true); + assert_eq!(*r.test_not()?, true); + Ok(()) } diff --git a/spec/rust/tests/test_expr_array.rs b/spec/rust/tests/test_expr_array.rs index f47d882c3..6b89c2ffb 100644 --- a/spec/rust/tests/test_expr_array.rs +++ b/spec/rust/tests/test_expr_array.rs @@ -1,39 +1,30 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_array::*; #[test] -fn test_expr_array() { +fn test_expr_array() -> KResult<()> { let bytes = fs::read("../../src/expr_array.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprArray::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprArray::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.aint_size().expect("error reading"), 4); - assert_eq!(*r.aint_first().expect("error reading"), 7657765); - assert_eq!(*r.aint_last().expect("error reading"), 16272640); - assert_eq!(*r.aint_min().expect("error reading"), 49185); - assert_eq!(*r.aint_max().expect("error reading"), 1123362332); - assert_eq!(*r.afloat_size().expect("error reading"), 3); - assert_eq!(*r.afloat_first().expect("error reading"), -2.6839530254859364E-121); - assert_eq!(*r.afloat_last().expect("error reading"), -1.1103359815095273E-175); - assert_eq!(*r.afloat_min().expect("error reading"), -8.754689149998834E+288); - assert_eq!(*r.afloat_max().expect("error reading"), -1.1103359815095273E-175); - assert_eq!(*r.astr_size().expect("error reading"), 3); - assert_eq!(*r.astr_first().expect("error reading"), "foo"); - assert_eq!(*r.astr_last().expect("error reading"), "baz"); - assert_eq!(*r.astr_min().expect("error reading"), "bar"); - assert_eq!(*r.astr_max().expect("error reading"), "foo"); + assert_eq!(*r.aint_size()?, 4); + assert_eq!(*r.aint_first()?, 7657765); + assert_eq!(*r.aint_last()?, 16272640); + assert_eq!(*r.aint_min()?, 49185); + assert_eq!(*r.aint_max()?, 1123362332); + assert_eq!(*r.afloat_size()?, 3); + assert_eq!(*r.afloat_first()?, -2.6839530254859364E-121); + assert_eq!(*r.afloat_last()?, -1.1103359815095273E-175); + assert_eq!(*r.afloat_min()?, -8.754689149998834E+288); + assert_eq!(*r.afloat_max()?, -1.1103359815095273E-175); + assert_eq!(*r.astr_size()?, 3); + assert_eq!(*r.astr_first()?, "foo"); + assert_eq!(*r.astr_last()?, "baz"); + assert_eq!(*r.astr_min()?, "bar"); + assert_eq!(*r.astr_max()?, "foo"); + Ok(()) } diff --git a/spec/rust/tests/test_expr_bits.rs b/spec/rust/tests/test_expr_bits.rs index 72eca5d1c..8ff2d7e30 100644 --- a/spec/rust/tests/test_expr_bits.rs +++ b/spec/rust/tests/test_expr_bits.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_bits::*; #[test] -fn test_expr_bits() { +fn test_expr_bits() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprBits::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprBits::read_into(&_io, None, None)?; assert_eq!(*r.a(), 2); assert_eq!(*r.enum_seq(), ExprBits_Items::Foo); @@ -29,6 +19,7 @@ fn test_expr_bits() { assert_eq!(r.repeat_expr()[1 as usize], 98); assert_eq!(r.switch_on_type(), 97); assert_eq!(*r.switch_on_endian().foo(), 29184); - assert_eq!(*r.enum_inst().expect("error reading"), ExprBits_Items::Bar); - assert_eq!(*r.inst_pos().expect("error reading"), 111); + assert_eq!(*r.enum_inst()?, ExprBits_Items::Bar); + assert_eq!(*r.inst_pos()?, 111); + Ok(()) } diff --git a/spec/rust/tests/test_expr_bytes_cmp.rs b/spec/rust/tests/test_expr_bytes_cmp.rs index 53b4c725c..75144846c 100644 --- a/spec/rust/tests/test_expr_bytes_cmp.rs +++ b/spec/rust/tests/test_expr_bytes_cmp.rs @@ -1,34 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_bytes_cmp::*; #[test] -fn test_expr_bytes_cmp() { +fn test_expr_bytes_cmp() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprBytesCmp::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprBytesCmp::read_into(&_io, None, None)?; assert_eq!(*r.one(), vec![0x50u8]); assert_eq!(*r.two(), vec![0x41u8, 0x43u8, 0x4bu8]); - assert_eq!(*r.is_eq().expect("error reading"), true); - assert_eq!(*r.is_ne().expect("error reading"), false); - assert_eq!(*r.is_lt().expect("error reading"), true); - assert_eq!(*r.is_gt().expect("error reading"), false); - assert_eq!(*r.is_le().expect("error reading"), true); - assert_eq!(*r.is_ge().expect("error reading"), false); - assert_eq!(*r.is_lt2().expect("error reading"), false); - assert_eq!(*r.is_gt2().expect("error reading"), true); + assert_eq!(*r.is_eq()?, true); + assert_eq!(*r.is_ne()?, false); + assert_eq!(*r.is_lt()?, true); + assert_eq!(*r.is_gt()?, false); + assert_eq!(*r.is_le()?, true); + assert_eq!(*r.is_ge()?, false); + assert_eq!(*r.is_lt2()?, false); + assert_eq!(*r.is_gt2()?, true); + Ok(()) } diff --git a/spec/rust/tests/test_expr_bytes_non_literal.rs b/spec/rust/tests/test_expr_bytes_non_literal.rs index 3b9fcbc5f..4ea35de9a 100644 --- a/spec/rust/tests/test_expr_bytes_non_literal.rs +++ b/spec/rust/tests/test_expr_bytes_non_literal.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_bytes_non_literal::*; #[test] -fn test_expr_bytes_non_literal() { +fn test_expr_bytes_non_literal() -> KResult<()> { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprBytesNonLiteral::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprBytesNonLiteral::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(r.calc_bytes().expect("error reading").len(), 2); - assert_eq!(r.calc_bytes().expect("error reading")[0 as usize], 255); - assert_eq!(r.calc_bytes().expect("error reading")[1 as usize], 1); + assert_eq!(r.calc_bytes()?.len(), 2); + assert_eq!(r.calc_bytes()?[0 as usize], 255); + assert_eq!(r.calc_bytes()?[1 as usize], 1); + Ok(()) } diff --git a/spec/rust/tests/test_expr_bytes_ops.rs b/spec/rust/tests/test_expr_bytes_ops.rs index 6115755ae..251ddafee 100644 --- a/spec/rust/tests/test_expr_bytes_ops.rs +++ b/spec/rust/tests/test_expr_bytes_ops.rs @@ -1,40 +1,31 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_bytes_ops::*; #[test] -fn test_expr_bytes_ops() { +fn test_expr_bytes_ops() -> KResult<()> { let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprBytesOps::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprBytesOps::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.one_size().expect("error reading"), 3); - assert_eq!(*r.one_first().expect("error reading"), 1); - assert_eq!(*r.one_mid().expect("error reading"), 66); - assert_eq!(*r.one_last().expect("error reading"), 255); - assert_eq!(r.one_last().expect("error reading").to_string(), "255"); - assert_eq!(*r.one_min().expect("error reading"), 1); - assert_eq!(*r.one_max().expect("error reading"), 255); - assert_eq!(r.one_max().expect("error reading").to_string(), "255"); - assert_eq!(*r.two_size().expect("error reading"), 3); - assert_eq!(*r.two_first().expect("error reading"), 65); - assert_eq!(*r.two_mid().expect("error reading"), 255); - assert_eq!(r.two_mid().expect("error reading").to_string(), "255"); - assert_eq!(*r.two_last().expect("error reading"), 75); - assert_eq!(*r.two_min().expect("error reading"), 65); - assert_eq!(*r.two_max().expect("error reading"), 255); - assert_eq!(r.two_max().expect("error reading").to_string(), "255"); + assert_eq!(*r.one_size()?, 3); + assert_eq!(*r.one_first()?, 1); + assert_eq!(*r.one_mid()?, 66); + assert_eq!(*r.one_last()?, 255); + assert_eq!(r.one_last()?.to_string(), "255"); + assert_eq!(*r.one_min()?, 1); + assert_eq!(*r.one_max()?, 255); + assert_eq!(r.one_max()?.to_string(), "255"); + assert_eq!(*r.two_size()?, 3); + assert_eq!(*r.two_first()?, 65); + assert_eq!(*r.two_mid()?, 255); + assert_eq!(r.two_mid()?.to_string(), "255"); + assert_eq!(*r.two_last()?, 75); + assert_eq!(*r.two_min()?, 65); + assert_eq!(*r.two_max()?, 255); + assert_eq!(r.two_max()?.to_string(), "255"); + Ok(()) } diff --git a/spec/rust/tests/test_expr_calc_array_ops.rs b/spec/rust/tests/test_expr_calc_array_ops.rs index 91666ec7f..a48014489 100644 --- a/spec/rust/tests/test_expr_calc_array_ops.rs +++ b/spec/rust/tests/test_expr_calc_array_ops.rs @@ -1,42 +1,33 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_calc_array_ops::*; #[test] -fn test_expr_calc_array_ops() { +fn test_expr_calc_array_ops() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprCalcArrayOps::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprCalcArrayOps::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.int_array_size().expect("error reading"), 7); - assert_eq!(*r.int_array_first().expect("error reading"), 10); - assert_eq!(*r.int_array_mid().expect("error reading"), 25); - assert_eq!(*r.int_array_last().expect("error reading"), 1000); - assert_eq!(*r.int_array_min().expect("error reading"), 10); - assert_eq!(*r.int_array_max().expect("error reading"), 1000); - assert_eq!(*r.double_array_size().expect("error reading"), 5); - assert_eq!(*r.double_array_first().expect("error reading"), 10.0); - assert_eq!(*r.double_array_mid().expect("error reading"), 25.0); - assert_eq!(*r.double_array_last().expect("error reading"), 3.14159); - assert_eq!(*r.double_array_min().expect("error reading"), 3.14159); - assert_eq!(*r.double_array_max().expect("error reading"), 100.0); - assert_eq!(*r.str_array_size().expect("error reading"), 4); - assert_eq!(*r.str_array_first().expect("error reading"), "un"); - assert_eq!(*r.str_array_mid().expect("error reading"), "deux"); - assert_eq!(*r.str_array_last().expect("error reading"), "quatre"); - assert_eq!(*r.str_array_min().expect("error reading"), "deux"); - assert_eq!(*r.str_array_max().expect("error reading"), "un"); + assert_eq!(*r.int_array_size()?, 7); + assert_eq!(*r.int_array_first()?, 10); + assert_eq!(*r.int_array_mid()?, 25); + assert_eq!(*r.int_array_last()?, 1000); + assert_eq!(*r.int_array_min()?, 10); + assert_eq!(*r.int_array_max()?, 1000); + assert_eq!(*r.double_array_size()?, 5); + assert_eq!(*r.double_array_first()?, 10.0); + assert_eq!(*r.double_array_mid()?, 25.0); + assert_eq!(*r.double_array_last()?, 3.14159); + assert_eq!(*r.double_array_min()?, 3.14159); + assert_eq!(*r.double_array_max()?, 100.0); + assert_eq!(*r.str_array_size()?, 4); + assert_eq!(*r.str_array_first()?, "un"); + assert_eq!(*r.str_array_mid()?, "deux"); + assert_eq!(*r.str_array_last()?, "quatre"); + assert_eq!(*r.str_array_min()?, "deux"); + assert_eq!(*r.str_array_max()?, "un"); + Ok(()) } diff --git a/spec/rust/tests/test_expr_enum.rs b/spec/rust/tests/test_expr_enum.rs index cab4f31a4..50a7cc7c5 100644 --- a/spec/rust/tests/test_expr_enum.rs +++ b/spec/rust/tests/test_expr_enum.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_enum::*; #[test] -fn test_expr_enum() { +fn test_expr_enum() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprEnum::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprEnum::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.const_dog().expect("error reading"), ExprEnum_Animal::Dog); - assert_eq!(*r.derived_boom().expect("error reading"), ExprEnum_Animal::Boom); - assert_eq!(*r.derived_dog().expect("error reading"), ExprEnum_Animal::Dog); + assert_eq!(*r.const_dog()?, ExprEnum_Animal::Dog); + assert_eq!(*r.derived_boom()?, ExprEnum_Animal::Boom); + assert_eq!(*r.derived_dog()?, ExprEnum_Animal::Dog); + Ok(()) } diff --git a/spec/rust/tests/test_expr_if_int_ops.rs b/spec/rust/tests/test_expr_if_int_ops.rs index d43225e67..d30eb9b63 100644 --- a/spec/rust/tests/test_expr_if_int_ops.rs +++ b/spec/rust/tests/test_expr_if_int_ops.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_if_int_ops::*; #[test] -fn test_expr_if_int_ops() { +fn test_expr_if_int_ops() -> KResult<()> { let bytes = fs::read("../../src/process_coerce_switch.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprIfIntOps::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprIfIntOps::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.is_eq_prim().expect("error reading"), true); - assert_eq!(*r.is_eq_boxed().expect("error reading"), true); + assert_eq!(*r.is_eq_prim()?, true); + assert_eq!(*r.is_eq_boxed()?, true); + Ok(()) } diff --git a/spec/rust/tests/test_expr_int_div.rs b/spec/rust/tests/test_expr_int_div.rs index e9c34832b..0ebe54e6e 100644 --- a/spec/rust/tests/test_expr_int_div.rs +++ b/spec/rust/tests/test_expr_int_div.rs @@ -1,28 +1,21 @@ -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_int_div::*; #[test] -fn test_expr_int_div() { +fn test_expr_int_div() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprIntDiv::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprIntDiv::read_into(&_io, None, None)?; assert_eq!(*r.int_u(), 1262698832); assert_eq!(*r.int_s(), -52947); - assert_eq!(*r.div_pos_const().expect("error reading"), 756); - assert_eq!(*r.div_neg_const().expect("error reading"), -756); - assert_eq!(*r.div_pos_seq().expect("error reading"), 97130679); - assert_eq!(*r.div_neg_seq().expect("error reading"), -4072); + assert_eq!(*r.div_pos_const()?, 756); + assert_eq!(*r.div_neg_const()?, -757); + assert_eq!(*r.div_pos_seq()?, 97130679); + assert_eq!(*r.div_neg_seq()?, -4073); + Ok(()) } diff --git a/spec/rust/tests/test_expr_io_eof.rs b/spec/rust/tests/test_expr_io_eof.rs index d8c2bc93d..07b1798f0 100644 --- a/spec/rust/tests/test_expr_io_eof.rs +++ b/spec/rust/tests/test_expr_io_eof.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_io_eof::*; #[test] -fn test_expr_io_eof() { +fn test_expr_io_eof() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprIoEof::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprIoEof::read_into(&_io, None, None)?; assert_eq!(*r.substream1().one(), 1262698832); - assert_eq!(*r.substream1().two(), 0); + assert!(r.substream1().two().is_none()); assert_eq!(*r.substream2().one(), 4294914349); assert_eq!(*r.substream2().two(), 1262698832); + Ok(()) } diff --git a/spec/rust/tests/test_expr_io_pos.rs b/spec/rust/tests/test_expr_io_pos.rs index 492e3f82e..c02dc685c 100644 --- a/spec/rust/tests/test_expr_io_pos.rs +++ b/spec/rust/tests/test_expr_io_pos.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_io_pos::*; #[test] -fn test_expr_io_pos() { +fn test_expr_io_pos() -> KResult<()> { let bytes = fs::read("../../src/expr_io_pos.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprIoPos::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprIoPos::read_into(&_io, None, None)?; assert_eq!(*r.substream1().my_str(), "CURIOSITY"); assert_eq!(*r.substream1().body(), vec![0x11u8, 0x22u8, 0x33u8, 0x44u8]); @@ -27,4 +17,5 @@ fn test_expr_io_pos() { assert_eq!(*r.substream2().my_str(), "KILLED"); assert_eq!(*r.substream2().body(), vec![0x61u8, 0x20u8, 0x63u8, 0x61u8, 0x74u8]); assert_eq!(*r.substream2().number(), 103); + Ok(()) } diff --git a/spec/rust/tests/test_expr_mod.rs b/spec/rust/tests/test_expr_mod.rs index f538a8edf..88dffcc3e 100644 --- a/spec/rust/tests/test_expr_mod.rs +++ b/spec/rust/tests/test_expr_mod.rs @@ -1,30 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_mod::*; #[test] -fn test_expr_mod() { +fn test_expr_mod() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprMod::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprMod::read_into(&_io, None, None)?; assert_eq!(*r.int_u(), 1262698832); assert_eq!(*r.int_s(), -52947); - assert_eq!(*r.mod_pos_const().expect("error reading"), 9); - assert_eq!(*r.mod_neg_const().expect("error reading"), 4); - assert_eq!(*r.mod_pos_seq().expect("error reading"), 5); - assert_eq!(*r.mod_neg_seq().expect("error reading"), 2); + assert_eq!(*r.mod_pos_const()?, 9); + assert_eq!(*r.mod_neg_const()?, 4); + assert_eq!(*r.mod_pos_seq()?, 5); + assert_eq!(*r.mod_neg_seq()?, 2); + Ok(()) } diff --git a/spec/rust/tests/test_expr_ops_parens.rs b/spec/rust/tests/test_expr_ops_parens.rs index a1c74288d..f670acae5 100644 --- a/spec/rust/tests/test_expr_ops_parens.rs +++ b/spec/rust/tests/test_expr_ops_parens.rs @@ -1,33 +1,24 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_ops_parens::*; #[test] -fn test_expr_ops_parens() { +fn test_expr_ops_parens() -> KResult<()> { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprOpsParens::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprOpsParens::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.i_sum_to_str().expect("error reading"), "29"); - assert_eq!(*r.f_sum_to_int().expect("error reading"), 9); - assert_eq!(*r.str_concat_len().expect("error reading"), 10); - assert_eq!(*r.str_concat_rev().expect("error reading"), "9876543210"); - assert_eq!(*r.str_concat_substr_2_to_7().expect("error reading"), "23456"); - assert_eq!(*r.str_concat_to_i().expect("error reading"), 123456789); - assert_eq!(*r.bool_eq().expect("error reading"), 0); - assert_eq!(*r.bool_and().expect("error reading"), 0); - assert_eq!(*r.bool_or().expect("error reading"), 1); + assert_eq!(*r.i_sum_to_str()?, "29"); + assert_eq!(*r.f_sum_to_int()?, 9); + assert_eq!(*r.str_concat_len()?, 10); + assert_eq!(*r.str_concat_rev()?, "9876543210"); + assert_eq!(*r.str_concat_substr_2_to_7()?, "23456"); + assert_eq!(*r.str_concat_to_i()?, 123456789); + assert_eq!(*r.bool_eq()?, 0); + assert_eq!(*r.bool_and()?, 0); + assert_eq!(*r.bool_or()?, 1); + Ok(()) } diff --git a/spec/rust/tests/test_expr_sizeof_type_0.rs b/spec/rust/tests/test_expr_sizeof_type_0.rs index 7d3a52ee4..783b85160 100644 --- a/spec/rust/tests/test_expr_sizeof_type_0.rs +++ b/spec/rust/tests/test_expr_sizeof_type_0.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_sizeof_type_0::*; #[test] -fn test_expr_sizeof_type_0() { +fn test_expr_sizeof_type_0() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprSizeofType0::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprSizeofType0::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.sizeof_block().expect("error reading"), (((1 + 4) as i32) + (2 as i32))); + assert_eq!(*r.sizeof_block()?, (((1 + 4) as i32) + (2 as i32))); + Ok(()) } diff --git a/spec/rust/tests/test_expr_sizeof_type_1.rs b/spec/rust/tests/test_expr_sizeof_type_1.rs index 4b1a87c13..6d5cd4c3b 100644 --- a/spec/rust/tests/test_expr_sizeof_type_1.rs +++ b/spec/rust/tests/test_expr_sizeof_type_1.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_sizeof_type_1::*; #[test] -fn test_expr_sizeof_type_1() { +fn test_expr_sizeof_type_1() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprSizeofType1::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprSizeofType1::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.sizeof_block().expect("error reading"), (((((1 + 4) as i32) + (2 as i32)) as i32) + (4 as i32))); - assert_eq!(*r.sizeof_subblock().expect("error reading"), 4); + assert_eq!(*r.sizeof_block()?, (((((1 + 4) as i32) + (2 as i32)) as i32) + (4 as i32))); + assert_eq!(*r.sizeof_subblock()?, 4); + Ok(()) } diff --git a/spec/rust/tests/test_expr_sizeof_value_0.rs b/spec/rust/tests/test_expr_sizeof_value_0.rs index 593f6b49c..14f7472e1 100644 --- a/spec/rust/tests/test_expr_sizeof_value_0.rs +++ b/spec/rust/tests/test_expr_sizeof_value_0.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_sizeof_value_0::*; #[test] -fn test_expr_sizeof_value_0() { +fn test_expr_sizeof_value_0() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprSizeofValue0::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprSizeofValue0::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.self_sizeof().expect("error reading"), (((((1 + 4) as i32) + (2 as i32)) as i32) + (2 as i32))); - assert_eq!(*r.sizeof_block().expect("error reading"), (((1 + 4) as i32) + (2 as i32))); - assert_eq!(*r.sizeof_block_a().expect("error reading"), 1); - assert_eq!(*r.sizeof_block_b().expect("error reading"), 4); - assert_eq!(*r.sizeof_block_c().expect("error reading"), 2); + assert_eq!(*r.self_sizeof()?, (((((1 + 4) as i32) + (2 as i32)) as i32) + (2 as i32))); + assert_eq!(*r.sizeof_block()?, (((1 + 4) as i32) + (2 as i32))); + assert_eq!(*r.sizeof_block_a()?, 1); + assert_eq!(*r.sizeof_block_b()?, 4); + assert_eq!(*r.sizeof_block_c()?, 2); + Ok(()) } diff --git a/spec/rust/tests/test_expr_sizeof_value_sized.rs b/spec/rust/tests/test_expr_sizeof_value_sized.rs index 452727e78..4ce4dae42 100644 --- a/spec/rust/tests/test_expr_sizeof_value_sized.rs +++ b/spec/rust/tests/test_expr_sizeof_value_sized.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_sizeof_value_sized::*; #[test] -fn test_expr_sizeof_value_sized() { +fn test_expr_sizeof_value_sized() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprSizeofValueSized::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprSizeofValueSized::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.self_sizeof().expect("error reading"), (12 + 2)); - assert_eq!(*r.sizeof_block().expect("error reading"), 12); - assert_eq!(*r.sizeof_block_a().expect("error reading"), 1); - assert_eq!(*r.sizeof_block_b().expect("error reading"), 4); - assert_eq!(*r.sizeof_block_c().expect("error reading"), 2); + assert_eq!(*r.self_sizeof()?, (12 + 2)); + assert_eq!(*r.sizeof_block()?, 12); + assert_eq!(*r.sizeof_block_a()?, 1); + assert_eq!(*r.sizeof_block_b()?, 4); + assert_eq!(*r.sizeof_block_c()?, 2); + Ok(()) } diff --git a/spec/rust/tests/test_expr_str_encodings.rs b/spec/rust/tests/test_expr_str_encodings.rs index c659b93cb..904418076 100644 --- a/spec/rust/tests/test_expr_str_encodings.rs +++ b/spec/rust/tests/test_expr_str_encodings.rs @@ -1,31 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_str_encodings::*; #[test] -fn test_expr_str_encodings() { +fn test_expr_str_encodings() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprStrEncodings::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = ExprStrEncodings::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.str1_eq().expect("error reading"), true); - assert_eq!(*r.str2_eq().expect("error reading"), true); - assert_eq!(*r.str3_eq().expect("error reading"), true); - assert_eq!(*r.str3_eq_str2().expect("error reading"), true); - assert_eq!(*r.str4_eq().expect("error reading"), true); - assert_eq!(*r.str4_gt_str_calc().expect("error reading"), true); - assert_eq!(*r.str4_gt_str_from_bytes().expect("error reading"), true); + assert_eq!(*r.str1_eq()?, true); + assert_eq!(*r.str2_eq()?, true); + assert_eq!(*r.str3_eq()?, true); + assert_eq!(*r.str3_eq_str2()?, true); + assert_eq!(*r.str4_eq()?, true); + assert_eq!(*r.str4_gt_str_calc()?, true); + assert_eq!(*r.str4_gt_str_from_bytes()?, true); + Ok(()) } diff --git a/spec/rust/tests/test_expr_str_ops.rs b/spec/rust/tests/test_expr_str_ops.rs index 910b7cd54..e03b70e20 100644 --- a/spec/rust/tests/test_expr_str_ops.rs +++ b/spec/rust/tests/test_expr_str_ops.rs @@ -1,41 +1,33 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_str_ops::*; #[test] -fn test_expr_str_ops() { +fn test_expr_str_ops() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprStrOps::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprStrOps::read_into(&_io, None, None)?; assert_eq!(*r.one(), "foo|b"); - assert_eq!(*r.one_len().expect("error reading"), 5); - assert_eq!(*r.one_rev().expect("error reading"), "b|oof"); - assert_eq!(*r.one_substr_0_to_3().expect("error reading"), "foo"); - assert_eq!(*r.one_substr_2_to_5().expect("error reading"), "o|b"); - assert_eq!(*r.one_substr_3_to_3().expect("error reading"), ""); - assert_eq!(*r.two().expect("error reading"), "0123456789"); - assert_eq!(*r.two_len().expect("error reading"), 10); - assert_eq!(*r.two_rev().expect("error reading"), "9876543210"); - assert_eq!(*r.two_substr_0_to_7().expect("error reading"), "0123456"); - assert_eq!(*r.two_substr_4_to_10().expect("error reading"), "456789"); - assert_eq!(*r.two_substr_0_to_10().expect("error reading"), "0123456789"); - assert_eq!(*r.to_i_attr().expect("error reading"), 9173); - assert_eq!(*r.to_i_r10().expect("error reading"), -72); - assert_eq!(*r.to_i_r2().expect("error reading"), 86); - assert_eq!(*r.to_i_r8().expect("error reading"), 465); - assert_eq!(*r.to_i_r16().expect("error reading"), 18383); + assert_eq!(*r.one_len()?, 5); + assert_eq!(*r.one_rev()?, "b|oof"); + assert_eq!(*r.one_substr_0_to_3()?, "foo"); + assert_eq!(*r.one_substr_2_to_5()?, "o|b"); + assert_eq!(*r.one_substr_3_to_3()?, ""); + assert_eq!(*r.one_substr_0_to_0()?, ""); + assert_eq!(*r.two()?, "0123456789"); + assert_eq!(*r.two_len()?, 10); + assert_eq!(*r.two_rev()?, "9876543210"); + assert_eq!(*r.two_substr_0_to_7()?, "0123456"); + assert_eq!(*r.two_substr_4_to_10()?, "456789"); + assert_eq!(*r.two_substr_0_to_10()?, "0123456789"); + assert_eq!(*r.to_i_attr()?, 9173); + assert_eq!(*r.to_i_r10()?, -72); + assert_eq!(*r.to_i_r2()?, 86); + assert_eq!(*r.to_i_r8()?, 465); + assert_eq!(*r.to_i_r16()?, 18383); + Ok(()) } diff --git a/spec/rust/tests/test_expr_to_i_trailing.rs b/spec/rust/tests/test_expr_to_i_trailing.rs index 36cbab356..64a8e1123 100644 --- a/spec/rust/tests/test_expr_to_i_trailing.rs +++ b/spec/rust/tests/test_expr_to_i_trailing.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::expr_to_i_trailing::*; #[test] -fn test_expr_to_i_trailing() { +fn test_expr_to_i_trailing() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ExprToITrailing::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ExprToITrailing::read_into(&_io, None, None)?; assert_eq!(r.to_i_r10().unwrap_err(), KError::CastError); - assert_eq!(*r.to_i_r16().expect("error reading"), 152517308); + assert_eq!(*r.to_i_r16()?, 152517308); assert_eq!(r.to_i_garbage().unwrap_err(), KError::CastError); + Ok(()) } diff --git a/spec/rust/tests/test_fixed_contents.rs b/spec/rust/tests/test_fixed_contents.rs index 550f9d28a..d22e41ded 100644 --- a/spec/rust/tests/test_fixed_contents.rs +++ b/spec/rust/tests/test_fixed_contents.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::fixed_contents::*; #[test] -fn test_fixed_contents() { +fn test_fixed_contents() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = FixedContents::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = FixedContents::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_fixed_struct.rs b/spec/rust/tests/test_fixed_struct.rs index 888694047..05b306caa 100644 --- a/spec/rust/tests/test_fixed_struct.rs +++ b/spec/rust/tests/test_fixed_struct.rs @@ -1,44 +1,35 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::fixed_struct::*; #[test] -fn test_fixed_struct() { +fn test_fixed_struct() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = FixedStruct::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = FixedStruct::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.hdr().expect("error reading").uint8(), 255); - assert_eq!(*r.hdr().expect("error reading").uint16(), 65535); - assert_eq!(*r.hdr().expect("error reading").uint32(), 4294967295); - assert_eq!(*r.hdr().expect("error reading").uint64(), 18446744073709551615); - assert_eq!(*r.hdr().expect("error reading").sint8(), -1); - assert_eq!(*r.hdr().expect("error reading").sint16(), -1); - assert_eq!(*r.hdr().expect("error reading").sint32(), -1); - assert_eq!(*r.hdr().expect("error reading").sint64(), -1); - assert_eq!(*r.hdr().expect("error reading").uint16le(), 66); - assert_eq!(*r.hdr().expect("error reading").uint32le(), 66); - assert_eq!(*r.hdr().expect("error reading").uint64le(), 66); - assert_eq!(*r.hdr().expect("error reading").sint16le(), -66); - assert_eq!(*r.hdr().expect("error reading").sint32le(), -66); - assert_eq!(*r.hdr().expect("error reading").sint64le(), -66); - assert_eq!(*r.hdr().expect("error reading").uint16be(), 66); - assert_eq!(*r.hdr().expect("error reading").uint32be(), 66); - assert_eq!(*r.hdr().expect("error reading").uint64be(), 66); - assert_eq!(*r.hdr().expect("error reading").sint16be(), -66); - assert_eq!(*r.hdr().expect("error reading").sint32be(), -66); - assert_eq!(*r.hdr().expect("error reading").sint64be(), -66); + assert_eq!(*r.hdr()?.uint8(), 255); + assert_eq!(*r.hdr()?.uint16(), 65535); + assert_eq!(*r.hdr()?.uint32(), 4294967295); + assert_eq!(*r.hdr()?.uint64(), 18446744073709551615); + assert_eq!(*r.hdr()?.sint8(), -1); + assert_eq!(*r.hdr()?.sint16(), -1); + assert_eq!(*r.hdr()?.sint32(), -1); + assert_eq!(*r.hdr()?.sint64(), -1); + assert_eq!(*r.hdr()?.uint16le(), 66); + assert_eq!(*r.hdr()?.uint32le(), 66); + assert_eq!(*r.hdr()?.uint64le(), 66); + assert_eq!(*r.hdr()?.sint16le(), -66); + assert_eq!(*r.hdr()?.sint32le(), -66); + assert_eq!(*r.hdr()?.sint64le(), -66); + assert_eq!(*r.hdr()?.uint16be(), 66); + assert_eq!(*r.hdr()?.uint32be(), 66); + assert_eq!(*r.hdr()?.uint64be(), 66); + assert_eq!(*r.hdr()?.sint16be(), -66); + assert_eq!(*r.hdr()?.sint32be(), -66); + assert_eq!(*r.hdr()?.sint64be(), -66); + Ok(()) } diff --git a/spec/rust/tests/test_float_to_i.rs b/spec/rust/tests/test_float_to_i.rs index 58aede007..6ef3d0c58 100644 --- a/spec/rust/tests/test_float_to_i.rs +++ b/spec/rust/tests/test_float_to_i.rs @@ -1,32 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::float_to_i::*; #[test] -fn test_float_to_i() { +fn test_float_to_i() -> KResult<()> { let bytes = fs::read("../../src/floating_points.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = FloatToI::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = FloatToI::read_into(&_io, None, None)?; assert_eq!(*r.single_value(), 0.5); assert_eq!(*r.double_value(), 0.25); - assert_eq!(*r.single_i().expect("error reading"), 0); - assert_eq!(*r.double_i().expect("error reading"), 0); - assert_eq!(*r.float1_i().expect("error reading"), 1); - assert_eq!(*r.float2_i().expect("error reading"), 1); - assert_eq!(*r.float3_i().expect("error reading"), 1); - assert_eq!(*r.float4_i().expect("error reading"), -2); + assert_eq!(*r.single_i()?, 0); + assert_eq!(*r.double_i()?, 0); + assert_eq!(*r.float1_i()?, 1); + assert_eq!(*r.float2_i()?, 1); + assert_eq!(*r.float3_i()?, 1); + assert_eq!(*r.float4_i()?, -2); + Ok(()) } diff --git a/spec/rust/tests/test_floating_points.rs b/spec/rust/tests/test_floating_points.rs index 5904e494c..08ccb82f8 100644 --- a/spec/rust/tests/test_floating_points.rs +++ b/spec/rust/tests/test_floating_points.rs @@ -1,32 +1,23 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::floating_points::*; #[test] -fn test_floating_points() { +fn test_floating_points() -> KResult<()> { let bytes = fs::read("../../src/floating_points.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = FloatingPoints::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = FloatingPoints::read_into(&_io, None, None)?; assert_eq!(*r.single_value(), (0.5 as f32)); assert_eq!(*r.single_value_be(), (0.5 as f32)); assert_eq!(*r.double_value(), 0.25); assert_eq!(*r.double_value_be(), 0.25); assert_eq!(*r.approximate_value(), 1.2345); - assert_eq!(*r.single_value_plus_int().expect("error reading"), 1.5); - assert_eq!(*r.single_value_plus_float().expect("error reading"), 1.0); - assert_eq!(*r.double_value_plus_float().expect("error reading"), 0.3); + assert_eq!(*r.single_value_plus_int()?, 1.5); + assert_eq!(*r.single_value_plus_float()?, 1.0); + assert_eq!(*r.double_value_plus_float()?, 0.3); + Ok(()) } diff --git a/spec/rust/tests/test_hello_world.rs b/spec/rust/tests/test_hello_world.rs index 45d836956..ec15fad1a 100644 --- a/spec/rust/tests/test_hello_world.rs +++ b/spec/rust/tests/test_hello_world.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::hello_world::*; #[test] -fn test_hello_world() { +fn test_hello_world() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = HelloWorld::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = HelloWorld::read_into(&_io, None, None)?; assert_eq!(*r.one(), 80); + Ok(()) } diff --git a/spec/rust/tests/test_if_instances.rs b/spec/rust/tests/test_if_instances.rs index ad5ff4228..8ae2ef7c0 100644 --- a/spec/rust/tests/test_if_instances.rs +++ b/spec/rust/tests/test_if_instances.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::if_instances::*; #[test] -fn test_if_instances() { +fn test_if_instances() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IfInstances::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = IfInstances::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.never_happens().expect("error reading"), 0); + assert!(r.never_happens()?.is_none()); + Ok(()) } diff --git a/spec/rust/tests/test_if_struct.rs b/spec/rust/tests/test_if_struct.rs index 613b5a40f..70ee30a44 100644 --- a/spec/rust/tests/test_if_struct.rs +++ b/spec/rust/tests/test_if_struct.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::if_struct::*; #[test] -fn test_if_struct() { +fn test_if_struct() -> KResult<()> { let bytes = fs::read("../../src/if_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IfStruct::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IfStruct::read_into(&_io, None, None)?; assert_eq!(*r.op1().opcode(), 83); assert_eq!(*r.op1().arg_str().str(), "foo"); @@ -28,4 +18,5 @@ fn test_if_struct() { assert_eq!(*r.op2().arg_tuple().num2(), 67); assert_eq!(*r.op3().opcode(), 83); assert_eq!(*r.op3().arg_str().str(), "bar"); + Ok(()) } diff --git a/spec/rust/tests/test_if_values.rs b/spec/rust/tests/test_if_values.rs index 672a83f8e..3699e8766 100644 --- a/spec/rust/tests/test_if_values.rs +++ b/spec/rust/tests/test_if_values.rs @@ -1,30 +1,21 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::if_values::*; #[test] -fn test_if_values() { +fn test_if_values() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IfValues::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IfValues::read_into(&_io, None, None)?; assert_eq!(*r.codes()[0 as usize].opcode(), 80); - assert_eq!(*r.codes()[0 as usize].half_opcode().expect("error reading"), 40); + assert_eq!(*r.codes()[0 as usize].half_opcode()?, 40); assert_eq!(*r.codes()[1 as usize].opcode(), 65); - assert_eq!(*r.codes()[1 as usize].half_opcode().expect("error reading"), 0); + assert!(r.codes()[1 as usize].half_opcode()?.is_none()); assert_eq!(*r.codes()[2 as usize].opcode(), 67); - assert_eq!(*r.codes()[2 as usize].half_opcode().expect("error reading"), 0); + assert!(r.codes()[2 as usize].half_opcode()?.is_none()); + Ok(()) } diff --git a/spec/rust/tests/test_imports0.rs b/spec/rust/tests/test_imports0.rs index 4540d040b..10d92c7b2 100644 --- a/spec/rust/tests/test_imports0.rs +++ b/spec/rust/tests/test_imports0.rs @@ -1,28 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::imports0::*; -use rust::formats::hello_world::*; #[test] -fn test_imports0() { +fn test_imports0() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Imports0::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Imports0::read_into(&_io, None, None)?; assert_eq!(*r.two(), 80); assert_eq!(*r.hw().one(), 65); - assert_eq!(*r.hw_one().expect("error reading"), 65); + assert_eq!(*r.hw_one()?, 65); + Ok(()) } diff --git a/spec/rust/tests/test_imports_abs.rs b/spec/rust/tests/test_imports_abs.rs index 61c075533..e12130fe2 100644 --- a/spec/rust/tests/test_imports_abs.rs +++ b/spec/rust/tests/test_imports_abs.rs @@ -1,27 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::imports_abs::*; -use rust::formats::vlq_base128_le::*; #[test] -fn test_imports_abs() { +fn test_imports_abs() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ImportsAbs::read_into(&_io, None, None); - let r: OptRc; + let r: OptRc = ImportsAbs::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.len().value().expect("error reading"), 80); + assert_eq!(*r.len().value()?, 80); assert_eq!(r.body().len(), 80); + Ok(()) } diff --git a/spec/rust/tests/test_imports_abs_abs.rs b/spec/rust/tests/test_imports_abs_abs.rs index ed6d90692..55edac7d7 100644 --- a/spec/rust/tests/test_imports_abs_abs.rs +++ b/spec/rust/tests/test_imports_abs_abs.rs @@ -1,23 +1,18 @@ -use std::fs; +// Autogenerated from KST: please remove this line if doing any edits by hand! +use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::imports_abs_abs::*; #[test] -fn test_params_def() { +fn test_imports_abs_abs() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = ImportsAbsAbs::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ImportsAbsAbs::read_into(&_io, None, None)?; assert_eq!(*r.one(), 80); assert_eq!(*r.two().one(), 65); assert_eq!(*r.two().two().one(), 67); + Ok(()) } diff --git a/spec/rust/tests/test_imports_abs_rel.rs b/spec/rust/tests/test_imports_abs_rel.rs index 16b48c175..629f9b6e1 100644 --- a/spec/rust/tests/test_imports_abs_rel.rs +++ b/spec/rust/tests/test_imports_abs_rel.rs @@ -1,23 +1,18 @@ -use std::fs; +// Autogenerated from KST: please remove this line if doing any edits by hand! +use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::imports_abs_rel::*; #[test] -fn test_imports_abs_rel() { +fn test_imports_abs_rel() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = ImportsAbsRel::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ImportsAbsRel::read_into(&_io, None, None)?; assert_eq!(*r.one(), 80); assert_eq!(*r.two().one(), 65); assert_eq!(*r.two().two().one(), 67); + Ok(()) } diff --git a/spec/rust/tests/test_imports_circular_a.rs b/spec/rust/tests/test_imports_circular_a.rs index 63df1a334..35cb096fd 100644 --- a/spec/rust/tests/test_imports_circular_a.rs +++ b/spec/rust/tests/test_imports_circular_a.rs @@ -1,28 +1,20 @@ -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::imports_circular_a::*; -use rust::formats::imports_circular_b::*; #[test] -fn test_imports_circular_a() { +fn test_imports_circular_a() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ImportsCircularA::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ImportsCircularA::read_into(&_io, None, None)?; assert_eq!(*r.code(), 80); assert_eq!(*r.two().initial(), 65); assert_eq!(*r.two().back_ref().code(), 67); assert_eq!(*r.two().back_ref().two().initial(), 75); - assert_eq!(r.two().back_ref().two().back_ref().is_none(), true); + assert!(r.two().back_ref().two().back_ref().is_none()); + Ok(()) } diff --git a/spec/rust/tests/test_imports_rel_1.rs b/spec/rust/tests/test_imports_rel_1.rs index d62d7ca66..0f9cea606 100644 --- a/spec/rust/tests/test_imports_rel_1.rs +++ b/spec/rust/tests/test_imports_rel_1.rs @@ -1,29 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::imports_rel_1::*; -use rust::formats::imported_1::*; -use rust::formats::imported_2::*; #[test] -fn test_imports_rel_1() { +fn test_imports_rel_1() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ImportsRel1::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ImportsRel1::read_into(&_io, None, None)?; assert_eq!(*r.one(), 80); assert_eq!(*r.two().one(), 65); assert_eq!(*r.two().two().one(), 67); + Ok(()) } diff --git a/spec/rust/tests/test_index_sizes.rs b/spec/rust/tests/test_index_sizes.rs index acfad6f1c..e73f6b981 100644 --- a/spec/rust/tests/test_index_sizes.rs +++ b/spec/rust/tests/test_index_sizes.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::index_sizes::*; #[test] -fn test_index_sizes() { +fn test_index_sizes() -> KResult<()> { let bytes = fs::read("../../src/index_sizes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IndexSizes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IndexSizes::read_into(&_io, None, None)?; assert_eq!(*r.qty(), 3); assert_eq!(r.sizes()[0 as usize], 1); @@ -28,4 +18,5 @@ fn test_index_sizes() { assert_eq!(r.bufs()[0 as usize], "A"); assert_eq!(r.bufs()[1 as usize], "BBBBBBBB"); assert_eq!(r.bufs()[2 as usize], "CCCC"); + Ok(()) } diff --git a/spec/rust/tests/test_index_to_param_eos.rs b/spec/rust/tests/test_index_to_param_eos.rs index 425fd1453..bc1a2c978 100644 --- a/spec/rust/tests/test_index_to_param_eos.rs +++ b/spec/rust/tests/test_index_to_param_eos.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::index_to_param_eos::*; #[test] -fn test_index_to_param_eos() { +fn test_index_to_param_eos() -> KResult<()> { let bytes = fs::read("../../src/index_sizes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IndexToParamEos::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IndexToParamEos::read_into(&_io, None, None)?; assert_eq!(*r.qty(), 3); assert_eq!(r.sizes()[0 as usize], 1); @@ -28,4 +18,5 @@ fn test_index_to_param_eos() { assert_eq!(*r.blocks()[0 as usize].buf(), "A"); assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB"); assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC"); + Ok(()) } diff --git a/spec/rust/tests/test_index_to_param_expr.rs b/spec/rust/tests/test_index_to_param_expr.rs index 33148c8f1..f39add36d 100644 --- a/spec/rust/tests/test_index_to_param_expr.rs +++ b/spec/rust/tests/test_index_to_param_expr.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::index_to_param_expr::*; #[test] -fn test_index_to_param_expr() { +fn test_index_to_param_expr() -> KResult<()> { let bytes = fs::read("../../src/index_sizes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IndexToParamExpr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IndexToParamExpr::read_into(&_io, None, None)?; assert_eq!(*r.qty(), 3); assert_eq!(r.sizes()[0 as usize], 1); @@ -28,4 +18,5 @@ fn test_index_to_param_expr() { assert_eq!(*r.blocks()[0 as usize].buf(), "A"); assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB"); assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC"); + Ok(()) } diff --git a/spec/rust/tests/test_index_to_param_until.rs b/spec/rust/tests/test_index_to_param_until.rs index 86ceac65e..9378ab36a 100644 --- a/spec/rust/tests/test_index_to_param_until.rs +++ b/spec/rust/tests/test_index_to_param_until.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::index_to_param_until::*; #[test] -fn test_index_to_param_until() { +fn test_index_to_param_until() -> KResult<()> { let bytes = fs::read("../../src/index_sizes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IndexToParamUntil::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IndexToParamUntil::read_into(&_io, None, None)?; assert_eq!(*r.qty(), 3); assert_eq!(r.sizes()[0 as usize], 1); @@ -28,4 +18,5 @@ fn test_index_to_param_until() { assert_eq!(*r.blocks()[0 as usize].buf(), "A"); assert_eq!(*r.blocks()[1 as usize].buf(), "BBBBBBBB"); assert_eq!(*r.blocks()[2 as usize].buf(), "CCCC"); + Ok(()) } diff --git a/spec/rust/tests/test_instance_io_user.rs b/spec/rust/tests/test_instance_io_user.rs index c2df78bdb..05c8e0b06 100644 --- a/spec/rust/tests/test_instance_io_user.rs +++ b/spec/rust/tests/test_instance_io_user.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::instance_io_user::*; #[test] -fn test_instance_io_user() { +fn test_instance_io_user() -> KResult<()> { let bytes = fs::read("../../src/instance_io.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = InstanceIoUser::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = InstanceIoUser::read_into(&_io, None, None)?; assert_eq!(*r.qty_entries(), 3); - assert_eq!(*r.entries()[0 as usize].name().expect("error reading"), "the"); - assert_eq!(*r.entries()[1 as usize].name().expect("error reading"), "rainy"); - assert_eq!(*r.entries()[2 as usize].name().expect("error reading"), "day it is"); + assert_eq!(*r.entries()[0 as usize].name()?, "the"); + assert_eq!(*r.entries()[1 as usize].name()?, "rainy"); + assert_eq!(*r.entries()[2 as usize].name()?, "day it is"); + Ok(()) } diff --git a/spec/rust/tests/test_instance_std.rs b/spec/rust/tests/test_instance_std.rs index 497087a88..a67938100 100644 --- a/spec/rust/tests/test_instance_std.rs +++ b/spec/rust/tests/test_instance_std.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::instance_std::*; #[test] -fn test_instance_std() { +fn test_instance_std() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = InstanceStd::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = InstanceStd::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.header().expect("error reading"), "Some "); + assert_eq!(*r.header()?, "Some "); + Ok(()) } diff --git a/spec/rust/tests/test_instance_std_array.rs b/spec/rust/tests/test_instance_std_array.rs index 2389cf179..257564064 100644 --- a/spec/rust/tests/test_instance_std_array.rs +++ b/spec/rust/tests/test_instance_std_array.rs @@ -1,31 +1,22 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::instance_std_array::*; #[test] -fn test_instance_std_array() { +fn test_instance_std_array() -> KResult<()> { let bytes = fs::read("../../src/instance_std_array.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = InstanceStdArray::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = InstanceStdArray::read_into(&_io, None, None)?; assert_eq!(*r.ofs(), 16); assert_eq!(*r.qty_entries(), 3); assert_eq!(*r.entry_size(), 4); - assert_eq!(r.entries().expect("error reading").len(), 3); - assert_eq!(r.entries().expect("error reading")[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); - assert_eq!(r.entries().expect("error reading")[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); - assert_eq!(r.entries().expect("error reading")[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); + assert_eq!(r.entries()?.len(), 3); + assert_eq!(r.entries()?[0 as usize], vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); + assert_eq!(r.entries()?[1 as usize], vec![0x22u8, 0x22u8, 0x22u8, 0x22u8]); + assert_eq!(r.entries()?[2 as usize], vec![0x33u8, 0x33u8, 0x33u8, 0x33u8]); + Ok(()) } diff --git a/spec/rust/tests/test_instance_user_array.rs b/spec/rust/tests/test_instance_user_array.rs index 63f789250..473e86eb8 100644 --- a/spec/rust/tests/test_instance_user_array.rs +++ b/spec/rust/tests/test_instance_user_array.rs @@ -1,34 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::instance_user_array::*; #[test] -fn test_instance_user_array() { +fn test_instance_user_array() -> KResult<()> { let bytes = fs::read("../../src/instance_std_array.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = InstanceUserArray::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = InstanceUserArray::read_into(&_io, None, None)?; assert_eq!(*r.ofs(), 16); assert_eq!(*r.qty_entries(), 3); assert_eq!(*r.entry_size(), 4); - assert_eq!(r.user_entries().expect("error reading").len(), 3); - assert_eq!(*r.user_entries().expect("error reading")[0 as usize].word1(), 4369); - assert_eq!(*r.user_entries().expect("error reading")[0 as usize].word2(), 4369); - assert_eq!(*r.user_entries().expect("error reading")[1 as usize].word1(), 8738); - assert_eq!(*r.user_entries().expect("error reading")[1 as usize].word2(), 8738); - assert_eq!(*r.user_entries().expect("error reading")[2 as usize].word1(), 13107); - assert_eq!(*r.user_entries().expect("error reading")[2 as usize].word2(), 13107); + assert_eq!(r.user_entries()?.len(), 3); + assert_eq!(*r.user_entries()?[0 as usize].word1(), 4369); + assert_eq!(*r.user_entries()?[0 as usize].word2(), 4369); + assert_eq!(*r.user_entries()?[1 as usize].word1(), 8738); + assert_eq!(*r.user_entries()?[1 as usize].word2(), 8738); + assert_eq!(*r.user_entries()?[2 as usize].word1(), 13107); + assert_eq!(*r.user_entries()?[2 as usize].word2(), 13107); + Ok(()) } diff --git a/spec/rust/tests/test_integers.rs b/spec/rust/tests/test_integers.rs index 1a99eee95..f69bd3511 100644 --- a/spec/rust/tests/test_integers.rs +++ b/spec/rust/tests/test_integers.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::integers::*; #[test] -fn test_integers() { +fn test_integers() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = Integers::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = Integers::read_into(&_io, None, None)?; assert_eq!(*r.uint8(), 255); assert_eq!(*r.uint16(), 65535); @@ -41,4 +31,5 @@ fn test_integers() { assert_eq!(*r.sint16be(), -66); assert_eq!(*r.sint32be(), -66); assert_eq!(*r.sint64be(), -66); + Ok(()) } diff --git a/spec/rust/tests/test_integers_double_overflow.rs b/spec/rust/tests/test_integers_double_overflow.rs index bcca77203..d5b002df1 100644 --- a/spec/rust/tests/test_integers_double_overflow.rs +++ b/spec/rust/tests/test_integers_double_overflow.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::integers_double_overflow::*; #[test] -fn test_integers_double_overflow() { +fn test_integers_double_overflow() -> KResult<()> { let bytes = fs::read("../../src/integers_double_overflow.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IntegersDoubleOverflow::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IntegersDoubleOverflow::read_into(&_io, None, None)?; assert_eq!(*r.signed_safe_min_be(), -9007199254740991); assert_eq!(*r.signed_safe_min_le(), -9007199254740991); @@ -29,4 +19,5 @@ fn test_integers_double_overflow() { assert_eq!(r.signed_unsafe_neg_le().to_string(), "-9007199254740993"); assert_eq!(r.signed_unsafe_pos_be().to_string(), "9007199254740993"); assert_eq!(r.signed_unsafe_pos_be().to_string(), "9007199254740993"); + Ok(()) } diff --git a/spec/rust/tests/test_integers_min_max.rs b/spec/rust/tests/test_integers_min_max.rs index cd2549d04..cf82dca25 100644 --- a/spec/rust/tests/test_integers_min_max.rs +++ b/spec/rust/tests/test_integers_min_max.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::integers_min_max::*; #[test] -fn test_integers_min_max() { +fn test_integers_min_max() -> KResult<()> { let bytes = fs::read("../../src/integers_min_max.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IntegersMinMax::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IntegersMinMax::read_into(&_io, None, None)?; assert_eq!(*r.unsigned_min().u1(), 0); assert_eq!(*r.unsigned_min().u2le(), 0); @@ -49,4 +39,5 @@ fn test_integers_min_max() { assert_eq!(*r.signed_max().s2be(), 32767); assert_eq!(*r.signed_max().s4be(), 2147483647); assert_eq!(*r.signed_max().s8be(), 9223372036854775807); + Ok(()) } diff --git a/spec/rust/tests/test_io_local_var.rs b/spec/rust/tests/test_io_local_var.rs index 92ba49634..ec7d3bda9 100644 --- a/spec/rust/tests/test_io_local_var.rs +++ b/spec/rust/tests/test_io_local_var.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::io_local_var::*; #[test] -fn test_io_local_var() { +fn test_io_local_var() -> KResult<()> { let bytes = fs::read("../../src/full256.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = IoLocalVar::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = IoLocalVar::read_into(&_io, None, None)?; assert_eq!(*r.skip(), vec![0x0u8, 0x1u8, 0x2u8, 0x3u8, 0x4u8, 0x5u8, 0x6u8, 0x7u8, 0x8u8, 0x9u8, 0xau8, 0xbu8, 0xcu8, 0xdu8, 0xeu8, 0xfu8, 0x10u8, 0x11u8, 0x12u8, 0x13u8]); assert_eq!(*r.followup(), 20); + Ok(()) } diff --git a/spec/rust/tests/test_js_signed_right_shift.rs b/spec/rust/tests/test_js_signed_right_shift.rs index 5e88306da..6afb2fac5 100644 --- a/spec/rust/tests/test_js_signed_right_shift.rs +++ b/spec/rust/tests/test_js_signed_right_shift.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::js_signed_right_shift::*; #[test] -fn test_js_signed_right_shift() { +fn test_js_signed_right_shift() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = JsSignedRightShift::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = JsSignedRightShift::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.should_be_40000000().expect("error reading"), 1073741824); - assert_eq!(*r.should_be_a00000().expect("error reading"), 10485760); + assert_eq!(*r.should_be_40000000()?, 1073741824); + assert_eq!(*r.should_be_a00000()?, 10485760); + Ok(()) } diff --git a/spec/rust/tests/test_meta_tags.rs b/spec/rust/tests/test_meta_tags.rs index 56faed93d..f54ebf3a0 100644 --- a/spec/rust/tests/test_meta_tags.rs +++ b/spec/rust/tests/test_meta_tags.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::meta_tags::*; #[test] -fn test_meta_tags() { +fn test_meta_tags() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = MetaTags::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = MetaTags::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_meta_xref.rs b/spec/rust/tests/test_meta_xref.rs index ce314b75e..d5db58492 100644 --- a/spec/rust/tests/test_meta_xref.rs +++ b/spec/rust/tests/test_meta_xref.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::meta_xref::*; #[test] -fn test_meta_xref() { +fn test_meta_xref() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = MetaXref::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = MetaXref::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_multiple_use.rs b/spec/rust/tests/test_multiple_use.rs index 99ba7a8cc..59749afe0 100644 --- a/spec/rust/tests/test_multiple_use.rs +++ b/spec/rust/tests/test_multiple_use.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::multiple_use::*; #[test] -fn test_multiple_use() { +fn test_multiple_use() -> KResult<()> { let bytes = fs::read("../../src/position_abs.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = MultipleUse::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = MultipleUse::read_into(&_io, None, None)?; assert_eq!(*r.t1().first_use().value(), 32); - assert_eq!(*r.t2().second_use().expect("error reading").value(), 32); + assert_eq!(*r.t2().second_use()?.value(), 32); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent.rs b/spec/rust/tests/test_nav_parent.rs index 37fbad468..be20edd72 100644 --- a/spec/rust/tests/test_nav_parent.rs +++ b/spec/rust/tests/test_nav_parent.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent::*; #[test] -fn test_nav_parent() { +fn test_nav_parent() -> KResult<()> { let bytes = fs::read("../../src/nav.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParent::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParent::read_into(&_io, None, None)?; assert_eq!(*r.header().qty_entries(), 2); assert_eq!(*r.header().filename_len(), 8); assert_eq!(r.index().entries().len(), 2); assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent2.rs b/spec/rust/tests/test_nav_parent2.rs index f1b0f4612..777048c05 100644 --- a/spec/rust/tests/test_nav_parent2.rs +++ b/spec/rust/tests/test_nav_parent2.rs @@ -1,34 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent2::*; #[test] -fn test_nav_parent2() { +fn test_nav_parent2() -> KResult<()> { let bytes = fs::read("../../src/nav_parent2.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParent2::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParent2::read_into(&_io, None, None)?; assert_eq!(*r.ofs_tags(), 8); assert_eq!(*r.num_tags(), 2); assert_eq!(*r.tags()[0 as usize].name(), "RAHC"); assert_eq!(*r.tags()[0 as usize].ofs(), 32); assert_eq!(*r.tags()[0 as usize].num_items(), 3); - assert_eq!(*r.tags()[0 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "foo"); + assert_eq!(*r.tags()[0 as usize].tag_content()?.as_ref().unwrap().content(), "foo"); assert_eq!(*r.tags()[1 as usize].name(), "RAHC"); assert_eq!(*r.tags()[1 as usize].ofs(), 35); assert_eq!(*r.tags()[1 as usize].num_items(), 6); - assert_eq!(*r.tags()[1 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "barbaz"); + assert_eq!(*r.tags()[1 as usize].tag_content()?.as_ref().unwrap().content(), "barbaz"); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent3.rs b/spec/rust/tests/test_nav_parent3.rs index 4bd165de2..c36906289 100644 --- a/spec/rust/tests/test_nav_parent3.rs +++ b/spec/rust/tests/test_nav_parent3.rs @@ -1,34 +1,25 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent3::*; #[test] -fn test_nav_parent3() { +fn test_nav_parent3() -> KResult<()> { let bytes = fs::read("../../src/nav_parent2.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParent3::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParent3::read_into(&_io, None, None)?; assert_eq!(*r.ofs_tags(), 8); assert_eq!(*r.num_tags(), 2); - assert_eq!(*r.tags().expect("error reading")[0 as usize].name(), "RAHC"); - assert_eq!(*r.tags().expect("error reading")[0 as usize].ofs(), 32); - assert_eq!(*r.tags().expect("error reading")[0 as usize].num_items(), 3); - assert_eq!(*r.tags().expect("error reading")[0 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "foo"); - assert_eq!(*r.tags().expect("error reading")[1 as usize].name(), "RAHC"); - assert_eq!(*r.tags().expect("error reading")[1 as usize].ofs(), 35); - assert_eq!(*r.tags().expect("error reading")[1 as usize].num_items(), 6); - assert_eq!(*r.tags().expect("error reading")[1 as usize].tag_content().expect("error reading").as_ref().unwrap().content(), "barbaz"); + assert_eq!(*r.tags()?[0 as usize].name(), "RAHC"); + assert_eq!(*r.tags()?[0 as usize].ofs(), 32); + assert_eq!(*r.tags()?[0 as usize].num_items(), 3); + assert_eq!(*r.tags()?[0 as usize].tag_content()?.as_ref().unwrap().content(), "foo"); + assert_eq!(*r.tags()?[1 as usize].name(), "RAHC"); + assert_eq!(*r.tags()?[1 as usize].ofs(), 35); + assert_eq!(*r.tags()?[1 as usize].num_items(), 6); + assert_eq!(*r.tags()?[1 as usize].tag_content()?.as_ref().unwrap().content(), "barbaz"); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent_false.rs b/spec/rust/tests/test_nav_parent_false.rs index f97644f8b..c0b2add72 100644 --- a/spec/rust/tests/test_nav_parent_false.rs +++ b/spec/rust/tests/test_nav_parent_false.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent_false::*; #[test] -fn test_nav_parent_false() { +fn test_nav_parent_false() -> KResult<()> { let bytes = fs::read("../../src/nav_parent_codes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParentFalse::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParentFalse::read_into(&_io, None, None)?; assert_eq!(*r.child_size(), 3); assert_eq!(*r.element_a().foo().code(), 73); assert_eq!(*r.element_a().foo().more(), vec![0x31u8, 0x32u8, 0x33u8]); assert_eq!(*r.element_a().bar().foo().code(), 66); assert_eq!(*r.element_b().foo().code(), 98); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent_false2.rs b/spec/rust/tests/test_nav_parent_false2.rs index c80954022..fd0ea572e 100644 --- a/spec/rust/tests/test_nav_parent_false2.rs +++ b/spec/rust/tests/test_nav_parent_false2.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent_false2::*; #[test] -fn test_nav_parent_false2() { +fn test_nav_parent_false2() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParentFalse2::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParentFalse2::read_into(&_io, None, None)?; assert_eq!(*r.parentless().foo(), 80); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent_override.rs b/spec/rust/tests/test_nav_parent_override.rs index 7777e4269..d1fb3f40e 100644 --- a/spec/rust/tests/test_nav_parent_override.rs +++ b/spec/rust/tests/test_nav_parent_override.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent_override::*; #[test] -fn test_nav_parent_override() { +fn test_nav_parent_override() -> KResult<()> { let bytes = fs::read("../../src/nav_parent_codes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParentOverride::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParentOverride::read_into(&_io, None, None)?; assert_eq!(*r.child_size(), 3); assert_eq!(*r.child_1().data(), vec![0x49u8, 0x31u8, 0x32u8]); assert_eq!(*r.mediator_2().child_2().data(), vec![0x33u8, 0x42u8, 0x62u8]); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent_switch.rs b/spec/rust/tests/test_nav_parent_switch.rs index 572494665..c57225c12 100644 --- a/spec/rust/tests/test_nav_parent_switch.rs +++ b/spec/rust/tests/test_nav_parent_switch.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent_switch::*; #[test] -fn test_nav_parent_switch() { +fn test_nav_parent_switch() -> KResult<()> { let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParentSwitch::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParentSwitch::read_into(&_io, None, None)?; assert_eq!(*r.category(), 1); assert_eq!(*Into::>::into(&*r.content().as_ref().unwrap()).foo(), 66); assert_eq!(*Into::>::into(&*r.content().as_ref().unwrap()).subelement().bar(), 255); + Ok(()) } diff --git a/spec/rust/tests/test_nav_parent_vs_value_inst.rs b/spec/rust/tests/test_nav_parent_vs_value_inst.rs index f598d5a93..7c91d176b 100644 --- a/spec/rust/tests/test_nav_parent_vs_value_inst.rs +++ b/spec/rust/tests/test_nav_parent_vs_value_inst.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_parent_vs_value_inst::*; #[test] -fn test_nav_parent_vs_value_inst() { +fn test_nav_parent_vs_value_inst() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavParentVsValueInst::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavParentVsValueInst::read_into(&_io, None, None)?; assert_eq!(*r.s1(), "foo"); + Ok(()) } diff --git a/spec/rust/tests/test_nav_root.rs b/spec/rust/tests/test_nav_root.rs index 2b3ecd8ea..8f91dfea4 100644 --- a/spec/rust/tests/test_nav_root.rs +++ b/spec/rust/tests/test_nav_root.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nav_root::*; #[test] -fn test_nav_root() { +fn test_nav_root() -> KResult<()> { let bytes = fs::read("../../src/nav.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NavRoot::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NavRoot::read_into(&_io, None, None)?; assert_eq!(*r.header().qty_entries(), 2); assert_eq!(*r.header().filename_len(), 8); assert_eq!(r.index().entries().len(), 2); assert_eq!(*r.index().entries()[0 as usize].filename(), "FIRST___"); assert_eq!(*r.index().entries()[1 as usize].filename(), "SECOND__"); + Ok(()) } diff --git a/spec/rust/tests/test_nested_same_name.rs b/spec/rust/tests/test_nested_same_name.rs index af758c3ee..41b48f77d 100644 --- a/spec/rust/tests/test_nested_same_name.rs +++ b/spec/rust/tests/test_nested_same_name.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nested_same_name::*; #[test] -fn test_nested_same_name() { +fn test_nested_same_name() -> KResult<()> { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NestedSameName::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NestedSameName::read_into(&_io, None, None)?; assert_eq!(*r.main_data().main_size(), 2); assert_eq!(*r.main_data().foo().data(), vec![0x10u8, 0x0u8, 0x0u8, 0x0u8]); + Ok(()) } diff --git a/spec/rust/tests/test_nested_same_name2.rs b/spec/rust/tests/test_nested_same_name2.rs index cfb684d86..28138b012 100644 --- a/spec/rust/tests/test_nested_same_name2.rs +++ b/spec/rust/tests/test_nested_same_name2.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nested_same_name2::*; #[test] -fn test_nested_same_name2() { +fn test_nested_same_name2() -> KResult<()> { let bytes = fs::read("../../src/nested_same_name2.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NestedSameName2::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NestedSameName2::read_into(&_io, None, None)?; assert_eq!(*r.version(), 66); assert_eq!(*r.main_data().main_size(), 2); assert_eq!(*r.main_data().foo().data1(), vec![0x11u8, 0x11u8, 0x11u8, 0x11u8]); assert_eq!(*r.dummy().dummy_size(), 3); assert_eq!(*r.dummy().foo().data2(), vec![0x22u8, 0x22u8, 0x22u8, 0x22u8, 0x22u8, 0x22u8]); + Ok(()) } diff --git a/spec/rust/tests/test_nested_type_param.rs b/spec/rust/tests/test_nested_type_param.rs index 4a8934aae..46bea7a44 100644 --- a/spec/rust/tests/test_nested_type_param.rs +++ b/spec/rust/tests/test_nested_type_param.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nested_type_param::*; #[test] -fn test_nested_type_param() { +fn test_nested_type_param() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NestedTypeParam::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NestedTypeParam::read_into(&_io, None, None)?; assert_eq!(*r.main_seq().my_len(), 5); assert_eq!(*r.main_seq().body(), "foo|b"); + Ok(()) } diff --git a/spec/rust/tests/test_nested_types.rs b/spec/rust/tests/test_nested_types.rs index 30e716be8..f86801e7f 100644 --- a/spec/rust/tests/test_nested_types.rs +++ b/spec/rust/tests/test_nested_types.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nested_types::*; #[test] -fn test_nested_types() { +fn test_nested_types() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NestedTypes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NestedTypes::read_into(&_io, None, None)?; assert_eq!(*r.one().typed_at_root().value_b(), 80); assert_eq!(*r.one().typed_here().value_c(), 65); assert_eq!(*r.two().value_b(), 67); + Ok(()) } diff --git a/spec/rust/tests/test_nested_types2.rs b/spec/rust/tests/test_nested_types2.rs index b7ac1b456..a0040cc84 100644 --- a/spec/rust/tests/test_nested_types2.rs +++ b/spec/rust/tests/test_nested_types2.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nested_types2::*; #[test] -fn test_nested_types2() { +fn test_nested_types2() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NestedTypes2::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NestedTypes2::read_into(&_io, None, None)?; assert_eq!(*r.one().typed_at_root().value_b(), 80); assert_eq!(*r.one().typed_here1().value_c(), 65); @@ -28,4 +18,5 @@ fn test_nested_types2() { assert_eq!(*r.one().typed_here1().typed_root().value_b(), 45); assert_eq!(*r.one().typed_here2().value_cc(), 49); assert_eq!(*r.two().value_b(), -1); + Ok(()) } diff --git a/spec/rust/tests/test_nested_types3.rs b/spec/rust/tests/test_nested_types3.rs index 41d6f6139..3748a20f6 100644 --- a/spec/rust/tests/test_nested_types3.rs +++ b/spec/rust/tests/test_nested_types3.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::nested_types3::*; #[test] -fn test_nested_types3() { +fn test_nested_types3() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NestedTypes3::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NestedTypes3::read_into(&_io, None, None)?; assert_eq!(*r.a_cc().value_cc(), 80); assert_eq!(*r.a_c_d().value_d(), 65); assert_eq!(*r.b().value_b(), 67); assert_eq!(*r.b().a_cc().value_cc(), 75); assert_eq!(*r.b().a_c_d().value_d(), 45); + Ok(()) } diff --git a/spec/rust/tests/test_non_standard.rs b/spec/rust/tests/test_non_standard.rs index 3eb325303..d12978c07 100644 --- a/spec/rust/tests/test_non_standard.rs +++ b/spec/rust/tests/test_non_standard.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::non_standard::*; #[test] -fn test_non_standard() { +fn test_non_standard() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = NonStandard::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = NonStandard::read_into(&_io, None, None)?; assert_eq!(*r.foo(), 80); + Ok(()) } diff --git a/spec/rust/tests/test_params_call_extra_parens.rs b/spec/rust/tests/test_params_call_extra_parens.rs index 9d526d666..1d3da910e 100644 --- a/spec/rust/tests/test_params_call_extra_parens.rs +++ b/spec/rust/tests/test_params_call_extra_parens.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::params_call_extra_parens::*; #[test] -fn test_params_call_extra_parens() { +fn test_params_call_extra_parens() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ParamsCallExtraParens::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsCallExtraParens::read_into(&_io, None, None)?; assert_eq!(*r.buf1().body(), "foo|b"); + Ok(()) } diff --git a/spec/rust/tests/test_params_enum.rs b/spec/rust/tests/test_params_enum.rs index 24750dc1c..b5a0ff4f8 100644 --- a/spec/rust/tests/test_params_enum.rs +++ b/spec/rust/tests/test_params_enum.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::params_enum::*; #[test] -fn test_params_enum() { +fn test_params_enum() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ParamsEnum::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsEnum::read_into(&_io, None, None)?; assert_eq!(*r.one(), ParamsEnum_Animal::Cat); - assert_eq!(*r.invoke_with_param().is_cat().expect("error reading"), true); + assert_eq!(*r.invoke_with_param().is_cat()?, true); + Ok(()) } diff --git a/spec/rust/tests/test_params_pass_array_int.rs b/spec/rust/tests/test_params_pass_array_int.rs index 7808e6ee2..235d20d26 100644 --- a/spec/rust/tests/test_params_pass_array_int.rs +++ b/spec/rust/tests/test_params_pass_array_int.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::params_pass_array_int::*; #[test] -fn test_params_pass_array_int() { +fn test_params_pass_array_int() -> KResult<()> { let bytes = fs::read("../../src/position_to_end.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ParamsPassArrayInt::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsPassArrayInt::read_into(&_io, None, None)?; assert_eq!(r.pass_ints().nums().len(), 3); assert_eq!(r.pass_ints().nums()[0 as usize], 513); @@ -28,4 +18,5 @@ fn test_params_pass_array_int() { assert_eq!(r.pass_ints_calc().nums().len(), 2); assert_eq!(r.pass_ints_calc().nums()[0 as usize], 27643); assert_eq!(r.pass_ints_calc().nums()[1 as usize], 7); + Ok(()) } diff --git a/spec/rust/tests/test_params_pass_array_str.rs b/spec/rust/tests/test_params_pass_array_str.rs index 679d2e7e0..fbd85cfe1 100644 --- a/spec/rust/tests/test_params_pass_array_str.rs +++ b/spec/rust/tests/test_params_pass_array_str.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::params_pass_array_str::*; #[test] -fn test_params_pass_array_str() { +fn test_params_pass_array_str() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ParamsPassArrayStr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsPassArrayStr::read_into(&_io, None, None)?; assert_eq!(r.pass_str_array().strs().len(), 3); assert_eq!(r.pass_str_array().strs()[0 as usize], "fo"); @@ -28,4 +18,5 @@ fn test_params_pass_array_str() { assert_eq!(r.pass_str_array_calc().strs().len(), 2); assert_eq!(r.pass_str_array_calc().strs()[0 as usize], "aB"); assert_eq!(r.pass_str_array_calc().strs()[1 as usize], "Cd"); + Ok(()) } diff --git a/spec/rust/tests/test_params_pass_array_usertype.rs b/spec/rust/tests/test_params_pass_array_usertype.rs index 291a9ce05..414678896 100644 --- a/spec/rust/tests/test_params_pass_array_usertype.rs +++ b/spec/rust/tests/test_params_pass_array_usertype.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::params_pass_array_usertype::*; #[test] -fn test_params_pass_array_usertype() { +fn test_params_pass_array_usertype() -> KResult<()> { let bytes = fs::read("../../src/position_to_end.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ParamsPassArrayUsertype::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsPassArrayUsertype::read_into(&_io, None, None)?; assert_eq!(r.pass_blocks().bar().len(), 2); assert_eq!(*r.pass_blocks().bar()[0 as usize].foo(), 1); assert_eq!(*r.pass_blocks().bar()[1 as usize].foo(), 2); assert_eq!(*r.pass_blocks().one(), vec![0x3u8]); assert_eq!(*r.pass_blocks().two(), vec![0x4u8, 0x5u8]); + Ok(()) } diff --git a/spec/rust/tests/test_params_pass_bool.rs b/spec/rust/tests/test_params_pass_bool.rs index 5f0af8868..1169b496f 100644 --- a/spec/rust/tests/test_params_pass_bool.rs +++ b/spec/rust/tests/test_params_pass_bool.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::params_pass_bool::*; #[test] -fn test_params_pass_bool() { +fn test_params_pass_bool() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ParamsPassBool::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsPassBool::read_into(&_io, None, None)?; assert_eq!(*r.s_false(), false); assert_eq!(*r.s_true(), true); @@ -35,4 +25,5 @@ fn test_params_pass_bool() { assert_eq!(r.inst_b1().foo().len(), 1); assert_eq!(*r.inst_bool().arg(), false); assert_eq!(r.inst_bool().foo().len(), 2); + Ok(()) } diff --git a/spec/rust/tests/test_params_pass_usertype.rs b/spec/rust/tests/test_params_pass_usertype.rs index aa1d103af..e2952dee4 100644 --- a/spec/rust/tests/test_params_pass_usertype.rs +++ b/spec/rust/tests/test_params_pass_usertype.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::params_pass_usertype::*; #[test] -fn test_params_pass_usertype() { +fn test_params_pass_usertype() -> KResult<()> { let bytes = fs::read("../../src/position_in_seq.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ParamsPassUsertype::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsPassUsertype::read_into(&_io, None, None)?; assert_eq!(*r.first().foo(), 1); assert_eq!(*r.one().buf(), vec![0x2u8]); + Ok(()) } diff --git a/spec/rust/tests/test_position_abs.rs b/spec/rust/tests/test_position_abs.rs index 3e5d50cef..79fddf658 100644 --- a/spec/rust/tests/test_position_abs.rs +++ b/spec/rust/tests/test_position_abs.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::position_abs::*; #[test] -fn test_position_abs() { +fn test_position_abs() -> KResult<()> { let bytes = fs::read("../../src/position_abs.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = PositionAbs::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = PositionAbs::read_into(&_io, None, None)?; assert_eq!(*r.index_offset(), 32); - assert_eq!(*r.index().expect("error reading").entry(), "foo"); + assert_eq!(*r.index()?.entry(), "foo"); + Ok(()) } diff --git a/spec/rust/tests/test_position_in_seq.rs b/spec/rust/tests/test_position_in_seq.rs index ce26f15c7..1d6559197 100644 --- a/spec/rust/tests/test_position_in_seq.rs +++ b/spec/rust/tests/test_position_in_seq.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::position_in_seq::*; #[test] -fn test_position_in_seq() { +fn test_position_in_seq() -> KResult<()> { let bytes = fs::read("../../src/position_in_seq.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = PositionInSeq::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = PositionInSeq::read_into(&_io, None, None)?; assert_eq!(*r.numbers(), vec![(0 + 1), 2, 3]); + Ok(()) } diff --git a/spec/rust/tests/test_position_to_end.rs b/spec/rust/tests/test_position_to_end.rs index 6f31b5120..0f74aab5e 100644 --- a/spec/rust/tests/test_position_to_end.rs +++ b/spec/rust/tests/test_position_to_end.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::position_to_end::*; #[test] -fn test_position_to_end() { +fn test_position_to_end() -> KResult<()> { let bytes = fs::read("../../src/position_to_end.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = PositionToEnd::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = PositionToEnd::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.index().expect("error reading").foo(), 66); - assert_eq!(*r.index().expect("error reading").bar(), 4660); + assert_eq!(*r.index()?.foo(), 66); + assert_eq!(*r.index()?.bar(), 4660); + Ok(()) } diff --git a/spec/rust/tests/test_process_coerce_bytes.rs b/spec/rust/tests/test_process_coerce_bytes.rs index e7dbe6940..27fe0f0f1 100644 --- a/spec/rust/tests/test_process_coerce_bytes.rs +++ b/spec/rust/tests/test_process_coerce_bytes.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_coerce_bytes::*; #[test] -fn test_process_coerce_bytes() { +fn test_process_coerce_bytes() -> KResult<()> { let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessCoerceBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessCoerceBytes::read_into(&_io, None, None)?; assert_eq!(*r.records()[0 as usize].flag(), 0); - assert_eq!(*r.records()[0 as usize].buf().expect("error reading"), vec![0x41u8, 0x41u8, 0x41u8, 0x41u8]); + assert_eq!(*r.records()[0 as usize].buf()?, vec![0x41u8, 0x41u8, 0x41u8, 0x41u8]); assert_eq!(*r.records()[1 as usize].flag(), 1); - assert_eq!(*r.records()[1 as usize].buf().expect("error reading"), vec![0x42u8, 0x42u8, 0x42u8, 0x42u8]); + assert_eq!(*r.records()[1 as usize].buf()?, vec![0x42u8, 0x42u8, 0x42u8, 0x42u8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_coerce_usertype1.rs b/spec/rust/tests/test_process_coerce_usertype1.rs index ed5cf8f3b..bb5d0b057 100644 --- a/spec/rust/tests/test_process_coerce_usertype1.rs +++ b/spec/rust/tests/test_process_coerce_usertype1.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_coerce_usertype1::*; #[test] -fn test_process_coerce_usertype1() { +fn test_process_coerce_usertype1() -> KResult<()> { let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessCoerceUsertype1::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessCoerceUsertype1::read_into(&_io, None, None)?; assert_eq!(*r.records()[0 as usize].flag(), 0); - assert_eq!(*r.records()[0 as usize].buf().expect("error reading").value(), 1094795585); + assert_eq!(*r.records()[0 as usize].buf()?.value(), 1094795585); assert_eq!(*r.records()[1 as usize].flag(), 1); - assert_eq!(*r.records()[1 as usize].buf().expect("error reading").value(), 1111638594); + assert_eq!(*r.records()[1 as usize].buf()?.value(), 1111638594); + Ok(()) } diff --git a/spec/rust/tests/test_process_coerce_usertype2.rs b/spec/rust/tests/test_process_coerce_usertype2.rs index d1a06f0f5..e4472c066 100644 --- a/spec/rust/tests/test_process_coerce_usertype2.rs +++ b/spec/rust/tests/test_process_coerce_usertype2.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_coerce_usertype2::*; #[test] -fn test_process_coerce_usertype2() { +fn test_process_coerce_usertype2() -> KResult<()> { let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessCoerceUsertype2::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessCoerceUsertype2::read_into(&_io, None, None)?; assert_eq!(*r.records()[0 as usize].flag(), 0); - assert_eq!(*r.records()[0 as usize].buf().expect("error reading").value(), 1094795585); + assert_eq!(*r.records()[0 as usize].buf()?.value(), 1094795585); assert_eq!(*r.records()[1 as usize].flag(), 1); - assert_eq!(*r.records()[1 as usize].buf().expect("error reading").value(), 1111638594); + assert_eq!(*r.records()[1 as usize].buf()?.value(), 1111638594); + Ok(()) } diff --git a/spec/rust/tests/test_process_custom.rs b/spec/rust/tests/test_process_custom.rs index f72332f77..c8779af13 100644 --- a/spec/rust/tests/test_process_custom.rs +++ b/spec/rust/tests/test_process_custom.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_custom::*; #[test] -fn test_process_custom() { +fn test_process_custom() -> KResult<()> { let bytes = fs::read("../../src/process_rotate.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessCustom::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessCustom::read_into(&_io, None, None)?; assert_eq!(*r.buf1(), vec![0x10u8, 0xb3u8, 0x94u8, 0x94u8, 0xf4u8]); assert_eq!(*r.buf2(), vec![0x5fu8, 0xbau8, 0x7bu8, 0x93u8, 0x63u8, 0x23u8, 0x5fu8]); assert_eq!(*r.buf3(), vec![0x29u8, 0x33u8, 0xb1u8, 0x38u8, 0xb1u8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_custom_no_args.rs b/spec/rust/tests/test_process_custom_no_args.rs index 07e3a4dec..1a07ec3c1 100644 --- a/spec/rust/tests/test_process_custom_no_args.rs +++ b/spec/rust/tests/test_process_custom_no_args.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_custom_no_args::*; #[test] -fn test_process_custom_no_args() { +fn test_process_custom_no_args() -> KResult<()> { let bytes = fs::read("../../src/process_rotate.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessCustomNoArgs::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessCustomNoArgs::read_into(&_io, None, None)?; assert_eq!(*r.buf(), vec![0x5fu8, 0x9u8, 0xacu8, 0x8du8, 0x8du8, 0xedu8, 0x5fu8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_repeat_bytes.rs b/spec/rust/tests/test_process_repeat_bytes.rs index 7c4f78240..1d5e90777 100644 --- a/spec/rust/tests/test_process_repeat_bytes.rs +++ b/spec/rust/tests/test_process_repeat_bytes.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_repeat_bytes::*; #[test] -fn test_process_repeat_bytes() { +fn test_process_repeat_bytes() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessRepeatBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessRepeatBytes::read_into(&_io, None, None)?; assert_eq!(r.bufs()[0 as usize], vec![0x72u8, 0x25u8, 0x3du8, 0x8au8, 0x14u8]); assert_eq!(r.bufs()[1 as usize], vec![0x4au8, 0x52u8, 0xaau8, 0x10u8, 0x44u8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_repeat_usertype.rs b/spec/rust/tests/test_process_repeat_usertype.rs index f991f121b..1f560d2f1 100644 --- a/spec/rust/tests/test_process_repeat_usertype.rs +++ b/spec/rust/tests/test_process_repeat_usertype.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_repeat_usertype::*; #[test] -fn test_process_repeat_usertype() { +fn test_process_repeat_usertype() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessRepeatUsertype::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessRepeatUsertype::read_into(&_io, None, None)?; assert_eq!(*r.blocks()[0 as usize].a(), -1975704206); assert_eq!(*r.blocks()[0 as usize].b(), 20); assert_eq!(*r.blocks()[1 as usize].a(), 279597642); assert_eq!(*r.blocks()[1 as usize].b(), 68); + Ok(()) } diff --git a/spec/rust/tests/test_process_rotate.rs b/spec/rust/tests/test_process_rotate.rs index 7688f1472..56a85b19c 100644 --- a/spec/rust/tests/test_process_rotate.rs +++ b/spec/rust/tests/test_process_rotate.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_rotate::*; #[test] -fn test_process_rotate() { +fn test_process_rotate() -> KResult<()> { let bytes = fs::read("../../src/process_rotate.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessRotate::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessRotate::read_into(&_io, None, None)?; assert_eq!(*r.buf1(), vec![0x48u8, 0x65u8, 0x6cu8, 0x6cu8, 0x6fu8]); assert_eq!(*r.buf2(), vec![0x57u8, 0x6fu8, 0x72u8, 0x6cu8, 0x64u8]); assert_eq!(*r.buf3(), vec![0x54u8, 0x68u8, 0x65u8, 0x72u8, 0x65u8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_to_user.rs b/spec/rust/tests/test_process_to_user.rs index 0ad672686..ade867ee8 100644 --- a/spec/rust/tests/test_process_to_user.rs +++ b/spec/rust/tests/test_process_to_user.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_to_user::*; #[test] -fn test_process_to_user() { +fn test_process_to_user() -> KResult<()> { let bytes = fs::read("../../src/process_rotate.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessToUser::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessToUser::read_into(&_io, None, None)?; assert_eq!(*r.buf1().str(), "Hello"); + Ok(()) } diff --git a/spec/rust/tests/test_process_xor4_const.rs b/spec/rust/tests/test_process_xor4_const.rs index ecda57953..a9e7e9231 100644 --- a/spec/rust/tests/test_process_xor4_const.rs +++ b/spec/rust/tests/test_process_xor4_const.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_xor4_const::*; #[test] -fn test_process_xor4_const() { +fn test_process_xor4_const() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessXor4Const::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessXor4Const::read_into(&_io, None, None)?; assert_eq!(*r.key(), vec![0xecu8, 0xbbu8, 0xa3u8, 0x14u8]); assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_xor4_value.rs b/spec/rust/tests/test_process_xor4_value.rs index e231e8b88..70dc81077 100644 --- a/spec/rust/tests/test_process_xor4_value.rs +++ b/spec/rust/tests/test_process_xor4_value.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_xor4_value::*; #[test] -fn test_process_xor4_value() { +fn test_process_xor4_value() -> KResult<()> { let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessXor4Value::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessXor4Value::read_into(&_io, None, None)?; assert_eq!(*r.key(), vec![0xecu8, 0xbbu8, 0xa3u8, 0x14u8]); assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_xor_const.rs b/spec/rust/tests/test_process_xor_const.rs index 31b8cf45e..707743b8e 100644 --- a/spec/rust/tests/test_process_xor_const.rs +++ b/spec/rust/tests/test_process_xor_const.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_xor_const::*; #[test] -fn test_process_xor_const() { +fn test_process_xor_const() -> KResult<()> { let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessXorConst::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessXorConst::read_into(&_io, None, None)?; assert_eq!(*r.key(), 255); assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); + Ok(()) } diff --git a/spec/rust/tests/test_process_xor_value.rs b/spec/rust/tests/test_process_xor_value.rs index c53850d57..98e0226f8 100644 --- a/spec/rust/tests/test_process_xor_value.rs +++ b/spec/rust/tests/test_process_xor_value.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::process_xor_value::*; #[test] -fn test_process_xor_value() { +fn test_process_xor_value() -> KResult<()> { let bytes = fs::read("../../src/process_xor_1.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ProcessXorValue::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ProcessXorValue::read_into(&_io, None, None)?; assert_eq!(*r.key(), 255); assert_eq!(*r.buf(), vec![0x66u8, 0x6fu8, 0x6fu8, 0x20u8, 0x62u8, 0x61u8, 0x72u8]); + Ok(()) } diff --git a/spec/rust/tests/test_recursive_one.rs b/spec/rust/tests/test_recursive_one.rs index af7f206f2..04119611a 100644 --- a/spec/rust/tests/test_recursive_one.rs +++ b/spec/rust/tests/test_recursive_one.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::recursive_one::*; #[test] -fn test_recursive_one() { +fn test_recursive_one() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RecursiveOne::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RecursiveOne::read_into(&_io, None, None)?; assert_eq!(*r.one(), 80); assert_eq!(*Into::>::into(&*r.next().as_ref().unwrap()).one(), 65); assert_eq!(*Into::>::into(&*Into::>::into(&*r.next().as_ref().unwrap()).next().as_ref().unwrap()).one(), 67); assert_eq!(*Into::>::into(&*Into::>::into(&*Into::>::into(&*r.next().as_ref().unwrap()).next().as_ref().unwrap()).next().as_ref().unwrap()).finisher(), 11595); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_eos_bit.rs b/spec/rust/tests/test_repeat_eos_bit.rs index 944ea9850..0d8524b5a 100644 --- a/spec/rust/tests/test_repeat_eos_bit.rs +++ b/spec/rust/tests/test_repeat_eos_bit.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_eos_bit::*; #[test] -fn test_repeat_eos_bit() { +fn test_repeat_eos_bit() -> KResult<()> { let bytes = fs::read("../../src/enum_0.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatEosBit::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatEosBit::read_into(&_io, None, None)?; assert_eq!(r.nibbles().len(), 16); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_eos_struct.rs b/spec/rust/tests/test_repeat_eos_struct.rs index eff5f57e7..acef8f0f8 100644 --- a/spec/rust/tests/test_repeat_eos_struct.rs +++ b/spec/rust/tests/test_repeat_eos_struct.rs @@ -1,27 +1,20 @@ -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_eos_struct::*; #[test] -fn test_repeat_eos_struct() { +fn test_repeat_eos_struct() -> KResult<()> { let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatEosStruct::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatEosStruct::read_into(&_io, None, None)?; assert_eq!(r.chunks().len(), 2); assert_eq!(*r.chunks()[0 as usize].offset(), 0); assert_eq!(*r.chunks()[0 as usize].len(), 66); assert_eq!(*r.chunks()[1 as usize].offset(), 66); assert_eq!(*r.chunks()[1 as usize].len(), 2069); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_eos_u4.rs b/spec/rust/tests/test_repeat_eos_u4.rs index bc18d03a8..e8852549e 100644 --- a/spec/rust/tests/test_repeat_eos_u4.rs +++ b/spec/rust/tests/test_repeat_eos_u4.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_eos_u4::*; #[test] -fn test_repeat_eos_u4() { +fn test_repeat_eos_u4() -> KResult<()> { let bytes = fs::read("../../src/repeat_eos_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatEosU4::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatEosU4::read_into(&_io, None, None)?; assert_eq!(*r.numbers(), vec![0, 66, 66, 2069]); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_n_struct.rs b/spec/rust/tests/test_repeat_n_struct.rs index 80ee009c6..6b625365c 100644 --- a/spec/rust/tests/test_repeat_n_struct.rs +++ b/spec/rust/tests/test_repeat_n_struct.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_n_struct::*; #[test] -fn test_repeat_n_struct() { +fn test_repeat_n_struct() -> KResult<()> { let bytes = fs::read("../../src/repeat_n_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatNStruct::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatNStruct::read_into(&_io, None, None)?; assert_eq!(r.chunks().len(), 2); assert_eq!(*r.chunks()[0 as usize].offset(), 16); assert_eq!(*r.chunks()[0 as usize].len(), 8312); assert_eq!(*r.chunks()[1 as usize].offset(), 8328); assert_eq!(*r.chunks()[1 as usize].len(), 15); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_n_strz.rs b/spec/rust/tests/test_repeat_n_strz.rs index 5618fde38..a614b1958 100644 --- a/spec/rust/tests/test_repeat_n_strz.rs +++ b/spec/rust/tests/test_repeat_n_strz.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_n_strz::*; #[test] -fn test_repeat_n_strz() { +fn test_repeat_n_strz() -> KResult<()> { let bytes = fs::read("../../src/repeat_n_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatNStrz::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatNStrz::read_into(&_io, None, None)?; assert_eq!(*r.qty(), 2); assert_eq!(*r.lines(), vec!["foo".to_string(), "bar".to_string()]); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_n_strz_double.rs b/spec/rust/tests/test_repeat_n_strz_double.rs index e29267fe8..05fc9fc66 100644 --- a/spec/rust/tests/test_repeat_n_strz_double.rs +++ b/spec/rust/tests/test_repeat_n_strz_double.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_n_strz_double::*; #[test] -fn test_repeat_n_strz_double() { +fn test_repeat_n_strz_double() -> KResult<()> { let bytes = fs::read("../../src/repeat_n_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatNStrzDouble::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatNStrzDouble::read_into(&_io, None, None)?; assert_eq!(*r.qty(), 2); assert_eq!(*r.lines1(), vec!["foo".to_string()]); assert_eq!(*r.lines2(), vec!["bar".to_string()]); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_until_calc_array_type.rs b/spec/rust/tests/test_repeat_until_calc_array_type.rs index 95ef28f6a..1490384c9 100644 --- a/spec/rust/tests/test_repeat_until_calc_array_type.rs +++ b/spec/rust/tests/test_repeat_until_calc_array_type.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_until_calc_array_type::*; #[test] -fn test_repeat_until_calc_array_type() { +fn test_repeat_until_calc_array_type() -> KResult<()> { let bytes = fs::read("../../src/repeat_until_process.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatUntilCalcArrayType::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatUntilCalcArrayType::read_into(&_io, None, None)?; assert_eq!(r.records().len(), 3); assert_eq!(*r.records()[0 as usize].marker(), 232); @@ -28,4 +18,5 @@ fn test_repeat_until_calc_array_type() { assert_eq!(*r.records()[1 as usize].body(), 2863315102); assert_eq!(*r.records()[2 as usize].marker(), 170); assert_eq!(*r.records()[2 as usize].body(), 1431655765); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_until_complex.rs b/spec/rust/tests/test_repeat_until_complex.rs index 516735752..9ad7b0cfa 100644 --- a/spec/rust/tests/test_repeat_until_complex.rs +++ b/spec/rust/tests/test_repeat_until_complex.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_until_complex::*; #[test] -fn test_repeat_until_complex() { +fn test_repeat_until_complex() -> KResult<()> { let bytes = fs::read("../../src/repeat_until_complex.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatUntilComplex::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatUntilComplex::read_into(&_io, None, None)?; assert_eq!(r.first().len(), 3); assert_eq!(*r.first()[0 as usize].count(), 4); @@ -36,4 +26,5 @@ fn test_repeat_until_complex() { assert_eq!(*r.second()[2 as usize].values(), vec![(0 + 1), 2, 3, 4]); assert_eq!(*r.second()[3 as usize].count(), 0); assert_eq!(*r.third(), vec![(0 + 102), 111, 111, 98, 97, 114, 0]); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_until_s4.rs b/spec/rust/tests/test_repeat_until_s4.rs index 381dd463e..b0f5b4ff1 100644 --- a/spec/rust/tests/test_repeat_until_s4.rs +++ b/spec/rust/tests/test_repeat_until_s4.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_until_s4::*; #[test] -fn test_repeat_until_s4() { +fn test_repeat_until_s4() -> KResult<()> { let bytes = fs::read("../../src/repeat_until_s4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatUntilS4::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatUntilS4::read_into(&_io, None, None)?; assert_eq!(*r.entries(), vec![66, 4919, -251658241, -1]); assert_eq!(*r.afterall(), "foobar"); + Ok(()) } diff --git a/spec/rust/tests/test_repeat_until_sized.rs b/spec/rust/tests/test_repeat_until_sized.rs index e6e196dfa..4e5abe69f 100644 --- a/spec/rust/tests/test_repeat_until_sized.rs +++ b/spec/rust/tests/test_repeat_until_sized.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::repeat_until_sized::*; #[test] -fn test_repeat_until_sized() { +fn test_repeat_until_sized() -> KResult<()> { let bytes = fs::read("../../src/repeat_until_process.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = RepeatUntilSized::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = RepeatUntilSized::read_into(&_io, None, None)?; assert_eq!(r.records().len(), 3); assert_eq!(*r.records()[0 as usize].marker(), 232); @@ -28,4 +18,5 @@ fn test_repeat_until_sized() { assert_eq!(*r.records()[1 as usize].body(), 2863315102); assert_eq!(*r.records()[2 as usize].marker(), 170); assert_eq!(*r.records()[2 as usize].body(), 1431655765); + Ok(()) } diff --git a/spec/rust/tests/test_str_encodings.rs b/spec/rust/tests/test_str_encodings.rs index a5a2361dd..ce1687cc6 100644 --- a/spec/rust/tests/test_str_encodings.rs +++ b/spec/rust/tests/test_str_encodings.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::str_encodings::*; #[test] -fn test_str_encodings() { +fn test_str_encodings() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = StrEncodings::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = StrEncodings::read_into(&_io, None, None)?; assert_eq!(*r.str1(), "Some ASCII"); assert_eq!(*r.str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); assert_eq!(*r.str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); assert_eq!(*r.str4(), "\u{2591}\u{2592}\u{2593}"); + Ok(()) } diff --git a/spec/rust/tests/test_str_encodings_default.rs b/spec/rust/tests/test_str_encodings_default.rs index 6be824e87..6fb85ea1b 100644 --- a/spec/rust/tests/test_str_encodings_default.rs +++ b/spec/rust/tests/test_str_encodings_default.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::str_encodings_default::*; #[test] -fn test_str_encodings_default() { +fn test_str_encodings_default() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = StrEncodingsDefault::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = StrEncodingsDefault::read_into(&_io, None, None)?; assert_eq!(*r.str1(), "Some ASCII"); assert_eq!(*r.rest().str2(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); assert_eq!(*r.rest().str3(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); assert_eq!(*r.rest().str4(), "\u{2591}\u{2592}\u{2593}"); + Ok(()) } diff --git a/spec/rust/tests/test_str_encodings_utf16.rs b/spec/rust/tests/test_str_encodings_utf16.rs index 2101ed834..431577988 100644 --- a/spec/rust/tests/test_str_encodings_utf16.rs +++ b/spec/rust/tests/test_str_encodings_utf16.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::str_encodings_utf16::*; #[test] -fn test_str_encodings_utf16() { +fn test_str_encodings_utf16() -> KResult<()> { let bytes = fs::read("../../src/str_encodings_utf16.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = StrEncodingsUtf16::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = StrEncodingsUtf16::read_into(&_io, None, None)?; assert_eq!(*r.len_be(), 12); assert_eq!(*r.be_bom_removed().bom(), 65279); @@ -27,4 +17,5 @@ fn test_str_encodings_utf16() { assert_eq!(*r.len_le(), 12); assert_eq!(*r.le_bom_removed().bom(), 65279); assert_eq!(*r.le_bom_removed().str(), "\u{3053}\u{3093}\u{306b}\u{3061}\u{306f}"); + Ok(()) } diff --git a/spec/rust/tests/test_str_eos.rs b/spec/rust/tests/test_str_eos.rs index 84d809774..b7f83d320 100644 --- a/spec/rust/tests/test_str_eos.rs +++ b/spec/rust/tests/test_str_eos.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::str_eos::*; #[test] -fn test_str_eos() { +fn test_str_eos() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = StrEos::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = StrEos::read_into(&_io, None, None)?; assert_eq!(*r.str(), "foo|bar|baz@"); + Ok(()) } diff --git a/spec/rust/tests/test_str_literals2.rs b/spec/rust/tests/test_str_literals2.rs index 4f33e61d7..d039f917c 100644 --- a/spec/rust/tests/test_str_literals2.rs +++ b/spec/rust/tests/test_str_literals2.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::str_literals2::*; #[test] -fn test_str_literals2() { +fn test_str_literals2() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = StrLiterals2::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = StrLiterals2::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.dollar1().expect("error reading"), "$foo"); - assert_eq!(*r.dollar2().expect("error reading"), "${foo}"); - assert_eq!(*r.hash().expect("error reading"), "#{foo}"); - assert_eq!(*r.at_sign().expect("error reading"), "@foo"); + assert_eq!(*r.dollar1()?, "$foo"); + assert_eq!(*r.dollar2()?, "${foo}"); + assert_eq!(*r.hash()?, "#{foo}"); + assert_eq!(*r.at_sign()?, "@foo"); + Ok(()) } diff --git a/spec/rust/tests/test_str_pad_term.rs b/spec/rust/tests/test_str_pad_term.rs index acf8fa41a..0d1411890 100644 --- a/spec/rust/tests/test_str_pad_term.rs +++ b/spec/rust/tests/test_str_pad_term.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::str_pad_term::*; #[test] -fn test_str_pad_term() { +fn test_str_pad_term() -> KResult<()> { let bytes = fs::read("../../src/str_pad_term.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = StrPadTerm::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = StrPadTerm::read_into(&_io, None, None)?; assert_eq!(*r.str_pad(), "str1"); assert_eq!(*r.str_term(), "str2foo"); assert_eq!(*r.str_term_and_pad(), "str+++3bar+++"); assert_eq!(*r.str_term_include(), "str4baz@"); + Ok(()) } diff --git a/spec/rust/tests/test_str_pad_term_empty.rs b/spec/rust/tests/test_str_pad_term_empty.rs index bcb97bff1..ca78aba31 100644 --- a/spec/rust/tests/test_str_pad_term_empty.rs +++ b/spec/rust/tests/test_str_pad_term_empty.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::str_pad_term_empty::*; #[test] -fn test_str_pad_term_empty() { +fn test_str_pad_term_empty() -> KResult<()> { let bytes = fs::read("../../src/str_pad_term_empty.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = StrPadTermEmpty::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = StrPadTermEmpty::read_into(&_io, None, None)?; assert_eq!(*r.str_pad(), ""); assert_eq!(*r.str_term(), ""); assert_eq!(*r.str_term_and_pad(), ""); assert_eq!(*r.str_term_include(), "@"); + Ok(()) } diff --git a/spec/rust/tests/test_switch_bytearray.rs b/spec/rust/tests/test_switch_bytearray.rs index 4ca5e4adc..2c6aae985 100644 --- a/spec/rust/tests/test_switch_bytearray.rs +++ b/spec/rust/tests/test_switch_bytearray.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_bytearray::*; #[test] -fn test_switch_bytearray() { +fn test_switch_bytearray() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchBytearray::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchBytearray::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), vec![0x53u8]); @@ -30,4 +20,5 @@ fn test_switch_bytearray() { assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); assert_eq!(*r.opcodes()[3 as usize].code(), vec![0x53u8]); assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); + Ok(()) } diff --git a/spec/rust/tests/test_switch_else_only.rs b/spec/rust/tests/test_switch_else_only.rs index c06a82e20..fe19c2631 100644 --- a/spec/rust/tests/test_switch_else_only.rs +++ b/spec/rust/tests/test_switch_else_only.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_else_only::*; #[test] -fn test_switch_else_only() { +fn test_switch_else_only() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchElseOnly::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchElseOnly::read_into(&_io, None, None)?; assert_eq!(*r.opcode(), 83); assert_eq!(r.prim_byte(), 102); assert_eq!(*r.ut().as_ref().unwrap().value(), vec![0x72u8, 0x0u8, 0x49u8, 0x42u8]); + Ok(()) } diff --git a/spec/rust/tests/test_switch_integers.rs b/spec/rust/tests/test_switch_integers.rs index 296cbbf08..889c1a3da 100644 --- a/spec/rust/tests/test_switch_integers.rs +++ b/spec/rust/tests/test_switch_integers.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_integers::*; #[test] -fn test_switch_integers() { +fn test_switch_integers() -> KResult<()> { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchIntegers::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchIntegers::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), 1); @@ -30,4 +20,5 @@ fn test_switch_integers() { assert_eq!(r.opcodes()[2 as usize].body(), 4919); assert_eq!(*r.opcodes()[3 as usize].code(), 8); assert_eq!(r.opcodes()[3 as usize].body(), 4919); + Ok(()) } diff --git a/spec/rust/tests/test_switch_integers2.rs b/spec/rust/tests/test_switch_integers2.rs index c446d874c..8ba2b286f 100644 --- a/spec/rust/tests/test_switch_integers2.rs +++ b/spec/rust/tests/test_switch_integers2.rs @@ -1,29 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_integers2::*; #[test] -fn test_switch_integers2() { +fn test_switch_integers2() -> KResult<()> { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchIntegers2::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchIntegers2::read_into(&_io, None, None)?; assert_eq!(*r.code(), 1); assert_eq!(r.len(), 7); assert_eq!(*r.ham(), vec![0x2u8, 0x40u8, 0x40u8, 0x4u8, 0x37u8, 0x13u8, 0x0u8]); assert_eq!(*r.padding(), 0); - assert_eq!(*r.len_mod_str().expect("error reading"), "13"); + assert_eq!(*r.len_mod_str()?, "13"); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_enum.rs b/spec/rust/tests/test_switch_manual_enum.rs index 5d435f87f..1d2aa8f9d 100644 --- a/spec/rust/tests/test_switch_manual_enum.rs +++ b/spec/rust/tests/test_switch_manual_enum.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_enum::*; #[test] -fn test_switch_manual_enum() { +fn test_switch_manual_enum() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualEnum::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualEnum::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); @@ -30,4 +20,5 @@ fn test_switch_manual_enum() { assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); assert_eq!(*r.opcodes()[3 as usize].code(), SwitchManualEnum_Opcode_CodeEnum::Strval); assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs index 2baa18772..2f4f08f71 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid_else.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid_else.rs @@ -1,44 +1,22 @@ -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_enum_invalid_else::*; #[test] -fn test_switch_manual_enum_invalid_else() { +fn test_switch_manual_enum_invalid_else() -> KResult<()> { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = - SwitchManualEnumInvalidElse::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualEnumInvalidElse::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 2); let n: i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); - assert_eq!( - *Into::>::into( - &*r.opcodes()[0 as usize].body().as_ref().unwrap() - ) - .value() - .unwrap(), - 123 - ); + assert_eq!(*Into::>::into(&*r.opcodes()[0 as usize].body().as_ref().unwrap()).value()?, 123); let n: i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); - assert_eq!( - *Into::>::into( - &*r.opcodes()[1 as usize].body().as_ref().unwrap() - ) - .value() - .unwrap(), - 123 - ); + assert_eq!(*Into::>::into(&*r.opcodes()[1 as usize].body().as_ref().unwrap()).value()?, 123); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_int.rs b/spec/rust/tests/test_switch_manual_int.rs index b80400d31..42bd4e748 100644 --- a/spec/rust/tests/test_switch_manual_int.rs +++ b/spec/rust/tests/test_switch_manual_int.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_int::*; #[test] -fn test_switch_manual_int() { +fn test_switch_manual_int() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualInt::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualInt::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), 83); @@ -30,4 +20,5 @@ fn test_switch_manual_int() { assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); assert_eq!(*r.opcodes()[3 as usize].code(), 83); assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_int_else.rs b/spec/rust/tests/test_switch_manual_int_else.rs index 8fcbf4bc1..3a8b8aa81 100644 --- a/spec/rust/tests/test_switch_manual_int_else.rs +++ b/spec/rust/tests/test_switch_manual_int_else.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_int_else::*; #[test] -fn test_switch_manual_int_else() { +fn test_switch_manual_int_else() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualIntElse::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualIntElse::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), 83); @@ -30,4 +20,5 @@ fn test_switch_manual_int_else() { assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).filler(), 51966); assert_eq!(*r.opcodes()[3 as usize].code(), 73); assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), 7); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_int_size.rs b/spec/rust/tests/test_switch_manual_int_size.rs index ce7f20487..0a3644d2f 100644 --- a/spec/rust/tests/test_switch_manual_int_size.rs +++ b/spec/rust/tests/test_switch_manual_int_size.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_int_size::*; #[test] -fn test_switch_manual_int_size() { +fn test_switch_manual_int_size() -> KResult<()> { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualIntSize::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualIntSize::read_into(&_io, None, None)?; assert_eq!(r.chunks().len(), 4); assert_eq!(*r.chunks()[0 as usize].code(), 17); @@ -31,4 +21,5 @@ fn test_switch_manual_int_size() { assert_eq!(Into::>::into(&*r.chunks()[2 as usize].body().as_ref().unwrap()), vec![0x10u8, 0x20u8, 0x30u8, 0x40u8, 0x50u8, 0x60u8, 0x70u8, 0x80u8]); assert_eq!(*r.chunks()[3 as usize].code(), 255); assert_eq!(Into::>::into(&*r.chunks()[3 as usize].body().as_ref().unwrap()), vec![]); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_int_size_else.rs b/spec/rust/tests/test_switch_manual_int_size_else.rs index d21acbafd..3c75b9aa1 100644 --- a/spec/rust/tests/test_switch_manual_int_size_else.rs +++ b/spec/rust/tests/test_switch_manual_int_size_else.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_int_size_else::*; #[test] -fn test_switch_manual_int_size_else() { +fn test_switch_manual_int_size_else() -> KResult<()> { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualIntSizeElse::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualIntSizeElse::read_into(&_io, None, None)?; assert_eq!(r.chunks().len(), 4); assert_eq!(*r.chunks()[0 as usize].code(), 17); @@ -31,4 +21,5 @@ fn test_switch_manual_int_size_else() { assert_eq!(*Into::>::into(&*r.chunks()[2 as usize].body().as_ref().unwrap()).rest(), vec![0x10u8, 0x20u8, 0x30u8, 0x40u8, 0x50u8, 0x60u8, 0x70u8, 0x80u8]); assert_eq!(*r.chunks()[3 as usize].code(), 255); assert_eq!(*Into::>::into(&*r.chunks()[3 as usize].body().as_ref().unwrap()).rest(), vec![]); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_int_size_eos.rs b/spec/rust/tests/test_switch_manual_int_size_eos.rs index c985776d9..19e3fa4fd 100644 --- a/spec/rust/tests/test_switch_manual_int_size_eos.rs +++ b/spec/rust/tests/test_switch_manual_int_size_eos.rs @@ -1,65 +1,25 @@ -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_int_size_eos::*; #[test] -fn test_switch_manual_int_size_eos() { +fn test_switch_manual_int_size_eos() -> KResult<()> { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = - SwitchManualIntSizeEos::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualIntSizeEos::read_into(&_io, None, None)?; assert_eq!(r.chunks().len(), 4); assert_eq!(*r.chunks()[0 as usize].code(), 17); - if let Some( - SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkMeta(s), - ) = r.chunks()[0].body().clone().body().as_ref() - { - assert_eq!("Stuff", *s.title()); - assert_eq!("Me", *s.author()); - } else { - panic!("expected enum SwitchManualIntSizeEos_ChunkBody_ChunkMeta"); - }; + assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().body().as_ref().unwrap()).title(), "Stuff"); + assert_eq!(*Into::>::into(&*r.chunks()[0 as usize].body().body().as_ref().unwrap()).author(), "Me"); assert_eq!(*r.chunks()[1 as usize].code(), 34); - if let Some(SwitchManualIntSizeEos_ChunkBody_Body::SwitchManualIntSizeEos_ChunkBody_ChunkDir( - s, - )) = r.chunks()[1].body().clone().body().as_ref() - { - let strings: Vec = vec!["AAAA", "BBBB", "CCCC"] - .iter() - .map(|&s| s.to_string()) - .collect(); - assert_eq!(strings, *s.entries()); - } else { - panic!("expected enum SwitchManualIntSizeEos_ChunkBody_ChunkDir"); - } + assert_eq!(*Into::>::into(&*r.chunks()[1 as usize].body().body().as_ref().unwrap()).entries(), vec!["AAAA".to_string(), "BBBB".to_string(), "CCCC".to_string()]); assert_eq!(*r.chunks()[2 as usize].code(), 51); - if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = - r.chunks()[2].body().clone().body().as_ref() - { - let raw: Vec = vec![0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80]; - assert_eq!(raw, *s); - } else { - panic!("expected enum Bytes"); - } + assert_eq!(Into::>::into(&*r.chunks()[2 as usize].body().body().as_ref().unwrap()), vec![0x10u8, 0x20u8, 0x30u8, 0x40u8, 0x50u8, 0x60u8, 0x70u8, 0x80u8]); assert_eq!(*r.chunks()[3 as usize].code(), 255); - if let Some(SwitchManualIntSizeEos_ChunkBody_Body::Bytes(s)) = - r.chunks()[3].body().clone().body().as_ref() - { - let raw: Vec = vec![]; - assert_eq!(raw, *s); - } else { - panic!("expected enum Bytes"); - }; + assert_eq!(Into::>::into(&*r.chunks()[3 as usize].body().body().as_ref().unwrap()), vec![]); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_str.rs b/spec/rust/tests/test_switch_manual_str.rs index 1a9e481c7..6f7223abf 100644 --- a/spec/rust/tests/test_switch_manual_str.rs +++ b/spec/rust/tests/test_switch_manual_str.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_str::*; #[test] -fn test_switch_manual_str() { +fn test_switch_manual_str() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualStr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualStr::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), "S"); @@ -30,4 +20,5 @@ fn test_switch_manual_str() { assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).value(), 55); assert_eq!(*r.opcodes()[3 as usize].code(), "S"); assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), ""); + Ok(()) } diff --git a/spec/rust/tests/test_switch_manual_str_else.rs b/spec/rust/tests/test_switch_manual_str_else.rs index 703cf7e1f..6ddfcf483 100644 --- a/spec/rust/tests/test_switch_manual_str_else.rs +++ b/spec/rust/tests/test_switch_manual_str_else.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_str_else::*; #[test] -fn test_switch_manual_str_else() { +fn test_switch_manual_str_else() -> KResult<()> { let bytes = fs::read("../../src/switch_opcodes2.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchManualStrElse::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualStrElse::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), "S"); @@ -30,4 +20,5 @@ fn test_switch_manual_str_else() { assert_eq!(*Into::>::into(&*r.opcodes()[2 as usize].body().as_ref().unwrap()).filler(), 51966); assert_eq!(*r.opcodes()[3 as usize].code(), "I"); assert_eq!(*Into::>::into(&*r.opcodes()[3 as usize].body().as_ref().unwrap()).value(), 7); + Ok(()) } diff --git a/spec/rust/tests/test_switch_multi_bool_ops.rs b/spec/rust/tests/test_switch_multi_bool_ops.rs index 9469f4015..a665cfd11 100644 --- a/spec/rust/tests/test_switch_multi_bool_ops.rs +++ b/spec/rust/tests/test_switch_multi_bool_ops.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_multi_bool_ops::*; #[test] -fn test_switch_multi_bool_ops() { +fn test_switch_multi_bool_ops() -> KResult<()> { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchMultiBoolOps::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchMultiBoolOps::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 4); assert_eq!(*r.opcodes()[0 as usize].code(), 1); @@ -30,4 +20,5 @@ fn test_switch_multi_bool_ops() { assert_eq!(r.opcodes()[2 as usize].body(), 4919); assert_eq!(*r.opcodes()[3 as usize].code(), 8); assert_eq!(r.opcodes()[3 as usize].body(), 4919); + Ok(()) } diff --git a/spec/rust/tests/test_switch_repeat_expr.rs b/spec/rust/tests/test_switch_repeat_expr.rs index b823b5385..5b9846d3c 100644 --- a/spec/rust/tests/test_switch_repeat_expr.rs +++ b/spec/rust/tests/test_switch_repeat_expr.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_repeat_expr::*; #[test] -fn test_switch_repeat_expr() { +fn test_switch_repeat_expr() -> KResult<()> { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchRepeatExpr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchRepeatExpr::read_into(&_io, None, None)?; assert_eq!(*r.code(), 17); assert_eq!(*r.size(), 9); assert_eq!(*Into::>::into(&r.body()[0 as usize]).first(), vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); + Ok(()) } diff --git a/spec/rust/tests/test_switch_repeat_expr_invalid.rs b/spec/rust/tests/test_switch_repeat_expr_invalid.rs index 1ae381fda..2ac0b5267 100644 --- a/spec/rust/tests/test_switch_repeat_expr_invalid.rs +++ b/spec/rust/tests/test_switch_repeat_expr_invalid.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_repeat_expr_invalid::*; #[test] -fn test_switch_repeat_expr_invalid() { +fn test_switch_repeat_expr_invalid() -> KResult<()> { let bytes = fs::read("../../src/switch_tlv.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = SwitchRepeatExprInvalid::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchRepeatExprInvalid::read_into(&_io, None, None)?; assert_eq!(*r.code(), 17); assert_eq!(*r.size(), 9); assert_eq!(Into::>::into(&r.body()[0 as usize]), vec![0x53u8, 0x74u8, 0x75u8, 0x66u8, 0x66u8, 0x0u8, 0x4du8, 0x65u8, 0x0u8]); + Ok(()) } diff --git a/spec/rust/tests/test_term_bytes.rs b/spec/rust/tests/test_term_bytes.rs index f1c3c98e6..8113cde90 100644 --- a/spec/rust/tests/test_term_bytes.rs +++ b/spec/rust/tests/test_term_bytes.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::term_bytes::*; #[test] -fn test_term_bytes() { +fn test_term_bytes() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = TermBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = TermBytes::read_into(&_io, None, None)?; assert_eq!(*r.s1(), vec![0x66u8, 0x6fu8, 0x6fu8]); assert_eq!(*r.s2(), vec![0x62u8, 0x61u8, 0x72u8]); assert_eq!(*r.s3(), vec![0x7cu8, 0x62u8, 0x61u8, 0x7au8, 0x40u8]); + Ok(()) } diff --git a/spec/rust/tests/test_term_strz.rs b/spec/rust/tests/test_term_strz.rs index c3e770612..349c671c3 100644 --- a/spec/rust/tests/test_term_strz.rs +++ b/spec/rust/tests/test_term_strz.rs @@ -1,27 +1,18 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::term_strz::*; #[test] -fn test_term_strz() { +fn test_term_strz() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = TermStrz::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = TermStrz::read_into(&_io, None, None)?; assert_eq!(*r.s1(), "foo"); assert_eq!(*r.s2(), "bar"); assert_eq!(*r.s3(), "|baz@"); + Ok(()) } diff --git a/spec/rust/tests/test_term_u1_val.rs b/spec/rust/tests/test_term_u1_val.rs index b90ec2d79..13fe9e0af 100644 --- a/spec/rust/tests/test_term_u1_val.rs +++ b/spec/rust/tests/test_term_u1_val.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::term_u1_val::*; #[test] -fn test_term_u1_val() { +fn test_term_u1_val() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = TermU1Val::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = TermU1Val::read_into(&_io, None, None)?; assert_eq!(*r.foo(), vec![0xau8, 0x0u8, 0x53u8, 0x6fu8, 0x6du8, 0x65u8, 0x20u8, 0x41u8, 0x53u8, 0x43u8, 0x49u8, 0x49u8, 0xfu8, 0x0u8]); assert_eq!(*r.bar(), "\u{3053}\u{3093}\u{306b}"); + Ok(()) } diff --git a/spec/rust/tests/test_ts_packet_header.rs b/spec/rust/tests/test_ts_packet_header.rs index dd8094bcd..2be1edd82 100644 --- a/spec/rust/tests/test_ts_packet_header.rs +++ b/spec/rust/tests/test_ts_packet_header.rs @@ -1,25 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::ts_packet_header::*; #[test] -fn test_ts_packet_header() { +fn test_ts_packet_header() -> KResult<()> { let bytes = fs::read("../../src/ts_packet.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = TsPacketHeader::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = TsPacketHeader::read_into(&_io, None, None)?; assert_eq!(*r.sync_byte(), 71); assert_eq!(*r.transport_error_indicator(), false); @@ -28,4 +18,5 @@ fn test_ts_packet_header() { assert_eq!(*r.pid(), 33); assert_eq!(*r.transport_scrambling_control(), 0); assert_eq!(*r.adaptation_field_control(), TsPacketHeader_AdaptationFieldControlEnum::PayloadOnly); + Ok(()) } diff --git a/spec/rust/tests/test_type_int_unary_op.rs b/spec/rust/tests/test_type_int_unary_op.rs index a8496a766..23c06965c 100644 --- a/spec/rust/tests/test_type_int_unary_op.rs +++ b/spec/rust/tests/test_type_int_unary_op.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::type_int_unary_op::*; #[test] -fn test_type_int_unary_op() { +fn test_type_int_unary_op() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = TypeIntUnaryOp::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = TypeIntUnaryOp::read_into(&_io, None, None)?; assert_eq!(*r.value_s2(), 16720); assert_eq!(*r.value_s8(), 4706543082108963651); - assert_eq!(*r.unary_s2().expect("error reading"), -16720); - assert_eq!(*r.unary_s8().expect("error reading"), -4706543082108963651); + assert_eq!(*r.unary_s2()?, -16720); + assert_eq!(*r.unary_s8()?, -4706543082108963651); + Ok(()) } diff --git a/spec/rust/tests/test_type_ternary.rs b/spec/rust/tests/test_type_ternary.rs index 0e1c1a924..2180eed56 100644 --- a/spec/rust/tests/test_type_ternary.rs +++ b/spec/rust/tests/test_type_ternary.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::type_ternary::*; #[test] -fn test_type_ternary() { +fn test_type_ternary() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = TypeTernary::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = TypeTernary::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.dif().expect("error reading").value(), 101); + assert_eq!(*r.dif()?.value(), 101); + Ok(()) } diff --git a/spec/rust/tests/test_type_ternary_2nd_falsy.rs b/spec/rust/tests/test_type_ternary_2nd_falsy.rs index 4e741b889..2f457f841 100644 --- a/spec/rust/tests/test_type_ternary_2nd_falsy.rs +++ b/spec/rust/tests/test_type_ternary_2nd_falsy.rs @@ -1,35 +1,28 @@ -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] +// Autogenerated from KST: please remove this line if doing any edits by hand! + use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::type_ternary_2nd_falsy::*; #[test] -fn test_type_ternary_2nd_falsy() { +fn test_type_ternary_2nd_falsy() -> KResult<()> { let bytes = fs::read("../../src/switch_integers.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = TypeTernary2ndFalsy::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = TypeTernary2ndFalsy::read_into(&_io, None, None)?; - assert_eq!(*r.v_false().expect("error reading"), false); - assert_eq!(*r.v_int_zero().expect("error reading"), 0); - assert_eq!(*r.v_int_neg_zero().expect("error reading"), 0); - assert_eq!(*r.v_float_zero().expect("error reading"), 0.0); - assert_eq!(*r.v_float_neg_zero().expect("error reading"), -0.0); - assert_eq!(*r.v_str_w_zero().expect("error reading"), "0"); - assert_eq!(r.v_str_w_zero().expect("error reading").len(), 1); + assert_eq!(*r.v_false()?, false); + assert_eq!(*r.v_int_zero()?, 0); + assert_eq!(*r.v_int_neg_zero()?, 0); + assert_eq!(*r.v_float_zero()?, 0.0); + assert_eq!(*r.v_float_neg_zero()?, -0.0); + assert_eq!(*r.v_str_w_zero()?, "0"); + assert_eq!(r.v_str_w_zero()?.len(), 1); assert_eq!(*r.ut().m(), 7); - assert_eq!(r.v_null_ut().expect("error reading").is_none(), true); - assert_eq!(*r.v_str_empty().expect("error reading"), ""); - assert_eq!(r.v_str_empty().expect("error reading").len(), 0); + assert!(r.v_null_ut()?.is_none()); + assert_eq!(*r.v_str_empty()?, ""); + assert_eq!(r.v_str_empty()?.len(), 0); assert_eq!(r.int_array().len(), 2); - assert_eq!(r.v_int_array_empty().expect("error reading").len(), 0); + assert_eq!(r.v_int_array_empty()?.len(), 0); + Ok(()) } diff --git a/spec/rust/tests/test_user_type.rs b/spec/rust/tests/test_user_type.rs index 9bb269651..5719b2ecc 100644 --- a/spec/rust/tests/test_user_type.rs +++ b/spec/rust/tests/test_user_type.rs @@ -1,26 +1,17 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::user_type::*; #[test] -fn test_user_type() { +fn test_user_type() -> KResult<()> { let bytes = fs::read("../../src/repeat_until_s4.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = UserType::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = UserType::read_into(&_io, None, None)?; assert_eq!(*r.one().width(), 66); assert_eq!(*r.one().height(), 4919); + Ok(()) } diff --git a/spec/rust/tests/test_valid_eq_str_encodings.rs b/spec/rust/tests/test_valid_eq_str_encodings.rs index fea4f8f98..fcae4b694 100644 --- a/spec/rust/tests/test_valid_eq_str_encodings.rs +++ b/spec/rust/tests/test_valid_eq_str_encodings.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_eq_str_encodings::*; #[test] -fn test_valid_eq_str_encodings() { +fn test_valid_eq_str_encodings() -> KResult<()> { let bytes = fs::read("../../src/str_encodings.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ValidEqStrEncodings::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ValidEqStrEncodings::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_valid_long.rs b/spec/rust/tests/test_valid_long.rs index b3f42442a..cbaef730f 100644 --- a/spec/rust/tests/test_valid_long.rs +++ b/spec/rust/tests/test_valid_long.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_long::*; #[test] -fn test_valid_long() { +fn test_valid_long() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ValidLong::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ValidLong::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_valid_not_parsed_if.rs b/spec/rust/tests/test_valid_not_parsed_if.rs index 9c5a0de70..502dc867c 100644 --- a/spec/rust/tests/test_valid_not_parsed_if.rs +++ b/spec/rust/tests/test_valid_not_parsed_if.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_not_parsed_if::*; #[test] -fn test_valid_not_parsed_if() { +fn test_valid_not_parsed_if() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ValidNotParsedIf::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ValidNotParsedIf::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_valid_optional_id.rs b/spec/rust/tests/test_valid_optional_id.rs index 80bae03f9..be9490fd3 100644 --- a/spec/rust/tests/test_valid_optional_id.rs +++ b/spec/rust/tests/test_valid_optional_id.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_optional_id::*; #[test] -fn test_valid_optional_id() { +fn test_valid_optional_id() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ValidOptionalId::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ValidOptionalId::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_valid_short.rs b/spec/rust/tests/test_valid_short.rs index ca3fdcdf8..80bca0234 100644 --- a/spec/rust/tests/test_valid_short.rs +++ b/spec/rust/tests/test_valid_short.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_short::*; #[test] -fn test_valid_short() { +fn test_valid_short() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ValidShort::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ValidShort::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_valid_switch.rs b/spec/rust/tests/test_valid_switch.rs index 073421f30..a04ba4bdf 100644 --- a/spec/rust/tests/test_valid_switch.rs +++ b/spec/rust/tests/test_valid_switch.rs @@ -1,24 +1,15 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_switch::*; #[test] -fn test_valid_switch() { +fn test_valid_switch() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ValidSwitch::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ValidSwitch::read_into(&_io, None, None)?; + Ok(()) } diff --git a/spec/rust/tests/test_yaml_ints.rs b/spec/rust/tests/test_yaml_ints.rs index ab9ca6170..8b9fb2b0d 100644 --- a/spec/rust/tests/test_yaml_ints.rs +++ b/spec/rust/tests/test_yaml_ints.rs @@ -1,28 +1,19 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::yaml_ints::*; #[test] -fn test_yaml_ints() { +fn test_yaml_ints() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = YamlInts::read_into(&_io, None, None); - let r : OptRc; + let r: OptRc = YamlInts::read_into(&_io, None, None)?; - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.test_u4_dec().expect("error reading"), 4294967295); - assert_eq!(*r.test_u4_hex().expect("error reading"), 4294967295); - assert_eq!(*r.test_u8_dec().expect("error reading"), 18446744073709551615); - assert_eq!(*r.test_u8_hex().expect("error reading"), 18446744073709551615); + assert_eq!(*r.test_u4_dec()?, 4294967295); + assert_eq!(*r.test_u4_hex()?, 4294967295); + assert_eq!(*r.test_u8_dec()?, 18446744073709551615); + assert_eq!(*r.test_u8_hex()?, 18446744073709551615); + Ok(()) } diff --git a/spec/rust/tests/test_zlib_surrounded.rs b/spec/rust/tests/test_zlib_surrounded.rs index 5d8ff4f0c..863754bff 100644 --- a/spec/rust/tests/test_zlib_surrounded.rs +++ b/spec/rust/tests/test_zlib_surrounded.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::zlib_surrounded::*; #[test] -fn test_zlib_surrounded() { +fn test_zlib_surrounded() -> KResult<()> { let bytes = fs::read("../../src/zlib_surrounded.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ZlibSurrounded::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ZlibSurrounded::read_into(&_io, None, None)?; assert_eq!(*r.zlib().num(), -1); + Ok(()) } diff --git a/spec/rust/tests/test_zlib_with_header_78.rs b/spec/rust/tests/test_zlib_with_header_78.rs index 5b8098287..114c71c18 100644 --- a/spec/rust/tests/test_zlib_with_header_78.rs +++ b/spec/rust/tests/test_zlib_with_header_78.rs @@ -1,25 +1,16 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::zlib_with_header_78::*; #[test] -fn test_zlib_with_header_78() { +fn test_zlib_with_header_78() -> KResult<()> { let bytes = fs::read("../../src/zlib_with_header_78.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = ZlibWithHeader78::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ZlibWithHeader78::read_into(&_io, None, None)?; assert_eq!(*r.data(), vec![0x61u8, 0x20u8, 0x71u8, 0x75u8, 0x69u8, 0x63u8, 0x6bu8, 0x20u8, 0x62u8, 0x72u8, 0x6fu8, 0x77u8, 0x6eu8, 0x20u8, 0x66u8, 0x6fu8, 0x78u8, 0x20u8, 0x6au8, 0x75u8, 0x6du8, 0x70u8, 0x73u8, 0x20u8, 0x6fu8, 0x76u8, 0x65u8, 0x72u8]); + Ok(()) } From 5e0eaba52bac9b54ee7ffd9153c6e64b611fc663 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sat, 29 Jun 2024 11:47:16 +0200 Subject: [PATCH 187/198] Rust: normalize specs not autogenerated from KST --- spec/rust/tests/test_debug_0.rs | 10 ---- spec/rust/tests/test_debug_array_user.rs | 16 ++----- spec/rust/tests/test_opaque_external_type.rs | 13 ++--- .../test_opaque_external_type_02_parent.rs | 13 ++--- spec/rust/tests/test_opaque_with_param.rs | 19 ++------ spec/rust/tests/test_optional_id.rs | 14 ++---- spec/rust/tests/test_params_def.rs | 13 ++--- spec/rust/tests/test_str_literals.rs | 35 ++++---------- spec/rust/tests/test_switch_cast.rs | 48 ++----------------- .../tests/test_switch_manual_enum_invalid.rs | 20 ++------ spec/rust/tests/test_to_string_custom.rs | 14 ++---- spec/rust/tests/test_type_ternary_opaque.rs | 20 +++----- 12 files changed, 49 insertions(+), 186 deletions(-) delete mode 100644 spec/rust/tests/test_debug_0.rs diff --git a/spec/rust/tests/test_debug_0.rs b/spec/rust/tests/test_debug_0.rs deleted file mode 100644 index 30af7751d..000000000 --- a/spec/rust/tests/test_debug_0.rs +++ /dev/null @@ -1,10 +0,0 @@ -#![allow(dead_code)] - -extern crate kaitai; -use rust::formats::debug_0::*; - -#[test] -fn basic_parse() { - let r = Debug0::default(); - assert_eq!(*r.one(), 0); -} diff --git a/spec/rust/tests/test_debug_array_user.rs b/spec/rust/tests/test_debug_array_user.rs index 219ef080c..239f258cf 100644 --- a/spec/rust/tests/test_debug_array_user.rs +++ b/spec/rust/tests/test_debug_array_user.rs @@ -1,25 +1,17 @@ -#![allow(dead_code)] use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::debug_array_user::*; #[test] -fn basic_parse() { +fn test_debug_array_user() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = DebugArrayUser::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = DebugArrayUser::read_into(&_io, None, None)?; assert_eq!(*r.one_cat().meow(), 0x50); assert_eq!(*r.array_of_cats()[0].meow(), 0x41); assert_eq!(*r.array_of_cats()[1].meow(), 0x43); assert_eq!(*r.array_of_cats()[2].meow(), 0x4b); - } + Ok(()) +} diff --git a/spec/rust/tests/test_opaque_external_type.rs b/spec/rust/tests/test_opaque_external_type.rs index 3871c8f34..20bf3f557 100644 --- a/spec/rust/tests/test_opaque_external_type.rs +++ b/spec/rust/tests/test_opaque_external_type.rs @@ -1,23 +1,16 @@ use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::opaque_external_type::*; #[test] -fn test_opaque_external_type() { +fn test_opaque_external_type() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = OpaqueExternalType::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = OpaqueExternalType::read_into(&_io, None, None)?; assert_eq!(*r.one().s1(), "foo"); assert_eq!(*r.one().s2(), "bar"); assert_eq!(*r.one().s3(), "|baz@"); + Ok(()) } diff --git a/spec/rust/tests/test_opaque_external_type_02_parent.rs b/spec/rust/tests/test_opaque_external_type_02_parent.rs index d19972f29..84a397039 100644 --- a/spec/rust/tests/test_opaque_external_type_02_parent.rs +++ b/spec/rust/tests/test_opaque_external_type_02_parent.rs @@ -1,23 +1,16 @@ use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::opaque_external_type_02_parent::*; #[test] -fn test_term_strz() { +fn test_opaque_external_type_02_parent() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = OpaqueExternalType02Parent::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = OpaqueExternalType02Parent::read_into(&_io, None, None)?; assert_eq!(*r.parent().child().s1(), "foo"); assert_eq!(*r.parent().child().s2(), "bar"); assert_eq!(*r.parent().child().s3().s3(), "|baz@"); + Ok(()) } diff --git a/spec/rust/tests/test_opaque_with_param.rs b/spec/rust/tests/test_opaque_with_param.rs index 577f10032..b8b1befbc 100644 --- a/spec/rust/tests/test_opaque_with_param.rs +++ b/spec/rust/tests/test_opaque_with_param.rs @@ -1,24 +1,15 @@ use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::opaque_with_param::*; #[test] -fn test_opaque_with_param() { +fn test_opaque_with_param() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = OpaqueWithParam::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = OpaqueWithParam::read_into(&_io, None, None)?; - let one = r.one(); - let p = one; - assert_eq!(*p.buf(), "foo|b"); - assert_eq!(*p.trailer(), 0x61); + assert_eq!(*r.one().buf(), "foo|b"); + assert_eq!(*r.one().trailer(), 0x61); + Ok(()) } diff --git a/spec/rust/tests/test_optional_id.rs b/spec/rust/tests/test_optional_id.rs index 113d49cb3..8abc492a0 100644 --- a/spec/rust/tests/test_optional_id.rs +++ b/spec/rust/tests/test_optional_id.rs @@ -1,24 +1,16 @@ -#![allow(dead_code)] use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::optional_id::*; #[test] -fn basic_parse() { +fn test_optional_id() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = OptionalId::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = OptionalId::read_into(&_io, None, None)?; assert_eq!(*r.unnamed0(), 80); assert_eq!(*r.unnamed1(), 65); assert_eq!(*r.unnamed2(), vec![0x43, 0x4B, 0x2D, 0x31, 0xFF]); + Ok(()) } diff --git a/spec/rust/tests/test_params_def.rs b/spec/rust/tests/test_params_def.rs index 30b525f9f..a366ef4d5 100644 --- a/spec/rust/tests/test_params_def.rs +++ b/spec/rust/tests/test_params_def.rs @@ -1,23 +1,16 @@ use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::params_def::*; #[test] -fn test_params_def() { +fn test_params_def() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let f = |t: &mut ParamsDef| Ok(t.set_params(5, true)); - let res = ParamsDef::read_into_with_init(&_io, None, None, &f); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ParamsDef::read_into_with_init(&_io, None, None, &f)?; assert_eq!(*r.buf(), "foo|b"); assert_eq!(*r.trailer(), 0x61); + Ok(()) } diff --git a/spec/rust/tests/test_str_literals.rs b/spec/rust/tests/test_str_literals.rs index 822a6bae4..48e9efeef 100644 --- a/spec/rust/tests/test_str_literals.rs +++ b/spec/rust/tests/test_str_literals.rs @@ -1,35 +1,18 @@ -#![allow(dead_code)] use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::str_literals::*; #[test] -fn basic_parse() { +fn test_str_literals() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = StrLiterals::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - let backslashes = r.backslashes().unwrap(); - assert_eq!("\u{005c}\u{005c}\u{005c}", *backslashes); - - let octal_eatup = r.octal_eatup().unwrap(); - assert_eq!("\u{0}\u{0032}\u{0032}", *octal_eatup); - - let octal_eatup2 = r.octal_eatup2().unwrap(); - assert_eq!("\u{2}\u{32}", *octal_eatup2); - - let double_quotes = r.double_quotes().unwrap(); - assert_eq!("\u{22}\u{22}\u{22}", *double_quotes); + let r: OptRc = StrLiterals::read_into(&_io, None, None)?; - let complex_str = r.complex_str().unwrap(); - assert_eq!("\u{0}\u{1}\u{2}\u{7}\u{8}\u{0a}\u{0d}\u{09}\u{0b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}", *complex_str); -} \ No newline at end of file + assert_eq!(*r.complex_str()?, "\u{0}\u{1}\u{2}\u{7}\u{8}\u{a}\u{d}\u{9}\u{b}\u{c}\u{1b}\u{3d}\u{7}\u{a}\u{24}\u{263b}"); + assert_eq!(*r.double_quotes()?, "\u{22}\u{22}\u{22}"); + assert_eq!(*r.backslashes()?, "\u{5c}\u{5c}\u{5c}"); + assert_eq!(*r.octal_eatup()?, "\u{0}\u{32}\u{32}"); + assert_eq!(*r.octal_eatup2()?, "\u{2}\u{32}"); + Ok(()) +} diff --git a/spec/rust/tests/test_switch_cast.rs b/spec/rust/tests/test_switch_cast.rs index 85615b350..ad1637dfa 100644 --- a/spec/rust/tests/test_switch_cast.rs +++ b/spec/rust/tests/test_switch_cast.rs @@ -1,54 +1,16 @@ -#![allow(dead_code)] use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::switch_cast::*; #[test] -fn basic_parse() { +#[should_panic(expected = "expected SwitchCast_Opcode_Body::SwitchCast_Strval, got SwitchCast_Intval(")] +fn test_switch_cast() { let bytes = fs::read("../../src/switch_opcodes.bin").unwrap(); let _io = BytesReader::from(bytes); - - let res = SwitchCast::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchCast::read_into(&_io, None, None).unwrap(); assert_eq!("foobar", *r.first_obj().unwrap().value()); assert_eq!(0x42, *r.second_val().unwrap()); - - assert_eq!(4, r.opcodes().len()); - - assert_eq!(0x53, *r.opcodes()[0].code()); - if let Some(SwitchCast_Opcode_Body::SwitchCast_Strval(s)) = r.opcodes()[0].body().as_ref() { - assert_eq!("foobar", *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Strval"); - } - - assert_eq!(0x49, *r.opcodes()[1].code()); - if let Some(SwitchCast_Opcode_Body::SwitchCast_Intval(s)) = r.opcodes()[1].body().as_ref() { - assert_eq!(66, *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Intval"); - } - - assert_eq!(0x49, *r.opcodes()[2].code()); - if let Some(SwitchCast_Opcode_Body::SwitchCast_Intval(s)) = r.opcodes()[2].body().as_ref() { - assert_eq!(55, *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Intval"); - } - - assert_eq!(0x53, *r.opcodes()[3].code()); - if let Some(SwitchCast_Opcode_Body::SwitchCast_Strval(s)) = r.opcodes()[3].body().as_ref() { - assert_eq!("", *s.value()); - } else { - panic!("expected enum SwitchCast_Opcode_Strval"); - }; -} \ No newline at end of file + let _ = r.err_cast(); +} diff --git a/spec/rust/tests/test_switch_manual_enum_invalid.rs b/spec/rust/tests/test_switch_manual_enum_invalid.rs index 257a5ffcf..e2e40e22c 100644 --- a/spec/rust/tests/test_switch_manual_enum_invalid.rs +++ b/spec/rust/tests/test_switch_manual_enum_invalid.rs @@ -1,30 +1,20 @@ -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::switch_manual_enum_invalid::*; #[test] -fn test_switch_manual_enum_invalid() { +fn test_switch_manual_enum_invalid() -> KResult<()> { let bytes = fs::read("../../src/enum_negative.bin").unwrap(); let _io = BytesReader::from(bytes); - let res: KResult> = - SwitchManualEnumInvalid::read_into(&_io, None, None); - let r: OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = SwitchManualEnumInvalid::read_into(&_io, None, None)?; assert_eq!(r.opcodes().len(), 2); let n: i64 = (&*r.opcodes()[0 as usize].code()).into(); assert_eq!(n, 255); - assert_eq!(r.opcodes()[0 as usize].body().is_none(), true); + assert!(r.opcodes()[0 as usize].body().is_none()); let n: i64 = (&*r.opcodes()[1 as usize].code()).into(); assert_eq!(n, 1); - assert_eq!(r.opcodes()[1 as usize].body().is_none(), true); + assert!(r.opcodes()[1 as usize].body().is_none()); + Ok(()) } diff --git a/spec/rust/tests/test_to_string_custom.rs b/spec/rust/tests/test_to_string_custom.rs index 2f5810e42..5c50be223 100644 --- a/spec/rust/tests/test_to_string_custom.rs +++ b/spec/rust/tests/test_to_string_custom.rs @@ -1,22 +1,14 @@ -#![allow(dead_code)] use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::to_string_custom::*; #[test] -fn basic_parse() { +fn test_to_string_custom() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = ToStringCustom::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = ToStringCustom::read_into(&_io, None, None)?; assert_eq!(r.to_string(), "s1 = foo, s2 = bar"); + Ok(()) } diff --git a/spec/rust/tests/test_type_ternary_opaque.rs b/spec/rust/tests/test_type_ternary_opaque.rs index 2a9e21b88..b37a99c7a 100644 --- a/spec/rust/tests/test_type_ternary_opaque.rs +++ b/spec/rust/tests/test_type_ternary_opaque.rs @@ -1,24 +1,16 @@ use std::fs; - extern crate kaitai; use self::kaitai::*; use rust::formats::type_ternary_opaque::*; #[test] -fn test_type_ternary_opaque() { +fn test_type_ternary_opaque() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); - let res = TypeTernaryOpaque::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } + let r: OptRc = TypeTernaryOpaque::read_into(&_io, None, None)?; - let dif = r.dif().unwrap(); - assert_eq!(*dif.s1(), "foo"); - assert_eq!(*dif.s2(), "bar"); - assert_eq!(*dif.s3(), "|baz@"); + assert_eq!(*r.dif()?.s1(), "foo"); + assert_eq!(*r.dif()?.s2(), "bar"); + assert_eq!(*r.dif()?.s3(), "|baz@"); + Ok(()) } From bf66bbefe71e36903321cb0b0aeeb6853e5dd3f5 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 1 Jul 2024 19:00:09 +0200 Subject: [PATCH 188/198] Rust: don't suppress the `overflowing_literals` error This breaks the YamlInts test, which is correct because it should be failing. All of the checked value instances (`test_{u4,u8}_{dec,hex}`) have type `i32` in the `compiled/rust/yaml_ints.rs` file generated by KSC, but that's wrong because none of the integer constants that these value instances should contain according to `formats/yaml_ints.ksy` fit within the `i32` range (which the Rust compiler, i.e. `rustc`, correctly reports as long as the `overflowing_literals` lint is enabled, which is the default). So the fact that this test now fails reflects reality. --- builder/rust_builder.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb index 26b12731f..48a131357 100644 --- a/builder/rust_builder.rb +++ b/builder/rust_builder.rb @@ -42,7 +42,6 @@ def create_project(mand_files, disp_files) File.open(@spec_list_file, 'w') { |f| f.puts '#![allow(unused_variables)]' f.puts '#![allow(unused_assignments)]' - f.puts '#![allow(overflowing_literals)]' grouped_files[:spec].each { |fn| f.puts "pub mod #{File.basename(fn, '.rs')};" } } File.open(@formats_list_file, 'w') { |f| From 04358b9f3bb989ff6f358f9454de9e5f53993fd0 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 1 Jul 2024 21:04:32 +0200 Subject: [PATCH 189/198] Rust: delete specs of old removed tests --- spec/rust/tests/test_cast_to_imported.rs | 27 ----------------------- spec/rust/tests/test_enum_import.rs | 28 ------------------------ 2 files changed, 55 deletions(-) delete mode 100644 spec/rust/tests/test_cast_to_imported.rs delete mode 100644 spec/rust/tests/test_enum_import.rs diff --git a/spec/rust/tests/test_cast_to_imported.rs b/spec/rust/tests/test_cast_to_imported.rs deleted file mode 100644 index 748311cec..000000000 --- a/spec/rust/tests/test_cast_to_imported.rs +++ /dev/null @@ -1,27 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] -use std::fs; -extern crate kaitai; -use self::kaitai::*; -use rust::formats::cast_to_imported::*; -use rust::formats::hello_world::*; - -#[test] -fn test_cast_to_imported() { - let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res: KResult> = CastToImported::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.one().one(), 80); - assert_eq!(*r.one_casted().expect("error reading").one(), 80); -} diff --git a/spec/rust/tests/test_enum_import.rs b/spec/rust/tests/test_enum_import.rs deleted file mode 100644 index 925beb8a8..000000000 --- a/spec/rust/tests/test_enum_import.rs +++ /dev/null @@ -1,28 +0,0 @@ -// Autogenerated from KST: please remove this line if doing any edits by hand! - -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] -use std::fs; -extern crate kaitai; -use self::kaitai::*; -use rust::formats::enum_import::*; -use rust::formats::enum_0::*; -use rust::formats::enum_deep::*; - -#[test] -fn test_enum_import() { - let bytes = fs::read("../../src/enum_0.bin").unwrap(); - let _io = BytesReader::from(bytes); - let res: KResult> = EnumImport::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - panic!("{:?}", err); - } else { - r = res.unwrap(); - } - - assert_eq!(*r.pet_1(), Enum0_Animal::Cat); - assert_eq!(*r.pet_2(), EnumDeep_Container1_Container2_Animal::Hare); -} From e1a79bc7db5be745542055e7943bfd865b024f37 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 2 Jul 2024 13:42:01 +0200 Subject: [PATCH 190/198] Rust: regen recently added positive tests from KST --- spec/rust/tests/test_enum_import_literals.rs | 19 +++++++++++++++ spec/rust/tests/test_enum_import_seq.rs | 19 +++++++++++++++ spec/rust/tests/test_expr_fstring_0.rs | 24 +++++++++++++++++++ spec/rust/tests/test_expr_io_ternary.rs | 18 ++++++++++++++ .../tests/test_imports_cast_to_imported.rs | 17 +++++++++++++ .../tests/test_imports_cast_to_imported2.rs | 17 +++++++++++++ ...orts_params_def_array_usertype_imported.rs | 20 ++++++++++++++++ .../test_imports_params_def_enum_imported.rs | 21 ++++++++++++++++ ...st_imports_params_def_usertype_imported.rs | 17 +++++++++++++ spec/rust/tests/test_nav_parent_recursive.rs | 19 +++++++++++++++ .../rust/tests/test_nav_parent_switch_cast.rs | 18 ++++++++++++++ spec/rust/tests/test_nav_root_recursive.rs | 19 +++++++++++++++ spec/rust/tests/test_params_call.rs | 18 ++++++++++++++ .../tests/test_params_pass_array_struct.rs | 18 ++++++++++++++ spec/rust/tests/test_params_pass_struct.rs | 19 +++++++++++++++ spec/rust/tests/test_str_pad_term_utf16.rs | 18 ++++++++++++++ spec/rust/tests/test_term_strz_utf16_v1.rs | 19 +++++++++++++++ spec/rust/tests/test_term_strz_utf16_v2.rs | 18 ++++++++++++++ spec/rust/tests/test_term_strz_utf16_v3.rs | 19 +++++++++++++++ spec/rust/tests/test_term_strz_utf16_v4.rs | 18 ++++++++++++++ 20 files changed, 375 insertions(+) create mode 100644 spec/rust/tests/test_enum_import_literals.rs create mode 100644 spec/rust/tests/test_enum_import_seq.rs create mode 100644 spec/rust/tests/test_expr_fstring_0.rs create mode 100644 spec/rust/tests/test_expr_io_ternary.rs create mode 100644 spec/rust/tests/test_imports_cast_to_imported.rs create mode 100644 spec/rust/tests/test_imports_cast_to_imported2.rs create mode 100644 spec/rust/tests/test_imports_params_def_array_usertype_imported.rs create mode 100644 spec/rust/tests/test_imports_params_def_enum_imported.rs create mode 100644 spec/rust/tests/test_imports_params_def_usertype_imported.rs create mode 100644 spec/rust/tests/test_nav_parent_recursive.rs create mode 100644 spec/rust/tests/test_nav_parent_switch_cast.rs create mode 100644 spec/rust/tests/test_nav_root_recursive.rs create mode 100644 spec/rust/tests/test_params_call.rs create mode 100644 spec/rust/tests/test_params_pass_array_struct.rs create mode 100644 spec/rust/tests/test_params_pass_struct.rs create mode 100644 spec/rust/tests/test_str_pad_term_utf16.rs create mode 100644 spec/rust/tests/test_term_strz_utf16_v1.rs create mode 100644 spec/rust/tests/test_term_strz_utf16_v2.rs create mode 100644 spec/rust/tests/test_term_strz_utf16_v3.rs create mode 100644 spec/rust/tests/test_term_strz_utf16_v4.rs diff --git a/spec/rust/tests/test_enum_import_literals.rs b/spec/rust/tests/test_enum_import_literals.rs new file mode 100644 index 000000000..61f8a6686 --- /dev/null +++ b/spec/rust/tests/test_enum_import_literals.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::enum_import_literals::*; +use rust::formats::enum_deep::*; + +#[test] +fn test_enum_import_literals() -> KResult<()> { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = EnumImportLiterals::read_into(&_io, None, None)?; + + assert_eq!(*r.pet_1_to_i()?, 7); + assert_eq!(*r.pet_1_eq()?, true); + assert_eq!(*r.pet_2()?, EnumDeep_Container1_Container2_Animal::Hare); + Ok(()) +} diff --git a/spec/rust/tests/test_enum_import_seq.rs b/spec/rust/tests/test_enum_import_seq.rs new file mode 100644 index 000000000..92e4fbf34 --- /dev/null +++ b/spec/rust/tests/test_enum_import_seq.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::enum_import_seq::*; +use rust::formats::enum_0::*; +use rust::formats::enum_deep::*; + +#[test] +fn test_enum_import_seq() -> KResult<()> { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = EnumImportSeq::read_into(&_io, None, None)?; + + assert_eq!(*r.pet_1(), Enum0_Animal::Cat); + assert_eq!(*r.pet_2(), EnumDeep_Container1_Container2_Animal::Hare); + Ok(()) +} diff --git a/spec/rust/tests/test_expr_fstring_0.rs b/spec/rust/tests/test_expr_fstring_0.rs new file mode 100644 index 000000000..3dcccd777 --- /dev/null +++ b/spec/rust/tests/test_expr_fstring_0.rs @@ -0,0 +1,24 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::expr_fstring_0::*; + +#[test] +fn test_expr_fstring_0() -> KResult<()> { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ExprFstring0::read_into(&_io, None, None)?; + + assert_eq!(*r.seq_str(), "foo|b"); + assert_eq!(*r.seq_int(), 97); + assert_eq!(*r.empty()?, ""); + assert_eq!(*r.literal()?, "abc"); + assert_eq!(*r.literal_with_escapes()?, "abc\n\tt"); + assert_eq!(*r.head_and_int_literal()?, "abc=123"); + assert_eq!(*r.head_and_str_literal()?, "abc=foo"); + assert_eq!(*r.head_and_int()?, "abc=97"); + assert_eq!(*r.head_and_str()?, "abc=foo|b"); + Ok(()) +} diff --git a/spec/rust/tests/test_expr_io_ternary.rs b/spec/rust/tests/test_expr_io_ternary.rs new file mode 100644 index 000000000..5dc3fbcca --- /dev/null +++ b/spec/rust/tests/test_expr_io_ternary.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::expr_io_ternary::*; + +#[test] +fn test_expr_io_ternary() -> KResult<()> { + let bytes = fs::read("../../src/if_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ExprIoTernary::read_into(&_io, None, None)?; + + assert_eq!(*r.one_or_two_io_size1()?, 8); + assert_eq!(*r.one_or_two_io_size2()?, 8); + assert_eq!(*r.one_or_two_io_size_add_3()?, 11); + Ok(()) +} diff --git a/spec/rust/tests/test_imports_cast_to_imported.rs b/spec/rust/tests/test_imports_cast_to_imported.rs new file mode 100644 index 000000000..4309da29a --- /dev/null +++ b/spec/rust/tests/test_imports_cast_to_imported.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::imports_cast_to_imported::*; + +#[test] +fn test_imports_cast_to_imported() -> KResult<()> { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ImportsCastToImported::read_into(&_io, None, None)?; + + assert_eq!(*r.hw().one(), 236); + assert_eq!(*r.two().hw_one()?, 236); + Ok(()) +} diff --git a/spec/rust/tests/test_imports_cast_to_imported2.rs b/spec/rust/tests/test_imports_cast_to_imported2.rs new file mode 100644 index 000000000..44fe73fc2 --- /dev/null +++ b/spec/rust/tests/test_imports_cast_to_imported2.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::imports_cast_to_imported2::*; + +#[test] +fn test_imports_cast_to_imported2() -> KResult<()> { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ImportsCastToImported2::read_into(&_io, None, None)?; + + assert_eq!(*r.hw().one(), 236); + assert_eq!(*r.two().hw()?.one(), 236); + Ok(()) +} diff --git a/spec/rust/tests/test_imports_params_def_array_usertype_imported.rs b/spec/rust/tests/test_imports_params_def_array_usertype_imported.rs new file mode 100644 index 000000000..da3eedfde --- /dev/null +++ b/spec/rust/tests/test_imports_params_def_array_usertype_imported.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::imports_params_def_array_usertype_imported::*; + +#[test] +fn test_imports_params_def_array_usertype_imported() -> KResult<()> { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ImportsParamsDefArrayUsertypeImported::read_into(&_io, None, None)?; + + assert_eq!(r.hws().len(), 2); + assert_eq!(*r.hws()[0 as usize].one(), 236); + assert_eq!(*r.hws()[1 as usize].one(), 187); + assert_eq!(*r.two().hw0_one()?, 236); + assert_eq!(*r.two().hw1_one()?, 187); + Ok(()) +} diff --git a/spec/rust/tests/test_imports_params_def_enum_imported.rs b/spec/rust/tests/test_imports_params_def_enum_imported.rs new file mode 100644 index 000000000..eeb4cc911 --- /dev/null +++ b/spec/rust/tests/test_imports_params_def_enum_imported.rs @@ -0,0 +1,21 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::imports_params_def_enum_imported::*; +use rust::formats::enum_0::*; +use rust::formats::enum_deep::*; + +#[test] +fn test_imports_params_def_enum_imported() -> KResult<()> { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ImportsParamsDefEnumImported::read_into(&_io, None, None)?; + + assert_eq!(*r.one().pet_1(), Enum0_Animal::Cat); + assert_eq!(*r.one().pet_2(), EnumDeep_Container1_Container2_Animal::Hare); + assert_eq!(*r.two().pet_1_param(), Enum0_Animal::Cat); + assert_eq!(*r.two().pet_2_param(), EnumDeep_Container1_Container2_Animal::Hare); + Ok(()) +} diff --git a/spec/rust/tests/test_imports_params_def_usertype_imported.rs b/spec/rust/tests/test_imports_params_def_usertype_imported.rs new file mode 100644 index 000000000..46faf20ad --- /dev/null +++ b/spec/rust/tests/test_imports_params_def_usertype_imported.rs @@ -0,0 +1,17 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::imports_params_def_usertype_imported::*; + +#[test] +fn test_imports_params_def_usertype_imported() -> KResult<()> { + let bytes = fs::read("../../src/process_xor_4.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ImportsParamsDefUsertypeImported::read_into(&_io, None, None)?; + + assert_eq!(*r.hw().one(), 236); + assert_eq!(*r.two().hw_one()?, 236); + Ok(()) +} diff --git a/spec/rust/tests/test_nav_parent_recursive.rs b/spec/rust/tests/test_nav_parent_recursive.rs new file mode 100644 index 000000000..aa24f9886 --- /dev/null +++ b/spec/rust/tests/test_nav_parent_recursive.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::nav_parent_recursive::*; + +#[test] +fn test_nav_parent_recursive() -> KResult<()> { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = NavParentRecursive::read_into(&_io, None, None)?; + + assert_eq!(*r.value(), 255); + assert_eq!(*r.next().value(), 1); + assert_eq!(*r.next().parent_value()?, 255); + assert!(r.next().next().is_none()); + Ok(()) +} diff --git a/spec/rust/tests/test_nav_parent_switch_cast.rs b/spec/rust/tests/test_nav_parent_switch_cast.rs new file mode 100644 index 000000000..f81c930f4 --- /dev/null +++ b/spec/rust/tests/test_nav_parent_switch_cast.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::nav_parent_switch_cast::*; + +#[test] +fn test_nav_parent_switch_cast() -> KResult<()> { + let bytes = fs::read("../../src/switch_integers.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = NavParentSwitchCast::read_into(&_io, None, None)?; + + assert_eq!(*r.main().buf_type(), 1); + assert_eq!(*r.main().flag(), 7); + assert_eq!(*Into::>::into(&*r.main().buf().as_ref().unwrap()).branch().flag()?, 7); + Ok(()) +} diff --git a/spec/rust/tests/test_nav_root_recursive.rs b/spec/rust/tests/test_nav_root_recursive.rs new file mode 100644 index 000000000..42f08335f --- /dev/null +++ b/spec/rust/tests/test_nav_root_recursive.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::nav_root_recursive::*; + +#[test] +fn test_nav_root_recursive() -> KResult<()> { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = NavRootRecursive::read_into(&_io, None, None)?; + + assert_eq!(*r.value(), 255); + assert_eq!(*r.next().value(), 1); + assert_eq!(*r.next().root_value()?, 255); + assert!(r.next().next().is_none()); + Ok(()) +} diff --git a/spec/rust/tests/test_params_call.rs b/spec/rust/tests/test_params_call.rs new file mode 100644 index 000000000..16170785b --- /dev/null +++ b/spec/rust/tests/test_params_call.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::params_call::*; + +#[test] +fn test_params_call() -> KResult<()> { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ParamsCall::read_into(&_io, None, None)?; + + assert_eq!(*r.buf1().body(), "foo|b"); + assert_eq!(*r.buf2().body(), "ar|ba"); + assert_eq!(*r.buf2().trailer(), 122); + Ok(()) +} diff --git a/spec/rust/tests/test_params_pass_array_struct.rs b/spec/rust/tests/test_params_pass_array_struct.rs new file mode 100644 index 000000000..c452043f7 --- /dev/null +++ b/spec/rust/tests/test_params_pass_array_struct.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::params_pass_array_struct::*; + +#[test] +fn test_params_pass_array_struct() -> KResult<()> { + let bytes = fs::read("../../src/position_to_end.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ParamsPassArrayStruct::read_into(&_io, None, None)?; + + assert_eq!(r.pass_structs().structs().len(), 2); + assert_eq!(*Into::>::into(&r.pass_structs().structs()[0 as usize]).f(), 1); + assert_eq!(*Into::>::into(&r.pass_structs().structs()[1 as usize]).b(), 2); + Ok(()) +} diff --git a/spec/rust/tests/test_params_pass_struct.rs b/spec/rust/tests/test_params_pass_struct.rs new file mode 100644 index 000000000..c2c10a13b --- /dev/null +++ b/spec/rust/tests/test_params_pass_struct.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::params_pass_struct::*; + +#[test] +fn test_params_pass_struct() -> KResult<()> { + let bytes = fs::read("../../src/enum_negative.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = ParamsPassStruct::read_into(&_io, None, None)?; + + assert_eq!(*r.first().foo(), 255); + assert_eq!(*r.one().bar().qux(), 1); + assert_eq!(*Into::>::into(&*r.one().foo()).foo(), 255); + assert_eq!(*Into::>::into(&*r.one().bar().foo()).foo(), 255); + Ok(()) +} diff --git a/spec/rust/tests/test_str_pad_term_utf16.rs b/spec/rust/tests/test_str_pad_term_utf16.rs new file mode 100644 index 000000000..50993aae0 --- /dev/null +++ b/spec/rust/tests/test_str_pad_term_utf16.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::str_pad_term_utf16::*; + +#[test] +fn test_str_pad_term_utf16() -> KResult<()> { + let bytes = fs::read("../../src/str_pad_term_utf16.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = StrPadTermUtf16::read_into(&_io, None, None)?; + + assert_eq!(*r.str_term(), "a\u{200}b"); + assert_eq!(*r.str_term_include(), "c\u{200}d\u{0}"); + assert_eq!(*r.str_term_and_pad(), "e\u{200}f"); + Ok(()) +} diff --git a/spec/rust/tests/test_term_strz_utf16_v1.rs b/spec/rust/tests/test_term_strz_utf16_v1.rs new file mode 100644 index 000000000..f76432a9f --- /dev/null +++ b/spec/rust/tests/test_term_strz_utf16_v1.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::term_strz_utf16_v1::*; + +#[test] +fn test_term_strz_utf16_v1() -> KResult<()> { + let bytes = fs::read("../../src/term_strz_utf16.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = TermStrzUtf16V1::read_into(&_io, None, None)?; + + assert_eq!(*r.s1(), "a\u{200}b"); + assert_eq!(*r.s2(), "c\u{200}d"); + assert_eq!(*r.term(), 0); + assert_eq!(*r.s3(), "e\u{200}f\u{0}"); + Ok(()) +} diff --git a/spec/rust/tests/test_term_strz_utf16_v2.rs b/spec/rust/tests/test_term_strz_utf16_v2.rs new file mode 100644 index 000000000..6d845c1b6 --- /dev/null +++ b/spec/rust/tests/test_term_strz_utf16_v2.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::term_strz_utf16_v2::*; + +#[test] +fn test_term_strz_utf16_v2() -> KResult<()> { + let bytes = fs::read("../../src/term_strz_utf16.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = TermStrzUtf16V2::read_into(&_io, None, None)?; + + assert_eq!(*r.s1(), "a\u{200}b"); + assert_eq!(*r.s2(), "c\u{200}d\u{0}"); + assert_eq!(*r.s3(), "e\u{200}f"); + Ok(()) +} diff --git a/spec/rust/tests/test_term_strz_utf16_v3.rs b/spec/rust/tests/test_term_strz_utf16_v3.rs new file mode 100644 index 000000000..861e1e8bf --- /dev/null +++ b/spec/rust/tests/test_term_strz_utf16_v3.rs @@ -0,0 +1,19 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::term_strz_utf16_v3::*; + +#[test] +fn test_term_strz_utf16_v3() -> KResult<()> { + let bytes = fs::read("../../src/term_strz_utf16.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = TermStrzUtf16V3::read_into(&_io, None, None)?; + + assert_eq!(*r.s1(), "a\u{200}b"); + assert_eq!(*r.term(), 0); + assert_eq!(*r.s2(), "c\u{200}d"); + assert_eq!(*r.s3(), ""); + Ok(()) +} diff --git a/spec/rust/tests/test_term_strz_utf16_v4.rs b/spec/rust/tests/test_term_strz_utf16_v4.rs new file mode 100644 index 000000000..cfc9b25ad --- /dev/null +++ b/spec/rust/tests/test_term_strz_utf16_v4.rs @@ -0,0 +1,18 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::term_strz_utf16_v4::*; + +#[test] +fn test_term_strz_utf16_v4() -> KResult<()> { + let bytes = fs::read("../../src/term_strz_utf16.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = TermStrzUtf16V4::read_into(&_io, None, None)?; + + assert_eq!(*r.s1().value(), "a\u{200}b"); + assert_eq!(*r.s2().value(), "c\u{200}d"); + assert_eq!(*r.s3().value(), "e\u{200}f"); + Ok(()) +} From 78b406e164e7791be0c0e45c2b1ca699d928c42e Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 2 Jul 2024 13:49:49 +0200 Subject: [PATCH 191/198] Port NestedTypesImport to Rust --- spec/rust/tests/test_nested_types_import.rs | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spec/rust/tests/test_nested_types_import.rs diff --git a/spec/rust/tests/test_nested_types_import.rs b/spec/rust/tests/test_nested_types_import.rs new file mode 100644 index 000000000..41edef086 --- /dev/null +++ b/spec/rust/tests/test_nested_types_import.rs @@ -0,0 +1,24 @@ +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::nested_types_import::*; + +#[test] +fn test_nested_types_import() -> KResult<()> { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = NestedTypesImport::read_into(&_io, None, None)?; + + assert_eq!(*r.a_cc().value_cc(), 80); + assert_eq!(*r.a_c_d().value_d(), 65); + assert_eq!(*r.b().value_b(), 67); + assert_eq!(*r.b().a_cc().value_cc(), 75); + assert_eq!(*r.b().a_c_d().value_d(), 45); + assert!(r.a_cc()._parent.get_value().borrow().upgrade().is_none()); + assert!(r.a_cc()._root.get_value().borrow().upgrade().is_none()); + assert!(r.a_c_d()._parent.get_value().borrow().upgrade().is_none()); + assert!(r.a_c_d()._root.get_value().borrow().upgrade().is_none()); + assert!(r.b()._parent.get_value().borrow().upgrade().is_none()); + assert!(r.b()._root.get_value().borrow().upgrade().is_none()); + Ok(()) +} From a4d569b5b00debad3741015807f40ad74250031b Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 1 Sep 2024 14:16:42 +0200 Subject: [PATCH 192/198] Rust: adapt custom decoders to runtime library changes --- spec/rust/src/custom_fx.rs | 4 ++-- spec/rust/src/custom_fx_no_args.rs | 4 ++-- spec/rust/src/my_custom_fx.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/rust/src/custom_fx.rs b/spec/rust/src/custom_fx.rs index d4d218fc3..b3bfe6d6a 100644 --- a/spec/rust/src/custom_fx.rs +++ b/spec/rust/src/custom_fx.rs @@ -13,11 +13,11 @@ pub mod Nested { } impl kaitai::CustomDecoder for CustomFx { - fn decode(&self, bytes: &[u8]) -> Vec { + fn decode(&self, bytes: &[u8]) -> Result, String> { let mut res = bytes.to_vec(); res.insert(0, '_' as u8); res.push('_' as u8); - res + Ok(res) } } } diff --git a/spec/rust/src/custom_fx_no_args.rs b/spec/rust/src/custom_fx_no_args.rs index 90cc58c5f..25fa080b7 100644 --- a/spec/rust/src/custom_fx_no_args.rs +++ b/spec/rust/src/custom_fx_no_args.rs @@ -11,10 +11,10 @@ impl CustomFxNoArgs { } impl CustomDecoder for CustomFxNoArgs { - fn decode(&self, bytes: &[u8]) -> Vec { + fn decode(&self, bytes: &[u8]) -> Result, String> { let mut res = bytes.to_vec(); res.insert(0, '_' as u8); res.push('_' as u8); - res + Ok(res) } } diff --git a/spec/rust/src/my_custom_fx.rs b/spec/rust/src/my_custom_fx.rs index 787d33020..0b88c7ddf 100644 --- a/spec/rust/src/my_custom_fx.rs +++ b/spec/rust/src/my_custom_fx.rs @@ -18,11 +18,11 @@ impl MyCustomFx { } impl CustomDecoder for MyCustomFx { - fn decode(&self, bytes: &[u8]) -> Vec { + fn decode(&self, bytes: &[u8]) -> Result, String> { let mut res = bytes.to_vec(); for i in res.iter_mut() { *i = (*i as i32 + self.key) as u8; } - res + Ok(res) } } From 855697d764bfd60c1f4d5925232d1c7e7b7cedf2 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 1 Sep 2024 19:08:28 +0200 Subject: [PATCH 193/198] RustSG: add support for asserting specific errors --- .../specgenerators/RustSG.scala | 43 +++++++++++++------ 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala index 532ace2c4..1cb0175d2 100644 --- a/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala +++ b/translator/src/main/scala/io/kaitai/struct/testtranslator/specgenerators/RustSG.scala @@ -1,7 +1,7 @@ package io.kaitai.struct.testtranslator.specgenerators import _root_.io.kaitai.struct.{ClassTypeProvider, JSON, RuntimeConfig} -import _root_.io.kaitai.struct.datatype.{DataType, KSError} +import _root_.io.kaitai.struct.datatype.{DataType, EndOfStreamError, KSError, UndecidedEndiannessError, ValidationError} import _root_.io.kaitai.struct.exprlang.Ast import _root_.io.kaitai.struct.languages.RustCompiler import _root_.io.kaitai.struct.testtranslator.{Main, TestAssert, TestEquals, TestSpec} @@ -12,7 +12,6 @@ import io.kaitai.struct.testtranslator.{Main, TestAssert, TestSpec} class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator(spec) { val className: String = RustCompiler.type2class(spec.id) val translator = new RustTranslator(provider, RuntimeConfig()) - val compiler = new RustCompiler(provider, RuntimeConfig()) override def fileName(name: String): String = s"tests/test_$name.rs" @@ -37,16 +36,7 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( override def runParseExpectError(exception: KSError): Unit = { out.puts(s"let res: KResult> = $className::read_into(&_io, None, None);") - out.puts - out.puts(s"if let Err(err) = res {") - out.inc - out.puts(s"""println!("expected err: {:?}, exception: $exception", err);""") - out.dec - out.puts("} else {") - out.inc - out.puts(s"""panic!("no expected exception: $exception");""") - out.dec - out.puts("}") + exceptionAssert("res", exception) } override def footer(): Unit = { @@ -79,8 +69,10 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( } override def testException(actual: Ast.expr, exception: KSError): Unit = { - val s = translator.remove_deref(translateAct(actual).replace(")?", ").unwrap_err()")) - out.puts(s"assert_eq!($s, ${compiler.ksErrorName(exception)});") + val actStr = translateAct(actual) + require(actStr.endsWith(")?"), s"$actStr does not end with )?") + val s = translator.remove_deref(actStr.stripSuffix(")?") + ")") + exceptionAssert(s, exception) } override def indentStr: String = " " @@ -93,4 +85,27 @@ class RustSG(spec: TestSpec, provider: ClassTypeProvider) extends BaseGenerator( def translateAct(x: Ast.expr): String = translator.translate(x).replace(s"self.${Main.INIT_OBJ_NAME}()", "r") + + private def exceptionAssert(actualStr: String, exception: KSError): Unit = { + out.puts(s"""let err = $actualStr.expect_err("expected Err representing $exception, but got Ok");""") + val errorName = RustCompiler.ksErrorName(exception) + val expectedErrPattern = exception match { + case EndOfStreamError | UndecidedEndiannessError => + s"$errorName { .. }" + case err: ValidationError => + val validationKind = RustCompiler.validationErrorKind(err) + s"$errorName(ValidationFailedError { kind: $validationKind, .. })" + case _ => + out.puts(s"assert_eq!(err, $errorName);") + return + } + val expectedErrPatternStr = translator.translate(Ast.expr.Str(expectedErrPattern)) + out.puts("assert!(") + out.inc + out.puts(s"matches!(err, $expectedErrPattern),") + out.puts("\"expected: {}\\n but got: {:?}\",") + out.puts(s"$expectedErrPatternStr, err") + out.dec + out.puts(");") + } } From 680639fe48e06744e6d51cb9a7e385853b1c291c Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 1 Sep 2024 19:09:38 +0200 Subject: [PATCH 194/198] Rust: regen negative tests from KST --- .../test_default_endian_expr_exception.rs | 19 ++++++++---------- spec/rust/tests/test_eof_exception_bytes.rs | 19 ++++++++---------- spec/rust/tests/test_eof_exception_sized.rs | 20 +++++++++++++++++++ spec/rust/tests/test_eof_exception_u4.rs | 19 ++++++++---------- spec/rust/tests/test_eos_exception_bytes.rs | 19 ++++++++---------- spec/rust/tests/test_eos_exception_sized.rs | 20 +++++++++++++++++++ spec/rust/tests/test_eos_exception_u4.rs | 19 ++++++++---------- spec/rust/tests/test_expr_to_i_trailing.rs | 6 ++++-- spec/rust/tests/test_valid_fail_anyof_int.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_contents.rs | 19 ++++++++---------- .../tests/test_valid_fail_contents_inst.rs | 20 +++++++++++++++++++ spec/rust/tests/test_valid_fail_eq_bytes.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_eq_int.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_eq_str.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_expr.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_in_enum.rs | 20 +++++++++++++++++++ spec/rust/tests/test_valid_fail_inst.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_max_int.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_min_int.rs | 19 ++++++++---------- .../rust/tests/test_valid_fail_range_bytes.rs | 19 ++++++++---------- .../rust/tests/test_valid_fail_range_float.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_range_int.rs | 19 ++++++++---------- spec/rust/tests/test_valid_fail_range_str.rs | 19 ++++++++---------- .../tests/test_valid_fail_repeat_anyof_int.rs | 20 +++++++++++++++++++ .../tests/test_valid_fail_repeat_contents.rs | 20 +++++++++++++++++++ .../tests/test_valid_fail_repeat_eq_int.rs | 20 +++++++++++++++++++ .../rust/tests/test_valid_fail_repeat_expr.rs | 20 +++++++++++++++++++ .../rust/tests/test_valid_fail_repeat_inst.rs | 20 +++++++++++++++++++ .../tests/test_valid_fail_repeat_max_int.rs | 20 +++++++++++++++++++ .../tests/test_valid_fail_repeat_min_int.rs | 20 +++++++++++++++++++ 30 files changed, 368 insertions(+), 200 deletions(-) create mode 100644 spec/rust/tests/test_eof_exception_sized.rs create mode 100644 spec/rust/tests/test_eos_exception_sized.rs create mode 100644 spec/rust/tests/test_valid_fail_contents_inst.rs create mode 100644 spec/rust/tests/test_valid_fail_in_enum.rs create mode 100644 spec/rust/tests/test_valid_fail_repeat_anyof_int.rs create mode 100644 spec/rust/tests/test_valid_fail_repeat_contents.rs create mode 100644 spec/rust/tests/test_valid_fail_repeat_eq_int.rs create mode 100644 spec/rust/tests/test_valid_fail_repeat_expr.rs create mode 100644 spec/rust/tests/test_valid_fail_repeat_inst.rs create mode 100644 spec/rust/tests/test_valid_fail_repeat_max_int.rs create mode 100644 spec/rust/tests/test_valid_fail_repeat_min_int.rs diff --git a/spec/rust/tests/test_default_endian_expr_exception.rs b/spec/rust/tests/test_default_endian_expr_exception.rs index 55bc99e37..002c9a229 100644 --- a/spec/rust/tests/test_default_endian_expr_exception.rs +++ b/spec/rust/tests/test_default_endian_expr_exception.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::default_endian_expr_exception::*; #[test] -fn test_default_endian_expr_exception() { +fn test_default_endian_expr_exception() -> KResult<()> { let bytes = fs::read("../../src/endian_expr.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = DefaultEndianExprException::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: UndecidedEndiannessError", err); - } else { - panic!("no expected exception: UndecidedEndiannessError"); - } + let err = res.expect_err("expected Err representing UndecidedEndiannessError, but got Ok"); + assert!( + matches!(err, KError::UndecidedEndianness { .. }), + "expected: {}\n but got: {:?}", + "KError::UndecidedEndianness { .. }", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_eof_exception_bytes.rs b/spec/rust/tests/test_eof_exception_bytes.rs index 916a858b1..ecbfca685 100644 --- a/spec/rust/tests/test_eof_exception_bytes.rs +++ b/spec/rust/tests/test_eof_exception_bytes.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::eof_exception_bytes::*; #[test] -fn test_eof_exception_bytes() { +fn test_eof_exception_bytes() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = EofExceptionBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: EndOfStreamError", err); - } else { - panic!("no expected exception: EndOfStreamError"); - } + let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok"); + assert!( + matches!(err, KError::Eof { .. }), + "expected: {}\n but got: {:?}", + "KError::Eof { .. }", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_eof_exception_sized.rs b/spec/rust/tests/test_eof_exception_sized.rs new file mode 100644 index 000000000..09a318501 --- /dev/null +++ b/spec/rust/tests/test_eof_exception_sized.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::eof_exception_sized::*; + +#[test] +fn test_eof_exception_sized() -> KResult<()> { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EofExceptionSized::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok"); + assert!( + matches!(err, KError::Eof { .. }), + "expected: {}\n but got: {:?}", + "KError::Eof { .. }", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_eof_exception_u4.rs b/spec/rust/tests/test_eof_exception_u4.rs index 9f9c67963..128d85792 100644 --- a/spec/rust/tests/test_eof_exception_u4.rs +++ b/spec/rust/tests/test_eof_exception_u4.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::eof_exception_u4::*; #[test] -fn test_eof_exception_u4() { +fn test_eof_exception_u4() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = EofExceptionU4::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: EndOfStreamError", err); - } else { - panic!("no expected exception: EndOfStreamError"); - } + let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok"); + assert!( + matches!(err, KError::Eof { .. }), + "expected: {}\n but got: {:?}", + "KError::Eof { .. }", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_eos_exception_bytes.rs b/spec/rust/tests/test_eos_exception_bytes.rs index aaa5b80f3..317991d41 100644 --- a/spec/rust/tests/test_eos_exception_bytes.rs +++ b/spec/rust/tests/test_eos_exception_bytes.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::eos_exception_bytes::*; #[test] -fn test_eos_exception_bytes() { +fn test_eos_exception_bytes() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = EosExceptionBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: EndOfStreamError", err); - } else { - panic!("no expected exception: EndOfStreamError"); - } + let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok"); + assert!( + matches!(err, KError::Eof { .. }), + "expected: {}\n but got: {:?}", + "KError::Eof { .. }", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_eos_exception_sized.rs b/spec/rust/tests/test_eos_exception_sized.rs new file mode 100644 index 000000000..ba580389c --- /dev/null +++ b/spec/rust/tests/test_eos_exception_sized.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::eos_exception_sized::*; + +#[test] +fn test_eos_exception_sized() -> KResult<()> { + let bytes = fs::read("../../src/term_strz.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = EosExceptionSized::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok"); + assert!( + matches!(err, KError::Eof { .. }), + "expected: {}\n but got: {:?}", + "KError::Eof { .. }", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_eos_exception_u4.rs b/spec/rust/tests/test_eos_exception_u4.rs index c5519254d..7a1cfd7f1 100644 --- a/spec/rust/tests/test_eos_exception_u4.rs +++ b/spec/rust/tests/test_eos_exception_u4.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::eos_exception_u4::*; #[test] -fn test_eos_exception_u4() { +fn test_eos_exception_u4() -> KResult<()> { let bytes = fs::read("../../src/term_strz.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = EosExceptionU4::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: EndOfStreamError", err); - } else { - panic!("no expected exception: EndOfStreamError"); - } + let err = res.expect_err("expected Err representing EndOfStreamError, but got Ok"); + assert!( + matches!(err, KError::Eof { .. }), + "expected: {}\n but got: {:?}", + "KError::Eof { .. }", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_expr_to_i_trailing.rs b/spec/rust/tests/test_expr_to_i_trailing.rs index 64a8e1123..cd31f1b02 100644 --- a/spec/rust/tests/test_expr_to_i_trailing.rs +++ b/spec/rust/tests/test_expr_to_i_trailing.rs @@ -11,8 +11,10 @@ fn test_expr_to_i_trailing() -> KResult<()> { let _io = BytesReader::from(bytes); let r: OptRc = ExprToITrailing::read_into(&_io, None, None)?; - assert_eq!(r.to_i_r10().unwrap_err(), KError::CastError); + let err = r.to_i_r10().expect_err("expected Err representing ConversionError, but got Ok"); + assert_eq!(err, KError::CastError); assert_eq!(*r.to_i_r16()?, 152517308); - assert_eq!(r.to_i_garbage().unwrap_err(), KError::CastError); + let err = r.to_i_garbage().expect_err("expected Err representing ConversionError, but got Ok"); + assert_eq!(err, KError::CastError); Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_anyof_int.rs b/spec/rust/tests/test_valid_fail_anyof_int.rs index ae790f840..17e91ab12 100644 --- a/spec/rust/tests/test_valid_fail_anyof_int.rs +++ b/spec/rust/tests/test_valid_fail_anyof_int.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_anyof_int::*; #[test] -fn test_valid_fail_anyof_int() { +fn test_valid_fail_anyof_int() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailAnyofInt::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationNotAnyOfError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationNotAnyOfError(Int1Type(false))"); - } + let err = res.expect_err("expected Err representing ValidationNotAnyOfError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotAnyOf, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotAnyOf, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_contents.rs b/spec/rust/tests/test_valid_fail_contents.rs index c7d96430d..5888c0129 100644 --- a/spec/rust/tests/test_valid_fail_contents.rs +++ b/spec/rust/tests/test_valid_fail_contents.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_contents::*; #[test] -fn test_valid_fail_contents() { +fn test_valid_fail_contents() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailContents::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); - } else { - panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); - } + let err = res.expect_err("expected Err representing ValidationNotEqualError(CalcBytesType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_contents_inst.rs b/spec/rust/tests/test_valid_fail_contents_inst.rs new file mode 100644 index 000000000..d9c950963 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_contents_inst.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_contents_inst::*; + +#[test] +fn test_valid_fail_contents_inst() -> KResult<()> { + let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailContentsInst::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationNotEqualError(CalcBytesType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_eq_bytes.rs b/spec/rust/tests/test_valid_fail_eq_bytes.rs index 9d08e70f7..c9eed1b04 100644 --- a/spec/rust/tests/test_valid_fail_eq_bytes.rs +++ b/spec/rust/tests/test_valid_fail_eq_bytes.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_eq_bytes::*; #[test] -fn test_valid_fail_eq_bytes() { +fn test_valid_fail_eq_bytes() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailEqBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationNotEqualError(CalcBytesType)", err); - } else { - panic!("no expected exception: ValidationNotEqualError(CalcBytesType)"); - } + let err = res.expect_err("expected Err representing ValidationNotEqualError(CalcBytesType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_eq_int.rs b/spec/rust/tests/test_valid_fail_eq_int.rs index a9ef983a6..19668e738 100644 --- a/spec/rust/tests/test_valid_fail_eq_int.rs +++ b/spec/rust/tests/test_valid_fail_eq_int.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_eq_int::*; #[test] -fn test_valid_fail_eq_int() { +fn test_valid_fail_eq_int() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailEqInt::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); - } + let err = res.expect_err("expected Err representing ValidationNotEqualError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_eq_str.rs b/spec/rust/tests/test_valid_fail_eq_str.rs index 431831e92..c3c10fd1d 100644 --- a/spec/rust/tests/test_valid_fail_eq_str.rs +++ b/spec/rust/tests/test_valid_fail_eq_str.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_eq_str::*; #[test] -fn test_valid_fail_eq_str() { +fn test_valid_fail_eq_str() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailEqStr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationNotEqualError(CalcStrType)", err); - } else { - panic!("no expected exception: ValidationNotEqualError(CalcStrType)"); - } + let err = res.expect_err("expected Err representing ValidationNotEqualError(CalcStrType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_expr.rs b/spec/rust/tests/test_valid_fail_expr.rs index a03ba538a..8f39118d2 100644 --- a/spec/rust/tests/test_valid_fail_expr.rs +++ b/spec/rust/tests/test_valid_fail_expr.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_expr::*; #[test] -fn test_valid_fail_expr() { +fn test_valid_fail_expr() -> KResult<()> { let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailExpr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationExprError(IntMultiType(true,Width2,None))", err); - } else { - panic!("no expected exception: ValidationExprError(IntMultiType(true,Width2,None))"); - } + let err = res.expect_err("expected Err representing ValidationExprError(IntMultiType(true,Width2,None)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::Expr, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::Expr, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_in_enum.rs b/spec/rust/tests/test_valid_fail_in_enum.rs new file mode 100644 index 000000000..320286228 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_in_enum.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_in_enum::*; + +#[test] +fn test_valid_fail_in_enum() -> KResult<()> { + let bytes = fs::read("../../src/enum_0.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailInEnum::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationNotInEnumError(IntMultiType(true,Width4,None)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotInEnum, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotInEnum, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_inst.rs b/spec/rust/tests/test_valid_fail_inst.rs index 3fa055470..5050c8833 100644 --- a/spec/rust/tests/test_valid_fail_inst.rs +++ b/spec/rust/tests/test_valid_fail_inst.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_inst::*; #[test] -fn test_valid_fail_inst() { +fn test_valid_fail_inst() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailInst::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationNotEqualError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationNotEqualError(Int1Type(false))"); - } + let err = res.expect_err("expected Err representing ValidationNotEqualError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_max_int.rs b/spec/rust/tests/test_valid_fail_max_int.rs index 136127319..34f79eb01 100644 --- a/spec/rust/tests/test_valid_fail_max_int.rs +++ b/spec/rust/tests/test_valid_fail_max_int.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_max_int::*; #[test] -fn test_valid_fail_max_int() { +fn test_valid_fail_max_int() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailMaxInt::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); - } + let err = res.expect_err("expected Err representing ValidationGreaterThanError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_min_int.rs b/spec/rust/tests/test_valid_fail_min_int.rs index cc7b35243..50cf06d98 100644 --- a/spec/rust/tests/test_valid_fail_min_int.rs +++ b/spec/rust/tests/test_valid_fail_min_int.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_min_int::*; #[test] -fn test_valid_fail_min_int() { +fn test_valid_fail_min_int() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailMinInt::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationLessThanError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationLessThanError(Int1Type(false))"); - } + let err = res.expect_err("expected Err representing ValidationLessThanError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::LessThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::LessThan, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_range_bytes.rs b/spec/rust/tests/test_valid_fail_range_bytes.rs index 3da2b7e26..85a3fae9f 100644 --- a/spec/rust/tests/test_valid_fail_range_bytes.rs +++ b/spec/rust/tests/test_valid_fail_range_bytes.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_range_bytes::*; #[test] -fn test_valid_fail_range_bytes() { +fn test_valid_fail_range_bytes() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailRangeBytes::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcBytesType)", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(CalcBytesType)"); - } + let err = res.expect_err("expected Err representing ValidationGreaterThanError(CalcBytesType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_range_float.rs b/spec/rust/tests/test_valid_fail_range_float.rs index 37ca849cb..7ebff5c5f 100644 --- a/spec/rust/tests/test_valid_fail_range_float.rs +++ b/spec/rust/tests/test_valid_fail_range_float.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_range_float::*; #[test] -fn test_valid_fail_range_float() { +fn test_valid_fail_range_float() -> KResult<()> { let bytes = fs::read("../../src/floating_points.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailRangeFloat::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationGreaterThanError(FloatMultiType(Width4,None))", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(FloatMultiType(Width4,None))"); - } + let err = res.expect_err("expected Err representing ValidationGreaterThanError(FloatMultiType(Width4,None)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_range_int.rs b/spec/rust/tests/test_valid_fail_range_int.rs index 66fc83c60..fb7f6f876 100644 --- a/spec/rust/tests/test_valid_fail_range_int.rs +++ b/spec/rust/tests/test_valid_fail_range_int.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_range_int::*; #[test] -fn test_valid_fail_range_int() { +fn test_valid_fail_range_int() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailRangeInt::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationGreaterThanError(Int1Type(false))", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(Int1Type(false))"); - } + let err = res.expect_err("expected Err representing ValidationGreaterThanError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_range_str.rs b/spec/rust/tests/test_valid_fail_range_str.rs index b8cecd1c4..e78a23155 100644 --- a/spec/rust/tests/test_valid_fail_range_str.rs +++ b/spec/rust/tests/test_valid_fail_range_str.rs @@ -1,23 +1,20 @@ // Autogenerated from KST: please remove this line if doing any edits by hand! -#![allow(unused_variables)] -#![allow(unused_assignments)] -#![allow(overflowing_literals)] use std::fs; extern crate kaitai; use self::kaitai::*; use rust::formats::valid_fail_range_str::*; #[test] -fn test_valid_fail_range_str() { +fn test_valid_fail_range_str() -> KResult<()> { let bytes = fs::read("../../src/fixed_struct.bin").unwrap(); let _io = BytesReader::from(bytes); let res: KResult> = ValidFailRangeStr::read_into(&_io, None, None); - let r : OptRc; - - if let Err(err) = res { - println!("expected err: {:?}, exception: ValidationGreaterThanError(CalcStrType)", err); - } else { - panic!("no expected exception: ValidationGreaterThanError(CalcStrType)"); - } + let err = res.expect_err("expected Err representing ValidationGreaterThanError(CalcStrType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })", err + ); + Ok(()) } diff --git a/spec/rust/tests/test_valid_fail_repeat_anyof_int.rs b/spec/rust/tests/test_valid_fail_repeat_anyof_int.rs new file mode 100644 index 000000000..02018f219 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_repeat_anyof_int.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_repeat_anyof_int::*; + +#[test] +fn test_valid_fail_repeat_anyof_int() -> KResult<()> { + let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRepeatAnyofInt::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationNotAnyOfError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotAnyOf, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotAnyOf, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_repeat_contents.rs b/spec/rust/tests/test_valid_fail_repeat_contents.rs new file mode 100644 index 000000000..59f7ec384 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_repeat_contents.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_repeat_contents::*; + +#[test] +fn test_valid_fail_repeat_contents() -> KResult<()> { + let bytes = fs::read("../../src/bcd_user_type_be.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRepeatContents::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationNotEqualError(CalcBytesType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_repeat_eq_int.rs b/spec/rust/tests/test_valid_fail_repeat_eq_int.rs new file mode 100644 index 000000000..ed2f76955 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_repeat_eq_int.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_repeat_eq_int::*; + +#[test] +fn test_valid_fail_repeat_eq_int() -> KResult<()> { + let bytes = fs::read("../../src/bcd_user_type_be.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRepeatEqInt::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationNotEqualError(IntMultiType(false,Width4,None)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_repeat_expr.rs b/spec/rust/tests/test_valid_fail_repeat_expr.rs new file mode 100644 index 000000000..60fb1df78 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_repeat_expr.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_repeat_expr::*; + +#[test] +fn test_valid_fail_repeat_expr() -> KResult<()> { + let bytes = fs::read("../../src/bcd_user_type_be.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRepeatExpr::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationExprError(CalcBytesType), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::Expr, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::Expr, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_repeat_inst.rs b/spec/rust/tests/test_valid_fail_repeat_inst.rs new file mode 100644 index 000000000..56c91ad04 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_repeat_inst.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_repeat_inst::*; + +#[test] +fn test_valid_fail_repeat_inst() -> KResult<()> { + let bytes = fs::read("../../src/bcd_user_type_be.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRepeatInst::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationNotEqualError(IntMultiType(false,Width4,None)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::NotEqual, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_repeat_max_int.rs b/spec/rust/tests/test_valid_fail_repeat_max_int.rs new file mode 100644 index 000000000..9bba517c4 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_repeat_max_int.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_repeat_max_int::*; + +#[test] +fn test_valid_fail_repeat_max_int() -> KResult<()> { + let bytes = fs::read("../../src/nav_parent_switch.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRepeatMaxInt::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationGreaterThanError(Int1Type(false)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::GreaterThan, .. })", err + ); + Ok(()) +} diff --git a/spec/rust/tests/test_valid_fail_repeat_min_int.rs b/spec/rust/tests/test_valid_fail_repeat_min_int.rs new file mode 100644 index 000000000..697b7d904 --- /dev/null +++ b/spec/rust/tests/test_valid_fail_repeat_min_int.rs @@ -0,0 +1,20 @@ +// Autogenerated from KST: please remove this line if doing any edits by hand! + +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::valid_fail_repeat_min_int::*; + +#[test] +fn test_valid_fail_repeat_min_int() -> KResult<()> { + let bytes = fs::read("../../src/process_coerce_bytes.bin").unwrap(); + let _io = BytesReader::from(bytes); + let res: KResult> = ValidFailRepeatMinInt::read_into(&_io, None, None); + let err = res.expect_err("expected Err representing ValidationLessThanError(Int1Type(true)), but got Ok"); + assert!( + matches!(err, KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::LessThan, .. })), + "expected: {}\n but got: {:?}", + "KError::ValidationFailed(ValidationFailedError { kind: ValidationKind::LessThan, .. })", err + ); + Ok(()) +} From 9cac8ca5ed71e6efd711396776f50d7305c516d0 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 1 Sep 2024 19:51:14 +0200 Subject: [PATCH 195/198] Port StrEncodingsEscaping{Enc,ToS} to Rust --- .../tests/test_str_encodings_escaping_enc.rs | 21 +++++++++++++++++++ .../tests/test_str_encodings_escaping_to_s.rs | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 spec/rust/tests/test_str_encodings_escaping_enc.rs create mode 100644 spec/rust/tests/test_str_encodings_escaping_to_s.rs diff --git a/spec/rust/tests/test_str_encodings_escaping_enc.rs b/spec/rust/tests/test_str_encodings_escaping_enc.rs new file mode 100644 index 000000000..c76102339 --- /dev/null +++ b/spec/rust/tests/test_str_encodings_escaping_enc.rs @@ -0,0 +1,21 @@ +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::str_encodings_escaping_enc::*; + +#[test] +fn test_str_encodings_escaping_enc() -> KResult<()> { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = StrEncodingsEscapingEnc::read_into(&_io, None, None)?; + + let err = r.str1().v().expect_err(r#"expected Err representing UnknownEncodingError('ASCII\\x'), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "ASCII\\\\x".to_string() }); + let err = r.str2().v().expect_err(r#"expected Err representing UnknownEncodingError("UTF-8\\'x"), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "UTF-8\\'x".to_string() }); + let err = r.str3().v().expect_err(r#"expected Err representing UnknownEncodingError('SJIS\"x'), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "SJIS\\\"x".to_string() }); + let err = r.str4().v().expect_err(r#"expected Err representing UnknownEncodingError('IBM437\nx'), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "IBM437\\nx".to_string() }); + Ok(()) +} diff --git a/spec/rust/tests/test_str_encodings_escaping_to_s.rs b/spec/rust/tests/test_str_encodings_escaping_to_s.rs new file mode 100644 index 000000000..c1cfed60c --- /dev/null +++ b/spec/rust/tests/test_str_encodings_escaping_to_s.rs @@ -0,0 +1,21 @@ +use std::fs; +extern crate kaitai; +use self::kaitai::*; +use rust::formats::str_encodings_escaping_to_s::*; + +#[test] +fn test_str_encodings_escaping_to_s() -> KResult<()> { + let bytes = fs::read("../../src/str_encodings.bin").unwrap(); + let _io = BytesReader::from(bytes); + let r: OptRc = StrEncodingsEscapingToS::read_into(&_io, None, None)?; + + let err = r.str1().expect_err(r#"expected Err representing UnknownEncodingError('ASCII\\x'), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "ASCII\\\\x".to_string() }); + let err = r.str2().expect_err(r#"expected Err representing UnknownEncodingError("UTF-8\\'x"), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "UTF-8\\'x".to_string() }); + let err = r.str3().expect_err(r#"expected Err representing UnknownEncodingError('SJIS\"x'), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "SJIS\\\"x".to_string() }); + let err = r.str4().expect_err(r#"expected Err representing UnknownEncodingError('IBM437\nx'), but got Ok"#); + assert_eq!(err, KError::UnknownEncoding { name: "IBM437\\nx".to_string() }); + Ok(()) +} From 42ed47721406875c606c3b8a6c8c8e458d267499 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Sun, 1 Sep 2024 23:04:29 +0200 Subject: [PATCH 196/198] Rust: print the outputs of failed tests only at the end --- spec/rust/.config/nextest.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/spec/rust/.config/nextest.toml b/spec/rust/.config/nextest.toml index c02e26555..2e631401c 100644 --- a/spec/rust/.config/nextest.toml +++ b/spec/rust/.config/nextest.toml @@ -1,8 +1,7 @@ # See https://nexte.st/book/configuration#profiles [profile.default] -# Print out output for failing tests as soon as they fail, and also at the end -# of the run (for easy scrollability). -failure-output = "immediate-final" +# Print stdout and stderr of failed tests only at the end of the run. +failure-output = "final" # Do not cancel the test run on the first failure. fail-fast = false From 5789f070d776563a22f130e410ee693cd1207bb5 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Mon, 2 Sep 2024 23:13:34 +0200 Subject: [PATCH 197/198] rust_builder: more reliable recovery from build errors --- builder/rust_builder.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/builder/rust_builder.rb b/builder/rust_builder.rb index 48a131357..39fd3c7c1 100644 --- a/builder/rust_builder.rb +++ b/builder/rust_builder.rb @@ -54,7 +54,13 @@ def create_project(mand_files, disp_files) def build_project(log_file) Dir.chdir(@base_spec_dir) do - cli = %w[cargo check --test spec --message-format json] + # We don't use `cargo check` here (which would seem like a more logical + # choice) because unfortunately it doesn't report all build errors, see + # https://doc.rust-lang.org/cargo/commands/cargo-check.html#description: + # + # > Some diagnostics and errors are only emitted during code generation, + # > so they inherently won't be reported with `cargo check`. + cli = %w[cargo test --no-run --test spec --message-format json] run_cargo_build({}, cli, log_file).exitstatus end end From 02cfdeea0a793c9e530a5ee0f3d2e5bee6e60249 Mon Sep 17 00:00:00 2001 From: Petr Pucil Date: Tue, 3 Sep 2024 00:50:53 +0200 Subject: [PATCH 198/198] ci-rust: prepare for running in a Docker container --- ci-rust | 9 +++++++++ config | 1 + 2 files changed, 10 insertions(+) diff --git a/ci-rust b/ci-rust index 14ddd4bdb..262708b4a 100755 --- a/ci-rust +++ b/ci-rust @@ -2,6 +2,15 @@ . ./config +if [ -f /download/runtime/Cargo.lock ]; then + # We're in the Docker container, let's copy the lockfile recording the + # prefetched dependencies into the runtime library dir + ( cd -- "$RUST_RUNTIME_DIR" && cp -v -t . /download/runtime/Cargo.lock ) + # Tell Cargo to work in `--offline` mode (see + # https://doc.rust-lang.org/cargo/reference/config.html#netoffline) + export CARGO_NET_OFFLINE=true +fi + ./run-rust ./kst-adoption-report rust diff --git a/config b/config index 43a876185..b90081728 100644 --- a/config +++ b/config @@ -16,5 +16,6 @@ PERL_RUNTIME_DIR=../runtime/perl/lib PHP_RUNTIME_DIR=../runtime/php PYTHON_RUNTIME_DIR=../runtime/python RUBY_RUNTIME_DIR=../runtime/ruby/lib +RUST_RUNTIME_DIR=../runtime/rust TEST_OUT_DIR=test_out