package block

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

import (
	"0chain.net/chaincore/node"
	"github.com/tinylib/msgp/msgp"
)

// MarshalMsg implements msgp.Marshaler
func (z *MagicBlock) MarshalMsg(b []byte) (o []byte, err error) {
	o = msgp.Require(b, z.Msgsize())
	// map header, size 11
	// string "HashIDField"
	o = append(o, 0x8b, 0xab, 0x48, 0x61, 0x73, 0x68, 0x49, 0x44, 0x46, 0x69, 0x65, 0x6c, 0x64)
	o, err = z.HashIDField.MarshalMsg(o)
	if err != nil {
		err = msgp.WrapError(err, "HashIDField")
		return
	}
	// string "PreviousMagicBlockHash"
	o = append(o, 0xb6, 0x50, 0x72, 0x65, 0x76, 0x69, 0x6f, 0x75, 0x73, 0x4d, 0x61, 0x67, 0x69, 0x63, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x48, 0x61, 0x73, 0x68)
	o = msgp.AppendString(o, z.PreviousMagicBlockHash)
	// string "MagicBlockNumber"
	o = append(o, 0xb0, 0x4d, 0x61, 0x67, 0x69, 0x63, 0x42, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72)
	o = msgp.AppendInt64(o, z.MagicBlockNumber)
	// string "StartingRound"
	o = append(o, 0xad, 0x53, 0x74, 0x61, 0x72, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x6f, 0x75, 0x6e, 0x64)
	o = msgp.AppendInt64(o, z.StartingRound)
	// string "Miners"
	o = append(o, 0xa6, 0x4d, 0x69, 0x6e, 0x65, 0x72, 0x73)
	if z.Miners == nil {
		o = msgp.AppendNil(o)
	} else {
		o, err = z.Miners.MarshalMsg(o)
		if err != nil {
			err = msgp.WrapError(err, "Miners")
			return
		}
	}
	// string "Sharders"
	o = append(o, 0xa8, 0x53, 0x68, 0x61, 0x72, 0x64, 0x65, 0x72, 0x73)
	if z.Sharders == nil {
		o = msgp.AppendNil(o)
	} else {
		o, err = z.Sharders.MarshalMsg(o)
		if err != nil {
			err = msgp.WrapError(err, "Sharders")
			return
		}
	}
	// string "ShareOrSigns"
	o = append(o, 0xac, 0x53, 0x68, 0x61, 0x72, 0x65, 0x4f, 0x72, 0x53, 0x69, 0x67, 0x6e, 0x73)
	if z.ShareOrSigns == nil {
		o = msgp.AppendNil(o)
	} else {
		o, err = z.ShareOrSigns.MarshalMsg(o)
		if err != nil {
			err = msgp.WrapError(err, "ShareOrSigns")
			return
		}
	}
	// string "Mpks"
	o = append(o, 0xa4, 0x4d, 0x70, 0x6b, 0x73)
	if z.Mpks == nil {
		o = msgp.AppendNil(o)
	} else {
		o, err = z.Mpks.MarshalMsg(o)
		if err != nil {
			err = msgp.WrapError(err, "Mpks")
			return
		}
	}
	// string "T"
	o = append(o, 0xa1, 0x54)
	o = msgp.AppendInt(o, z.T)
	// string "K"
	o = append(o, 0xa1, 0x4b)
	o = msgp.AppendInt(o, z.K)
	// string "N"
	o = append(o, 0xa1, 0x4e)
	o = msgp.AppendInt(o, z.N)
	return
}

