Skip to content

gaplotech/kotlin-protobuf-bson-codec

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Introduction

kotlin-protobuf-bson-codec provide a PBCodecProvider to encode/decode from google protocol buffer & BSON genericly. It is 100% written by Kotlin.

The underlying implementation (PBBsonReader & PBBsonWriter) are mainly inspired by the official google protocol buffer json serialization (JsonFormat.Parser & JsonFormat.Printer).

Compatibility

PBCodecProvider is compatible to all mongodb driver using org.bson.*, for example

Note: Only Proto3 is supported

Gradle

compile 'io.github.gaplotech:kotlin-protobuf-bson-codec:0.3.0'

Maven

<dependency>
  <groupId>io.github.gaplotech</groupId>
  <artifactId>kotlin-protobuf-bson-codec</artifactId>
  <version>0.3.0</version>
</dependency>

Example

// register the codec provider
val registry = CodecRegistries.fromRegistries(
                   CodecRegistries.fromProviders(PBCodecProvider()),
                   MongoClients.getDefaultCodecRegistry()
               )

// use the registry for the database
val collection = createClient()
    .getDatabase(...)
    .withCodecRegistry(registry)