bool StoreBlob::readRaw(ConnectionReader& reader) { int len = reader.expectInt(); String buf(YARP_STRINIT(len)); reader.expectBlock((const char *)buf.c_str(),len); x = buf; return true; }
bool Stamp::read(ConnectionReader& connection) { connection.convertTextMode(); int header = connection.expectInt(); if (header!=BOTTLE_TAG_LIST) { return false; } int len = connection.expectInt(); if (len!=2) { return false; } int code; code = connection.expectInt(); if (code!=BOTTLE_TAG_INT) { return false; } sequenceNumber = connection.expectInt(); code = connection.expectInt(); if (code!=BOTTLE_TAG_DOUBLE) { return false; } timeStamp = connection.expectDouble(); if (connection.isError()) { sequenceNumber = -1; timeStamp = 0; return false; } return true; }
bool StoreString::readRaw(ConnectionReader& reader) { int len = reader.expectInt(); String buf(YARP_STRINIT(len)); reader.expectBlock((const char *)buf.c_str(),len); if (len>0) { if (buf[len-1] == '\0') { len--; } } x = buf.substr(0,len); return true; }
bool Value::read(ConnectionReader& connection) { if (proxy) { delete proxy; proxy = 0; } int x = connection.expectInt(); if ((x&0xffff) != x) return false; if (!(x&BOTTLE_TAG_LIST)) return false; int len = connection.expectInt(); if (len==0) return true; if (len!=1) return false; if (x==BOTTLE_TAG_LIST) { x = connection.expectInt(); } else { x &= ~BOTTLE_TAG_LIST; } if (connection.isError()) return false; Storable *s = Storable::createByCode(x); setProxy(s); if (!proxy) return false; return s->readRaw(connection); }
bool BottleImpl::fromBytes(ConnectionReader& reader) { if (reader.isError()) return false; int id = speciality; YMSG(("READING, nest flag is %d\n", nested)); if (id==0) { id = reader.expectInt(); YMSG(("READ subcode %d\n", id)); } else { YMSG(("READ skipped subcode %d\n", speciality)); } Storable *storable = Storable::createByCode(id); if (storable==NULL) { YARP_SPRINTF1(Logger::get(),error,"BottleImpl reader failed, unrecognized object code %d",id); return false; } storable->readRaw(reader); add(storable); return true; }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bool dynContact::read(ConnectionReader& connection){ // auto-convert text mode interaction connection.convertTextMode(); // represent a dynContact as a list of 4 elements that are: // - a list of 3 int, i.e. contactId, bodyPart, linkNumber // - a list of 3 double, i.e. the CoP // - a list of 3 double, i.e. the force // - a list of 3 double, i.e. the moment if(connection.expectInt()!= BOTTLE_TAG_LIST || connection.expectInt()!=4) return false; // - a list of 3 int, i.e. contactId, bodyPart, linkNumber if(connection.expectInt()!=BOTTLE_TAG_LIST+BOTTLE_TAG_INT || connection.expectInt()!=3) return false; contactId = connection.expectInt(); bodyPart = (BodyPart)connection.expectInt(); linkNumber = connection.expectInt(); // - a list of 3 double, i.e. the CoP if(connection.expectInt()!=BOTTLE_TAG_LIST+BOTTLE_TAG_DOUBLE || connection.expectInt()!=3) return false; for(int i=0;i<3;i++) CoP[i] = connection.expectDouble(); // - a list of 3 double, i.e. the force if(connection.expectInt()!=BOTTLE_TAG_LIST+BOTTLE_TAG_DOUBLE || connection.expectInt()!=3) return false; for(int i=0;i<3;i++) F[i] = connection.expectDouble(); setForce(F); // - a list of 3 double, i.e. the moment if(connection.expectInt()!=BOTTLE_TAG_LIST+BOTTLE_TAG_DOUBLE || connection.expectInt()!=3) return false; for(int i=0;i<3;i++) Mu[i] = connection.expectDouble(); return !connection.isError(); }
bool StoreVocab::readRaw(ConnectionReader& reader) { x = reader.expectInt(); return true; }
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; }
bool Storable::read(ConnectionReader& connection) { int x = connection.expectInt(); if (x!=getCode()) return false; return readRaw(connection); }
virtual bool read(ConnectionReader& connection) { printf("Reading an integer\n"); val = connection.expectInt(); return true; }