예제 #1
0
/**
* This helper function groups code to avoid duplication. It is not a member function of Image because 
* there are problems with ImageNetworkHeader, anyhow the function is state-less and uses only parameters.
*/
inline bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader& connection)
{
    dest.resize(header.width, header.height);
    unsigned char *mem = dest.getRawImage();
    int allocatedBytes = dest.getRawImageSize();
    yAssert(mem != NULL);
    //this check is redundant with assertion, I would remove it
    if (dest.getRawImageSize() != header.imgSize) {
        printf("There is a problem reading an image\n");
        printf("incoming: width %d, height %d, code %d, quantum %d, size %d\n",
            (int)header.width, (int)header.height,
            (int)header.id,
            (int)header.quantum, (int)header.imgSize);
        printf("my space: width %d, height %d, code %d, quantum %d, size %d\n",
            dest.width(), dest.height(), dest.getPixelCode(), dest.getQuantum(), allocatedBytes);
    }
    yAssert(allocatedBytes == header.imgSize);
    bool ok = connection.expectBlock((char *)mem, allocatedBytes);
    return (!connection.isError() && ok);
}
예제 #2
0
bool StoreDouble::readRaw(ConnectionReader& reader) {
    NetFloat64 flt = 0;
    reader.expectBlock((const char*)&flt,sizeof(flt));
    x = flt;
    return true;
}
예제 #3
0
bool BottleImpl::read(ConnectionReader& reader) {
    bool result = false;

    if (reader.isTextMode()) {
        String str = reader.expectText().c_str();
        if (reader.isError()) return false;
        bool done = (str.length()<=0);
        while (!done) {
            if (str[str.length()-1]=='\\') {
                str = str.substr(0,str.length()-1);
                str += reader.expectText().c_str();
                if (reader.isError()) return false;
            } else {
                if (isComplete(str.c_str())) {
                    done = true;
                } else {
                    str += "\n";
                    str += reader.expectText().c_str();
                    if (reader.isError()) return false;
                }
            }
        }
        fromString(str);
        result = true;
    } else {
#if USE_YARP1_PREFIX
        if (!nested) {
            int len = reader.expectInt();
            if (reader.isError()) return false;
            //String name = reader.expectString(len);
            String buf(YARP_STRINIT(len));
            reader.expectBlock((const char *)buf.c_str(),len);
            if (reader.isError()) return false;
            String name = buf.c_str();
        }
#endif
        if (!nested) {
            // no byte length any more to facilitate nesting
            //reader.expectInt(); // the bottle byte ct; ignored
            
            clear();
            specialize(0);
            
            int code = reader.expectInt();
            if (reader.isError()) return false;
            YMSG(("READ got top level code %d\n", code));
            code = code & UNIT_MASK;
            if (code!=0) {
                specialize(code);
            }
        }
        
        result = true;
        clear();
        dirty = true; // for clarity
        
        int len = 0;
        int i = 0;
        len = reader.expectInt();
        if (reader.isError()) return false;
        YMSG(("READ got length %d\n", len));
        for (i=0; i<len; i++) {
            bool ok = fromBytes(reader);
            if (!ok) return false;
        }
    }
    return result;
}