本文整理汇总了C++中Data::Append方法的典型用法代码示例。如果您正苦于以下问题:C++ Data::Append方法的具体用法?C++ Data::Append怎么用?C++ Data::Append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data
的用法示例。
在下文中一共展示了Data::Append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buf
torch::Data Bz2::Decompress(const torch::Data &data)
{
const int size100k = 100000;
int bufsize = size100k * Bz2::block100k;
int status = 0;
bz_stream stream = {0};
Data buf(bufsize);
Data dst;
dst.HiddenAlloc(data.GetSize() * 2);
/* next_in should point at the data to be compressed
* avail_in should indicate how many bytes the library may read
* BZ2_bzDecompress updates next_in, avail_in and total_in to reflect the number of bytes it has read */
stream.next_in = (char*) data.GetBytes();
stream.avail_in = (int)data.GetSize();
/* next_out should point to a buffer in which the compressed data is to be placed
* avail_out indicating how much output space is available.
* BZ2_bzDecompress updates next_out, avail_out and total_out to reflect the number of bytes output. */
stream.next_out = (char*)buf.GetBytes();
stream.avail_out = (int)buf.GetSize();
status = BZ2_bzDecompressInit(&stream, 0, 0);
if (status != BZ_OK) {
BZ2_bzDecompressEnd(&stream);
return dst;
}
do {
status = BZ2_bzDecompress(&stream);
if (status != BZ_OK && status != BZ_STREAM_END)
break;
dst.Append(buf.GetBytes(), bufsize - stream.avail_out);
stream.next_out = (char*)buf.GetBytes();
stream.avail_out = (int)buf.GetSize();
}while (status != BZ_STREAM_END);
BZ2_bzDecompressEnd(&stream);
return dst;
}
示例2: torch_data
bool torch_data() {
using namespace torch;
std::string respath = Path(projectdir).Append("/tests/res").GetPath();
std::string testpath = Path(respath).Append("test.go").GetPath();
// torch::Data d = torch::File::GetBytes(testpath);
// InfoLog("%s\n", d.ToString().c_str());
Data buf;
int count = 0;
// Fill
buf.Fill(0, 1);
buf.Fill(1, 2, 0);
buf.DumpHex();
buf.Free();
// Alloc
buf.Alloc(sizeof("hello,world"));
if ( buf.GetSize() != 12 ) return false;
buf.Free();
if ( buf.GetSize() != 0 ) return false;
printf("[%d] %zu\n", ++count, buf.GetSize());
char *ptr = "hello,world";
size_t size = (strlen(ptr)+1) * sizeof(char);
buf.Alloc( size );
// CopyFrom
buf.CopyFrom(ptr, size);
((char *)buf.GetBytes())[5] = '|';
printf("print string: %s\n", buf.ToString().c_str());
// Insert
echo("[Insert] Free");
buf.Free();
buf.DumpHex();
buf.Free();
echo ("[Insert] Insert \"\\1\\2\\3\\4\\5\\6\\7\" -> 0xff(3)");
char s1[] = "\1\2\3\4\5\6\7";
buf.Insert(0, s1, sizeof(s1));
buf.DumpHex();
buf.DumpBinary();
buf.DumpBinary(1);
buf.DumpBinary(2);
if (buf.ToHex() != std::string("0102030405060700")) return false;
if (buf.ToBinary(1) != std::string("00000001 00000010 00000011 00000100 00000101 00000110 00000111 00000000")) return false;
if (buf.ToBinary(2) != std::string("0000000100000010 0000001100000100 0000010100000110 0000011100000000")) return false;
if (buf.ToBinary() != std::string("0000000100000010000000110000010000000101000001100000011100000000")) return false;
{
Data b = buf;
b.DumpHex();
b.Insert(-1, 0xff);
b.DumpHex();
if (b.ToHex() != "01020304050607FF00") return false;
}
{
char str[] = "hello,world";
Data b;
b.Insert(0, str, sizeof(str));
printf("%s\n", b.GetBytes());
}
buf.Insert(3, 0xff);
buf.DumpHex();
if (buf.ToHex() != "010203FF0405060700") return false;
buf.Free();
char ss[] = "hello,world";
buf.Insert(0, ss, sizeof(ss));
printf("%s\n", buf.GetBytes());
if (std::string("hello,world") != (char*)buf.GetBytes()) return false;
buf.Insert(3, '|');
printf("%s\n", buf.GetBytes());
if (std::string("hel|lo,world") != (char*)buf.GetBytes()) return false;
// Append
echo ("[Append] Append \\0");
buf.Free();
buf.Append('\0');
if (buf.ToHex() != "00") return false;
buf.DumpHex();
echo ("[Append] Append \"\\1\\2\\3\\4\\5\\6\\7\"");
buf.Append(s1, sizeof(s1));
if (buf.ToHex() != "000102030405060700") return false;
buf.DumpHex();
Data b;
b.Append((void*)"\0\0", 2);
buf.Append(b);
if (buf.ToHex(2) != "0001 0203 0405 0607 0000 00") return false;
buf.DumpHex(2);
// Erase
//.........这里部分代码省略.........