AI-Generated Go Serialization: Zero Boilerplate, Maximum Speed
<p>I wanted to share a quick story about a weekend experiment.</p> <p>There is a library called <a href="https://github.com/ymz-ncnk/mok" rel="noopener noreferrer">mok</a> that lacks a code generator, so every time you want to mock an interface, it requires you to write all the boilerplate yourself. It's simple but tedious work. I usually just offload it to an AI agent, and with a small example, it completes this task exceptionally well.</p> <p>This got me thinking - could AI handle something more complex, like writing serialization code? If it could, we'd basically get the best of both worlds: the raw speed of generated code, with the same simplicity you get from reflection-based libraries.</p> <p>But is it safe to trust AI with something as sensitive as serialization logic? With all its
I wanted to share a quick story about a weekend experiment.
There is a library called mok that lacks a code generator, so every time you want to mock an interface, it requires you to write all the boilerplate yourself. It's simple but tedious work. I usually just offload it to an AI agent, and with a small example, it completes this task exceptionally well.
This got me thinking - could AI handle something more complex, like writing serialization code? If it could, we'd basically get the best of both worlds: the raw speed of generated code, with the same simplicity you get from reflection-based libraries.
But is it safe to trust AI with something as sensitive as serialization logic? With all its non-determinism and unpredictable behavior, the answer is more likely a hard "No", unless we enforce two strict requirements:
-
Provide a solid foundation — give the AI a robust library to work with.
-
Test everything — all AI-generated code must be rigorously tested.
With those guidelines in place, I decided to give it a shot. After a few late nights, and honestly, way more fun than expected, I ended up building mus-skill: an AI skill for generating MUS serialization code.
At its core, the skill is just a set of rules for combining the serialization primitives provided by the mus and mus-stream libraries. In addition to the code itself, it also generates the accompanying tests so you can be sure everything works correctly.
Because the code looks exactly like the output of a traditional code generator you can expect from it the same high-performance.
| NAME | NS/OP | B/SIZE | B/OP | ALLOCS/OP | |--------------|----------|--------|---------|-----------| | mus | 102.90 | 58.00 | 48.00 | 1 | | protobuf | 531.70 | 69.00 | 271.00 | 4 | | json | 2779.00 | 150.00 | 600.00 | 9 || NAME | NS/OP | B/SIZE | B/OP | ALLOCS/OP | |--------------|----------|--------|---------|-----------| | mus | 102.90 | 58.00 | 48.00 | 1 | | protobuf | 531.70 | 69.00 | 271.00 | 4 | | json | 2779.00 | 150.00 | 600.00 | 9 |Full benchmarks https://github.com/ymz-ncnk/go-serialization-benchmarks`
Enter fullscreen mode
Exit fullscreen mode
This approach even works flawlessly on deeply nested, complex types (where AI usually hallucinates), such as:
// mus:vl = ValidateLen // mus:elemVl = ValidateComplexMapValue type ComplexMap map[string]map[*[]int][][]float32// mus:vl = ValidateLen // mus:elemVl = ValidateComplexMapValue type ComplexMap map[string]map[*[]int][][]float32Enter fullscreen mode
Exit fullscreen mode
And supports user hints, so you can easily customize the generated code to fit your exact needs (like specifying custom validators).
Getting started is simple. Just clone this repository into your project's agent directory (e.g., .agents/skills). Or, even easier, install it using the skills CLI tool:
npx skills add github.com/mus-format/mus-skill-go
Enter fullscreen mode
Exit fullscreen mode
Once installed, simply give your AI agent a prompt like this:
Generate MUS serializers for the types found in the .go file.
Enter fullscreen mode
Exit fullscreen mode
The result? Two newly generated files: mus.ai.gen.go and mus.ai.gen_test.go. As always, just be sure to double-check that the generated tests actually cover all your edge cases.
Have you ever tried a similar approach? I'd love to hear how it went for you!
DEV Community
https://dev.to/ymz-ncnk/ai-generated-go-serialization-zero-boilerplate-maximum-speed-49f8Sign in to highlight and annotate this article

Conversation starters
Daily AI Digest
Get the top 5 AI stories delivered to your inbox every morning.
More about
benchmarkcompanyinterfaceAI #162: Visions of Mythos
Anthropic had some problem with leaks this week. We learned that they are sitting on a new larger-than-Opus AI model, Mythos, that they believe offers a step change in cyber capabilities. We also got a full leak of the source for Claude Code. Oh, and Axios was compromised, on the heels of LiteLLM. This looks to be getting a lot more common. Defense beats offense in most cases, but offense is getting a lot more shots on goal than it used to. The AI Doc: Or How I Became an Aplocayloptimist came out this week. I gave it 4.5/5 stars, and I think the world would be better off if more people saw it. I am not generally a fan of documentary movies, but this is probably my new favorite, replacing The King of Kong: A Fistful of Quarters. There was also the usual background hum of quite a lot of thin

Noom acquires compounding pharmacy to expand beyond weight loss
Weight-loss company Noom has acquired 503A pharmacy Tailor Made Compounding, which Noom said will allow it to expand its behavior change programs and move beyond weight health. Tailor Made provides sterile and non-sterile compounding through its pharmacy practice focused on aging. It offers compounded drugs, including hormone replacement therapies and peptide therapies, as well as pharmacist-formulated supplements and cosmetics.
Knowledge Map
Connected Articles — Knowledge Graph
This article is connected to other articles through shared AI topics and tags.
More in Products
HNL Lab s digital pathology platform enables faster results and more
HNL Lab Medicine is the laboratory partner affiliated with Lehigh Valley Health Network, part of Jefferson Health, which includes 14 hospital campuses and 981 licensed acute beds across its flagship campuses. Since digitizing its anatomic pathology practice, HNL has enabled remote case review and seamless case sharing across its large network. THE CHALLENGE Before adopting the digital pathology platform, the lab's primary challenge was managing an increasingly complex workflow across an expanding network.


Discussion
Sign in to join the discussion
No comments yet — be the first to share your thoughts!