...

Source file src/github.com/rs/zerolog/encoder_cbor.go

Documentation: github.com/rs/zerolog

     1  // +build binary_log
     2  
     3  package zerolog
     4  
     5  // This file contains bindings to do binary encoding.
     6  
     7  import (
     8  	"github.com/rs/zerolog/internal/cbor"
     9  )
    10  
    11  var (
    12  	_ encoder = (*cbor.Encoder)(nil)
    13  
    14  	enc = cbor.Encoder{}
    15  )
    16  
    17  func init() {
    18  	// using closure to reflect the changes at runtime.
    19  	cbor.JSONMarshalFunc = func(v interface{}) ([]byte, error) {
    20  		return InterfaceMarshalFunc(v)
    21  	}
    22  }
    23  
    24  func appendJSON(dst []byte, j []byte) []byte {
    25  	return cbor.AppendEmbeddedJSON(dst, j)
    26  }
    27  
    28  // decodeIfBinaryToString - converts a binary formatted log msg to a
    29  // JSON formatted String Log message.
    30  func decodeIfBinaryToString(in []byte) string {
    31  	return cbor.DecodeIfBinaryToString(in)
    32  }
    33  
    34  func decodeObjectToStr(in []byte) string {
    35  	return cbor.DecodeObjectToStr(in)
    36  }
    37  
    38  // decodeIfBinaryToBytes - converts a binary formatted log msg to a
    39  // JSON formatted Bytes Log message.
    40  func decodeIfBinaryToBytes(in []byte) []byte {
    41  	return cbor.DecodeIfBinaryToBytes(in)
    42  }
    43  

View as plain text