/// <summary>Encodes the given unprintable char codes in the given stream.</summary> /// <remarks>Encodes the given unprintable char codes in the given stream.</remarks> /// <exception cref="System.IO.IOException"></exception> private static void WriteUnprintableCodes(int charOffset, byte[] bytes, ByteUtil.ByteStream unprintableCodes, GeneralLegacyIndexCodes.ExtraCodesStream extraCodes) { // the offset seems to be calculated based on the number of bytes in the // "extra codes" part of the entry (even if there are no extra codes bytes // actually written in the final entry). int unprintCharOffset = charOffset; if (extraCodes != null) { // we need to account for some extra codes which have not been written // yet. additionally, any unprintable bytes added to the beginning of // the extra codes are ignored. unprintCharOffset = extraCodes.GetLength() + (charOffset - extraCodes.GetNumChars ()) - extraCodes.GetUnprintablePrefixLen(); } // we write a whacky combo of bytes for each unprintable char which // includes a funky offset and extra char itself int offset = (UNPRINTABLE_COUNT_START + (UNPRINTABLE_COUNT_MULTIPLIER * unprintCharOffset )) | UNPRINTABLE_OFFSET_FLAGS; // write offset as big-endian short unprintableCodes.Write((offset >> 8) & unchecked ((int)(0xFF))); unprintableCodes.Write(offset & unchecked ((int)(0xFF))); unprintableCodes.Write(UNPRINTABLE_MIDFIX); unprintableCodes.Write(bytes); }