| 63 | // much smaller encoding for unsigned integers up to 28 bits, but can handle signed |
| 64 | template<class T> |
| 65 | static inline void putuint_(T &p, int n) |
| 66 | { |
| 67 | DEBUGVAR(n); |
| 68 | if(n < 0 || n >= (1<<21)) |
| 69 | { |
| 70 | p.put(0x80 | (n & 0x7F)); |
| 71 | p.put(0x80 | ((n >> 7) & 0x7F)); |
| 72 | p.put(0x80 | ((n >> 14) & 0x7F)); |
| 73 | p.put(n >> 21); |
| 74 | } |
| 75 | else if(n < (1<<7)) p.put(n); |
| 76 | else if(n < (1<<14)) |
| 77 | { |
| 78 | p.put(0x80 | (n & 0x7F)); |
| 79 | p.put(n >> 7); |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | p.put(0x80 | (n & 0x7F)); |
| 84 | p.put(0x80 | ((n >> 7) & 0x7F)); |
| 85 | p.put(n >> 14); |
| 86 | } |
| 87 | } |
| 88 | void putuint(ucharbuf &p, int n) { putuint_(p, n); } |
| 89 | void putuint(packetbuf &p, int n) { putuint_(p, n); } |
| 90 | void putuint(vector<uchar> &p, int n) { putuint_(p, n); } |