locka99 / opcua

A client and server implementation of the OPC UA specification written in Rust
Mozilla Public License 2.0
475 stars 128 forks source link

Reimplement status codes by hand #321

Open einarmo opened 2 months ago

einarmo commented 2 months ago

Instead of using bitflags, this reimplements the status code struct by hand. Using bitflags has some unfortunate side effects in that it makes the debug implementation completely wrong. Instead of logging the name of the status code, bitflags usually produces a weird mix of other status codes, probably because the different status codes overlap. This is very inconvenient when debugging, as you will often just unwrap errors.

Instead of using a JS script for codegen, this generates the status code implementation from the CSV inline. While putting the CSV in rust code is slightly inconvenient, it does mean that the code is more self-contained. Implementation wise it is a pair of not-actually-that-hairy macros (no recursion, which is what tends to make these macros hard to work with).

I tried to do this without too many breaking changes, and the effect on the rest of the codebase is minimal. The implementation is now all in a single file, which is manageable because the generated code isn't committed. There are some changes to note: