Home > Back-end >  Sort repeated field in protobuf
Sort repeated field in protobuf

Time:11-30

I have an object with a few lists inside

message Info {
  repeated Dependency f1 = 1;
  repeated Dependency f2 = 2;
}

I wanted these fields to be sorted when I'm building the Info Class.
any idea how can I do that?

CodePudding user response:

The only way to do this is the simple, obvious way: make your own MutableList to hold the objects you're adding, and then sort it before adding it to the proto DSL or builder.

Neither the Java nor the Kotlin proto APIs will allow you to sort elements of a proto after they have been added to a builder.

  • Related