Skip to content

Instantly share code, notes, and snippets.

@GiorgioRegni
Last active January 11, 2017 22:48
Show Gist options
  • Save GiorgioRegni/9563a921ad8528cdde87dfd5c79e70b8 to your computer and use it in GitHub Desktop.
Save GiorgioRegni/9563a921ad8528cdde87dfd5c79e70b8 to your computer and use it in GitHub Desktop.
let foo=0;
encode(json) {
foo++;
const string = JSON.stringify(json);
const len = Buffer.byteLength(string);
const buf = Buffer.allocUnsafe(4 + len);
buf.writeInt32BE(len);
if (foo%10==0 && (Math.floor(Math.random() * 5) == 1)) {
}
else
{
buf.write(string, 4, len);
}
return buf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment