MCPcopy Create free account
hub / github.com/assaultcube/AC / putuint_

Function putuint_

source/src/protocol.cpp:65–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63// much smaller encoding for unsigned integers up to 28 bits, but can handle signed
64template<class T>
65static 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}
88void putuint(ucharbuf &p, int n) { putuint_(p, n); }
89void putuint(packetbuf &p, int n) { putuint_(p, n); }
90void putuint(vector<uchar> &p, int n) { putuint_(p, n); }

Callers 1

putuintFunction · 0.85

Calls 1

putMethod · 0.45

Tested by

no test coverage detected