func serializeAnyValue()

in transform/otlp_logs_csv.go [149:200]


func serializeAnyValue(buf *strings.Builder, v *commonv1.AnyValue, depth int) {
	if depth == 0 {
		buf.Reset()
	}
	if depth > maxNestedDepth {
		buf.WriteString("...")
		return
	}

	switch v.GetValue().(type) {

	case *commonv1.AnyValue_StringValue:
		// In the case of unstructured text, the top-level Body object
		// is just a simple string, so there is no need to WriteJson
		if depth == 0 {
			buf.WriteString(v.GetStringValue())
			return
		}
		fflib.WriteJson(buf, []byte(v.GetStringValue()))
	case *commonv1.AnyValue_BoolValue:
		fflib.WriteJson(buf, []byte(strconv.FormatBool(v.GetBoolValue())))
	case *commonv1.AnyValue_IntValue:
		fflib.WriteJson(buf, []byte(strconv.FormatInt(v.GetIntValue(), 10)))
	case *commonv1.AnyValue_DoubleValue:
		fflib.WriteJson(buf, []byte(strconv.FormatFloat(v.GetDoubleValue(), 'f', -1, 64)))

	case *commonv1.AnyValue_KvlistValue:
		buf.WriteByte('{')
		for i, kv := range v.GetKvlistValue().GetValues() {
			if i != 0 {
				buf.WriteByte(',')
			}
			fflib.WriteJson(buf, []byte(kv.GetKey()))
			buf.WriteByte(':')
			serializeAnyValue(buf, kv.GetValue(), depth+1)
		}
		buf.WriteByte('}')

	case *commonv1.AnyValue_ArrayValue:
		buf.WriteByte('[')
		for i, v := range v.GetArrayValue().GetValues() {
			if i != 0 {
				buf.WriteByte(',')
			}
			serializeAnyValue(buf, v, depth+1)
		}
		buf.WriteByte(']')

	default:
		fflib.WriteJson(buf, []byte(v.GetStringValue()))
	}
}