Add Protobuf.HasField native.
This commit is contained in:
parent
2a8c390498
commit
a17b47a2dc
@ -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();
|
||||
|
@ -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},
|
||||
|
@ -109,9 +109,16 @@ methodmap Protobuf < Handle
|
||||
//
|
||||
// @param field Field name.
|
||||
// @return Number of elements in the field.
|
||||
// @error Non-existent field, or incorrect field type.
|
||||
// @error Non-existent field, or non-repeated field.
|
||||
public native int GetRepeatedFieldCount(const char[] field);
|
||||
|
||||
// Returns whether or not the named, non-repeated field has a value set.
|
||||
//
|
||||
// @param field Field name.
|
||||
// @return True if value has been set, else false.
|
||||
// @error Non-existent field, or repeated field.
|
||||
public native bool HasField(const char[] field);
|
||||
|
||||
// Sets an int32, uint32, sint32, fixed32, sfixed32, or enum value on a protobuf message.
|
||||
//
|
||||
// @param field Field name.
|
||||
|
Loading…
Reference in New Issue
Block a user