Skip to content

Commit

Permalink
Ruby: add UTF-16 and UTF-32 support to type: strz
Browse files Browse the repository at this point in the history
See kaitai-io/kaitai_struct#187

The new methods used in this commit have been implemented in
kaitai-io/kaitai_struct_ruby_runtime@a203e14
  • Loading branch information
generalmimon committed Aug 7, 2024
1 parent cf2f475 commit 24efb14
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,12 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
case _: BytesEosType =>
s"$io.read_bytes_full"
case BytesTerminatedType(terminator, include, consume, eosError, _) =>
val term = terminator.head & 0xff
s"$io.read_bytes_term($term, $include, $consume, $eosError)"
if (terminator.length == 1) {
val term = terminator.head & 0xff
s"$io.read_bytes_term($term, $include, $consume, $eosError)"
} else {
s"$io.read_bytes_term_multi(${translator.doByteArrayLiteral(terminator)}, $include, $consume, $eosError)"
}
case BitsType1(bitEndian) =>
s"$io.read_bits_int_${bitEndian.toSuffix}(1) != 0"
case BitsType(width: Int, bitEndian) =>
Expand Down Expand Up @@ -404,8 +408,12 @@ class RubyCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}
val expr2 = terminator match {
case Some(term) =>
val t = term.head & 0xff
s"$kstreamName::bytes_terminate($expr1, $t, $include)"
if (term.length == 1) {
val t = term.head & 0xff
s"$kstreamName::bytes_terminate($expr1, $t, $include)"
} else {
s"$kstreamName::bytes_terminate_multi($expr1, ${translator.doByteArrayLiteral(term)}, $include)"
}
case None => expr1
}
expr2
Expand Down

0 comments on commit 24efb14

Please sign in to comment.