/// <summary> /// Ensures that the current tag lvt is an expected value /// </summary> /// <param name="lvt">The expected lvt value</param> private void _ensureLVT(LVT lvt) { if (_lvt != lvt) { throw new InvalidTagException(); } }
/// <summary> /// Reads the next header from the input stream /// if it hasn't already been read /// </summary> /// <returns>True if a header was read, false if the end of a stream was found</returns> private bool _readHeader() { try { byte header = _reader.ReadByte(); _tagNumber = (byte)(header >> 4); _isContext = (header & 0x08) > 0; byte lvt = (byte)(header & 0x07); if (_tagNumber == 0x0F) _tagNumber = _reader.ReadByte(); if (!_isContext && _tagNumber == 0x01) { // boolean app tag, LVT is a value _lvt = LVT.Value; _value = lvt == 1 ? true : false; } else if (_isContext && lvt == 0x06) { // open tag, LVT is type _lvt = LVT.Type; _type = TagType.Open; } else if (_isContext && lvt == 0x07) { // close tag, LVT is type _lvt = LVT.Type; _type = TagType.Close; } else { // LVT is length _lvt = LVT.Length; if (lvt == 0x05) { _length = _reader.ReadByte(); if (_length == 254) { _length = _reader.ReadByte(); _length <<= 8; _length |= _reader.ReadByte(); } else if (_length == 255) { _length = _reader.ReadByte(); _length <<= 8; _length |= _reader.ReadByte(); _length <<= 8; _length = _reader.ReadByte(); _length <<= 8; _length |= _reader.ReadByte(); } } else _length = lvt; } _hasHeader = true; return true; } catch(EndOfStreamException) { return false; } }
/// <summary> /// Ensures that the current tag lvt is an expected value /// </summary> /// <param name="lvt">The expected lvt value</param> private void _ensureLVT(LVT lvt) { if (_lvt != lvt) throw new InvalidTagException(); }
/// <summary> /// Reads the next header from the input stream /// if it hasn't already been read /// </summary> /// <returns>True if a header was read, false if the end of a stream was found</returns> private bool _readHeader() { try { byte header = _reader.ReadByte(); _tagNumber = (byte)(header >> 4); _isContext = (header & 0x08) > 0; byte lvt = (byte)(header & 0x07); if (_tagNumber == 0x0F) { _tagNumber = _reader.ReadByte(); } if (!_isContext && _tagNumber == 0x01) { // boolean app tag, LVT is a value _lvt = LVT.Value; _value = lvt == 1 ? true : false; } else if (_isContext && lvt == 0x06) { // open tag, LVT is type _lvt = LVT.Type; _type = TagType.Open; } else if (_isContext && lvt == 0x07) { // close tag, LVT is type _lvt = LVT.Type; _type = TagType.Close; } else { // LVT is length _lvt = LVT.Length; if (lvt == 0x05) { _length = _reader.ReadByte(); if (_length == 254) { _length = _reader.ReadByte(); _length <<= 8; _length |= _reader.ReadByte(); } else if (_length == 255) { _length = _reader.ReadByte(); _length <<= 8; _length |= _reader.ReadByte(); _length <<= 8; _length = _reader.ReadByte(); _length <<= 8; _length |= _reader.ReadByte(); } } else { _length = lvt; } } _hasHeader = true; return(true); } catch (EndOfStreamException) { return(false); } }