Add Protobuf.HasField native.

This commit is contained in:
Nicholas Hastings
2018-02-25 10:49:37 -05:00
parent 2a8c390498
commit a17b47a2dc
3 changed files with 24 additions and 1 deletions
+7
View File
@@ -118,6 +118,13 @@ public:
return msg;
}
inline bool HasField(const char *pszFieldName)
{
GETCHECK_FIELD();
CHECK_FIELD_NOT_REPEATED();
return msg->GetReflection()->HasField(*msg, field);
}
inline bool GetInt32(const char *pszFieldName, int32 *out)
{
GETCHECK_FIELD();
+9
View File
@@ -304,6 +304,14 @@ static cell_t smn_PbGetRepeatedFieldCount(IPluginContext *pCtx, const cell_t *pa
return cnt;
}
static cell_t smn_PbHasField(IPluginContext *pCtx, const cell_t *params)
{
GET_MSG_FROM_HANDLE_OR_ERR();
GET_FIELD_NAME_OR_ERR();
return msg->HasField(strField) ? 1 : 0;
}
static cell_t smn_PbSetInt(IPluginContext *pCtx, const cell_t *params)
{
GET_MSG_FROM_HANDLE_OR_ERR();
@@ -778,6 +786,7 @@ REGISTER_NATIVES(protobufnatives)
{"Protobuf.ReadVector", smn_PbReadVector},
{"Protobuf.ReadVector2D", smn_PbReadVector2D},
{"Protobuf.GetRepeatedFieldCount", smn_PbGetRepeatedFieldCount},
{"Protobuf.HasField", smn_PbHasField},
{"Protobuf.SetInt", smn_PbSetInt},
{"Protobuf.SetFloat", smn_PbSetFloat},
{"Protobuf.SetBool", smn_PbSetBool},