# Serialization Library PTOT: Put this over there

**URL:** <https://ziggit.dev/t/serialization-library-ptot-put-this-over-there/17585>\
**Category:** Showcase\
**Tags:** handmade\
**Created:** [September 12, 2026, 8:50pm UTC](https://ziggit.dev/t/serialization-library-ptot-put-this-over-there/17585 "2026-09-12T20:50:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![biom4st3r](https://ziggit.dev/user_avatar/ziggit.dev/biom4st3r/32/4342_2.png) [@biom4st3r](https://ziggit.dev/u/biom4st3r)\
**Post date:** [September 12, 2026, 8:50pm UTC](https://ziggit.dev/t/serialization-library-ptot-put-this-over-there/17585/1 "2026-09-12T20:50:37Z")

</div>

# [PTOT: Put this over there](https://codeberg.org/biom4st3r/ptot)

* * *

This is a general purpose serialization library for Zig types. I created this over time for my in progress mmo and then separated it out into it’s own library. Hopefully, this can be of use to you as well.

Features:

- Types must be added to your Lexicon for them to be serialized. I didn’t want to accidentally sent data to the client that was unnecessary and that I didn’t realize I was sending
- Allocation is only required when a type contains a pointer. This is assert-able via `Lexicon.assert_no_allocation_required`. it even gives a nice little crumble trail for where the allocation is required.
- You can register manually created `Codecs` to your Lexicon for fine control over how the data is serialized.  
For Example:

```zig
pub const StrRefCodec = struct {
    // StrRef is a enum(u32) into an intern pool. If I send a StrRef to the client I expect the receiving field to be a []const u8, so the codec isn't called client side
    pub fn serialize(Lexicon: type, self: common.StrRef, w: *std.Io.Writer) C.SError!void {
        _ = @import("build_options").role == .Server or unreachable;
        try Lexicon.serialize([]const u8, self.slice(), w);
    }
    pub fn deserialize(Lexicon: type, _: *std.Io.Reader, _: std.mem.Allocator) C.DError!common.StrRef {
        unreachable;
    }
};

```

I recently added a `byte slice optimization`: If a type has a safe and stable memory layout it can be serialized as bytes in 1 `writeAll` call instead of generating more generic functions. In the future I want to support allocating to a type controlled Arena for simpler deallocation and a niche optimization for types that contain many optionals.

### Supported Zig versions

0.16.0
