// ApplyFormatter update message payload
507735
func (format *Serialize) ApplyFormatter(msg *core.Message) error {
	data, err := msg.Serialize()
	if err != nil {
		format.Logger.Error(err)
		return err
	}

	format.SetAppliedContent(msg, data)
	return nil
}
222157
func (b *MultiHandler) SetFormatter(f Formatter) {
	for _, h := range b.handlers {
		h.SetFormatter(f)
	}
}
243894
func (logger *Logger) SetFormatter(formatter Formatter) {
	logger.mu.Lock()
	defer logger.mu.Unlock()
	logger.Formatter = formatter
}
860864
func (format *Timestamp) ApplyFormatter(msg *core.Message) error {
	timestampStr := msg.GetCreationTime().Format(format.timestampFormat)
	content := format.GetAppliedContent(msg)

	dataSize := len(timestampStr) + len(content)
	payload := make([]byte, dataSize)

	offset := copy(payload, []byte(timestampStr))
	copy(payload[offset:], content)

	format.SetAppliedContent(msg, payload)
	return nil
}
916886
func NewFormatter(verb, format string) (Formatter, error) {
	switch verb {
	case "color":
		return newColorFormatter(format)
	case "id":
		return newSequenceFormatter(format), nil
	case "level":
		return newLevelFormatter(format), nil
	case "message":
		return newMessageFormatter(format), nil
	case "module":
		return newModuleFormatter(format), nil
	case "shortfunc":
		return newShortFuncFormatter(format), nil
	case "time":
		return newTimeFormatter(format), nil
	default:
		return nil, fmt.Errorf("unknown verb: %s", verb)
	}
}
517906
func applyMap(dst reflect.Value, src reflect.Value) error {
	dstKeyType := dst.Type().Key()
	dstValType := dst.Type().Elem()

	dst.Set(reflect.MakeMap(dst.Type()))
	for _, k := range src.MapKeys() {
		if k.Type().Kind() == reflect.Interface {
			k = k.Elem()
		}
		var err error
		if k, err = convert(k, dstKeyType); err != nil {
			return fmt.Errorf("key '%v' invalid type: %s", k.Interface(), err)
		}

		v := src.MapIndex(k)
		if v, err = convert(v, dstValType); err != nil {
			return fmt.Errorf("value for key '%v' invalid type: %s", k.Interface(), err)
		}
		dst.SetMapIndex(k, v)
	}
	return nil
}
1294483
func (k *KeyReadWriter) SetKeyFormatter(kf keyutils.Formatter) {
	k.mu.Lock()
	defer k.mu.Unlock()
	k.keyFormatter = kf
}
582819
func (sf *SigFilter) Apply(message *cb.Envelope) error {
	signedData, err := message.AsSignedData()

	if err != nil {
		return fmt.Errorf("could not convert message to signedData: %s", err)
	}

	policy, ok := sf.support.PolicyManager().GetPolicy(sf.policyName)
	if !ok {
		return fmt.Errorf("could not find policy %s", sf.policyName)
	}

	err = policy.Evaluate(signedData)
	if err != nil {
		return errors.Wrap(errors.WithStack(ErrPermissionDenied), err.Error())
	}
	return nil
}
1051277
func (format *StreamRevert) ApplyFormatter(msg *core.Message) error {
	msg.SetStreamID(msg.GetPrevStreamID())
	return nil
}
1344638
func (format *JSONToArray) ApplyFormatter(msg *core.Message) error {
	content, err := format.getCsvContent(format.GetAppliedContent(msg))
	if err != nil {
		return err
	}

	format.SetAppliedContent(msg, content)
	return nil
}
958061
func NewFormatter(fraction int, decimal, thousand, grapheme, template string) *Formatter {
	return &Formatter{
		Fraction: fraction,
		Decimal:  decimal,
		Thousand: thousand,
		Grapheme: grapheme,
		Template: template,
	}
}
367197
func applyTransform(str string, transform sf) (out string) {
	out = ""

	for idx, line := range strings.Split(str, "\n") {
		out += transform(idx, line)
	}

	return
}
936927
func (format *RegExp) ApplyFormatter(msg *core.Message) error {
	content := format.GetAppliedContent(msg)
	matches := format.expression.FindSubmatchIndex(content)
	transformed := format.expression.Expand([]byte{}, format.template, content, matches)

	format.SetAppliedContent(msg, transformed)
	return nil
}
974239
func (formatters FormatterArray) ApplyFormatter(msg *Message) error {
	for _, formatter := range formatters {
		if formatter.CanBeApplied(msg) {
			if err := formatter.ApplyFormatter(msg); err != nil {
				return err
			}
		}
	}
	return nil
}
977772
func (m *MultiFormatter) SetFormatters(formatters []Formatter) {
	m.mutex.Lock()
	m.formatters = formatters
	m.mutex.Unlock()
}
1166200
func (format *Aggregate) ApplyFormatter(msg *core.Message) error {
	for _, modulator := range format.modulators {
		modulateResult := modulator.Modulate(msg)
		if modulateResult != core.ModulateResultContinue {
			errMsg := "child modulator discarded or trigger fallback routing. " +
				"Please try to use only contend based formatter and filter as child modulators"
			return fmt.Errorf(errMsg)
		}
	}
	return nil
}
742362
func (filter *JSON) ApplyFilter(msg *core.Message) (core.FilterResult, error) {
	values := tcontainer.NewMarshalMap()
	if err := json.Unmarshal(filter.getAppliedContent(msg), &values); err != nil {
		return filter.GetFilterResultMessageReject(), err
	}

	// Check rejects
	for key, exp := range filter.rejectValues {
		if value, exists := filter.getValue(key, values); exists {
			if exp.MatchString(value) {
				return filter.GetFilterResultMessageReject(), nil
			}
		}
	}

	// Check accepts
	for key, exp := range filter.acceptValues {
		if value, exists := filter.getValue(key, values); exists {
			if !exp.MatchString(value) {
				return filter.GetFilterResultMessageReject(), nil
			}
		}
	}

	return core.FilterResultMessageAccept, nil
}