/// <summary>
        /// Read a Length-prefixed string from the stream
        /// </summary>
        /// <param name="binaryReader"></param>
        /// <param name="byteLength">Size of the Length representation</param>
        /// <returns></returns>
        public static String ReadPString(this BinaryReader binaryReader, StringSizeEnum byteLength = StringSizeEnum.Int32)
        {
            Int32 stringLength = 0;

            switch (byteLength)
            {
            case StringSizeEnum.Int8:
                stringLength = binaryReader.ReadByte();
                break;

            case StringSizeEnum.Int16:
                stringLength = binaryReader.ReadInt16();
                break;

            case StringSizeEnum.Int32:
                stringLength = binaryReader.ReadInt32();
                break;

            default:
                throw new NotSupportedException("Only Int8, Int16, and Int32 string sizes are supported");
            }

            // If there is actually a string to read
            if (stringLength > 0)
            {
                return(new String(binaryReader.ReadChars(stringLength)));
            }

            return(null);
        }
Example #2
0
 /// <summary>
 /// Read a Length-prefixed string from the stream
 /// </summary>
 /// <param name="binaryReader"></param>
 /// <param name="byteLength">Size of the Length representation</param>
 /// <returns></returns>
 public static String ReadPString(this BinaryReader binaryReader, StringSizeEnum byteLength = StringSizeEnum.Int32)
 {
     return DDRIT.ReadPString(binaryReader, byteLength);
 }
Example #3
0
        /// <summary>
        /// Read a Length-prefixed string from the stream
        /// </summary>
        /// <param name="binaryReader"></param>
        /// <param name="byteLength">Size of the Length representation</param>
        /// <returns></returns>
        public static String ReadPString(this BinaryReader binaryReader, StringSizeEnum byteLength = StringSizeEnum.Int32)
        {
            Int32 stringLength = 0;

            switch (byteLength)
            {
                case StringSizeEnum.Int8:
                    stringLength = binaryReader.ReadByte();
                    break;
                case StringSizeEnum.Int16:
                    stringLength = binaryReader.ReadInt16();
                    break;
                case StringSizeEnum.Int32:
                    stringLength = binaryReader.ReadInt32();
                    break;
                default:
                    throw new NotSupportedException("Only Int8, Int16, and Int32 string sizes are supported");
            }

            // If there is actually a string to read
            if (stringLength > 0)
            {
                return new String(binaryReader.ReadChars(stringLength));
            }

            return null;
        }
 /// <summary>
 /// Read a Length-prefixed string from the stream
 /// </summary>
 /// <param name="binaryReader"></param>
 /// <param name="byteLength">Size of the Length representation</param>
 /// <returns></returns>
 public static String ReadPString(this BinaryReader binaryReader, StringSizeEnum byteLength = StringSizeEnum.Int32)
 {
     return(DDRIT.ReadPString(binaryReader, byteLength));
 }