None of the repo, the tool, nor the repo owner is affiliated with, or sponsored or authorized by, Google or its affiliates.
Protocol Buffers (a.k.a., protobuf) are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. For more information, please check the original repository at https://github.com/protocolbuffers/protobuf.
This repository provides a Unity package that utilizes my forked version of Protocol Buffers, incorporating several optimizations.
- Unity >= 2021.3.
- Mono Cecil >= 1.10.1.
Faster string parsing by defining GOOGLE_PROTOBUF_SUPPORT_FAST_STRING
.
This package provides a thread-safe object pool for Protobuf Messages.
-
Usage 1
var msg = ExampleMessage.NewFromPool(); // ... msg.Dispose(); // recycle to pool
-
Usage 2
var msg = ExampleMessage.Parser.ParseFrom(data); // ... msg.Dispose(); // recycle to pool
The protoc that supports this feature is available here: https://github.com/stalomeow/protobuf/tree/unity; simply compile it according to the documentation, and you'll be able to use it.
-
DO NOT use
foreach
on a Repeated/Map Field because it will cause extra GC allocation. Simply usefor
instead (if possible). -
DO use
MessageParser<T>.ParseFrom(ReadOnlySpan<byte> data)
MessageParser<T>.ParseFrom(ReadOnlySequence<byte> data)
MessageExtensions.WriteTo(this IMessage message, Span<byte> output)
when deserializing/serializing Messages because they do not cause extra GC allocation.
-
Others can be found in Protobuf's Official Document.
-
To be continued...
The codes in the Runtime/Core folder are licensed under Google's LICENSE, and the rest are licensed under the MIT LICENSE.