plugins/include/protobuf.inc
author Nicholas Hastings <skamonkey@gmail.com>
Wed Jan 23 18:28:06 2013 -0500 (2013-01-23)
changeset 3756 114d52909940
parent 3743 a98686a77974
child 3813 bf1faf4a16c9
permissions -rw-r--r--
Marked some missed Pb natives as optional (bug 5579).
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod (C)2013 AlliedModders LLC.  All rights reserved.
     5  * =============================================================================
     6  *
     7  * This file is part of the SourceMod/SourcePawn SDK.
     8  *
     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.
    12  * 
    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
    16  * details.
    17  *
    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/>.
    20  *
    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>.
    29  *
    30  * Version: $Id$
    31  */
    32  
    33 #if defined _protobuf_included
    34 #endinput
    35 #endif
    36 #define _protobuf_included
    37 
    38 /**
    39  * Reads an int32, uint32, sint32, fixed32, or sfixed32 from a protobuf message.
    40  *
    41  * @param pb			protobuf handle.
    42  * @param field			Field name.
    43  * @return				Integer value read.
    44  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
    45  */
    46 native PbReadInt(Handle:pb, const String:field[]);
    47 
    48 /**
    49  * Reads a float or downcasted double from a protobuf message.
    50  *
    51  * @param pb			protobuf handle.
    52  * @param field			Field name.
    53  * @return				Float value read.
    54  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
    55  */
    56 native Float:PbReadFloat(Handle:pb, const String:field[]);
    57 
    58 /**
    59  * Reads a bool from a protobuf message.
    60  *
    61  * @param pb			protobuf handle.
    62  * @param field			Field name.
    63  * @return				Boolean value read.
    64  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
    65  */
    66 native bool:PbReadBool(Handle:pb, const String:field[]);
    67 
    68 /**
    69  * Reads a string from a protobuf message.
    70  *
    71  * @param pb			protobuf handle.
    72  * @param field			Field name.
    73  * @param buffer		Destination string buffer.
    74  * @param maxlength		Maximum length of output string buffer.
    75  * @noreturn
    76  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
    77  */
    78 native PbReadString(Handle:pb, const String:field[], String:buffer[], maxlength);
    79 
    80 /**
    81  * Reads an RGBA color value from a protobuf message.
    82  *
    83  * @param pb			protobuf handle.
    84  * @param field			Field name.
    85  * @param buffer		Destination color buffer.
    86  * @noreturn
    87  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
    88  */
    89 native PbReadColor(Handle:pb, const String:field[], buffer[4]);
    90 
    91 /**
    92  * Reads an XYZ angle value from a protobuf message.
    93  *
    94  * @param pb			protobuf handle.
    95  * @param field			Field name.
    96  * @param buffer		Destination angle buffer.
    97  * @noreturn
    98  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
    99  */
   100 native PbReadAngle(Handle:pb, const String:field[], Float:buffer[3]);
   101 
   102 /**
   103  * Reads an XYZ vector value from a protobuf message.
   104  *
   105  * @param pb			protobuf handle.
   106  * @param field			Field name.
   107  * @param buffer		Destination vector buffer.
   108  * @noreturn
   109  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   110  */
   111 native PbReadVector(Handle:pb, const String:field[], Float:buffer[3]);
   112 
   113 /**
   114  * Reads an XY vector value from a protobuf message.
   115  *
   116  * @param pb			protobuf handle.
   117  * @param field			Field name.
   118  * @param buffer		Destination vector buffer.
   119  * @noreturn
   120  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   121  */
   122 native PbReadVector2D(Handle:pb, const String:field[], Float:buffer[2]);
   123 
   124 /**
   125  * Gets the number of elements in a repeated field of a protobuf message.
   126  *
   127  * @param pb			protobuf handle.
   128  * @param field			Field name.
   129  * @return				Number of elements in the field.
   130  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   131  */
   132 native PbGetRepeatedFieldCount(Handle:pb, const String:field[]);
   133 
   134 /**
   135  * Reads an int32, uint32, sint32, fixed32, or sfixed32 from a protobuf message repeated field.
   136  *
   137  * @param pb			protobuf handle.
   138  * @param field			Field name.
   139  * @param index			Index in the repeated field.
   140  * @return				Integer value read.
   141  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   142  */
   143 native PbReadRepeatedInt(Handle:pb, const String:field[], index);
   144 
   145 /**
   146  * Reads a float or downcasted double from a protobuf message repeated field.
   147  *
   148  * @param pb			protobuf handle.
   149  * @param field			Field name.
   150  * @param index			Index in the repeated field.
   151  * @return				Float value read.
   152  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   153  */
   154 native Float:PbReadRepeatedFloat(Handle:pb, const String:field[], index);
   155 
   156 /**
   157  * Reads a bool from a protobuf message repeated field.
   158  *
   159  * @param pb			protobuf handle.
   160  * @param field			Field name.
   161  * @param index			Index in the repeated field.
   162  * @return				Boolean value read.
   163  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   164  */
   165 native bool:PbReadRepeatedBool(Handle:pb, const String:field[], index);
   166 
   167 /**
   168  * Reads a string from a protobuf message repeated field.
   169  *
   170  * @param pb			protobuf handle.
   171  * @param field			Field name.
   172  * @param index			Index in the repeated field.
   173  * @param buffer		Destination string buffer.
   174  * @param maxlength		Maximum length of output string buffer.
   175  * @noreturn
   176  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   177  */
   178 native PbReadRepeatedString(Handle:pb, const String:field[], index, String:buffer[], size);
   179 
   180 /**
   181  * Reads an RGBA color value from a protobuf message repeated field.
   182  *
   183  * @param pb			protobuf handle.
   184  * @param field			Field name.
   185  * @param index			Index in the repeated field.
   186  * @param buffer		Destination color buffer.
   187  * @noreturn
   188  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   189  */
   190 native PbReadRepeatedColor(Handle:pb, const String:field[], index, buffer[4]);
   191 
   192 /**
   193  * Reads an XYZ angle value from a protobuf message repeated field.
   194  *
   195  * @param pb			protobuf handle.
   196  * @param field			Field name.
   197  * @param index			Index in the repeated field.
   198  * @param buffer		Destination angle buffer.
   199  * @noreturn
   200  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   201  */
   202 native PbReadRepeatedAngle(Handle:pb, const String:field[], index, Float:buffer[3]);
   203 
   204 /**
   205  * Reads an XYZ vector value from a protobuf message repeated field.
   206  *
   207  * @param pb			protobuf handle.
   208  * @param field			Field name.
   209  * @param index			Index in the repeated field.
   210  * @param buffer		Destination vector buffer.
   211  * @noreturn
   212  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   213  */
   214 native PbReadRepeatedVector(Handle:pb, const String:field[], index, Float:buffer[3]);
   215 
   216 /**
   217  * Reads an XY vector value from a protobuf message repeated field.
   218  *
   219  * @param pb			protobuf handle.
   220  * @param field			Field name.
   221  * @param index			Index in the repeated field.
   222  * @param buffer		Destination vector buffer.
   223  * @noreturn
   224  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   225  */
   226 native PbReadRepeatedVector2D(Handle:pb, const String:field[], index, Float:buffer[2]);
   227 
   228 /**
   229  * Sets an int32, uint32, sint32, fixed32, or sfixed32  on a protobuf message.
   230  *
   231  * @param pb			protobuf handle.
   232  * @param field			Field name.
   233  * @param value			Integer value to set.
   234  * @noreturn
   235  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   236  */
   237 native PbSetInt(Handle:pb, const String:field[], value);
   238 
   239 /**
   240  * Sets a float or double on a protobuf message.
   241  *
   242  * @param pb			protobuf handle.
   243  * @param field			Field name.
   244  * @param value			Float value to set.
   245  * @noreturn
   246  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   247  */
   248 native PbSetFloat(Handle:pb, const String:field[], Float:value);
   249 
   250 /**
   251  * Sets a bool on a protobuf message.
   252  *
   253  * @param pb			protobuf handle.
   254  * @param field			Field name.
   255  * @param value			Boolean value to set.
   256  * @noreturn
   257  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   258  */
   259 native PbSetBool(Handle:pb, const String:field[], bool:value);
   260 
   261 /**
   262  * Sets a string on a protobuf message.
   263  *
   264  * @param pb			protobuf handle.
   265  * @param field			Field name.
   266  * @param value			String value to set.
   267  * @noreturn
   268  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   269  */
   270 native PbSetString(Handle:pb, const String:field[], const String:value[]);
   271 
   272 /**
   273  * Sets an RGBA color on a protobuf message.
   274  *
   275  * @param pb			protobuf handle.
   276  * @param field			Field name.
   277  * @param value			Color value to set.
   278  * @noreturn
   279  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   280  */
   281 native PbSetColor(Handle:pb, const String:field[], const color[4]);
   282 
   283 /**
   284  * Sets an XYZ angle on a protobuf message.
   285  *
   286  * @param pb			protobuf handle.
   287  * @param field			Field name.
   288  * @param value			Angle value to set.
   289  * @noreturn
   290  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   291  */
   292 native PbSetAngle(Handle:pb, const String:field[], const Float:angle[3]);
   293 
   294 /**
   295  * Sets an XYZ vector on a protobuf message.
   296  *
   297  * @param pb			protobuf handle.
   298  * @param field			Field name.
   299  * @param value			Vector value to set.
   300  * @noreturn
   301  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   302  */
   303 native PbSetVector(Handle:pb, const String:field[], const Float:vec[3]);
   304 
   305 /**
   306  * Sets an XY vector on a protobuf message.
   307  *
   308  * @param pb			protobuf handle.
   309  * @param field			Field name.
   310  * @param value			Vector value to set.
   311  * @noreturn
   312  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   313  */
   314 native PbSetVector2D(Handle:pb, const String:field[], const Float:vec[2]);
   315 
   316 /**
   317  * Add an int32, uint32, sint32, fixed32, or sfixed32 to a protobuf message repeated field.
   318  *
   319  * @param pb			protobuf handle.
   320  * @param field			Field name.
   321  * @param value			Integer value to add.
   322  * @noreturn
   323  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   324  */
   325 native PbAddInt(Handle:pb, const String:field[], value);
   326 
   327 /**
   328  * Add a float or double to a protobuf message repeated field.
   329  *
   330  * @param pb			protobuf handle.
   331  * @param field			Field name.
   332  * @param value			Float value to add.
   333  * @noreturn
   334  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   335  */
   336 native PbAddFloat(Handle:pb, const String:field[], Float:value);
   337 
   338 /**
   339  * Add a bool to a protobuf message repeated field.
   340  *
   341  * @param pb			protobuf handle.
   342  * @param field			Field name.
   343  * @param value			Boolean value to add.
   344  * @noreturn
   345  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   346  */
   347 native PbAddBool(Handle:pb, const String:field[], bool:value);
   348 
   349 /**
   350  * Add a string to a protobuf message repeated field.
   351  *
   352  * @param pb			protobuf handle.
   353  * @param field			Field name.
   354  * @param value			String value to add.
   355  * @noreturn
   356  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   357  */
   358 native PbAddString(Handle:pb, const String:field[], const String:value[]);
   359 
   360 /**
   361  * Add an RGBA color to a protobuf message repeated field.
   362  *
   363  * @param pb			protobuf handle.
   364  * @param field			Field name.
   365  * @param value			Color value to add.
   366  * @noreturn
   367  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   368  */
   369 native PbAddColor(Handle:pb, const String:field[], const color[4]);
   370 
   371 /**
   372  * Add an XYZ angle to a protobuf message repeated field.
   373  *
   374  * @param pb			protobuf handle.
   375  * @param field			Field name.
   376  * @param value			Angle value to add.
   377  * @noreturn
   378  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   379  */
   380 native PbAddAngle(Handle:pb, const String:field[], const Float:angle[3]);
   381 
   382 /**
   383  * Add an XYZ vector to a protobuf message repeated field.
   384  *
   385  * @param pb			protobuf handle.
   386  * @param field			Field name.
   387  * @param value			Vector value to add.
   388  * @noreturn
   389  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   390  */
   391 native PbAddVector(Handle:pb, const String:field[], const Float:vec[3]);
   392 
   393 /**
   394  * Add an XY vector to a protobuf message repeated field.
   395  *
   396  * @param pb			protobuf handle.
   397  * @param field			Field name.
   398  * @param value			Vector value to add.
   399  * @noreturn
   400  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   401  */
   402 native PbAddVector2D(Handle:pb, const String:field[], const Float:vec[2]);
   403 
   404 /**
   405  * Retrieve a handle to an embedded protobuf message in a protobuf message.
   406  *
   407  * @param pb			protobuf handle.
   408  * @param field			Field name.
   409  * @return				protobuf handle to embedded message.
   410  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   411  */ 
   412 native Handle:PbReadMessage(Handle:pb, const String:field[]);
   413 
   414 /**
   415  * Retrieve a handle to an embedded protobuf message in a protobuf message repeated field.
   416  *
   417  * @param pb			protobuf handle.
   418  * @param field			Field name.
   419  * @param index			Index in the repeated field.
   420  * @return				protobuf handle to embedded message.
   421  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   422  */ 
   423 native Handle:PbReadRepeatedMessage(Handle:pb, const String:field[], index);
   424 
   425 /**
   426  * Adds an embedded protobuf message to a protobuf message repeated field.
   427  *
   428  * @param pb			protobuf handle.
   429  * @param field			Field name.
   430  * @return				protobuf handle to added, embedded message.
   431  * @error				Invalid or incorrect Handle, non-existant field, or incorrect field type.
   432  */ 
   433 native Handle:PbAddMessage(Handle:pb, const String:field[]);