Giter Site home page Giter Site logo

go-protom's Introduction

Go Proto MongoDB Utils

The lib is not considered as stable and an API might be broken until v1.x.x version is tagged.

This lib provides some utils to work with protobuf messages together with MongoDB.

Main reason to create this package is a protojson package that encodes proto messages differently than an encodying/json package. This creates a big gap between regular golang structs and structs provided by a protoc.

Message

This package is highly inspired by the original protojson package but bound to the go.mongodb.org/mongo-driver package.

The package provides codecs and a registry that compatible with the mongo-dirver and fits well into the mongo-driver encode/decode process. The codec designed mostly as intermediate component who can encode and decode the proto.Message and leverage the mongo-driver registry machinery to encode or decode primitive types and lists/maps.

Enum

Only special case is enums. Enums cannot be properly decoded because in protoreflect they represented as the protoreflect.EnumNumber which completely loose an original enum type, so when we encode or decode an enum value represented as string we cannot guess which enum we currently encode or decode.

To solve this we have two ways:

  1. Embed the enum codec into the ProtoMessageCodec.
  2. Implement the ProtoEnumCodec and introduce special handling of the enum values in the ProtoMessageCodec

In the protojson package implemented second solution. It decouple encode and decode of enums from the ProtoMessageCodec. But still introduce pretty ugly way to operate with enum fields in the message.

Usage:

If you use a default registry from mongo-driver you can just overwrite it in client โ€” registry provided by the protobson.BsonPBRegistry should be equal to default one, just with special hooks that will handle protobuf models.

If you customize your registry โ€” you should read the registry.go file and see how you can add required codecs into registry.

Partially implemented with some caveats. To see details - go to README in protobson/types package.

go-protom's People

Contributors

dependabot[bot] avatar rdmrcv avatar

Watchers

 avatar

go-protom's Issues

Better tests

Currently test is too optimistic and does not cover all edge cases.

Introduce EmitEmpty option

Introduce option to prevent encoder to emit empty values as null and omit entire value if it is empty.

Implement missing options.

Some options is presented in the ProtoMessageCodec but does not actually do something. Handle them properly or remove.

Currently do not works:

  • AllowMarshalPartial
  • AllowUnmarshalPartial
  • DiscardUnknown
    Partially supported. Do not decode fields to unknown but raise error on unknown fields if false is set..

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.