// Serialize returns the result as bytes representation of the serializer(s)
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...)
}
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
}
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
}
1036226
func (m MockContext) Serialize() ([]byte, error) {
	if m.SigningIdentity == nil {
		return nil, errors.New("anonymous countext")
	}
	return m.SigningIdentity.Serialize()
}
135015
func (e *Serializer) Serialize(val interface{}, options ...map[string]interface{}) ([]byte, error) {
	var result []byte
	var err error
	if e.config.Indent {
		result, err = json.MarshalIndent(val, "", "  ")
	} else {
		result, err = json.Marshal(val)
	}

	if err != nil {
		return nil, err
	}

	// the config's callback can be overriden with the options
	callback := e.config.Callback
	if len(options) > 0 {
		callback = e.getCallbackOption(options[0])
	}

	if callback != "" {
		result = append([]byte(callback+"("), result...)
		result = append(result, finishCallbackB...)
	}

	if e.config.Indent {
		result = append(result, newLineB...)
	}
	return result, nil
}
1106095
func Serialize(u *up.Uptime) []byte {
	mu.Lock()
	defer mu.Unlock()
	// ensure the Builder is in a usable state.
	builder.Reset()
	structs.UptimeStart(builder)
	structs.UptimeAddTimestamp(builder, u.Timestamp)
	structs.UptimeAddUptime(builder, u.Uptime)
	builder.Finish(structs.UptimeEnd(builder))
	p := builder.Bytes[builder.Head():]
	// copy them (otherwise gets lost in reset)
	tmp := make([]byte, len(p))
	copy(tmp, p)
	return tmp
}
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
}
194380
func (s *Single) Serialize(w io.Writer) error {
	// Check to ensure that we'll only attempt to serialize a version that
	// we're aware of.
	switch s.Version {
	case DefaultSingleVersion:
	default:
		return fmt.Errorf("unable to serialize w/ unknown "+
			"version: %v", s.Version)
	}

	// If the sha chain root has specified a public key (which is
	// optional), then we'll encode it now.
	var shaChainPub [33]byte
	if s.ShaChainRootDesc.PubKey != nil {
		copy(
			shaChainPub[:],
			s.ShaChainRootDesc.PubKey.SerializeCompressed(),
		)
	}

	// First we gather the SCB as is into a temporary buffer so we can
	// determine the total length. Before we write out the serialized SCB,
	// we write the length which allows us to skip any Singles that we
	// don't know of when decoding a multi.
	var singleBytes bytes.Buffer
	if err := lnwire.WriteElements(
		&singleBytes,
		s.IsInitiator,
		s.ChainHash[:],
		s.FundingOutpoint,
		s.ShortChannelID,
		s.RemoteNodePub,
		s.Addresses,
		s.Capacity,

		s.LocalChanCfg.CsvDelay,

		// We only need to write out the KeyLocator portion of the
		// local channel config.
		uint32(s.LocalChanCfg.MultiSigKey.Family),
		s.LocalChanCfg.MultiSigKey.Index,
		uint32(s.LocalChanCfg.RevocationBasePoint.Family),
		s.LocalChanCfg.RevocationBasePoint.Index,
		uint32(s.LocalChanCfg.PaymentBasePoint.Family),
		s.LocalChanCfg.PaymentBasePoint.Index,
		uint32(s.LocalChanCfg.DelayBasePoint.Family),
		s.LocalChanCfg.DelayBasePoint.Index,
		uint32(s.LocalChanCfg.HtlcBasePoint.Family),
		s.LocalChanCfg.HtlcBasePoint.Index,

		s.RemoteChanCfg.CsvDelay,

		// We only need to write out the raw pubkey for the remote
		// channel config.
		s.RemoteChanCfg.MultiSigKey.PubKey,
		s.RemoteChanCfg.RevocationBasePoint.PubKey,
		s.RemoteChanCfg.PaymentBasePoint.PubKey,
		s.RemoteChanCfg.DelayBasePoint.PubKey,
		s.RemoteChanCfg.HtlcBasePoint.PubKey,

		shaChainPub[:],
		uint32(s.ShaChainRootDesc.KeyLocator.Family),
		s.ShaChainRootDesc.KeyLocator.Index,
	); err != nil {
		return err
	}

	return lnwire.WriteElements(
		w,
		byte(s.Version),
		uint16(len(singleBytes.Bytes())),
		singleBytes.Bytes(),
	)
}
676376
func (prof *Profiler) Serialize(f *freq.Frequency) ([]byte, error) {
	return json.Marshal(f)
}
827374
func (j JSONPBStateSerializer) Serialize(state interface{}) (string, error) {
	pm, ok := state.(proto.Message)
	if ok {
		return j.m.MarshalToString(pm)
	}
	return j.fbss.Serialize(state)
}
418607
func (prof *Profiler) Serialize(inf *info.CPUInfo) ([]byte, error) {
	return json.Marshal(inf)
}
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
}
252684
func (msg *Message) Serialize() []byte {
	msg.DataLen = msgLenToBytes(int64(len(msg.Data)))
	buf := bytes.NewBuffer([]byte{})
	binary.Write(buf, binary.BigEndian, msg.MessageHeader)
	binary.Write(buf, binary.BigEndian, msg.Data[:])

	return buf.Bytes()
}
1372813
func Serialize(k *v.Kernel) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Serialize(k)
}
704709
func Serialize(la l.LoadAvg) (p []byte, err error) {
	stdMu.Lock()
	defer stdMu.Unlock()
	if std == nil {
		std, err = NewProfiler()
		if err != nil {
			return nil, err
		}
	}
	return std.Serialize(la)
}
579542
func (record *PreKeyRecord) Serialize() ([]byte, error) {
	b, err := proto.Marshal(record.Pkrs)
	if err != nil {
		return nil, err
	}
	return b, nil
}
426105
func (s JSONSerialize) Serialize(m *Message) ([]byte, error) {
	if s.Pretty {
		return json.MarshalIndent(m, "", "  ")
	}
	return json.Marshal(m)
}