Exemplo n.º 1
0
        public int Decode(byte[] data, int offset, int length, out DecodedPacket pkt)
        {
            int ret;

            // When data exists in queue, add on and attempt decode.
            if (_readpos > 0)
            {
                if (!Save(data, offset, length))
                {
                    _error      = true;
                    pkt.packet  = null;
                    pkt.type_id = -1;
                    return(length);
                }

                ret = DoDecode(_data, _parsepos, _readpos - _parsepos, out pkt);
                if (ret > 0)
                {
                    OnParsed(ret);
                }
                return(length);
            }

            // No data in queue; attempt decode directly in buffer
            ret = DoDecode(data, offset, length, out pkt);
            if (pkt.type_id < 0)
            {
                // No decode yet. Consume what it wants and store the rest.
                if (!Save(data, offset + ret, length - ret))
                {
                    pkt.packet  = null;
                    pkt.type_id = -1;
                    _error      = true;
                }
                return(length);
            }

            return(ret);
        }
Exemplo n.º 2
0
		public int Decode(byte[] data, int offset, int length, out DecodedPacket pkt)
		{
			int ret;

			// When data exists in queue, add on and attempt decode.
			if (_readpos > 0)
			{
				if (!Save(data, offset, length))
				{
					_error = true;
					pkt.packet = null;
					pkt.type_id = -1;
					return length;
				}

				ret = DoDecode(_data, _parsepos, _readpos - _parsepos, out pkt);
				if (ret > 0)
					OnParsed(ret);
				return length;
			}

			// No data in queue; attempt decode directly in buffer
			ret = DoDecode(data, offset, length, out pkt);
			if (pkt.type_id < 0)
			{
				// No decode yet. Consume what it wants and store the rest.
				if (!Save(data, offset + ret, length - ret))
				{
					pkt.packet = null;
					pkt.type_id = -1;
					_error = true;
				}
				return length;
			}

			return ret;
		}
Exemplo n.º 3
0
 public int DoDecode(byte[] data, int offset, int length, out DecodedPacket pkt)
 {
     return(_decoder.Decode(data, offset, length, out pkt));
 }
Exemplo n.º 4
0
		public int DoDecode(byte[] data, int offset, int length, out DecodedPacket pkt)
		{
			return _decoder.Decode(data, offset, length, out pkt);
		}