refactor: v2 (#150)

This commit is contained in:
Louis
2023-08-09 19:47:20 -07:00
committed by GitHub
parent 1298b9408d
commit ae56e41786
75 changed files with 4905 additions and 4828 deletions

16
decoders/sflow/format.go Normal file
View File

@@ -0,0 +1,16 @@
package sflow
import (
"encoding/json"
"fmt"
"net/netip"
)
func (p *Packet) MarshalJSON() ([]byte, error) {
return json.Marshal(*p) // this is a trick to avoid having the JSON marshaller defaults to MarshalText
}
func (p *Packet) MarshalText() ([]byte, error) {
agentIP, _ := netip.AddrFromSlice(p.AgentIP)
return []byte(fmt.Sprintf("sFlow%d agent:%s seq:%d count:%d", p.Version, agentIP.String(), p.SequenceNumber, p.SamplesCount)), nil
}