Coder Social home page Coder Social logo

msgpack-bal's Introduction

msgpack-bal

an implementation of the msgpack spec in ballerina.

!!! this library is still a WIP, see the progress tracker below.

how to use

import it from your ballerina project by tossing this into your Ballerina.toml file

[[dependency]]
org="drewmca"
name="msgpack"
version="0.0.7"

and your editor should see the module and let you use the library, something like this:

import ballerina/io;
import drewmca/msgpack;
json obj = {"hello": "world!"}
byte[] encoded = msgpack:encode(obj);
json decoded = msgpack:decode(encoded);
io:println(decoded);

Formats implemented

from the msgpack format spec

  • nil format
    • nil
  • bool format family
    • true
    • false
  • int format family
    • PositiveFixInt
    • NegativeFixInt
    • Uint8
    • Uint16
    • Uint32
    • Uint64
    • Int8
    • Int16
    • Int32
    • Int64 (not implemented bc ballerina cannot do 1 << 64)
  • float format family
    • Float32
    • Float64
  • str format family
    • FixStr
    • Str8
    • Str16
    • Str32 (implemented but untested)
  • bin format family
    • Bin8
    • Bin16
    • Bin32 (implemented but untested)
  • array format family
    • FixArray
    • Array16
    • Array32 (implemented but untested)
  • map format family
    • FixMap
    • Map16
    • Map32 (implemented but untested)
  • ext format family
    • Ext8
    • Ext16
    • Ext32
    • FixExt1
    • FixExt2
    • FixExt4
    • FixExt8
    • FixExt16
  • Timestamp extension type

Roadmap

This is a quick and dirty implementation, generally building out functionality first and will refactor after.

  • v0.3: implementation of some, but not all of the spec. quick & dirty implementation.
  • v0.4: added benchmarks, coreutil for int->byte[] map16, str, & int impl
  • v0.5: implemented maps and arrays, also refactored decoding to pop bytes off as it goes
  • v0.6: implemented binary byte arrays, introduced some better error handling
  • v0.7: version bump for updating docs and pushing to bal central
  • v1.0: full compatibility with the msgpack spec, including a full test suite and benchmarks

TODO:

  • create a big json file of test cases
  • put a checkbox of msgpack format types here
  • separate functions into different files
  • refactor decoding to pop bytes off the array
  • test long array/map values

msgpack-bal's People

Contributors

drewmcarthur avatar

Stargazers

 avatar

Watchers

 avatar  avatar

msgpack-bal's Issues

Cannot decode large signed Int64

from testCases.bal:67

// saving this test case for later: encoding works, 
// but currently trying to run decode([0xd3, ...]) will fail, 
// because 0xd3 == signed Int64, and our algorithm fails.
// this is because we calculat an int, then subtract (1 << 8*nBytes), and 
// if nBytes == 8, we would try to 1 << 64, which doesn't work with 64-bit ints.
TestCase[] SignedInt64TestCase = [
    {"input": -11111111111, "output": [0xd3, 0xff, 0xff, 0xff, 0xfd, 0x69, 0xb9, 0xe6, 0x39]}
];

`Float` type not yet implemented

Main blocker on this is messing with number -> binary conversions, endianness, etc. feels like this should be another ballerina library that we can lean on.

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.