public String Read(ChannelBuffer buf, byte separator) { int count = buf.BytesBefore(separator); if (count < 0) { return(null); } byte[] data = new byte[count]; buf.ReadBytes(data); buf.ReadByte(); // get rid of separator return(Encoding.UTF8.GetString(data)); }
public String ReadRaw(ChannelBuffer buf, byte separator) { int count = buf.BytesBefore(separator); if (count < 0) { return(null); } byte[] data = new byte[count]; buf.ReadBytes(data); buf.ReadByte(); // get rid of separator int length = data.Length; for (int i = 0; i < length; i++) { if (data[i] == '\\') { if (i + 1 < length) { byte b = data[i + 1]; if (b == 't') { data[i] = (byte)'\t'; } else if (b == 'r') { data[i] = (byte)'\r'; } else if (b == 'n') { data[i] = (byte)'\n'; } else { data[i] = b; } Array.Copy(data, i + 2, data, i + 1, length - i - 2); length--; } } } return(Encoding.UTF8.GetString(data, 0, length)); }
public String ReadRaw(ChannelBuffer buf, byte separator) { int count = buf.BytesBefore(separator); if (count < 0) { return null; } byte[] data = new byte[count]; buf.ReadBytes(data); buf.ReadByte(); // get rid of separator int length = data.Length; for (int i = 0; i < length; i++) { if (data[i] == '\\') { if (i + 1 < length) { byte b = data[i + 1]; if (b == 't') { data[i] = (byte) '\t'; } else if (b == 'r') { data[i] = (byte) '\r'; } else if (b == 'n') { data[i] = (byte) '\n'; } else { data[i] = b; } Array.Copy(data, i + 2, data, i + 1, length - i - 2); length--; } } } return Encoding.UTF8.GetString(data, 0, length); }
public String Read(ChannelBuffer buf, byte separator) { int count = buf.BytesBefore(separator); if (count < 0) { return null; } byte[] data = new byte[count]; buf.ReadBytes(data); buf.ReadByte(); // get rid of separator return Encoding.UTF8.GetString(data); }
protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent, Stack<ITransaction> stack, IMessageTree tree) { BufferHelper helper = _mBufferHelper; byte identifier = buf.ReadByte(); String timestamp = helper.Read(buf, TAB); String type = helper.Read(buf, TAB); String name = helper.Read(buf, TAB); if (identifier == 'E') { IMessage evt = new DefaultEvent(type, name); String status = helper.Read(buf, TAB); String data = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed evt.Timestamp = _mDateHelper.Parse(timestamp); evt.Status = status; evt.AddData(data); if (parent != null) { parent.AddChild(evt); return parent; } return evt; } if (identifier == 'H') { IMessage heartbeat = new DefaultHeartbeat(type, name); String status0 = helper.Read(buf, TAB); String data1 = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed heartbeat.Timestamp = _mDateHelper.Parse(timestamp); heartbeat.Status = status0; heartbeat.AddData(data1); if (parent != null) { parent.AddChild(heartbeat); return parent; } return heartbeat; } if (identifier == 't') { IMessage transaction = new DefaultTransaction(type, name, null); helper.Read(buf, LF); // get rid of line feed transaction.Timestamp = _mDateHelper.Parse(timestamp); if (parent != null) { parent.AddChild(transaction); } stack.Push(parent); return transaction; } if (identifier == 'A') { ITransaction transaction2 = new DefaultTransaction(type, name, null); String status3 = helper.Read(buf, TAB); String duration = helper.Read(buf, TAB); String data4 = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed transaction2.Timestamp = _mDateHelper.Parse(timestamp); transaction2.Status = status3; transaction2.AddData(data4); long d = Int64.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer); transaction2.DurationInMicros = d; if (parent != null) { parent.AddChild(transaction2); return parent; } return transaction2; } if (identifier == 'T') { String status5 = helper.Read(buf, TAB); String duration6 = helper.Read(buf, TAB); String data7 = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed parent.Status = status5; parent.AddData(data7); long d8 = Int64.Parse( duration6.Substring(0, duration6.Length - 2), NumberStyles.Integer); parent.DurationInMicros = d8; return stack.Pop(); } Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf); // unknown message, ignore it return parent; }
protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent, Stack <ITransaction> stack, IMessageTree tree) { BufferHelper helper = _mBufferHelper; byte identifier = buf.ReadByte(); String timestamp = helper.Read(buf, TAB); String type = helper.Read(buf, TAB); String name = helper.Read(buf, TAB); if (identifier == 'E') { IMessage evt = new DefaultEvent(type, name); String status = helper.Read(buf, TAB); String data = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed evt.Timestamp = _mDateHelper.Parse(timestamp); evt.Status = status; evt.AddData(data); if (parent != null) { parent.AddChild(evt); return(parent); } return(evt); } if (identifier == 'H') { IMessage heartbeat = new DefaultHeartbeat(type, name); String status0 = helper.Read(buf, TAB); String data1 = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed heartbeat.Timestamp = _mDateHelper.Parse(timestamp); heartbeat.Status = status0; heartbeat.AddData(data1); if (parent != null) { parent.AddChild(heartbeat); return(parent); } return(heartbeat); } if (identifier == 't') { IMessage transaction = new DefaultTransaction(type, name, null); helper.Read(buf, LF); // get rid of line feed transaction.Timestamp = _mDateHelper.Parse(timestamp); if (parent != null) { parent.AddChild(transaction); } stack.Push(parent); return(transaction); } if (identifier == 'A') { ITransaction transaction2 = new DefaultTransaction(type, name, null); String status3 = helper.Read(buf, TAB); String duration = helper.Read(buf, TAB); String data4 = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed transaction2.Timestamp = _mDateHelper.Parse(timestamp); transaction2.Status = status3; transaction2.AddData(data4); long d = Int64.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer); transaction2.DurationInMicros = d; if (parent != null) { parent.AddChild(transaction2); return(parent); } return(transaction2); } if (identifier == 'T') { String status5 = helper.Read(buf, TAB); String duration6 = helper.Read(buf, TAB); String data7 = helper.ReadRaw(buf, TAB); helper.Read(buf, LF); // get rid of line feed parent.Status = status5; parent.AddData(data7); long d8 = Int64.Parse( duration6.Substring(0, duration6.Length - 2), NumberStyles.Integer); parent.DurationInMicros = d8; return(stack.Pop()); } Logger.Error("Unknown identifier(" + identifier + ") of message: " + buf); // unknown message, ignore it return(parent); }