public void Add(DataResponse.Type dataType, BinaryReader reader) { switch (dataType) { case DataResponse.Type.FrameDescriptionBoard: { EventDescriptionBoard board = EventDescriptionBoard.Read(reader); groups[board.ID] = new FrameGroup(board); break; } case DataResponse.Type.EventFrame: { int id = reader.ReadInt32(); FrameGroup group = groups[id]; EventFrame frame = new EventFrame(reader, group); group.Add(frame); if (group.Board.MainThreadIndex == frame.Header.ThreadIndex) { Add(frame); } break; } case DataResponse.Type.SamplingFrame: { Add(new SamplingFrame(reader)); break; } } }
public static void Serialize(DataResponse.Type type, Stream data, Stream result) { BinaryWriter writer = new BinaryWriter(result); writer.Write(NetworkProtocol.NETWORK_PROTOCOL_VERSION); writer.Write((UInt32)data.Length); writer.Write((UInt32)type); long position = data.Position; data.Seek(0, SeekOrigin.Begin); data.CopyTo(result); data.Seek(position, SeekOrigin.Begin); }
public static DataResponse Create(Stream stream) { if (stream == null || !stream.CanRead) { return(null); } var reader = new BinaryReader(stream); try { uint version = reader.ReadUInt32(); uint length = reader.ReadUInt32(); DataResponse.Type responseType = (DataResponse.Type)reader.ReadUInt32(); byte[] bytes = reader.ReadBytes((int)length); return(new DataResponse(responseType, version, new BinaryReader(new MemoryStream(bytes)))); } catch (EndOfStreamException) { } return(null); }