Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol Buffer for PHP [closed]

What are the avaliable libraries for using protobuf in PHP?

like image 420
oluies Avatar asked Jun 03 '11 08:06

oluies


People also ask

What is Protobuf PHP?

Protobuf for PHP is an implementation of Google's Protocol Buffers for the PHP language, supporting its binary data serialization and including a protoc plugin to generate PHP classes from . proto files.

What is the difference between Proto2 and Proto3?

Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.

Should I use Proto2 and Proto3?

Proto2: supports optional natively, the wrapper types were recommended but should be avoided in new applications. Proto3: originally did not support presence tracking for primitive fields. As of 2020, proto3 supports both optional fields which have has_foo() methods and "singular" fields, which do not.

Is Protobuf compressed?

Protobuf achieves good compression ratios through varint encoding. It might not be necessary to add an extra layer of compression in most cases.


2 Answers

There is also https://github.com/drslump/Protobuf-PHP

Last updated December 2013.

Requirements (from the Github page):

  • PHP 5.3
  • Pear's Console_CommandLine (for the protoc wrapper tool)
  • Google's protoc compiler version 2.3 or above
  • GMP or BC Math extensions ¹

    ¹ Only needed for negative values in int32, int64 or fixed64 types. See the known issues section.

like image 20
j-a Avatar answered Oct 12 '22 11:10

j-a


Protocol_Buffer_for_PHP

Last updated in May 2009

Implementing the Google "Protocol Buffer" for PHP, include parsing ...

Issue list: http://code.google.com/p/pb4php/issues/list

Protobuf-PHP

Last updated in April 2011

Protobuf for PHP is an implementation of Google's Protocol Buffers for the PHP language, supporting its binary data serialization and including a protoc plugin to generate PHP classes from .proto files.

Great effort has been put into generating PHP files that include all sort of type hints to aide IDE's with autocompletion. Therefore, it can not only be used to communicate with Protocol Buffers services but also as a generation tool for data objects no matter what the final serialization is.

Example:

$person = new Tutorial\Person();
$person->name = 'DrSlump';
$person->setId(12);

$book = new Tutorial\AddressBook();
$book->addPerson($person);

// Use default codec
$data = $book->serialize();

// Use custom codec
$codec = new \DrSlump\Protobuf\Codec\Binary();
$data = $codec->encode($book);
// ... or ...
$data = $book->serialize($codec);

protoc-gen-php

Last updated December 05, 2010

This is a PHP Google Protocol Buffer Generator Plugin for protoc. It generates PHP code from a .proto file.

like image 159
3 revs Avatar answered Oct 12 '22 11:10

3 revs