GithubHelp home page GithubHelp logo

selectel / bson-haskell Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mongodb/bson-haskell

11.0 14.0 4.0 320 KB

Haskell representation and serialization of BSON documents (version 1.0) as defined at bsonspec.org

Home Page: http://hackage.haskell.org/package/bson

License: Apache License 2.0

Haskell 100.00%
community haskell

bson-haskell's Introduction

bson-haskell Build Status

Haskell library for the encoding and decoding BSON documents, which are JSON-like objects with a standard binary encoding, defined at http://bsonspec.org. This library implements version 1 of that spec.

A BSON Document is an untyped (dynamically type-checked) record. I.e. it is a list of name-value pairs, where a Value is a single sum type with constructors for basic types (Bool, Int, Float, String, and Time), compound types (List, and (embedded) Document), and special types (Binary, Javascript, ObjectId, RegEx, and a few others).

bson-haskell's People

Contributors

ajhannan avatar gregwebs avatar knsd avatar luite avatar nathanhowell avatar rocco66 avatar siim avatar sseveran avatar superbobry avatar tommd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bson-haskell's Issues

BSON to JSON?

Is there an easy way to convert BSON to JSON? The two ways in which this would be useful are to convert to an aeson data structure and convert to a JSON string (Text, ByteString, etc.).

David

Library fails on reading BSON with additional data at the end

Hello.
While parsing some files I noticed that when BSON file has some "extra" 0s at the end, it can't be parsed. The problem is that getDocument stops on the end of file, but it should stop on 0. Here is my git diff patch fixing the problem for me:

diff --git a/Data/Bson/Binary.hs b/Data/Bson/Binary.hs
index 361296a..339a5e4 100644
--- a/Data/Bson/Binary.hs
+++ b/Data/Bson/Binary.hs
@@ -13,7 +13,7 @@ import Control.Applicative ((<$>), (<*>))
 import Control.Monad (when)
 import Data.Binary.Get (Get, runGet, getWord8, getWord32be, getWord64be,
                         getWord32le, getWord64le, getLazyByteStringNul,
-                        getLazyByteString, getByteString, isEmpty)
+                        getLazyByteString, getByteString, isEmpty, lookAhead)
 import Data.Binary.Put (Put, runPut, putWord8, putWord32le, putWord64le,
                         putWord32be, putWord64be, putLazyByteString,
                         putByteString)
@@ -148,12 +148,11 @@ putDocument es = let b = runPut (mapM_ putField es) in do

 getDocument :: Get Document
 getDocument = do
-       len <- subtract 5 <$> getInt32
+       len <- subtract 4 <$> getInt32
        b <- getLazyByteString (fromIntegral len)
-       getWord8
        return (runGet getFields b)
  where
-       getFields = isEmpty >>= \done -> if done
+       getFields = lookAhead getWord8 >>= \done -> if done==0
                then return []
                else (:) <$> getField <*> getFields

Hope it will be helpful for you.

Version requirement of `Text` package

Thanks for making the awesome bson package. I’m wondering if you can modify the dependency of bson to allow for more recent versions of text packages? I’m using persistent-mongoDB that ultimately depends on bson, but since bson requires an old version of text there will be conflict if text package’s more recent version is required elsewhere in the build.

Currently I’m removing this constraint manually when i install bson to work around it and it doesn’t seem to break it with 1.*’s text. Hope you can consider updating it.

Human-readable typeclass names

The current BSON typeclass has a really confusing name, maybe we should:

  • split the implementation into two typeclasses, similar to aeson;
  • give them proper names, ex: ToBson, FromBson.

User defined binary subtypes

I have a MongoDB collection that have data with user-defined binary subtypes.
bson-haskell only handles the subtype explicitly defined in the spec (0x80 for user-defined data), but it's possible to use any byte value for the subtype in MongoDB.

0x80 is a strange choice of constant to use for user defined, unless the intention was allow values of 0x80 and above to be user defined. And there is definitely a use for multiple user-defined binary types.

The values of the subtype in my collection are all 0x80 and above.

In any case, I would like for bson-haskell to be able to read my data without failing and leave the interpretation of binary data to the application.

To avoid breaking the interface, I changed UserDefined in my local copy to:
data UserDefined = UserDefined S.ByteString | UserDefinedExt Word8 S.ByteString

and all data with unknown subtype becomes UserDefinedExt.

Lower version bound on binary

It looks like Data.Bson requires the lookAhead function in Data.Binary.Get. This was added in version 0.7.0. Adding a lower bound

binary >= 0.7

to bson.cabal should avoid some compilation errors.

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.