internal GridPointDataSimplePacking(BufferedBinaryReader reader) { ReferenceValue = reader.ReadSingle(); BinaryScaleFactor = reader.ReadInt16(); DecimalScaleFactor = reader.ReadInt16(); NumberOfBits = reader.ReadUInt8(); OriginalFieldValuesType = (OriginalFieldValuesType)reader.ReadUInt8(); }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="numGlyphs">Num glyphs.</param> public void ReadData(BufferedBinaryReader binaryReader, ushort numGlyphs) { for (int i = 0; i < numGlyphs; i++) { this.Add(binaryReader.ReadInt16()); } }
private static object ReadValue(BufferedBinaryReader reader, SystemTypeCode type) { switch (type) { case SystemTypeCode.Boolean: return(reader.ReadBoolean()); case SystemTypeCode.Int8: return(reader.ReadInt8()); case SystemTypeCode.UInt8: return(reader.ReadUInt8()); case SystemTypeCode.Int16: return(reader.ReadInt16()); case SystemTypeCode.UInt16: return(reader.ReadUInt16()); case SystemTypeCode.Int32: return(reader.ReadInt32()); case SystemTypeCode.UInt32: return(reader.ReadUInt32()); case SystemTypeCode.Int64: return(reader.ReadInt64()); case SystemTypeCode.UInt64: return(reader.ReadUInt64()); case SystemTypeCode.Single: return(reader.ReadSingle()); case SystemTypeCode.Double: return(reader.ReadDouble()); case SystemTypeCode.Decimal: throw new NotImplementedException(); case SystemTypeCode.DateTime: throw new NotImplementedException(); case SystemTypeCode.Char: return(reader.ReadChar()); case SystemTypeCode.String: return(reader.ReadCountedUtf8()); case SystemTypeCode.Enum: throw new NotImplementedException(); default: throw new ArgumentOutOfRangeException(); } }
public DatabaseHeader(ref BufferedBinaryReader reader) { byte versionInfo = reader.ReadByte(); Level = (EDatabaseLevel)(versionInfo & 0b0000_0111); Version = (EDatabaseVersion)(versionInfo & 0b1111_1000); UpdateYear = reader.ReadByte(); UpdateMonth = reader.ReadByte(); UpdateDay = reader.ReadByte(); RecordCount = reader.ReadInt32(); HeaderLength = reader.ReadInt16(); RecordLength = reader.ReadInt16(); Reserved01 = reader.ReadBytes(2); IncompleteTransaction = reader.ReadByte(); EncryptionFlag = reader.ReadByte(); Reserved02 = reader.ReadBytes(12); TableFlags = (ETableFlags)reader.ReadByte(); LanguageDriverId = reader.ReadByte(); EndOfHeaderMarker = reader.ReadInt16(); }
public SEHBlock(BufferedBinaryReader reader, bool fatFormat) { if (fatFormat) { Flags = (SEHFlags)reader.ReadInt32(); TryOffset = reader.ReadInt32(); TryLength = reader.ReadInt32(); HandlerOffset = reader.ReadInt32(); HandlerLength = reader.ReadInt32(); Value = reader.ReadInt32(); } else { Flags = (SEHFlags)reader.ReadInt16(); TryOffset = reader.ReadInt16(); TryLength = reader.ReadByte(); HandlerOffset = reader.ReadInt16(); HandlerLength = reader.ReadByte(); Value = reader.ReadInt32(); } }
private static object ReadValue(ElementType type, BufferedBinaryReader reader) { switch (type) { case ElementType.Boolean: return(reader.ReadBoolean()); case ElementType.Char: return(reader.ReadChar()); case ElementType.Int8: return(reader.ReadSByte()); case ElementType.UInt8: return(reader.ReadByte()); case ElementType.Int16: return(reader.ReadInt16()); case ElementType.UInt16: return(reader.ReadUInt16()); case ElementType.Int32: return(reader.ReadInt32()); case ElementType.UInt32: return(reader.ReadUInt32()); case ElementType.Int64: return(reader.ReadInt64()); case ElementType.UInt64: return(reader.ReadUInt64()); case ElementType.Single: return(reader.ReadSingle()); case ElementType.Double: return(reader.ReadDouble()); case ElementType.String: return(Encoding.Unicode.GetString(reader.ToArray())); case ElementType.Class: return(null); default: return(reader.ToArray()); } }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="fontFlagsWideCodes">Font flags wide codes.</param> public void ReadData(BufferedBinaryReader binaryReader, bool fontFlagsWideCodes) { this.fontFlagsWideCodes = fontFlagsWideCodes; if (fontFlagsWideCodes) { fontFlagsWideCode1 = (uint)binaryReader.ReadUInt16(); fontFlagsWideCode2 = (uint)binaryReader.ReadUInt16(); } else { fontFlagsWideCode1 = (uint)binaryReader.ReadByte(); fontFlagsWideCode2 = (uint)binaryReader.ReadByte(); } short fontKerningAdjustement = binaryReader.ReadInt16(); }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); binaryReader.ReadUBits(4); playbackSoundRate = binaryReader.ReadUBits(2); playbackSoundSize = binaryReader.ReadUBits(1); playbackSoundType = binaryReader.ReadUBits(1); streamSoundCompression = binaryReader.ReadUBits(4); streamSoundRate = binaryReader.ReadUBits(2); streamSoundSize = binaryReader.ReadUBits(1); streamSoundType = binaryReader.ReadUBits(1); streamSoundSampleCount = binaryReader.ReadUInt16(); latencySeek = 0; if (streamSoundCompression == 2) { latencySeek = binaryReader.ReadInt16(); } }
private bool getInfo(BufferedBinaryReader source, FileInfo info, ReadTagParams readTagParams) { // Get info from file bool result = false; bool isValidHeader = false; // Check for ID3v2 (NB : this case should not even exist since OGG has its own native tagging system, and is not deemed compatible with ID3v2 according to the ID3 FAQ) source.Seek(sizeInfo.ID3v2Size, SeekOrigin.Begin); // Read global file header info.IdentificationHeader.ReadFromStream(source); if (info.IdentificationHeader.IsValid()) { source.Seek(sizeInfo.ID3v2Size + info.IdentificationHeader.Segments + 27, SeekOrigin.Begin); // 27 being the size from 'ID' to 'Segments' // Read Vorbis or Opus stream info long position = source.Position; String headerStart = Utils.Latin1Encoding.GetString(source.ReadBytes(3)); source.Seek(position, SeekOrigin.Begin); if (VORBIS_HEADER_ID.StartsWith(headerStart)) { contents = CONTENTS_VORBIS; info.VorbisParameters.ID = Utils.Latin1Encoding.GetString(source.ReadBytes(7)); isValidHeader = VORBIS_HEADER_ID.Equals(info.VorbisParameters.ID); info.VorbisParameters.BitstreamVersion = source.ReadBytes(4); info.VorbisParameters.ChannelMode = source.ReadByte(); info.VorbisParameters.SampleRate = source.ReadInt32(); info.VorbisParameters.BitRateMaximal = source.ReadInt32(); info.VorbisParameters.BitRateNominal = source.ReadInt32(); info.VorbisParameters.BitRateMinimal = source.ReadInt32(); info.VorbisParameters.BlockSize = source.ReadByte(); info.VorbisParameters.StopFlag = source.ReadByte(); } else if (OPUS_HEADER_ID.StartsWith(headerStart)) { contents = CONTENTS_OPUS; info.OpusParameters.ID = Utils.Latin1Encoding.GetString(source.ReadBytes(8)); isValidHeader = OPUS_HEADER_ID.Equals(info.OpusParameters.ID); info.OpusParameters.Version = source.ReadByte(); info.OpusParameters.OutputChannelCount = source.ReadByte(); info.OpusParameters.PreSkip = source.ReadUInt16(); //info.OpusParameters.InputSampleRate = source.ReadUInt32(); info.OpusParameters.InputSampleRate = 48000; // Actual sample rate is hardware-dependent. Let's assume for now that the hardware ATL runs on supports 48KHz source.Seek(4, SeekOrigin.Current); info.OpusParameters.OutputGain = source.ReadInt16(); info.OpusParameters.ChannelMappingFamily = source.ReadByte(); if (info.OpusParameters.ChannelMappingFamily > 0) { info.OpusParameters.StreamCount = source.ReadByte(); info.OpusParameters.CoupledStreamCount = source.ReadByte(); info.OpusParameters.ChannelMapping = new byte[info.OpusParameters.OutputChannelCount]; for (int i = 0; i < info.OpusParameters.OutputChannelCount; i++) { info.OpusParameters.ChannelMapping[i] = source.ReadByte(); } } } if (isValidHeader) { info.CommentHeaderStart = source.Position; IList <long> pagePos = new List <long>(); // Reads all related Vorbis pages that describe Comment and Setup headers // and concatenate their content into a single, continuous data stream bool loop = true; bool first = true; using (MemoryStream s = new MemoryStream()) { // Reconstruct the whole Comment header from OGG pages to a MemoryStream while (loop) { info.SetupHeaderEnd = source.Position; // When the loop stops, cursor is starting to read a brand new page located after Comment _and_ Setup headers info.CommentHeader.ID = Utils.Latin1Encoding.GetString(source.ReadBytes(4)); info.CommentHeader.StreamVersion = source.ReadByte(); info.CommentHeader.TypeFlag = source.ReadByte(); // 0 marks a new page if (0 == info.CommentHeader.TypeFlag) { loop = first; } if (loop) { info.CommentHeader.AbsolutePosition = source.ReadUInt64(); info.CommentHeader.Serial = source.ReadInt32(); info.CommentHeader.PageNumber = source.ReadInt32(); info.CommentHeader.Checksum = source.ReadUInt32(); info.CommentHeader.Segments = source.ReadByte(); info.CommentHeader.LacingValues = source.ReadBytes(info.CommentHeader.Segments); s.Write(source.ReadBytes(info.CommentHeader.GetPageLength()), 0, info.CommentHeader.GetPageLength()); pagePos.Add(info.SetupHeaderEnd); } first = false; } if (readTagParams.PrepareForWriting) // Metrics to prepare writing { if (pagePos.Count > 1) { source.Position = pagePos[pagePos.Count - 2]; } else { source.Position = pagePos[0]; } // Determine the boundaries of 3rd header (Setup header) by searching from last-but-one page if (StreamUtils.FindSequence(source, Utils.Latin1Encoding.GetBytes(VORBIS_SETUP_ID))) { info.SetupHeaderStart = source.Position - VORBIS_SETUP_ID.Length; info.CommentHeaderEnd = info.SetupHeaderStart; if (pagePos.Count > 1) { int firstSetupPage = -1; for (int i = 1; i < pagePos.Count; i++) { if (info.CommentHeaderEnd < pagePos[i]) { info.CommentHeaderSpanPages = i - 1; firstSetupPage = i - 1; } if (info.SetupHeaderEnd < pagePos[i]) { info.SetupHeaderSpanPages = i - firstSetupPage; } } /// Not found yet => comment header takes up all pages, and setup header is on the end of the last page if (-1 == firstSetupPage) { info.CommentHeaderSpanPages = pagePos.Count; info.SetupHeaderSpanPages = 1; } } else { info.CommentHeaderSpanPages = 1; info.SetupHeaderSpanPages = 1; } } } // Get total number of samples info.Samples = getSamples(source); // Read metadata from the reconstructed Comment header inside the memoryStream if (readTagParams.ReadTag) { BinaryReader msr = new BinaryReader(s); s.Seek(0, SeekOrigin.Begin); string tagId; bool isValidTagHeader = false; if (contents.Equals(CONTENTS_VORBIS)) { tagId = Utils.Latin1Encoding.GetString(msr.ReadBytes(7)); isValidTagHeader = (VORBIS_TAG_ID.Equals(tagId)); } else if (contents.Equals(CONTENTS_OPUS)) { tagId = Utils.Latin1Encoding.GetString(msr.ReadBytes(8)); isValidTagHeader = (OPUS_TAG_ID.Equals(tagId)); } if (isValidTagHeader) { vorbisTag.Clear(); vorbisTag.Read(msr, readTagParams); } } } // using MemoryStream result = true; } } return(result); }
private object ReadValue(BufferedBinaryReader reader, IType type) { var st = type.SystemType(); if (st != null) { switch (st.Code) { case SystemTypeCode.Boolean: return reader.ReadBoolean(); case SystemTypeCode.Int8: return reader.ReadInt8(); case SystemTypeCode.UInt8: return reader.ReadUInt8(); case SystemTypeCode.Int16: return reader.ReadInt16(); case SystemTypeCode.UInt16: return reader.ReadUInt16(); case SystemTypeCode.Int32: return reader.ReadInt32(); case SystemTypeCode.UInt32: return reader.ReadUInt32(); case SystemTypeCode.Int64: return reader.ReadInt64(); case SystemTypeCode.UInt64: return reader.ReadUInt64(); case SystemTypeCode.Single: return reader.ReadSingle(); case SystemTypeCode.Double: return reader.ReadDouble(); case SystemTypeCode.Char: return reader.ReadChar(); case SystemTypeCode.String: return reader.ReadCountedUtf8(); case SystemTypeCode.Object: //boxed value type var e = (ElementType)reader.ReadInt8(); return ReadValue(reader, e); case SystemTypeCode.Type: return ReadType(reader); } } if (type.TypeKind == TypeKind.Enum) { return ReadValue(reader, type.ValueType); } if (type.IsArray) { int numElem = reader.ReadInt32(); Array arr = null; for (int i = 0; i < numElem; ++i) { var val = ReadValue(reader, type.ElementType); if (arr == null) arr = Array.CreateInstance(val.GetType(), numElem); arr.SetValue(val, i); } return arr; } return null; }
private object ReadValue(BufferedBinaryReader reader, ElementType e) { switch (e) { case ElementType.Boolean: return reader.ReadBoolean(); case ElementType.Char: return reader.ReadChar(); case ElementType.Int8: return reader.ReadSByte(); case ElementType.UInt8: return reader.ReadByte(); case ElementType.Int16: return reader.ReadInt16(); case ElementType.UInt16: return reader.ReadUInt16(); case ElementType.Int32: return reader.ReadInt32(); case ElementType.UInt32: return reader.ReadUInt32(); case ElementType.Int64: return reader.ReadInt64(); case ElementType.UInt64: return reader.ReadUInt64(); case ElementType.Single: return reader.ReadSingle(); case ElementType.Double: return reader.ReadDouble(); case ElementType.String: return reader.ReadCountedUtf8(); case ElementType.Object: case ElementType.CustomArgsBoxedObject: { var elem = (ElementType)reader.ReadInt8(); return ReadValue(reader, elem); } case ElementType.CustomArgsEnum: { string enumTypeName = reader.ReadCountedUtf8(); var enumType = FindType(enumTypeName); if (enumType == null) { //TODO: throw new BadMetadataException(); } return ReadValue(reader, enumType); } case ElementType.CustomArgsType: return ReadType(reader); case ElementType.ArraySz: { var arrElemType = (ElementType)reader.ReadInt8(); return ReadArray(reader, arrElemType); } default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// see <see cref="SwfDotNet.IO.Tags.BaseTag">base class</see> /// </summary> public override void ReadData(byte version, BufferedBinaryReader binaryReader) { RecordHeader rh = new RecordHeader(); rh.ReadData(binaryReader); fontId = binaryReader.ReadUInt16(); bool fontFlagsHasLayout = binaryReader.ReadBoolean(); fontFlagsShiftJIS = binaryReader.ReadBoolean(); fontFlagsSmallText = binaryReader.ReadBoolean(); fontFlagsANSI = binaryReader.ReadBoolean(); bool fontFlagsWideOffsets = binaryReader.ReadBoolean(); bool fontFlagsWideCodes = binaryReader.ReadBoolean(); fontFlagsItalic = binaryReader.ReadBoolean(); fontFlagsBold = binaryReader.ReadBoolean(); languageCode = (LanguageCode)binaryReader.ReadByte(); byte fontNameLength = binaryReader.ReadByte(); fontName = binaryReader.ReadString(fontNameLength); ushort numGlyphs = binaryReader.ReadUInt16(); if (numGlyphs > 0) { uint[] offsetTable = new uint[numGlyphs]; for (int i = 0; i < numGlyphs; i++) { if (fontFlagsWideOffsets) { offsetTable[i] = binaryReader.ReadUInt32(); } else { offsetTable[i] = (uint)binaryReader.ReadUInt16(); } } } uint codeTableOffset = 0; if (fontFlagsWideOffsets) { codeTableOffset = binaryReader.ReadUInt32(); } else { codeTableOffset = (uint)binaryReader.ReadUInt16(); } if (numGlyphs > 0) { this.glyphShapesTable.IsWideCodes = fontFlagsWideCodes; this.glyphShapesTable.ReadData(binaryReader, numGlyphs); } if (fontFlagsHasLayout) { fontAscent = binaryReader.ReadInt16(); fontDescent = binaryReader.ReadInt16(); fontLeading = binaryReader.ReadInt16(); if (numGlyphs > 0) { fontAdvanceTable.ReadData(binaryReader, numGlyphs); fontBoundsTable.ReadData(binaryReader, numGlyphs); fontKerningTable.ReadData(binaryReader, fontFlagsWideCodes); } } }
/// <summary> /// Reads the data. /// </summary> /// <param name="binaryReader">Binary reader.</param> /// <param name="endOfRecordsFlag">End of records flag.</param> /// <param name="tagCodeEnum">Tag code enum.</param> public void ReadData(BufferedBinaryReader binaryReader, ref bool endOfRecordsFlag, TagCodeEnum tagCodeEnum) { binaryReader.SynchBits(); bool textRecordType = binaryReader.ReadBoolean(); binaryReader.ReadUBits(3); bool styleFlagsHasFont = binaryReader.ReadBoolean(); bool styleFlagsHasColor = binaryReader.ReadBoolean(); bool styleFlagsHasYOffset = binaryReader.ReadBoolean(); bool styleFlagsHasXOffset = binaryReader.ReadBoolean(); if (textRecordType == false) { endOfRecordsFlag = true; return; } fontId = 0; if (styleFlagsHasFont) { fontId = binaryReader.ReadUInt16(); } textColor = null; if (styleFlagsHasColor) { if (tagCodeEnum == TagCodeEnum.DefineText2) { textColor = new RGBA(); textColor.ReadData(binaryReader); } else { textColor = new RGB(); textColor.ReadData(binaryReader); } } xOffset = 0; if (styleFlagsHasXOffset) { xOffset = binaryReader.ReadInt16(); } yOffset = 0; if (styleFlagsHasYOffset) { yOffset = binaryReader.ReadInt16(); } textHeight = 0; if (styleFlagsHasFont) { textHeight = binaryReader.ReadUInt16(); } byte glyphCount = binaryReader.ReadByte(); if (glyphCount > 0) { if (glyphEntries == null) { glyphEntries = new GlyphEntryCollection(); } else { glyphEntries.Clear(); } for (int i = 0; i < glyphCount; i++) { GlyphEntry glyphEntry = new GlyphEntry(); glyphEntry.ReadData(binaryReader); glyphEntries.Add(glyphEntry); } } }