Skip to content
esrrhsPublic

About

Lightweight XML-to-C++ message codegen with tag-based Marshal/Unmarshal (simple protobuf alternative).

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Repository files navigation

libyang

A lightweight message codegen tool — a simple alternative to Protocol Buffers for C++.

English | Chinese


Overview

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.

Install

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

Usage

  1. Edit sample.xml (or your own schema) to define enums and structs.
  2. Generate the header:
./libyang -xml sample.xml -out sample.h
# or
./libyang sample.xml sample.h
# or
./run.sh
  1. Include yang.h and the generated header in your C++ project.

Show version:

./libyang -version

Schema sketch

<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 char strings (type="char" + length)
  • Arrays with a runtime count field (length + ref)
  • Tagged unions (struct with type="union", members use ref as the case enum)

Build release packages

./pack.sh

Cross-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.

License

MIT — see LICENSE.

About

Lightweight XML-to-C++ message codegen with tag-based Marshal/Unmarshal (simple protobuf alternative).

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages