private bool ReadTraceHeader() { // Read Trace Header CtfStruct traceHeader = _metadata.Trace.Header; int traceHeaderSize = traceHeader.GetSize(); if (traceHeaderSize == CtfEvent.SizeIndeterminate) { throw new FormatException("Unexpected metadata format."); } int magicOffset = traceHeader.GetFieldOffset("magic"); if (magicOffset < 0) { throw new FormatException("Unexpected metadata format: No magic field."); } int streamIdOffset = traceHeader.GetFieldOffset("stream_id"); if (streamIdOffset < 0) { throw new FormatException("Unexpected metadata format: No stream_id field."); } // Convert to bytes instead of bits magicOffset /= 8; streamIdOffset /= 8; traceHeaderSize /= 8; if (_stream.Read(_buffer, 0, traceHeaderSize) != traceHeaderSize) { return(false); } #if DEBUG _fileOffset += traceHeaderSize; #endif uint magic = BitConverter.ToUInt32(_buffer, magicOffset); if (magic != 0xc1fc1fc1) { throw new FormatException("Unknown magic number in trace header."); } uint streamId = BitConverter.ToUInt32(_buffer, streamIdOffset); _ctfStream = _metadata.Streams[streamId]; return(true); }
private bool ReadPacketContext() { // Read Packet Context CtfStruct packetContext = _ctfStream.PacketContext; int packetContextSize = packetContext.GetSize(); if (packetContextSize == CtfEvent.SizeIndeterminate) { throw new FormatException("Unexpected metadata format."); } int contentSizeOffset = packetContext.GetFieldOffset("content_size"); if (contentSizeOffset < 0) { throw new FormatException("Unexpected metadata format: No context_size field."); } int packetSizeOffset = packetContext.GetFieldOffset("packet_size"); if (packetSizeOffset < 0) { throw new FormatException("Unexpected metadata format: No packet_size field."); } // Convert to bytes instead of bits packetContextSize /= 8; contentSizeOffset /= 8; packetSizeOffset /= 8; if (_stream.Read(_buffer, 0, packetContextSize) != packetContextSize) { return(false); } #if DEBUG _fileOffset += packetContextSize; #endif int headerSize = (_metadata.Trace.Header.GetSize() / 8) + packetContextSize; _contentSize = (long)BitConverter.ToUInt64(_buffer, contentSizeOffset) / 8 - headerSize; _packetSize = (long)BitConverter.ToUInt64(_buffer, packetSizeOffset) / 8 - headerSize; return(true); }