2018-03-28 18:49:41 +00:00
|
|
|
// +build binary_log
|
|
|
|
|
2022-03-20 19:19:42 +00:00
|
|
|
package zlog
|
2018-03-28 18:49:41 +00:00
|
|
|
|
|
|
|
// This file contains bindings to do binary encoding.
|
|
|
|
|
|
|
|
import (
|
2022-11-03 15:18:09 +00:00
|
|
|
"tuxpa.in/a/zlog/internal/cbor"
|
2018-03-28 18:49:41 +00:00
|
|
|
)
|
|
|
|
|
2018-05-10 22:01:41 +00:00
|
|
|
var (
|
|
|
|
_ encoder = (*cbor.Encoder)(nil)
|
2018-03-28 18:49:41 +00:00
|
|
|
|
2018-05-10 22:01:41 +00:00
|
|
|
enc = cbor.Encoder{}
|
|
|
|
)
|
2018-03-28 18:49:41 +00:00
|
|
|
|
2021-05-20 12:46:36 +00:00
|
|
|
func init() {
|
|
|
|
// using closure to reflect the changes at runtime.
|
|
|
|
cbor.JSONMarshalFunc = func(v interface{}) ([]byte, error) {
|
|
|
|
return InterfaceMarshalFunc(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 18:49:41 +00:00
|
|
|
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)
|
|
|
|
}
|