// serializeUtxoEntry returns the entry serialized to a format that is suitable
// for long-term storage.  The format is described in detail above.
9551
func serializeUtxoEntry(entry *UtxoEntry) ([]byte, error) {
	// Spent outputs have no serialization.
	if entry.IsSpent() {
		return nil, nil
	}

	// Encode the header code.
	headerCode, err := utxoEntryHeaderCode(entry)
	if err != nil {
		return nil, err
	}

	// Calculate the size needed to serialize the entry.
	size := serializeSizeVLQ(headerCode) +
		compressedTxOutSize(uint64(entry.Amount()), entry.PkScript())

	// Serialize the header code followed by the compressed unspent
	// transaction output.
	serialized := make([]byte, size)
	offset := putVLQ(serialized, headerCode)
	offset += putCompressedTxOut(serialized[offset:], uint64(entry.Amount()),
		entry.PkScript())

	return serialized, nil
}
890262
func (pk *PublicKey) serializeWithoutHeaders(w io.Writer) (err error) {
	var buf [6]byte
	buf[0] = 4
	t := uint32(pk.CreationTime.Unix())
	buf[1] = byte(t >> 24)
	buf[2] = byte(t >> 16)
	buf[3] = byte(t >> 8)
	buf[4] = byte(t)
	buf[5] = byte(pk.PubKeyAlgo)

	_, err = w.Write(buf[:])
	if err != nil {
		return
	}

	switch pk.PubKeyAlgo {
	case PubKeyAlgoRSA, PubKeyAlgoRSAEncryptOnly, PubKeyAlgoRSASignOnly:
		return writeMPIs(w, pk.n, pk.e)
	case PubKeyAlgoDSA:
		return writeMPIs(w, pk.p, pk.q, pk.g, pk.y)
	case PubKeyAlgoElGamal:
		return writeMPIs(w, pk.p, pk.g, pk.y)
	case PubKeyAlgoECDSA:
		return pk.ec.serialize(w)
	case PubKeyAlgoECDH:
		if err = pk.ec.serialize(w); err != nil {
			return
		}
		return pk.ecdh.serialize(w)
	}
	return errors.InvalidArgumentError("bad public-key algorithm")
}
536609
func (p *PublicKey) SerializeUncompressed() []byte {
	b := make([]byte, 0, PubKeyBytesLenUncompressed)
	b = append(b, pubkeyUncompressed)
	b = paddedAppend(32, b, p.X.Bytes())
	return paddedAppend(32, b, p.Y.Bytes())
}
79724
func (pgb *ChainDB) InitUtxoCache(utxos []dbtypes.UTXO) {
	pgb.utxoCache.Reinit(utxos)
}
280035
func (b *IPRouteBody) Serialize(version uint8) ([]byte, error) {
	var buf []byte
	if version <= 3 {
		buf = make([]byte, 5)
	} else if version == 4 {
		buf = make([]byte, 10)
	} else { // version >= 5
		buf = make([]byte, 9)
	}
	buf[0] = uint8(b.Type)
	if version <= 3 {
		buf[1] = uint8(b.Flags)
		buf[2] = uint8(b.Message)
		binary.BigEndian.PutUint16(buf[3:5], uint16(b.SAFI))
	} else { // version >= 4
		binary.BigEndian.PutUint16(buf[1:3], uint16(b.Instance))
		binary.BigEndian.PutUint32(buf[3:7], uint32(b.Flags))
		buf[7] = uint8(b.Message)
		if version == 4 {
			binary.BigEndian.PutUint16(buf[8:10], uint16(b.SAFI))
		} else { // version >= 5
			buf[8] = uint8(b.SAFI)
			if b.Flags&FLAG_EVPN_ROUTE > 0 {
				// size of struct ethaddr is 6 octets defined by ETH_ALEN
				buf = append(buf, b.Rmac[:6]...)
			}
			if b.Prefix.Family == syscall.AF_UNSPEC {
				if b.Prefix.Prefix.To4() != nil {
					b.Prefix.Family = syscall.AF_INET
				} else if b.Prefix.Prefix.To16() != nil {
					b.Prefix.Family = syscall.AF_INET6
				}
			}
			buf = append(buf, b.Prefix.Family)
		}
	}
	byteLen := (int(b.Prefix.PrefixLen) + 7) / 8
	buf = append(buf, b.Prefix.PrefixLen)
	buf = append(buf, b.Prefix.Prefix[:byteLen]...)

	if (version == 4 && b.Message&FRR_MESSAGE_SRCPFX > 0) ||
		(version >= 5 && b.Message&FRR_ZAPI5_MESSAGE_SRCPFX > 0) {
		byteLen = (int(b.SrcPrefix.PrefixLen) + 7) / 8
		buf = append(buf, b.SrcPrefix.PrefixLen)
		buf = append(buf, b.SrcPrefix.Prefix[:byteLen]...)
	}
	if (version <= 3 && b.Message&MESSAGE_NEXTHOP > 0) ||
		(version == 4 && b.Message&FRR_MESSAGE_NEXTHOP > 0) ||
		(version >= 5 && b.Message&FRR_ZAPI5_MESSAGE_NEXTHOP > 0) {
		if version < 5 {
			if b.Flags&FLAG_BLACKHOLE > 0 {
				buf = append(buf, []byte{1, uint8(NEXTHOP_TYPE_BLACKHOLE)}...)
			} else {
				buf = append(buf, uint8(len(b.Nexthops)))
			}
		} else { // version >= 5
			bbuf := make([]byte, 2)
			binary.BigEndian.PutUint16(bbuf, uint16(len(b.Nexthops)))
			buf = append(buf, bbuf...)
		}
		for _, nexthop := range b.Nexthops {
			if version >= 5 {
				bbuf := make([]byte, 4)
				binary.BigEndian.PutUint32(bbuf, nexthop.VrfId)
				buf = append(buf, bbuf...)
			}

			if nexthop.Type == NEXTHOP_TYPE(0) {
				if nexthop.Gate.To4() != nil {
					if version <= 3 {
						nexthop.Type = NEXTHOP_TYPE_IPV4
					} else {
						nexthop.Type = FRR_NEXTHOP_TYPE_IPV4
					}
					if version >= 5 && nexthop.Ifindex > 0 {
						nexthop.Type = FRR_NEXTHOP_TYPE_IPV4_IFINDEX
					}
				} else if nexthop.Gate.To16() != nil {
					if version <= 3 {
						nexthop.Type = NEXTHOP_TYPE_IPV6
					} else {
						nexthop.Type = FRR_NEXTHOP_TYPE_IPV6
					}
					if version >= 5 && nexthop.Ifindex > 0 {
						nexthop.Type = FRR_NEXTHOP_TYPE_IPV6_IFINDEX
					}
				} else if nexthop.Ifindex > 0 {
					if version <= 3 {
						nexthop.Type = NEXTHOP_TYPE_IFINDEX
					} else {
						nexthop.Type = FRR_NEXTHOP_TYPE_IFINDEX
					}
				} else if version >= 5 {
					nexthop.Type = FRR_NEXTHOP_TYPE_BLACKHOLE
				}
			}

			buf = append(buf, uint8(nexthop.Type))

			if (version <= 3 && nexthop.Type == NEXTHOP_TYPE_IPV4) ||
				(version >= 4 && nexthop.Type == FRR_NEXTHOP_TYPE_IPV4) {
				buf = append(buf, nexthop.Gate.To4()...)
			} else if (version <= 3 && nexthop.Type == NEXTHOP_TYPE_IPV6) ||
				(version >= 4 && nexthop.Type == FRR_NEXTHOP_TYPE_IPV6) {
				buf = append(buf, nexthop.Gate.To16()...)
			} else if (version <= 3 && nexthop.Type == NEXTHOP_TYPE_IFINDEX) ||
				(version >= 4 && nexthop.Type == FRR_NEXTHOP_TYPE_IFINDEX) {
				bbuf := make([]byte, 4)
				binary.BigEndian.PutUint32(bbuf, nexthop.Ifindex)
				buf = append(buf, bbuf...)
			} else if version >= 5 && nexthop.Type == FRR_NEXTHOP_TYPE_IPV4_IFINDEX {
				buf = append(buf, nexthop.Gate.To4()...)
				bbuf := make([]byte, 4)
				binary.BigEndian.PutUint32(bbuf, nexthop.Ifindex)
				buf = append(buf, bbuf...)
			} else if version >= 5 && nexthop.Type == FRR_NEXTHOP_TYPE_IPV6_IFINDEX {
				buf = append(buf, nexthop.Gate.To16()...)
				bbuf := make([]byte, 4)
				binary.BigEndian.PutUint32(bbuf, nexthop.Ifindex)
				buf = append(buf, bbuf...)
			} else if version >= 5 && nexthop.Type == FRR_NEXTHOP_TYPE_BLACKHOLE {
				buf = append(buf, uint8(nexthop.BlackholeType))
			}
			if version >= 5 && b.Message&FRR_ZAPI5_MESSAGE_LABEL > 0 {
				buf = append(buf, nexthop.LabelNum)
				for i := uint8(0); i < nexthop.LabelNum; i++ {
					bbuf := make([]byte, 4)
					/* Frr uses stream_put for mpls label array.
					   stream_put is unaware of byteorder coversion.
					   Therefore LittleEndian is used instead of BigEndian. */
					binary.LittleEndian.PutUint32(bbuf, nexthop.MplsLabels[i])
					buf = append(buf, bbuf...)

				}
			}
		}
		if (version <= 3 && b.Message&MESSAGE_DISTANCE > 0) ||
			(version == 4 && b.Message&FRR_MESSAGE_DISTANCE > 0) ||
			(version >= 5 && b.Message&FRR_ZAPI5_MESSAGE_DISTANCE > 0) {
			buf = append(buf, b.Distance)
		}
		if (version <= 3 && b.Message&MESSAGE_METRIC > 0) ||
			(version == 4 && b.Message&FRR_MESSAGE_METRIC > 0) ||
			(version >= 5 && b.Message&FRR_ZAPI5_MESSAGE_METRIC > 0) {
			bbuf := make([]byte, 4)
			binary.BigEndian.PutUint32(bbuf, b.Metric)
			buf = append(buf, bbuf...)
		}
		if (version <= 3 && b.Message&MESSAGE_MTU > 0) ||
			(version == 4 && b.Message&FRR_MESSAGE_MTU > 0) ||
			(version >= 5 && b.Message&FRR_ZAPI5_MESSAGE_MTU > 0) {
			bbuf := make([]byte, 4)
			binary.BigEndian.PutUint32(bbuf, b.Mtu)
			buf = append(buf, bbuf...)
		}
		if (version <= 3 && b.Message&MESSAGE_TAG > 0) ||
			(version == 4 && b.Message&FRR_MESSAGE_TAG > 0) ||
			(version >= 5 && b.Message&FRR_ZAPI5_MESSAGE_TAG > 0) {
			bbuf := make([]byte, 4)
			binary.BigEndian.PutUint32(bbuf, b.Tag)
			buf = append(buf, bbuf...)
		}
	}
	return buf, nil
}
1233583
func (key *Key) Serialize() ([]byte, error) {
	// Private keys should be prepended with a single null byte
	keyBytes := key.Key
	if key.IsPrivate {
		keyBytes = append([]byte{0x0}, keyBytes...)
	}

	// Write fields to buffer in order
	buffer := new(bytes.Buffer)
	buffer.Write(key.Version)
	buffer.WriteByte(key.Depth)
	buffer.Write(key.FingerPrint)
	buffer.Write(key.ChildNumber)
	buffer.Write(key.ChainCode)
	buffer.Write(keyBytes)

	// Append the standard doublesha256 checksum
	serializedKey, err := addChecksumToBytes(buffer.Bytes())
	if err != nil {
		return nil, err
	}

	return serializedKey, nil
}
637420
func (s SerializeFunc) Serialize(obj interface{}, options ...map[string]interface{}) ([]byte, error) {
	return s(obj, options...)
}
871382
func (j *jws) Serialize(key interface{}) ([]byte, error) {
	if j.isJWT {
		return j.Compact(key)
	}
	return nil, ErrIsNotJWT
}
778635
func Serialize(u *util.CPUUtil) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Serialize(u), nil
}
827374
func (j JSONPBStateSerializer) Serialize(state interface{}) (string, error) {
	pm, ok := state.(proto.Message)
	if ok {
		return j.m.MarshalToString(pm)
	}
	return j.fbss.Serialize(state)
}
876325
func (w *WIF) SerializePubKey() []byte {
	pk := (*btcec.PublicKey)(&w.PrivKey.PublicKey)
	if w.CompressPubKey {
		return pk.SerializeCompressed()
	}
	return pk.SerializeUncompressed()
}
819751
func (t *TxOut) SerializeSize() int {
	// Value 8 bytes + serialized varint size for the length of PkScript +
	// PkScript bytes.
	return 8 + VarIntSerializeSize(uint64(len(t.PkScript))) + len(t.PkScript)
}
1217117
func XEntry(description string, parameters ...interface{}) TableEntry {
	return TableEntry{description, parameters, true, false}
}
1100690
func (p *PublicKey) SerializeHybrid() []byte {
	b := make([]byte, 0, PubKeyBytesLenHybrid)
	format := pubkeyHybrid
	if isOdd(p.Y) {
		format |= 0x1
	}
	b = append(b, format)
	b = paddedAppend(32, b, p.X.Bytes())
	return paddedAppend(32, b, p.Y.Bytes())
}
755886
func (k *Keyring) Serialize() ([]byte, error) {
	// Create the encoded entry
	enc := EncodedKeyring{
		MasterKey: k.masterKey,
	}
	for _, key := range k.keys {
		enc.Keys = append(enc.Keys, key)
	}

	// JSON encode the keyring
	buf, err := json.Marshal(enc)
	return buf, err
}
21956
func Serialize(s Serializer) (string, error) {
	w := &standardWriter{}
	if err := s.Serialize(w); err != nil {
		return "", err
	}
	return w.String(), nil
}
500368
func (b *HelloBody) Serialize(version uint8) ([]byte, error) {
	if version <= 3 {
		return []byte{uint8(b.RedistDefault)}, nil
	} else { // version >= 4
		var buf []byte
		if version == 4 {
			buf = make([]byte, 3)
		} else if version >= 5 {
			buf = make([]byte, 4)
		}
		buf[0] = uint8(b.RedistDefault)
		binary.BigEndian.PutUint16(buf[1:3], b.Instance)
		if version >= 5 {
			buf[3] = b.ReceiveNotify
		}
		return buf, nil
	}
}