Coder Social home page Coder Social logo

msgpack4s's Introduction

msgpack4s

A super-simple MessagePack serialization library for Scala, based on msgpack-java-lite

  • Simple API: MsgPack.pack(object) and MsgPack.unpack(byteArray).
  • Directly unpacks maps, sequences, and any non-cyclic nested sequences/maps to Scala immutable collections
  • Can unpack Map[Any, Any] or Map[String, Any] without extra code, unlike msgpack-scala
  • No extra dependencies. No need to build a separate Java library.
  • significantly (3x as of 3/29/13) faster than msgpack-scala for unpacking Maps

For the exact semantics of packing and unpacking, see the ScalaDoc.

Using this library

Include this in build.sbt:

repositories += "velvia maven" at "http://dl.bintray.com/velvia/maven"

libraryDependencies += "org.velvia" %% "msgpack4s" % "0.4.2"

Streaming mode

There is a streaming API available as well. This may be useful for cases where you need to unpack bytes that were written with multiple pack() calls. For example:

val outStream = new DataOutputStream(...)
MsgPack.pack(item1, outStream)
MsgPack.pack(item2, outStream)
MsgPack.pack(item3, outStream)

....

val item1: String = MsgPack.unpack(inStream, UNPACK_RAW_AS_STRING)
val item2: Int = MsgPack.unpack(inStream, 0)
val item3: Long = MsgPack.unpack(inStream, 0)

Convenience Functions

MsgPackUtils has convenience functions so you can pull out the right types from unpack without needing verbose isInstanceOf[..]. They are especially useful when working with numbers. For example:

import org.velvia.MsgPackUtils._
val map = unpackMap(bytes)
println("My number = " + map.asInt("number") + 99)

Building, testing, packaging

sbt test
sbt "+ package"
sbt "+ make-pom"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.