forked from drslump/Protobuf-PHP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include tests for encoding/decoding extended fields
- Loading branch information
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
FIRSTSECOND |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
// DO NOT EDIT! Generated by Protobuf-PHP protoc plugin @package_version@ | ||
// Source: extension.proto | ||
// Date: 2012-09-19 15:03:23 | ||
|
||
namespace tests { | ||
|
||
class ExtA extends \DrSlump\Protobuf\Message { | ||
|
||
/** @var string */ | ||
public $first = null; | ||
|
||
|
||
/** @var \Closure[] */ | ||
protected static $__extensions = array(); | ||
|
||
public static function descriptor() | ||
{ | ||
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'tests.ExtA'); | ||
|
||
// OPTIONAL STRING first = 1 | ||
$f = new \DrSlump\Protobuf\Field(); | ||
$f->number = 1; | ||
$f->name = "first"; | ||
$f->type = \DrSlump\Protobuf::TYPE_STRING; | ||
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; | ||
$descriptor->addField($f); | ||
|
||
foreach (self::$__extensions as $cb) { | ||
$descriptor->addField($cb(), true); | ||
} | ||
|
||
return $descriptor; | ||
} | ||
|
||
/** | ||
* Check if <first> has a value | ||
* | ||
* @return boolean | ||
*/ | ||
public function hasFirst(){ | ||
return $this->_has(1); | ||
} | ||
|
||
/** | ||
* Clear <first> value | ||
* | ||
* @return \tests\ExtA | ||
*/ | ||
public function clearFirst(){ | ||
return $this->_clear(1); | ||
} | ||
|
||
/** | ||
* Get <first> value | ||
* | ||
* @return string | ||
*/ | ||
public function getFirst(){ | ||
return $this->_get(1); | ||
} | ||
|
||
/** | ||
* Set <first> value | ||
* | ||
* @param string $value | ||
* @return \tests\ExtA | ||
*/ | ||
public function setFirst( $value){ | ||
return $this->_set(1, $value); | ||
} | ||
} | ||
} | ||
|
||
namespace tests { | ||
|
||
class ExtB extends \DrSlump\Protobuf\Message { | ||
|
||
|
||
/** @var \Closure[] */ | ||
protected static $__extensions = array(); | ||
|
||
public static function descriptor() | ||
{ | ||
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, 'tests.ExtB'); | ||
|
||
foreach (self::$__extensions as $cb) { | ||
$descriptor->addField($cb(), true); | ||
} | ||
|
||
return $descriptor; | ||
} | ||
} | ||
} | ||
|
||
namespace { | ||
\tests\ExtA::extension(function(){ | ||
// OPTIONAL STRING tests\ExtB\second = 2 | ||
$f = new \DrSlump\Protobuf\Field(); | ||
$f->number = 2; | ||
$f->name = "tests\ExtB\second"; | ||
$f->type = \DrSlump\Protobuf::TYPE_STRING; | ||
$f->rule = \DrSlump\Protobuf::RULE_OPTIONAL; | ||
return $f; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package tests; | ||
|
||
message ExtA { | ||
optional string first = 1; | ||
extensions 2 to 3; | ||
} | ||
|
||
message ExtB { | ||
extend ExtA { | ||
optional string second = 2; | ||
} | ||
} |