Skip to content

Commit 5135b8b

Browse files
committed
chore: support packed lists for proto2
1 parent 8ef60e3 commit 5135b8b

File tree

10 files changed

+15
-13
lines changed

10 files changed

+15
-13
lines changed

src/Compiler/FieldOptions.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ public function __construct(
3232
public bool $debugRedact = false,
3333
#[Reflection\Field(17, new Reflection\EnumT(FieldOptions\OptionRetention::class))]
3434
public ?FieldOptions\OptionRetention $retention = null,
35-
#[Reflection\Field(19, new Reflection\ListT(
36-
new Reflection\ObjectT(FieldOptions\OptionTargetType::class),
37-
))]
35+
#[Reflection\Field(19, new Reflection\ListT(new Reflection\EnumT(FieldOptions\OptionTargetType::class), false))]
3836
public array $targets = [],
3937
#[Reflection\Field(20, new Reflection\ListT(
4038
new Reflection\ObjectT(FieldOptions\EditionDefault::class),

src/Compiler/FileDescriptorProto.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public function __construct(
2828
public ?string $package = null,
2929
#[Reflection\Field(3, new Reflection\ListT(Reflection\StringT::T))]
3030
public array $dependencies = [],
31-
#[Reflection\Field(10, new Reflection\ListT(Reflection\Int32T::T))]
31+
#[Reflection\Field(10, new Reflection\ListT(Reflection\Int32T::T, false))]
3232
public array $publicDependencies = [],
33-
#[Reflection\Field(11, new Reflection\ListT(Reflection\Int32T::T))]
33+
#[Reflection\Field(11, new Reflection\ListT(Reflection\Int32T::T, false))]
3434
public array $weakDependencies = [],
3535
#[Reflection\Field(15, new Reflection\ListT(Reflection\StringT::T))]
3636
public array $optionDependencies = [],

src/Reflection/Internal/Visitor/RecursionBreakTypeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(
3232
public function list(ListT $type): mixed
3333
{
3434
/** @phpstan-ignore argument.type */
35-
return Protobuf\listT($type->element->accept($this));
35+
return Protobuf\listT($type->element->accept($this), $type->packed);
3636
}
3737

3838
#[\Override]

src/Reflection/Internal/Visitor/ToProtobufTypeTypeVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public function list(ListT $type): Type
134134
/** @var Type<mixed, 'repeatable'> $element */
135135
$element = $type->element->accept($this);
136136

137-
return Protobuf\listT($element);
137+
return Protobuf\listT($element, $type->packed);
138138
}
139139

140140
#[\Override]

src/Reflection/ListT.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
public function __construct(
1818
public Type $element,
19+
public ?bool $packed = null,
1920
) {}
2021

2122
#[\Override]

src/Type/ListT.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
public function __construct(
1919
public Type $element,
20+
public ?bool $packed = null,
2021
) {}
2122

2223
#[\Override]

src/Type/Visitor/TypeDeserializerVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ public function list(ListT $type): DeserializeValue
146146
/** @phpstan-ignore argument.type */
147147
$type->element->accept($this),
148148
$this->tag,
149-
$type->element->accept(new IsPacked()),
149+
$type->packed ?? $type->element->accept(new IsPacked()),
150150
);
151151
}
152152

src/Type/Visitor/TypeSerializerVisitor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function list(ListT $type): SerializeValue
155155
->accept($this)
156156
->without(SerializeTag::class),
157157
$this->tag,
158-
$type->element->accept(new IsPacked()),
158+
$type->packed ?? $type->element->accept(new IsPacked()),
159159
),
160160
);
161161
}

src/Value.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,11 @@ public static function message(Message $message): self
155155
public static function listOf(
156156
Type $type,
157157
array $values,
158+
?bool $packed = null,
158159
): self {
159160
return new self(
160161
$values,
161-
listT($type),
162+
listT($type, $packed),
162163
);
163164
}
164165

src/constructors.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,9 @@ function recursionT(\Closure $continuation): Type\RecursionT
247247
function listOf(
248248
Type $type,
249249
array $values,
250+
?bool $packed = null,
250251
): Value {
251-
return Value::listOf($type, $values);
252+
return Value::listOf($type, $values, $packed);
252253
}
253254

254255
/**
@@ -257,9 +258,9 @@ function listOf(
257258
* @param Type<T, 'repeatable', *, *> $element
258259
* @return Type\ListT<T>
259260
*/
260-
function listT(Type $element): Type\ListT
261+
function listT(Type $element, ?bool $packed = null): Type\ListT
261262
{
262-
return new Type\ListT($element);
263+
return new Type\ListT($element, $packed);
263264
}
264265

265266
/**

0 commit comments

Comments
 (0)