Skip to content

Commit ddac579

Browse files
committed
Added a required field
1 parent 899da7a commit ddac579

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

generated/test/proto2_ex1_proto.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class example1 implements \Protobuf\Message {
4747
private bool $was_astring_set;
4848
private string $abytes;
4949
private bool $was_abytes_set;
50+
public string $required_field;
5051
private string $XXX_unrecognized;
5152

5253
public function __construct(shape(
@@ -57,6 +58,7 @@ public function __construct(shape(
5758
?'abool' => bool,
5859
?'astring' => string,
5960
?'abytes' => string,
61+
?'required_field' => string,
6062
) $s = shape()) {
6163
if (Shapes::keyExists($s, 'enum_default')) {
6264
$this->enum_default = $s['enum_default'];
@@ -107,6 +109,7 @@ public function __construct(shape(
107109
$this->abytes = \stripcslashes('foo');
108110
$this->was_abytes_set = false;
109111
}
112+
$this->required_field = $s['required_field'] ?? '';
110113
$this->XXX_unrecognized = '';
111114
}
112115

@@ -246,6 +249,9 @@ public function MergeFrom(\Protobuf\Internal\Decoder $d): void {
246249
$this->abytes = $d->readString();
247250
$this->was_abytes_set = true;
248251
break;
252+
case 8:
253+
$this->required_field = $d->readString();
254+
break;
249255
default:
250256
$d->skip($fn, $wt);
251257
}
@@ -282,6 +288,10 @@ public function WriteTo(\Protobuf\Internal\Encoder $e): void {
282288
$e->writeTag(7, 2);
283289
$e->writeString($this->abytes);
284290
}
291+
if ($this->required_field !== '') {
292+
$e->writeTag(8, 2);
293+
$e->writeString($this->required_field);
294+
}
285295
$e->writeRaw($this->XXX_unrecognized);
286296
}
287297

@@ -307,6 +317,7 @@ public function WriteJsonTo(\Protobuf\Internal\JsonEncoder $e): void {
307317
if ($this->hasAbytes()) {
308318
$e->writeBytes('abytes', 'abytes', $this->abytes, false);
309319
}
320+
$e->writeString('required_field', 'requiredField', $this->required_field, false);
310321
}
311322

312323
public function MergeJsonFrom(mixed $m): void {
@@ -342,6 +353,9 @@ public function MergeJsonFrom(mixed $m): void {
342353
$this->abytes = \Protobuf\Internal\JsonDecoder::readBytes($v);
343354
$this->was_abytes_set = true;
344355
break;
356+
case 'required_field': case 'requiredField':
357+
$this->required_field = \Protobuf\Internal\JsonDecoder::readString($v);
358+
break;
345359
default:
346360
break;
347361
}
@@ -373,6 +387,7 @@ public function CopyFrom(\Protobuf\Message $o): \Errors\Error {
373387
if ($o->hasAbytes()) {
374388
$this->abytes = $o->abytes;
375389
}
390+
$this->required_field = $o->required_field;
376391
$this->XXX_unrecognized = $o->XXX_unrecognized;
377392
return \Errors\Ok();
378393
}
@@ -386,7 +401,7 @@ public function Name(): string {
386401
}
387402

388403
public function FileDescriptorProtoBytes(): string {
389-
// 1015 bytes of gzipped FileDescriptorProto as a string
390-
return (string)\gzuncompress("\x78\xda\x74\x8f\xc1\x6a\xb3\x40\x10\xc7\x99\x18\x63\x9c\x2f\x7c\xd8\x85\xc2\xd2\x5c\xd6\x9e\x96\x1e\x2c\xa6\xe9\xa1\x7b\xb3\x69\x6f\x3d\x6d\x1e\x40\xd6\x66\x95\x80\xba\x41\x77\x21\x7d\x8c\xbe\x71\x51\x93\xde\x7a\x9a\x99\x1f\xbf\x19\xfe\x83\xb7\x56\xf7\xf6\xf1\xd4\x19\x6b\x36\xb9\x3e\xa7\xc9\xd8\x92\xb0\x38\xb6\x55\x52\x98\xb6\xba\xff\x9e\xe1\x52\x9f\x55\x73\xaa\x75\x4a\xb6\xb8\xd2\xad\x6b\xf2\x83\x2e\x95\xab\x2d\x5\x6\xfc\xff\xe6\x26\xf9\xd5\x93\xec\xbd\x75\x4d\x2a\xff\xd\xda\xdb\x64\x91\x17\x1c\xc7\xfc\xd3\xf5\xd6\x34\x74\xf6\xc7\x92\xf0\x77\x1f\xd9\x7e\x2f\x71\x90\x77\xa3\x4b\xd6\x18\xa8\x83\x71\x45\xad\xa9\xc7\x80\x83\x80\x27\x79\x25\x64\x8d\xb\x55\xd6\x46\x59\x3a\x67\xc0\x67\xc2\xdb\x26\xcf\xf2\x82\xc8\x1d\xfa\xaa\x30\xa6\xa6\x3e\x3\xbe\x14\x73\xdb\x39\x2d\x27\x44\x62\xc\x54\x6f\xbb\x63\x5b\xd1\x5\x3\x1e\x8a\x60\x8a\x16\xcb\x2b\x1f\x6f\x17\x5f\x56\xf7\x34\x60\xc0\x57\xc2\x2b\x8d\x91\x17\xf4\x10\xe3\x62\x8a\x4c\x7c\x84\x2c\xf2\x86\xf2\x1a\x1\x9\x71\x7a\x21\xc2\x9f\x0\x0\x0\xff\xff\xa1\x62\x5d\xdb");
404+
// 1102 bytes of gzipped FileDescriptorProto as a string
405+
return (string)\gzuncompress("\x78\xda\x74\x8f\xc1\x4a\xc3\x40\x10\x86\xd9\xa4\x69\x9a\xb1\x96\xba\x20\x2c\xf6\xb2\x15\x84\xc5\x43\xa4\xb5\x1e\xcc\xad\x56\x3d\x79\xda\x3e\x40\xd8\x98\x49\x9\x24\xd9\x9a\xec\x42\x7d\x33\x1f\x4f\x92\x34\xde\x3c\xcd\xcc\xc7\x37\xc3\xfc\x70\x6d\xb0\x31\xf\xc7\x5a\x1b\xbd\x8e\xf1\xb4\xa\xbb\x96\x6\x49\x5e\x1d\xc2\x44\x57\x87\xdb\x1f\x7\x26\x78\x52\xe5\xb1\xc0\x15\xdd\xc0\x14\x2b\x5b\xc6\x29\x66\xca\x16\x86\x11\x4e\xc4\x6c\x7d\x15\xfe\xe9\xe1\xf6\xad\xb2\xe5\x4a\x5e\xb4\xda\x6b\x6f\xd1\x67\xe8\xc6\xf8\xd3\x36\x46\x97\xcc\xf9\x67\x29\xf2\x76\x1f\xdb\xfd\x5e\x42\x2b\xef\x3a\x97\x2e\xc0\x57\xa9\xb6\x49\x81\xcc\xe5\x44\x90\x88\x3c\xca\x81\xd0\x5\x8c\x55\x56\x68\x65\xd8\x88\x13\xe1\x44\xee\x26\x7c\x92\x67\x44\x6f\xc0\x53\x89\xd6\x5\xf3\x38\x11\x93\x68\x64\x6a\x8b\xb2\x47\x74\x9\xbe\x6a\x4c\x9d\x57\x7\x36\xe6\x44\x4\x91\xdf\xbf\xb6\x94\x3\xef\x6e\x27\xdf\x6\x1b\xe6\x73\x22\xa6\x91\x9b\x69\x2d\xcf\x88\xde\xc1\xac\xc6\x2f\x9b\xd7\x98\xc6\x59\x8e\x45\xca\x26\xdc\x11\x81\xbc\x1c\xe8\x7b\xb\xef\x97\x30\xee\x93\x51\xf\xc8\x76\xee\xb6\xe5\x65\x4e\x68\x0\x7d\xd2\x39\xfc\x6\x0\x0\xff\xff\xed\xcc\x6a\x2c");
391406
}
392407
}

test/proto2_ex1.proto

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ message example1 {
1515
optional AEnum1 enum_default = 1;
1616
optional AEnum1 enum_custom = 2 [ default = CLASS ];
1717

18-
optional double adouble = 3 [ default = 3];
19-
optional float afloat = 4 [default = 4.5];
20-
optional bool abool = 5 [default = true];
21-
optional string astring = 6 [default = "custom!"];
22-
optional bytes abytes = 7 [default = "foo"];
18+
optional double adouble = 3 [ default = 3];
19+
optional float afloat = 4 [default = 4.5];
20+
optional bool abool = 5 [default = true];
21+
optional string astring = 6 [default = "custom!"];
22+
optional bytes abytes = 7 [default = "foo"];
23+
24+
required string required_field = 8;
2325
}

0 commit comments

Comments
 (0)