Code Monkey home page Code Monkey logo

bson-lua's Introduction

BSON generator/parser in pure Lua (5.1)

Introduction

This is a very simple BSON implementation in Lua. It doesn't support all BSON types (yet). In particular, and ironically, it doesn't support the floating point type.

Building

There are no external dependencies, Lua 5.1 or LuaJIT should work.

Supported Types

  • int32, int64
  • boolean
  • string
  • number
  • array
  • document
  • binary (generic)
  • UTC datetime

Limitations

  • Pure Lua has no way of retrieving millisecond system time, so right now I hack "seconds * 1000" for BSON datetime.
  • No support for floating point (double) until I figure out how to encode/decode it in pure Lua.
  • int64 is limited by Lua's double type.
  • No javascript-ish types (code, object_id, etc)

Getting started

Here is an example to get you started:

bson=require'bson'
epoch=os.time({year=1970, month=1, day=1, hour=0})
bsondoc1=bson.encode{username="maroc", 
		     info={first="todd",
			     last="coram",
			     age=46,
			     signature1=bson.binary("\000\001\002\003",bson.B_GENERIC),
			     signature2=bson.binary("\000\001\002\003"),
			     saved=true,
			     now=bson.utc_datetime(),
			     past=bson.utc_datetime(epoch * 1000),
			     colors={"Red","Green","Blue"}
		     }}
decoded=bson.decode(bsondoc1)

print("username = "..decoded.username)

for i,v in pairs(decoded) do print(i,v) end
print()
for i,v in pairs(decoded.info) do print(i,v) end
print()
for i,v in ipairs(decoded.info.colors) do print(i,v) end

/todd

bson-lua's People

Contributors

tcoram avatar i-rinat avatar dptole avatar

Watchers

James Cloos avatar

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.