本文整理汇总了C++中StringBuffer::GetSize方法的典型用法代码示例。如果您正苦于以下问题:C++ StringBuffer::GetSize方法的具体用法?C++ StringBuffer::GetSize怎么用?C++ StringBuffer::GetSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringBuffer
的用法示例。
在下文中一共展示了StringBuffer::GetSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(StringBuffer, Push) {
StringBuffer buffer;
buffer.Push(5);
EXPECT_EQ(5u, buffer.GetSize());
// Causes sudden expansion to make the stack's capacity equal to size
buffer.Push(65536u);
EXPECT_EQ(5u + 65536u, buffer.GetSize());
}
示例2: run_test
bool run_test(uint32_t* hash_out) {
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
write_object(writer, root_object);
*hash_out = hash_str(*hash_out, buffer.GetString(), buffer.GetSize());
return true;
}
示例3: jsonToString
std::string jsonToString(const Value& elem)
{
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
elem.Accept(writer);
return std::string(buffer.GetString(), buffer.GetSize());
}
示例4: main
int main(int argc, char **argv)
{
Document d;
d.SetObject();
Value vElem;
vElem.SetArray();
Document::AllocatorType & allocator = d.GetAllocator();
for(int i = 0; i < 10; ++i)
{
Value tmp;///(i);
tmp.SetInt(i);
// vElem.PushBack<int>(i, d.GetAllocator);
vElem.PushBack(tmp, allocator);
}
d.AddMember("Data", vElem, allocator);
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
d.Accept(writer);
string json(buffer.GetString(), buffer.GetSize());
cout << json << endl;
// Document::AllocatorType& a = d.GetAllocator();
// cout << d["test"].IsNull() << endl;// = 1;
// Value v1("foo");
// Value v2(v1, a);
}
示例5: s
TEST(Writer, Compact) {
StringStream s("{ \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3] } ");
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
Reader reader;
reader.Parse<0>(s, writer);
EXPECT_STREQ("{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3]}", buffer.GetString());
EXPECT_EQ(77u, buffer.GetSize());
}
示例6: doc2str
string doc2str(Document &doc)
{
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
string str(buffer.GetString(), buffer.GetSize());
return str;
}
示例7: jsonToPrettyString
std::string jsonToPrettyString(const Value& elem)
{
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer);
writer.SetIndent(' ', 2);
writer.SetFormatOptions(PrettyFormatOptions::kFormatSingleLineArray);
elem.Accept(writer);
return std::string(buffer.GetString(), buffer.GetSize());
}
示例8: Save
bool JSONFile::Save(Serializer& dest, const String& indendation) const
{
StringBuffer buffer;
PrettyWriter<StringBuffer> writer(buffer, &(document_->GetAllocator()));
writer.SetIndent(!indendation.Empty() ? indendation.Front() : '\0', indendation.Length());
document_->Accept(writer);
unsigned size = (unsigned)buffer.GetSize();
return dest.Write(buffer.GetString(), size) == size;
}
示例9: writer
int Dynamo::Json2str(const rapidjson::Value &json, std::string& str) {
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
if (false == json.Accept(writer)) {
snprintf(lastErr, sizeof(lastErr), "Value::Accept failed");
return -1;
}
str.append(buffer.GetString(), buffer.GetSize());
return 0;
}
示例10: accept
bool packet::accept(string& payload_ptr, vector<shared_ptr<const string> >&buffers)
{
char frame_char = _frame+'0';
payload_ptr.append(&frame_char,1);
if (_frame!=frame_message) {
return false;
}
bool hasMessage = false;
Document doc;
if (_message) {
accept_message(*_message, doc, doc, buffers);
hasMessage = true;
}
bool hasBinary = buffers.size()>0;
_type = _type&(~type_undetermined);
if(_type == type_event)
{
_type = hasBinary?type_binary_event:type_event;
}
else if(_type == type_ack)
{
_type = hasBinary? type_binary_ack : type_ack;
}
ostringstream ss;
ss.precision(8);
ss<<_type;
if (hasBinary) {
ss<<buffers.size()<<"-";
}
if(_nsp.size()>0 && _nsp!="/")
{
ss<<_nsp;
if (hasMessage || _pack_id>=0) {
ss<<",";
}
}
if(_pack_id>=0)
{
ss<<_pack_id;
}
payload_ptr.append(ss.str());
if (hasMessage)
{
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
payload_ptr.append(buffer.GetString(),buffer.GetSize());
}
return hasBinary;
}
示例11: y
TEST(StringBuffer, MoveConstructor) {
StringBuffer x;
x.Put('A');
x.Put('B');
x.Put('C');
x.Put('D');
EXPECT_EQ(4u, x.GetSize());
EXPECT_STREQ("ABCD", x.GetString());
// StringBuffer y(x); // does not compile (!is_copy_constructible)
StringBuffer y(std::move(x));
EXPECT_EQ(0u, x.GetSize());
EXPECT_EQ(4u, y.GetSize());
EXPECT_STREQ("ABCD", y.GetString());
// StringBuffer z = y; // does not compile (!is_copy_assignable)
StringBuffer z = std::move(y);
EXPECT_EQ(0u, y.GetSize());
EXPECT_EQ(4u, z.GetSize());
EXPECT_STREQ("ABCD", z.GetString());
}
示例12: json_encode
static int json_encode(lua_State* L)
{
try
{
Encoder encode(L, 2);
StringBuffer s;
encode.encode(L, &s, 1);
lua_pushlstring(L, s.GetString(), s.GetSize());
return 1;
}
catch (...)
{
luaL_error(L, "error while encoding");
}
return 0;
}
示例13: create_json_response_sds
void create_json_response_sds(write_batch* batch) {
StringBuffer s;
Writer<StringBuffer> writer(s);
writer.StartObject();
writer.Key("message");
writer.String("Hello, World!");
writer.EndObject();
sds response_buffer = sdsnew("HTTP/1.1 200 OK\r\n");
response_buffer = sdscat(response_buffer, "Server: octane\r\n");
response_buffer = sdscat(response_buffer, "Content-Type: application/json\r\n");
response_buffer = sdscatprintf(response_buffer, "Content-Length: %d\r\n", s.GetSize());
response_buffer = sdscatprintf(response_buffer, "Date: %s\r\n", current_time);
response_buffer = sdscat(response_buffer, s.GetString());
batch->buffers[batch->number_of_used_buffers].base = response_buffer;
batch->buffers[batch->number_of_used_buffers].len = sdslen(response_buffer);
batch->number_of_used_buffers++;
}
示例14: bis
TEST(Document, ParseStream_EncodedInputStream) {
// UTF8 -> UTF16
FILE* fp = OpenEncodedFile("utf8.json");
char buffer[256];
FileReadStream bis(fp, buffer, sizeof(buffer));
EncodedInputStream<UTF8<>, FileReadStream> eis(bis);
GenericDocument<UTF16<> > d;
d.ParseStream<0, UTF8<> >(eis);
EXPECT_FALSE(d.HasParseError());
fclose(fp);
wchar_t expected[] = L"I can eat glass and it doesn't hurt me.";
GenericValue<UTF16<> >& v = d[L"en"];
EXPECT_TRUE(v.IsString());
EXPECT_EQ(sizeof(expected) / sizeof(wchar_t) - 1, v.GetStringLength());
EXPECT_EQ(0, StrCmp(expected, v.GetString()));
// UTF16 -> UTF8 in memory
StringBuffer bos;
typedef EncodedOutputStream<UTF8<>, StringBuffer> OutputStream;
OutputStream eos(bos, false); // Not writing BOM
{
Writer<OutputStream, UTF16<>, UTF8<> > writer(eos);
d.Accept(writer);
}
// Condense the original file and compare.
fp = OpenEncodedFile("utf8.json");
FileReadStream is(fp, buffer, sizeof(buffer));
Reader reader;
StringBuffer bos2;
Writer<StringBuffer> writer2(bos2);
reader.Parse(is, writer2);
fclose(fp);
EXPECT_EQ(bos.GetSize(), bos2.GetSize());
EXPECT_EQ(0, memcmp(bos.GetString(), bos2.GetString(), bos2.GetSize()));
}
示例15: bis
TEST(Document, ParseStream_AutoUTFInputStream) {
// Any -> UTF8
FILE* fp = OpenEncodedFile("utf32be.json");
char buffer[256];
FileReadStream bis(fp, buffer, sizeof(buffer));
AutoUTFInputStream<unsigned, FileReadStream> eis(bis);
Document d;
d.ParseStream<0, AutoUTF<unsigned> >(eis);
EXPECT_FALSE(d.HasParseError());
fclose(fp);
char expected[] = "I can eat glass and it doesn't hurt me.";
Value& v = d["en"];
EXPECT_TRUE(v.IsString());
EXPECT_EQ(sizeof(expected) - 1, v.GetStringLength());
EXPECT_EQ(0, StrCmp(expected, v.GetString()));
// UTF8 -> UTF8 in memory
StringBuffer bos;
Writer<StringBuffer> writer(bos);
d.Accept(writer);
{
// Condense the original file and compare.
FILE *fp = OpenEncodedFile("utf8.json");
FileReadStream is(fp, buffer, sizeof(buffer));
Reader reader;
StringBuffer bos2;
Writer<StringBuffer> writer(bos2);
reader.Parse(is, writer);
fclose(fp);
EXPECT_EQ(bos.GetSize(), bos2.GetSize());
EXPECT_EQ(0, memcmp(bos.GetString(), bos2.GetString(), bos2.GetSize()));
}
}