Created
September 20, 2012 18:43
-
-
Save incompl/3757612 to your computer and use it in GitHub Desktop.
This file contains 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
var msg = JSON.stringify( state ); | |
var getUTF8Size = function( str ) { | |
var sizeInBytes = str.split('') | |
.map(function( ch ) { | |
return ch.charCodeAt(0); | |
}).map(function( uchar ) { | |
// The reason for this is explained later in | |
// the section “An Aside on Text Encodings” | |
return uchar < 128 ? 1 : 2; | |
}).reduce(function( curr, next ) { | |
return curr + next; | |
}); | |
return sizeInBytes; | |
}; | |
var msgSize = getUTF8Size( msg ); // 410 bytes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment