Add PbRemoveRepeatedFieldValue native (bug 6066, r=asherkin).

This commit is contained in:
Nicholas Hastings
2014-03-21 13:23:48 -04:00
parent fb0fd0c6d2
commit 9215ddcf8a
4 changed files with 44 additions and 0 deletions
+18
View File
@@ -1093,6 +1093,24 @@ public:
return msg->GetReflection()->FieldSize(*msg, field);
}
inline bool RemoveRepeatedFieldValue(const char *pszFieldName, int index)
{
GETCHECK_FIELD();
CHECK_FIELD_REPEATED();
CHECK_REPEATED_ELEMENT(index);
// Protobuf guarantees that repeated field values will stay in order and so must we.
const protobuf::Reflection *pReflection = msg->GetReflection();
for (int i = index; i < elemCount - 1; ++i)
{
pReflection->SwapElements(msg, field, i, i + 1);
}
pReflection->RemoveLast(msg, field);
return true;
}
private:
protobuf::Message *msg;
PBHandleList childHandles;