I

I built a JSON-RPC library for Zig with compile time reflection

Hacker News

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 card

Actual performance

13points
2comments
Made the leaderboard

Launch Intel predictions

Analyze your own launch →
Product HuntOn track for Day 1 leaderboard · Strong signals: mac · Missing: agents, macos, agent
55%55% predicted probability of success on Product Hunt, based on ML models trained on real launch data.
best fitHighest predicted score across all platforms for this description.
Indie HackersFits the IH revenue-focused audience · Strong signals: para · Missing: supports, reddit linkedin, podcasting
54%54% predicted probability of success on Indie Hackers, based on ML models trained on real launch data.
TrustMRRFits verified-revenue profile · Strong signals: para · Missing: mobile apps, ios, personal
51%51% predicted probability of success on TrustMRR, based on ML models trained on real launch data.
AppSumoMay struggle as an AppSumo deal · Strong signals: interface · Missing: plus, platform, intuitive
49%49% predicted probability of success on AppSumo, based on ML models trained on real launch data.
Hacker NewsMay not resonate with HN audience · Strong signals: io · Missing: https docs, excited, just released
38%38% predicted probability of success on Hacker News, based on ML models trained on real launch data.
nativeThis product was originally launched on this platform.
Acquire.comPre-revenue stage for this audience · Missing: arr, mrr, revenue
15%15% predicted probability of success on Acquire.com, based on ML models trained on real launch data.
BetaListMay not resonate with beta-testers · Missing: web3, chat, crypto
0%0% predicted probability of success on BetaList, based on ML models trained on real launch data.

Incorrect prediction on native model

Similar products

Ne
New C++ compile-time enum reflection library42%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

New C++ compile-time enum reflection library

Hacker News2
Co
Compile Time Reflection in C++ for Serialization Functions38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Compile Time Reflection in C++ for Serialization Functions

Hacker News2
Co
Compile Time Reflection in C++ for Serialization Functions38%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Compile Time Reflection in C++ for Serialization Functions

Hacker News3
Te
Teleport.py - Clever serialization library on top of JSON33%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Teleport.py - Clever serialization library on top of JSON

Hacker News2
Co
Conjure_enum – a C++20 enum and typename reflection Library32%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Conjure_enum – a C++20 enum and typename reflection Library

Hacker News2
JS
JSON-to-Go, Built with Go and QML53%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

JSON-to-Go, Built with Go and QML

Hacker News4
Mi
Mirror_hash – Hash anything with C++ reflection33%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Mirror_hash – Hash anything with C++ reflection

Hacker News3
Re
ReflectableEnum – Reflection for enumerations in Objective-C25%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

ReflectableEnum – Reflection for enumerations in Objective-C

Hacker News1
A
A fast JSON library for Go57%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

A fast JSON library for Go

Hacker News119
El
Elixir Library for Chicago Metra JSON API72%Launch Intel prediction score: how likely this product is to succeed on its source platform, based on its name, tagline, and description.

Elixir Library for Chicago Metra JSON API

Hacker News2