Last active
January 11, 2017 22:48
-
-
Save GiorgioRegni/9563a921ad8528cdde87dfd5c79e70b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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