Ejemplo n.º 1
0
        /// <summary>Read a single-byte CString from a bitstream</summary>
        /// <param name="s">Endian stream to read from</param>
        /// <param name="ms">Stream to write the character's bytes to</param>
        /// <param name="maxLength">Optional maximum length of this specific string</param>
        void ReadCStringSingleByte(IO.BitStream s, System.IO.MemoryStream ms, int maxLength)
        {
            byte character;

            if (maxLength > 0)
            {
                int x = 0;
                while ((character = s.ReadByte()) != 0 && ++x <= maxLength)
                {
                    ms.WriteByte(character);
                }
            }
            else if (!mStorage.IsFixedLength)
            {
                while ((character = s.ReadByte()) != 0)
                {
                    ms.WriteByte(character);
                }
            }
            else
            {
                byte[] characters = s.ReadBytes(mFixedLengthByteLength);

                int x;
                for (x = 0; x < characters.Length; x++)
                {
                    if (characters[x] == 0)
                    {
                        break;
                    }
                }

                ms.Write(characters, 0, x);
            }
        }
Ejemplo n.º 2
0
        byte[] ReadStrPascal(IO.BitStream s, out int actualCount, int prefixBitLength)
        {
            actualCount = TypeExtensions.kNone;

            if (prefixBitLength.IsNone())
            {
                switch (mStorage.LengthPrefix)
                {
                case StringStorageLengthPrefix.Int8: prefixBitLength = Bits.kByteBitCount; break;

                case StringStorageLengthPrefix.Int16: prefixBitLength = Bits.kInt16BitCount; break;

                case StringStorageLengthPrefix.Int32: prefixBitLength = Bits.kInt32BitCount; break;
                }
            }

            int length;

            switch (mStorage.LengthPrefix)
            {
            case StringStorageLengthPrefix.Int7: throw new NotSupportedException();

            case StringStorageLengthPrefix.Int8: length = s.ReadByte(prefixBitLength); break;

            case StringStorageLengthPrefix.Int16: length = s.ReadInt16(prefixBitLength); break;

            case StringStorageLengthPrefix.Int32: length = s.ReadInt32(prefixBitLength); break;

            default: throw new Debug.UnreachableException();
            }

            return(s.ReadBytes(GetMaxCleanByteCount(length)));
        }