diff options
author | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:54 -0500 |
commit | b2afb8800bb033a04bb3ecdf0363068d56648ef1 (patch) | |
tree | 3568129b5bbddb47cd39d622b4137a8fbff4abaf /linden/indra/llmessage/llsdmessagereader.cpp | |
parent | Second Life viewer sources 1.14.0.1 (diff) | |
download | meta-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-x | linden/indra/llmessage/llsdmessagereader.cpp | 264 |
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 | |||
6 | LLSDMessageReader::LLSDMessageReader() | ||
7 | { | ||
8 | } | ||
9 | |||
10 | //virtual | ||
11 | LLSDMessageReader::~LLSDMessageReader() | ||
12 | { | ||
13 | } | ||
14 | |||
15 | |||
16 | LLSD 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 | ||
26 | void 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 | ||
47 | void 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 | ||
55 | void 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 | ||
62 | void 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 | ||
69 | void 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 | ||
76 | void 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 | ||
83 | void 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 | ||
90 | void 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 | ||
97 | void 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 | ||
104 | void 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 | ||
111 | void 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 | ||
118 | void 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 | ||
125 | void 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 | ||
132 | void 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 | ||
139 | void 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 | ||
146 | void 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 | ||
153 | void 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 | ||
160 | void 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 | ||
167 | void 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 | ||
183 | S32 LLSDMessageReader::getNumberOfBlocks(const char *blockname) | ||
184 | { | ||
185 | return mMessage[blockname].size(); | ||
186 | } | ||
187 | |||
188 | S32 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 | ||
222 | S32 LLSDMessageReader::getSize(const char *blockname, const char *varname) | ||
223 | { | ||
224 | return getElementSize(mMessage[blockname][0][varname]); | ||
225 | } | ||
226 | |||
227 | |||
228 | //virtual | ||
229 | S32 LLSDMessageReader::getSize(const char *blockname, S32 blocknum, | ||
230 | const char *varname) | ||
231 | { | ||
232 | return getElementSize(mMessage[blockname][blocknum][varname]); | ||
233 | } | ||
234 | |||
235 | //virtual | ||
236 | void LLSDMessageReader::clearMessage() | ||
237 | { | ||
238 | mMessage = LLSD(); | ||
239 | } | ||
240 | |||
241 | //virtual | ||
242 | const char* LLSDMessageReader::getMessageName() const | ||
243 | { | ||
244 | return mMessageName.c_str(); | ||
245 | } | ||
246 | |||
247 | // virtual | ||
248 | S32 LLSDMessageReader::getMessageSize() const | ||
249 | { | ||
250 | return 0; | ||
251 | } | ||
252 | |||
253 | //virtual | ||
254 | void LLSDMessageReader::copyToBuilder(LLMessageBuilder& builder) const | ||
255 | { | ||
256 | builder.copyFromLLSD(mMessage); | ||
257 | } | ||
258 | |||
259 | void LLSDMessageReader::setMessage(const std::string& name, const LLSD& message) | ||
260 | { | ||
261 | mMessageName = name; | ||
262 | // TODO: Validate | ||
263 | mMessage = message; | ||
264 | } | ||