Пример #1
0
bool RedisCommandDecoder::Decode(ChannelHandlerContext& ctx, Channel* channel, Buffer& buffer, RedisCommandFrame& msg)
{
    bool have_empty = false;
    while (buffer.Readable() && (buffer.GetRawReadBuffer()[0] == '\r' || buffer.GetRawReadBuffer()[0] == '\n'))
    {
        buffer.AdvanceReadIndex(1);
        have_empty = true;
    }
    if(!m_ignore_empty && have_empty)
    {
        msg.Clear();
        return true;
    }
    return Decode(channel, buffer, msg);
}
Пример #2
0
bool RedisCommandDecoder::Decode(Channel* channel, Buffer& buffer, RedisCommandFrame& msg)
{
    while (buffer.Readable() && (buffer.GetRawReadBuffer()[0] == '\r' || buffer.GetRawReadBuffer()[0] == '\n'))
    {
        buffer.AdvanceReadIndex(1);
    }
    size_t mark_read_index = buffer.GetReadIndex();
    char ch;
    if (buffer.ReadByte(ch))
    {
        int ret = -1;
        if (ch == '*')
        {
            //reqtype = REDIS_REQ_MULTIBULK;
            msg.m_is_inline = false;
            ret = ProcessMultibulkBuffer(channel, buffer, msg);
        }
        else
        {
            //reqtype = REDIS_REQ_INLINE;
            msg.m_is_inline = true;
            buffer.AdvanceReadIndex(-1);
            ret = ProcessInlineBuffer(buffer, msg);
        }
        if (ret > 0)
        {
            size_t raw_data_size = buffer.GetReadIndex() - mark_read_index;
            msg.m_raw_msg.WrapReadableContent(buffer.GetRawReadBuffer() - raw_data_size, raw_data_size);
            return true;
        }
        else
        {
            msg.Clear();
            if (0 == ret)
            {
                buffer.SetReadIndex(mark_read_index);
            }
            return false;
        }
    }
    buffer.SetReadIndex(mark_read_index);
    return false;
}