This is nmsgpcnt
. It contains code that counts NMSG protobuf payloads. It is
intended as an example of how to write C code to manually deserialize an NMSG
Google Protocol Buffer encoded container. It reads input from a binary NMSG
file and counts the number of NMSG containers and payloads. Originally
published in Google Protocol Buffer Deserialization The Hard Way.
In addition to the primary nmsgpcnt-fsi
program, two other reference
implementations of nmsgpcnt
are included. One built using the
protoc-c API, the other using the
nanopb API. To compile these tools you'll
need to install both packages.
nmsgpcnt
comes with three top-level source files containing the program code
to count NMSG containers payloads. While the FSI implementation is
self-contained, the other two examples require respective API code. It can be
confusing so here's a file manifest:
Makefile
: Simple non-autoconf'd MakefileREADME.md
: This filenmsgpcnt-fsi.c
Farsight Security Nmsg protobuf decodernmsgpcnt-npb.c
Nanopb Nmsg protobuf decodernmsgpcnt-ptc.c
Protoc-c Nmsg protobuf decodersrc/nmsg.pb-c.{c,h}
Protoc-c generated Nmsg interfacesrc/nmsg.pb.{c,h}
Nanopb Nmsg generated definitions and headersrc/nmsg.proto
Nmsg protobuf definitionssrc/pb.h
Nanopb low-level headersrc/pb_common.{c,h}
Nanopb common support functionssrc/pb_decode.{c,h}
Nanopb runtime library decoding routinestest.sh
Benchmarking test script
All of the nmsgpcnt
programs have the same calling convention:
$ nmsgpcnt-fsi
nmsgpcnt-npb parse an NMSG file and emit container/payload count
usage: ./nmsgpcnt-npb file.nmsg
For SIE / SRA customers you can easily generate a file to use via nmsgtool
.
$ nmsgtool -C ch202 -c 2000000 -w 202-2000000.nmsg
The included test.sh
script will invoke and time all three programs against
the specified input file:
$ ./test.sh 202-2000000.nmsg
Running nmsgpcnt-npb (nanopb) against 202-2000000.nmsg
containers: 720
payloads: 2000481
real 2.31
user 1.84
sys 0.47
Running nmsgpcnt-ptc (protoc-c) against 202-2000000.nmsg
containers: 720
payloads: 2000481
real 1.47
user 0.97
sys 0.49
Running nmsgpcnt-fsi (Farsight Security) against 202-2000000.nmsg
containers: 720
payloads: 2000481
real 0.59
user 0.15
sys 0.44