diff --git a/data/config.db b/data/config.db index 2d92fba..a39ebf7 100644 --- a/data/config.db +++ b/data/config.db Binary files differ diff --git a/internal/converter.go b/internal/converter.go index e0ae349..035a6db 100644 --- a/internal/converter.go +++ b/internal/converter.go @@ -7,13 +7,27 @@ "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" yaml "gopkg.in/yaml.v3" ) // ConvertProtoToYAML converts any protobuf message to a YAML string with 2-space indentation func ConvertProtoToYAML(msg proto.Message) (string, error) { - // 1. Marshal protobuf to JSON - jsonBytes, err := protojson.Marshal(msg) + // 1. Wrap the message in a google.protobuf.Any container. + // This is the standard way to ensure the "@type" field is emitted. + anyMsg, err := anypb.New(msg) + if err != nil { + return "", fmt.Errorf("failed to wrap proto message in Any: %w", err) + } + + // 2. Marshal the 'Any' message to JSON. + // MarshalOptions can use default settings here. + options := protojson.MarshalOptions{ + // Still a good practice to use, but EmitType is not the answer here. + UseProtoNames: false, + } + + jsonBytes, err := options.Marshal(anyMsg) // <-- Marshal the 'anyMsg' if err != nil { return "", fmt.Errorf("failed to marshal proto to JSON: %w", err) }