No description
Find a file
Akira Hayakawa 3e36b57f17 use quit() on unreachable path
Signed-off-by: Akira Hayakawa <ruby.wktk@gmail.com>
2019-10-12 19:34:13 +09:00
GenTests fix quickcheck 2019-10-12 19:06:08 +09:00
.travis.yml modify travis script 2019-10-12 18:06:51 +09:00
example.nim fix readme 2015-03-14 12:50:30 +09:00
gentest.rb remove echoing to remove overhead 2015-03-13 13:16:41 +09:00
LICENSE Initial commit 2015-02-22 18:38:46 +09:00
Makefile use stack to build haskell program 2019-10-12 17:46:31 +09:00
msgpack.html mark public: $ for debugging 2015-03-15 19:38:06 +09:00
msgpack.nim use quit() on unreachable path 2019-10-12 19:34:13 +09:00
msgpack.nimble add checklist (I love check list!!!) 2015-02-23 19:05:00 +09:00
overview.svg update fig 2015-03-14 12:36:47 +09:00
README.md Update README.md 2015-10-26 12:38:36 +09:00
stack.yaml use stack to build haskell program 2019-10-12 17:46:31 +09:00
unwrapinto.nim add unwrappable.nim 2015-03-13 22:55:46 +09:00
unwrappable.nim add unwrappable.nim 2015-03-13 22:55:46 +09:00

I will start this project once Nim compiler reaches 1.0

msgpack-nim

A MessagePack binding for Nim

Build Status

API: https://rawgit.com/akiradeveloper/msgpack-nim/master/msgpack.html

msgpack-nim currently provides only the basic functionality. Please see what's listed in Todo section. Compared to other language bindings, it's well-tested by 1000 auto-generated test cases by Haskell QuickCheck, which always runs on every commit to Github repository. Please try make quickcheck on your local machine to see what happens (It will take a bit while. Be patient). Have a nice packing!

Overview

Install

$ nimble update
$ nimble install msgpack

Example

import msgpack
import streams

# You can use any stream subclasses to serialize/deserialize
# messages. e.g. FileStream
let st: Stream = newStringStream()

assert(st.getPosition == 0)

# Type checking protects you from making trivial mistakes.
# Now we pack {"a":[5,-3], "b":[1,2,3]} but more complex
# combination of any Msg types is allowed.
#
# In xs we can mix specific conversion (PFixNum) and generic
# conversion (unwrap).
let xs: Msg = wrap(@[PFixNum(5), (-3).wrap])
let ys: Msg = wrap(@[("a".wrap, xs.wrap), ("b".wrap, @[1, 2, 3].wrap)])
st.pack(ys.wrap) # Serialize!

# We need to reset the cursor to the beginning of the target
# byte sequence.
st.setPosition(0)

let msg = st.unpack # Deserialize!

# output:
# a
# 5
# -3
# b
# 1
# 2
# 3
for e in msg.unwrapMap:
  echo e.key.unwrapStr
  for e in e.val.unwrapArray:
    echo e.unwrapInt

Todo

  • Implement unwrapInto to convert Msg object to Nim object handily
  • Evaluate performance and scalability
  • Talk with offical Ruby implementation
  • Don't repeat yourself: The code now has too much duplications. Using templates?

Author

Akira Hayakawa (ruby.wktk@gmail.com)