本文整理汇总了C++中LLSD::asBinary方法的典型用法代码示例。如果您正苦于以下问题:C++ LLSD::asBinary方法的具体用法?C++ LLSD::asBinary怎么用?C++ LLSD::asBinary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LLSD
的用法示例。
在下文中一共展示了LLSD::asBinary方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: actual
void sd_object::test<2>()
{
const std::string decoded("random");
//const std::string encoded("cmFuZG9t\n");
const std::string streamed("b(6)\"random\"");
typedef std::vector<U8> buf_t;
buf_t buf;
std::copy(
decoded.begin(),
decoded.end(),
std::back_insert_iterator<buf_t>(buf));
LLSD sd;
sd = buf;
std::stringstream str;
S32 count = LLSDSerialize::toNotation(sd, str);
ensure_equals("output count", count, 1);
std::string actual(str.str());
ensure_equals("formatted binary encoding", actual, streamed);
sd.clear();
LLSDSerialize::fromNotation(sd, str);
std::vector<U8> after;
after = sd.asBinary();
ensure_equals("binary decoded size", after.size(), decoded.size());
ensure("binary decoding", (0 == memcmp(
&after[0],
decoded.c_str(),
decoded.size())));
}
示例2: rand
void sd_object::test<5>()
{
for(S32 i = 0; i < 100; ++i)
{
// gen up a starting point
typedef std::vector<U8> buf_t;
buf_t source;
srand(666 + i); /* Flawfinder: ignore */
S32 size = rand() % 1000 + 10;
std::generate_n(
std::back_insert_iterator<buf_t>(source),
size,
rand);
std::stringstream str;
str << "b(" << size << ")\"";
str.write((const char*)&source[0], size);
str << "\"";
LLSD sd;
S32 count = LLSDSerialize::fromNotation(sd, str);
ensure_equals("binary parse", count, 1);
buf_t actual = sd.asBinary();
ensure_equals("binary size", actual.size(), (size_t)size);
ensure("binary data", (0 == memcmp(&source[0], &actual[0], size)));
}
}
示例3: ll_string_from_binary
// Converts an LLSD binary to an LLSD string
LLSD ll_string_from_binary(const LLSD& sd)
{
std::vector<U8> value = sd.asBinary();
std::string str;
str.resize(value.size());
memcpy(&str[0], &value[0], value.size());
return str;
}
示例4: cipher
const std::string LLSavedLoginEntry::decryptPassword(const LLSD& pwdata)
{
std::string pw = "";
if (pwdata.isBinary() && pwdata.asBinary().size() == PASSWORD_HASH_LENGTH+1)
{
LLSD::Binary buffer = pwdata.asBinary();
LLXORCipher cipher(gMACAddress, 6);
cipher.decrypt(&buffer[0], PASSWORD_HASH_LENGTH);
buffer[PASSWORD_HASH_LENGTH] = '\0';
if (LLStringOps::isHexString(std::string(reinterpret_cast<const char*>(&buffer[0]), PASSWORD_HASH_LENGTH)))
{
pw.assign(reinterpret_cast<char*>(&buffer[0]));
}
}
return pw;
}
示例5: ll_ipaddr_from_sd
U32 ll_ipaddr_from_sd(const LLSD& sd)
{
U32 ret;
std::vector<U8> v = sd.asBinary();
if (v.size() < 4)
{
return 0;
}
memcpy(&ret, &(v[0]), 4); /* Flawfinder: ignore */
return ret;
}
示例6: ntohl
U64 ll_U64_from_sd(const LLSD& sd)
{
U32 high, low;
std::vector<U8> v = sd.asBinary();
if (v.size() < 8)
{
return 0;
}
memcpy(&high, &(v[0]), 4); /* Flawfinder: ignore */
memcpy(&low, &(v[4]), 4); /* Flawfinder: ignore */
high = ntohl(high);
low = ntohl(low);
return ((U64)high) << 32 | low;
}
示例7: format_impl
//.........这里部分代码省略.........
format_count += format_impl((*iter).second, ostr, options, level + 1);
}
ostr << pre << "</map>" << post;
}
break;
case LLSD::TypeArray:
if(0 == data.size())
{
ostr << pre << "<array />" << post;
}
else
{
ostr << pre << "<array>" << post;
LLSD::array_const_iterator iter = data.beginArray();
LLSD::array_const_iterator end = data.endArray();
for(; iter != end; ++iter)
{
format_count += format_impl(*iter, ostr, options, level + 1);
}
ostr << pre << "</array>" << post;
}
break;
case LLSD::TypeUndefined:
ostr << pre << "<undef />" << post;
break;
case LLSD::TypeBoolean:
ostr << pre << "<boolean>";
if(mBoolAlpha ||
(ostr.flags() & std::ios::boolalpha)
)
{
ostr << (data.asBoolean() ? "true" : "false");
}
else
{
ostr << (data.asBoolean() ? 1 : 0);
}
ostr << "</boolean>" << post;
break;
case LLSD::TypeInteger:
ostr << pre << "<integer>" << data.asInteger() << "</integer>" << post;
break;
case LLSD::TypeReal:
ostr << pre << "<real>";
if(mRealFormat.empty())
{
ostr << data.asReal();
}
else
{
formatReal(data.asReal(), ostr);
}
ostr << "</real>" << post;
break;
case LLSD::TypeUUID:
if(data.asUUID().isNull()) ostr << pre << "<uuid />" << post;
else ostr << pre << "<uuid>" << data.asUUID() << "</uuid>" << post;
break;
case LLSD::TypeString:
if(data.asStringRef().empty()) ostr << pre << "<string />" << post;
else ostr << pre << "<string>" << escapeString(data.asStringRef()) <<"</string>" << post;
break;
case LLSD::TypeDate:
ostr << pre << "<date>" << data.asDate() << "</date>" << post;
break;
case LLSD::TypeURI:
ostr << pre << "<uri>" << escapeString(data.asString()) << "</uri>" << post;
break;
case LLSD::TypeBinary:
{
const LLSD::Binary& buffer = data.asBinary();
if(buffer.empty())
{
ostr << pre << "<binary />" << post;
}
else
{
ostr << pre << "<binary encoding=\"base64\">";
ostr << LLBase64::encode(&buffer[0], buffer.size());
ostr << "</binary>" << post;
}
break;
}
default:
// *NOTE: This should never happen.
ostr << pre << "<undef />" << post;
break;
}
return format_count;
}
示例8: ensure_equals
void ensure_equals(const std::string& msg, const LLSD& actual,
const LLSD& expected)
{
ensure_equals(msg + " type", actual.type(), expected.type());
switch (actual.type())
{
case LLSD::TypeUndefined:
return;
case LLSD::TypeBoolean:
ensure_equals(msg + " boolean", actual.asBoolean(), expected.asBoolean());
return;
case LLSD::TypeInteger:
ensure_equals(msg + " integer", actual.asInteger(), expected.asInteger());
return;
case LLSD::TypeReal:
ensure_equals(msg + " real", actual.asReal(), expected.asReal());
return;
case LLSD::TypeString:
ensure_equals(msg + " string", actual.asString(), expected.asString());
return;
case LLSD::TypeUUID:
ensure_equals(msg + " uuid", actual.asUUID(), expected.asUUID());
return;
case LLSD::TypeDate:
ensure_equals(msg + " date", actual.asDate(), expected.asDate());
return;
case LLSD::TypeURI:
ensure_equals(msg + " uri", actual.asURI(), expected.asURI());
return;
case LLSD::TypeBinary:
ensure_equals(msg + " binary", actual.asBinary(), expected.asBinary());
return;
case LLSD::TypeMap:
{
ensure_equals(msg + " map size", actual.size(), expected.size());
LLSD::map_const_iterator actual_iter = actual.beginMap();
LLSD::map_const_iterator expected_iter = expected.beginMap();
while(actual_iter != actual.endMap())
{
ensure_equals(msg + " map keys",
actual_iter->first, expected_iter->first);
ensure_equals(msg + "[" + actual_iter->first + "]",
actual_iter->second, expected_iter->second);
++actual_iter;
++expected_iter;
}
return;
}
case LLSD::TypeArray:
{
ensure_equals(msg + " array size", actual.size(), expected.size());
for(int i = 0; i < actual.size(); ++i)
{
ensure_equals(msg + llformat("[%d]", i),
actual[i], expected[i]);
}
return;
}
default:
// should never get here, but compiler produces warning if we
// don't cover this case, and at Linden warnings are fatal.
throw failure(STRINGIZE("invalid type field " << actual.type()));
}
}
示例9:
//.........这里部分代码省略.........
#endif
ostr << "<array><data>";
LLSD::array_const_iterator it = sd.beginArray();
LLSD::array_const_iterator end = sd.endArray();
for(; it != end; ++it)
{
streamOut(ostr, *it);
if(ostr.fail())
{
llinfos << "STREAM FAILURE writing array element sd type "
<< (*it).type() << llendl;
}
}
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(array) END" << llendl;
#endif
ostr << "</data></array>";
break;
}
case LLSD::TypeUndefined:
// treat undefined as a bool with a false value.
case LLSD::TypeBoolean:
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(bool)" << llendl;
#endif
ostr << "<boolean>" << (sd.asBoolean() ? "1" : "0") << "</boolean>";
break;
case LLSD::TypeInteger:
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(int)" << llendl;
#endif
ostr << "<i4>" << sd.asInteger() << "</i4>";
break;
case LLSD::TypeReal:
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(real)" << llendl;
#endif
ostr << "<double>" << sd.asReal() << "</double>";
break;
case LLSD::TypeString:
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(string)" << llendl;
#endif
ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
break;
case LLSD::TypeUUID:
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(uuid)" << llendl;
#endif
// serialize it as a string
ostr << "<string>" << sd.asString() << "</string>";
break;
case LLSD::TypeURI:
{
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(uri)" << llendl;
#endif
// serialize it as a string
ostr << "<string>" << xml_escape_string(sd.asString()) << "</string>";
break;
}
case LLSD::TypeBinary:
{
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(binary)" << llendl;
#endif
// this is pretty inefficient, but we'll deal with that
// problem when it becomes one.
ostr << "<base64>";
LLSD::Binary buffer = sd.asBinary();
if(!buffer.empty())
{
// *TODO: convert to LLBase64
int b64_buffer_length = apr_base64_encode_len(buffer.size());
char* b64_buffer = new char[b64_buffer_length];
b64_buffer_length = apr_base64_encode_binary(
b64_buffer,
&buffer[0],
buffer.size());
ostr.write(b64_buffer, b64_buffer_length - 1);
delete[] b64_buffer;
}
ostr << "</base64>";
break;
}
case LLSD::TypeDate:
#if LL_SPEW_STREAM_OUT_DEBUGGING
llinfos << "streamOut(date)" << llendl;
#endif
// no need to escape this since it will be alpha-numeric.
ostr << "<dateTime.iso8601>" << sd.asString() << "</dateTime.iso8601>";
break;
default:
// unhandled type
llwarns << "Unhandled structured data type: " << sd.type()
<< llendl;
break;
}
ostr << "</value>";
}
示例10:
LLMaterialID::LLMaterialID(const LLSD& pMaterialID)
{
llassert(pMaterialID.isBinary());
parseFromBinary(pMaterialID.asBinary());
}
示例11: format
// virtual
S32 LLSDBinaryFormatter::format(const LLSD& data, std::ostream& ostr, U32 options) const
{
S32 format_count = 1;
switch(data.type())
{
case LLSD::TypeMap:
{
ostr.put('{');
U32 size_nbo = htonl(data.size());
ostr.write((const char*)(&size_nbo), sizeof(U32));
LLSD::map_const_iterator iter = data.beginMap();
LLSD::map_const_iterator end = data.endMap();
for(; iter != end; ++iter)
{
ostr.put('k');
formatString((*iter).first, ostr);
format_count += format((*iter).second, ostr);
}
ostr.put('}');
break;
}
case LLSD::TypeArray:
{
ostr.put('[');
U32 size_nbo = htonl(data.size());
ostr.write((const char*)(&size_nbo), sizeof(U32));
LLSD::array_const_iterator iter = data.beginArray();
LLSD::array_const_iterator end = data.endArray();
for(; iter != end; ++iter)
{
format_count += format(*iter, ostr);
}
ostr.put(']');
break;
}
case LLSD::TypeUndefined:
ostr.put('!');
break;
case LLSD::TypeBoolean:
if(data.asBoolean()) ostr.put(BINARY_TRUE_SERIAL);
else ostr.put(BINARY_FALSE_SERIAL);
break;
case LLSD::TypeInteger:
{
ostr.put('i');
U32 value_nbo = htonl(data.asInteger());
ostr.write((const char*)(&value_nbo), sizeof(U32));
break;
}
case LLSD::TypeReal:
{
ostr.put('r');
F64 value_nbo = ll_htond(data.asReal());
ostr.write((const char*)(&value_nbo), sizeof(F64));
break;
}
case LLSD::TypeUUID:
ostr.put('u');
ostr.write((const char*)(&(data.asUUID().mData)), UUID_BYTES);
break;
case LLSD::TypeString:
ostr.put('s');
formatString(data.asString(), ostr);
break;
case LLSD::TypeDate:
{
ostr.put('d');
F64 value = data.asReal();
ostr.write((const char*)(&value), sizeof(F64));
break;
}
case LLSD::TypeURI:
ostr.put('l');
formatString(data.asString(), ostr);
break;
case LLSD::TypeBinary:
{
// *FIX: memory inefficient.
ostr.put('b');
std::vector<U8> buffer = data.asBinary();
U32 size_nbo = htonl(buffer.size());
ostr.write((const char*)(&size_nbo), sizeof(U32));
if(buffer.size()) ostr.write((const char*)&buffer[0], buffer.size());
break;
}
default:
// *NOTE: This should never happen.
ostr.put('!');
//.........这里部分代码省略.........
示例12: setValue
void DOHexEditor::setValue(const LLSD& value)
{
mValue = value.asBinary();
changedLength();
}
示例13: format_impl
//.........这里部分代码省略.........
ostr << pre << "<array>" << post;
LLSD::array_const_iterator iter = data.beginArray();
LLSD::array_const_iterator end = data.endArray();
for(; iter != end; ++iter)
{
format_count += format_impl(*iter, ostr, options, level + 1);
}
ostr << pre << "</array>" << post;
}
break;
case LLSD::TypeUndefined:
ostr << pre << "<undef />" << post;
break;
case LLSD::TypeBoolean:
ostr << pre << "<boolean>";
if(mBoolAlpha ||
#if( LL_WINDOWS || __GNUC__ > 2)
(ostr.flags() & std::ios::boolalpha)
#else
(ostr.flags() & 0x0100)
#endif
)
{
ostr << (data.asBoolean() ? "true" : "false");
}
else
{
ostr << (data.asBoolean() ? 1 : 0);
}
ostr << "</boolean>" << post;
break;
case LLSD::TypeInteger:
ostr << pre << "<integer>" << data.asInteger() << "</integer>" << post;
break;
case LLSD::TypeReal:
ostr << pre << "<real>";
if(mRealFormat.empty())
{
ostr << data.asReal();
}
else
{
formatReal(data.asReal(), ostr);
}
ostr << "</real>" << post;
break;
case LLSD::TypeUUID:
if(data.asUUID().isNull()) ostr << pre << "<uuid />" << post;
else ostr << pre << "<uuid>" << data.asUUID() << "</uuid>" << post;
break;
case LLSD::TypeString:
if(data.asString().empty()) ostr << pre << "<string />" << post;
else ostr << pre << "<string>" << escapeString(data.asString()) <<"</string>" << post;
break;
case LLSD::TypeDate:
ostr << pre << "<date>" << data.asDate() << "</date>" << post;
break;
case LLSD::TypeURI:
ostr << pre << "<uri>" << escapeString(data.asString()) << "</uri>" << post;
break;
case LLSD::TypeBinary:
{
LLSD::Binary buffer = data.asBinary();
if(buffer.empty())
{
ostr << pre << "<binary />" << post;
}
else
{
// *FIX: memory inefficient.
// *TODO: convert to use LLBase64
ostr << pre << "<binary encoding=\"base64\">";
int b64_buffer_length = apr_base64_encode_len(buffer.size());
char* b64_buffer = new char[b64_buffer_length];
b64_buffer_length = apr_base64_encode_binary(
b64_buffer,
&buffer[0],
buffer.size());
ostr.write(b64_buffer, b64_buffer_length - 1);
delete[] b64_buffer;
ostr << "</binary>" << post;
}
break;
}
default:
// *NOTE: This should never happen.
ostr << pre << "<undef />" << post;
break;
}
return format_count;
}
示例14: format_impl
//.........这里部分代码省略.........
if(need_comma) ostr << ",";
need_comma = true;
format_count += format_impl(*iter, ostr, options, level + 1);
}
ostr << "]";
break;
}
case LLSD::TypeUndefined:
ostr << "!";
break;
case LLSD::TypeBoolean:
if(mBoolAlpha ||
#if( LL_WINDOWS || __GNUC__ > 2)
(ostr.flags() & std::ios::boolalpha)
#else
(ostr.flags() & 0x0100)
#endif
)
{
ostr << (data.asBoolean()
? NOTATION_TRUE_SERIAL : NOTATION_FALSE_SERIAL);
}
else
{
ostr << (data.asBoolean() ? 1 : 0);
}
break;
case LLSD::TypeInteger:
ostr << "i" << data.asInteger();
break;
case LLSD::TypeReal:
ostr << "r";
if(mRealFormat.empty())
{
ostr << data.asReal();
}
else
{
formatReal(data.asReal(), ostr);
}
break;
case LLSD::TypeUUID:
ostr << "u" << data.asUUID();
break;
case LLSD::TypeString:
ostr << '\'';
serialize_string(data.asStringRef(), ostr);
ostr << '\'';
break;
case LLSD::TypeDate:
ostr << "d\"" << data.asDate() << "\"";
break;
case LLSD::TypeURI:
ostr << "l\"";
serialize_string(data.asString(), ostr);
ostr << "\"";
break;
case LLSD::TypeBinary:
{
// *FIX: memory inefficient.
const std::vector<U8>& buffer = data.asBinary();
ostr << "b(" << buffer.size() << ")\"";
if(buffer.size())
{
if (options & LLSDFormatter::OPTIONS_PRETTY_BINARY)
{
std::ios_base::fmtflags old_flags = ostr.flags();
ostr.setf( std::ios::hex, std::ios::basefield );
ostr << "0x";
for (size_t i = 0; i < buffer.size(); i++)
{
ostr << (int) buffer[i];
}
ostr.flags(old_flags);
}
else
{
ostr.write((const char*)&buffer[0], buffer.size());
}
}
ostr << "\"";
break;
}
default:
// *NOTE: This should never happen.
ostr << "!";
break;
}
return format_count;
}