C3 Protobuf
  • C3 95.5%
  • Go 3.5%
  • Makefile 1%
Find a file
2026-05-14 11:58:55 +02:00
cmd feat: generator 2026-05-14 11:58:55 +02:00
example chore: iterop example 2026-05-11 17:55:53 +02:00
src feat: generator 2026-05-14 11:58:55 +02:00
test feat: generator 2026-05-14 11:58:55 +02:00
.gitignore first commit 2026-05-11 11:45:40 +02:00
LICENSE first commit 2026-05-11 11:45:40 +02:00
Makefile feat: generator 2026-05-14 11:58:55 +02:00
project.json feat: generator 2026-05-14 11:58:55 +02:00
README.md feat: generator 2026-05-14 11:58:55 +02:00

C3 Protobuf

A lightweight, native Protocol Buffers (proto3) implementation for the C3 programming language.

Features

  • Proto3 Support: Adheres to proto3 semantics (e.g., default values omitted from wire).
  • Core Types: Supports Varints, 32/64-bit fixed types, strings, bytes, and nested messages.
  • Packed Fields: Efficient encoding/decoding for repeated primitive fields.
  • Memory Efficient: Uses growable buffers with manual memory management or temporary pools.
  • Cross-Language Compatibility: Verified interoperability with Go using the official google.golang.org/protobuf package.
  • Code Generator: Compile-time proto-to-C3 code generation via $exec.

Project Structure

  • src/: Core implementation (buffer, wire, encoder, decoder, message).
  • cmd/proto_gen.c3: Proto file parser and C3 code generator.
  • test/: Unit test suite.
  • example/: Cross-language example (C3 <-> Go). The Go implementation uses the official protowire package for ground-truth wire format validation.

Building & Testing

Build the library:

make build

Run tests:

make test

Run the example:

make -C example run

Build the proto generator:

c3c build proto_gen

Run the generator standalone:

bin/proto_gen path/to/file.proto  generated.c3

What Gets Generated

For each proto message:

  • A C3 struct with proto-to-C3 type mapping
  • encode(WriteBuffer* buf) method
  • decode(char[] data) method

For each proto enum:

  • A C3 constdef with integer values

For oneof fields:

  • A tag constdef enum
  • Pointer fields for each variant
  • Tag field to track which variant is set

Proto → C3 Type Mapping

Proto Type C3 Type
int32, sint32, sfixed32 int
int64, sint64, sfixed64 long
uint32, fixed32 uint
uint64, fixed64 ulong
float float
double double
bool bool
string String
bytes char[]
repeated T T[]
optional T T*
Custom message struct (inline)

Limitations

  • repeated field decode currently emits comments for array append (C3 arrays are fixed-size)
  • map types are not supported
  • service definitions are skipped
  • Nested messages within other messages are parsed but generate top-level structs

License

MIT