decimalcodec

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2021 License: MIT Imports: 7 Imported by: 0

README

decimal.Decimal{} codec

Go Doc Go Report Card

Encoder and Decoder Codec for decimal.Decimal{} as primitive.Decimal128 on official mongo-go-driver

Usage

import (
    ...
    "github.com/muktihari/decimalcodec"
)

func main() {
    rb := bsoncodec.NewRegistryBuilder()

    // you might want to include defaults encoder and decoder as well
    bsoncodec.DefaultValueDecoders{}.RegisterDefaultDecoders(rb)
    bsoncodec.DefaultValueEncoders{}.RegisterDefaultEncoders(rb)

    decimalcodec.RegisterEncodeDecoder(rb)
    
    registry := rb.Build()
    
    client, err := mongo.Connect(context.Background(),
        options.Client().
            ApplyURI("mongodb://localhost:27017").
            SetRegistry(registry),
    )
    ...
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecimalValueDecoder

func DecimalValueDecoder(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, v reflect.Value) (err error)

DecimalValueDecoder implements bsoncodec.ValueDecoderFunc

func DecimalValueEncoder

func DecimalValueEncoder(ec bsoncodec.EncodeContext, vw bsonrw.ValueWriter, v reflect.Value) (err error)

DecimalValueEncoder implements bsoncodec.ValueEncoderFunc

func RegisterEncodeDecoder

func RegisterEncodeDecoder(rb *bsoncodec.RegistryBuilder)

RegisterEncodeDecoder register decimal.Decimal ValueEncoder and ValueDecoder into *bsoncodec.RegistryBuilder.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL