/// <summary>Bit encode a none-able value into this handle</summary>
        /// <param name="value">Value to encode</param>
        /// <param name="bitMask">Masking value for <paramref name="value"/></param>
        public void EncodeNoneable32(int value, uint bitMask)
        {
            Contract.Requires <ArgumentException>(bitMask != 0);
            Contract.Requires <ArgumentOutOfRangeException>(value.IsNoneOrPositive());

            Bits.BitEncodeEnum((ulong)(value + 1), ref mBits.u64, ref mBitIndex, bitMask);
        }
        /// <summary>Bit encode a none-able value into this handle</summary>
        /// <param name="value">Value to encode</param>
        /// <param name="traits"></param>
        public void EncodeNoneable64(long value, Bitwise.BitFieldTraits traits)
        {
            Contract.Requires <ArgumentException>(!traits.IsEmpty);
            Contract.Requires <ArgumentOutOfRangeException>(value.IsNoneOrPositive());

            Bits.BitEncodeEnum((ulong)(value + 1), ref mBits.u64, ref mBitIndex, traits.Bitmask64);
        }
示例#3
0
        public void Enum_BitEncoderHashCode32Test()
        {
            var ss = new Memory.Strings.StringStorage(
                Memory.Strings.StringStorageWidthType.UTF32,
                Memory.Strings.StringStorageType.CharArray,
                Shell.EndianFormat.Big, 16);
            uint bits      = 0;
            int  bit_index = 0;

            TypeExtensions.BitEncoders.StringStorageWidthType.BitEncode(ss.WidthType, ref bits, ref bit_index);
            TypeExtensions.BitEncoders.StringStorageType.BitEncode(ss.Type, ref bits, ref bit_index);
            TypeExtensions.BitEncoders.EndianFormat.BitEncode(ss.ByteOrder, ref bits, ref bit_index);
            Bits.BitEncodeEnum((uint)ss.FixedLength, ref bits, ref bit_index, 0x7FFF);

            bits      = (uint)ss.GetHashCode();
            bit_index = 0;
            var widthType   = TypeExtensions.BitEncoders.StringStorageWidthType.BitDecode(bits, ref bit_index);
            var type        = TypeExtensions.BitEncoders.StringStorageType.BitDecode(bits, ref bit_index);
            var byteOrder   = TypeExtensions.BitEncoders.EndianFormat.BitDecode(bits, ref bit_index);
            var fixedLength = (short)Bits.BitDecode(bits, ref bit_index, 0x7FFF);

            Assert.AreEqual(ss.WidthType, widthType);
            Assert.AreEqual(ss.Type, type);
            Assert.AreEqual(ss.ByteOrder, byteOrder);
            Assert.AreEqual(ss.FixedLength, fixedLength);
        }
        public void Encode32(uint value, uint bitMask)
        {
            Contract.Requires <ArgumentException>(bitMask != 0);

            Bits.BitEncodeEnum(value, ref mBits.u64, ref mBitIndex, bitMask);
        }
        /// <summary>Bit encode a value into this handle</summary>
        /// <param name="value">Value to encode</param>
        /// <param name="traits"></param>
        public void Encode64(ulong value, Bitwise.BitFieldTraits traits)
        {
            Contract.Requires <ArgumentException>(!traits.IsEmpty);

            Bits.BitEncodeEnum(value, ref mBits.u64, ref mBitIndex, traits.Bitmask64);
        }