git-svn-id: svn://db.shs.com.ru/pip@176 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#include "pikbdlistener.h"
|
|
#include "piconnection.h"
|
|
#include "piconfig.h"
|
|
#include "pichunkstream.h"
|
|
|
|
|
|
struct S {
|
|
int i;
|
|
float f;
|
|
PIString s;
|
|
};
|
|
|
|
PIByteArray & operator <<(PIByteArray & b, const S & s) {b << s.i << s.f << s.s; return b;}
|
|
PIByteArray & operator >>(PIByteArray & b, S & s) {b >> s.i >> s.f >> s.s; return b;}
|
|
|
|
int main (int argc, char * argv[]) {
|
|
PIChunkStream cs;
|
|
S s;
|
|
s.i = 99; s.f = 0.01; s.s = "SSS";
|
|
PIVector<float> f;
|
|
f << -1. << 2.5 << 11.;
|
|
cs << cs.chunk(1, 10) << cs.chunk(2, PIString("text")) << cs.chunk(4, f) << cs.chunk(3, s);
|
|
f.clear();
|
|
PIByteArray ba(cs.data());
|
|
piCout << ba;
|
|
PIChunkStream cs2(ba);
|
|
s.i = 0; s.f = 0; s.s = "";
|
|
int i(0);
|
|
PIString str;
|
|
piCout << i << str << f << s.i << s.f << s.s;
|
|
while (!cs2.atEnd()) {
|
|
switch (cs2.read()) {
|
|
case 1: i = cs2.getData<int>(); break;
|
|
case 2: str = cs2.getData<PIString>(); break;
|
|
case 3: s = cs2.getData<S>(); break;
|
|
case 4: f = cs2.getData<PIVector<float> >(); break;
|
|
}
|
|
}
|
|
piCout << i << str << f << s.i << s.f << s.s;
|
|
return 0;
|
|
}
|
|
|