aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llsdutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llcommon/llsdutil.cpp')
-rw-r--r--linden/indra/llcommon/llsdutil.cpp62
1 files changed, 57 insertions, 5 deletions
diff --git a/linden/indra/llcommon/llsdutil.cpp b/linden/indra/llcommon/llsdutil.cpp
index 0f295a1..d30afc7 100644
--- a/linden/indra/llcommon/llsdutil.cpp
+++ b/linden/indra/llcommon/llsdutil.cpp
@@ -6,6 +6,7 @@
6 * 6 *
7 * Copyright (c) 2006-2007, Linden Research, Inc. 7 * Copyright (c) 2006-2007, Linden Research, Inc.
8 * 8 *
9 * Second Life Viewer Source Code
9 * The source code in this file ("Source Code") is provided by Linden Lab 10 * The source code in this file ("Source Code") is provided by Linden Lab
10 * to you under the terms of the GNU General Public License, version 2.0 11 * to you under the terms of the GNU General Public License, version 2.0
11 * ("GPL"), unless you have obtained a separate licensing agreement 12 * ("GPL"), unless you have obtained a separate licensing agreement
@@ -40,7 +41,7 @@
40# include <arpa/inet.h> 41# include <arpa/inet.h>
41#endif 42#endif
42 43
43 44#include "llsdserialize.h"
44 45
45// vector3 46// vector3
46LLSD ll_sd_from_vector3(const LLVector3& vec) 47LLSD ll_sd_from_vector3(const LLVector3& vec)
@@ -61,6 +62,27 @@ LLVector3 ll_vector3_from_sd(const LLSD& sd, S32 start_index)
61 return rv; 62 return rv;
62} 63}
63 64
65// vector4
66LLSD ll_sd_from_vector4(const LLVector4& vec)
67{
68 LLSD rv;
69 rv.append((F64)vec.mV[VX]);
70 rv.append((F64)vec.mV[VY]);
71 rv.append((F64)vec.mV[VZ]);
72 rv.append((F64)vec.mV[VW]);
73 return rv;
74}
75
76LLVector4 ll_vector4_from_sd(const LLSD& sd, S32 start_index)
77{
78 LLVector4 rv;
79 rv.mV[VX] = (F32)sd[start_index].asReal();
80 rv.mV[VY] = (F32)sd[++start_index].asReal();
81 rv.mV[VZ] = (F32)sd[++start_index].asReal();
82 rv.mV[VW] = (F32)sd[++start_index].asReal();
83 return rv;
84}
85
64// vector3d 86// vector3d
65LLSD ll_sd_from_vector3d(const LLVector3d& vec) 87LLSD ll_sd_from_vector3d(const LLVector3d& vec)
66{ 88{
@@ -227,9 +249,39 @@ U32 ll_ipaddr_from_sd(const LLSD& sd)
227LLSD ll_string_from_binary(const LLSD& sd) 249LLSD ll_string_from_binary(const LLSD& sd)
228{ 250{
229 std::vector<U8> value = sd.asBinary(); 251 std::vector<U8> value = sd.asBinary();
230 char* c_str = new char[value.size() + 1]; 252 std::string str;
231 memcpy(c_str, &value[0], value.size()); 253 str.resize(value.size());
232 c_str[value.size()] = '\0'; 254 memcpy(&str[0], &value[0], value.size());
255 return str;
256}
233 257
234 return c_str; 258// Converts an LLSD string to an LLSD binary
259LLSD ll_binary_from_string(const LLSD& sd)
260{
261 std::vector<U8> binary_value;
262
263 LLString string_value = sd.asString();
264 const char* string_p = string_value.c_str();
265 while (*string_p)
266 {
267 binary_value.push_back(*string_p);
268 string_p++;
269 }
270
271 binary_value.push_back('\0');
272
273 return binary_value;
274}
275
276char* ll_print_sd(const LLSD& sd)
277{
278 const U32 bufferSize = 10 * 1024;
279 static char buffer[bufferSize];
280 std::ostringstream stream;
281 //stream.rdbuf()->pubsetbuf(buffer, bufferSize);
282 stream << LLSDOStreamer<LLSDXMLFormatter>(sd);
283 stream << std::ends;
284 strncpy(buffer, stream.str().c_str(), bufferSize);
285 buffer[bufferSize - 1] = '\0';
286 return buffer;
235} 287}