go-dnp3 is a Go library for parsing and encoding DNP3 (Distributed Network Protocol) frames.
- Parsing: Use
FromBytes([]byte)to parse raw byte slices into structured DNP3 objects. - Encoding: Use
ToBytes()to serialize structs back into bytes. This automatically handles length calculations and inserts CRCs on the fly. - Inspection: Use
String()to generate human-readable, indented string representations of packets (excluds reserved fields and CRCs). - Serialization: Full support for
json.Marshal()to convert packets into machine-friendly JSON formats.
See example.go
Run make setup to install development tools used by this repository.
Data for tests is sourced from opendnp3 conformance reports
Run make test to run basic tests.
Pass a full PCAP file using the -args option -pcaps=comma.pcap,delimited.pcap,list.pcap.
go test ./dnp3 -v -args -pcaps=my-custom.pcapView the string and json outputs of test cases using the -args flag -print-string and -print-json.
go test ./dnp3 -args -printgolangci-lint is used for lint and format checking. Run make lint to check for errors, and make fix to try to automatically fix linting or formatting errors.
Based on Wireshark's parser and publicly available documents (such as this validation guide), as access to the official DNP3 specification is restricted.