C3 Protobuf
- C3 95.5%
- Go 3.5%
- Makefile 1%
| cmd | ||
| example | ||
| src | ||
| test | ||
| .gitignore | ||
| LICENSE | ||
| Makefile | ||
| project.json | ||
| README.md | ||
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/protobufpackage. - 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 officialprotowirepackage 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
structwith proto-to-C3 type mapping encode(WriteBuffer* buf)methoddecode(char[] data)method
For each proto enum:
- A C3
constdefwith integer values
For oneof fields:
- A tag
constdefenum - 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
repeatedfield decode currently emits comments for array append (C3 arrays are fixed-size)maptypes are not supportedservicedefinitions are skipped- Nested messages within other messages are parsed but generate top-level structs
License
MIT