Example #1
0
        public int ReadUInt31()
        {
            int i = ReadInt32();

            if (i < 0)
            {
                XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
            }
            return(i);
        }
Example #2
0
        public void ReadQName(ValueHandle value)
        {
            int prefix = ReadUInt8();

            if (prefix >= 26)
            {
                XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
            }
            int key = ReadDictionaryKey();

            value.SetQNameValue(prefix, key);
        }
Example #3
0
        public int ReadMultiByteUInt31()
        {
            int i = GetByte();

            Advance(1);
            if ((i & 0x80) == 0)
            {
                return(i);
            }
            i &= 0x7F;

            int j = GetByte();

            Advance(1);
            i |= ((j & 0x7F) << 7);
            if ((j & 0x80) == 0)
            {
                return(i);
            }

            int k = GetByte();

            Advance(1);
            i |= ((k & 0x7F) << 14);
            if ((k & 0x80) == 0)
            {
                return(i);
            }

            int l = GetByte();

            Advance(1);
            i |= ((l & 0x7F) << 21);
            if ((l & 0x80) == 0)
            {
                return(i);
            }

            int m = GetByte();

            Advance(1);
            i |= (m << 28);
            if ((m & 0xF8) != 0)
            {
                XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
            }

            return(i);
        }
        public XmlDictionaryString GetDictionaryString(int key)
        {
            IXmlDictionary      session;
            XmlDictionaryString str;

            if ((key & 1) != 0)
            {
                session = this.session;
            }
            else
            {
                session = this.dictionary;
            }
            if (!session.TryLookup((int)(key >> 1), out str))
            {
                XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader);
            }
            return(str);
        }
Example #5
0
        public XmlDictionaryString GetDictionaryString(int key)
        {
            IXmlDictionary keyDictionary;

            if ((key & 1) != 0)
            {
                keyDictionary = _session;
            }
            else
            {
                keyDictionary = _dictionary;
            }
            XmlDictionaryString s;

            if (!keyDictionary.TryLookup(key >> 1, out s))
            {
                XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
            }
            return(s);
        }
Example #6
0
        public int ReadDictionaryKey()
        {
            int key = ReadMultiByteUInt31();

            if ((key & 1) != 0)
            {
                if (_session == null)
                {
                    XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
                }
                int sessionKey = (key >> 1);
                XmlDictionaryString xmlString;
                if (!_session.TryLookup(sessionKey, out xmlString))
                {
                    if (sessionKey < XmlDictionaryString.MinKey || sessionKey > XmlDictionaryString.MaxKey)
                    {
                        XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(_reader);
                    }
                    XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedSession(_reader, sessionKey);
                }
            }
            else
            {
                if (_dictionary == null)
                {
                    XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
                }
                int staticKey = (key >> 1);
                XmlDictionaryString xmlString;
                if (!_dictionary.TryLookup(staticKey, out xmlString))
                {
                    if (staticKey < XmlDictionaryString.MinKey || staticKey > XmlDictionaryString.MaxKey)
                    {
                        XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(_reader);
                    }
                    XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedStatic(_reader, staticKey);
                }
            }
            return(key);
        }
        public int ReadDictionaryKey()
        {
            XmlDictionaryString str2;
            int num = this.ReadMultiByteUInt31();

            if ((num & 1) != 0)
            {
                XmlDictionaryString str;
                if (this.session == null)
                {
                    XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader);
                }
                int num2 = num >> 1;
                if (!this.session.TryLookup(num2, out str))
                {
                    if ((num2 < 0) || (num2 > 0x1fffffff))
                    {
                        XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(this.reader);
                    }
                    XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedSession(this.reader, num2);
                }
                return(num);
            }
            if (this.dictionary == null)
            {
                XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader);
            }
            int key = num >> 1;

            if (!this.dictionary.TryLookup(key, out str2))
            {
                if ((key < 0) || (key > 0x1fffffff))
                {
                    XmlExceptionHelper.ThrowXmlDictionaryStringIDOutOfRange(this.reader);
                }
                XmlExceptionHelper.ThrowXmlDictionaryStringIDUndefinedStatic(this.reader, key);
            }
            return(num);
        }
        public unsafe decimal GetDecimal(int offset)
        {
            byte[] buffer = this.buffer;
            byte   num    = buffer[offset];
            byte   num2   = buffer[offset + 1];
            byte   num3   = buffer[offset + 2];
            byte   num4   = buffer[offset + 3];
            int    num5   = (((((num4 << 8) + num3) << 8) + num2) << 8) + num;

            if (((num5 & 0x7f00ffff) == 0) && ((num5 & 0xff0000) <= 0x1c0000))
            {
                decimal num6;
                byte *  numPtr = (byte *)&num6;
                for (int i = 0; i < 0x10; i++)
                {
                    numPtr[i] = buffer[offset + i];
                }
                return(num6);
            }
            XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader);
            return(0M);
        }
        public int ReadMultiByteUInt31()
        {
            int @byte = this.GetByte();

            this.Advance(1);
            if ((@byte & 0x80) != 0)
            {
                @byte &= 0x7f;
                int num2 = this.GetByte();
                this.Advance(1);
                @byte |= (num2 & 0x7f) << 7;
                if ((num2 & 0x80) == 0)
                {
                    return(@byte);
                }
                int num3 = this.GetByte();
                this.Advance(1);
                @byte |= (num3 & 0x7f) << 14;
                if ((num3 & 0x80) == 0)
                {
                    return(@byte);
                }
                int num4 = this.GetByte();
                this.Advance(1);
                @byte |= (num4 & 0x7f) << 0x15;
                if ((num4 & 0x80) == 0)
                {
                    return(@byte);
                }
                int num5 = this.GetByte();
                this.Advance(1);
                @byte |= num5 << 0x1c;
                if ((num5 & 0xf8) != 0)
                {
                    XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader);
                }
            }
            return(@byte);
        }
