// Serialize encodes the alert to w using the alert protocol encoding format.
964280
func (alert *Alert) Serialize(w io.Writer, pver uint32) error {
	err := writeElements(w, alert.Version, alert.RelayUntil,
		alert.Expiration, alert.ID, alert.Cancel)
	if err != nil {
		return err
	}

	count := len(alert.SetCancel)
	if count > maxCountSetCancel {
		str := fmt.Sprintf("too many cancel alert IDs for alert "+
			"[count %v, max %v]", count, maxCountSetCancel)
		return messageError("Alert.Serialize", str)
	}
	err = WriteVarInt(w, pver, uint64(count))
	if err != nil {
		return err
	}
	for i := 0; i < count; i++ {
		err = writeElement(w, alert.SetCancel[i])
		if err != nil {
			return err
		}
	}

	err = writeElements(w, alert.MinVer, alert.MaxVer)
	if err != nil {
		return err
	}

	count = len(alert.SetSubVer)
	if count > maxCountSetSubVer {
		str := fmt.Sprintf("too many sub versions for alert "+
			"[count %v, max %v]", count, maxCountSetSubVer)
		return messageError("Alert.Serialize", str)
	}
	err = WriteVarInt(w, pver, uint64(count))
	if err != nil {
		return err
	}
	for i := 0; i < count; i++ {
		err = WriteVarString(w, pver, alert.SetSubVer[i])
		if err != nil {
			return err
		}
	}

	err = writeElement(w, alert.Priority)
	if err != nil {
		return err
	}
	err = WriteVarString(w, pver, alert.Comment)
	if err != nil {
		return err
	}
	err = WriteVarString(w, pver, alert.StatusBar)
	if err != nil {
		return err
	}
	return WriteVarString(w, pver, alert.Reserved)
}
502310
func Serialize(opts []*UnitOption) io.Reader {
	var buf bytes.Buffer

	if len(opts) == 0 {
		return &buf
	}

	// Index of sections -> ordered options
	idx := map[string][]*UnitOption{}
	// Separately preserve order in which sections were seen
	sections := []string{}
	for _, opt := range opts {
		sec := opt.Section
		if _, ok := idx[sec]; !ok {
			sections = append(sections, sec)
		}
		idx[sec] = append(idx[sec], opt)
	}

	for i, sect := range sections {
		writeSectionHeader(&buf, sect)
		writeNewline(&buf)

		opts := idx[sect]
		for _, opt := range opts {
			writeOption(&buf, opt)
			writeNewline(&buf)
		}
		if i < len(sections)-1 {
			writeNewline(&buf)
		}
	}

	return &buf
}
1208624
func Serialize(w io.Writer, key []byte, rand io.Reader, passphrase []byte, c *Config) error {
	var buf [11]byte
	buf[0] = 3 /* iterated and salted */
	buf[1], _ = HashToHashId(c.hash())
	salt := buf[2:10]
	if _, err := io.ReadFull(rand, salt); err != nil {
		return err
	}
	encodedCount := c.encodedCount()
	count := decodeCount(encodedCount)
	buf[10] = encodedCount
	if _, err := w.Write(buf[:]); err != nil {
		return err
	}

	Iterated(key, c.hash().New(), passphrase, salt, count)
	return nil
}
676376
func (prof *Profiler) Serialize(f *freq.Frequency) ([]byte, error) {
	return json.Marshal(f)
}
1216375
func (req *NetlinkRequest) Serialize() []byte {
	length := unix.SizeofNlMsghdr
	dataBytes := make([][]byte, len(req.Data))
	for i, data := range req.Data {
		dataBytes[i] = data.Serialize()
		length = length + len(dataBytes[i])
	}
	length += len(req.RawData)

	req.Len = uint32(length)
	b := make([]byte, length)
	hdr := (*(*[unix.SizeofNlMsghdr]byte)(unsafe.Pointer(req)))[:]
	next := unix.SizeofNlMsghdr
	copy(b[0:next], hdr)
	for _, data := range dataBytes {
		for _, dataByte := range data {
			b[next] = dataByte
			next = next + 1
		}
	}
	// Add the raw data if any
	if len(req.RawData) > 0 {
		copy(b[next:length], req.RawData)
	}
	return b
}
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
}
90427
func (prof *Profiler) Serialize(st *stats.CPUStats) ([]byte, error) {
	return json.Marshal(st)
}
395560
func (j JSONStateSerializer) Serialize(state interface{}) (string, error) {
	var b bytes.Buffer
	if err := json.NewEncoder(&b).Encode(state); err != nil {
		return "", err
	}
	return b.String(), nil
}
485324
func (s Serializers) Serialize(key string, obj interface{}, options ...map[string]interface{}) ([]byte, error) {
	if key == "" {
		return nil, errKeyMissing
	}
	if s == nil {
		return nil, errSerializersEmpty
	}

	serializers := s[key]
	if serializers == nil {
		return nil, errSerializerNotFound.Format(key)
	}
	var finalResult []byte

	for i, n := 0, len(serializers); i < n; i++ {
		result, err := serializers[i].Serialize(obj, options...)
		if err != nil {
			return nil, err
		}
		finalResult = append(finalResult, result...)
	}
	return finalResult, nil
}
1046685
func (p *TerminalParams) Serialize() string {
	return fmt.Sprintf("%d:%d", p.W, p.H)
}
639876
func (s *MessagePackSerializer) Serialize(msg Message) ([]byte, error) {
	var b []byte
	return b, codec.NewEncoderBytes(&b, new(codec.MsgpackHandle)).Encode(toList(msg))
}
344097
func (s Shard) Serialize() []byte {
	sorted := make([]string, 0, len(s))
	for blob := range s {
		sorted = append(sorted, blob)
	}
	sort.Strings(sorted)
	out := bytes.Buffer{}
	enc := gob.NewEncoder(&out)
	err := enc.Encode(sorted)
	if err != nil {
		panic("impossible error when encoding []string")
	}
	return out.Bytes()
}
428527
func (r Store) Serialize() []byte {
	w := new(bytes.Buffer)
	enc := gob.NewEncoder(w)
	err := enc.Encode(r)
	if err != nil {
		return nil
	}

	return w.Bytes()
}
878003
func (n *RegisteredNexthop) Serialize() ([]byte, error) {
	// Connected (1 byte)
	buf := make([]byte, 4)
	buf[0] = byte(n.Connected)

	// Address Family (2 bytes)
	binary.BigEndian.PutUint16(buf[1:3], n.Family)
	// Prefix Length (1 byte)
	addrByteLen, err := addressByteLength(uint8(n.Family))
	if err != nil {
		return nil, err
	}

	buf[3] = byte(addrByteLen * 8)
	// Prefix (variable)
	switch n.Family {
	case uint16(syscall.AF_INET):
		buf = append(buf, n.Prefix.To4()...)
	case uint16(syscall.AF_INET6):
		buf = append(buf, n.Prefix.To16()...)
	default:
		return nil, fmt.Errorf("invalid address family: %d", n.Family)
	}

	return buf, nil
}
115764
func (u *User) Serialize() ([]byte, error) {
	serializedIdentity := &pb_msp.SerializedIdentity{
		Mspid:   u.mspID,
		IdBytes: u.enrollmentCertificate,
	}
	identity, err := proto.Marshal(serializedIdentity)
	if err != nil {
		return nil, errors.Wrap(err, "marshal serializedIdentity failed")
	}
	return identity, nil
}
338139
func (alert *Alert) Deserialize(r io.Reader, pver uint32) error {
	err := readElements(r, &alert.Version, &alert.RelayUntil,
		&alert.Expiration, &alert.ID, &alert.Cancel)
	if err != nil {
		return err
	}

	// SetCancel: first read a VarInt that contains
	// count - the number of Cancel IDs, then
	// iterate count times and read them
	count, err := ReadVarInt(r, pver)
	if err != nil {
		return err
	}
	if count > maxCountSetCancel {
		str := fmt.Sprintf("too many cancel alert IDs for alert "+
			"[count %v, max %v]", count, maxCountSetCancel)
		return messageError("Alert.Deserialize", str)
	}
	alert.SetCancel = make([]int32, count)
	for i := 0; i < int(count); i++ {
		err := readElement(r, &alert.SetCancel[i])
		if err != nil {
			return err
		}
	}

	err = readElements(r, &alert.MinVer, &alert.MaxVer)
	if err != nil {
		return err
	}

	// SetSubVer: similar to SetCancel
	// but read count number of sub-version strings
	count, err = ReadVarInt(r, pver)
	if err != nil {
		return err
	}
	if count > maxCountSetSubVer {
		str := fmt.Sprintf("too many sub versions for alert "+
			"[count %v, max %v]", count, maxCountSetSubVer)
		return messageError("Alert.Deserialize", str)
	}
	alert.SetSubVer = make([]string, count)
	for i := 0; i < int(count); i++ {
		alert.SetSubVer[i], err = ReadVarString(r, pver)
		if err != nil {
			return err
		}
	}

	err = readElement(r, &alert.Priority)
	if err != nil {
		return err
	}
	alert.Comment, err = ReadVarString(r, pver)
	if err != nil {
		return err
	}
	alert.StatusBar, err = ReadVarString(r, pver)
	if err != nil {
		return err
	}
	alert.Reserved, err = ReadVarString(r, pver)
	return err
}
794787
func (w *Writer) Serialize(v interface{}) *Writer {
	if v == nil {
		w.WriteNil()
	} else if rv, ok := v.(reflect.Value); ok {
		w.WriteValue(rv)
	} else {
		w.WriteValue(reflect.ValueOf(v))
	}
	return w
}