3 * =============================================================================
5 * Copyright (C) 2013 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_
33 #define _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_
36 #include <google/protobuf/descriptor.h>
38 #define GETCHECK_FIELD() \
39 const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \
45 #define CHECK_FIELD_TYPE(type) \
46 if (field->cpp_type() != protobuf::FieldDescriptor::CPPTYPE_##type) \
51 #define CHECK_FIELD_TYPE2(type1, type2) \
52 protobuf::FieldDescriptor::CppType fieldType = field->cpp_type(); \
53 if (fieldType != protobuf::FieldDescriptor::CPPTYPE_##type1 \
54 && fieldType != protobuf::FieldDescriptor::CPPTYPE_##type2) \
59 #define CHECK_FIELD_TYPE3(type1, type2, type3) \
60 protobuf::FieldDescriptor::CppType fieldType = field->cpp_type(); \
61 if (fieldType != protobuf::FieldDescriptor::CPPTYPE_##type1 \
62 && fieldType != protobuf::FieldDescriptor::CPPTYPE_##type2 \
63 && fieldType != protobuf::FieldDescriptor::CPPTYPE_##type3) \
68 #define CHECK_FIELD_REPEATED() \
69 if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED) \
74 #define CHECK_FIELD_NOT_REPEATED() \
75 if (field->label() == protobuf::FieldDescriptor::LABEL_REPEATED) \
80 #define CHECK_REPEATED_ELEMENT(idx) \
81 int elemCount = msg->GetReflection()->FieldSize(*msg, field); \
82 if (elemCount == 0 || idx >= elemCount || idx < 0) \
87 typedef List<Handle_t> PBHandleList;
89 class SMProtobufMessage
92 SMProtobufMessage( protobuf::Message *message )
99 PBHandleList::iterator iter = childHandles.begin();
100 while (iter != childHandles.end())
102 Handle_t &hndl = (*iter);
104 sec.pIdentity = g_pCoreIdent;
105 handlesys->FreeHandle(hndl, &sec);
106 iter = childHandles.erase(iter);
110 inline void AddChildHandle(Handle_t hndl)
112 childHandles.push_back(hndl);
115 inline protobuf::Message *GetProtobufMessage()
120 inline bool GetInt32(const char *pszFieldName, int32 *out)
123 CHECK_FIELD_TYPE(INT32);
124 CHECK_FIELD_NOT_REPEATED();
126 *out = msg->GetReflection()->GetInt32(*msg, field);
130 inline bool SetInt32(const char *pszFieldName, int32 value)
133 CHECK_FIELD_TYPE(INT32);
134 CHECK_FIELD_NOT_REPEATED();
136 msg->GetReflection()->SetInt32(msg, field, value);
140 inline bool GetRepeatedInt32(const char *pszFieldName, int index, int32 *out)
143 CHECK_FIELD_TYPE(INT32);
144 CHECK_FIELD_REPEATED();
145 CHECK_REPEATED_ELEMENT(index);
147 *out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
151 inline bool SetRepeatedInt32(const char *pszFieldName, int index, int32 value)
154 CHECK_FIELD_TYPE(INT32);
155 CHECK_FIELD_REPEATED();
156 CHECK_REPEATED_ELEMENT(index);
158 msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
162 inline bool AddInt32(const char *pszFieldName, int32 value)
165 CHECK_FIELD_TYPE(INT32);
166 CHECK_FIELD_REPEATED();
168 msg->GetReflection()->AddInt32(msg, field, value);
172 inline bool GetInt64(const char *pszFieldName, int64 *out)
175 CHECK_FIELD_TYPE(INT64);
176 CHECK_FIELD_NOT_REPEATED();
178 *out = msg->GetReflection()->GetInt64(*msg, field);
182 inline bool SetInt64(const char *pszFieldName, int64 value)
185 CHECK_FIELD_TYPE(INT64);
186 CHECK_FIELD_NOT_REPEATED();
188 msg->GetReflection()->SetInt64(msg, field, value);
192 inline bool GetRepeatedInt64(const char *pszFieldName, int index, int64 *out)
195 CHECK_FIELD_TYPE(INT64);
196 CHECK_FIELD_REPEATED();
197 CHECK_REPEATED_ELEMENT(index);
199 *out = msg->GetReflection()->GetRepeatedInt64(*msg, field, index);
203 inline bool SetRepeatedInt64(const char *pszFieldName, int index, int64 value)
206 CHECK_FIELD_TYPE(INT64);
207 CHECK_FIELD_REPEATED();
208 CHECK_REPEATED_ELEMENT(index);
210 msg->GetReflection()->SetRepeatedInt64(msg, field, index, value);
214 inline bool AddInt64(const char *pszFieldName, int64 value)
217 CHECK_FIELD_TYPE(INT64);
218 CHECK_FIELD_REPEATED();
220 msg->GetReflection()->AddInt64(msg, field, value);
224 inline bool GetUInt32(const char *pszFieldName, uint32 *out)
227 CHECK_FIELD_TYPE(UINT32);
228 CHECK_FIELD_NOT_REPEATED();
230 *out = msg->GetReflection()->GetUInt32(*msg, field);
234 inline bool SetUInt32(const char *pszFieldName, uint32 value)
237 CHECK_FIELD_TYPE(UINT32);
238 CHECK_FIELD_NOT_REPEATED();
240 msg->GetReflection()->SetUInt32(msg, field, value);
244 inline bool GetRepeatedUInt32(const char *pszFieldName, int index, uint32 *out)
247 CHECK_FIELD_TYPE(UINT32);
248 CHECK_FIELD_REPEATED();
249 CHECK_REPEATED_ELEMENT(index);
251 *out = msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
255 inline bool SetRepeatedUInt32(const char *pszFieldName, int index, uint32 value)
258 CHECK_FIELD_TYPE(UINT32);
259 CHECK_FIELD_REPEATED();
260 CHECK_REPEATED_ELEMENT(index);
262 msg->GetReflection()->SetRepeatedUInt32(msg, field, index, value);
266 inline bool AddUInt32(const char *pszFieldName, uint32 value)
269 CHECK_FIELD_TYPE(UINT32);
270 CHECK_FIELD_REPEATED();
272 msg->GetReflection()->AddUInt32(msg, field, value);
276 inline bool GetUInt64(const char *pszFieldName, uint64 *out)
279 CHECK_FIELD_TYPE(UINT64);
280 CHECK_FIELD_NOT_REPEATED();
282 *out = msg->GetReflection()->GetUInt64(*msg, field);
286 inline bool SetUInt64(const char *pszFieldName, uint64 value)
289 CHECK_FIELD_TYPE(UINT64);
290 CHECK_FIELD_NOT_REPEATED();
292 msg->GetReflection()->SetUInt64(msg, field, value);
296 inline bool GetRepeatedUInt64(const char *pszFieldName, int index, uint64 *out)
299 CHECK_FIELD_TYPE(UINT64);
300 CHECK_FIELD_REPEATED();
301 CHECK_REPEATED_ELEMENT(index);
303 *out = msg->GetReflection()->GetRepeatedUInt64(*msg, field, index);
307 inline bool SetRepeatedUInt64(const char *pszFieldName, int index, uint64 value)
310 CHECK_FIELD_TYPE(UINT64);
311 CHECK_FIELD_REPEATED();
312 CHECK_REPEATED_ELEMENT(index);
314 msg->GetReflection()->SetRepeatedUInt64(msg, field, index, value);
318 inline bool AddUInt64(const char *pszFieldName, uint64 value)
321 CHECK_FIELD_TYPE(UINT64);
322 CHECK_FIELD_REPEATED();
324 msg->GetReflection()->AddUInt32(msg, field, value);
328 inline bool GetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 *out)
331 CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
332 CHECK_FIELD_NOT_REPEATED();
334 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
335 *out = (int32)msg->GetReflection()->GetUInt32(*msg, field);
336 else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
337 *out = msg->GetReflection()->GetInt32(*msg, field);
339 *out = msg->GetReflection()->GetEnum(*msg, field)->number();
344 inline bool SetInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
347 CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
348 CHECK_FIELD_NOT_REPEATED();
350 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
352 msg->GetReflection()->SetUInt32(msg, field, (uint32)value);
354 else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
356 msg->GetReflection()->SetInt32(msg, field, value);
360 const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
364 msg->GetReflection()->SetEnum(msg, field, pEnumValue);
370 inline bool GetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 *out)
373 CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
374 CHECK_FIELD_REPEATED();
375 CHECK_REPEATED_ELEMENT(index);
377 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
378 *out = (int32)msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
379 else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
380 *out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
382 *out = msg->GetReflection()->GetRepeatedEnum(*msg, field, index)->number();
387 inline bool SetRepeatedInt32OrUnsignedOrEnum(const char *pszFieldName, int index, int32 value)
390 CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
391 CHECK_FIELD_REPEATED();
392 CHECK_REPEATED_ELEMENT(index);
394 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
396 msg->GetReflection()->SetRepeatedUInt32(msg, field, index, (uint32)value);
398 else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
400 msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
404 const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
408 msg->GetReflection()->SetRepeatedEnum(msg, field, index, pEnumValue);
414 inline bool AddInt32OrUnsignedOrEnum(const char *pszFieldName, int32 value)
417 CHECK_FIELD_TYPE3(INT32, UINT32, ENUM);
418 CHECK_FIELD_REPEATED();
420 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
422 msg->GetReflection()->AddUInt32(msg, field, (uint32)value);
424 else if (fieldType == protobuf::FieldDescriptor::CPPTYPE_INT32)
426 msg->GetReflection()->AddInt32(msg, field, value);
430 const protobuf::EnumValueDescriptor *pEnumValue = field->enum_type()->FindValueByNumber(value);
434 msg->GetReflection()->AddEnum(msg, field, pEnumValue);
440 inline bool GetBool(const char *pszFieldName, bool *out)
443 CHECK_FIELD_TYPE(BOOL);
444 CHECK_FIELD_NOT_REPEATED();
446 *out = msg->GetReflection()->GetBool(*msg, field);
450 inline bool SetBool(const char *pszFieldName, bool value)
453 CHECK_FIELD_TYPE(BOOL);
454 CHECK_FIELD_NOT_REPEATED();
456 msg->GetReflection()->SetBool(msg, field, value);
460 inline bool GetRepeatedBool(const char *pszFieldName, int index, bool *out)
463 CHECK_FIELD_TYPE(BOOL);
464 CHECK_FIELD_REPEATED();
465 CHECK_REPEATED_ELEMENT(index);
467 *out = msg->GetReflection()->GetRepeatedBool(*msg, field, index);
471 inline bool SetRepeatedBool(const char *pszFieldName, int index, bool value)
474 CHECK_FIELD_TYPE(BOOL);
475 CHECK_FIELD_REPEATED();
476 CHECK_REPEATED_ELEMENT(index);
478 msg->GetReflection()->SetRepeatedBool(msg, field, index, value);
482 inline bool AddBool(const char *pszFieldName, bool value)
485 CHECK_FIELD_TYPE(BOOL);
486 CHECK_FIELD_REPEATED();
488 msg->GetReflection()->AddBool(msg, field, value);
492 inline bool GetFloat(const char *pszFieldName, float *out)
495 CHECK_FIELD_TYPE(FLOAT);
496 CHECK_FIELD_NOT_REPEATED();
498 *out = msg->GetReflection()->GetFloat(*msg, field);
502 inline bool SetFloat(const char *pszFieldName, float value)
505 CHECK_FIELD_TYPE(FLOAT);
506 CHECK_FIELD_NOT_REPEATED();
508 msg->GetReflection()->SetFloat(msg, field, value);
512 inline bool GetRepeatedFloat(const char *pszFieldName, int index, float *out)
515 CHECK_FIELD_TYPE(FLOAT);
516 CHECK_FIELD_REPEATED();
517 CHECK_REPEATED_ELEMENT(index);
519 *out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index);
523 inline bool SetRepeatedFloat(const char *pszFieldName, int index, float value)
526 CHECK_FIELD_TYPE(FLOAT);
527 CHECK_FIELD_REPEATED();
528 CHECK_REPEATED_ELEMENT(index);
530 msg->GetReflection()->SetRepeatedFloat(msg, field, index, value);
534 inline bool AddFloat(const char *pszFieldName, float value)
537 CHECK_FIELD_TYPE(FLOAT);
538 CHECK_FIELD_REPEATED();
540 msg->GetReflection()->AddFloat(msg, field, value);
544 inline bool GetDouble(const char *pszFieldName, double *out)
547 CHECK_FIELD_TYPE(DOUBLE);
548 CHECK_FIELD_NOT_REPEATED();
550 *out = msg->GetReflection()->GetDouble(*msg, field);
554 inline bool SetDouble(const char *pszFieldName, double value)
557 CHECK_FIELD_TYPE(DOUBLE);
558 CHECK_FIELD_NOT_REPEATED();
560 msg->GetReflection()->SetDouble(msg, field, value);
564 inline bool GetRepeatedDouble(const char *pszFieldName, int index, double *out)
567 CHECK_FIELD_TYPE(DOUBLE);
568 CHECK_FIELD_REPEATED();
569 CHECK_REPEATED_ELEMENT(index);
571 *out = msg->GetReflection()->GetRepeatedDouble(*msg, field, index);
575 inline bool SetRepeatedDouble(const char *pszFieldName, int index, double value)
578 CHECK_FIELD_TYPE(DOUBLE);
579 CHECK_FIELD_REPEATED();
580 CHECK_REPEATED_ELEMENT(index);
582 msg->GetReflection()->SetRepeatedDouble(msg, field, index, value);
586 inline bool AddDouble(const char *pszFieldName, double value)
589 CHECK_FIELD_TYPE(DOUBLE);
590 CHECK_FIELD_REPEATED();
592 msg->GetReflection()->AddDouble(msg, field, value);
596 inline bool GetFloatOrDouble(const char *pszFieldName, float *out)
599 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
600 CHECK_FIELD_NOT_REPEATED();
602 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
603 *out = (float)msg->GetReflection()->GetDouble(*msg, field);
605 *out = msg->GetReflection()->GetFloat(*msg, field);
610 inline bool SetFloatOrDouble(const char *pszFieldName, float value)
613 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
614 CHECK_FIELD_NOT_REPEATED();
616 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
617 msg->GetReflection()->SetDouble(msg, field, (double)value);
619 msg->GetReflection()->SetFloat(msg, field, value);
624 inline bool GetRepeatedFloatOrDouble(const char *pszFieldName, int index, float *out)
627 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
628 CHECK_FIELD_REPEATED();
629 CHECK_REPEATED_ELEMENT(index);
631 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
632 *out = (float)msg->GetReflection()->GetRepeatedDouble(*msg, field, index);
634 *out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index);
639 inline bool SetRepeatedFloatOrDouble(const char *pszFieldName, int index, float value)
642 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
643 CHECK_FIELD_REPEATED();
644 CHECK_REPEATED_ELEMENT(index);
646 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
647 msg->GetReflection()->SetRepeatedDouble(msg, field, index, (double)value);
649 msg->GetReflection()->SetRepeatedFloat(msg, field, index, value);
654 inline bool AddFloatOrDouble(const char *pszFieldName, float value)
657 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
658 CHECK_FIELD_REPEATED();
660 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
661 msg->GetReflection()->AddDouble(msg, field, (double)value);
663 msg->GetReflection()->AddFloat(msg, field, value);
668 inline bool GetString(const char *pszFieldName, char *out, int size)
671 CHECK_FIELD_TYPE(STRING);
672 CHECK_FIELD_NOT_REPEATED();
675 strncopy(out, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str(), size);
680 inline bool SetString(const char *pszFieldName, const char *value)
683 CHECK_FIELD_TYPE(STRING);
684 CHECK_FIELD_NOT_REPEATED();
686 msg->GetReflection()->SetString(msg, field, value);
690 inline bool GetRepeatedString(const char *pszFieldName, int index, char *out, int size)
693 CHECK_FIELD_TYPE(STRING);
694 CHECK_FIELD_REPEATED();
695 CHECK_REPEATED_ELEMENT(index);
698 strncopy(out, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str(), size);
703 inline bool SetRepeatedString(const char *pszFieldName, int index, const char *value)
706 CHECK_FIELD_TYPE(STRING);
707 CHECK_FIELD_REPEATED();
708 CHECK_REPEATED_ELEMENT(index);
710 msg->GetReflection()->SetRepeatedString(msg, field, index, value);
715 inline bool AddString(const char *pszFieldName, const char *value)
718 CHECK_FIELD_TYPE(STRING);
719 CHECK_FIELD_REPEATED();
721 msg->GetReflection()->AddString(msg, field, value);
725 inline bool GetColor(const char *pszFieldName, Color *out)
727 #if SOURCE_ENGINE != SE_CSGO
731 CHECK_FIELD_TYPE(MESSAGE);
732 CHECK_FIELD_NOT_REPEATED();
734 const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetMessage(*msg, field);
746 inline bool SetColor(const char *pszFieldName, const Color &value)
748 #if SOURCE_ENGINE != SE_CSGO
752 CHECK_FIELD_TYPE(MESSAGE);
753 CHECK_FIELD_NOT_REPEATED();
755 CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableMessage(msg, field);
756 msgRGBA->set_r(value.r());
757 msgRGBA->set_g(value.g());
758 msgRGBA->set_b(value.b());
759 msgRGBA->set_a(value.a());
765 inline bool GetRepeatedColor(const char *pszFieldName, int index, Color *out)
767 #if SOURCE_ENGINE != SE_CSGO
771 CHECK_FIELD_TYPE(MESSAGE);
772 CHECK_FIELD_REPEATED();
773 CHECK_REPEATED_ELEMENT(index);
775 const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
787 inline bool SetRepeatedColor(const char *pszFieldName, int index, const Color &value)
789 #if SOURCE_ENGINE != SE_CSGO
793 CHECK_FIELD_TYPE(MESSAGE);
794 CHECK_FIELD_REPEATED();
795 CHECK_REPEATED_ELEMENT(index);
797 CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
798 msgRGBA->set_r(value.r());
799 msgRGBA->set_g(value.g());
800 msgRGBA->set_b(value.b());
801 msgRGBA->set_a(value.a());
807 inline bool AddColor(const char *pszFieldName, const Color &value)
809 #if SOURCE_ENGINE != SE_CSGO
813 CHECK_FIELD_TYPE(MESSAGE);
814 CHECK_FIELD_REPEATED();
816 CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->AddMessage(msg, field);
817 msgRGBA->set_r(value.r());
818 msgRGBA->set_g(value.g());
819 msgRGBA->set_b(value.b());
820 msgRGBA->set_a(value.a());
826 inline bool GetVector2D(const char *pszFieldName, Vector2D *out)
829 CHECK_FIELD_TYPE(MESSAGE);
830 CHECK_FIELD_NOT_REPEATED();
832 const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetMessage(*msg, field);
841 inline bool SetVector2D(const char *pszFieldName, Vector2D &vec)
844 CHECK_FIELD_TYPE(MESSAGE);
845 CHECK_FIELD_NOT_REPEATED();
847 CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableMessage(msg, field);
848 msgVec2d->set_x(vec.x);
849 msgVec2d->set_y(vec.y);
854 inline bool GetRepeatedVector2D(const char *pszFieldName, int index, Vector2D *out)
857 CHECK_FIELD_TYPE(MESSAGE);
858 CHECK_FIELD_REPEATED();
859 CHECK_REPEATED_ELEMENT(index);
861 const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
870 inline bool SetRepeatedVector2D(const char *pszFieldName, int index, Vector2D &vec)
873 CHECK_FIELD_TYPE(MESSAGE);
874 CHECK_FIELD_REPEATED();
875 CHECK_REPEATED_ELEMENT(index);
877 CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
878 msgVec2d->set_x(vec.x);
879 msgVec2d->set_y(vec.y);
884 inline bool AddVector2D(const char *pszFieldName, Vector2D &vec)
887 CHECK_FIELD_TYPE(MESSAGE);
888 CHECK_FIELD_REPEATED();
890 CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->AddMessage(msg, field);
891 msgVec2d->set_x(vec.x);
892 msgVec2d->set_y(vec.y);
897 inline bool GetVector(const char *pszFieldName, Vector *out)
900 CHECK_FIELD_TYPE(MESSAGE);
901 CHECK_FIELD_NOT_REPEATED();
903 const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetMessage(*msg, field);
913 inline bool SetVector(const char *pszFieldName, Vector &vec)
916 CHECK_FIELD_TYPE(MESSAGE);
917 CHECK_FIELD_NOT_REPEATED();
919 CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableMessage(msg, field);
920 msgVec->set_x(vec.x);
921 msgVec->set_y(vec.y);
922 msgVec->set_z(vec.z);
927 inline bool GetRepeatedVector(const char *pszFieldName, int index, Vector *out)
930 CHECK_FIELD_TYPE(MESSAGE);
931 CHECK_FIELD_REPEATED();
932 CHECK_REPEATED_ELEMENT(index);
934 const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
944 inline bool SetRepeatedVector(const char *pszFieldName, int index, Vector &vec)
947 CHECK_FIELD_TYPE(MESSAGE);
948 CHECK_FIELD_REPEATED();
949 CHECK_REPEATED_ELEMENT(index);
951 CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
952 msgVec->set_x(vec.x);
953 msgVec->set_y(vec.y);
954 msgVec->set_z(vec.z);
959 inline bool AddVector(const char *pszFieldName, Vector &vec)
962 CHECK_FIELD_TYPE(MESSAGE);
963 CHECK_FIELD_REPEATED();
965 CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->AddMessage(msg, field);
966 msgVec->set_x(vec.x);
967 msgVec->set_y(vec.y);
968 msgVec->set_z(vec.z);
973 inline bool GetQAngle(const char *pszFieldName, QAngle *out)
976 CHECK_FIELD_TYPE(MESSAGE);
977 CHECK_FIELD_NOT_REPEATED();
979 const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetMessage(*msg, field);
989 inline bool SetQAngle(const char *pszFieldName, QAngle &vec)
992 CHECK_FIELD_TYPE(MESSAGE);
993 CHECK_FIELD_NOT_REPEATED();
995 CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableMessage(msg, field);
996 msgAng->set_x(vec.x);
997 msgAng->set_y(vec.y);
998 msgAng->set_z(vec.z);
1003 inline bool GetRepeatedQAngle(const char *pszFieldName, int index, QAngle *out)
1006 CHECK_FIELD_TYPE(MESSAGE);
1007 CHECK_FIELD_REPEATED();
1008 CHECK_REPEATED_ELEMENT(index);
1010 const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
1020 inline bool SetRepeatedQAngle(const char *pszFieldName, int index, QAngle &vec)
1023 CHECK_FIELD_TYPE(MESSAGE);
1024 CHECK_FIELD_REPEATED();
1025 CHECK_REPEATED_ELEMENT(index);
1027 CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
1028 msgAng->set_x(vec.x);
1029 msgAng->set_y(vec.y);
1030 msgAng->set_z(vec.z);
1035 inline bool AddQAngle(const char *pszFieldName, QAngle &vec)
1038 CHECK_FIELD_TYPE(MESSAGE);
1039 CHECK_FIELD_REPEATED();
1041 CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->AddMessage(msg, field);
1042 msgAng->set_x(vec.x);
1043 msgAng->set_y(vec.y);
1044 msgAng->set_z(vec.z);
1049 inline bool GetMessage(const char *pszFieldName, protobuf::Message **message)
1052 CHECK_FIELD_TYPE(MESSAGE);
1053 CHECK_FIELD_NOT_REPEATED();
1055 *message = msg->GetReflection()->MutableMessage(msg, field);
1060 inline bool GetRepeatedMessage(const char *pszFieldName, int index, const protobuf::Message **message)
1063 CHECK_FIELD_TYPE(MESSAGE);
1064 CHECK_FIELD_REPEATED();
1065 CHECK_REPEATED_ELEMENT(index);
1067 const protobuf::Message *m = &msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
1073 inline bool AddMessage(const char *pszFieldName, protobuf::Message **message)
1076 CHECK_FIELD_TYPE(MESSAGE);
1077 CHECK_FIELD_REPEATED();
1079 *message = msg->GetReflection()->AddMessage(msg, field);
1084 inline int GetRepeatedFieldCount(const char *pszFieldName)
1086 const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \
1090 if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED)
1093 return msg->GetReflection()->FieldSize(*msg, field);
1097 protobuf::Message *msg;
1098 PBHandleList childHandles;
1101 #endif // _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_