partikus / protobuf-encoder
Installs: 7
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=5.5.9
- protobuf-php/google-protobuf-proto: dev-master
- protobuf-php/protobuf: dev-master
- protobuf-php/protobuf-plugin: dev-master
Requires (Dev)
- phpmetrics/phpmetrics: ~1.9
- phpunit/phpunit: ~4.0|~5.0
- squizlabs/php_codesniffer: ~2.7
- symfony/property-access: ~3.0
This package is auto-updated.
Last update: 2024-11-05 19:32:52 UTC
README
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.
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);