// Serialize the CPU Utilization using the package global Profiler.
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
}
1134148
func (f *File) Serialize(w io.Writer) error {
	_, err := iotools.WriteTracker(w, func(w io.Writer) error {
		needsNLs := 0
		maybeAddNL := func() {
			if needsNLs > 0 {
				w.Write(bytes.Repeat([]byte("\n"), needsNLs))
				needsNLs = 0
			}
		}

		if f.ServiceURL != "" {
			maybeAddNL()
			fmt.Fprintf(w, "$ServiceURL %s", f.ServiceURL)
			needsNLs = 1
		}
		if f.ParanoidMode != "" && f.ParanoidMode != deployer.NotParanoid {
			maybeAddNL()
			fmt.Fprintf(w, "$ParanoidMode %s", f.ParanoidMode)
			needsNLs = 1
		}
		if f.ResolvedVersions != "" {
			maybeAddNL()
			fmt.Fprintf(w, "$ResolvedVersions %s", f.ResolvedVersions)
			needsNLs = 1
		}

		if needsNLs != 0 {
			needsNLs += 1 // new line separator if any of $Directives were used
		}

		if len(f.VerifyPlatforms) > 0 {
			for _, plat := range f.VerifyPlatforms {
				maybeAddNL()

				fmt.Fprintf(w, "$VerifiedPlatform %s", plat.String())
				needsNLs = 1
			}

			needsNLs = 2
		}

		keys := make(sort.StringSlice, 0, len(f.PackagesBySubdir))
		for k := range f.PackagesBySubdir {
			keys = append(keys, k)
		}
		keys.Sort()

		for _, k := range keys {
			maybeAddNL()
			if k != "" {
				fmt.Fprintf(w, "@Subdir %s", k)
				needsNLs = 1
			}

			pkgs := f.PackagesBySubdir[k]
			pkgsSort := make(PackageSlice, len(pkgs))
			maxLength := 0
			for i, pkg := range pkgs {
				pkgsSort[i] = pkg
				if l := len(pkg.PackageTemplate); l > maxLength {
					maxLength = l
				}
			}
			sort.Sort(pkgsSort)

			for _, p := range pkgsSort {
				maybeAddNL()
				fmt.Fprintf(w, "%-*s %s", maxLength+1, p.PackageTemplate, p.UnresolvedVersion)
				needsNLs = 1
			}
			needsNLs++
		}

		// We only ever want to end the file with 1 newline.
		if needsNLs > 0 {
			needsNLs = 1
		}
		maybeAddNL()
		return nil
	})
	return err
}
697966
func (l *bunyanLog) serialize(key string, value interface{}) interface{} {
	if fn, ok := l.logger.serializers[key]; ok {
		return fn(value)
	} else if isError(value) {
		return fmt.Sprintf("%v", value)
	} else {
		return value
	}
}
730252
func (p *Profiler) Serialize(inf *info.CPUInfo) []byte {
	// ensure the Builder is in a usable state.
	p.Builder.Reset()
	uoffs := make([]fb.UOffsetT, len(inf.CPU))
	for i, cpu := range inf.CPU {
		uoffs[i] = p.SerializeCPU(&cpu)
	}
	structs.CPUInfoStartCPUVector(p.Builder, len(uoffs))
	for i := len(uoffs) - 1; i >= 0; i-- {
		p.Builder.PrependUOffsetT(uoffs[i])
	}
	cpusV := p.Builder.EndVector(len(uoffs))
	structs.CPUInfoStart(p.Builder)
	structs.CPUInfoAddTimestamp(p.Builder, inf.Timestamp)
	structs.CPUInfoAddSockets(p.Builder, inf.Sockets)
	structs.CPUInfoAddCPU(p.Builder, cpusV)
	p.Builder.Finish(structs.CPUInfoEnd(p.Builder))
	b := p.Builder.Bytes[p.Builder.Head():]
	// copy them (otherwise gets lost in reset)
	tmp := make([]byte, len(b))
	copy(tmp, b)
	return tmp
}
579542
func (record *PreKeyRecord) Serialize() ([]byte, error) {
	b, err := proto.Marshal(record.Pkrs)
	if err != nil {
		return nil, err
	}
	return b, nil
}
1088687
func (o *objectCache) serialize(hash string) (fq *serializer.FunctionQueue, found bool) {
	o.Lock()
	defer o.Unlock()

	fq, compiled := o.compileQueue[hash]
	if !compiled {
		fq = serializer.NewFunctionQueue(1)
		o.compileQueue[hash] = fq
	}
	return fq, compiled
}
688313
func (p *Profiler) SerializeNode(node *numa.Node) fb.UOffsetT {
	cpuList := p.Builder.CreateString(node.CPUList)
	structs.NodeStart(p.Builder)
	structs.NodeAddID(p.Builder, node.ID)
	structs.NodeAddCPUList(p.Builder, cpuList)
	return structs.NodeEnd(p.Builder)
}
1246498
func (p *Profiler) Serialize(f *freq.Frequency) []byte {
	// ensure the Builder is in a usable state.
	p.Builder.Reset()
	uoffs := make([]fb.UOffsetT, len(f.CPU))
	for i, cpu := range f.CPU {
		uoffs[i] = p.SerializeCPU(&cpu)
	}
	structs.FrequencyStartCPUVector(p.Builder, len(uoffs))
	for i := len(uoffs) - 1; i >= 0; i-- {
		p.Builder.PrependUOffsetT(uoffs[i])
	}
	cpusV := p.Builder.EndVector(len(uoffs))
	structs.FrequencyStart(p.Builder)
	structs.FrequencyAddTimestamp(p.Builder, f.Timestamp)
	structs.FrequencyAddSockets(p.Builder, f.Sockets)
	structs.FrequencyAddCPU(p.Builder, cpusV)
	p.Builder.Finish(structs.FrequencyEnd(p.Builder))
	b := p.Builder.Bytes[p.Builder.Head():]
	// copy them (otherwise gets lost in reset)
	tmp := make([]byte, len(b))
	copy(tmp, b)
	return tmp
}
887798
func (prof *Profiler) calculateUtilization(cur *stats.CPUStats) *CPUUtil {
	u := &CPUUtil{
		Timestamp:  cur.Timestamp,
		TimeDelta:  cur.Timestamp - prof.prior.Timestamp,
		BTimeDelta: int32(cur.Timestamp/1000000000 - cur.BTime),
		CtxtDelta:  cur.Ctxt - prof.prior.Ctxt,
		Processes:  int32(cur.Processes),
		CPU:        make([]Utilization, len(cur.CPU)),
	}
	var dUser, dNice, dSys, dIdle, tot float32
	// Rest of the calculations are per core
	for i := 0; i < len(cur.CPU); i++ {
		v := Utilization{ID: cur.CPU[i].ID}
		dUser = float32(cur.CPU[i].User - prof.prior.CPU[i].User)
		dNice = float32(cur.CPU[i].Nice - prof.prior.CPU[i].Nice)
		dSys = float32(cur.CPU[i].System - prof.prior.CPU[i].System)
		dIdle = float32(cur.CPU[i].Idle - prof.prior.CPU[i].Idle)
		tot = dUser + dNice + dSys + dIdle
		v.Usage = (dUser + dNice + dSys) / tot * float32(cur.ClkTck)
		v.User = dUser / tot * float32(cur.ClkTck)
		v.Nice = dNice / tot * float32(cur.ClkTck)
		v.System = dSys / tot * float32(cur.ClkTck)
		v.Idle = dIdle / tot * float32(cur.ClkTck)
		v.IOWait = float32(cur.CPU[i].IOWait-prof.prior.CPU[i].IOWait) / tot * float32(cur.ClkTck)
		u.CPU[i] = v
	}
	return u
}
141433
func Deserialize(p []byte) *processors.Processors {
	flatP := structs.GetRootAsProcessors(p, 0)
	procs := &processors.Processors{}
	flatCache := &structs.CacheInf{}
	procs.Timestamp = flatP.Timestamp()
	procs.Architecture = string(flatP.Architecture())
	procs.CPUs = flatP.CPUs()
	procs.Possible = string(flatP.Possible())
	procs.Present = string(flatP.Present())
	procs.Offline = string(flatP.Offline())
	procs.Online = string(flatP.Online())
	procs.Sockets = flatP.Sockets()
	procs.CoresPerSocket = flatP.CoresPerSocket()
	procs.ThreadsPerCore = flatP.ThreadsPerCore()
	procs.VendorID = string(flatP.VendorID())
	procs.CPUFamily = string(flatP.CPUFamily())
	procs.Model = string(flatP.Model())
	procs.ModelName = string(flatP.ModelName())
	procs.Stepping = string(flatP.Stepping())
	procs.Microcode = string(flatP.Microcode())
	procs.CPUMHz = flatP.CPUMHz()
	procs.MHzMin = flatP.MHzMin()
	procs.MHzMax = flatP.MHzMax()
	procs.BogoMIPS = flatP.BogoMIPS()
	procs.CacheSize = string(flatP.CacheSize())
	procs.CacheIDs = make([]string, 0, flatP.CacheLength())
	procs.Cache = make(map[string]string, flatP.CacheLength())
	for j := 0; j < flatP.CacheLength(); j++ {
		if !flatP.Cache(flatCache, j) {
			continue
		}
		procs.CacheIDs = append(procs.CacheIDs, string(flatCache.ID()))
		procs.Cache[procs.CacheIDs[j]] = string(flatCache.Size())
	}
	procs.Flags = make([]string, flatP.FlagsLength())
	for i := 0; i < len(procs.Flags); i++ {
		procs.Flags[i] = string(flatP.Flags(i))
	}
	procs.Bugs = make([]string, flatP.BugsLength())
	for i := 0; i < len(procs.Bugs); i++ {
		procs.Bugs[i] = string(flatP.Bugs(i))
	}
	procs.OpModes = make([]string, flatP.OpModesLength())
	for i := 0; i < len(procs.OpModes); i++ {
		procs.OpModes[i] = string(flatP.OpModes(i))
	}
	procs.Virtualization = string(flatP.Virtualization())
	procs.NumaNodes = flatP.NumaNodes()
	var n structs.Node
	procs.NumaNodeCPUs = make([]node.Node, flatP.NumaNodeCPUsLength())
	for i := 0; i < len(procs.NumaNodeCPUs); i++ {
		if !flatP.NumaNodeCPUs(&n, i) {
			continue
		}
		procs.NumaNodeCPUs[i].ID = n.ID()
		procs.NumaNodeCPUs[i].CPUList = string(n.CPUList())
	}
	return procs
}
859889
func (b *NexthopRegisterBody) Serialize(version uint8) ([]byte, error) {
	buf := make([]byte, 0)

	// List of Registered Nexthops
	for _, nh := range b.Nexthops {
		nhBuf, err := nh.Serialize()
		if err != nil {
			return nil, err
		}
		buf = append(buf, nhBuf...)
	}

	return buf, nil
}
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)
}
75721
func (prof *Profiler) Serialize(u *util.CPUUtil) []byte {
	// ensure the Builder is in a usable state.
	prof.Builder.Reset()
	utils := make([]fb.UOffsetT, len(u.CPU))
	ids := make([]fb.UOffsetT, len(u.CPU))
	for i := 0; i < len(ids); i++ {
		ids[i] = prof.Builder.CreateString(u.CPU[i].ID)
	}
	for i := 0; i < len(utils); i++ {
		structs.UtilizationStart(prof.Builder)
		structs.UtilizationAddID(prof.Builder, ids[i])
		structs.UtilizationAddUsage(prof.Builder, u.CPU[i].Usage)
		structs.UtilizationAddUser(prof.Builder, u.CPU[i].User)
		structs.UtilizationAddNice(prof.Builder, u.CPU[i].Nice)
		structs.UtilizationAddSystem(prof.Builder, u.CPU[i].System)
		structs.UtilizationAddIdle(prof.Builder, u.CPU[i].Idle)
		structs.UtilizationAddIOWait(prof.Builder, u.CPU[i].IOWait)
		utils[i] = structs.UtilizationEnd(prof.Builder)
	}
	structs.CPUUtilStartCPUVector(prof.Builder, len(utils))
	for i := len(utils) - 1; i >= 0; i-- {
		prof.Builder.PrependUOffsetT(utils[i])
	}
	utilsV := prof.Builder.EndVector(len(utils))
	structs.CPUUtilStart(prof.Builder)
	structs.CPUUtilAddTimestamp(prof.Builder, u.Timestamp)
	structs.CPUUtilAddTimeDelta(prof.Builder, u.TimeDelta)
	structs.CPUUtilAddBTimeDelta(prof.Builder, u.BTimeDelta)
	structs.CPUUtilAddCtxtDelta(prof.Builder, u.CtxtDelta)
	structs.CPUUtilAddProcesses(prof.Builder, u.Processes)
	structs.CPUUtilAddCPU(prof.Builder, utilsV)
	prof.Builder.Finish(structs.CPUUtilEnd(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
}
1027588
func (b *AnnealingEpsilonGreedy) Serialize() interface{} {
	data := make(map[string]interface{})
	data["strategy"] = "annealing epsilon greedy"
	data["epsilon"] = b.Epsilon()
	data["counts"] = b.counts
	data["values"] = b.values
	return data
}
237811
func Serialize(st *structs.DiskStats) (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)
}
607192
func Deserialize(p []byte) *stats.CPUStats {
	statsS := &stats.CPUStats{}
	cpuF := &structs.CPU{}
	statsF := structs.GetRootAsCPUStats(p, 0)
	statsS.ClkTck = statsF.ClkTck()
	statsS.Timestamp = statsF.Timestamp()
	statsS.Ctxt = statsF.Ctxt()
	statsS.BTime = statsF.BTime()
	statsS.Processes = statsF.Processes()
	len := statsF.CPULength()
	statsS.CPU = make([]stats.CPU, len)
	for i := 0; i < len; i++ {
		var cpu stats.CPU
		if statsF.CPU(cpuF, i) {
			cpu.ID = string(cpuF.ID())
			cpu.User = cpuF.User()
			cpu.Nice = cpuF.Nice()
			cpu.System = cpuF.System()
			cpu.Idle = cpuF.Idle()
			cpu.IOWait = cpuF.IOWait()
			cpu.IRQ = cpuF.IRQ()
			cpu.SoftIRQ = cpuF.SoftIRQ()
			cpu.Steal = cpuF.Steal()
			cpu.Quest = cpuF.Quest()
			cpu.QuestNice = cpuF.QuestNice()
		}
		statsS.CPU[i] = cpu
	}
	return statsS
}
451308
func Serialize(v interface{}, simple bool) []byte {
	return NewWriter(simple).Serialize(v).Bytes()
}