Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added unpack functionality #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@
$("#msgpack-bytes").text(msg.length.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') + " bytes");
$("#msgpack-percent").text(Math.round(msg.length / textLength * 100).toString() + " %");
}).keyup();
$("#msgpack-text").keyup(function(event) {
var hex = $("#msgpack-text").val().replace(/ +/g,'');
var msgbytes = [];
for(var i=0; i< hex.length-1; i+=2){
msgbytes.push(parseInt(hex.substr(i, 2), 16));
}
var msg = String.fromCharCode.apply(String, msgbytes);
var obj=msgpack.unpack(msg);
var text=JSON.stringify(obj);
$("#json-text").text(text);
var textLength = encodeURIComponent(text).replace(/%../g,"%").length;
$("#json-bytes").text(textLength.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') + " bytes");
$("#msgpack-bytes").text(msg.length.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1,') + " bytes");
$("#msgpack-percent").text(Math.round(msg.length / textLength * 100).toString() + " %");
});
});
</script>

Expand Down Expand Up @@ -185,7 +200,7 @@
<textarea type="text" id="json-text">{"compact":true,"schema":0}</textarea>
</form>
<h3>MessagePack (hex) <span class="bytes" id="msgpack-bytes"></span> <span class="bytes" id="msgpack-percent"></span></h3>
<textarea readonly id="msgpack-text"></textarea>
<textarea id="msgpack-text"></textarea>
</div>
</main>

Expand Down