Skip to content

Commit 3c3330b

Browse files
author
Trey Hyde
committed
bugfix() Make sure we read the photos from protoc until EOF
PHP silently changes the read size back down to some ini configured max. In this case, 1MB read size was being converted to 8k. Descriptors over 8k were silently dying. This use of fread was bad practice anyway.
1 parent dcc630d commit 3c3330b

File tree

5 files changed

+46
-24
lines changed

5 files changed

+46
-24
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
],
1515
"bin" : ["protoc-gen-php.bat", "protoc-gen-php.php"],
1616
"require" : {
17-
"php" : ">=5.3.0",
17+
"php" : ">=5.5.0",
1818
"ext-mbstring" : "*",
19-
"phpoption/phpoption": "1.4.0",
19+
"phpoption/phpoption": "1.4.*",
2020
"symfony/console" : "2.*"
2121
},
2222
"require-dev": {

library/DrSlump/Protobuf/Codec/Binary/Native.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -238,25 +238,25 @@ protected function assertWireType($wire, $type)
238238

239239
protected function getWireType($type, $default)
240240
{
241-
static $map = array(
242-
Protobuf\Protobuf::TYPE_INT32 => self::WIRE_VARINT,
243-
Protobuf\Protobuf::TYPE_INT64 => self::WIRE_VARINT,
244-
Protobuf\Protobuf::TYPE_UINT32 => self::WIRE_VARINT,
245-
Protobuf\Protobuf::TYPE_UINT64 => self::WIRE_VARINT,
246-
Protobuf\Protobuf::TYPE_SINT32 => self::WIRE_VARINT,
247-
Protobuf\Protobuf::TYPE_SINT64 => self::WIRE_VARINT,
248-
Protobuf\Protobuf::TYPE_BOOL => self::WIRE_VARINT,
249-
Protobuf\Protobuf::TYPE_ENUM => self::WIRE_VARINT,
250-
Protobuf\Protobuf::TYPE_FIXED64 => self::WIRE_FIXED64,
241+
static $map = [
242+
Protobuf\Protobuf::TYPE_INT32 => self::WIRE_VARINT,
243+
Protobuf\Protobuf::TYPE_INT64 => self::WIRE_VARINT,
244+
Protobuf\Protobuf::TYPE_UINT32 => self::WIRE_VARINT,
245+
Protobuf\Protobuf::TYPE_UINT64 => self::WIRE_VARINT,
246+
Protobuf\Protobuf::TYPE_SINT32 => self::WIRE_VARINT,
247+
Protobuf\Protobuf::TYPE_SINT64 => self::WIRE_VARINT,
248+
Protobuf\Protobuf::TYPE_BOOL => self::WIRE_VARINT,
249+
Protobuf\Protobuf::TYPE_ENUM => self::WIRE_VARINT,
250+
Protobuf\Protobuf::TYPE_FIXED64 => self::WIRE_FIXED64,
251251
Protobuf\Protobuf::TYPE_SFIXED64 => self::WIRE_FIXED64,
252-
Protobuf\Protobuf::TYPE_DOUBLE => self::WIRE_FIXED64,
253-
Protobuf\Protobuf::TYPE_STRING => self::WIRE_LENGTH,
254-
Protobuf\Protobuf::TYPE_BYTES => self::WIRE_LENGTH,
255-
Protobuf\Protobuf::TYPE_MESSAGE => self::WIRE_LENGTH,
256-
Protobuf\Protobuf::TYPE_FIXED32 => self::WIRE_FIXED32,
252+
Protobuf\Protobuf::TYPE_DOUBLE => self::WIRE_FIXED64,
253+
Protobuf\Protobuf::TYPE_STRING => self::WIRE_LENGTH,
254+
Protobuf\Protobuf::TYPE_BYTES => self::WIRE_LENGTH,
255+
Protobuf\Protobuf::TYPE_MESSAGE => self::WIRE_LENGTH,
256+
Protobuf\Protobuf::TYPE_FIXED32 => self::WIRE_FIXED32,
257257
Protobuf\Protobuf::TYPE_SFIXED32 => self::WIRE_FIXED32,
258-
Protobuf\Protobuf::TYPE_FLOAT => self::WIRE_FIXED32
259-
);
258+
Protobuf\Protobuf::TYPE_FLOAT => self::WIRE_FIXED32
259+
];
260260

261261
// Unknown types just return the reported wire type
262262
return isset($map[$type]) ? $map[$type] : $default;
@@ -296,6 +296,7 @@ protected function decodeSimpleType($reader, $type, $wireType)
296296
case Protobuf\Protobuf::TYPE_STRING:
297297
case Protobuf\Protobuf::TYPE_BYTES:
298298
$length = $reader->varint();
299+
299300
return $reader->read($length);
300301

301302
case Protobuf\Protobuf::TYPE_MESSAGE:
@@ -312,6 +313,7 @@ protected function decodeSimpleType($reader, $type, $wireType)
312313
return $reader->fixed64();
313314
case self::WIRE_LENGTH:
314315
$length = $reader->varint();
316+
315317
return $reader->read($length);
316318
case self::WIRE_GROUP_START:
317319
case self::WIRE_GROUP_END:

library/DrSlump/Protobuf/Compiler/Command/ProtocGenPhpCommand.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ protected function executeProtoc(InputInterface $input, OutputInterface $output)
198198

199199
$cmdStr = implode(' ', $cmd);
200200

201+
$output->writeln("Generating protos with protoc -- $cmdStr");
202+
201203
// Run command with stderr redirected to stdout
202204
exec($cmdStr . ' 2>&1', $stdout, $return);
203205

@@ -207,6 +209,8 @@ protected function executeProtoc(InputInterface $input, OutputInterface $output)
207209
$output->writeln('<error>protoc exited with an error (' . $return . ') when executed with: </error>');
208210
$output->writeln('');
209211
$output->writeln('<error> ' . implode(" \\\n ", $cmd) . '</error>');
212+
} else {
213+
$output->writeln(join("\n", $stdout));
210214
}
211215
return $return;
212216
}
@@ -237,7 +241,12 @@ protected function getStdIn() {
237241
}
238242
}
239243
} else {
240-
$stdin = fread(STDIN, 1024 * 1024);
244+
$bytes = '';
245+
while (!feof(STDIN)) {
246+
$bytes .= fread(STDIN, 8192);
247+
}
248+
249+
$stdin = $bytes;
241250
}
242251

