MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / mp_encode_bytes

Function mp_encode_bytes

deps/lua/src/lua_cmsgpack.c:174–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

172/* ------------------------- Low level MP encoding -------------------------- */
173
174void mp_encode_bytes(lua_State *L, mp_buf *buf, const unsigned char *s, size_t len) {
175 unsigned char hdr[5];
176 int hdrlen;
177
178 if (len < 32) {
179 hdr[0] = 0xa0 | (len&0xff); /* fix raw */
180 hdrlen = 1;
181 } else if (len <= 0xff) {
182 hdr[0] = 0xd9;
183 hdr[1] = len;
184 hdrlen = 2;
185 } else if (len <= 0xffff) {
186 hdr[0] = 0xda;
187 hdr[1] = (len&0xff00)>>8;
188 hdr[2] = len&0xff;
189 hdrlen = 3;
190 } else {
191 hdr[0] = 0xdb;
192 hdr[1] = (len&0xff000000)>>24;
193 hdr[2] = (len&0xff0000)>>16;
194 hdr[3] = (len&0xff00)>>8;
195 hdr[4] = len&0xff;
196 hdrlen = 5;
197 }
198 mp_buf_append(L,buf,hdr,hdrlen);
199 mp_buf_append(L,buf,s,len);
200}
201
202/* we assume IEEE 754 internal format for single and double precision floats. */
203void mp_encode_double(lua_State *L, mp_buf *buf, double d) {

Callers 1

mp_encode_lua_stringFunction · 0.85

Calls 1

mp_buf_appendFunction · 0.85

Tested by

no test coverage detected