skamonkey@3743: /** skamonkey@3743: * vim: set ts=4 : skamonkey@3743: * ============================================================================= skamonkey@3743: * SourceMod skamonkey@3743: * Copyright (C) 2013 AlliedModders LLC. All rights reserved. skamonkey@3743: * ============================================================================= skamonkey@3743: * skamonkey@3743: * This program is free software; you can redistribute it and/or modify it under skamonkey@3743: * the terms of the GNU General Public License, version 3.0, as published by the skamonkey@3743: * Free Software Foundation. skamonkey@3743: * skamonkey@3743: * This program is distributed in the hope that it will be useful, but WITHOUT skamonkey@3743: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS skamonkey@3743: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more skamonkey@3743: * details. skamonkey@3743: * skamonkey@3743: * You should have received a copy of the GNU General Public License along with skamonkey@3743: * this program. If not, see . skamonkey@3743: * skamonkey@3743: * As a special exception, AlliedModders LLC gives you permission to link the skamonkey@3743: * code of this program (as well as its derivative works) to "Half-Life 2," the skamonkey@3743: * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software skamonkey@3743: * by the Valve Corporation. You must obey the GNU General Public License in skamonkey@3743: * all respects for all other code used. Additionally, AlliedModders LLC grants skamonkey@3743: * this exception to all derivative works. AlliedModders LLC defines further skamonkey@3743: * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), skamonkey@3743: * or . skamonkey@3743: * skamonkey@3743: * Version: $Id$ skamonkey@3743: */ skamonkey@3743: skamonkey@3743: #ifndef _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_ skamonkey@3743: #define _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_ skamonkey@3743: skamonkey@3743: #include skamonkey@3743: #include skamonkey@3743: skamonkey@3743: #define GETCHECK_FIELD() \ skamonkey@3743: const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \ skamonkey@3743: if (!field) \ skamonkey@3743: { \ skamonkey@3743: return false; \ skamonkey@3743: } skamonkey@3743: skamonkey@3743: #define CHECK_FIELD_TYPE(type) \ skamonkey@3743: if (field->cpp_type() != protobuf::FieldDescriptor::CPPTYPE_##type) \ skamonkey@3743: { \ skamonkey@3743: return false; \ skamonkey@3743: } skamonkey@3743: skamonkey@3743: #define CHECK_FIELD_TYPE2(type1, type2) \ skamonkey@3743: protobuf::FieldDescriptor::CppType fieldType = field->cpp_type(); \ skamonkey@3743: if (fieldType != protobuf::FieldDescriptor::CPPTYPE_##type1 \ skamonkey@3743: && fieldType != protobuf::FieldDescriptor::CPPTYPE_##type2) \ skamonkey@3743: { \ skamonkey@3743: return false; \ skamonkey@3743: } skamonkey@3743: skamonkey@3896: #define CHECK_FIELD_TYPE3(type1, type2, type3) \ skamonkey@3896: protobuf::FieldDescriptor::CppType fieldType = field->cpp_type(); \ skamonkey@3896: if (fieldType != protobuf::FieldDescriptor::CPPTYPE_##type1 \ skamonkey@3896: && fieldType != protobuf::FieldDescriptor::CPPTYPE_##type2 \ skamonkey@3896: && fieldType != protobuf::FieldDescriptor::CPPTYPE_##type3) \ skamonkey@3896: { \ skamonkey@3896: return false; \ skamonkey@3896: } skamonkey@3896: skamonkey@3743: #define CHECK_FIELD_REPEATED() \ skamonkey@3743: if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED) \ skamonkey@3743: { \ skamonkey@3743: return false; \ skamonkey@3743: } skamonkey@3743: skamonkey@3743: #define CHECK_FIELD_NOT_REPEATED() \ skamonkey@3743: if (field->label() == protobuf::FieldDescriptor::LABEL_REPEATED) \ skamonkey@3743: { \ skamonkey@3743: return false; \ skamonkey@3743: } skamonkey@3743: skamonkey@3743: #define CHECK_REPEATED_ELEMENT(idx) \ skamonkey@3743: int elemCount = msg->GetReflection()->FieldSize(*msg, field); \ skamonkey@3751: if (elemCount == 0 || idx >= elemCount || idx < 0) \ skamonkey@3743: { \ skamonkey@3743: return false; \ skamonkey@3743: } skamonkey@3743: skamonkey@3743: typedef List PBHandleList; skamonkey@3743: skamonkey@3743: class SMProtobufMessage skamonkey@3743: { skamonkey@3743: public: skamonkey@3743: SMProtobufMessage( protobuf::Message *message ) skamonkey@3743: { skamonkey@3743: msg = message; skamonkey@3743: } skamonkey@3743: skamonkey@3743: ~SMProtobufMessage() skamonkey@3743: { skamonkey@3743: PBHandleList::iterator iter = childHandles.begin(); skamonkey@3743: while (iter != childHandles.end()) skamonkey@3743: { skamonkey@3743: Handle_t &hndl = (*iter); skamonkey@3743: HandleSecurity sec; skamonkey@3743: sec.pIdentity = g_pCoreIdent; dvander@3875: handlesys->FreeHandle(hndl, &sec); skamonkey@3743: iter = childHandles.erase(iter); skamonkey@3743: } skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline void AddChildHandle(Handle_t hndl) skamonkey@3743: { skamonkey@3743: childHandles.push_back(hndl); skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline protobuf::Message *GetProtobufMessage() skamonkey@3743: { skamonkey@3743: return msg; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetInt32(const char *pszFieldName, int32 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT32); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetInt32(*msg, field); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetInt32(const char *pszFieldName, int32 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT32); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetInt32(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedInt32(const char *pszFieldName, int index, int32 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT32); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedInt32(const char *pszFieldName, int index, int32 value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(INT32); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedInt32(msg, field, index, value); skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddInt32(const char *pszFieldName, int32 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT32); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddInt32(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetInt64(const char *pszFieldName, int64 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT64); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetInt64(*msg, field); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetInt64(const char *pszFieldName, int64 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT64); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetInt64(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedInt64(const char *pszFieldName, int index, int64 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT64); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetRepeatedInt64(*msg, field, index); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedInt64(const char *pszFieldName, int index, int64 value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(INT64); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedInt64(msg, field, index, value); skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddInt64(const char *pszFieldName, int64 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(INT64); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddInt64(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetUInt32(const char *pszFieldName, uint32 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT32); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetUInt32(*msg, field); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetUInt32(const char *pszFieldName, uint32 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT32); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetUInt32(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedUInt32(const char *pszFieldName, int index, uint32 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT32); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetRepeatedUInt32(*msg, field, index); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedUInt32(const char *pszFieldName, int index, uint32 value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(UINT32); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedUInt32(msg, field, index, value); skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddUInt32(const char *pszFieldName, uint32 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT32); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddUInt32(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetUInt64(const char *pszFieldName, uint64 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT64); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetUInt64(*msg, field); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetUInt64(const char *pszFieldName, uint64 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT64); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetUInt64(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedUInt64(const char *pszFieldName, int index, uint64 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT64); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetRepeatedUInt64(*msg, field, index); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedUInt64(const char *pszFieldName, int index, uint64 value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(UINT64); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedUInt64(msg, field, index, value); skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddUInt64(const char *pszFieldName, uint64 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(UINT64); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddUInt32(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3896: inline bool GetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3896: CHECK_FIELD_TYPE3(INT32, UINT32, ENUM); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32) skamonkey@3743: *out = (int32)msg->GetReflection()->GetUInt32(*msg, field); skamonkey@3896: else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32) skamonkey@3743: *out = msg->GetReflection()->GetInt32(*msg, field); skamonkey@3896: else // CPPTYPE_ENUM skamonkey@3896: *out = msg->GetReflection()->GetEnum(*msg, field)->number(); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3896: inline bool SetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3896: CHECK_FIELD_TYPE3(INT32, UINT32, ENUM); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32) skamonkey@3896: { skamonkey@3743: msg->GetReflection()->SetUInt32(msg, field, (uint32)value); skamonkey@3896: } skamonkey@3896: else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32) skamonkey@3896: { skamonkey@3743: msg->GetReflection()->SetInt32(msg, field, value); skamonkey@3896: } skamonkey@3896: else // CPPTYPE_ENUM skamonkey@3896: { skamonkey@3896: const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value); skamonkey@3896: if (!pEnumValue) skamonkey@3896: return false; skamonkey@3896: skamonkey@3896: msg->GetReflection()->SetEnum(msg, field, pEnumValue); skamonkey@3896: } skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3896: inline bool GetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3896: CHECK_FIELD_TYPE3(INT32, UINT32, ENUM); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32) skamonkey@3743: *out = (int32)msg->GetReflection()->GetRepeatedUInt32(*msg, field, index); skamonkey@3896: else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32) skamonkey@3743: *out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index); skamonkey@3896: else // CPPTYPE_ENUM skamonkey@3896: *out = msg->GetReflection()->GetRepeatedEnum(*msg, field, index)->number(); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3896: inline bool SetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3896: CHECK_FIELD_TYPE3(INT32, UINT32, ENUM); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32) skamonkey@3896: { skamonkey@3814: msg->GetReflection()->SetRepeatedUInt32(msg, field, index, (uint32)value); skamonkey@3896: } skamonkey@3896: else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32) skamonkey@3896: { skamonkey@3814: msg->GetReflection()->SetRepeatedInt32(msg, field, index, value); skamonkey@3896: } skamonkey@3896: else // CPPTYPE_ENUM skamonkey@3896: { skamonkey@3896: const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value); skamonkey@3896: if (!pEnumValue) skamonkey@3896: return false; skamonkey@3896: skamonkey@3896: msg->GetReflection()->SetRepeatedEnum(msg, field, index, pEnumValue); skamonkey@3896: } skamonkey@3814: skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3896: inline bool AddInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3896: CHECK_FIELD_TYPE3(INT32, UINT32, ENUM); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32) skamonkey@3896: { skamonkey@3743: msg->GetReflection()->AddUInt32(msg, field, (uint32)value); skamonkey@3896: } skamonkey@3896: else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32) skamonkey@3896: { skamonkey@3743: msg->GetReflection()->AddInt32(msg, field, value); skamonkey@3896: } skamonkey@3896: else // CPPTYPE_ENUM skamonkey@3896: { skamonkey@3896: const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value); skamonkey@3896: if (!pEnumValue) skamonkey@3896: return false; skamonkey@3896: skamonkey@3896: msg->GetReflection()->AddEnum(msg, field, pEnumValue); skamonkey@3896: } skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetBool(const char *pszFieldName, bool *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(BOOL); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetBool(*msg, field); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetBool(const char *pszFieldName, bool value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(BOOL); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetBool(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedBool(const char *pszFieldName, int index, bool *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(BOOL); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetRepeatedBool(*msg, field, index); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedBool(const char *pszFieldName, int index, bool value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(BOOL); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedBool(msg, field, index, value); skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddBool(const char *pszFieldName, bool value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(BOOL); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddBool(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetFloat(const char *pszFieldName, float *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(FLOAT); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetFloat(*msg, field); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetFloat(const char *pszFieldName, float value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(FLOAT); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetFloat(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedFloat(const char *pszFieldName, int index, float *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(FLOAT); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedFloat(const char *pszFieldName, int index, float value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(FLOAT); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedFloat(msg, field, index, value); skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddFloat(const char *pszFieldName, float value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(FLOAT); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddFloat(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetDouble(const char *pszFieldName, double *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(DOUBLE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetDouble(*msg, field); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetDouble(const char *pszFieldName, double value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(DOUBLE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetDouble(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedDouble(const char *pszFieldName, int index, double *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(DOUBLE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: *out = msg->GetReflection()->GetRepeatedDouble(*msg, field, index); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedDouble(const char *pszFieldName, int index, double value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(DOUBLE); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedDouble(msg, field, index, value); skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddDouble(const char *pszFieldName, double value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(DOUBLE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddDouble(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetFloatOrDouble(const char *pszFieldName, float *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE2(FLOAT, DOUBLE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE) skamonkey@3743: *out = (float)msg->GetReflection()->GetDouble(*msg, field); skamonkey@3743: else skamonkey@3743: *out = msg->GetReflection()->GetFloat(*msg, field); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetFloatOrDouble(const char *pszFieldName, float value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE2(FLOAT, DOUBLE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE) skamonkey@3743: msg->GetReflection()->SetDouble(msg, field, (double)value); skamonkey@3743: else skamonkey@3743: msg->GetReflection()->SetFloat(msg, field, value); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedFloatOrDouble(const char *pszFieldName, int index, float *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE2(FLOAT, DOUBLE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE) skamonkey@3743: *out = (float)msg->GetReflection()->GetRepeatedDouble(*msg, field, index); skamonkey@3743: else skamonkey@3743: *out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedFloatOrDouble(const char *pszFieldName, int index, float value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE2(FLOAT, DOUBLE); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE) skamonkey@3814: msg->GetReflection()->SetRepeatedDouble(msg, field, index, (double)value); skamonkey@3814: else skamonkey@3814: msg->GetReflection()->SetRepeatedFloat(msg, field, index, value); skamonkey@3814: skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddFloatOrDouble(const char *pszFieldName, float value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE2(FLOAT, DOUBLE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE) skamonkey@3743: msg->GetReflection()->AddDouble(msg, field, (double)value); skamonkey@3743: else skamonkey@3743: msg->GetReflection()->AddFloat(msg, field, value); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetString(const char *pszFieldName, char *out, int size) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(STRING); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: std::string scratch; skamonkey@3746: strncopy(out, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str(), size); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetString(const char *pszFieldName, const char *value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(STRING); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->SetString(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedString(const char *pszFieldName, int index, char *out, int size) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(STRING); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: std::string scratch; skamonkey@3743: strncopy(out, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str(), size); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedString(const char *pszFieldName, int index, const char *value) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(STRING); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: msg->GetReflection()->SetRepeatedString(msg, field, index, value); skamonkey@3814: skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddString(const char *pszFieldName, const char *value) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(STRING); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: msg->GetReflection()->AddString(msg, field, value); skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetColor(const char *pszFieldName, Color *out) skamonkey@3743: { skamonkey@3855: #if SOURCE_ENGINE != SE_CSGO skamonkey@3855: return false; skamonkey@3855: #else skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetMessage(*msg, field); skamonkey@3743: out->SetColor( skamonkey@3743: msgRGBA.r(), skamonkey@3743: msgRGBA.g(), skamonkey@3743: msgRGBA.b(), skamonkey@3743: msgRGBA.a() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3855: #endif skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetColor(const char *pszFieldName, const Color &value) skamonkey@3743: { skamonkey@3855: #if SOURCE_ENGINE != SE_CSGO skamonkey@3855: return false; skamonkey@3855: #else skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableMessage(msg, field); skamonkey@3743: msgRGBA->set_r(value.r()); skamonkey@3743: msgRGBA->set_g(value.g()); skamonkey@3743: msgRGBA->set_b(value.b()); skamonkey@3743: msgRGBA->set_a(value.a()); skamonkey@3743: skamonkey@3743: return true; skamonkey@3855: #endif skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedColor(const char *pszFieldName, int index, Color *out) skamonkey@3743: { skamonkey@3855: #if SOURCE_ENGINE != SE_CSGO skamonkey@3855: return false; skamonkey@3855: #else skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index); skamonkey@3743: out->SetColor( skamonkey@3743: msgRGBA.r(), skamonkey@3743: msgRGBA.g(), skamonkey@3743: msgRGBA.b(), skamonkey@3743: msgRGBA.a() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3855: #endif skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedColor(const char *pszFieldName, int index, const Color &value) skamonkey@3814: { skamonkey@3855: #if SOURCE_ENGINE != SE_CSGO skamonkey@3855: return false; skamonkey@3855: #else skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index); skamonkey@3814: msgRGBA->set_r(value.r()); skamonkey@3814: msgRGBA->set_g(value.g()); skamonkey@3814: msgRGBA->set_b(value.b()); skamonkey@3814: msgRGBA->set_a(value.a()); skamonkey@3814: skamonkey@3814: return true; skamonkey@3855: #endif skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddColor(const char *pszFieldName, const Color &value) skamonkey@3743: { skamonkey@3855: #if SOURCE_ENGINE != SE_CSGO skamonkey@3855: return false; skamonkey@3855: #else skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->AddMessage(msg, field); skamonkey@3743: msgRGBA->set_r(value.r()); skamonkey@3743: msgRGBA->set_g(value.g()); skamonkey@3743: msgRGBA->set_b(value.b()); skamonkey@3743: msgRGBA->set_a(value.a()); skamonkey@3743: skamonkey@3743: return true; skamonkey@3855: #endif skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetVector2D(const char *pszFieldName, Vector2D *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetMessage(*msg, field); skamonkey@3743: out->Init( skamonkey@3743: msgVec2d.x(), skamonkey@3743: msgVec2d.y() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetVector2D(const char *pszFieldName, Vector2D &vec) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableMessage(msg, field); skamonkey@3743: msgVec2d->set_x(vec.x); skamonkey@3743: msgVec2d->set_y(vec.y); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedVector2D(const char *pszFieldName, int index, Vector2D *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index); skamonkey@3743: out->Init( skamonkey@3743: msgVec2d.x(), skamonkey@3743: msgVec2d.y() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedVector2D(const char *pszFieldName, int index, Vector2D &vec) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index); skamonkey@3814: msgVec2d->set_x(vec.x); skamonkey@3814: msgVec2d->set_y(vec.y); skamonkey@3814: skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddVector2D(const char *pszFieldName, Vector2D &vec) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->AddMessage(msg, field); skamonkey@3743: msgVec2d->set_x(vec.x); skamonkey@3743: msgVec2d->set_y(vec.y); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetVector(const char *pszFieldName, Vector *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetMessage(*msg, field); skamonkey@3743: out->Init( skamonkey@3743: msgVec.x(), skamonkey@3743: msgVec.y(), skamonkey@3743: msgVec.z() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetVector(const char *pszFieldName, Vector &vec) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableMessage(msg, field); skamonkey@3743: msgVec->set_x(vec.x); skamonkey@3743: msgVec->set_y(vec.y); skamonkey@3743: msgVec->set_z(vec.z); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedVector(const char *pszFieldName, int index, Vector *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index); skamonkey@3743: out->Init( skamonkey@3743: msgVec.x(), skamonkey@3743: msgVec.y(), skamonkey@3743: msgVec.z() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedVector(const char *pszFieldName, int index, Vector &vec) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index); skamonkey@3814: msgVec->set_x(vec.x); skamonkey@3814: msgVec->set_y(vec.y); skamonkey@3814: msgVec->set_z(vec.z); skamonkey@3814: skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddVector(const char *pszFieldName, Vector &vec) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->AddMessage(msg, field); skamonkey@3743: msgVec->set_x(vec.x); skamonkey@3743: msgVec->set_y(vec.y); skamonkey@3743: msgVec->set_z(vec.z); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetQAngle(const char *pszFieldName, QAngle *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetMessage(*msg, field); skamonkey@3743: out->Init( skamonkey@3743: msgAng.x(), skamonkey@3743: msgAng.y(), skamonkey@3743: msgAng.z() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool SetQAngle(const char *pszFieldName, QAngle &vec) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableMessage(msg, field); skamonkey@3743: msgAng->set_x(vec.x); skamonkey@3743: msgAng->set_y(vec.y); skamonkey@3743: msgAng->set_z(vec.z); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedQAngle(const char *pszFieldName, int index, QAngle *out) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index); skamonkey@3743: out->Init( skamonkey@3743: msgAng.x(), skamonkey@3743: msgAng.y(), skamonkey@3743: msgAng.z() skamonkey@3743: ); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3814: inline bool SetRepeatedQAngle(const char *pszFieldName, int index, QAngle &vec) skamonkey@3814: { skamonkey@3814: GETCHECK_FIELD(); skamonkey@3814: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3814: CHECK_FIELD_REPEATED(); skamonkey@3814: CHECK_REPEATED_ELEMENT(index); skamonkey@3814: skamonkey@3814: CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index); skamonkey@3814: msgAng->set_x(vec.x); skamonkey@3814: msgAng->set_y(vec.y); skamonkey@3814: msgAng->set_z(vec.z); skamonkey@3814: skamonkey@3814: return true; skamonkey@3814: } skamonkey@3814: skamonkey@3743: inline bool AddQAngle(const char *pszFieldName, QAngle &vec) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->AddMessage(msg, field); skamonkey@3743: msgAng->set_x(vec.x); skamonkey@3743: msgAng->set_y(vec.y); skamonkey@3743: msgAng->set_z(vec.z); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetMessage(const char *pszFieldName, protobuf::Message **message) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_NOT_REPEATED(); skamonkey@3743: skamonkey@3743: *message = msg->GetReflection()->MutableMessage(msg, field); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool GetRepeatedMessage(const char *pszFieldName, int index, const protobuf::Message **message) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: CHECK_REPEATED_ELEMENT(index); skamonkey@3743: skamonkey@3743: const protobuf::Message *m = &msg->GetReflection()->GetRepeatedMessage(*msg, field, index); skamonkey@3743: *message = m; skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline bool AddMessage(const char *pszFieldName, protobuf::Message **message) skamonkey@3743: { skamonkey@3743: GETCHECK_FIELD(); skamonkey@3743: CHECK_FIELD_TYPE(MESSAGE); skamonkey@3743: CHECK_FIELD_REPEATED(); skamonkey@3743: skamonkey@3743: *message = msg->GetReflection()->AddMessage(msg, field); skamonkey@3743: skamonkey@3743: return true; skamonkey@3743: } skamonkey@3743: skamonkey@3743: inline int GetRepeatedFieldCount(const char *pszFieldName) skamonkey@3743: { skamonkey@3743: const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \ skamonkey@3743: if (!field) skamonkey@3743: return -1; skamonkey@3743: skamonkey@3743: if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED) skamonkey@3743: return -1; skamonkey@3743: skamonkey@3743: return msg->GetReflection()->FieldSize(*msg, field); skamonkey@3743: } skamonkey@3743: skamonkey@4293: inline bool RemoveRepeatedFieldValue(const char *pszFieldName, int index) skamonkey@4293: { skamonkey@4293: GETCHECK_FIELD(); skamonkey@4293: CHECK_FIELD_REPEATED(); skamonkey@4293: CHECK_REPEATED_ELEMENT(index); skamonkey@4293: skamonkey@4293: // Protobuf guarantees that repeated field values will stay in order and so must we. skamonkey@4293: const protobuf::Reflection *pReflection = msg->GetReflection(); skamonkey@4293: for (int i = index; i < elemCount - 1; ++i) skamonkey@4293: { skamonkey@4293: pReflection->SwapElements(msg, field, i, i + 1); skamonkey@4293: } skamonkey@4293: skamonkey@4293: pReflection->RemoveLast(msg, field); skamonkey@4293: skamonkey@4293: return true; skamonkey@4293: } skamonkey@4293: skamonkey@3743: private: skamonkey@3743: protobuf::Message *msg; skamonkey@3743: PBHandleList childHandles; skamonkey@3743: }; skamonkey@3743: skamonkey@3743: #endif // _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_