Categorygithub.com/peterrk/protocache-go
modulepackage
0.0.0-20241111034506-479287c87a3a
Repository: https://github.com/peterrk/protocache-go.git
Documentation: pkg.go.dev

# README

ProtoCache Go

Alternative flat binary format for Protobuf schema. It' works like FlatBuffers, but it's usually smaller and surpports map. Flat means no deserialization overhead. A benchmark shows the Protobuf has considerable deserialization overhead and significant reflection overhead. FlatBuffers is fast but wastes space. ProtoCache takes balance of data size and read speed, so it's useful in data caching.

Data SizeDecode + TraverseDecode + Traverse(reflection)
Protobuf574B11451ns25458ns
vtprotobuf574B5029ns19907ns
ProtoCache780B1121ns2266ns
FlatBuffers1296B2191nsNo Go Api

See detail in C++ version.

Code Gen

protoc --pcgo_out=. test.proto

A protobuf compiler plugin called protoc-gen-pcgo is available to generate Go file. The generated file is short and human friendly. Don't mind to edit it if nessasery.

Basic APIs

raw, err := protocache.Serialize(pbMessage)
assert(t, err == nil)

root := pc.AS_Main(raw)
assert(t, root.IsValid())

Serializing a protobuf message with protocache.Serialize is the only way to create protocache binary at present. It's easy to access by wrapping the data with generated code.

Reflection

std::string err;
raw, err := os.ReadFile("test.proto")
assert(t, err == nil)

proto, err := compiler.ParseProto(raw) //CGO
assert(t, err == nil)

var pool reflect.DescriptorPool
assert(t, pool.Register(proto))

root := pool.Find("test.Main")
assert(t, root != nil)

field := root.Lookup("f64")
assert(t, field != nil)

The reflection apis are simliar to C++ version. An example can be found in the test. CGO is needed to parse schema.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author