243252
return $stdin;
@@ -253,11 +262,13 @@ protected function executeCompile(InputInterface $input, OutputInterface $output
253262
try {
254263
// Create a compiler interface
255264
$comp = new Protobuf\Compiler();
265+
256266
echo $comp->compile($this->getStdIn());
257267
return 0;
258268
} catch(\Exception $e) {
259-
$output->writeln('ERROR: ' . $e->getMessage());
260-
$output->writeln($e->getTraceAsString());
269+
$output->writeln('<error>' . $e->getMessage() . '</error>');
270+
$output->writeln('<error>' . $e->getTraceAsString() . '<error>');
271+
261272
return 255;
262273
}
263274
}

library/DrSlump/Protobuf/Compiler/templates/php-message.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static function descriptor()
4242
{
4343
$descriptor = new \DrSlump\Protobuf\Descriptor(__CLASS__, '<?php echo $ns?>');
4444

45-
<?php if (!empty($data->field)): foreach ($data->field as $f): ?>
45+
<?php if (!empty($data->field)): foreach ($data->field as $f): ?>
4646
// <?php echo $this->rule($f)?> <?php echo $this->type($f)?> <?php echo $f->name?> = <?php echo $f->number?>
4747
$f = new \DrSlump\Protobuf\Field();
4848
$f->number = <?php echo $f->number?>;
@@ -153,15 +153,24 @@ public function get<?php echo $Name?>List()
153153
}
154154

155155
/**
156+
* @deprecated Use set<?php echo $Name?>List($value) instead
156157
* Set "<?php echo $name?>" value
157-
*
158158
* @param <?php echo $this->doctype($f)?>[] $value
159159
*/
160160
public function set<?php echo $Name?>($value)
161161
{
162162
return $this-><?php echo $name?> = $value;
163163
}
164164

165+
/**
166+
* Set "<?php echo $name?>" list
167+
* @param <?php echo $this->doctype($f)?>[]|\Traversable $value
168+
*/
169+
public function set<?php echo $Name?>List($value)
170+
{
171+
return $this-><?php echo $name?> = $value;
172+
}
173+
165174
/**
166175
* Add a new element to "<?php echo $name?>"
167176
*

protoc-gen-php.bat

100644100755
File mode changed.

0 commit comments

Comments
 (0)