A lightweight message codegen tool — a simple alternative to Protocol Buffers for C++.
libyang reads an XML message schema and generates C++ structs with tag-based Marshal / Unmarshal helpers. Field tags enable forward/backward compatibility across versions: unknown tags are skipped on decode, and missing fields stay at defaults.
The generator is a pure Go CLI (no external scripting runtime). Generated code depends only on the bundled header yang.h.
Download a prebuilt binary from the Releases page, or build from source:
git clone https://github.com/esrrhs/libyang.git
cd libyang
go build -ldflags="-s -w" -o libyang .Docker:
docker pull esrrhs/libyang- Edit
sample.xml(or your own schema) to define enums and structs. - Generate the header:
./libyang -xml sample.xml -out sample.h
# or
./libyang sample.xml sample.h
# or
./run.sh- Include
yang.hand the generated header in your C++ project.
Show version:
./libyang -version<result>
<enum name="MsgID" comment="message ids">
<member name="CS_REQ_LOGIN" type="1" comment="login request"/>
</enum>
<struct name="CSReqLogin" comment="login request">
<member name="Acc" type="char" length="ACC_LEN" comment="account" tag="1"/>
<member name="Pwd" type="char" length="PWD_LEN" comment="password" tag="2"/>
</struct>
</result>Supported member shapes:
- Scalar numeric types (
uint32_t,float, …) and nested structs - Fixed-length
charstrings (type="char"+length) - Arrays with a runtime count field (
length+ref) - Tagged unions (
structwithtype="union", members userefas the case enum)
./pack.shCross-platform archives are written to pack/ (binary plus yang.h, sample.xml, docs). The Release workflow watches version.go: when its version string changes on master (and the tag does not exist yet), CI runs ./pack.sh and publishes a GitHub Release.
MIT — see LICENSE.