msgpack2 2.0.0+1

MsgPack for Dart #

Build Status

A full-featured MsgPack library for Dart 1.x and 2.x.

Attribution #

This package was originally forked from msgpack. Due to the number of incompatible refactorings and loss of backwards compatibility, the decision was made to spin it off as a new package. This package contains numerous enhancements over the original MsgPack implementation which should help with performance in many places (see benchmarks), as well as a more complete testing suite.

Usage #

Because this project relies on Dart Libraries which contain inconsistencies between Dart 1.x and Dart 2.x, there are two versions of the this package maintained.

If you want to use this package for Dart projects with Dart 2.x, please ensure your version dependencies are set to:

    msgpack2: ^2.0.0

If you want to use this package for Dart projects with Dart 1.x, please ensure your version dependencies are set to:

    msgpack2: ^1.0.0

Simple Example #

import "dart:typed_data";

import "package:msgpack/msgpack.dart";

main() {
  var binary = new Uint8List.fromList(
    new List<int>.generate(40, (int i) => i)

  var data = {
    "String": "Hello World",
    "Integer": 42,
    "Double": 45.29,
    "Integer List": [1, 2, 3],
    "Binary": binary,
    "Map": {
      1: 2,
      3: 4

  List<int> packed = pack(data);
  Map unpacked = unpack(packed);


2.0.0 #

  • v2.0.0+1 - Update some metadata for the package.
  • v2.0.0 - Initial release for Dart 2.x.

1.0.0 #

  • v1.0.0+1 - Update some metadata for the package.
  • v1.0.0 - Initial release for Dart 1.x.


import "package:msgpack2/msgpack2.dart";

import "dart:typed_data";
import "dart:math";

main() {
  var byteList = new Uint8List(1024 * 1024 * 20);
  var random = new Random();
  for (var i = 0; i < byteList.lengthInBytes; i++) {
    byteList[i] = random.nextInt(255);
  var byteData = byteList.buffer
      .asByteData(byteList.offsetInBytes, byteList.lengthInBytes);

  var data = {
    "String": "Hello World",
    "Integer": 42,
    "Double": 45.29,
    "Integer List": [1, 2, 3],
    "Map": {1: 2, 3: 4},
    "Large Number": 1455232609379,
    "Negative Large Number": -1455232609379,
    "Simple Negative": -59,
    "Bytes": byteData,
    "Uint16": 65235

  List<int> packed = serialize(data);
  Map unpacked = deserialize(packed);

  print("Original: $data");
  print("Unpacked: $unpacked");

  ByteData gotByteData = unpacked["Bytes"];

  if (gotByteData.lengthInBytes != byteData.lengthInBytes) {
    throw "Byte data is not the correct amount of bytes.";

  for (var i = 0; i < gotByteData.lengthInBytes; i++) {
    if (byteData.getUint8(i) != gotByteData.getUint8(i)) {
      throw "Byte data is not the correct content.";

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  msgpack2: ^2.0.0+1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:msgpack2/msgpack2.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5

Health suggestions

Fix lib/msgpack2.dart. (-0.50 points)

Analysis of lib/msgpack2.dart reported 1 hint:

line 12 col 31: Avoid const keyword.

Maintenance suggestions

Package is getting outdated. (-27.12 points)

The package was last published 66 weeks ago.

The description is too long. (-6 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.3.0