5 operator<<(marshall &m, uint8_t x) {
11 operator<<(marshall &m, uint16_t x) {
13 m.rawbytes((char *)&x, 2);
18 operator<<(marshall &m, uint32_t x) {
20 m.rawbytes((char *)&x, 4);
24 marshall & operator<<(marshall &m, int32_t x) { return m << (uint32_t) x; }
25 marshall & operator<<(marshall &m, int8_t x) { return m << (uint8_t)x; }
26 marshall & operator<<(marshall &m, bool x) { return m << (uint8_t)x; }
27 marshall & operator<<(marshall &m, int16_t x) { return m << (uint16_t)x; }
28 marshall & operator<<(marshall &m, uint64_t x) { return m << (uint32_t)(x>>32) << (uint32_t)x; }
31 operator<<(marshall &m, const string &s) {
32 m << (unsigned int) s.size();
33 m.rawbytes(s.data(), s.size());
37 void marshall::pack_req_header(const request_header &h) {
38 size_t saved_sz = index_;
39 //leave the first 4-byte empty for channel to fill size of pdu
40 index_ = sizeof(rpc_sz_t);
41 *this << h.xid << h.proc << h.clt_nonce << h.srv_nonce << h.xid_rep;
45 void marshall::pack_reply_header(const reply_header &h) {
46 size_t saved_sz = index_;
47 //leave the first 4-byte empty for channel to fill size of pdu
48 index_ = sizeof(rpc_sz_t);
49 *this << h.xid << h.ret;
53 // take the contents from another unmarshall object
55 unmarshall::take_in(unmarshall &another)
59 another.take_buf(&buf_, &sz_);
60 index_ = RPC_HEADER_SZ;
61 ok_ = sz_ >= RPC_HEADER_SZ?true:false;
65 unmarshall::ensure(size_t n) {
76 return (uint8_t)buf_[index_++];
80 unmarshall::rawbytes(string &ss, size_t n)
83 ss.assign(buf_+index_, n);
89 unmarshall::rawbytes(T &t)
91 const size_t n = sizeof(T);
93 memcpy(&t, buf_+index_, n);
98 unmarshall & operator>>(unmarshall &u, bool &x) { x = (bool)u.rawbyte(); return u; }
99 unmarshall & operator>>(unmarshall &u, uint8_t &x) { x = u.rawbyte(); return u; }
100 unmarshall & operator>>(unmarshall &u, int8_t &x) { x = (int8_t)u.rawbyte(); return u; }
101 unmarshall & operator>>(unmarshall &u, uint16_t &x) { u.rawbytes<uint16_t>(x); return u; }
102 unmarshall & operator>>(unmarshall &u, int16_t &x) { u.rawbytes<int16_t>(x); return u; }
103 unmarshall & operator>>(unmarshall &u, uint32_t &x) { u.rawbytes<uint32_t>(x); return u; }
104 unmarshall & operator>>(unmarshall &u, int32_t &x) { u.rawbytes<int32_t>(x); return u; }
105 unmarshall & operator>>(unmarshall &u, size_t &x) { uint32_t xx; u.rawbytes<uint32_t>(xx); x = xx; return u; }
106 unmarshall & operator>>(unmarshall &u, uint64_t &x) { u.rawbytes<uint64_t>(x); return u; }
107 unmarshall & operator>>(unmarshall &u, int64_t &x) { u.rawbytes<int64_t>(x); return u; }
109 unmarshall & operator>>(unmarshall &u, string &s) {
110 unsigned sz = u.grab<unsigned>();