2017-07-26 03:51:49 +00:00
|
|
|
package json
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"math"
|
2018-04-03 21:07:18 +00:00
|
|
|
"net"
|
2017-07-26 03:51:49 +00:00
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
2018-05-10 22:01:41 +00:00
|
|
|
// AppendNil inserts a 'Nil' object into the dst byte array.
|
|
|
|
func (Encoder) AppendNil(dst []byte) []byte {
|
|
|
|
return append(dst, "null"...)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendBeginMarker inserts a map start into the dst byte array.
|
|
|
|
func (Encoder) AppendBeginMarker(dst []byte) []byte {
|
|
|
|
return append(dst, '{')
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendEndMarker inserts a map end into the dst byte array.
|
|
|
|
func (Encoder) AppendEndMarker(dst []byte) []byte {
|
|
|
|
return append(dst, '}')
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendLineBreak appends a line break.
|
|
|
|
func (Encoder) AppendLineBreak(dst []byte) []byte {
|
|
|
|
return append(dst, '\n')
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendArrayStart adds markers to indicate the start of an array.
|
|
|
|
func (Encoder) AppendArrayStart(dst []byte) []byte {
|
|
|
|
return append(dst, '[')
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendArrayEnd adds markers to indicate the end of an array.
|
|
|
|
func (Encoder) AppendArrayEnd(dst []byte) []byte {
|
|
|
|
return append(dst, ']')
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendArrayDelim adds markers to indicate end of a particular array element.
|
|
|
|
func (Encoder) AppendArrayDelim(dst []byte) []byte {
|
|
|
|
if len(dst) > 0 {
|
|
|
|
return append(dst, ',')
|
|
|
|
}
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendBool converts the input bool to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendBool(dst []byte, val bool) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendBool(dst, val)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendBools encodes the input bools to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendBools(dst []byte, vals []bool) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendBool(dst, vals[0])
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendBool(append(dst, ','), val)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInt converts the input int to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInt(dst []byte, val int) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendInt(dst, int64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInts encodes the input ints to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInts(dst []byte, vals []int) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendInt(dst, int64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendInt(append(dst, ','), int64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInt8 converts the input []int8 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInt8(dst []byte, val int8) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendInt(dst, int64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInts8 encodes the input int8s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInts8(dst []byte, vals []int8) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendInt(dst, int64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendInt(append(dst, ','), int64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInt16 converts the input int16 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInt16(dst []byte, val int16) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendInt(dst, int64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInts16 encodes the input int16s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInts16(dst []byte, vals []int16) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendInt(dst, int64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendInt(append(dst, ','), int64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInt32 converts the input int32 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInt32(dst []byte, val int32) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendInt(dst, int64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInts32 encodes the input int32s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInts32(dst []byte, vals []int32) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendInt(dst, int64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendInt(append(dst, ','), int64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInt64 converts the input int64 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInt64(dst []byte, val int64) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendInt(dst, val, 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInts64 encodes the input int64s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendInts64(dst []byte, vals []int64) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendInt(dst, vals[0], 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendInt(append(dst, ','), val, 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUint converts the input uint to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUint(dst []byte, val uint) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendUint(dst, uint64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUints encodes the input uints to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUints(dst []byte, vals []uint) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendUint(dst, uint64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendUint(append(dst, ','), uint64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUint8 converts the input uint8 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUint8(dst []byte, val uint8) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendUint(dst, uint64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUints8 encodes the input uint8s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUints8(dst []byte, vals []uint8) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendUint(dst, uint64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendUint(append(dst, ','), uint64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUint16 converts the input uint16 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUint16(dst []byte, val uint16) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendUint(dst, uint64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUints16 encodes the input uint16s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUints16(dst []byte, vals []uint16) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendUint(dst, uint64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendUint(append(dst, ','), uint64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUint32 converts the input uint32 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUint32(dst []byte, val uint32) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
return strconv.AppendUint(dst, uint64(val), 10)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUints32 encodes the input uint32s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUints32(dst []byte, vals []uint32) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendUint(dst, uint64(vals[0]), 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendUint(append(dst, ','), uint64(val), 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUint64 converts the input uint64 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUint64(dst []byte, val uint64) []byte {
|
2021-12-21 12:07:54 +00:00
|
|
|
return strconv.AppendUint(dst, val, 10)
|
2017-07-26 03:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendUints64 encodes the input uint64s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendUints64(dst []byte, vals []uint64) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
|
|
|
dst = strconv.AppendUint(dst, vals[0], 10)
|
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
|
|
|
dst = strconv.AppendUint(append(dst, ','), val, 10)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-05-10 22:01:41 +00:00
|
|
|
func appendFloat(dst []byte, val float64, bitSize int) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
// JSON does not permit NaN or Infinity. A typical JSON encoder would fail
|
2021-12-21 12:07:54 +00:00
|
|
|
// with an error, but a logging library wants the data to get through so we
|
2017-07-26 03:51:49 +00:00
|
|
|
// make a tradeoff and store those types as string.
|
|
|
|
switch {
|
|
|
|
case math.IsNaN(val):
|
|
|
|
return append(dst, `"NaN"`...)
|
|
|
|
case math.IsInf(val, 1):
|
|
|
|
return append(dst, `"+Inf"`...)
|
|
|
|
case math.IsInf(val, -1):
|
|
|
|
return append(dst, `"-Inf"`...)
|
|
|
|
}
|
|
|
|
return strconv.AppendFloat(dst, val, 'f', -1, bitSize)
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendFloat32 converts the input float32 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendFloat32(dst []byte, val float32) []byte {
|
|
|
|
return appendFloat(dst, float64(val), 32)
|
2017-07-26 03:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendFloats32 encodes the input float32s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendFloats32(dst []byte, vals []float32) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
2018-05-10 22:01:41 +00:00
|
|
|
dst = appendFloat(dst, float64(vals[0]), 32)
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
2018-05-10 22:01:41 +00:00
|
|
|
dst = appendFloat(append(dst, ','), float64(val), 32)
|
2017-07-26 03:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendFloat64 converts the input float64 to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendFloat64(dst []byte, val float64) []byte {
|
|
|
|
return appendFloat(dst, val, 64)
|
2017-07-26 03:51:49 +00:00
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendFloats64 encodes the input float64s to json and
|
|
|
|
// appends the encoded string list to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendFloats64(dst []byte, vals []float64) []byte {
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) == 0 {
|
|
|
|
return append(dst, '[', ']')
|
|
|
|
}
|
|
|
|
dst = append(dst, '[')
|
2020-10-27 16:05:59 +00:00
|
|
|
dst = appendFloat(dst, vals[0], 64)
|
2017-07-26 03:51:49 +00:00
|
|
|
if len(vals) > 1 {
|
|
|
|
for _, val := range vals[1:] {
|
2018-05-10 22:01:41 +00:00
|
|
|
dst = appendFloat(append(dst, ','), val, 64)
|
2017-07-26 03:51:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
dst = append(dst, ']')
|
|
|
|
return dst
|
|
|
|
}
|
|
|
|
|
2018-03-15 17:29:26 +00:00
|
|
|
// AppendInterface marshals the input interface to a string and
|
|
|
|
// appends the encoded string to the input byte slice.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (e Encoder) AppendInterface(dst []byte, i interface{}) []byte {
|
2021-05-20 12:46:36 +00:00
|
|
|
marshaled, err := JSONMarshalFunc(i)
|
2017-07-26 03:51:49 +00:00
|
|
|
if err != nil {
|
2018-05-10 22:01:41 +00:00
|
|
|
return e.AppendString(dst, fmt.Sprintf("marshaling error: %v", err))
|
2017-07-26 03:51:49 +00:00
|
|
|
}
|
|
|
|
return append(dst, marshaled...)
|
|
|
|
}
|
2018-03-28 18:49:41 +00:00
|
|
|
|
2018-04-03 21:07:18 +00:00
|
|
|
// AppendObjectData takes in an object that is already in a byte array
|
|
|
|
// and adds it to the dst.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (Encoder) AppendObjectData(dst []byte, o []byte) []byte {
|
2019-06-05 06:48:09 +00:00
|
|
|
// Three conditions apply here:
|
|
|
|
// 1. new content starts with '{' - which should be dropped OR
|
|
|
|
// 2. new content starts with '{' - which should be replaced with ','
|
|
|
|
// to separate with existing content OR
|
|
|
|
// 3. existing content has already other fields
|
2018-03-28 18:49:41 +00:00
|
|
|
if o[0] == '{' {
|
2020-05-06 02:44:34 +00:00
|
|
|
if len(dst) > 1 {
|
|
|
|
dst = append(dst, ',')
|
2019-06-05 06:48:09 +00:00
|
|
|
}
|
2020-05-06 02:44:34 +00:00
|
|
|
o = o[1:]
|
2018-03-28 18:49:41 +00:00
|
|
|
} else if len(dst) > 1 {
|
|
|
|
dst = append(dst, ',')
|
|
|
|
}
|
|
|
|
return append(dst, o...)
|
|
|
|
}
|
2018-04-03 21:07:18 +00:00
|
|
|
|
|
|
|
// AppendIPAddr adds IPv4 or IPv6 address to dst.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (e Encoder) AppendIPAddr(dst []byte, ip net.IP) []byte {
|
|
|
|
return e.AppendString(dst, ip.String())
|
2018-04-03 21:07:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AppendIPPrefix adds IPv4 or IPv6 Prefix (address & mask) to dst.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (e Encoder) AppendIPPrefix(dst []byte, pfx net.IPNet) []byte {
|
|
|
|
return e.AppendString(dst, pfx.String())
|
2018-04-03 21:07:18 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// AppendMACAddr adds MAC address to dst.
|
2018-05-10 22:01:41 +00:00
|
|
|
func (e Encoder) AppendMACAddr(dst []byte, ha net.HardwareAddr) []byte {
|
|
|
|
return e.AppendString(dst, ha.String())
|
2018-04-03 21:07:18 +00:00
|
|
|
}
|