Decoder

decode redis values from stream of ubyte chunks

Members

Enums

State
enum State
Undocumented in source.

Functions

get
RedisdValue get()

try to fetch decoded value from decoder. Return next value or value of type Incomplete.

put
bool put(NbuffChunk chunk)

put next data chunk to decoder

Examples

globalLogLevel = LogLevel.trace;
RedisdValue str = {_type:ValueType.String, _svar : "abc"};
RedisdValue err = {_type:ValueType.Error, _svar : "err"};
immutable(ubyte)[] b = redisdValue(1001).encode 
        ~ redisdValue(1002).encode
        ~ str.encode
        ~ err.encode
        ~ redisdValue("\r\nBulkString\r\n").encode
        ~ redisdValue(1002).encode
        ~ redisdValue([1,2,3]).encode
        ~ redisdValue(["abc", "def"]).encode
        ~ redisdValue(1002).encode;

foreach(chunkSize; 1..b.length) {
    auto s = new Decoder();
    foreach (c; b.chunks(chunkSize)) {
        s.put(NbuffChunk(c));
    }
    auto v = s.get();
    assert(v._ivar == 1001);

    v = s.get();
    assert(v._ivar == 1002);

    v = s.get();
    assert(v._svar == "abc");

    v = s.get();
    assert(v._svar == "err");

    v = s.get();
    assert(v._svar == "\r\nBulkString\r\n");
    v = s.get();
    debug(redisd)trace(v);
    assert(v._ivar == 1002);
    int lists_to_get = 2;
    while( lists_to_get>0 ) {
        v = s.get();
        debug(redisd)trace(v);
        debug (redisd)
            () @trusted { tracef("%s: %s, %s", v._type, v, lists_to_get); }();
        if (v._type == ValueType.List) {
            lists_to_get--;
        }
    }
    v = s.get();
    debug(redisd)trace(v);
    assert(v._ivar == 1002);
    v = s.get();
    debug(redisd)trace(v);
    assert(v._type == ValueType.Incomplete);
}
info("test ok");

Meta