diff options
author | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-05-22 19:04:52 +0200 |
---|---|---|
committer | Ansariel <ansariel.hiller@phoenixviewer.com> | 2024-05-22 19:04:52 +0200 |
commit | 1b67dd855c41f5a0cda7ec2a68d98071986ca703 (patch) | |
tree | ab243607f74f78200787bba5b9b88f07ef1b966f /indra/llmessage/lldatapacker.h | |
parent | 6d6eabca44d08d5b97bfe3e941d2b9687c2246ea (diff) | |
parent | e1623bb276f83a43ce7a197e388720c05bdefe61 (diff) |
Merge remote-tracking branch 'origin/main' into DRTVWR-600-maint-A
# Conflicts:
# autobuild.xml
# indra/cmake/CMakeLists.txt
# indra/cmake/GoogleMock.cmake
# indra/llaudio/llaudioengine_fmodstudio.cpp
# indra/llaudio/llaudioengine_fmodstudio.h
# indra/llaudio/lllistener_fmodstudio.cpp
# indra/llaudio/lllistener_fmodstudio.h
# indra/llaudio/llstreamingaudio_fmodstudio.cpp
# indra/llaudio/llstreamingaudio_fmodstudio.h
# indra/llcharacter/llmultigesture.cpp
# indra/llcharacter/llmultigesture.h
# indra/llimage/llimage.cpp
# indra/llimage/llimagepng.cpp
# indra/llimage/llimageworker.cpp
# indra/llimage/tests/llimageworker_test.cpp
# indra/llmessage/tests/llmockhttpclient.h
# indra/llprimitive/llgltfmaterial.h
# indra/llrender/llfontfreetype.cpp
# indra/llui/llcombobox.cpp
# indra/llui/llfolderview.cpp
# indra/llui/llfolderviewmodel.h
# indra/llui/lllineeditor.cpp
# indra/llui/lllineeditor.h
# indra/llui/lltextbase.cpp
# indra/llui/lltextbase.h
# indra/llui/lltexteditor.cpp
# indra/llui/lltextvalidate.cpp
# indra/llui/lltextvalidate.h
# indra/llui/lluictrl.h
# indra/llui/llview.cpp
# indra/llwindow/llwindowmacosx.cpp
# indra/newview/app_settings/settings.xml
# indra/newview/llappearancemgr.cpp
# indra/newview/llappearancemgr.h
# indra/newview/llavatarpropertiesprocessor.cpp
# indra/newview/llavatarpropertiesprocessor.h
# indra/newview/llbreadcrumbview.cpp
# indra/newview/llbreadcrumbview.h
# indra/newview/llbreastmotion.cpp
# indra/newview/llbreastmotion.h
# indra/newview/llconversationmodel.h
# indra/newview/lldensityctrl.cpp
# indra/newview/lldensityctrl.h
# indra/newview/llface.inl
# indra/newview/llfloatereditsky.cpp
# indra/newview/llfloatereditwater.cpp
# indra/newview/llfloateremojipicker.h
# indra/newview/llfloaterimsessiontab.cpp
# indra/newview/llfloaterprofiletexture.cpp
# indra/newview/llfloaterprofiletexture.h
# indra/newview/llgesturemgr.cpp
# indra/newview/llgesturemgr.h
# indra/newview/llimpanel.cpp
# indra/newview/llimpanel.h
# indra/newview/llinventorybridge.cpp
# indra/newview/llinventorybridge.h
# indra/newview/llinventoryclipboard.cpp
# indra/newview/llinventoryclipboard.h
# indra/newview/llinventoryfunctions.cpp
# indra/newview/llinventoryfunctions.h
# indra/newview/llinventorygallery.cpp
# indra/newview/lllistbrowser.cpp
# indra/newview/lllistbrowser.h
# indra/newview/llpanelobjectinventory.cpp
# indra/newview/llpanelprofile.cpp
# indra/newview/llpanelprofile.h
# indra/newview/llpreviewgesture.cpp
# indra/newview/llsavedsettingsglue.cpp
# indra/newview/llsavedsettingsglue.h
# indra/newview/lltooldraganddrop.cpp
# indra/newview/llurllineeditorctrl.cpp
# indra/newview/llvectorperfoptions.cpp
# indra/newview/llvectorperfoptions.h
# indra/newview/llviewerparceloverlay.cpp
# indra/newview/llviewertexlayer.cpp
# indra/newview/llviewertexturelist.cpp
# indra/newview/macmain.h
# indra/test/test.cpp
Diffstat (limited to 'indra/llmessage/lldatapacker.h')
-rw-r--r-- | indra/llmessage/lldatapacker.h | 870 |
1 files changed, 435 insertions, 435 deletions
diff --git a/indra/llmessage/lldatapacker.h b/indra/llmessage/lldatapacker.h index 8e980d8611..5c896d28fc 100644 --- a/indra/llmessage/lldatapacker.h +++ b/indra/llmessage/lldatapacker.h @@ -1,435 +1,435 @@ -/** - * @file lldatapacker.h - * @brief Data packer declaration for tightly storing binary data. - * - * $LicenseInfo:firstyear=2002&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#ifndef LL_LLDATAPACKER_H -#define LL_LLDATAPACKER_H - -class LLColor4; -class LLColor4U; -class LLVector2; -class LLVector3; -class LLVector4; -class LLUUID; - -class LLDataPacker -{ -public: - virtual ~LLDataPacker() {} - - // Not required to override, but error to call? - virtual void reset(); - virtual void dumpBufferToLog(); - - virtual bool hasNext() const = 0; - - virtual bool packString(const std::string& value, const char *name) = 0; - virtual bool unpackString(std::string& value, const char *name) = 0; - - virtual bool packBinaryData(const U8 *value, S32 size, const char *name) = 0; - virtual bool unpackBinaryData(U8 *value, S32 &size, const char *name) = 0; - - // Constant size binary data packing - virtual bool packBinaryDataFixed(const U8 *value, S32 size, const char *name) = 0; - virtual bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name) = 0; - - virtual bool packU8(const U8 value, const char *name) = 0; - virtual bool unpackU8(U8 &value, const char *name) = 0; - - virtual bool packU16(const U16 value, const char *name) = 0; - virtual bool unpackU16(U16 &value, const char *name) = 0; - bool unpackU16s(U16 *value, S32 count, const char *name); - - virtual bool packS16(const S16 value, const char *name) = 0; - virtual bool unpackS16(S16 &value, const char *name) = 0; - bool unpackS16s(S16 *value, S32 count, const char *name); - - virtual bool packU32(const U32 value, const char *name) = 0; - virtual bool unpackU32(U32 &value, const char *name) = 0; - - virtual bool packS32(const S32 value, const char *name) = 0; - virtual bool unpackS32(S32 &value, const char *name) = 0; - - virtual bool packF32(const F32 value, const char *name) = 0; - virtual bool unpackF32(F32 &value, const char *name) = 0; - bool unpackF32s(F32 *values, S32 count, const char *name); - - // Packs a float into an integer, using the given size - // and picks the right U* data type to pack into. - bool packFixed(const F32 value, const char *name, - const bool is_signed, const U32 int_bits, const U32 frac_bits); - bool unpackFixed(F32 &value, const char *name, - const bool is_signed, const U32 int_bits, const U32 frac_bits); - - virtual bool packColor4(const LLColor4 &value, const char *name) = 0; - virtual bool unpackColor4(LLColor4 &value, const char *name) = 0; - - virtual bool packColor4U(const LLColor4U &value, const char *name) = 0; - virtual bool unpackColor4U(LLColor4U &value, const char *name) = 0; - bool unpackColor4Us(LLColor4U *values, S32 count, const char *name); - - virtual bool packVector2(const LLVector2 &value, const char *name) = 0; - virtual bool unpackVector2(LLVector2 &value, const char *name) = 0; - - virtual bool packVector3(const LLVector3 &value, const char *name) = 0; - virtual bool unpackVector3(LLVector3 &value, const char *name) = 0; - - virtual bool packVector4(const LLVector4 &value, const char *name) = 0; - virtual bool unpackVector4(LLVector4 &value, const char *name) = 0; - - virtual bool packUUID(const LLUUID &value, const char *name) = 0; - virtual bool unpackUUID(LLUUID &value, const char *name) = 0; - bool unpackUUIDs(LLUUID *values, S32 count, const char *name); - U32 getPassFlags() const { return mPassFlags; } - void setPassFlags(U32 flags) { mPassFlags = flags; } -protected: - LLDataPacker(); -protected: - U32 mPassFlags; - bool mWriteEnabled; // disable this to do things like determine filesize without actually copying data -}; - -class LLDataPackerBinaryBuffer : public LLDataPacker -{ -public: - LLDataPackerBinaryBuffer(U8 *bufferp, S32 size) - : LLDataPacker(), - mBufferp(bufferp), - mCurBufferp(bufferp), - mBufferSize(size) - { - mWriteEnabled = true; - } - - LLDataPackerBinaryBuffer() - : LLDataPacker(), - mBufferp(NULL), - mCurBufferp(NULL), - mBufferSize(0) - { - } - - /*virtual*/ bool packString(const std::string& value, const char *name); - /*virtual*/ bool unpackString(std::string& value, const char *name); - - /*virtual*/ bool packBinaryData(const U8 *value, S32 size, const char *name); - /*virtual*/ bool unpackBinaryData(U8 *value, S32 &size, const char *name); - - // Constant size binary data packing - /*virtual*/ bool packBinaryDataFixed(const U8 *value, S32 size, const char *name); - /*virtual*/ bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name); - - /*virtual*/ bool packU8(const U8 value, const char *name); - /*virtual*/ bool unpackU8(U8 &value, const char *name); - - /*virtual*/ bool packU16(const U16 value, const char *name); - /*virtual*/ bool unpackU16(U16 &value, const char *name); - - /*virtual*/ bool packS16(const S16 value, const char *name); - /*virtual*/ bool unpackS16(S16 &value, const char *name); - - /*virtual*/ bool packU32(const U32 value, const char *name); - /*virtual*/ bool unpackU32(U32 &value, const char *name); - - /*virtual*/ bool packS32(const S32 value, const char *name); - /*virtual*/ bool unpackS32(S32 &value, const char *name); - - /*virtual*/ bool packF32(const F32 value, const char *name); - /*virtual*/ bool unpackF32(F32 &value, const char *name); - - /*virtual*/ bool packColor4(const LLColor4 &value, const char *name); - /*virtual*/ bool unpackColor4(LLColor4 &value, const char *name); - - /*virtual*/ bool packColor4U(const LLColor4U &value, const char *name); - /*virtual*/ bool unpackColor4U(LLColor4U &value, const char *name); - - /*virtual*/ bool packVector2(const LLVector2 &value, const char *name); - /*virtual*/ bool unpackVector2(LLVector2 &value, const char *name); - - /*virtual*/ bool packVector3(const LLVector3 &value, const char *name); - /*virtual*/ bool unpackVector3(LLVector3 &value, const char *name); - - /*virtual*/ bool packVector4(const LLVector4 &value, const char *name); - /*virtual*/ bool unpackVector4(LLVector4 &value, const char *name); - - /*virtual*/ bool packUUID(const LLUUID &value, const char *name); - /*virtual*/ bool unpackUUID(LLUUID &value, const char *name); - - S32 getCurrentSize() const { return (S32)(mCurBufferp - mBufferp); } - S32 getBufferSize() const { return mBufferSize; } - const U8* getBuffer() const { return mBufferp; } - void reset() { mCurBufferp = mBufferp; mWriteEnabled = (mCurBufferp != NULL); } - void shift(S32 offset) { reset(); mCurBufferp += offset;} - void freeBuffer() { delete [] mBufferp; mBufferp = mCurBufferp = NULL; mBufferSize = 0; mWriteEnabled = false; } - void assignBuffer(U8 *bufferp, S32 size) - { - if(mBufferp && mBufferp != bufferp) - { - freeBuffer() ; - } - mBufferp = bufferp; - mCurBufferp = bufferp; - mBufferSize = size; - mWriteEnabled = true; - } - const LLDataPackerBinaryBuffer& operator=(const LLDataPackerBinaryBuffer &a); - - /*virtual*/ bool hasNext() const { return getCurrentSize() < getBufferSize(); } - - /*virtual*/ void dumpBufferToLog(); -protected: - inline bool verifyLength(const S32 data_size, const char *name); - - U8 *mBufferp; - U8 *mCurBufferp; - S32 mBufferSize; -}; - -inline bool LLDataPackerBinaryBuffer::verifyLength(const S32 data_size, const char *name) -{ - if (mWriteEnabled && (mCurBufferp - mBufferp) > mBufferSize - data_size) - { - LL_WARNS() << "Buffer overflow in BinaryBuffer length verify, field name " << name << "!" << LL_ENDL; - LL_WARNS() << "Current pos: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << " Data size: " << data_size << LL_ENDL; - return false; - } - - return true; -} - -class LLDataPackerAsciiBuffer : public LLDataPacker -{ -public: - LLDataPackerAsciiBuffer(char* bufferp, S32 size) - { - mBufferp = bufferp; - mCurBufferp = bufferp; - mBufferSize = size; - mPassFlags = 0; - mIncludeNames = false; - mWriteEnabled = true; - } - - LLDataPackerAsciiBuffer() - { - mBufferp = NULL; - mCurBufferp = NULL; - mBufferSize = 0; - mPassFlags = 0; - mIncludeNames = false; - mWriteEnabled = false; - } - - /*virtual*/ bool packString(const std::string& value, const char *name); - /*virtual*/ bool unpackString(std::string& value, const char *name); - - /*virtual*/ bool packBinaryData(const U8 *value, S32 size, const char *name); - /*virtual*/ bool unpackBinaryData(U8 *value, S32 &size, const char *name); - - // Constant size binary data packing - /*virtual*/ bool packBinaryDataFixed(const U8 *value, S32 size, const char *name); - /*virtual*/ bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name); - - /*virtual*/ bool packU8(const U8 value, const char *name); - /*virtual*/ bool unpackU8(U8 &value, const char *name); - - /*virtual*/ bool packU16(const U16 value, const char *name); - /*virtual*/ bool unpackU16(U16 &value, const char *name); - - /*virtual*/ bool packS16(const S16 value, const char *name); - /*virtual*/ bool unpackS16(S16 &value, const char *name); - - /*virtual*/ bool packU32(const U32 value, const char *name); - /*virtual*/ bool unpackU32(U32 &value, const char *name); - - /*virtual*/ bool packS32(const S32 value, const char *name); - /*virtual*/ bool unpackS32(S32 &value, const char *name); - - /*virtual*/ bool packF32(const F32 value, const char *name); - /*virtual*/ bool unpackF32(F32 &value, const char *name); - - /*virtual*/ bool packColor4(const LLColor4 &value, const char *name); - /*virtual*/ bool unpackColor4(LLColor4 &value, const char *name); - - /*virtual*/ bool packColor4U(const LLColor4U &value, const char *name); - /*virtual*/ bool unpackColor4U(LLColor4U &value, const char *name); - - /*virtual*/ bool packVector2(const LLVector2 &value, const char *name); - /*virtual*/ bool unpackVector2(LLVector2 &value, const char *name); - - /*virtual*/ bool packVector3(const LLVector3 &value, const char *name); - /*virtual*/ bool unpackVector3(LLVector3 &value, const char *name); - - /*virtual*/ bool packVector4(const LLVector4 &value, const char *name); - /*virtual*/ bool unpackVector4(LLVector4 &value, const char *name); - - /*virtual*/ bool packUUID(const LLUUID &value, const char *name); - /*virtual*/ bool unpackUUID(LLUUID &value, const char *name); - - void setIncludeNames(bool b) { mIncludeNames = b; } - - // Include the trailing NULL so it's always a valid string - S32 getCurrentSize() const { return (S32)(mCurBufferp - mBufferp) + 1; } - - S32 getBufferSize() const { return mBufferSize; } - /*virtual*/ void reset() { mCurBufferp = mBufferp; mWriteEnabled = (mCurBufferp != NULL); } - - /*virtual*/ bool hasNext() const { return getCurrentSize() < getBufferSize(); } - - inline void freeBuffer(); - inline void assignBuffer(char* bufferp, S32 size); - void dump(); - -protected: - void writeIndentedName(const char *name); - bool getValueStr(const char *name, char *out_value, const S32 value_len); - -protected: - inline bool verifyLength(const S32 data_size, const char *name); - - char *mBufferp; - char *mCurBufferp; - S32 mBufferSize; - bool mIncludeNames; // useful for debugging, print the name of each field -}; - -inline void LLDataPackerAsciiBuffer::freeBuffer() -{ - delete [] mBufferp; - mBufferp = mCurBufferp = NULL; - mBufferSize = 0; - mWriteEnabled = false; -} - -inline void LLDataPackerAsciiBuffer::assignBuffer(char* bufferp, S32 size) -{ - mBufferp = bufferp; - mCurBufferp = bufferp; - mBufferSize = size; - mWriteEnabled = true; -} - -inline bool LLDataPackerAsciiBuffer::verifyLength(const S32 data_size, const char *name) -{ - if (mWriteEnabled && (mCurBufferp - mBufferp) > mBufferSize - data_size) - { - LL_WARNS() << "Buffer overflow in AsciiBuffer length verify, field name " << name << "!" << LL_ENDL; - LL_WARNS() << "Current pos: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << " Data size: " << data_size << LL_ENDL; - return false; - } - - return true; -} - -class LLDataPackerAsciiFile : public LLDataPacker -{ -public: - LLDataPackerAsciiFile(LLFILE *fp, const S32 indent = 2) - : LLDataPacker(), - mIndent(indent), - mFP(fp), - mOutputStream(NULL), - mInputStream(NULL) - { - } - - LLDataPackerAsciiFile(std::ostream& output_stream, const S32 indent = 2) - : LLDataPacker(), - mIndent(indent), - mFP(NULL), - mOutputStream(&output_stream), - mInputStream(NULL) - { - mWriteEnabled = true; - } - - LLDataPackerAsciiFile(std::istream& input_stream, const S32 indent = 2) - : LLDataPacker(), - mIndent(indent), - mFP(NULL), - mOutputStream(NULL), - mInputStream(&input_stream) - { - } - - /*virtual*/ bool packString(const std::string& value, const char *name); - /*virtual*/ bool unpackString(std::string& value, const char *name); - - /*virtual*/ bool packBinaryData(const U8 *value, S32 size, const char *name); - /*virtual*/ bool unpackBinaryData(U8 *value, S32 &size, const char *name); - - /*virtual*/ bool packBinaryDataFixed(const U8 *value, S32 size, const char *name); - /*virtual*/ bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name); - - /*virtual*/ bool packU8(const U8 value, const char *name); - /*virtual*/ bool unpackU8(U8 &value, const char *name); - - /*virtual*/ bool packU16(const U16 value, const char *name); - /*virtual*/ bool unpackU16(U16 &value, const char *name); - - /*virtual*/ bool packS16(const S16 value, const char *name); - /*virtual*/ bool unpackS16(S16 &value, const char *name); - - /*virtual*/ bool packU32(const U32 value, const char *name); - /*virtual*/ bool unpackU32(U32 &value, const char *name); - - /*virtual*/ bool packS32(const S32 value, const char *name); - /*virtual*/ bool unpackS32(S32 &value, const char *name); - - /*virtual*/ bool packF32(const F32 value, const char *name); - /*virtual*/ bool unpackF32(F32 &value, const char *name); - - /*virtual*/ bool packColor4(const LLColor4 &value, const char *name); - /*virtual*/ bool unpackColor4(LLColor4 &value, const char *name); - - /*virtual*/ bool packColor4U(const LLColor4U &value, const char *name); - /*virtual*/ bool unpackColor4U(LLColor4U &value, const char *name); - - /*virtual*/ bool packVector2(const LLVector2 &value, const char *name); - /*virtual*/ bool unpackVector2(LLVector2 &value, const char *name); - - /*virtual*/ bool packVector3(const LLVector3 &value, const char *name); - /*virtual*/ bool unpackVector3(LLVector3 &value, const char *name); - - /*virtual*/ bool packVector4(const LLVector4 &value, const char *name); - /*virtual*/ bool unpackVector4(LLVector4 &value, const char *name); - - /*virtual*/ bool packUUID(const LLUUID &value, const char *name); - /*virtual*/ bool unpackUUID(LLUUID &value, const char *name); -protected: - void writeIndentedName(const char *name); - bool getValueStr(const char *name, char *out_value, const S32 value_len); - - /*virtual*/ bool hasNext() const { return true; } - -protected: - S32 mIndent; - LLFILE *mFP; - std::ostream* mOutputStream; - std::istream* mInputStream; -}; - -#endif // LL_LLDATAPACKER - +/**
+ * @file lldatapacker.h
+ * @brief Data packer declaration for tightly storing binary data.
+ *
+ * $LicenseInfo:firstyear=2002&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2010, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLDATAPACKER_H
+#define LL_LLDATAPACKER_H
+
+class LLColor4;
+class LLColor4U;
+class LLVector2;
+class LLVector3;
+class LLVector4;
+class LLUUID;
+
+class LLDataPacker
+{
+public:
+ virtual ~LLDataPacker() {}
+
+ // Not required to override, but error to call?
+ virtual void reset();
+ virtual void dumpBufferToLog();
+
+ virtual bool hasNext() const = 0;
+
+ virtual bool packString(const std::string& value, const char *name) = 0;
+ virtual bool unpackString(std::string& value, const char *name) = 0;
+
+ virtual bool packBinaryData(const U8 *value, S32 size, const char *name) = 0;
+ virtual bool unpackBinaryData(U8 *value, S32 &size, const char *name) = 0;
+
+ // Constant size binary data packing
+ virtual bool packBinaryDataFixed(const U8 *value, S32 size, const char *name) = 0;
+ virtual bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name) = 0;
+
+ virtual bool packU8(const U8 value, const char *name) = 0;
+ virtual bool unpackU8(U8 &value, const char *name) = 0;
+
+ virtual bool packU16(const U16 value, const char *name) = 0;
+ virtual bool unpackU16(U16 &value, const char *name) = 0;
+ bool unpackU16s(U16 *value, S32 count, const char *name);
+
+ virtual bool packS16(const S16 value, const char *name) = 0;
+ virtual bool unpackS16(S16 &value, const char *name) = 0;
+ bool unpackS16s(S16 *value, S32 count, const char *name);
+
+ virtual bool packU32(const U32 value, const char *name) = 0;
+ virtual bool unpackU32(U32 &value, const char *name) = 0;
+
+ virtual bool packS32(const S32 value, const char *name) = 0;
+ virtual bool unpackS32(S32 &value, const char *name) = 0;
+
+ virtual bool packF32(const F32 value, const char *name) = 0;
+ virtual bool unpackF32(F32 &value, const char *name) = 0;
+ bool unpackF32s(F32 *values, S32 count, const char *name);
+
+ // Packs a float into an integer, using the given size
+ // and picks the right U* data type to pack into.
+ bool packFixed(const F32 value, const char *name,
+ const bool is_signed, const U32 int_bits, const U32 frac_bits);
+ bool unpackFixed(F32 &value, const char *name,
+ const bool is_signed, const U32 int_bits, const U32 frac_bits);
+
+ virtual bool packColor4(const LLColor4 &value, const char *name) = 0;
+ virtual bool unpackColor4(LLColor4 &value, const char *name) = 0;
+
+ virtual bool packColor4U(const LLColor4U &value, const char *name) = 0;
+ virtual bool unpackColor4U(LLColor4U &value, const char *name) = 0;
+ bool unpackColor4Us(LLColor4U *values, S32 count, const char *name);
+
+ virtual bool packVector2(const LLVector2 &value, const char *name) = 0;
+ virtual bool unpackVector2(LLVector2 &value, const char *name) = 0;
+
+ virtual bool packVector3(const LLVector3 &value, const char *name) = 0;
+ virtual bool unpackVector3(LLVector3 &value, const char *name) = 0;
+
+ virtual bool packVector4(const LLVector4 &value, const char *name) = 0;
+ virtual bool unpackVector4(LLVector4 &value, const char *name) = 0;
+
+ virtual bool packUUID(const LLUUID &value, const char *name) = 0;
+ virtual bool unpackUUID(LLUUID &value, const char *name) = 0;
+ bool unpackUUIDs(LLUUID *values, S32 count, const char *name);
+ U32 getPassFlags() const { return mPassFlags; }
+ void setPassFlags(U32 flags) { mPassFlags = flags; }
+protected:
+ LLDataPacker();
+protected:
+ U32 mPassFlags;
+ bool mWriteEnabled; // disable this to do things like determine filesize without actually copying data
+};
+
+class LLDataPackerBinaryBuffer : public LLDataPacker
+{
+public:
+ LLDataPackerBinaryBuffer(U8 *bufferp, S32 size)
+ : LLDataPacker(),
+ mBufferp(bufferp),
+ mCurBufferp(bufferp),
+ mBufferSize(size)
+ {
+ mWriteEnabled = true;
+ }
+
+ LLDataPackerBinaryBuffer()
+ : LLDataPacker(),
+ mBufferp(NULL),
+ mCurBufferp(NULL),
+ mBufferSize(0)
+ {
+ }
+
+ /*virtual*/ bool packString(const std::string& value, const char *name);
+ /*virtual*/ bool unpackString(std::string& value, const char *name);
+
+ /*virtual*/ bool packBinaryData(const U8 *value, S32 size, const char *name);
+ /*virtual*/ bool unpackBinaryData(U8 *value, S32 &size, const char *name);
+
+ // Constant size binary data packing
+ /*virtual*/ bool packBinaryDataFixed(const U8 *value, S32 size, const char *name);
+ /*virtual*/ bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name);
+
+ /*virtual*/ bool packU8(const U8 value, const char *name);
+ /*virtual*/ bool unpackU8(U8 &value, const char *name);
+
+ /*virtual*/ bool packU16(const U16 value, const char *name);
+ /*virtual*/ bool unpackU16(U16 &value, const char *name);
+
+ /*virtual*/ bool packS16(const S16 value, const char *name);
+ /*virtual*/ bool unpackS16(S16 &value, const char *name);
+
+ /*virtual*/ bool packU32(const U32 value, const char *name);
+ /*virtual*/ bool unpackU32(U32 &value, const char *name);
+
+ /*virtual*/ bool packS32(const S32 value, const char *name);
+ /*virtual*/ bool unpackS32(S32 &value, const char *name);
+
+ /*virtual*/ bool packF32(const F32 value, const char *name);
+ /*virtual*/ bool unpackF32(F32 &value, const char *name);
+
+ /*virtual*/ bool packColor4(const LLColor4 &value, const char *name);
+ /*virtual*/ bool unpackColor4(LLColor4 &value, const char *name);
+
+ /*virtual*/ bool packColor4U(const LLColor4U &value, const char *name);
+ /*virtual*/ bool unpackColor4U(LLColor4U &value, const char *name);
+
+ /*virtual*/ bool packVector2(const LLVector2 &value, const char *name);
+ /*virtual*/ bool unpackVector2(LLVector2 &value, const char *name);
+
+ /*virtual*/ bool packVector3(const LLVector3 &value, const char *name);
+ /*virtual*/ bool unpackVector3(LLVector3 &value, const char *name);
+
+ /*virtual*/ bool packVector4(const LLVector4 &value, const char *name);
+ /*virtual*/ bool unpackVector4(LLVector4 &value, const char *name);
+
+ /*virtual*/ bool packUUID(const LLUUID &value, const char *name);
+ /*virtual*/ bool unpackUUID(LLUUID &value, const char *name);
+
+ S32 getCurrentSize() const { return (S32)(mCurBufferp - mBufferp); }
+ S32 getBufferSize() const { return mBufferSize; }
+ const U8* getBuffer() const { return mBufferp; }
+ void reset() { mCurBufferp = mBufferp; mWriteEnabled = (mCurBufferp != NULL); }
+ void shift(S32 offset) { reset(); mCurBufferp += offset;}
+ void freeBuffer() { delete [] mBufferp; mBufferp = mCurBufferp = NULL; mBufferSize = 0; mWriteEnabled = false; }
+ void assignBuffer(U8 *bufferp, S32 size)
+ {
+ if(mBufferp && mBufferp != bufferp)
+ {
+ freeBuffer() ;
+ }
+ mBufferp = bufferp;
+ mCurBufferp = bufferp;
+ mBufferSize = size;
+ mWriteEnabled = true;
+ }
+ const LLDataPackerBinaryBuffer& operator=(const LLDataPackerBinaryBuffer &a);
+
+ /*virtual*/ bool hasNext() const { return getCurrentSize() < getBufferSize(); }
+
+ /*virtual*/ void dumpBufferToLog();
+protected:
+ inline bool verifyLength(const S32 data_size, const char *name);
+
+ U8 *mBufferp;
+ U8 *mCurBufferp;
+ S32 mBufferSize;
+};
+
+inline bool LLDataPackerBinaryBuffer::verifyLength(const S32 data_size, const char *name)
+{
+ if (mWriteEnabled && (mCurBufferp - mBufferp) > mBufferSize - data_size)
+ {
+ LL_WARNS() << "Buffer overflow in BinaryBuffer length verify, field name " << name << "!" << LL_ENDL;
+ LL_WARNS() << "Current pos: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << " Data size: " << data_size << LL_ENDL;
+ return false;
+ }
+
+ return true;
+}
+
+class LLDataPackerAsciiBuffer : public LLDataPacker
+{
+public:
+ LLDataPackerAsciiBuffer(char* bufferp, S32 size)
+ {
+ mBufferp = bufferp;
+ mCurBufferp = bufferp;
+ mBufferSize = size;
+ mPassFlags = 0;
+ mIncludeNames = false;
+ mWriteEnabled = true;
+ }
+
+ LLDataPackerAsciiBuffer()
+ {
+ mBufferp = NULL;
+ mCurBufferp = NULL;
+ mBufferSize = 0;
+ mPassFlags = 0;
+ mIncludeNames = false;
+ mWriteEnabled = false;
+ }
+
+ /*virtual*/ bool packString(const std::string& value, const char *name);
+ /*virtual*/ bool unpackString(std::string& value, const char *name);
+
+ /*virtual*/ bool packBinaryData(const U8 *value, S32 size, const char *name);
+ /*virtual*/ bool unpackBinaryData(U8 *value, S32 &size, const char *name);
+
+ // Constant size binary data packing
+ /*virtual*/ bool packBinaryDataFixed(const U8 *value, S32 size, const char *name);
+ /*virtual*/ bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name);
+
+ /*virtual*/ bool packU8(const U8 value, const char *name);
+ /*virtual*/ bool unpackU8(U8 &value, const char *name);
+
+ /*virtual*/ bool packU16(const U16 value, const char *name);
+ /*virtual*/ bool unpackU16(U16 &value, const char *name);
+
+ /*virtual*/ bool packS16(const S16 value, const char *name);
+ /*virtual*/ bool unpackS16(S16 &value, const char *name);
+
+ /*virtual*/ bool packU32(const U32 value, const char *name);
+ /*virtual*/ bool unpackU32(U32 &value, const char *name);
+
+ /*virtual*/ bool packS32(const S32 value, const char *name);
+ /*virtual*/ bool unpackS32(S32 &value, const char *name);
+
+ /*virtual*/ bool packF32(const F32 value, const char *name);
+ /*virtual*/ bool unpackF32(F32 &value, const char *name);
+
+ /*virtual*/ bool packColor4(const LLColor4 &value, const char *name);
+ /*virtual*/ bool unpackColor4(LLColor4 &value, const char *name);
+
+ /*virtual*/ bool packColor4U(const LLColor4U &value, const char *name);
+ /*virtual*/ bool unpackColor4U(LLColor4U &value, const char *name);
+
+ /*virtual*/ bool packVector2(const LLVector2 &value, const char *name);
+ /*virtual*/ bool unpackVector2(LLVector2 &value, const char *name);
+
+ /*virtual*/ bool packVector3(const LLVector3 &value, const char *name);
+ /*virtual*/ bool unpackVector3(LLVector3 &value, const char *name);
+
+ /*virtual*/ bool packVector4(const LLVector4 &value, const char *name);
+ /*virtual*/ bool unpackVector4(LLVector4 &value, const char *name);
+
+ /*virtual*/ bool packUUID(const LLUUID &value, const char *name);
+ /*virtual*/ bool unpackUUID(LLUUID &value, const char *name);
+
+ void setIncludeNames(bool b) { mIncludeNames = b; }
+
+ // Include the trailing NULL so it's always a valid string
+ S32 getCurrentSize() const { return (S32)(mCurBufferp - mBufferp) + 1; }
+
+ S32 getBufferSize() const { return mBufferSize; }
+ /*virtual*/ void reset() { mCurBufferp = mBufferp; mWriteEnabled = (mCurBufferp != NULL); }
+
+ /*virtual*/ bool hasNext() const { return getCurrentSize() < getBufferSize(); }
+
+ inline void freeBuffer();
+ inline void assignBuffer(char* bufferp, S32 size);
+ void dump();
+
+protected:
+ void writeIndentedName(const char *name);
+ bool getValueStr(const char *name, char *out_value, const S32 value_len);
+
+protected:
+ inline bool verifyLength(const S32 data_size, const char *name);
+
+ char *mBufferp;
+ char *mCurBufferp;
+ S32 mBufferSize;
+ bool mIncludeNames; // useful for debugging, print the name of each field
+};
+
+inline void LLDataPackerAsciiBuffer::freeBuffer()
+{
+ delete [] mBufferp;
+ mBufferp = mCurBufferp = NULL;
+ mBufferSize = 0;
+ mWriteEnabled = false;
+}
+
+inline void LLDataPackerAsciiBuffer::assignBuffer(char* bufferp, S32 size)
+{
+ mBufferp = bufferp;
+ mCurBufferp = bufferp;
+ mBufferSize = size;
+ mWriteEnabled = true;
+}
+
+inline bool LLDataPackerAsciiBuffer::verifyLength(const S32 data_size, const char *name)
+{
+ if (mWriteEnabled && (mCurBufferp - mBufferp) > mBufferSize - data_size)
+ {
+ LL_WARNS() << "Buffer overflow in AsciiBuffer length verify, field name " << name << "!" << LL_ENDL;
+ LL_WARNS() << "Current pos: " << (int)(mCurBufferp - mBufferp) << " Buffer size: " << mBufferSize << " Data size: " << data_size << LL_ENDL;
+ return false;
+ }
+
+ return true;
+}
+
+class LLDataPackerAsciiFile : public LLDataPacker
+{
+public:
+ LLDataPackerAsciiFile(LLFILE *fp, const S32 indent = 2)
+ : LLDataPacker(),
+ mIndent(indent),
+ mFP(fp),
+ mOutputStream(NULL),
+ mInputStream(NULL)
+ {
+ }
+
+ LLDataPackerAsciiFile(std::ostream& output_stream, const S32 indent = 2)
+ : LLDataPacker(),
+ mIndent(indent),
+ mFP(NULL),
+ mOutputStream(&output_stream),
+ mInputStream(NULL)
+ {
+ mWriteEnabled = true;
+ }
+
+ LLDataPackerAsciiFile(std::istream& input_stream, const S32 indent = 2)
+ : LLDataPacker(),
+ mIndent(indent),
+ mFP(NULL),
+ mOutputStream(NULL),
+ mInputStream(&input_stream)
+ {
+ }
+
+ /*virtual*/ bool packString(const std::string& value, const char *name);
+ /*virtual*/ bool unpackString(std::string& value, const char *name);
+
+ /*virtual*/ bool packBinaryData(const U8 *value, S32 size, const char *name);
+ /*virtual*/ bool unpackBinaryData(U8 *value, S32 &size, const char *name);
+
+ /*virtual*/ bool packBinaryDataFixed(const U8 *value, S32 size, const char *name);
+ /*virtual*/ bool unpackBinaryDataFixed(U8 *value, S32 size, const char *name);
+
+ /*virtual*/ bool packU8(const U8 value, const char *name);
+ /*virtual*/ bool unpackU8(U8 &value, const char *name);
+
+ /*virtual*/ bool packU16(const U16 value, const char *name);
+ /*virtual*/ bool unpackU16(U16 &value, const char *name);
+
+ /*virtual*/ bool packS16(const S16 value, const char *name);
+ /*virtual*/ bool unpackS16(S16 &value, const char *name);
+
+ /*virtual*/ bool packU32(const U32 value, const char *name);
+ /*virtual*/ bool unpackU32(U32 &value, const char *name);
+
+ /*virtual*/ bool packS32(const S32 value, const char *name);
+ /*virtual*/ bool unpackS32(S32 &value, const char *name);
+
+ /*virtual*/ bool packF32(const F32 value, const char *name);
+ /*virtual*/ bool unpackF32(F32 &value, const char *name);
+
+ /*virtual*/ bool packColor4(const LLColor4 &value, const char *name);
+ /*virtual*/ bool unpackColor4(LLColor4 &value, const char *name);
+
+ /*virtual*/ bool packColor4U(const LLColor4U &value, const char *name);
+ /*virtual*/ bool unpackColor4U(LLColor4U &value, const char *name);
+
+ /*virtual*/ bool packVector2(const LLVector2 &value, const char *name);
+ /*virtual*/ bool unpackVector2(LLVector2 &value, const char *name);
+
+ /*virtual*/ bool packVector3(const LLVector3 &value, const char *name);
+ /*virtual*/ bool unpackVector3(LLVector3 &value, const char *name);
+
+ /*virtual*/ bool packVector4(const LLVector4 &value, const char *name);
+ /*virtual*/ bool unpackVector4(LLVector4 &value, const char *name);
+
+ /*virtual*/ bool packUUID(const LLUUID &value, const char *name);
+ /*virtual*/ bool unpackUUID(LLUUID &value, const char *name);
+protected:
+ void writeIndentedName(const char *name);
+ bool getValueStr(const char *name, char *out_value, const S32 value_len);
+
+ /*virtual*/ bool hasNext() const { return true; }
+
+protected:
+ S32 mIndent;
+ LLFILE *mFP;
+ std::ostream* mOutputStream;
+ std::istream* mInputStream;
+};
+
+#endif // LL_LLDATAPACKER
+
|