PHPackages                             thesis/protobuf - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. thesis/protobuf

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

thesis/protobuf
===============

A modern strictly typed full-featured serializer for Google's protocol buffers.

0.1.6(2mo ago)41.4k[1 issues](https://github.com/thesis-php/protobuf/issues)7MITPHPPHP ^8.4CI passing

Since Jan 3Pushed 1mo agoCompare

[ Source](https://github.com/thesis-php/protobuf)[ Packagist](https://packagist.org/packages/thesis/protobuf)[ Fund](https://www.tinkoff.ru/cf/5MqZQas2dk7)[ RSS](/packages/thesis-protobuf/feed)WikiDiscussions 0.1.x Synced 1mo ago

READMEChangelog (9)Dependencies (10)Versions (10)Used By (7)

Native PHP protobuf implementation
----------------------------------

[](#native-php-protobuf-implementation)

### Installation

[](#installation)

```
composer require thesis/protobuf
```

### Usage

[](#usage)

First of all, you should remember that the intended way to use this library is through the [protoc plugin](https://github.com/thesis-php/protoc-plugin), which you should use to generate PHP code from your proto schema. While it is possible to write such code manually, it is not recommended.

Although the library provides a low-level API for building other tools, such as reflection, it is recommended to use the `Encoder/Decoder` from this library. They use attributes from `Thesis\Protobuf\Reflection` to locate the necessary information, such as the field number and its type in protobuf.

Let's look at encoding and decoding using a simple protobuf message as an example:

```
use Thesis\Protobuf\Reflection;

final readonly class CreateUserRequest
{
    /**
     * @param list $roles
     */
    public function __construct(
        #[Reflection\Field(1, Reflection\Int32T::T)]
        public int $id = 0,
        #[Reflection\Field(2, Reflection\StringT::T)]
        public string $name = '',
        #[Reflection\Field(3, new Reflection\ListT(Reflection\StringT::T))]
        public array $roles = [],
    ) {}
}
```

#### Encoding

[](#encoding)

To encode such an object in protobuf format, you need to create an `Encoder` using the `Encoder\Builder`:

```
use Thesis\Protobuf\Encoder;

$encoder = Encoder\Builder::buildDefault();
```

Or using `PSR-16` cache implementation to cache the reflection:

```
use Thesis\Protobuf\Encoder;

$encoder = new Encoder\Builder()
    ->withCache(/** cache implementation */)
    ->build();
```

By default, simple `InMemoryPsr16Cache` implementation will be used.

Now we are ready to encode the message:

```
$encoder->encode(new CreateUserRequest(1, 'kafkiansky', ['developer']));
```

You will get a ready-to-use protobuf message that can be used to store in files, in queues (for example, messages in Kafka are often stored as protobuf messages for better compression), and, of course, for transmission over the network within the [gRPC](https://github.com/thesis-php/grpc) protocol.

#### Decoding

[](#decoding)

To decode a protobuf message into a class (and only into a class: enums cannot be a top-level type, but they can be part of message fields), use the `Decoder`. Creating it is just as simple as creating an `Encoder`:

```
use Thesis\Protobuf\Decoder;

$decoder = Decoder\Builder::buildDefault();
```

Since the `Decoder` also uses reflection, you can configure caching yourself or leave the default in-memory implementation, which is already efficient enough for long-running applications.

```
use Thesis\Protobuf\Decoder;

$decoder = new Decoder\Builder()
    ->withCache(/** cache implementation */)
    ->build();
```

And now you are ready to decode the message:

```
$request = $decoder->decode(/** protobuf buffer here */, CreateUserRequest::class);

echo $request->name;
```

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance84

Actively maintained with recent releases

Popularity25

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~9 days

Total

8

Last Release

73d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2552865?v=4)[Valentin Udaltsov](/maintainers/vudaltsov)[@vudaltsov](https://github.com/vudaltsov)

---

Top Contributors

[![kafkiansky](https://avatars.githubusercontent.com/u/37590388?v=4)](https://github.com/kafkiansky "kafkiansky (80 commits)")

---

Tags

protobufprotocol-buffers

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thesis-protobuf/health.svg)

```
[![Health](https://phpackages.com/badges/thesis-protobuf/health.svg)](https://phpackages.com/packages/thesis-protobuf)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[mck89/peast

Peast is PHP library that generates AST for JavaScript code

18934.7M29](/packages/mck89-peast)[ivopetkov/html5-dom-document-php

HTML5 DOMDocument PHP library (extends DOMDocument)

6031.4M49](/packages/ivopetkov-html5-dom-document-php)[json-mapper/json-mapper

Map JSON structures to PHP classes

2181.1M22](/packages/json-mapper-json-mapper)[tebru/gson-php

Gson for PHP: Convert PHP objects to and from json

152134.3k8](/packages/tebru-gson-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
