Skip to content

Commit 9c66b0a

Browse files
committed
Added PoC of README
1 parent 7168a30 commit 9c66b0a

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.md

+42-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,46 @@ PHP Protbuf Encode
33

44
[![Build Status](https://travis-ci.org/partikus/php-protobuf-encoder.svg?branch=master)](https://travis-ci.org/partikus/php-protobuf-encoder)
55

6+
Simple PHP library that allows you encode Protobuf Message to byte code. Additionally this library allows to encode/decode massage into single message.
7+
The implementation is based on [this article](http://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers).
8+
9+
## How to use it?
10+
11+
### Prepare Proto Message file
12+
13+
```
14+
syntax = "proto3";
15+
16+
package Your.Namespace;
17+
18+
message DummyMessage {
19+
string Title = 1;
20+
string Description = 2;
21+
string CreatedAt = 3;
22+
string UpdatedAt = 4;
23+
}
24+
25+
```
26+
27+
### Generate PHP files
28+
29+
```
30+
vendor/bin/protobuf --include-descriptors -i . -o src/ DummyMessage.proto
31+
```
32+
33+
### Create PHP objects
34+
35+
```
36+
$dummyMessage = Your\Namespace\DummyMessage::fromArray([
37+
'Title' => 'Test 123',
38+
'Description' => 'Description from the text',
39+
'CreatedAt' => '2016-12-12 12:00:00',
40+
'UpdatedAt' => '2016-12-12 13:00:00',
41+
]);
42+
43+
$encoder = new ClearCode\Protobuf\ByteEncoder();
44+
/** @var \Protobuf\Stream $stream */
45+
$stream = $encoder->encode($dummyMessage);
46+
file_put_contents(__DIR__ . '/dummyMessage.pb.bin', $stream);
47+
```
648

7-
http://eli.thegreenplace.net/2011/08/02/length-prefix-framing-for-protocol-buffers

0 commit comments

Comments
 (0)