aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llsdmessagereader.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:54 -0500
committerJacek Antonelli2008-08-15 23:44:54 -0500
commitb2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch)
tree3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/llmessage/llsdmessagereader.cpp
parentSecond Life viewer sources 1.14.0.1 (diff)
downloadmeta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.zip
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.gz
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.bz2
meta-impy-b2afb8800bb033a04bb3ecdf0363068d56648ef1.tar.xz
Second Life viewer sources 1.15.0.2
Diffstat (limited to 'linden/indra/llmessage/llsdmessagereader.cpp')
-rwxr-xr-xlinden/indra/llmessage/llsdmessagereader.cpp264
1 files changed, 264 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llsdmessagereader.cpp b/linden/indra/llmessage/llsdmessagereader.cpp
new file mode 100755
index 0000000..6312bee
--- /dev/null
+++ b/linden/indra/llmessage/llsdmessagereader.cpp
@@ -0,0 +1,264 @@
1#include "llsdmessagereader.h"
2#include "llsdutil.h"
3#include "llmessagebuilder.h"
4#include "llsdmessagebuilder.h"
5
6LLSDMessageReader::LLSDMessageReader()
7{
8}
9
10//virtual
11LLSDMessageReader::~LLSDMessageReader()
12{
13}
14
15
16LLSD getLLSD(const LLSD& input, const char* block, const char* var, S32 blocknum)
17{
18 if(input[block].isArray())
19 {
20 return input[block][blocknum][var];
21 }
22 return LLSD();
23}
24
25//virtual
26void LLSDMessageReader::getBinaryData(const char *block, const char *var,
27 void *datap, S32 size, S32 blocknum,
28 S32 max_size)
29{
30 std::vector<U8> data = getLLSD(mMessage, block, var, blocknum);
31 S32 data_size = (S32)data.size();
32
33 if (size && data_size != size)
34 {
35 return;
36 }
37
38 if (max_size < data_size)
39 {
40 data_size = max_size;
41 }
42
43 memcpy(datap, &(data[0]), data_size);
44}
45
46//virtual
47void LLSDMessageReader::getBOOL(const char *block, const char *var,
48 BOOL &data,
49 S32 blocknum)
50{
51 data = getLLSD(mMessage, block, var, blocknum);
52}
53
54//virtual
55void LLSDMessageReader::getS8(const char *block, const char *var, S8 &data,
56 S32 blocknum)
57{
58 data = getLLSD(mMessage, block, var, blocknum).asInteger();
59}
60
61//virtual
62void LLSDMessageReader::getU8(const char *block, const char *var, U8 &data,
63 S32 blocknum)
64{
65 data = getLLSD(mMessage, block, var, blocknum).asInteger();
66}
67
68//virtual
69void LLSDMessageReader::getS16(const char *block, const char *var, S16 &data,
70 S32 blocknum)
71{
72 data = getLLSD(mMessage, block, var, blocknum).asInteger();
73}
74
75//virtual
76void LLSDMessageReader::getU16(const char *block, const char *var, U16 &data,
77 S32 blocknum)
78{
79 data = getLLSD(mMessage, block, var, blocknum).asInteger();
80}
81
82//virtual
83void LLSDMessageReader::getS32(const char *block, const char *var, S32 &data,
84 S32 blocknum)
85{
86 data = getLLSD(mMessage, block, var, blocknum);
87}
88
89//virtual
90void LLSDMessageReader::getF32(const char *block, const char *var, F32 &data,
91 S32 blocknum)
92{
93 data = (F32)getLLSD(mMessage, block, var, blocknum).asReal();
94}
95
96//virtual
97void LLSDMessageReader::getU32(const char *block, const char *var, U32 &data,
98 S32 blocknum)
99{
100 data = ll_U32_from_sd(getLLSD(mMessage, block, var, blocknum));
101}
102
103//virtual
104void LLSDMessageReader::getU64(const char *block, const char *var,
105 U64 &data, S32 blocknum)
106{
107 data = ll_U64_from_sd(getLLSD(mMessage, block, var, blocknum));
108}
109
110//virtual
111void LLSDMessageReader::getF64(const char *block, const char *var,
112 F64 &data, S32 blocknum)
113{
114 data = getLLSD(mMessage, block, var, blocknum);
115}
116
117//virtual
118void LLSDMessageReader::getVector3(const char *block, const char *var,
119 LLVector3 &vec, S32 blocknum)
120{
121 vec = ll_vector3_from_sd(getLLSD(mMessage, block, var, blocknum));
122}
123
124//virtual
125void LLSDMessageReader::getVector4(const char *block, const char *var,
126 LLVector4 &vec, S32 blocknum)
127{
128 vec = ll_vector4_from_sd(getLLSD(mMessage, block, var, blocknum));
129}
130
131//virtual
132void LLSDMessageReader::getVector3d(const char *block, const char *var,
133 LLVector3d &vec, S32 blocknum)
134{
135 vec = ll_vector3d_from_sd(getLLSD(mMessage, block, var, blocknum));
136}
137
138//virtual
139void LLSDMessageReader::getQuat(const char *block, const char *var,
140 LLQuaternion &q, S32 blocknum)
141{
142 q = ll_quaternion_from_sd(getLLSD(mMessage, block, var, blocknum));
143}
144
145//virtual
146void LLSDMessageReader::getUUID(const char *block, const char *var,
147 LLUUID &uuid, S32 blocknum)
148{
149 uuid = getLLSD(mMessage, block, var, blocknum);
150}
151
152//virtual
153void LLSDMessageReader::getIPAddr(const char *block, const char *var,
154 U32 &ip, S32 blocknum)
155{
156 ip = ll_ipaddr_from_sd(getLLSD(mMessage, block, var, blocknum));
157}
158
159//virtual
160void LLSDMessageReader::getIPPort(const char *block, const char *var,
161 U16 &port, S32 blocknum)
162{
163 port = getLLSD(mMessage, block, var, blocknum).asInteger();
164}
165
166//virtual
167void LLSDMessageReader::getString(const char *block, const char *var,
168 S32 buffer_size, char *buffer, S32 blocknum)
169{
170 std::string data = getLLSD(mMessage, block, var, blocknum);
171
172 S32 data_size = data.size();
173 if (data_size >= buffer_size)
174 {
175 data_size = buffer_size - 1;
176 }
177 memcpy(buffer, data.data(), data_size);
178 buffer[data_size] = '\0';
179}
180
181
182//virtual
183S32 LLSDMessageReader::getNumberOfBlocks(const char *blockname)
184{
185 return mMessage[blockname].size();
186}
187
188S32 getElementSize(const LLSD& llsd)
189{
190 LLSD::Type type = llsd.type();
191 switch(type)
192 {
193 case LLSD::TypeBoolean:
194 return sizeof(bool);
195 case LLSD::TypeInteger:
196 return sizeof(S32);
197 case LLSD::TypeReal:
198 return sizeof(F64);
199 case LLSD::TypeString:
200 return llsd.asString().size();
201 case LLSD::TypeUUID:
202 return sizeof(LLUUID);
203 case LLSD::TypeDate:
204 return sizeof(LLDate);
205 case LLSD::TypeURI:
206 return sizeof(LLURI);
207 case LLSD::TypeBinary:
208 {
209 std::vector<U8> data = llsd;
210 return data.size() * sizeof(U8);
211 }
212 case LLSD::TypeMap:
213 case LLSD::TypeArray:
214 case LLSD::TypeUndefined:
215 return 0;
216 }
217 return 0;
218}
219
220//virtual
221//Mainly used to find size of binary block of data
222S32 LLSDMessageReader::getSize(const char *blockname, const char *varname)
223{
224 return getElementSize(mMessage[blockname][0][varname]);
225}
226
227
228//virtual
229S32 LLSDMessageReader::getSize(const char *blockname, S32 blocknum,
230 const char *varname)
231{
232 return getElementSize(mMessage[blockname][blocknum][varname]);
233}
234
235//virtual
236void LLSDMessageReader::clearMessage()
237{
238 mMessage = LLSD();
239}
240
241//virtual
242const char* LLSDMessageReader::getMessageName() const
243{
244 return mMessageName.c_str();
245}
246
247// virtual
248S32 LLSDMessageReader::getMessageSize() const
249{
250 return 0;
251}
252
253//virtual
254void LLSDMessageReader::copyToBuilder(LLMessageBuilder& builder) const
255{
256 builder.copyFromLLSD(mMessage);
257}
258
259void LLSDMessageReader::setMessage(const std::string& name, const LLSD& message)
260{
261 mMessageName = name;
262 // TODO: Validate
263 mMessage = message;
264}