Example #10
0
        private void ReadList(ValueHandle value)
        {
            _listValue ??= new ValueHandle(this);
            int count  = 0;
            int offset = this.Offset;

            while (true)
            {
                XmlBinaryNodeType nodeType = GetNodeType();
                SkipNodeType();
                if (nodeType == XmlBinaryNodeType.StartListText)
                {
                    XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
                }
                if (nodeType == XmlBinaryNodeType.EndListText)
                {
                    break;
                }
                ReadValue(nodeType, _listValue);
                count++;
            }
            value.SetValue(ValueHandleType.List, offset, count);
        }
Example #11
0
        public void ReadValue(XmlBinaryNodeType nodeType, ValueHandle value)
        {
            switch (nodeType)
            {
            case XmlBinaryNodeType.EmptyText:
                value.SetValue(ValueHandleType.Empty);
                break;

            case XmlBinaryNodeType.ZeroText:
                value.SetValue(ValueHandleType.Zero);
                break;

            case XmlBinaryNodeType.OneText:
                value.SetValue(ValueHandleType.One);
                break;

            case XmlBinaryNodeType.TrueText:
                value.SetValue(ValueHandleType.True);
                break;

            case XmlBinaryNodeType.FalseText:
                value.SetValue(ValueHandleType.False);
                break;

            case XmlBinaryNodeType.BoolText:
                value.SetValue(ReadUInt8() != 0 ? ValueHandleType.True : ValueHandleType.False);
                break;

            case XmlBinaryNodeType.Chars8Text:
                ReadValue(value, ValueHandleType.UTF8, ReadUInt8());
                break;

            case XmlBinaryNodeType.Chars16Text:
                ReadValue(value, ValueHandleType.UTF8, ReadUInt16());
                break;

            case XmlBinaryNodeType.Chars32Text:
                ReadValue(value, ValueHandleType.UTF8, ReadUInt31());
                break;

            case XmlBinaryNodeType.UnicodeChars8Text:
                ReadUnicodeValue(value, ReadUInt8());
                break;

            case XmlBinaryNodeType.UnicodeChars16Text:
                ReadUnicodeValue(value, ReadUInt16());
                break;

            case XmlBinaryNodeType.UnicodeChars32Text:
                ReadUnicodeValue(value, ReadUInt31());
                break;

            case XmlBinaryNodeType.Bytes8Text:
                ReadValue(value, ValueHandleType.Base64, ReadUInt8());
                break;

            case XmlBinaryNodeType.Bytes16Text:
                ReadValue(value, ValueHandleType.Base64, ReadUInt16());
                break;

            case XmlBinaryNodeType.Bytes32Text:
                ReadValue(value, ValueHandleType.Base64, ReadUInt31());
                break;

            case XmlBinaryNodeType.DictionaryText:
                value.SetDictionaryValue(ReadDictionaryKey());
                break;

            case XmlBinaryNodeType.UniqueIdText:
                ReadValue(value, ValueHandleType.UniqueId, ValueHandleLength.UniqueId);
                break;

            case XmlBinaryNodeType.GuidText:
                ReadValue(value, ValueHandleType.Guid, ValueHandleLength.Guid);
                break;

            case XmlBinaryNodeType.DecimalText:
                ReadValue(value, ValueHandleType.Decimal, ValueHandleLength.Decimal);
                break;

            case XmlBinaryNodeType.Int8Text:
                ReadValue(value, ValueHandleType.Int8, ValueHandleLength.Int8);
                break;

            case XmlBinaryNodeType.Int16Text:
                ReadValue(value, ValueHandleType.Int16, ValueHandleLength.Int16);
                break;

            case XmlBinaryNodeType.Int32Text:
                ReadValue(value, ValueHandleType.Int32, ValueHandleLength.Int32);
                break;

            case XmlBinaryNodeType.Int64Text:
                ReadValue(value, ValueHandleType.Int64, ValueHandleLength.Int64);
                break;

            case XmlBinaryNodeType.UInt64Text:
                ReadValue(value, ValueHandleType.UInt64, ValueHandleLength.UInt64);
                break;

            case XmlBinaryNodeType.FloatText:
                ReadValue(value, ValueHandleType.Single, ValueHandleLength.Single);
                break;

            case XmlBinaryNodeType.DoubleText:
                ReadValue(value, ValueHandleType.Double, ValueHandleLength.Double);
                break;

            case XmlBinaryNodeType.TimeSpanText:
                ReadValue(value, ValueHandleType.TimeSpan, ValueHandleLength.TimeSpan);
                break;

            case XmlBinaryNodeType.DateTimeText:
                ReadValue(value, ValueHandleType.DateTime, ValueHandleLength.DateTime);
                break;

            case XmlBinaryNodeType.StartListText:
                ReadList(value);
                break;

            case XmlBinaryNodeType.QNameDictionaryText:
                ReadQName(value);
                break;

            default:
                XmlExceptionHelper.ThrowInvalidBinaryFormat(_reader);
                break;
            }
        }
        public void ReadValue(XmlBinaryNodeType nodeType, ValueHandle value)
        {
            switch (nodeType)
            {
            case XmlBinaryNodeType.MinText:
                value.SetValue(ValueHandleType.Zero);
                return;

            case XmlBinaryNodeType.OneText:
                value.SetValue(ValueHandleType.One);
                return;

            case XmlBinaryNodeType.FalseText:
                value.SetValue(ValueHandleType.False);
                return;

            case XmlBinaryNodeType.TrueText:
                value.SetValue(ValueHandleType.True);
                return;

            case XmlBinaryNodeType.Int8Text:
                this.ReadValue(value, ValueHandleType.Int8, 1);
                return;

            case XmlBinaryNodeType.Int16Text:
                this.ReadValue(value, ValueHandleType.Int16, 2);
                return;

            case XmlBinaryNodeType.Int32Text:
                this.ReadValue(value, ValueHandleType.Int32, 4);
                return;

            case XmlBinaryNodeType.Int64Text:
                this.ReadValue(value, ValueHandleType.Int64, 8);
                return;

            case XmlBinaryNodeType.FloatText:
                this.ReadValue(value, ValueHandleType.Single, 4);
                return;

            case XmlBinaryNodeType.DoubleText:
                this.ReadValue(value, ValueHandleType.Double, 8);
                return;

            case XmlBinaryNodeType.DecimalText:
                this.ReadValue(value, ValueHandleType.Decimal, 0x10);
                return;

            case XmlBinaryNodeType.DateTimeText:
                this.ReadValue(value, ValueHandleType.DateTime, 8);
                return;

            case XmlBinaryNodeType.Chars8Text:
                this.ReadValue(value, ValueHandleType.UTF8, this.ReadUInt8());
                return;

            case XmlBinaryNodeType.Chars16Text:
                this.ReadValue(value, ValueHandleType.UTF8, this.ReadUInt16());
                return;

            case XmlBinaryNodeType.Chars32Text:
                this.ReadValue(value, ValueHandleType.UTF8, this.ReadUInt31());
                return;

            case XmlBinaryNodeType.Bytes8Text:
                this.ReadValue(value, ValueHandleType.Base64, this.ReadUInt8());
                return;

            case XmlBinaryNodeType.Bytes16Text:
                this.ReadValue(value, ValueHandleType.Base64, this.ReadUInt16());
                return;

            case XmlBinaryNodeType.Bytes32Text:
                this.ReadValue(value, ValueHandleType.Base64, this.ReadUInt31());
                return;

            case XmlBinaryNodeType.StartListText:
                this.ReadList(value);
                return;

            case XmlBinaryNodeType.EmptyText:
                value.SetValue(ValueHandleType.Empty);
                return;

            case XmlBinaryNodeType.DictionaryText:
                value.SetDictionaryValue(this.ReadDictionaryKey());
                return;

            case XmlBinaryNodeType.UniqueIdText:
                this.ReadValue(value, ValueHandleType.UniqueId, 0x10);
                return;

            case XmlBinaryNodeType.TimeSpanText:
                this.ReadValue(value, ValueHandleType.TimeSpan, 8);
                return;

            case XmlBinaryNodeType.GuidText:
                this.ReadValue(value, ValueHandleType.Guid, 0x10);
                return;

            case XmlBinaryNodeType.UInt64Text:
                this.ReadValue(value, ValueHandleType.UInt64, 8);
                return;

            case XmlBinaryNodeType.BoolText:
                value.SetValue((this.ReadUInt8() != 0) ? ValueHandleType.True : ValueHandleType.False);
                return;

            case XmlBinaryNodeType.UnicodeChars8Text:
                this.ReadUnicodeValue(value, this.ReadUInt8());
                return;

            case XmlBinaryNodeType.UnicodeChars16Text:
                this.ReadUnicodeValue(value, this.ReadUInt16());
                return;

            case XmlBinaryNodeType.UnicodeChars32Text:
                this.ReadUnicodeValue(value, this.ReadUInt31());
                return;

            case XmlBinaryNodeType.QNameDictionaryText:
                this.ReadQName(value);
                return;
            }
            XmlExceptionHelper.ThrowInvalidBinaryFormat(this.reader);
        }