-class unmarshall {
- private:
- char *_buf;
- int _sz;
- int _ind;
- bool _ok;
- public:
- unmarshall(): _buf(NULL),_sz(0),_ind(0),_ok(false) {}
- unmarshall(char *b, int sz): _buf(b),_sz(sz),_ind(),_ok(true) {}
- unmarshall(const std::string &s) : _buf(NULL),_sz(0),_ind(0),_ok(false)
- {
- //take the content which does not exclude a RPC header from a string
- take_content(s);
- }
- ~unmarshall() {
- if (_buf) free(_buf);
- }
-
- //take contents from another unmarshall object
- void take_in(unmarshall &another);
-
- //take the content which does not exclude a RPC header from a string
- void take_content(const std::string &s) {
- _sz = s.size()+RPC_HEADER_SZ;
- _buf = (char *)realloc(_buf,_sz);
- VERIFY(_buf);
- _ind = RPC_HEADER_SZ;
- memcpy(_buf+_ind, s.data(), s.size());
- _ok = true;
- }
-
- bool ok() { return _ok; }
- char *cstr() { return _buf;}
- bool okdone();
- unsigned int rawbyte();
- void rawbytes(std::string &s, unsigned int n);
-
- int ind() { return _ind;}
- int size() { return _sz;}
- void unpack(int *); //non-const ref
- void take_buf(char **b, int *sz) {
- *b = _buf;
- *sz = _sz;
- _sz = _ind = 0;
- _buf = NULL;
- }
-
- void unpack_req_header(req_header *h) {
- //the first 4-byte is for channel to fill size of pdu
- _ind = sizeof(rpc_sz_t);
- unpack(&h->xid);
- unpack(&h->proc);
- unpack((int *)&h->clt_nonce);
- unpack((int *)&h->srv_nonce);
- unpack(&h->xid_rep);
- _ind = RPC_HEADER_SZ;
- }
-
- void unpack_reply_header(reply_header *h) {
- //the first 4-byte is for channel to fill size of pdu
- _ind = sizeof(rpc_sz_t);
- unpack(&h->xid);
- unpack(&h->ret);
- _ind = RPC_HEADER_SZ;
- }
-
- template <class OutputIterator>
- void iterate(OutputIterator i, int n) {
- while (n--) {
- typename OutputIterator::value_type t;
- *this >> t;
- *i++ = t;
- }
- }
-};