// Deserialize takes some Flatbuffer serialized bytes and deserializes them as
// structs.DevInfo.
12062
func Deserialize(p []byte) *structs.DevInfo {
	devInfo := flat.GetRootAsDevInfo(p, 0)
	// get the # of interfaces
	dLen := devInfo.DeviceLength()
	info := &structs.DevInfo{Timestamp: devInfo.Timestamp(), Device: make([]structs.Device, dLen)}
	fDev := &flat.Device{}
	sDev := structs.Device{}
	for i := 0; i < dLen; i++ {
		if devInfo.Device(fDev, i) {
			sDev.Name = string(fDev.Name())
			sDev.RBytes = fDev.RBytes()
			sDev.RPackets = fDev.RPackets()
			sDev.RErrs = fDev.RErrs()
			sDev.RDrop = fDev.RDrop()
			sDev.RFIFO = fDev.RFIFO()
			sDev.RFrame = fDev.RFrame()
			sDev.RCompressed = fDev.RCompressed()
			sDev.RMulticast = fDev.RMulticast()
			sDev.TBytes = fDev.TBytes()
			sDev.TPackets = fDev.TPackets()
			sDev.TErrs = fDev.TErrs()
			sDev.TDrop = fDev.TDrop()
			sDev.TFIFO = fDev.TFIFO()
			sDev.TColls = fDev.TColls()
			sDev.TCarrier = fDev.TCarrier()
			sDev.TCompressed = fDev.TCompressed()
		}
		info.Device[i] = sDev
	}
	return info
}
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
}
664248
func (t *FpdfTpl) Serialize() ([]byte, error) {
	b := new(bytes.Buffer)
	enc := gob.NewEncoder(b)
	err := enc.Encode(t)

	return b.Bytes(), err
}
473768
func (j JSONPBStateSerializer) Deserialize(serialized string, state interface{}) error {
	pm, ok := state.(proto.Message)
	if ok {
		return j.u.Unmarshal(strings.NewReader(serialized), pm)
	}
	return j.fbss.Deserialize(serialized, state)
}
349703
func Serialize(key string, obj interface{}, options ...map[string]interface{}) ([]byte, error) {
	// only to the default serializer, check if no of the built'n serializer's key are registered, if not register them here
	// I don't put it to the initialize of the defaultSerializers because the developer may don't want the built'n serializers at all
	once.Do(func() {
		RegisterDefaults(defaultSerializers)
	})

	return defaultSerializers.Serialize(key, obj, options...)
}
528705
func DeserializeAttributes(data []byte) ([]Attribute, error) {

	// Define a JSON shim Attribute
	var attrs []json.RawMessage
	err := json.Unmarshal(data, &attrs)
	if err != nil {
		return nil, fmt.Errorf("Failed to deserialize attributes: %v", err)
	}

	ret := make([]Attribute, len(attrs))
	for i, v := range attrs {
		ret[i], err = DeserializeAttribute(v)
		if err != nil {
			return nil, err
		}
	}

	return ret, nil
}
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
}
90427
func (prof *Profiler) Serialize(st *stats.CPUStats) ([]byte, error) {
	return json.Marshal(st)
}
691746
func (s *Single) Deserialize(r io.Reader) error {
	// First, we'll need to read the version of this single-back up so we
	// can know how to unpack each of the SCB.
	var version byte
	err := lnwire.ReadElements(r, &version)
	if err != nil {
		return err
	}

	s.Version = SingleBackupVersion(version)

	switch s.Version {
	case DefaultSingleVersion:
	default:
		return fmt.Errorf("unable to de-serialize w/ unknown "+
			"version: %v", s.Version)
	}

	var length uint16
	if err := lnwire.ReadElements(r, &length); err != nil {
		return err
	}

	err = lnwire.ReadElements(
		r, &s.IsInitiator, s.ChainHash[:], &s.FundingOutpoint,
		&s.ShortChannelID, &s.RemoteNodePub, &s.Addresses, &s.Capacity,
	)
	if err != nil {
		return err
	}

	err = lnwire.ReadElements(r, &s.LocalChanCfg.CsvDelay)
	if err != nil {
		return err
	}
	s.LocalChanCfg.MultiSigKey, err = readLocalKeyDesc(r)
	if err != nil {
		return err
	}
	s.LocalChanCfg.RevocationBasePoint, err = readLocalKeyDesc(r)
	if err != nil {
		return err
	}
	s.LocalChanCfg.PaymentBasePoint, err = readLocalKeyDesc(r)
	if err != nil {
		return err
	}
	s.LocalChanCfg.DelayBasePoint, err = readLocalKeyDesc(r)
	if err != nil {
		return err
	}
	s.LocalChanCfg.HtlcBasePoint, err = readLocalKeyDesc(r)
	if err != nil {
		return err
	}

	err = lnwire.ReadElements(r, &s.RemoteChanCfg.CsvDelay)
	if err != nil {
		return err
	}
	s.RemoteChanCfg.MultiSigKey, err = readRemoteKeyDesc(r)
	if err != nil {
		return err
	}
	s.RemoteChanCfg.RevocationBasePoint, err = readRemoteKeyDesc(r)
	if err != nil {
		return err
	}
	s.RemoteChanCfg.PaymentBasePoint, err = readRemoteKeyDesc(r)
	if err != nil {
		return err
	}
	s.RemoteChanCfg.DelayBasePoint, err = readRemoteKeyDesc(r)
	if err != nil {
		return err
	}
	s.RemoteChanCfg.HtlcBasePoint, err = readRemoteKeyDesc(r)
	if err != nil {
		return err
	}

	// Finally, we'll parse out the ShaChainRootDesc.
	var (
		shaChainPub [33]byte
		zeroPub     [33]byte
	)
	if err := lnwire.ReadElements(r, shaChainPub[:]); err != nil {
		return err
	}

	// Since this field is optional, we'll check to see if the pubkey has
	// been specified or not.
	if !bytes.Equal(shaChainPub[:], zeroPub[:]) {
		s.ShaChainRootDesc.PubKey, err = btcec.ParsePubKey(
			shaChainPub[:], btcec.S256(),
		)
		if err != nil {
			return err
		}
	}

	var shaKeyFam uint32
	if err := lnwire.ReadElements(r, &shaKeyFam); err != nil {
		return err
	}
	s.ShaChainRootDesc.KeyLocator.Family = keychain.KeyFamily(shaKeyFam)

	return lnwire.ReadElements(r, &s.ShaChainRootDesc.KeyLocator.Index)
}
568133
func Deserialize(p []byte) (*structs.DevUsage, error) {
	u := &structs.DevUsage{}
	err := json.Unmarshal(p, u)
	if err != nil {
		return nil, err
	}
	return u, nil
}
1314522
func (s GobSerializer) Serialize(ss *sessions.Session) ([]byte, error) {
	buf := new(bytes.Buffer)
	enc := gob.NewEncoder(buf)
	err := enc.Encode(ss.Values)
	if err == nil {
		return buf.Bytes(), nil
	}
	return nil, err
}
1243069
func (j JSONStateSerializer) Deserialize(serialized string, state interface{}) error {
	err := json.NewDecoder(strings.NewReader(serialized)).Decode(state)
	return err
}
588784
func B58Deserialize(data string) (*Key, error) {
	b, err := base58Decode(data)
	if err != nil {
		return nil, err
	}
	return Deserialize(b)
}
533615
func Deserialize(p []byte) (*procs.Processors, error) {
	proc := &procs.Processors{}
	err := json.Unmarshal(p, proc)
	if err != nil {
		return nil, err
	}
	return proc, nil
}
187152
func Deserialize(p []byte) *structs.DiskStats {
	stts := &structs.DiskStats{}
	devF := &flat.Device{}
	statsFlat := flat.GetRootAsDiskStats(p, 0)
	stts.Timestamp = statsFlat.Timestamp()
	len := statsFlat.DeviceLength()
	stts.Device = make([]structs.Device, len)
	for i := 0; i < len; i++ {
		var dev structs.Device
		if statsFlat.Device(devF, i) {
			dev.Major = devF.Major()
			dev.Minor = devF.Minor()
			dev.Name = string(devF.Name())
			dev.ReadsCompleted = devF.ReadsCompleted()
			dev.ReadsMerged = devF.ReadsMerged()
			dev.ReadSectors = devF.ReadSectors()
			dev.ReadingTime = devF.ReadingTime()
			dev.WritesCompleted = devF.WritesCompleted()
			dev.WritesMerged = devF.WritesMerged()
			dev.WrittenSectors = devF.WrittenSectors()
			dev.WritingTime = devF.WritingTime()
			dev.IOInProgress = devF.IOInProgress()
			dev.IOTime = devF.IOTime()
			dev.WeightedIOTime = devF.WeightedIOTime()
		}
		stts.Device[i] = dev
	}
	return stts
}
507600
func (p ProtobufStateSerializer) Serialize(state interface{}) (string, error) {
	bin, err := proto.Marshal(state.(proto.Message))
	if err != nil {
		return "", err
	}
	return base64.StdEncoding.EncodeToString(bin), nil
}
414707
func (prof *Profiler) Serialize(stts *structs.DiskStats) []byte {
	// ensure the Builder is in a usable state.
	prof.Builder.Reset()
	devF := make([]fb.UOffsetT, len(stts.Device))
	names := make([]fb.UOffsetT, len(stts.Device))
	for i := 0; i < len(names); i++ {
		names[i] = prof.Builder.CreateString(stts.Device[i].Name)
	}
	for i := 0; i < len(devF); i++ {
		flat.DeviceStart(prof.Builder)
		flat.DeviceAddMajor(prof.Builder, stts.Device[i].Major)
		flat.DeviceAddMinor(prof.Builder, stts.Device[i].Minor)
		flat.DeviceAddName(prof.Builder, names[i])
		flat.DeviceAddReadsCompleted(prof.Builder, stts.Device[i].ReadsCompleted)
		flat.DeviceAddReadsMerged(prof.Builder, stts.Device[i].ReadsMerged)
		flat.DeviceAddReadSectors(prof.Builder, stts.Device[i].ReadSectors)
		flat.DeviceAddReadingTime(prof.Builder, stts.Device[i].ReadingTime)
		flat.DeviceAddWritesCompleted(prof.Builder, stts.Device[i].WritesCompleted)
		flat.DeviceAddWritesMerged(prof.Builder, stts.Device[i].WritesMerged)
		flat.DeviceAddWrittenSectors(prof.Builder, stts.Device[i].WrittenSectors)
		flat.DeviceAddWritingTime(prof.Builder, stts.Device[i].WritingTime)
		flat.DeviceAddIOInProgress(prof.Builder, stts.Device[i].IOInProgress)
		flat.DeviceAddIOTime(prof.Builder, stts.Device[i].IOTime)
		flat.DeviceAddWeightedIOTime(prof.Builder, stts.Device[i].WeightedIOTime)
		devF[i] = flat.DeviceEnd(prof.Builder)
	}
	flat.DiskStatsStartDeviceVector(prof.Builder, len(devF))
	for i := len(devF) - 1; i >= 0; i-- {
		prof.Builder.PrependUOffsetT(devF[i])
	}
	devV := prof.Builder.EndVector(len(devF))
	flat.DiskStatsStart(prof.Builder)
	flat.DiskStatsAddTimestamp(prof.Builder, stts.Timestamp)
	flat.DiskStatsAddDevice(prof.Builder, devV)
	prof.Builder.Finish(flat.DiskStatsEnd(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
}