Beispiel #1
0
        /// <summary>
        /// Construct a HeapRecordId from a byte array, typically
        /// <see cref="DatabaseEntry.Data"/>.
        /// </summary>
        /// <param name="array">The array representing the record id</param>
        /// <param name="order">The byte order of the data in
        /// <paramref name="array"/></param>
        /// <returns>A new HeapRecordId</returns>
        public static HeapRecordId fromArray(byte[] array, ByteOrder order)
        {
            if (array.Length != 6)
                throw new ArgumentException("Input array too small.");

            /*
             * If necessary, reverse the bytes in the array.  An RID is a
             * u_int32_t followed by a u_int16_t.  Note that we never convert if
             * the user gave us ByteOrder.MACHINE.
             */
            if ((BitConverter.IsLittleEndian &&
                order == ByteOrder.BIG_ENDIAN) ||
                (!BitConverter.IsLittleEndian &&
                order == ByteOrder.LITTLE_ENDIAN)) {
                Array.Reverse(array, 0, 4);
                Array.Reverse(array, 4, 2);
            }
            uint pgno = BitConverter.ToUInt32(array, 0);
            ushort indx = BitConverter.ToUInt16(array, 4);

            return new HeapRecordId(pgno, indx);
        }
Beispiel #2
0
        /*
         * If configure MACHINE, the ByteOrder in database will
         * switch to LITTLE_ENDIAN or BIG_ENDIAN according to the
         * current machine.
         */
        public static void ConfirmByteOrder(XmlElement xmlElem,
		    string name, ByteOrder byteOrder, bool compulsory)
        {
            XmlNode xmlNode;
            ByteOrder specOrder;

            xmlNode = XMLReader.GetNode(xmlElem, name);
            if (xmlNode == null && compulsory == true)
                throw new ConfigNotFoundException(name);
            else if (xmlNode != null)
            {
                specOrder = ByteOrder.FromConst(int.Parse(
                    xmlNode.InnerText));
                if (specOrder == ByteOrder.MACHINE)
                    Assert.AreNotEqual(specOrder, byteOrder);
                else
                    Assert.AreEqual(specOrder, byteOrder);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Return a byte array representing this record id.
        /// </summary>
        /// <param name="order">The byte order to use when constructing the 
        /// array.</param>
        /// <returns>A byte array representing this record id.</returns>
        public byte[] toArray(ByteOrder order)
        {
            byte[] ret = new byte[6];
            byte[] pgnoArray = BitConverter.GetBytes(pgno);
            byte[] indxArray = BitConverter.GetBytes(indx);
            /*
             * If necessary, reverse the bytes in the array.  An RID is a
             * u_int32_t followed by a u_int16_t.  Note that we never convert if
             * the user gave us ByteOrder.MACHINE.
             */
            if ((BitConverter.IsLittleEndian &&
                order == ByteOrder.BIG_ENDIAN) ||
                (!BitConverter.IsLittleEndian &&
                order == ByteOrder.LITTLE_ENDIAN)) {
                Array.Reverse(pgnoArray);
                Array.Reverse(indxArray);
            }
            Buffer.BlockCopy(pgnoArray, 0, ret, 0, pgnoArray.Length);
            Buffer.BlockCopy(indxArray, 0, ret, 4, indxArray.Length);

            return ret;
        }
Beispiel #4
0
        public static bool ConfigByteOrder(XmlElement xmlElem,
		    string name, ref ByteOrder byteOrder, bool compulsory)
        {
            XmlNode xmlNode;

            xmlNode = XMLReader.GetNode(xmlElem, name);
            if (xmlNode == null && compulsory == false)
                return false;
            else if (xmlNode == null && compulsory == true)
                throw new ConfigNotFoundException(name);

            byteOrder = ByteOrder.FromConst(
            int.Parse(xmlNode.InnerText));
            return true;
        }