bool BufferedConnectionWriter::applyConvertTextMode() { if (convertTextModePending) { convertTextModePending = false; Bottle b; StringOutputStream sos; for (size_t i = 0; i < lst_used; i++) { yarp::os::ManagedBytes& m = *(lst[i]); sos.write(m.usedBytes()); } const std::string& str = sos.str(); b.fromBinary(str.c_str(), (int)str.length()); std::string replacement = b.toString() + "\n"; for (auto& i : lst) { delete i; } lst_used = 0; target = &lst; lst.clear(); stopPool(); Bytes data((char*)replacement.c_str(), replacement.length()); appendBlockCopy(data); } return true; }
void checkFormat() { report(0,"check matrix format conforms to network standard..."); Matrix m; size_t rr = 10; size_t cc = 5; makeTestMatrix(m,rr,cc); BufferedConnectionWriter writer; m.write(writer); std::string s = writer.toString(); Bottle bot; bot.fromBinary(s.c_str(),s.length()); checkEqual((size_t) bot.get(0).asInt32(),rr,"row count matches"); checkEqual((size_t) bot.get(1).asInt32(),cc,"column count matches"); Bottle *lst = bot.get(2).asList(); checkTrue(lst!=nullptr,"have data"); if (!lst) return; checkEqual(lst->size(),(rr*cc),"data length matches"); if (lst->size()!=(rr*cc)) return; bool ok = true; for (int i=0; i<(int)(rr*cc); i++) { double v = lst->get(i).asFloat64(); if (fabs(v-i)>0.01) { ok = false; checkEqualish(v,i,"cell matches"); break; } } checkTrue(ok,"data matches"); }
void checkStandard() { PortablePair<Bottle,Bottle> pp; pp.head.fromString("1 2 3"); pp.body.fromString("yes no"); BufferedConnectionWriter writer; pp.write(writer); std::string s = writer.toString(); Bottle bot; bot.fromBinary(s.c_str(),s.length()); checkEqual(bot.size(),(size_t) 2,"it is a pair"); checkEqual(bot.get(0).asList()->size(),(size_t) 3,"head len is right"); checkEqual(bot.get(1).asList()->size(),(size_t) 2,"body len is right"); }
bool create(void* buf, size_t buflen, int op) { if (op==YDR_FREE) return true; save = (op==YDR_ENCODE); if (!save) { printf("reading binary\n"); b.fromBinary((const char *)buf,buflen); printf("read binary\n"); } else { b.clear(); } obuf = buf; obuflen = buflen; return true; }
void testStandard() { report(0,"checking standard compliance of description..."); ImageOf<PixelRgb> img; img.resize(8,4); img.zero(); BufferedConnectionWriter writer; img.write(writer); ConstString s = writer.toString(); Bottle bot; bot.fromBinary(s.c_str(),s.length()); checkEqual(bot.size(),4,"plausible bottle out"); checkEqual(bot.get(0).toString().c_str(),"mat","good tag"); YARP_DEBUG(Logger::get(),"an example image:"); YARP_DEBUG(Logger::get(),bot.toString().c_str()); }