Exemplo n.º 1
0
bool WireReader::readString(ConstString& str, bool *is_vocab)
{
    if (state->len<=0) {
        return false;
    }
    int tag = state->code;
    if (state->code<0) {
        if (noMore()) {
            return false;
        }
        tag = reader.expectInt();
        if (tag!=BOTTLE_TAG_STRING&&tag!=BOTTLE_TAG_VOCAB) {
            return false;
        }
    }
    state->len--;
    if (tag==BOTTLE_TAG_VOCAB) {
        if (is_vocab) {
            *is_vocab = true;
        }
        if (noMore()) {
            return false;
        }
        NetInt32 v = reader.expectInt();
        if (reader.isError()) {
            return false;
        }
        str = Vocab::decode(v);
        return true;
    }
    if (is_vocab) {
        *is_vocab = false;
    }
    if (noMore()) {
        return false;
    }
    int len = reader.expectInt();
    if (reader.isError()) {
        return false;
    }
    if (noMore()) {
        return false;
    }
    str.resize(len);
    reader.expectBlock((const char *)str.c_str(),len);
    // This is needed for compatiblity with versions of yarp before March 2015
    if (len>0) {
        if (str[len-1] == '\0') {
            str.resize(len-1);
        }
    }
    return !reader.isError();
}
Exemplo n.º 2
0
bool WireReader::readBinary(ConstString& str)
{
    if (state->len<=0) {
        return false;
    }
    int tag = state->code;
    if (state->code<0) {
        if (noMore()) {
            return false;
        }
        tag = reader.expectInt();
        if (tag!=BOTTLE_TAG_BLOB) {
            return false;
        }
    }
    state->len--;
    if (noMore()) {
        return false;
    }
    int len = reader.expectInt();
    if (reader.isError()) {
        return false;
    }
    if (len == 0) {
        str = ConstString();
        return true;
    }
    if (len<0) {
        return false;
    }
    if (noMore()) {
        return false;
    }
    str.resize(len);
    reader.expectBlock((const char *)str.c_str(),len);
    return !reader.isError();
}