// Serialize takes a map and generates a string that can be parsed by Set
962934
func SerializePairs(pairs map[string]string) string {
	tmp := make([]string, 0, len(pairs))

	for k, v := range pairs {
		tmp = append(tmp, fmt.Sprintf("%s=%s", k, v))
	}
	return strings.Join(tmp, ",")
}
1248142
func (s SerializableUsageSet) Serialize() []byte {
	sz := 1 + 4 + (len(s) * (32 + 4 + timeSzBytes + timeSzBytes + 4))
	out := make([]byte, sz)
	out[0] = szMemSetHeaderV1
	binary.BigEndian.PutUint32(out[1:], uint32(len(s)))
	p := 5
	for k, entry := range s {
		copy(out[p:], k[:])
		p += 32
		binary.BigEndian.PutUint32(out[p:], uint32(entry.usage))
		p += 4
		created, _ := entry.created.In(time.UTC).MarshalBinary()
		expires, _ := entry.expire.In(time.UTC).MarshalBinary()
		copy(out[p:], created)
		p += len(created)
		copy(out[p:], expires)
		p += len(expires)
		binary.BigEndian.PutUint32(out[p:], uint32(entry.max))
		p += 4
	}
	return out
}
740237
func (record *SignedPreKeyRecord) Serialize() ([]byte, error) {
	b, err := proto.Marshal(record.Spkrs)
	if err != nil {
		return nil, err
	}
	return b, nil
}
1046685
func (p *TerminalParams) Serialize() string {
	return fmt.Sprintf("%d:%d", p.W, p.H)
}
748257
func Serialize(st *stats.CPUStats) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Serialize(st)
}
691838
func (e *Serializer) Serialize(val interface{}, options ...map[string]interface{}) ([]byte, error) {
	if e.config.StreamingJSON {
		w := buffer.Get()
		if len(e.config.Prefix) > 0 {
			w.Write(e.config.Prefix)
		}
		err := json.NewEncoder(w).Encode(val)
		result := w.Bytes()
		buffer.Put(w)
		return result, err
	}

	var result []byte
	var err error

	if e.config.Indent {
		result, err = json.MarshalIndent(val, "", "  ")
		result = append(result, newLineB...)
	} else {
		result, err = json.Marshal(val)
	}
	if err != nil {
		return nil, err
	}

	if e.config.UnEscapeHTML {
		result = bytes.Replace(result, ltHex, lt, -1)
		result = bytes.Replace(result, gtHex, gt, -1)
		result = bytes.Replace(result, andHex, and, -1)
	}
	if len(e.config.Prefix) > 0 {
		result = append(e.config.Prefix, result...)
	}
	return result, nil
}
1214270
func (e GobEncoder) Serialize(src interface{}) ([]byte, error) {
	buf := new(bytes.Buffer)
	enc := gob.NewEncoder(buf)
	if err := enc.Encode(src); err != nil {
		return nil, cookieError{cause: err, typ: usageError}
	}
	return buf.Bytes(), nil
}
1131540
func (prof *Profiler) Serialize(up u.Uptime) ([]byte, error) {
	return json.Marshal(up)
}
90427
func (prof *Profiler) Serialize(st *stats.CPUStats) ([]byte, error) {
	return json.Marshal(st)
}
75646
func (ba *sparseBitArray) Serialize() ([]byte, error) {
	w := new(bytes.Buffer)

	var identifier uint8 = 'S'
	err := binary.Write(w, binary.LittleEndian, identifier)
	if err != nil {
		return nil, err
	}

	blocksLen := uint64(len(ba.blocks))
	indexLen := uint64(len(ba.indices))

	err = binary.Write(w, binary.LittleEndian, blocksLen)
	if err != nil {
		return nil, err
	}

	err = binary.Write(w, binary.LittleEndian, ba.blocks)
	if err != nil {
		return nil, err
	}

	err = binary.Write(w, binary.LittleEndian, indexLen)
	if err != nil {
		return nil, err
	}

	err = binary.Write(w, binary.LittleEndian, ba.indices)
	if err != nil {
		return nil, err
	}
	return w.Bytes(), nil
}
438261
func (b *VrfLabelBody) Serialize(version uint8) ([]byte, error) {
	buf := make([]byte, 6)
	binary.BigEndian.PutUint32(buf[0:4], b.Label)
	buf[4] = uint8(b.Afi)
	buf[5] = uint8(b.LabelType)
	return buf, nil
}
1008380
func (s *WavefrontSerializer) Serialize(m telegraf.Metric) ([]byte, error) {
	out := []byte{}
	metricSeparator := "."

	for fieldName, value := range m.Fields() {
		var name string

		if fieldName == "value" {
			name = fmt.Sprintf("%s%s", s.Prefix, m.Name())
		} else {
			name = fmt.Sprintf("%s%s%s%s", s.Prefix, m.Name(), metricSeparator, fieldName)
		}

		if s.UseStrict {
			name = strictSanitizedChars.Replace(name)
		} else {
			name = sanitizedChars.Replace(name)
		}

		name = pathReplacer.Replace(name)

		metric := &wavefront.MetricPoint{
			Metric:    name,
			Timestamp: m.Time().Unix(),
		}

		metricValue, buildError := buildValue(value, metric.Metric)
		if buildError != nil {
			// bad value continue to next metric
			continue
		}
		metric.Value = metricValue

		source, tags := buildTags(m.Tags(), s)
		metric.Source = source
		metric.Tags = tags

		out = append(out, formatMetricPoint(metric, s)...)
	}
	return out, nil
}
364125
func (prof *Profiler) Serialize(st *structs.DiskStats) ([]byte, error) {
	return json.Marshal(st)
}
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
}
579542
func (record *PreKeyRecord) Serialize() ([]byte, error) {
	b, err := proto.Marshal(record.Pkrs)
	if err != nil {
		return nil, err
	}
	return b, nil
}
947821
func (e *EncryptedKey) Serialize(w io.Writer) error {
	var mpiLen int
	switch e.Algo {
	case PubKeyAlgoRSA, PubKeyAlgoRSAEncryptOnly:
		mpiLen = 2 + len(e.encryptedMPI1.bytes)
	case PubKeyAlgoElGamal:
		mpiLen = 2 + len(e.encryptedMPI1.bytes) + 2 + len(e.encryptedMPI2.bytes)
	default:
		return errors.InvalidArgumentError("don't know how to serialize encrypted key type " + strconv.Itoa(int(e.Algo)))
	}

	serializeHeader(w, packetTypeEncryptedKey, 1 /* version */ +8 /* key id */ +1 /* algo */ +mpiLen)

	w.Write([]byte{encryptedKeyVersion})
	binary.Write(w, binary.BigEndian, e.KeyId)
	w.Write([]byte{byte(e.Algo)})

	switch e.Algo {
	case PubKeyAlgoRSA, PubKeyAlgoRSAEncryptOnly:
		writeMPIs(w, e.encryptedMPI1)
	case PubKeyAlgoElGamal:
		writeMPIs(w, e.encryptedMPI1, e.encryptedMPI2)
	default:
		panic("internal error")
	}

	return nil
}
507863
func (record *SessionRecord) Serialize() ([]byte, error) {
	rs := &protobuf.RecordStructure{}
	rs.CurrentSession = record.sessionState.SS
	for _, s := range record.PreviousStates {
		rs.PreviousSessions = append(rs.PreviousSessions, s.SS)
	}
	b, err := proto.Marshal(rs)
	if err != nil {
		return nil, err
	}
	return b, nil
}