public static List<ProfilerNode> DecodeProfilerData(byte[] data) { List<ProfilerNode> nodes = new List<ProfilerNode>(); ByteStream stream = new ByteStream(data); Protocol.ProfileDataType profilerType = (Protocol.ProfileDataType)stream.ReadBytes(1)[0]; int fieldsNumber = Protocol.ParseInt(stream); for (int i = 0; i < fieldsNumber; ++i) { int nodeId = Protocol.ParseInt(stream); int nodeParentId = Protocol.ParseInt(stream); string nodeName = Protocol.ParseString(stream); int nodeCount = Protocol.ParseInt(stream); float nodeInterval = Protocol.ParseFloat(stream); // in seconds ProfilerNode node = new ProfilerNode { id = nodeId, parentId = nodeParentId, name = nodeName, count = nodeCount, interval = nodeInterval }; if (profilerType == Protocol.ProfileDataType.CPU) node.interval *= 1000.0f; nodes.Add(node); } return nodes; }
public static int ParseInt(ByteStream stream) { return ConvertToInt(stream.ReadBytes(4)); }
public static string ParseString(ByteStream stream) { byte[] len = stream.ReadBytes(4); return stream.Read(ConvertToInt(len)); }
public static float ParseFloat(ByteStream stream) { byte[] b = stream.ReadBytes(4); return System.BitConverter.ToSingle(b, 0); }