// UnmarshalMsg implements msgp.Unmarshaler
func (z *MagicBlock) UnmarshalMsg(bts []byte) (o []byte, err error) {
	var field []byte
	_ = field
	var zb0001 uint32
	zb0001, bts, err = msgp.ReadMapHeaderBytes(bts)
	if err != nil {
		err = msgp.WrapError(err)
		return
	}
	for zb0001 > 0 {
		zb0001--
		field, bts, err = msgp.ReadMapKeyZC(bts)
		if err != nil {
			err = msgp.WrapError(err)
			return
		}
		switch msgp.UnsafeString(field) {
		case "HashIDField":
			bts, err = z.HashIDField.UnmarshalMsg(bts)
			if err != nil {
				err = msgp.WrapError(err, "HashIDField")
				return
			}
		case "PreviousMagicBlockHash":
			z.PreviousMagicBlockHash, bts, err = msgp.ReadStringBytes(bts)
			if err != nil {
				err = msgp.WrapError(err, "PreviousMagicBlockHash")
				return
			}
		case "MagicBlockNumber":
			z.MagicBlockNumber, bts, err = msgp.ReadInt64Bytes(bts)
			if err != nil {
				err = msgp.WrapError(err, "MagicBlockNumber")
				return
			}
		case "StartingRound":
			z.StartingRound, bts, err = msgp.ReadInt64Bytes(bts)
			if err != nil {
				err = msgp.WrapError(err, "StartingRound")
				return
			}
		case "Miners":
			if msgp.IsNil(bts) {
				bts, err = msgp.ReadNilBytes(bts)
				if err != nil {
					return
				}
				z.Miners = nil
			} else {
				if z.Miners == nil {
					z.Miners = new(node.Pool)
				}
				bts, err = z.Miners.UnmarshalMsg(bts)
				if err != nil {
					err = msgp.WrapError(err, "Miners")
					return
				}
			}
		case "Sharders":
			if msgp.IsNil(bts) {
				bts, err = msgp.ReadNilBytes(bts)
				if err != nil {
					return
				}
				z.Sharders = nil
			} else {
				if z.Sharders == nil {
					z.Sharders = new(node.Pool)
				}
				bts, err = z.Sharders.UnmarshalMsg(bts)
				if err != nil {
					err = msgp.WrapError(err, "Sharders")
					return
				}
			}
		case "ShareOrSigns":
			if msgp.IsNil(bts) {
				bts, err = msgp.ReadNilBytes(bts)
				if err != nil {
					return
				}
				z.ShareOrSigns = nil
			} else {
				if z.ShareOrSigns == nil {
					z.ShareOrSigns = new(GroupSharesOrSigns)
				}
				bts, err = z.ShareOrSigns.UnmarshalMsg(bts)
				if err != nil {
					err = msgp.WrapError(err, "ShareOrSigns")
					return
				}
			}
		case "Mpks":
			if msgp.IsNil(bts) {
				bts, err = msgp.ReadNilBytes(bts)
				if err != nil {
					return
				}
				z.Mpks = nil
			} else {
				if z.Mpks == nil {
					z.Mpks = new(Mpks)
				}
				bts, err = z.Mpks.UnmarshalMsg(bts)
				if err != nil {
					err = msgp.WrapError(err, "Mpks")
					return
				}
			}
		case "T":
			z.T, bts, err = msgp.ReadIntBytes(bts)
			if err != nil {
				err = msgp.WrapError(err, "T")
				return
			}
		case "K":
			z.K, bts, err = msgp.ReadIntBytes(bts)
			if err != nil {
				err = msgp.WrapError(err, "K")
				return
			}
		case "N":
			z.N, bts, err = msgp.ReadIntBytes(bts)
			if err != nil {
				err = msgp.WrapError(err, "N")
				return
			}
		default:
			bts, err = msgp.Skip(bts)
			if err != nil {
				err = msgp.WrapError(err)
				return
			}
		}
	}
	o = bts
	return
}

// Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message
func (z *MagicBlock) Msgsize() (s int) {
	s = 1 + 12 + z.HashIDField.Msgsize() + 23 + msgp.StringPrefixSize + len(z.PreviousMagicBlockHash) + 17 + msgp.Int64Size + 14 + msgp.Int64Size + 7
	if z.Miners == nil {
		s += msgp.NilSize
	} else {
		s += z.Miners.Msgsize()
	}
	s += 9
	if z.Sharders == nil {
		s += msgp.NilSize
	} else {
		s += z.Sharders.Msgsize()
	}
	s += 13
	if z.ShareOrSigns == nil {
		s += msgp.NilSize
	} else {
		s += z.ShareOrSigns.Msgsize()
	}
	s += 5
	if z.Mpks == nil {
		s += msgp.NilSize
	} else {
		s += z.Mpks.Msgsize()
	}
	s += 2 + msgp.IntSize + 2 + msgp.IntSize + 2 + msgp.IntSize
	return
}
