<commit_before>package events

import (
	"context"
	"time"

	"github.com/gogo/protobuf/types"
)

// Envelope provides the packaging for an event.
type Envelope struct {
	Timestamp time.Time
	Namespace string
	Topic     string
	Event     *types.Any
}

// Event is a generic interface for any type of event
type Event interface{}
<commit_msg>events: define fieldpath implement for envelope<commit_after>package events

import (
	"context"
	"time"

	"github.com/containerd/typeurl"
	"github.com/gogo/protobuf/types"
)

// Envelope provides the packaging for an event.
type Envelope struct {
	Timestamp time.Time
	Namespace string
	Topic     string
	Event     *types.Any
}

// Field returns the value for the given fieldpath as a string, if defined.
// If the value is not defined, the second value will be false.
func (e *Envelope) Field(fieldpath []string) (string, bool) {
	if len(fieldpath) == 0 {
		return "", false
	}

	switch fieldpath[0] {
	// unhandled: timestamp
	case "namespace":
		return string(e.Namespace), len(e.Namespace) > 0
	case "topic":
		return string(e.Topic), len(e.Topic) > 0
	case "event":
		decoded, err := typeurl.UnmarshalAny(e.Event)
		if err != nil {
			return "", false
		}

		adaptor, ok := decoded.(interface {
			Field([]string) (string, bool)
		})
		if !ok {
			return "", false
		}
		return adaptor.Field(fieldpath[1:])
	}
	return "", false
}

// Event is a generic interface for any type of event
type Event interface{}

{'fraction_non_alphanumeric': 0.11348005502063274, 'fraction_numerical': 0.0034387895460797797, 'mean_word_length': 3.5754716981132075, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3660285', 'n_tokens_mistral': 491, 'n_tokens_neox': 463, 'n_words': 157}