Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/partikus/php-protobuf-encoder
PHP Protbuf Encode library.
https://github.com/partikus/php-protobuf-encoder
encoder library php php7 protobuf protobuf3
Last synced: about 1 month ago
JSON representation
PHP Protbuf Encode library.
- Host: GitHub
- URL: https://github.com/partikus/php-protobuf-encoder
- Owner: partikus
- License: mit
- Created: 2017-02-25T20:45:02.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-09-05T06:42:56.000Z (over 6 years ago)
- Last Synced: 2024-04-22T04:13:49.551Z (9 months ago)
- Topics: encoder, library, php, php7, protobuf, protobuf3
- Language: PHP
- Homepage:
- Size: 9.77 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
PHP Protbuf Encode
==================[![Build Status](https://travis-ci.org/partikus/php-protobuf-encoder.svg?branch=master)](https://travis-ci.org/partikus/php-protobuf-encoder)
Simple PHP library that allows you encode Protobuf Message to byte code. Additionally this library allows to encode/decode massage into single message.
The implementation is based on [this article](http://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers).
## How to use it?### Prepare Proto Message file
```
syntax = "proto3";package Your.Namespace;
message DummyMessage {
string Title = 1;
string Description = 2;
string CreatedAt = 3;
string UpdatedAt = 4;
}```
### Generate PHP files
```
vendor/bin/protobuf --include-descriptors -i . -o src/ DummyMessage.proto
```### Create PHP objects
```
$dummyMessage = Your\Namespace\DummyMessage::fromArray([
'Title' => 'Test 123',
'Description' => 'Description from the text',
'CreatedAt' => '2016-12-12 12:00:00',
'UpdatedAt' => '2016-12-12 13:00:00',
]);$encoder = new ClearCode\Protobuf\ByteEncoder();
/** @var \Protobuf\Stream $stream */
$stream = $encoder->encode($dummyMessage);
file_put_contents(__DIR__ . '/dummyMessage.pb.bin', $stream);
```