3 * ===============================================================
4 * SourceMod, Copyright (C) 2004-2007 AlliedModders LLC.
6 * ===============================================================
8 * This file is part of the SourceMod/SourcePawn SDK. This file may only be
9 * used or modified under the Terms and Conditions of its License Agreement,
10 * which is found in public/licenses/LICENSE.txt. As of this notice, derivative
11 * works must be licensed under the GNU General Public License (version 2 or
12 * greater). A copy of the GPL is included under public/licenses/GPL.txt.
14 * To view the latest information, see: http://www.sourcemod.net/license.php
19 #ifndef _INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_
20 #define _INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_
22 #include <sp_vm_api.h>
26 * @brief Contains functions for packing data abstractly to/from plugins. The wrappers
27 * for creating these are contained in ISourceMod.h
33 * @brief Specifies a data pack that can only be read.
39 * @brief Resets the position in the data stream to the beginning.
41 virtual void Reset() const =0;
44 * @brief Retrieves the current stream position.
46 * @return Index into the stream.
48 virtual size_t GetPosition() const =0;
51 * @brief Sets the current stream position.
53 * @param pos Index to set the stream at.
54 * @return True if succeeded, false if out of bounds.
56 virtual bool SetPosition(size_t pos) const =0;
59 * @brief Reads one cell from the data stream.
61 * @return A cell read from the current position.
63 virtual cell_t ReadCell() const =0;
66 * @brief Reads one float from the data stream.
68 * @return A float read from the current position.
70 virtual float ReadFloat() const =0;
73 * @brief Returns whether or not a specified number of bytes from the current stream
74 * position to the end can be read.
76 * @param bytes Number of bytes to simulate reading.
77 * @return True if can be read, false otherwise.
79 virtual bool IsReadable(size_t bytes) const =0;
82 * @brief Reads a string from the data stream.
84 * @param len Optional pointer to store the string length.
85 * @return Pointer to the string, or NULL if out of bounds.
87 virtual const char *ReadString(size_t *len) const =0;
90 * @brief Reads the current position as a generic address.
92 * @return Pointer to the memory.
94 virtual void *GetMemory() const =0;
97 * @brief Reads the current position as a generic data type.
99 * @param size Optional pointer to store the size of the data type.
100 * @return Pointer to the data, or NULL if out of bounds.
102 virtual void *ReadMemory(size_t *size) const =0;
106 * @brief Specifies a data pack that can only be written.
108 class IDataPack : public IDataReader
112 * @brief Resets the used size of the stream back to zero.
114 virtual void ResetSize() =0;
117 * @brief Packs one cell into the data stream.
119 * @param cell Cell value to write.
121 virtual void PackCell(cell_t cell) =0;
124 * @brief Packs one float into the data stream.
126 * @param val Float value to write.
128 virtual void PackFloat(float val) =0;
131 * @brief Packs one string into the data stream.
132 * The length is recorded as well for buffer overrun protection.
134 * @param string String to write.
136 virtual void PackString(const char *string) =0;
139 * @brief Creates a generic block of memory in the stream.
141 * Note that the pointer it returns can be invalidated on further
142 * writing, since the stream size may grow. You may need to double back
143 * and fetch the pointer again.
145 * @param size Size of the memory to create in the stream.
146 * @param addr Optional pointer to store the relocated memory address.
147 * @return Current position of the stream beforehand.
149 virtual size_t CreateMemory(size_t size, void **addr) =0;
153 #endif //_INCLUDE_SOURCEMOD_INTERFACE_DATAPACK_H_