// --------------------------------------------------------- // 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; }
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; }
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()); }
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; }
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()); }
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; }
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(); }
// 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); }
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))); }
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 (); }
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. }
// 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); }
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; }
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(); }
Bytes Info::openFile(const String &file) const { auto containerIt = _manifest.find(file); if (containerIt != _manifest.end()) { return openFile(containerIt->second); } return Bytes(); }
// Downloads the header of the specified HTTP URL with a HEAD request // and queries its "content-length" field. (Note that according to the // HTTP specification there is no guarantee that this field contains // any useful value.) inline Try<Bytes> contentLength(const std::string& url) { initialize(); CURL* curl = curl_easy_init(); if (curl == NULL) { curl_easy_cleanup(curl); return Error("Failed to initialize libcurl"); } curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl, CURLOPT_HEADER, 1); curl_easy_setopt(curl, CURLOPT_NOBODY, 1); CURLcode curlErrorCode = curl_easy_perform(curl); if (curlErrorCode != 0) { curl_easy_cleanup(curl); return Error(curl_easy_strerror(curlErrorCode)); } double result; curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &result); curl_easy_cleanup(curl); if (result < 0) { return Error("No URL content-length available"); } return Bytes(uint64_t(result)); }
int SSDB::qfix(const Bytes &name){ Transaction trans(binlogs); std::string key_s = encode_qitem_key(name, QITEM_MIN_SEQ - 1); std::string key_e = encode_qitem_key(name, QITEM_MAX_SEQ); bool error = false; uint64_t seq_min = 0; uint64_t seq_max = 0; uint64_t count = 0; Iterator *it = this->iterator(key_s, key_e, QITEM_MAX_SEQ); while(it->next()){ //dump(it->key().data(), it->key().size()); if(seq_min == 0){ if(decode_qitem_key(it->key(), NULL, &seq_min) == -1){ // or just delete it? error = true; break; } } if(decode_qitem_key(it->key(), NULL, &seq_max) == -1){ error = true; break; } count ++; } delete it; if(error){ return -1; } if(count == 0){ this->binlogs->Delete(encode_qsize_key(name)); qdel_one(this, name, QFRONT_SEQ); qdel_one(this, name, QBACK_SEQ); }else{ this->binlogs->Put(encode_qsize_key(name), leveldb::Slice((char *)&count, sizeof(count))); qset_one(this, name, QFRONT_SEQ, Bytes(&seq_min, sizeof(seq_min))); qset_one(this, name, QBACK_SEQ, Bytes(&seq_max, sizeof(seq_max))); } leveldb::Status s = binlogs->commit(); if(!s.ok()){ log_error("Write error!"); return -1; } return 0; }
int Buffer::read_record(Bytes *s){ char *head = this->data(); char *body = (char *)memchr(head, '\n', this->size_); if(body == NULL){ return 0; } body ++; int head_len = body - head; if(head[0] < '0' || head[0] > '9'){ return -1; } char head_str[20]; if(head_len + 1 > (int)sizeof(head_str)){ return -1; } memcpy(head_str, head, head_len - 1); // no '\n' head_str[head_len - 1] = '\0'; int body_len = atoi(head_str); if(body_len < 0){ return -1; } char *p = body + body_len; if(this->size_ >= head_len + body_len + 1){ if(p[0] == '\n'){ this->size_ -= head_len + body_len + 1; *s = Bytes(body, body_len); return 1; }else if(p[0] == '\r'){ if(this->size_ >= head_len + body_len + 2){ if(p[1] == '\n'){ this->size_ -= head_len + body_len + 2; *s = Bytes(body, body_len); return 1; }else{ return -1; } } }else{ return -1; } } return 0; }
int RedisLink::parse_req(Buffer *input){ recv_bytes.clear(); int parsed = 0; int size = input->size(); char *ptr = input->data(); //dump(ptr, size); if(ptr[0] != '*'){ return -1; } int num_args = 0; while(size > 0){ char *lf = (char *)memchr(ptr, '\n', size); if(lf == NULL){ break; } lf += 1; size -= (lf - ptr); parsed += (lf - ptr); int len = (int)strtol(ptr + 1, NULL, 10); // ptr + 1: skip '$' or '*' if(errno == EINVAL){ return -1; } ptr = lf; if(len < 0){ return -1; } if(num_args == 0){ if(len <= 0){ return -1; } num_args = len; continue; } if(len > size - 2){ break; } recv_bytes.push_back(Bytes(ptr, len)); ptr += len + 2; size -= len + 2; parsed += len + 2; num_args --; if(num_args == 0){ input->decr(parsed); return 1; } } recv_bytes.clear(); return 0; }
// Returns the total size of main and free memory. inline Try<Memory> memory() { Memory memory; MEMORYSTATUSEX memory_status; memory_status.dwLength = sizeof(MEMORYSTATUSEX); if (!::GlobalMemoryStatusEx(&memory_status)) { return WindowsError("os::memory: Call to `GlobalMemoryStatusEx` failed"); } memory.total = Bytes(memory_status.ullTotalPhys); memory.free = Bytes(memory_status.ullAvailPhys); memory.totalSwap = Bytes(memory_status.ullTotalPageFile); memory.freeSwap = Bytes(memory_status.ullAvailPageFile); return memory; }
u8 ReadSPMCSR(void) { u8 spmcsr; DwSend(Bytes(0x64)); // Set up for single step mode DwIn(30, SPMCSR()); // in r30,SPMCSR DwGetRegs(30, &spmcsr, 1); // spmcsr := r30 //Ws(" SPMCSR $"); Wx(spmcsr,2); Wsl("."); return spmcsr; }
ByteArray::ByteArray (const QuickVec<uint8> &inData) { mValue = val_call1 (gByteArrayCreate->get (), alloc_int (inData.size ())); uint8 *bytes = Bytes (); if (bytes) memcpy (bytes, &inData[0], inData.size ()); }
Error FDRTraceWriter::visit(TypedEventRecord &R) { if (auto E = writeMetadata<8u>(OS, R.size(), R.delta(), R.eventType())) return E; auto D = R.data(); ArrayRef<char> Bytes(D.data(), D.size()); OS.write(Bytes); return Error::success(); }
Error FDRTraceWriter::visit(CustomEventRecord &R) { if (auto E = writeMetadata<5u>(OS, R.size(), R.tsc(), R.cpu())) return E; auto D = R.data(); ArrayRef<char> Bytes(D.data(), D.size()); OS.write(Bytes); return Error::success(); }
// Returns the total available disk size in bytes. inline Try<Bytes> available(const std::string& path = "/") { struct statvfs buf; if (::statvfs(path.c_str(), &buf) < 0) { return ErrnoError(); } return Bytes(buf.f_bavail * buf.f_frsize); }
void DwWriteAddr(int addr, int len, const u8 *buf) { DwSetZ(addr); DwSetBP(3); DwSend(Bytes(0x66, 0xC2, 0x04)); // Set data area write mode int limit = addr + len; while (addr < limit) { if (addr < 28 || (addr > 31 && addr != DWDRaddr())) { DwSetPC(1); DwSend(Bytes(0x20, *buf)); // Write one byte to data area and increment Z } else { if (addr >= 28 && addr <= 31) {R[addr] = *buf;} DwSetZ(addr+1); } addr++; buf++; } }
void DwUnsafeReadAddr(int addr, int len, u8 *buf) { // Do not read addresses 30, 31 or DWDR as these interfere with the read process DwSetZ(addr); DwSetPC(0); DwSetBP(2*len); DwSend(Bytes(0x66, 0xC2, 0x00, 0x20)); // Start data area read DwReceive(buf, len); }
Bytes Bitmap::writePng(const uint8_t *data, uint32_t width, uint32_t height, uint32_t stride, Format format, bool invert) { Bytes state; Bitmap_PngStruct s(&state); if (s.write(data, width, height, stride, format, invert)) { return state; } else { return Bytes(); } }
// TODO(andschwa): Share logic with other overload. inline Try<Bytes> size(const int_fd fd) { Try<struct ::stat> s = internal::stat(fd); if (s.isError()) { return Error(s.error()); } return Bytes(s->st_size); }
//////////////////////////////////////////////// // 写入数据到文件,写入后数据将从流中删除 int XStream::WriteToFile(XFile&file,int nLength) { FlushReadBits(); if(nLength==0||readPos+nLength>=writePos) nLength=Bytes(); nLength=file.Write(m_pData+readPos,nLength); //::fwrite(m_pData+readPos,1,nLength,file); readPos+=nLength; return nLength; }