// FeeForSerializeSize calculates the required fee for a transaction of some
// arbitrary size given a mempool's relay fee policy.
163142
func FeeForSerializeSize(relayFeePerKb btcutil.Amount, txSerializeSize int) btcutil.Amount {
	fee := relayFeePerKb * btcutil.Amount(txSerializeSize) / 1000

	if fee == 0 && relayFeePerKb > 0 {
		fee = relayFeePerKb
	}

	if fee < 0 || fee > btcutil.MaxSatoshi {
		fee = btcutil.MaxSatoshi
	}

	return fee
}
241564
func (si *SegmentCommitInfo) SizeInBytes() (sum int64, err error) {
	if si.sizeInBytes == -1 {
		sum = 0
		for _, fileName := range si.Files() {
			d, err := si.Info.Dir.FileLength(fileName)
			if err != nil {
				return 0, err
			}
			sum += d
		}
		si.sizeInBytes = sum
	}
	return si.sizeInBytes, nil
}
556059
func (t *Field) SerializeTo(w io.Writer) error {
	b := make([]byte, len(t.Data)+4)
	binary.BigEndian.PutUint16(b[0:2], uint16(t.Tag))
	binary.BigEndian.PutUint16(b[2:4], uint16(len(t.Data)))
	copy(b[4:], t.Data)

	_, err := w.Write(b)
	return err
}
913917
func (db *StakeDatabase) PoolSize() int {
	db.nodeMtx.Lock()
	defer db.nodeMtx.Unlock()
	return db.BestNode.PoolSize()
}
262023
func (b *RedistributeBody) Serialize(version uint8) ([]byte, error) {
	if version <= 3 {
		return []byte{uint8(b.Redist)}, nil
	} else { // version >= 4
		buf := make([]byte, 4)
		buf[0] = uint8(b.Afi)
		buf[1] = uint8(b.Redist)
		binary.BigEndian.PutUint16(buf[2:4], b.Instance)
		return buf, nil
	}
}
873021
func (s CompactSerialize) Serialize(m *Message) ([]byte, error) {
	if len(m.Recipients) != 1 {
		return nil, errors.New("wrong number of recipients for compact serialization")
	}

	recipient := m.Recipients[0]

	// The protected header must be a merge between the message-wide
	// protected header AND the recipient header
	hcopy := NewHeader()
	// There's something wrong if m.ProtectedHeader.Header is nil, but
	// it could happen
	if m.ProtectedHeader == nil || m.ProtectedHeader.Header == nil {
		return nil, errors.New("invalid protected header")
	}
	err := hcopy.Copy(m.ProtectedHeader.Header)
	if err != nil {
		return nil, errors.Wrap(err, "failed to copy protected header")
	}
	hcopy, err = hcopy.Merge(m.UnprotectedHeader)
	if err != nil {
		return nil, errors.Wrap(err, "failed to merge unprotected header")
	}
	hcopy, err = hcopy.Merge(recipient.Header)
	if err != nil {
		return nil, errors.Wrap(err, "failed to merge recipient header")
	}

	protected, err := EncodedHeader{Header: hcopy}.Base64Encode()
	if err != nil {
		return nil, errors.Wrap(err, "failed to encode header")
	}

	encryptedKey, err := recipient.EncryptedKey.Base64Encode()
	if err != nil {
		return nil, errors.Wrap(err, "failed to encode encryption key")
	}

	iv, err := m.InitializationVector.Base64Encode()
	if err != nil {
		return nil, errors.Wrap(err, "failed to encode iv")
	}

	cipher, err := m.CipherText.Base64Encode()
	if err != nil {
		return nil, errors.Wrap(err, "failed to encode cipher text")
	}

	tag, err := m.Tag.Base64Encode()
	if err != nil {
		return nil, errors.Wrap(err, "failed to encode tag")
	}

	buf := append(append(append(append(append(append(append(append(protected, '.'), encryptedKey...), '.'), iv...), '.'), cipher...), '.'), tag...)
	return buf, nil
}
809321
func (fv *RawFeatureVector) SerializeSize() int {
	// Find the largest feature bit index
	max := -1
	for feature := range fv.features {
		index := int(feature)
		if index > max {
			max = index
		}
	}
	if max == -1 {
		return 0
	}

	// We calculate byte-length via the largest bit index
	return max/8 + 1
}
564183
func (tx *Transaction) Size() common.StorageSize {
	if size := tx.size.Load(); size != nil {
		return size.(common.StorageSize)
	}
	c := writeCounter(0)
	rlp.Encode(&c, &tx.data)
	tx.size.Store(common.StorageSize(c))
	return common.StorageSize(c)
}
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
}
1155022
func NewSatoshiPerByte(fee btcutil.Amount, size uint32) SatoshiPerByte {
	return SatoshiPerByte(float64(fee) / float64(size))
}
810801
func (p *PrivateKey) Serialize() []byte {
	b := make([]byte, 0, PrivKeyBytesLen)
	return paddedAppend(PrivKeyBytesLen, b, p.ToECDSA().D.Bytes())
}
28981
func Unserialize(b []byte, p interface{}, simple bool) {
	reader := AcquireReader(b, simple)
	defer ReleaseReader(reader)
	reader.Unserialize(p)
}
890306
func (s *StreamRecord) SetSizeBytes(v int64) *StreamRecord {
	s.SizeBytes = &v
	return s
}
1036226
func (m MockContext) Serialize() ([]byte, error) {
	if m.SigningIdentity == nil {
		return nil, errors.New("anonymous countext")
	}
	return m.SigningIdentity.Serialize()
}
637420
func (s SerializeFunc) Serialize(obj interface{}, options ...map[string]interface{}) ([]byte, error) {
	return s(obj, options...)
}
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)
}
1023722
func (pdu *codec) SerializeTo(w io.Writer) error {
	var b bytes.Buffer
	for _, k := range pdu.FieldList() {
		f, ok := pdu.f[k]
		if !ok {
			pdu.f.Set(k, nil)
			f = pdu.f[k]
		}
		if err := f.SerializeTo(&b); err != nil {
			return err
		}
	}
	for _, f := range pdu.TLVFields() {
		if err := f.SerializeTo(&b); err != nil {
			return err
		}
	}
	pdu.h.Len = uint32(pdu.Len())
	err := pdu.h.SerializeTo(w)
	if err != nil {
		return err
	}
	_, err = io.Copy(w, &b)
	return err
}