/// <summary>Define a string storage markup</summary>
        /// <param name="widthType">Width size of a single character of the string type</param>
        /// <param name="type">Storage method for this string type</param>
        /// <param name="byteOrder"></param>
        /// <param name="fixedLength">The storage fixed length (in characters) of this string type</param>
        public StringStorageMarkupAttribute(StringStorageWidthType widthType, StringStorageType type,
                                            Shell.EndianFormat byteOrder = Shell.EndianFormat.Little, short fixedLength = 0)
        {
            Contract.Requires(fixedLength >= 0);

            Storage = new StringStorage(widthType, type, byteOrder, fixedLength);
        }
Esempio n. 2
0
 /// <summary>Construct a new string storage definition (in <see cref="Shell.EndianFormat.Little"/> byte order)</summary>
 /// <param name="widthType">Width size of a single character of this string definition</param>
 /// <param name="type">Storage method for this string definition</param>
 /// <param name="fixedLength">The storage fixed length (in characters) of this string definition</param>
 public StringStorage(StringStorageWidthType widthType, StringStorageType type, short fixedLength) :
     this(widthType, type, Shell.EndianFormat.Little, fixedLength)
 {
     Contract.Requires(!type.UsesLengthPrefix(), "Use ctor with StringStorageLengthPrefix instead");
     Contract.Requires(fixedLength >= 0);
     Contract.Requires(fixedLength == 0 || !widthType.IsVariableWidth(),
                       "Can't use a variable width encoding with fixed buffers!");
 }
Esempio n. 3
0
 public void Read(IO.EndianReader s)
 {
     mWidthType = (StringStorageWidthType)s.ReadByte();
     mType      = (StringStorageType)s.ReadByte();
     mByteOrder = (Shell.EndianFormat)s.ReadByte();
     s.Seek(sizeof(byte));
     mFixedLength = s.ReadInt16();
     s.Seek(sizeof(ushort));
 }
Esempio n. 4
0
        /// <summary>Construct a new Pascal string storage definition</summary>
        /// <param name="widthType">Width size of a single character of this string definition</param>
        /// <param name="prefix">Length prefix size</param>
        /// <param name="byteOrder"></param>
        public StringStorage(StringStorageWidthType widthType, StringStorageLengthPrefix prefix,
                             Shell.EndianFormat byteOrder = Shell.EndianFormat.Little)
        {
            mWidthType    = widthType;
            mType         = StringStorageType.Pascal;
            mByteOrder    = byteOrder;
            mLengthPrefix = prefix;
            mFixedLength  = 0;

            kHashCode = CalculateHashCode(mWidthType, mType, mByteOrder, mLengthPrefix, mFixedLength);
        }
Esempio n. 5
0
        /// <summary>Construct a new string storage definition</summary>
        /// <param name="widthType">Width size of a single character of this string definition</param>
        /// <param name="type">Storage method for this string definition</param>
        /// <param name="byteOrder"></param>
        /// <param name="fixedLength">The storage fixed length (in characters) of this string definition</param>
        public StringStorage(StringStorageWidthType widthType, StringStorageType type,
                             Shell.EndianFormat byteOrder = Shell.EndianFormat.Little, short fixedLength = 0)
        {
            Contract.Requires(!type.UsesLengthPrefix(), "Use ctor with StringStorageLengthPrefix instead");
            Contract.Requires(fixedLength >= 0);
            Contract.Requires(fixedLength == 0 || !widthType.IsVariableWidth(),
                              "Can't use a variable width encoding with fixed buffers!");

            mWidthType    = widthType;
            mType         = type;
            mByteOrder    = byteOrder;
            mLengthPrefix = StringStorageLengthPrefix.None;
            mFixedLength  = fixedLength;

            kHashCode = CalculateHashCode(mWidthType, mType, mByteOrder, mLengthPrefix, mFixedLength);
        }
Esempio n. 6
0
        static int CalculateHashCode(StringStorageWidthType widthType, StringStorageType type, Shell.EndianFormat byteOrder,
                                     StringStorageLengthPrefix prefix,
                                     short fixedLength)
        {
            var encoder = new Bitwise.HandleBitEncoder();

            encoder.Encode32(widthType, TypeExtensions.BitEncoders.StringStorageWidthType);
            encoder.Encode32(type, TypeExtensions.BitEncoders.StringStorageType);
            encoder.Encode32(byteOrder, TypeExtensions.BitEncoders.EndianFormat);

            if (type.UsesLengthPrefix())
            {
                encoder.Encode32(prefix, TypeExtensions.BitEncoders.StringStorageLengthPrefix);
            }
            else if (fixedLength != 0)
            {
                encoder.Encode32((uint)fixedLength, 0x7FFF);
            }

            return((int)encoder.GetHandle32());
        }
 /// <summary>Define a string storage markup (in <see cref="Shell.EndianFormat.Little"/> byte order)</summary>
 /// <param name="widthType">Width size of a single character of this string type</param>
 /// <param name="type">Storage method for this string type</param>
 /// <param name="fixedLength">The storage fixed length (in characters) of this string type</param>
 public StringStorageMarkupAttribute(StringStorageWidthType widthType, StringStorageType type, short fixedLength) :
     this(widthType, type, Shell.EndianFormat.Little, fixedLength)
 {
     Contract.Requires(fixedLength >= 0);
 }