Exemplo n.º 1
0
            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));
            }
Exemplo n.º 2
0
            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));
            }
Exemplo n.º 3
0
        protected internal IMessage DecodeLine(ChannelBuffer buf, ITransaction parent,
                                               Stack <ITransaction> stack, IMessageTree tree)
        {
            BufferHelper helper     = _mBufferHelper;
            char         identifier = (char)buf.ReadByte();
            String       timestamp  = helper.Read(buf, TAB);
            String       type       = helper.Read(buf, TAB);
            String       name       = helper.Read(buf, TAB);

            switch (identifier)
            {
            case '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);

            case 'A':
                DefaultTransaction tran     = new DefaultTransaction(type, name, null);
                String             status   = helper.Read(buf, TAB);
                String             duration = helper.Read(buf, TAB);
                String             data     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                tran.Timestamp = _mDateHelper.Parse(timestamp);
                tran.Status    = status;
                tran.AddData(data);

                long d = Int64.Parse(duration.Substring(0, duration.Length - 2), NumberStyles.Integer);

                tran.DurationInMicros = d;

                if (parent != null)
                {
                    parent.AddChild(tran);
                    return(parent);
                }
                return(tran);

            case 'T':
                String transactionStatus   = helper.Read(buf, TAB);
                String transactionDuration = helper.Read(buf, TAB);
                String transactionData     = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                parent.Status = transactionStatus;
                parent.AddData(transactionData);

                long transactionD = Int64.Parse(transactionDuration.Substring(0, transactionDuration.Length - 2), NumberStyles.Integer);

                parent.DurationInMicros = transactionD;

                return(stack.Pop());

            case 'E':
                DefaultEvent evt         = new DefaultEvent(type, name);
                String       eventStatus = helper.Read(buf, TAB);
                String       eventData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                evt.Timestamp = _mDateHelper.Parse(timestamp);
                evt.Status    = eventStatus;
                evt.AddData(eventData);

                if (parent != null)
                {
                    parent.AddChild(evt);
                    return(parent);
                }
                return(evt);

            case 'M':
                DefaultMetric metric       = new DefaultMetric(type, name);
                String        metricStatus = helper.Read(buf, TAB);
                String        metricData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);
                metric.Timestamp = _mDateHelper.Parse(timestamp);
                metric.Status    = metricStatus;
                metric.AddData(metricData);

                if (parent != null)
                {
                    parent.AddChild(metric);
                    return(parent);
                }
                return(metric);

            case 'H':
                DefaultHeartbeat heartbeat       = new DefaultHeartbeat(type, name);
                String           heartbeatStatus = helper.Read(buf, TAB);
                String           heartbeatData   = helper.ReadRaw(buf, TAB);

                helper.Read(buf, LF);     // get rid of line feed
                heartbeat.Timestamp = _mDateHelper.Parse(timestamp);
                heartbeat.Status    = heartbeatStatus;
                heartbeat.AddData(heartbeatData);

                if (parent != null)
                {
                    parent.AddChild(heartbeat);
                    return(parent);
                }
                return(heartbeat);
            }

            LoggerManager.Error("Unknown identifier(" + identifier + ") of message: " + buf);
            //throw new Exception("Unknown identifier int name"); //java版的抛出异常

            // unknown message, ignore it
            return(parent);
        }