Mine is brokenly injecting some empty bytes in the encoding. Luckily I didn't make that the canonical encoding or I would be ashamed forever.
Have you looked at the nostrdb format?
Me and nostr:npub1acg6thl5psv62405rljzkj8spesceyfz2c32udakc2ak0dmvfeyse9p35c also talked about this at nostrasia. You can either make it compact (varints) with an encoding/decoding step or flat/aligned with zero copy. I chose flat for query performance.
I think nostr:npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6 also has one in his Go libraries somewhere.
Discussion
I am also not sure about mine which is why I’ve never wrote it up. I lack extensibility :(
I was going to just use flatbuffers but I couldn’t get the [[String]] tags encoder to work with swift.