I built a JSON-RPC library for Zig with compile time reflection
I built a JSON-RPC library for Zig with compile time reflection
Doing dynamic dispatching in a strict static typing language is hard. Something as simple as, map.put("add", add); map.put("hello", hello); fn add(a: i32, b: i32) i32 { return a + b; } fn hello() []const u8 { return "Hello World"; } is impossible because the value type of key/value of the map needs to be the same but all the function types are different. Calling functions with different number of parameters, different parameter types, and different return type dynamically is difficult. Other languages either use dynamic typing, runtime reflection, macro, or passing in one big generic parameter and let the function figure it out. In ZigJR, I use Zig's comptime feature to do compile time reflection to figure out a function's parameter types, return types, and return errors. I package them up into a specific call object and use the interface pattern to produce a uniformly typed object to be put into the map. It's not easy but doable. [1] [1] https://github.com/williamw520/zigjr/blob/master/src/rpc/jso...
Share cardActual performance
Launch Intel predictions
Analyze your own launch →Incorrect prediction on native model
Similar products
New C++ compile-time enum reflection library
Compile Time Reflection in C++ for Serialization Functions
Compile Time Reflection in C++ for Serialization Functions
Teleport.py - Clever serialization library on top of JSON
Conjure_enum – a C++20 enum and typename reflection Library
JSON-to-Go, Built with Go and QML
Mirror_hash – Hash anything with C++ reflection
ReflectableEnum – Reflection for enumerations in Objective-C
A fast JSON library for Go
Elixir Library for Chicago Metra JSON API