Closed
Description
It is impossible to use String encodings with DTOs that encode string using different byte length and Unicode units - UTF-16, UTF-32 etc. This is problematic when using tryClaim
or anything else that pre allocates the exact amount of bytes.
To recreate. Add/change custom UTF-16 field result in different estimated length and encoded length. Tests such as uk.co.real_logic.sbe.generation.java.DtoTest
will fail.
<composite name="varUTF16Encoding">
<type name="length" primitiveType="uint32" maxValue="1073741824"/>
<type name="varData" primitiveType="uint8" length="0" characterEncoding="UTF-16"/>
</composite>
<sbe:message name="Car" id="1" description="Description of a basic Car">
[...]
<data name="activationCode" id="20" type="varUTF16Encoding"/>
</sbe:message>
Unfortunately this means that the string has to be converted to byte[] array using SBE encoding in the xml file for that field (e.g. extension.CarDecoder#activationCodeCharacterEncoding
). It could be optimized by estimating string lengths for common charsets defined in java.nio.charset.StandardCharsets
.
// encodedLength += this.activationCode.length();
encodedLength += this.activationCode.getBytes(CarDecoder.activationCodeCharacterEncoding()).length;
Metadata
Metadata
Assignees
Labels
No labels