How to delete arbitrary objects in repeated field? (protobuf)

后端 未结 5 1234
广开言路
广开言路 2021-02-18 17:51

I have some entries in the repeated field in my proto. Now I want delete some of them. How can I accomplish this? There is a function to delete the last element, but I want to d

5条回答
  •  星月不相逢
    2021-02-18 18:22

    Protobuf v2

    You can use the DeleteSubrange(int start, int num) in RepeatedPtrField class.

    If you want to delete a single element then you have to call this method as DeleteSubrange(index_to_be_del, 1). It will remove the element at that index.

    Protobuf v3 update

    As mentioned in the comments, iterator RepeatedField::erase(const_iterator position) can delete at arbitrary position

提交回复
热议问题