Home

Awesome

vertx-bson-codec

Build Status

BSON Codec for Vert.x 3

Why another codec?

The standard EventBus from Vert.x allows Verticles to communicate with each other using JSON. JSON is a generic and fairly simple encoding scheme, however it limits the data types to be:

Although for most cases these data types are enough, in some more complex cases a Verticle might need to exchange more rich type data such as Dates, Integers, UUIDs, Regular Expressions, Binary data. This is where the BSON EventBus comes in.

Implementation details

The module has no external dependencies, I've decided to implement the bson codec myself to optimize the usage of vert.x buffers, and for that reason it is quite basic for the moment.

Type mapping implementation status

BSONJavaImplementedComments
Floating PointDouble
UTF-8 StringString
Embedded Documentjava.util.Map
Arrayjava.util.List
Binary::Genericbyte[]
Binary::Function
Binary::Binary (OLD)byte[]Deprecated/Only ReadOnly Support (when other sources write data to the Bus
Binary::UUID (OLD)Deprecated
Binary::UUIDjava.util.UUID
Binary::MD5com.jetdrone.bson.vertx.MD5This is a interface that you need to implement getHash() : byte[]
Binary::User Definedcom.jetdrone.bson.vertx.BinaryThis is a interface that you need to implement getBytes() : byte[]
UndefinedDeprecated
ObjectIdcom.jetdrone.bson.vertx.ObjectId
BooleanBoolean
UTC Datetimejava.util.Date
Nullnull
Regular Expressionjava.util.regex.Pattern
DBPointerDeprecated
JavaScript Code
SymbolDeprecated
JavaScript Code w/scope
32bit IntegerInteger
Timestampjava.sql.Timestamp
64bit IntegerLong
MinKeycom.jetdrone.bson.vertx.Key.MIN
MaxKeycom.jetdrone.bson.vertx.Key.MAX

Quickstart

Just register the Codec as any other codec:

    EventBus eb = vertx.eventBus();

    eb.registerDefaultCodec(BSONDocument.class, new BSONMessageCodec());