本文整理汇总了C++中Bytes函数的典型用法代码示例。如果您正苦于以下问题:C++ Bytes函数的具体用法?C++ Bytes怎么用?C++ Bytes使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Bytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Bytes
// ---------------------------------------------------------
// CDownloadDataClient::MarshalDataL()
// ---------------------------------------------------------
//
HBufC8* CDownloadDataClient::MarshalDataL() const
{
TInt bufLen = Bytes(); // Size of class including iMediaArray elements.
// Note that this includes actual bytes occupied by
// contents of descriptors and pointers.
bufLen += sizeof(TInt); // We include the count of elements in iMediaArray
// while externalizing.
bufLen += sizeof(TInt) * iMediaArray.Count();
// iMediaArray has an array iTypes. We are including
// count of elements in iTypes array while externalizing
// each element of iMediaArray.
// Dynamic data buffer
CBufFlat* buf = CBufFlat::NewL(bufLen);
CleanupStack::PushL(buf);
// Stream over the buffer
RBufWriteStream stream(*buf);
CleanupClosePushL(stream);
ExternalizeL(stream);
CleanupStack::PopAndDestroy(); //stream
// Create a heap descriptor from the buffer
HBufC8* des = HBufC8::NewL(buf->Size());
TPtr8 ptr(des->Des());
buf->Read(0, ptr, buf->Size());
CleanupStack::PopAndDestroy(); //buf
return des;
}
示例2: proc_ndel
int proc_ndel(NetworkServer *net, Link *link, const Request &req, Response *resp){
SSDBServer *serv = (SSDBServer *)net->data;
CHECK_NUM_PARAMS(3);
Locking l(&serv->expiration->mutex);
int ret = serv->ssdb->ndel(req[1], req[2]);
if(ret == -1){
resp->push_back("error");
}else{
std::string buf;
buf.append(1, DataType::NSET);
buf.append(1, (uint8_t)req[1].size());
buf.append(req[1].data(), req[1].size());
int64_t s = req[2].Int64();
if(s < 0){
buf.append(1, '-');
}else{
buf.append(1, '=');
}
s = encode_score(s);
buf.append((char *)&s, sizeof(int64_t));
serv->expiration->del_ttl(Bytes(buf));
resp->push_back("ok");
resp->push_back("1");
}
return 0;
}
示例3: du
Try<Bytes> du(std::string path)
{
// Make sure 'path' starts with a '/'.
path = path::join("", path);
Try<std::string> command = strings::format(
"%s fs -du -h '%s'", hadoop, path);
CHECK_SOME(command);
std::ostringstream output;
Try<int> status = os::shell(&output, command.get() + " 2>&1");
if (status.isError()) {
return Error("HDFS du failed: " + status.error());
}
const std::vector<std::string>& s = strings::split(output.str(), " ");
if (s.size() != 2) {
return Error("HDFS du returned an unexpected number of results: '" +
output.str() + "'");
}
Result<size_t> size = numify<size_t>(s[0]);
if (size.isError()) {
return Error("HDFS du returned unexpected format: " + size.error());
} else if (size.isNone()) {
return Error("HDFS du returned unexpected format");
}
return Bytes(size.get());
}
示例4: strtolower
const std::vector<Bytes>* RedisLink::recv_req(Buffer *input){
int ret = this->parse_req(input);
if(ret == -1){
return NULL;
}
if(recv_bytes.empty()){
return &recv_bytes;
}
cmd = recv_bytes[0].String();
strtolower(&cmd);
recv_string.clear();
this->convert_req();
// Bytes don't hold memory, so we firstly copy Bytes into string and store
// in a vector of string, then create Bytes-es prointing to strings
recv_bytes.clear();
for(int i=0; i<recv_string.size(); i++){
std::string *str = &recv_string[i];
recv_bytes.push_back(Bytes(str->data(), str->size()));
}
return &recv_bytes;
}
示例5: HQWrappedPictureIO
std::ostream& HQWrappedPictureIO(std::ostream& stream, const WrappedPicture& d) {
std::ostringstream ss;
ss.copyfmt(stream);
// Picture Header
ss << Bytes(4, d.picture_number);
// Transform Params
ss << vlc::unbounded
<< UnsignedVLC(d.wavelet_kernel)
<< UnsignedVLC(d.depth)
<< UnsignedVLC(d.slices_x)
<< UnsignedVLC(d.slices_y)
<< UnsignedVLC(d.slice_prefix)
<< UnsignedVLC(d.slice_size_scalar)
<< Boolean(false)
<< vlc::align;
// Transform Data
ss << d.slices;
stream << ParseInfoIO(HQ_PICTURE, ss.str().size());
return (stream << ss.str());
}
示例6: time_ms
int ExpirationHandler::set_ttl(const Bytes &key, int64_t ttl){
int64_t expired = time_ms() + ttl * 1000;
char data[30];
int size = snprintf(data, sizeof(data), "%" PRId64, expired);
if(size <= 0){
log_error("snprintf return error!");
return -1;
}
int ret = ssdb->zset(this->list_name, key, Bytes(data, size));
if(ret == -1){
return -1;
}
if(!this->enable){
return 0;
}
if(expired < first_timeout){
first_timeout = expired;
}
std::string s_key = key.String();
fast_keys.del(s_key);
if(expired <= fast_keys.max_score()){
fast_keys.add(s_key, expired);
if(fast_keys.size() > BATCH_SIZE){
log_debug("pop_back");
fast_keys.pop_back();
}
}else{
//log_debug("don't put in fast_keys");
}
return 0;
}
示例7: DwTrace
void DwTrace(void) { // Execute one instruction
DwSetRegs(28, R+28, 4); // Restore cached registers
DwSetPC(PC/2); // Trace start address
DwSend(Bytes(0x60, 0x31)); // Single step
DwSync();
DwReconnect();
}
示例8: size
// Returns the size in Bytes of a given file system entry. When
// applied to a symbolic link with `follow` set to
// `DO_NOT_FOLLOW_SYMLINK`, this will return the length of the entry
// name (strlen).
inline Try<Bytes> size(
const std::string& path,
const FollowSymlink follow = FOLLOW_SYMLINK)
{
struct stat s;
switch (follow) {
case DO_NOT_FOLLOW_SYMLINK: {
if (::lstat(path.c_str(), &s) < 0) {
return ErrnoError("Error invoking lstat for '" + path + "'");
}
break;
}
case FOLLOW_SYMLINK: {
if (::stat(path.c_str(), &s) < 0) {
return ErrnoError("Error invoking stat for '" + path + "'");
}
break;
}
default: {
UNREACHABLE();
}
}
return Bytes(s.st_size);
}
示例9: TEST
TEST(BytesTest, Stringify)
{
EXPECT_NE(Megabytes(1023), Gigabytes(1));
EXPECT_EQ("0B", stringify(Bytes()));
EXPECT_EQ("1KB", stringify(Kilobytes(1)));
EXPECT_EQ("1MB", stringify(Megabytes(1)));
EXPECT_EQ("1GB", stringify(Gigabytes(1)));
EXPECT_EQ("1TB", stringify(Terabytes(1)));
EXPECT_EQ("1023B", stringify(Bytes(1023)));
EXPECT_EQ("1023KB", stringify(Kilobytes(1023)));
EXPECT_EQ("1023MB", stringify(Megabytes(1023)));
EXPECT_EQ("1023GB", stringify(Gigabytes(1023)));
}
示例10: lime_audio_load
value lime_audio_load (value data) {
AudioBuffer audioBuffer;
Resource resource;
Bytes bytes;
if (val_is_string (data)) {
resource = Resource (val_string (data));
} else {
bytes = Bytes ();
bytes.Set (data);
resource = Resource (&bytes);
}
if (WAV::Decode (&resource, &audioBuffer)) {
return audioBuffer.Value ();
}
#ifdef LIME_OGG
if (OGG::Decode (&resource, &audioBuffer)) {
return audioBuffer.Value ();
}
#endif
return alloc_null ();
}
示例11: DwGo
void DwGo(void) { // Begin executing.
DwSetRegs(28, R+28, 4); // Restore cached registers
DwSetPC(PC/2); // Execution start address
if (BP < 0) { // Prepare to start execution with no breakpoint set
DwSend(Bytes(TimerEnable ? 0x40 : 0x60)); // Set execution context
} else { // Prpare to start execution with breakpoint set
DwSetBP(BP/2); // Breakpoint address
DwSend(Bytes(TimerEnable ? 0x41 : 0x61)); // Set execution context including breakpoint enable
}
DwSend(Bytes(0x30)); // Continue execution (go)
DwWait();
// Note: We return to UI with the target processor running. The UI go command handles
// getting control back, either on the debice hitting the hardware breakpoint, or
// on the user pressing return to trigger a break.
}
示例12: OnFull
// Returns the first string in the list. Note that the very first string is
// always discarded.
Bytes OnFull(Bytes const bytes,
not_null<std::list<std::string>*> const strings) {
strings->push_back(
std::string(reinterpret_cast<const char*>(&bytes.data[0]),
static_cast<size_t>(bytes.size)));
return Bytes(data_, kSmallChunkSize);
}
示例13: GetDeviceType
int GetDeviceType(void) {
DwSend(Bytes(0xF3)); // Request signature
int signature = DwReadWord();
int i=0; while ( Characteristics[i].signature
&& Characteristics[i].signature != signature) {i++;}
return Characteristics[i].signature ? i : -1;
}
示例14: write
Bytes write(const data::Value &data, EncodeFormat fmt) {
if (fmt.isRaw()) {
switch (fmt.format) {
case EncodeFormat::Json: {
String s = writeJson(data, false);
Bytes ret; ret.reserve(s.length());
ret.assign(s.begin(), s.end());
return ret;
}
break;
case EncodeFormat::Pretty: {
String s = writeJson(data, true);
Bytes ret; ret.reserve(s.length());
ret.assign(s.begin(), s.end());
return ret;
}
break;
case EncodeFormat::Cbor:
case EncodeFormat::DefaultFormat:
return writeCbor(data);
break;
}
}
return Bytes();
}
示例15: openFile
Bytes Info::openFile(const String &file) const {
auto containerIt = _manifest.find(file);
if (containerIt != _manifest.end()) {
return openFile(containerIt->second);
}
return Bytes();
}