File: encoder_cbor.go

package info (click to toggle)
golang-github-rs-zerolog 1.29.1-1~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 728 kB
  • sloc: makefile: 11
file content (42 lines) | stat: -rw-r--r-- 941 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// +build binary_log

package zerolog

// This file contains bindings to do binary encoding.

import (
	"github.com/rs/zerolog/internal/cbor"
)

var (
	_ encoder = (*cbor.Encoder)(nil)

	enc = cbor.Encoder{}
)

func init() {
	// using closure to reflect the changes at runtime.
	cbor.JSONMarshalFunc = func(v interface{}) ([]byte, error) {
		return InterfaceMarshalFunc(v)
	}
}

func appendJSON(dst []byte, j []byte) []byte {
	return cbor.AppendEmbeddedJSON(dst, j)
}

// decodeIfBinaryToString - converts a binary formatted log msg to a
// JSON formatted String Log message.
func decodeIfBinaryToString(in []byte) string {
	return cbor.DecodeIfBinaryToString(in)
}

func decodeObjectToStr(in []byte) string {
	return cbor.DecodeObjectToStr(in)
}

// decodeIfBinaryToBytes - converts a binary formatted log msg to a
// JSON formatted Bytes Log message.
func decodeIfBinaryToBytes(in []byte) []byte {
	return cbor.DecodeIfBinaryToBytes(in)
}