// serialize returns the data that should be written to disk for the
// provided Conf, rendered in the systemd unit file format.
6453
func serialize(name string, conf common.Conf, renderer shell.Renderer) ([]byte, error) {
	if err := validate(name, conf, renderer); err != nil {
		return nil, errors.Trace(err)
	}

	var unitOptions []*unit.UnitOption
	unitOptions = append(unitOptions, serializeUnit(conf)...)
	unitOptions = append(unitOptions, serializeService(conf)...)
	unitOptions = append(unitOptions, serializeInstall(conf)...)
	// Don't use unit.Serialize because it has map ordering issues.
	// Serialize copied locally, and outputs sections in alphabetical order.
	data, err := ioutil.ReadAll(UnitSerialize(unitOptions))
	return data, errors.Trace(err)
}
892980
func (s Session) Serialize() map[string]string {
	sessionJsonMap := s.getSessionJsonMap()
	newMap := map[string]string{}
	newObjectMap := map[string]string{}
	for key, value := range sessionJsonMap {
		newObjectMap[key] = value
	}
	for key, value := range s {
		if key == SessionObjectKeyName || key == SessionMapKeyName {
			continue
		}
		if reflect.ValueOf(value).Kind() == reflect.String {
			newMap[key] = value.(string)
			continue
		}
		println("Serialize the data for", key)
		if data, err := json.Marshal(value); err != nil {
			sessionLog.Error("Unable to marshal session ", "key", key, "error", err)
			continue
		} else {
			newObjectMap[key] = string(data)
		}
	}
	if len(newObjectMap) > 0 {
		if data, err := json.Marshal(newObjectMap); err != nil {
			sessionLog.Error("Unable to marshal session ", "key", SessionObjectKeyName, "error", err)

		} else {
			newMap[SessionObjectKeyName] = string(data)
		}
	}

	return newMap
}
706503
func Serialize(data interface{}) (bytes []byte, err error) {
	switch data.(type) {
	case []byte:
		return data.([]byte), nil
	case string:
		return []byte(data.(string)), nil
	default:
		if data != nil {
			return []byte(fmt.Sprint(data)), nil
		}
	}
	return nil, nil
}
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
}
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
}
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
}
63196
func (d *ClientDigestsFile) Serialize(w io.Writer, version, versionFile string) error {
	_, err := iotools.WriteTracker(w, func(w io.Writer) error {
		fmt.Fprintf(w, "# This file was generated by\n")
		fmt.Fprintf(w, "#\n")
		fmt.Fprintf(w, "#  cipd selfupdate-roll -version-file %s \\\n", versionFile)
		fmt.Fprintf(w, "#      -version %s\n", version)
		fmt.Fprintf(w, "#\n")
		fmt.Fprintf(w, "# Do not modify manually. All changes will be overwritten.\n")
		fmt.Fprintf(w, "# Use 'cipd selfupdate-roll ...' to modify.\n\n")

		// Align fields nicely.
		max := []int{0, 0}
		for _, e := range d.entries {
			if l := len(e.plat); l > max[0] {
				max[0] = l
			}
			if l := len(e.ref.HashAlgo.String()); l > max[1] {
				max[1] = l
			}
		}

		for _, e := range d.entries {
			algo := strings.ToLower(e.ref.HashAlgo.String())
			fmt.Fprintf(w, "%s%s%s%s%s\n",
				e.plat, strings.Repeat(" ", max[0]+2-len(e.plat)),
				algo, strings.Repeat(" ", max[1]+2-len(algo)),
				e.ref.HexDigest,
			)
		}

		return nil
	})
	return err
}
1032436
func (ca commandAPDU) serialize() ([]byte, error) {
	buf := new(bytes.Buffer)

	if err := binary.Write(buf, binary.BigEndian, ca.Cla); err != nil {
		return nil, err
	}
	if err := binary.Write(buf, binary.BigEndian, ca.Ins); err != nil {
		return nil, err
	}
	if err := binary.Write(buf, binary.BigEndian, ca.P1); err != nil {
		return nil, err
	}
	if err := binary.Write(buf, binary.BigEndian, ca.P2); err != nil {
		return nil, err
	}
	if len(ca.Data) > 0 {
		if err := binary.Write(buf, binary.BigEndian, uint8(len(ca.Data))); err != nil {
			return nil, err
		}
		if err := binary.Write(buf, binary.BigEndian, ca.Data); err != nil {
			return nil, err
		}
	}
	if err := binary.Write(buf, binary.BigEndian, ca.Le); err != nil {
		return nil, err
	}
	return buf.Bytes(), nil
}
899608
func (prof *Profiler) Serialize(os *o.OS) []byte {
	// ensure the Builder is in a usable state.
	prof.Builder.Reset()
	name := prof.Builder.CreateString(os.Name)
	id := prof.Builder.CreateString(os.ID)
	idLike := prof.Builder.CreateString(os.IDLike)
	prettyName := prof.Builder.CreateString(os.PrettyName)
	version := prof.Builder.CreateString(os.Version)
	versionID := prof.Builder.CreateString(os.VersionID)
	homeURL := prof.Builder.CreateString(os.HomeURL)
	bugReportURL := prof.Builder.CreateString(os.BugReportURL)
	structs.OSStart(prof.Builder)
	structs.OSAddName(prof.Builder, name)
	structs.OSAddID(prof.Builder, id)
	structs.OSAddIDLike(prof.Builder, idLike)
	structs.OSAddPrettyName(prof.Builder, prettyName)
	structs.OSAddVersion(prof.Builder, version)
	structs.OSAddVersionID(prof.Builder, versionID)
	structs.OSAddHomeURL(prof.Builder, homeURL)
	structs.OSAddBugReportURL(prof.Builder, bugReportURL)
	prof.Builder.Finish(structs.OSEnd(prof.Builder))
	p := prof.Builder.Bytes[prof.Builder.Head():]
	// copy them (otherwise gets lost in reset)
	tmp := make([]byte, len(p))
	copy(tmp, p)
	return tmp
}
287183
func (JSONSerializer) Serialize(spans []*model.SpanModel) ([]byte, error) {
	return json.Marshal(spans)
}
740237
func (record *SignedPreKeyRecord) Serialize() ([]byte, error) {
	b, err := proto.Marshal(record.Spkrs)
	if err != nil {
		return nil, err
	}
	return b, nil
}
1294031
func Serialize(os *o.OS) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Serialize(os)
}
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)
}
539777
func (prof *Profiler) Serialize(k *v.Kernel) []byte {
	// ensure the Builder is in a usable state.
	prof.Builder.Reset()
	os := prof.Builder.CreateString(k.OS)
	version := prof.Builder.CreateString(k.Version)
	compileUser := prof.Builder.CreateString(k.CompileUser)
	gcc := prof.Builder.CreateString(k.GCC)
	osgcc := prof.Builder.CreateString(k.OSGCC)
	typ := prof.Builder.CreateString(k.Type)
	compileDate := prof.Builder.CreateString(k.CompileDate)
	arch := prof.Builder.CreateString(k.Arch)
	structs.KernelStart(prof.Builder)
	structs.KernelAddOS(prof.Builder, os)
	structs.KernelAddVersion(prof.Builder, version)
	structs.KernelAddCompileUser(prof.Builder, compileUser)
	structs.KernelAddGCC(prof.Builder, gcc)
	structs.KernelAddOSGCC(prof.Builder, osgcc)
	structs.KernelAddType(prof.Builder, typ)
	structs.KernelAddCompileDate(prof.Builder, compileDate)
	structs.KernelAddArch(prof.Builder, arch)
	prof.Builder.Finish(structs.KernelEnd(prof.Builder))
	p := prof.Builder.Bytes[prof.Builder.Head():]
	// copy them (otherwise gets lost in reset)
	tmp := make([]byte, len(p))
	copy(tmp, p)
	return tmp
}
364125
func (prof *Profiler) Serialize(st *structs.DiskStats) ([]byte, error) {
	return json.Marshal(st)
}
871382
func (j *jws) Serialize(key interface{}) ([]byte, error) {
	if j.isJWT {
		return j.Compact(key)
	}
	return nil, ErrIsNotJWT
}
680180
func Serialize(inf *info.CPUInfo) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Serialize(inf), nil
}