Skip to content

Commit

Permalink
Java: 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_java_runtime@6a321d1
  • Loading branch information
generalmimon committed Aug 7, 2024
1 parent 7051dbf commit a311948
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,12 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
case _: BytesEosType =>
s"$io.readBytesFull()"
case BytesTerminatedType(terminator, include, consume, eosError, _) =>
val term = terminator.head & 0xff
s"$io.readBytesTerm((byte) $term, $include, $consume, $eosError)"
if (terminator.length == 1) {
val term = terminator.head & 0xff
s"$io.readBytesTerm((byte) $term, $include, $consume, $eosError)"
} else {
s"$io.readBytesTermMulti(${translator.doByteArrayLiteral(terminator)}, $include, $consume, $eosError)"
}
case BitsType1(bitEndian) =>
s"$io.readBitsInt${Utils.upperCamelCase(bitEndian.toSuffix)}(1) != 0"
case BitsType(width: Int, bitEndian) =>
Expand Down Expand Up @@ -499,8 +503,12 @@ class JavaCompiler(typeProvider: ClassTypeProvider, config: RuntimeConfig)
}
val expr2 = terminator match {
case Some(term) =>
val t = term.head & 0xff
s"$kstreamName.bytesTerminate($expr1, (byte) $t, $include)"
if (term.length == 1) {
val t = term.head & 0xff
s"$kstreamName.bytesTerminate($expr1, (byte) $t, $include)"
} else {
s"$kstreamName.bytesTerminateMulti($expr1, ${translator.doByteArrayLiteral(term)}, $include)"
}
case None => expr1
}
expr2
Expand Down

0 comments on commit a311948

Please sign in to comment.