• Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A minimal yet complete MessagePack implementation for JavaScript. msgpack.org[JavaScript]

msgpack.js

This is a MessagePack serializer and deserializer written in JavaScript for web browsers (including IE 11) and Node.js.

It is compact but still fully-featured. This library supports the complete MessagePack specification released on 2017-08-09, including date/time values. No other extension types are implemented in this library, it’s only the standard types which is perfectly fine for interoperability with MessagePack codecs in other programming languages.

I’m using the MessagePack-CSharp library on the server side in my .NET applications.

NPM

MessagePack

MessagePack is an efficient binary serialisation format. It lets you exchange data among multiple languages like JSON. But it’s faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.

Size

This library is very lightweight. The source code has around 560 lines (incl. browser/Node detection), the minified file has 7.0 kB and can be GZip-compressed to 2.7 kB.

Performance

The file msgpack-tests.html contains some tests and a benchmark function that compares this library with msgpack-lite. Here are the results, in milliseconds (lower is better). All tests done on an Intel Core i7-3770 and Windows 10.

Function Chrome 72 Firefox 65 Edge 16 IE 11  
msgpack.js serialize 702 ms +6% 1232 ms −42% 2483 ms +41% 2493 ms −3%
msgpack-lite encode 663 ms 2124 ms 1762 ms 2578 ms
msgpack.js deserialize 652 ms +13% 869 ms +5% 821 ms −48% 651 ms −68%
msgpack-lite decode 577 ms 827 ms 1587 ms 2021 ms

The numbers show that this library is comparable with msgpack-lite. In Chrome it’s only 10% slower. But serializing in Firefox and deserializing in Microsoft browsers is twice as fast.

Usage

Browser

In browsers, a global msgpack object is created that contains the functions serialize and deserialize. The first can be called with any data and returns the serialized bytes. The second works in reverse, taking the serialized bytes and returning the runtime value.

Include the JavaScript file into your HTML document like this:

<script src="msgpack.min.js"></script>

You can use the library functions after loading the script.

If there should be a naming conflict with another library you want to load, you can change the global object name from msgpack to something else by setting msgpackJsName before loading the script file:

<script>
    msgpackJsName = "msgpackJs";
</script>
<script src="msgpack.min.js"></script>

Node.js

In Node.js, these functions are exported in the object you get from the require function.

var msgpack = require("@ygoe/msgpack");

Example

Here’s a simple example:

// Define some data
var sourceData = {
    number: 123,
    number2: -0.129,
    text: "Abc with Üñıçôðé and ユニコード",
    flag: true,
    list: [ 1, 2, 3 ],
    obj: { a: 1, b: "2", c: false, d: { a: 0, b: -1 } },
    time: Date.now()
};

// Serialize to byte array
var bytes = msgpack.serialize(sourceData);

// Deserialize again
var deserializedData = msgpack.deserialize(bytes);

Compatibility

You can also use the functions encode and decode which are aliases to serialize and deserialize. This makes it easier to replace other libraries that use these function names with msgpack.js.

New projects should use the preferred (and more precisely named) serialize and deserialize functions though.

License

MIT license

More Repositories

1

HyperVSwitch

Hyper-V Switch – A simple GUI to enable or disable Hyper-V without uninstallation, allowing the use of other virtualisation solutions.
C#
290
star
2

MultiSelectTreeView

A WPF TreeView control with support for multiple selection.
C#
181
star
3

AsyncTcpClient

An asynchronous variant of TcpClient and TcpListener for .NET Standard.
C#
152
star
4

T-Clock

Highly configurable Windows taskbar clock
C
41
star
5

NetRevisionTask

Injects the current VCS revision of a working directory in a custom format into a .NET assembly build. Based on the .NET Revision Tool, integrated as an MSBuild task, for .NET Framework and .NET Core.
C#
33
star
6

TxTranslation

Tx Translation & Localisation for .NET and WPF
C#
28
star
7

FieldLog

Fast and comprehensive logging tool for .NET applications
C#
21
star
8

EasyPdfSigning

Easy digital signing of PDF documents without rebuilding them. Allows multiple signing.
C#
19
star
9

NetDllExport

Exports static methods in a managed DLL as library functions that can be called from an unmanaged Windows application.
C#
19
star
10

TodoHighlighter

Visual Studio extension that places red boxes behind all the “TODO”s in the editor window.
C#
19
star
11

NetRevisionTool

Injects the current VCS revision into a .NET assembly build.
C#
15
star
12

DotnetMakeDeb

Creates a .deb Debian binary package from a specification file through the dotnet CLI command or as standalone command-line tool.
C#
13
star
13

ViewModelKit

Makes WPF ViewModel classes smart by default.
C#
11
star
14

CecilExplorer

Mono.Cecil object model explorer
C#
9
star
15

MiniWebCompiler

Compiles JavaScript code and SCSS stylesheets for the web, in a simple and clean GUI for Windows. https://unclassified.software/apps/miniwebcompiler
C#
5
star
16

FlashConsoleWindow

Flashes the console window entry in the taskbar and changes the integrated progress bar (Windows Vista+).
C++
3
star
17

DeepConvert

Converts a data type to another data type, smarter than the standard Convert class, including collections and their items as well as object properties (duck typing). With special support for DateTime conversions.
C#
3
star
18

psbuild

Automated, local building of Visual Studio solutions and calling external tools like unit tests, source code commit, obfuscation, digitally signing, file publishing and transfer.
PowerShell
3
star
19

SettingsAdapterFactory

Generates dynamic types that implement an interface with properties that bind to a settings store and implement INotifyPropertyChanged.
C#
2
star
20

DotnetSshDeploy

Deploys websites and applications to SSH servers through the dotnet CLI command or as standalone command-line tool.
C#
2
star
21

Frontfire1

The Frontfire Web Frontend Framework offers essential styles and effects combined with a consistent set of interactive widgets and layout utilities.
JavaScript
2
star
22

GitRevisionTool

Prints out the current Git revision info of a working directory and automatically writes it into your .NET project for the build.
C#
1
star
23

NewMailNotification

Thunderbird new e-mail notification UI helper, designed to work with the Mailbox Alert add-on.
C#
1
star
24

GitInstaller

Installs or updates Git components on a developer computer. http://unclassified.software/apps/gitinstaller
C#
1
star