Fix protobuf builds.
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_REPEATED() \
60 if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED) \
65 #define CHECK_FIELD_NOT_REPEATED() \
66 if (field->label() == protobuf::FieldDescriptor::LABEL_REPEATED) \
71 #define CHECK_REPEATED_ELEMENT(idx) \
72 int elemCount = msg->GetReflection()->FieldSize(*msg, field); \
73 if (elemCount == 0 || idx >= elemCount || idx < 0) \
78 typedef List<Handle_t> PBHandleList;
80 class SMProtobufMessage
83 SMProtobufMessage( protobuf::Message *message )
90 PBHandleList::iterator iter = childHandles.begin();
91 while (iter != childHandles.end())
93 Handle_t &hndl = (*iter);
95 sec.pIdentity = g_pCoreIdent;
96 handlesys->FreeHandle(hndl, &sec);
97 iter = childHandles.erase(iter);
101 inline void AddChildHandle(Handle_t hndl)
103 childHandles.push_back(hndl);
106 inline protobuf::Message *GetProtobufMessage()
111 inline bool GetInt32(const char *pszFieldName, int32 *out)
114 CHECK_FIELD_TYPE(INT32);
115 CHECK_FIELD_NOT_REPEATED();
117 *out = msg->GetReflection()->GetInt32(*msg, field);
121 inline bool SetInt32(const char *pszFieldName, int32 value)
124 CHECK_FIELD_TYPE(INT32);
125 CHECK_FIELD_NOT_REPEATED();
127 msg->GetReflection()->SetInt32(msg, field, value);
131 inline bool GetRepeatedInt32(const char *pszFieldName, int index, int32 *out)
134 CHECK_FIELD_TYPE(INT32);
135 CHECK_FIELD_REPEATED();
136 CHECK_REPEATED_ELEMENT(index);
138 *out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
142 inline bool SetRepeatedInt32(const char *pszFieldName, int index, int32 value)
145 CHECK_FIELD_TYPE(INT32);
146 CHECK_FIELD_REPEATED();
147 CHECK_REPEATED_ELEMENT(index);
149 msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
153 inline bool AddInt32(const char *pszFieldName, int32 value)
156 CHECK_FIELD_TYPE(INT32);
157 CHECK_FIELD_REPEATED();
159 msg->GetReflection()->AddInt32(msg, field, value);
163 inline bool GetInt64(const char *pszFieldName, int64 *out)
166 CHECK_FIELD_TYPE(INT64);
167 CHECK_FIELD_NOT_REPEATED();
169 *out = msg->GetReflection()->GetInt64(*msg, field);
173 inline bool SetInt64(const char *pszFieldName, int64 value)
176 CHECK_FIELD_TYPE(INT64);
177 CHECK_FIELD_NOT_REPEATED();
179 msg->GetReflection()->SetInt64(msg, field, value);
183 inline bool GetRepeatedInt64(const char *pszFieldName, int index, int64 *out)
186 CHECK_FIELD_TYPE(INT64);
187 CHECK_FIELD_REPEATED();
188 CHECK_REPEATED_ELEMENT(index);
190 *out = msg->GetReflection()->GetRepeatedInt64(*msg, field, index);
194 inline bool SetRepeatedInt64(const char *pszFieldName, int index, int64 value)
197 CHECK_FIELD_TYPE(INT64);
198 CHECK_FIELD_REPEATED();
199 CHECK_REPEATED_ELEMENT(index);
201 msg->GetReflection()->SetRepeatedInt64(msg, field, index, value);
205 inline bool AddInt64(const char *pszFieldName, int64 value)
208 CHECK_FIELD_TYPE(INT64);
209 CHECK_FIELD_REPEATED();
211 msg->GetReflection()->AddInt64(msg, field, value);
215 inline bool GetUInt32(const char *pszFieldName, uint32 *out)
218 CHECK_FIELD_TYPE(UINT32);
219 CHECK_FIELD_NOT_REPEATED();
221 *out = msg->GetReflection()->GetUInt32(*msg, field);
225 inline bool SetUInt32(const char *pszFieldName, uint32 value)
228 CHECK_FIELD_TYPE(UINT32);
229 CHECK_FIELD_NOT_REPEATED();
231 msg->GetReflection()->SetUInt32(msg, field, value);
235 inline bool GetRepeatedUInt32(const char *pszFieldName, int index, uint32 *out)
238 CHECK_FIELD_TYPE(UINT32);
239 CHECK_FIELD_REPEATED();
240 CHECK_REPEATED_ELEMENT(index);
242 *out = msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
246 inline bool SetRepeatedUInt32(const char *pszFieldName, int index, uint32 value)
249 CHECK_FIELD_TYPE(UINT32);
250 CHECK_FIELD_REPEATED();
251 CHECK_REPEATED_ELEMENT(index);
253 msg->GetReflection()->SetRepeatedUInt32(msg, field, index, value);
257 inline bool AddUInt32(const char *pszFieldName, uint32 value)
260 CHECK_FIELD_TYPE(UINT32);
261 CHECK_FIELD_REPEATED();
263 msg->GetReflection()->AddUInt32(msg, field, value);
267 inline bool GetUInt64(const char *pszFieldName, uint64 *out)
270 CHECK_FIELD_TYPE(UINT64);
271 CHECK_FIELD_NOT_REPEATED();
273 *out = msg->GetReflection()->GetUInt64(*msg, field);
277 inline bool SetUInt64(const char *pszFieldName, uint64 value)
280 CHECK_FIELD_TYPE(UINT64);
281 CHECK_FIELD_NOT_REPEATED();
283 msg->GetReflection()->SetUInt64(msg, field, value);
287 inline bool GetRepeatedUInt64(const char *pszFieldName, int index, uint64 *out)
290 CHECK_FIELD_TYPE(UINT64);
291 CHECK_FIELD_REPEATED();
292 CHECK_REPEATED_ELEMENT(index);
294 *out = msg->GetReflection()->GetRepeatedUInt64(*msg, field, index);
298 inline bool SetRepeatedUInt64(const char *pszFieldName, int index, uint64 value)
301 CHECK_FIELD_TYPE(UINT64);
302 CHECK_FIELD_REPEATED();
303 CHECK_REPEATED_ELEMENT(index);
305 msg->GetReflection()->SetRepeatedUInt64(msg, field, index, value);
309 inline bool AddUInt64(const char *pszFieldName, uint64 value)
312 CHECK_FIELD_TYPE(UINT64);
313 CHECK_FIELD_REPEATED();
315 msg->GetReflection()->AddUInt32(msg, field, value);
319 inline bool GetInt32OrUnsigned(const char *pszFieldName, int32 *out)
322 CHECK_FIELD_TYPE2(INT32, UINT32);
323 CHECK_FIELD_NOT_REPEATED();
325 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
326 *out = (int32)msg->GetReflection()->GetUInt32(*msg, field);
328 *out = msg->GetReflection()->GetInt32(*msg, field);
333 inline bool SetInt32OrUnsigned(const char *pszFieldName, int32 value)
336 CHECK_FIELD_TYPE2(INT32, UINT32);
337 CHECK_FIELD_NOT_REPEATED();
339 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
340 msg->GetReflection()->SetUInt32(msg, field, (uint32)value);
342 msg->GetReflection()->SetInt32(msg, field, value);
347 inline bool GetRepeatedInt32OrUnsigned(const char *pszFieldName, int index, int32 *out)
350 CHECK_FIELD_TYPE2(INT32, UINT32);
351 CHECK_FIELD_REPEATED();
352 CHECK_REPEATED_ELEMENT(index);
354 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
355 *out = (int32)msg->GetReflection()->GetRepeatedUInt32(*msg, field, index);
357 *out = msg->GetReflection()->GetRepeatedInt32(*msg, field, index);
362 inline bool SetRepeatedInt32OrUnsigned(const char *pszFieldName, int index, int32 value)
365 CHECK_FIELD_TYPE2(INT32, UINT32);
366 CHECK_FIELD_REPEATED();
367 CHECK_REPEATED_ELEMENT(index);
369 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
370 msg->GetReflection()->SetRepeatedUInt32(msg, field, index, (uint32)value);
372 msg->GetReflection()->SetRepeatedInt32(msg, field, index, value);
377 inline bool AddInt32OrUnsigned(const char *pszFieldName, int32 value)
380 CHECK_FIELD_TYPE2(INT32, UINT32);
381 CHECK_FIELD_REPEATED();
383 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_UINT32)
384 msg->GetReflection()->AddUInt32(msg, field, (uint32)value);
386 msg->GetReflection()->AddInt32(msg, field, value);
391 inline bool GetBool(const char *pszFieldName, bool *out)
394 CHECK_FIELD_TYPE(BOOL);
395 CHECK_FIELD_NOT_REPEATED();
397 *out = msg->GetReflection()->GetBool(*msg, field);
401 inline bool SetBool(const char *pszFieldName, bool value)
404 CHECK_FIELD_TYPE(BOOL);
405 CHECK_FIELD_NOT_REPEATED();
407 msg->GetReflection()->SetBool(msg, field, value);
411 inline bool GetRepeatedBool(const char *pszFieldName, int index, bool *out)
414 CHECK_FIELD_TYPE(BOOL);
415 CHECK_FIELD_REPEATED();
416 CHECK_REPEATED_ELEMENT(index);
418 *out = msg->GetReflection()->GetRepeatedBool(*msg, field, index);
422 inline bool SetRepeatedBool(const char *pszFieldName, int index, bool value)
425 CHECK_FIELD_TYPE(BOOL);
426 CHECK_FIELD_REPEATED();
427 CHECK_REPEATED_ELEMENT(index);
429 msg->GetReflection()->SetRepeatedBool(msg, field, index, value);
433 inline bool AddBool(const char *pszFieldName, bool value)
436 CHECK_FIELD_TYPE(BOOL);
437 CHECK_FIELD_REPEATED();
439 msg->GetReflection()->AddBool(msg, field, value);
443 inline bool GetFloat(const char *pszFieldName, float *out)
446 CHECK_FIELD_TYPE(FLOAT);
447 CHECK_FIELD_NOT_REPEATED();
449 *out = msg->GetReflection()->GetFloat(*msg, field);
453 inline bool SetFloat(const char *pszFieldName, float value)
456 CHECK_FIELD_TYPE(FLOAT);
457 CHECK_FIELD_NOT_REPEATED();
459 msg->GetReflection()->SetFloat(msg, field, value);
463 inline bool GetRepeatedFloat(const char *pszFieldName, int index, float *out)
466 CHECK_FIELD_TYPE(FLOAT);
467 CHECK_FIELD_REPEATED();
468 CHECK_REPEATED_ELEMENT(index);
470 *out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index);
474 inline bool SetRepeatedFloat(const char *pszFieldName, int index, float value)
477 CHECK_FIELD_TYPE(FLOAT);
478 CHECK_FIELD_REPEATED();
479 CHECK_REPEATED_ELEMENT(index);
481 msg->GetReflection()->SetRepeatedFloat(msg, field, index, value);
485 inline bool AddFloat(const char *pszFieldName, float value)
488 CHECK_FIELD_TYPE(FLOAT);
489 CHECK_FIELD_REPEATED();
491 msg->GetReflection()->AddFloat(msg, field, value);
495 inline bool GetDouble(const char *pszFieldName, double *out)
498 CHECK_FIELD_TYPE(DOUBLE);
499 CHECK_FIELD_NOT_REPEATED();
501 *out = msg->GetReflection()->GetDouble(*msg, field);
505 inline bool SetDouble(const char *pszFieldName, double value)
508 CHECK_FIELD_TYPE(DOUBLE);
509 CHECK_FIELD_NOT_REPEATED();
511 msg->GetReflection()->SetDouble(msg, field, value);
515 inline bool GetRepeatedDouble(const char *pszFieldName, int index, double *out)
518 CHECK_FIELD_TYPE(DOUBLE);
519 CHECK_FIELD_REPEATED();
520 CHECK_REPEATED_ELEMENT(index);
522 *out = msg->GetReflection()->GetRepeatedDouble(*msg, field, index);
526 inline bool SetRepeatedDouble(const char *pszFieldName, int index, double value)
529 CHECK_FIELD_TYPE(DOUBLE);
530 CHECK_FIELD_REPEATED();
531 CHECK_REPEATED_ELEMENT(index);
533 msg->GetReflection()->SetRepeatedDouble(msg, field, index, value);
537 inline bool AddDouble(const char *pszFieldName, double value)
540 CHECK_FIELD_TYPE(DOUBLE);
541 CHECK_FIELD_REPEATED();
543 msg->GetReflection()->AddDouble(msg, field, value);
547 inline bool GetFloatOrDouble(const char *pszFieldName, float *out)
550 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
551 CHECK_FIELD_NOT_REPEATED();
553 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
554 *out = (float)msg->GetReflection()->GetDouble(*msg, field);
556 *out = msg->GetReflection()->GetFloat(*msg, field);
561 inline bool SetFloatOrDouble(const char *pszFieldName, float value)
564 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
565 CHECK_FIELD_NOT_REPEATED();
567 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
568 msg->GetReflection()->SetDouble(msg, field, (double)value);
570 msg->GetReflection()->SetFloat(msg, field, value);
575 inline bool GetRepeatedFloatOrDouble(const char *pszFieldName, int index, float *out)
578 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
579 CHECK_FIELD_REPEATED();
580 CHECK_REPEATED_ELEMENT(index);
582 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
583 *out = (float)msg->GetReflection()->GetRepeatedDouble(*msg, field, index);
585 *out = msg->GetReflection()->GetRepeatedFloat(*msg, field, index);
590 inline bool SetRepeatedFloatOrDouble(const char *pszFieldName, int index, float value)
593 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
594 CHECK_FIELD_REPEATED();
595 CHECK_REPEATED_ELEMENT(index);
597 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
598 msg->GetReflection()->SetRepeatedDouble(msg, field, index, (double)value);
600 msg->GetReflection()->SetRepeatedFloat(msg, field, index, value);
605 inline bool AddFloatOrDouble(const char *pszFieldName, float value)
608 CHECK_FIELD_TYPE2(FLOAT, DOUBLE);
609 CHECK_FIELD_REPEATED();
611 if (fieldType == protobuf::FieldDescriptor::CPPTYPE_DOUBLE)
612 msg->GetReflection()->AddDouble(msg, field, (double)value);
614 msg->GetReflection()->AddFloat(msg, field, value);
619 inline bool GetString(const char *pszFieldName, char *out, int size)
622 CHECK_FIELD_TYPE(STRING);
623 CHECK_FIELD_NOT_REPEATED();
626 strncopy(out, msg->GetReflection()->GetStringReference(*msg, field, &scratch).c_str(), size);
631 inline bool SetString(const char *pszFieldName, const char *value)
634 CHECK_FIELD_TYPE(STRING);
635 CHECK_FIELD_NOT_REPEATED();
637 msg->GetReflection()->SetString(msg, field, value);
641 inline bool GetRepeatedString(const char *pszFieldName, int index, char *out, int size)
644 CHECK_FIELD_TYPE(STRING);
645 CHECK_FIELD_REPEATED();
646 CHECK_REPEATED_ELEMENT(index);
649 strncopy(out, msg->GetReflection()->GetRepeatedStringReference(*msg, field, index, &scratch).c_str(), size);
654 inline bool SetRepeatedString(const char *pszFieldName, int index, const char *value)
657 CHECK_FIELD_TYPE(STRING);
658 CHECK_FIELD_REPEATED();
659 CHECK_REPEATED_ELEMENT(index);
661 msg->GetReflection()->SetRepeatedString(msg, field, index, value);
666 inline bool AddString(const char *pszFieldName, const char *value)
669 CHECK_FIELD_TYPE(STRING);
670 CHECK_FIELD_REPEATED();
672 msg->GetReflection()->AddString(msg, field, value);
676 inline bool GetColor(const char *pszFieldName, Color *out)
678 #if SOURCE_ENGINE != SE_CSGO
682 CHECK_FIELD_TYPE(MESSAGE);
683 CHECK_FIELD_NOT_REPEATED();
685 const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetMessage(*msg, field);
697 inline bool SetColor(const char *pszFieldName, const Color &value)
699 #if SOURCE_ENGINE != SE_CSGO
703 CHECK_FIELD_TYPE(MESSAGE);
704 CHECK_FIELD_NOT_REPEATED();
706 CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableMessage(msg, field);
707 msgRGBA->set_r(value.r());
708 msgRGBA->set_g(value.g());
709 msgRGBA->set_b(value.b());
710 msgRGBA->set_a(value.a());
716 inline bool GetRepeatedColor(const char *pszFieldName, int index, Color *out)
718 #if SOURCE_ENGINE != SE_CSGO
722 CHECK_FIELD_TYPE(MESSAGE);
723 CHECK_FIELD_REPEATED();
724 CHECK_REPEATED_ELEMENT(index);
726 const CMsgRGBA &msgRGBA = (const CMsgRGBA &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
738 inline bool SetRepeatedColor(const char *pszFieldName, int index, const Color &value)
740 #if SOURCE_ENGINE != SE_CSGO
744 CHECK_FIELD_TYPE(MESSAGE);
745 CHECK_FIELD_REPEATED();
746 CHECK_REPEATED_ELEMENT(index);
748 CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
749 msgRGBA->set_r(value.r());
750 msgRGBA->set_g(value.g());
751 msgRGBA->set_b(value.b());
752 msgRGBA->set_a(value.a());
758 inline bool AddColor(const char *pszFieldName, const Color &value)
760 #if SOURCE_ENGINE != SE_CSGO
764 CHECK_FIELD_TYPE(MESSAGE);
765 CHECK_FIELD_REPEATED();
767 CMsgRGBA *msgRGBA = (CMsgRGBA *)msg->GetReflection()->AddMessage(msg, field);
768 msgRGBA->set_r(value.r());
769 msgRGBA->set_g(value.g());
770 msgRGBA->set_b(value.b());
771 msgRGBA->set_a(value.a());
777 inline bool GetVector2D(const char *pszFieldName, Vector2D *out)
780 CHECK_FIELD_TYPE(MESSAGE);
781 CHECK_FIELD_NOT_REPEATED();
783 const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetMessage(*msg, field);
792 inline bool SetVector2D(const char *pszFieldName, Vector2D &vec)
795 CHECK_FIELD_TYPE(MESSAGE);
796 CHECK_FIELD_NOT_REPEATED();
798 CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableMessage(msg, field);
799 msgVec2d->set_x(vec.x);
800 msgVec2d->set_y(vec.y);
805 inline bool GetRepeatedVector2D(const char *pszFieldName, int index, Vector2D *out)
808 CHECK_FIELD_TYPE(MESSAGE);
809 CHECK_FIELD_REPEATED();
810 CHECK_REPEATED_ELEMENT(index);
812 const CMsgVector2D &msgVec2d = (const CMsgVector2D &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
821 inline bool SetRepeatedVector2D(const char *pszFieldName, int index, Vector2D &vec)
824 CHECK_FIELD_TYPE(MESSAGE);
825 CHECK_FIELD_REPEATED();
826 CHECK_REPEATED_ELEMENT(index);
828 CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
829 msgVec2d->set_x(vec.x);
830 msgVec2d->set_y(vec.y);
835 inline bool AddVector2D(const char *pszFieldName, Vector2D &vec)
838 CHECK_FIELD_TYPE(MESSAGE);
839 CHECK_FIELD_REPEATED();
841 CMsgVector2D *msgVec2d = (CMsgVector2D *)msg->GetReflection()->AddMessage(msg, field);
842 msgVec2d->set_x(vec.x);
843 msgVec2d->set_y(vec.y);
848 inline bool GetVector(const char *pszFieldName, Vector *out)
851 CHECK_FIELD_TYPE(MESSAGE);
852 CHECK_FIELD_NOT_REPEATED();
854 const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetMessage(*msg, field);
864 inline bool SetVector(const char *pszFieldName, Vector &vec)
867 CHECK_FIELD_TYPE(MESSAGE);
868 CHECK_FIELD_NOT_REPEATED();
870 CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableMessage(msg, field);
871 msgVec->set_x(vec.x);
872 msgVec->set_y(vec.y);
873 msgVec->set_z(vec.z);
878 inline bool GetRepeatedVector(const char *pszFieldName, int index, Vector *out)
881 CHECK_FIELD_TYPE(MESSAGE);
882 CHECK_FIELD_REPEATED();
883 CHECK_REPEATED_ELEMENT(index);
885 const CMsgVector &msgVec = (const CMsgVector &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
895 inline bool SetRepeatedVector(const char *pszFieldName, int index, Vector &vec)
898 CHECK_FIELD_TYPE(MESSAGE);
899 CHECK_FIELD_REPEATED();
900 CHECK_REPEATED_ELEMENT(index);
902 CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
903 msgVec->set_x(vec.x);
904 msgVec->set_y(vec.y);
905 msgVec->set_z(vec.z);
910 inline bool AddVector(const char *pszFieldName, Vector &vec)
913 CHECK_FIELD_TYPE(MESSAGE);
914 CHECK_FIELD_REPEATED();
916 CMsgVector *msgVec = (CMsgVector *)msg->GetReflection()->AddMessage(msg, field);
917 msgVec->set_x(vec.x);
918 msgVec->set_y(vec.y);
919 msgVec->set_z(vec.z);
924 inline bool GetQAngle(const char *pszFieldName, QAngle *out)
927 CHECK_FIELD_TYPE(MESSAGE);
928 CHECK_FIELD_NOT_REPEATED();
930 const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetMessage(*msg, field);
940 inline bool SetQAngle(const char *pszFieldName, QAngle &vec)
943 CHECK_FIELD_TYPE(MESSAGE);
944 CHECK_FIELD_NOT_REPEATED();
946 CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableMessage(msg, field);
947 msgAng->set_x(vec.x);
948 msgAng->set_y(vec.y);
949 msgAng->set_z(vec.z);
954 inline bool GetRepeatedQAngle(const char *pszFieldName, int index, QAngle *out)
957 CHECK_FIELD_TYPE(MESSAGE);
958 CHECK_FIELD_REPEATED();
959 CHECK_REPEATED_ELEMENT(index);
961 const CMsgQAngle &msgAng = (const CMsgQAngle &)msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
971 inline bool SetRepeatedQAngle(const char *pszFieldName, int index, QAngle &vec)
974 CHECK_FIELD_TYPE(MESSAGE);
975 CHECK_FIELD_REPEATED();
976 CHECK_REPEATED_ELEMENT(index);
978 CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->MutableRepeatedMessage(msg, field, index);
979 msgAng->set_x(vec.x);
980 msgAng->set_y(vec.y);
981 msgAng->set_z(vec.z);
986 inline bool AddQAngle(const char *pszFieldName, QAngle &vec)
989 CHECK_FIELD_TYPE(MESSAGE);
990 CHECK_FIELD_REPEATED();
992 CMsgQAngle *msgAng = (CMsgQAngle *)msg->GetReflection()->AddMessage(msg, field);
993 msgAng->set_x(vec.x);
994 msgAng->set_y(vec.y);
995 msgAng->set_z(vec.z);
1000 inline bool GetMessage(const char *pszFieldName, protobuf::Message **message)
1003 CHECK_FIELD_TYPE(MESSAGE);
1004 CHECK_FIELD_NOT_REPEATED();
1006 *message = msg->GetReflection()->MutableMessage(msg, field);
1011 inline bool GetRepeatedMessage(const char *pszFieldName, int index, const protobuf::Message **message)
1014 CHECK_FIELD_TYPE(MESSAGE);
1015 CHECK_FIELD_REPEATED();
1016 CHECK_REPEATED_ELEMENT(index);
1018 const protobuf::Message *m = &msg->GetReflection()->GetRepeatedMessage(*msg, field, index);
1024 inline bool AddMessage(const char *pszFieldName, protobuf::Message **message)
1027 CHECK_FIELD_TYPE(MESSAGE);
1028 CHECK_FIELD_REPEATED();
1030 *message = msg->GetReflection()->AddMessage(msg, field);
1035 inline int GetRepeatedFieldCount(const char *pszFieldName)
1037 const protobuf::FieldDescriptor *field = msg->GetDescriptor()->FindFieldByName(pszFieldName); \
1041 if (field->label() != protobuf::FieldDescriptor::LABEL_REPEATED)
1044 return msg->GetReflection()->FieldSize(*msg, field);
1048 protobuf::Message *msg;
1049 PBHandleList childHandles;
1052 #endif // _INCLUDE_SOURCEMOD_SMPBMESSAGE_H_