Skip to content

Instantly share code, notes, and snippets.

@maxogden maxogden/index.js
Created Jan 9, 2014

Embed
What would you like to do?
git packfile sidechannel message encoder
module.exports = function encode(string) {
// \2 is verbose messange defined by git protocol
// \r\n is optimized for recive method on git side see sideband.c
var msg = "\2" + string + "\r\n";
function dec2hex(i) {
return (i+0x10000).toString(16).substr(-4).toUpperCase();
}
// rpc messange consists of each line preceded by * its length (including the header) as a 4-byte hex number.
return new Buffer(dec2hex(msg.length + 4) + msg)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.