Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make formatter and unknown fields public in ProtoProducerMessage #296

Closed

Conversation

mieczkowski
Copy link
Contributor

I propose to make formatter and unknown fields map more public in protoproducer.ProtoProducerMessage struct.

The reason is that I try to create flows enrichment in custom formatter.

My struct is:

type FlowMessage struct {
	*protoproducer.ProtoProducerMessage
	SrcCountry string `json:"src_country"`
	DstCountry string `json:"dst_country"`
	// other fields
}

In this scenario in method Format(data interface{}) ([]byte, []byte, error) I can fill additional fields without make a copy of original struct. But marshall to json needs to be done in three steps:

  1. Marshal embedded struct to json with m.ProtoProducerMessage.MarshalJSON() to create unknownFields as fields in json and use renderers from config
  2. Parse json into map, fill additional fields
  3. Marshal map to json

With access to formatter from ProtoProducerMessage I could write more efficient json serializer with my fields.

I also need unknown fields for two reasons:

  1. Custom json marshal (obvious ;-) ). If I will make more efficient json marshal function I will be happy to propose it in another PR,
  2. I use expr to make some queries from flow, for example: FlowDirection == "12345" and DstAddr == IP("1.1.2.2")). FlowDirection is in UnknownFields, so I need to materialize them in my struct as map or fields.

@mieczkowski mieczkowski deleted the public_formatter_unknown_keys branch March 14, 2024 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant