Files
akvorado/inlet/flow/decoder/tests.go
Vincent Bernat c6a9319b57 common/schema: turns into a component
This is a first step to make it accept configuration. Most of the
changes are quite trivial, but I also ran into some difficulties with
query columns and filters. They need the schema for parsing, but parsing
happens before dependencies are instantiated (and even if it was not the
case, parsing is stateless). Therefore, I have added a `Validate()`
method that must be called after instantiation. Various bits `panic()`
if not validated to ensure we catch all cases.

The alternative to make the component manages a global state would have
been simpler but it would break once we add the ability to add or
disable columns.
2023-01-18 12:22:10 +01:00

37 lines
988 B
Go

// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
//go:build !release
package decoder
import (
"net/netip"
"akvorado/common/schema"
)
// DummyDecoder is a simple decoder producing flows from random data.
// The payload is copied in IfDescription
type DummyDecoder struct {
Schema *schema.Component
}
// Decode returns uninteresting flow messages.
func (dc *DummyDecoder) Decode(in RawFlow) []*schema.FlowMessage {
exporterAddress, _ := netip.AddrFromSlice(in.Source.To16())
f := &schema.FlowMessage{
TimeReceived: uint64(in.TimeReceived.UTC().Unix()),
ExporterAddress: exporterAddress,
}
dc.Schema.ProtobufAppendVarint(f, schema.ColumnBytes, uint64(len(in.Payload)))
dc.Schema.ProtobufAppendVarint(f, schema.ColumnPackets, 1)
dc.Schema.ProtobufAppendBytes(f, schema.ColumnInIfDescription, in.Payload)
return []*schema.FlowMessage{f}
}
// Name returns the original name.
func (dc *DummyDecoder) Name() string {
return "dummy"
}