Download the PHP package thesis/protobuf without Composer

On this page you can find all versions of the php package thesis/protobuf. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package protobuf

Native PHP protobuf implementation

Installation

Usage

First of all, you should remember that the intended way to use this library is through the 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:

Encoding

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

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

By default, simple InMemoryPsr16Cache implementation will be used.

Now we are ready to encode the message:

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 protocol.

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:

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.

And now you are ready to decode the message:

Required fields

Reflector::map() maps missing fields using property defaults when they exist. If a property is non-nullable and has no default value, it is treated as required.

When one or more required properties are missing, decoding fails with Thesis\Protobuf\Reflection\Exception\MappingError. The exception contains all reasons in ->reasons (each reason is typically PropertyRequired).

This behavior is aligned with other protobuf implementations/plugins: messages missing required fields are treated as invalid during decode.

A field is considered required when either:

Both Encoder::encode() and Decoder::decode() throw Thesis\Protobuf\ProtobufException. Domain protobuf exceptions are preserved and are not wrapped into generic runtime errors.

Unknown fields

When a protobuf message is decoded, it may contain fields that are not defined in the target class. This happens when the sender uses a newer version of the schema, but the receiver has not been updated yet.

By default, unknown fields are silently skipped during decoding. However, you can configure the Decoder to capture them, which is useful for logging, debugging, or forwarding messages without data loss.

Storing unknown fields in memory

The UnknownFields handler stores unknown fields in a WeakMap attached to the decoded object. Once the object is garbage collected, the unknown fields are automatically cleaned up.

Each decoded object tracks its own unknown fields independently. If CreateUserRequest has a nested message with unknown fields, you can inspect them separately:

Using a callback

The UnknownFieldsCallback handler calls a user-defined function each time unknown fields are detected. This is convenient for logging without keeping the data in memory:

Custom handler

You can implement the UnknownFields\Handler interface to define your own strategy:


All versions of protobuf with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
ext-bcmath Version *
psr/simple-cache Version ^3.0
thesis/endian Version ^0.3.3
thesis/varint Version ^0.2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package thesis/protobuf contains the following files

Loading the files please wait ...