// Code generated by github.com/tinylib/msgp DO NOT EDIT.

package tracer

import (
	"github.com/tinylib/msgp/msgp"
)

// DecodeMsg implements msgp.Decodable
func (z *SpanLink) DecodeMsg(dc *msgp.Reader) (err error) {
	var field []byte
	_ = field
	var zb0001 uint32
	zb0001, err = dc.ReadMapHeader()
	if err != nil {
		err = msgp.WrapError(err)
		return
	}
	for zb0001 > 0 {
		zb0001--
		field, err = dc.ReadMapKeyPtr()
		if err != nil {
			err = msgp.WrapError(err)
			return
		}
		switch msgp.UnsafeString(field) {
		case "trace_id":
			z.TraceID, err = dc.ReadUint64()
			if err != nil {
				err = msgp.WrapError(err, "TraceID")
				return
			}
		case "trace_id_high":
			z.TraceIDHigh, err = dc.ReadUint64()
			if err != nil {
				err = msgp.WrapError(err, "TraceIDHigh")
				return
			}
		case "span_id":
			z.SpanID, err = dc.ReadUint64()
			if err != nil {
				err = msgp.WrapError(err, "SpanID")
				return
			}
		case "attributes":
			var zb0002 uint32
			zb0002, err = dc.ReadMapHeader()
			if err != nil {
				err = msgp.WrapError(err, "Attributes")
				return
			}
			if z.Attributes == nil {
				z.Attributes = make(map[string]string, zb0002)
			} else if len(z.Attributes) > 0 {
				clear(z.Attributes)
			}
			for zb0002 > 0 {
				zb0002--
				var za0001 string
				za0001, err = dc.ReadString()
				if err != nil {
					err = msgp.WrapError(err, "Attributes")
					return
				}
				var za0002 string
				za0002, err = dc.ReadString()
				if err != nil {
					err = msgp.WrapError(err, "Attributes", za0001)
					return
				}
				z.Attributes[za0001] = za0002
			}
		case "tracestate":
			z.Tracestate, err = dc.ReadString()
			if err != nil {
				err = msgp.WrapError(err, "Tracestate")
				return
			}
		case "flags":
			z.Flags, err = dc.ReadUint32()
			if err != nil {
				err = msgp.WrapError(err, "Flags")
				return
			}
		default:
			err = dc.Skip()
			if err != nil {
				err = msgp.WrapError(err)
				return
			}
		}
	}
	return
}

// EncodeMsg implements msgp.Encodable
func (z *SpanLink) EncodeMsg(en *msgp.Writer) (err error) {
	// check for omitted fields
	zb0001Len := uint32(6)
	var zb0001Mask uint8 /* 6 bits */
	_ = zb0001Mask
	if z.TraceIDHigh == 0 {
		zb0001Len--
		zb0001Mask |= 0x2
	}
	if z.Attributes == nil {
		zb0001Len--
		zb0001Mask |= 0x8
	}
	if z.Tracestate == "" {
		zb0001Len--
		zb0001Mask |= 0x10
	}
	if z.Flags == 0 {
		zb0001Len--
		zb0001Mask |= 0x20
	}
	// variable map header, size zb0001Len
	err = en.Append(0x80 | uint8(zb0001Len))
	if err != nil {
		return
	}

	// skip if no fields are to be emitted
	if zb0001Len != 0 {
		// write "trace_id"
		err = en.Append(0xa8, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64)
		if err != nil {
			return
		}
		err = en.WriteUint64(z.TraceID)
		if err != nil {
			err = msgp.WrapError(err, "TraceID")
			return
		}
		if (zb0001Mask & 0x2) == 0 { // if not omitted
			// write "trace_id_high"
			err = en.Append(0xad, 0x74, 0x72, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x5f, 0x68, 0x69, 0x67, 0x68)
			if err != nil {
				return
			}
			err = en.WriteUint64(z.TraceIDHigh)
			if err != nil {
				err = msgp.WrapError(err, "TraceIDHigh")
				return
			}
		}
		// write "span_id"
		err = en.Append(0xa7, 0x73, 0x70, 0x61, 0x6e, 0x5f, 0x69, 0x64)
		if err != nil {
			return
		}
		err = en.WriteUint64(z.SpanID)
		if err != nil {
			err = msgp.WrapError(err, "SpanID")
			return
		}
		if (zb0001Mask & 0x8) == 0 { // if not omitted
			// write "attributes"
			err = en.Append(0xaa, 0x61, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x73)
			if err != nil {
				return
			}
			err = en.WriteMapHeader(uint32(len(z.Attributes)))
			if err != nil {
				err = msgp.WrapError(err, "Attributes")
				return
			}
			for za0001, za0002 := range z.Attributes {
				err = en.WriteString(za0001)
				if err != nil {
					err = msgp.WrapError(err, "Attributes")
					return
				}
				err = en.WriteString(za0002)
				if err != nil {
					err = msgp.WrapError(err, "Attributes", za0001)
					return
				}
			}
		}
		if (zb0001Mask & 0x10) == 0 { // if not omitted
			// write "tracestate"
			err = en.Append(0xaa, 0x74, 0x72, 0x61, 0x63, 0x65, 0x73, 0x74, 0x61, 0x74, 0x65)
			if err != nil {
				return
			}
			err = en.WriteString(z.Tracestate)
			if err != nil {
				err = msgp.WrapError(err, "Tracestate")
				return
			}
		}
		if (zb0001Mask & 0x20) == 0 { // if not omitted
			// write "flags"
			err = en.Append(0xa5, 0x66, 0x6c, 0x61, 0x67, 0x73)
			if err != nil {
				return
			}
			err = en.WriteUint32(z.Flags)
			if err != nil {
				err = msgp.WrapError(err, "Flags")
				return
			}
		}
	}
	return
}

// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (z *SpanLink) Msgsize() (s int) {
	s = 1 + 9 + msgp.Uint64Size + 14 + msgp.Uint64Size + 8 + msgp.Uint64Size + 11 + msgp.MapHeaderSize
	if z.Attributes != nil {
		for za0001, za0002 := range z.Attributes {
			_ = za0002
			s += msgp.StringPrefixSize + len(za0001) + msgp.StringPrefixSize + len(za0002)
		}
	}
	s += 11 + msgp.StringPrefixSize + len(z.Tracestate) + 6 + msgp.Uint32Size
	return
}
