Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default implementation is not using Vector but List instead #1766

Open
sjoerdmulder opened this issue Nov 15, 2024 · 0 comments
Open

Default implementation is not using Vector but List instead #1766

sjoerdmulder opened this issue Nov 15, 2024 · 0 comments

Comments

@sjoerdmulder
Copy link
Contributor

sjoerdmulder commented Nov 15, 2024

According to the documentation (which explicitly says When a message is parsed from bytes) the default implementation for repeated fields is a Vector[T]

This is indeed true when parsing from bytes, but when constructing a new message from the Generated classes (without parsing) the underlying implementation is a List. Please see the following example:

message Event {
  repeated string ids = 1;
}

Will generated code something like:

final case class Event(
    ids: _root_.scala.Seq[_root_.scala.Predef.String] = _root_.scala.Seq.empty,
    unknownFields: _root_.scalapb.UnknownFieldSet = _root_.scalapb.UnknownFieldSet.empty
    ) extends scalapb.GeneratedMessage with scalapb.lenses.Updatable[Event]

But the _root_.scala.Seq.empty is a scala.collection.immutable.Seq which uses List as delegate by default, see also the following screenshot that compares a serialize / parsed object with the live object:

image

Is it possible to make the default implementation a Vector? This should also apply then to them methods like clearIds that now do copy(ids = _root_.scala.Seq.empty). But the signature should still expose Seq[T]

final case class Event(
    ids: _root_.scala.Seq[_root_.scala.Predef.String] = _root_.scala.Vector.empty,
    unknownFields: _root_.scalapb.UnknownFieldSet = _root_.scalapb.UnknownFieldSet.empty
    ) extends scalapb.GeneratedMessage with scalapb.lenses.Updatable[Event]

I know it's possible to set the collection_type option but that changes the whole signature. I want to expose the Seq as interface but the implementation should be a Vector

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant