3 * =============================================================================
5 * Copyright (C) 2004-2007 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_INTERFACE_DATAPACK_H_
33 #define _INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_
35 #include <sp_vm_api.h>
39 * @brief Contains functions for packing data abstractly to/from plugins. The wrappers
40 * for creating these are contained in ISourceMod.h
46 * @brief Specifies a data pack that can only be read.
52 * @brief Resets the position in the data stream to the beginning.
54 virtual void Reset() const =0;
57 * @brief Retrieves the current stream position.
59 * @return Index into the stream.
61 virtual size_t GetPosition() const =0;
64 * @brief Sets the current stream position.
66 * @param pos Index to set the stream at.
67 * @return True if succeeded, false if out of bounds.
69 virtual bool SetPosition(size_t pos) const =0;
72 * @brief Reads one cell from the data stream.
74 * @return A cell read from the current position.
76 virtual cell_t ReadCell() const =0;
79 * @brief Reads one float from the data stream.
81 * @return A float read from the current position.
83 virtual float ReadFloat() const =0;
86 * @brief Returns whether or not a specified number of bytes from the current stream
87 * position to the end can be read.
89 * @param bytes Number of bytes to simulate reading.
90 * @return True if can be read, false otherwise.
92 virtual bool IsReadable(size_t bytes) const =0;
95 * @brief Reads a string from the data stream.
97 * @param len Optional pointer to store the string length.
98 * @return Pointer to the string, or NULL if out of bounds.
100 virtual const char *ReadString(size_t *len) const =0;
103 * @brief Reads the current position as a generic address.
105 * @return Pointer to the memory.
107 virtual void *GetMemory() const =0;
110 * @brief Reads the current position as a generic data type.
112 * @param size Optional pointer to store the size of the data type.
113 * @return Pointer to the data, or NULL if out of bounds.
115 virtual void *ReadMemory(size_t *size) const =0;
119 * @brief Specifies a data pack that can only be written.
121 class IDataPack : public IDataReader
125 * @brief Resets the used size of the stream back to zero.
127 virtual void ResetSize() =0;
130 * @brief Packs one cell into the data stream.
132 * @param cell Cell value to write.
134 virtual void PackCell(cell_t cell) =0;
137 * @brief Packs one float into the data stream.
139 * @param val Float value to write.
141 virtual void PackFloat(float val) =0;
144 * @brief Packs one string into the data stream.
145 * The length is recorded as well for buffer overrun protection.
147 * @param string String to write.
149 virtual void PackString(const char *string) =0;
152 * @brief Creates a generic block of memory in the stream.
154 * Note that the pointer it returns can be invalidated on further
155 * writing, since the stream size may grow. You may need to double back
156 * and fetch the pointer again.
158 * @param size Size of the memory to create in the stream.
159 * @param addr Optional pointer to store the relocated memory address.
160 * @return Current position of the stream beforehand.
162 virtual size_t CreateMemory(size_t size, void **addr) =0;
166 #endif //_INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_