{"thread":{"id":"1091","subject":"Re: kernel.org and GIT tree rebuilding","startedAt":"2005-07-03T00:17:43Z","lastAt":"2005-07-03T00:17:43Z","messageCount":1,"participants":["linux@horizon.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"5590","messageId":"20050703025112.18758.qmail@science.horizon.com","threadId":"1091","inReplyTo":null,"subject":"Re: kernel.org and GIT tree rebuilding","fromName":"","fromEmail":"linux@horizon.com","sentAt":null,"receivedAt":"2005-07-03T00:17:43Z","isPatch":false,"sender":{"key":"linux@horizon.com","avatar":null},"body":"> \tunsigned long size;\n> \tunsigned char c;\n> \n> \tc = *pack++;\n> \tsize = c & 15;\n> \ttype = (c >> 4) & 7;\n> \twhile (c & 0x80) {\n> \t\tc = *pack++;\n> \t\tsize = (size << 7) + (c & 0x7f);\n> \t}\n> \n> or something. That's even denser.\n\nIf you're going for density, you missed something.  Try:\n\n \tc = *pack++;\n \tsize = c & 15;\n \ttype = (c >> 4) & 7;\n \twhile (c & 0x80) {\n \t\tc = *pack++;\n \t\tsize = (size << 7) + (c & 0x7f) + 16;\n \t}\n\nEncoding is most easily done in little-endian order, such as:\n\nstatic unsigned\nencode(unsigned char *p, unsigned long x)\n{\n        unsigned char *q = p;\n        unsigned char buf[5];\n        unsigned char *b = buf;\n\n        while (x > 15) {\n                assert(b < buf+5);\n                x -= 16;\n                *b++ = x & 0x7f;\n                x >>= 7;\n        }\n        *b = x;\n\n        while (b != buf)\n                *q++ = *b-- | 0x80;\n        *q++ = *b;\n        return (unsigned)(q - p);\n}\n\n(You'll probably want to rewrite the above, but it's abandoned to the\npublic domain in any case.  Go nuts.)\n"}]}