3 * =============================================================================
4 * SourceMod (C)2013 AlliedModders LLC. All rights reserved.
5 * =============================================================================
7 * This file is part of the SourceMod/SourcePawn SDK.
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License, version 3.0, as published by the
11 * Free Software Foundation.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
18 * You should have received a copy of the GNU General Public License along with
19 * this program. If not, see <http://www.gnu.org/licenses/>.
21 * As a special exception, AlliedModders LLC gives you permission to link the
22 * code of this program (as well as its derivative works) to "Half-Life 2," the
23 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
24 * by the Valve Corporation. You must obey the GNU General Public License in
25 * all respects for all other code used. Additionally, AlliedModders LLC grants
26 * this exception to all derivative works. AlliedModders LLC defines further
27 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
28 * or <http://www.sourcemod.net/license.php>.
33 #if defined _protobuf_included
36 #define _protobuf_included
38 #define PB_FIELD_NOT_REPEATED -1
41 * Reads an int32, uint32, sint32, fixed32, sfixed32, or enum value from a protobuf message.
43 * @param pb protobuf handle.
44 * @param field Field name.
45 * @param index Index into repeated field.
46 * @return Integer value read.
47 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
49 native PbReadInt(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEATED);
52 * Reads a float or downcasted double from a protobuf message.
54 * @param pb protobuf handle.
55 * @param field Field name.
56 * @param index Index into repeated field.
57 * @return Float value read.
58 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
60 native Float:PbReadFloat(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEATED);
63 * Reads a bool from a protobuf message.
65 * @param pb protobuf handle.
66 * @param field Field name.
67 * @param index Index into repeated field.
68 * @return Boolean value read.
69 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
71 native bool:PbReadBool(Handle:pb, const String:field[], index=PB_FIELD_NOT_REPEATED);
74 * Reads a string from a protobuf message.
76 * @param pb protobuf handle.
77 * @param field Field name.
78 * @param buffer Destination string buffer.
79 * @param maxlength Maximum length of output string buffer.
80 * @param index Index into repeated field.
82 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
84 native PbReadString(Handle:pb, const String:field[], String:buffer[], maxlength, index=PB_FIELD_NOT_REPEATED);
87 * Reads an RGBA color value from a protobuf message.
89 * @param pb protobuf handle.
90 * @param field Field name.
91 * @param buffer Destination color buffer.
92 * @param index Index into repeated field.
94 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
96 native PbReadColor(Handle:pb, const String:field[], buffer[4], index=PB_FIELD_NOT_REPEATED);
99 * Reads an XYZ angle value from a protobuf message.
101 * @param pb protobuf handle.
102 * @param field Field name.
103 * @param buffer Destination angle buffer.
104 * @param index Index into repeated field.
106 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
108 native PbReadAngle(Handle:pb, const String:field[], Float:buffer[3], index=PB_FIELD_NOT_REPEATED);
111 * Reads an XYZ vector value from a protobuf message.
113 * @param pb protobuf handle.
114 * @param field Field name.
115 * @param buffer Destination vector buffer.
116 * @param index Index into repeated field.
118 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
120 native PbReadVector(Handle:pb, const String:field[], Float:buffer[3], index=PB_FIELD_NOT_REPEATED);
123 * Reads an XY vector value from a protobuf message.
125 * @param pb protobuf handle.
126 * @param field Field name.
127 * @param buffer Destination vector buffer.
128 * @param index Index into repeated field.
130 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
132 native PbReadVector2D(Handle:pb, const String:field[], Float:buffer[2], index=PB_FIELD_NOT_REPEATED);
135 * Gets the number of elements in a repeated field of a protobuf message.
137 * @param pb protobuf handle.
138 * @param field Field name.
139 * @return Number of elements in the field.
140 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
142 native PbGetRepeatedFieldCount(Handle:pb, const String:field[]);
145 * Sets an int32, uint32, sint32, fixed32, sfixed32, or enum value on a protobuf message.
147 * @param pb protobuf handle.
148 * @param field Field name.
149 * @param value Integer value to set.
150 * @param index Index into repeated field.
152 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
154 native PbSetInt(Handle:pb, const String:field[], value, index=PB_FIELD_NOT_REPEATED);
157 * Sets a float or double on a protobuf message.
159 * @param pb protobuf handle.
160 * @param field Field name.
161 * @param value Float value to set.
162 * @param index Index into repeated field.
164 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
166 native PbSetFloat(Handle:pb, const String:field[], Float:value, index=PB_FIELD_NOT_REPEATED);
169 * Sets a bool on a protobuf message.
171 * @param pb protobuf handle.
172 * @param field Field name.
173 * @param value Boolean value to set.
174 * @param index Index into repeated field.
176 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
178 native PbSetBool(Handle:pb, const String:field[], bool:value, index=PB_FIELD_NOT_REPEATED);
181 * Sets a string on a protobuf message.
183 * @param pb protobuf handle.
184 * @param field Field name.
185 * @param value String value to set.
186 * @param index Index into repeated field.
188 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
190 native PbSetString(Handle:pb, const String:field[], const String:value[], index=PB_FIELD_NOT_REPEATED);
193 * Sets an RGBA color on a protobuf message.
195 * @param pb protobuf handle.
196 * @param field Field name.
197 * @param color Color value to set.
198 * @param index Index into repeated field.
200 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
202 native PbSetColor(Handle:pb, const String:field[], const color[4], index=PB_FIELD_NOT_REPEATED);
205 * Sets an XYZ angle on a protobuf message.
207 * @param pb protobuf handle.
208 * @param field Field name.
209 * @param angle Angle value to set.
210 * @param index Index into repeated field.
212 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
214 native PbSetAngle(Handle:pb, const String:field[], const Float:angle[3], index=PB_FIELD_NOT_REPEATED);
217 * Sets an XYZ vector on a protobuf message.
219 * @param pb protobuf handle.
220 * @param field Field name.
221 * @param vec Vector value to set.
222 * @param index Index into repeated field.
224 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
226 native PbSetVector(Handle:pb, const String:field[], const Float:vec[3], index=PB_FIELD_NOT_REPEATED);
229 * Sets an XY vector on a protobuf message.
231 * @param pb protobuf handle.
232 * @param field Field name.
233 * @param vec Vector value to set.
234 * @param index Index into repeated field.
236 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
238 native PbSetVector2D(Handle:pb, const String:field[], const Float:vec[2], index=PB_FIELD_NOT_REPEATED);
241 * Add an int32, uint32, sint32, fixed32, sfixed32, or enum value to a protobuf message repeated field.
243 * @param pb protobuf handle.
244 * @param field Field name.
245 * @param value Integer value to add.
247 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
249 native PbAddInt(Handle:pb, const String:field[], value);
252 * Add a float or double to a protobuf message repeated field.
254 * @param pb protobuf handle.
255 * @param field Field name.
256 * @param value Float value to add.
258 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
260 native PbAddFloat(Handle:pb, const String:field[], Float:value);
263 * Add a bool to a protobuf message repeated field.
265 * @param pb protobuf handle.
266 * @param field Field name.
267 * @param value Boolean value to add.
269 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
271 native PbAddBool(Handle:pb, const String:field[], bool:value);
274 * Add a string to a protobuf message repeated field.
276 * @param pb protobuf handle.
277 * @param field Field name.
278 * @param value String value to add.
280 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
282 native PbAddString(Handle:pb, const String:field[], const String:value[]);
285 * Add an RGBA color to a protobuf message repeated field.
287 * @param pb protobuf handle.
288 * @param field Field name.
289 * @param color Color value to add.
291 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
293 native PbAddColor(Handle:pb, const String:field[], const color[4]);
296 * Add an XYZ angle to a protobuf message repeated field.
298 * @param pb protobuf handle.
299 * @param field Field name.
300 * @param angle Angle value to add.
302 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
304 native PbAddAngle(Handle:pb, const String:field[], const Float:angle[3]);
307 * Add an XYZ vector to a protobuf message repeated field.
309 * @param pb protobuf handle.
310 * @param field Field name.
311 * @param vec Vector value to add.
313 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
315 native PbAddVector(Handle:pb, const String:field[], const Float:vec[3]);
318 * Add an XY vector to a protobuf message repeated field.
320 * @param pb protobuf handle.
321 * @param field Field name.
322 * @param vec Vector value to add.
324 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
326 native PbAddVector2D(Handle:pb, const String:field[], const Float:vec[2]);
329 * Retrieve a handle to an embedded protobuf message in a protobuf message.
331 * @param pb protobuf handle.
332 * @param field Field name.
333 * @return protobuf handle to embedded message.
334 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
336 native Handle:PbReadMessage(Handle:pb, const String:field[]);
339 * Retrieve a handle to an embedded protobuf message in a protobuf message repeated field.
341 * @param pb protobuf handle.
342 * @param field Field name.
343 * @param index Index in the repeated field.
344 * @return protobuf handle to embedded message.
345 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
347 native Handle:PbReadRepeatedMessage(Handle:pb, const String:field[], index);
350 * Adds an embedded protobuf message to a protobuf message repeated field.
352 * @param pb protobuf handle.
353 * @param field Field name.
354 * @return protobuf handle to added, embedded message.
355 * @error Invalid or incorrect Handle, non-existent field, or incorrect field type.
357 native Handle:PbAddMessage(Handle:pb, const String:field[]);