void TableInfo::get(const RecordType &rec, UINT n, String &v) const {
  if(!isDefined(rec,n)) {
    return;
  }
  USES_CONVERSION;
  switch(getColumn(n).getType()) {
  case DBTYPE_CSTRING    :
  case DBTYPE_CSTRINGN   :
    { char tmp[MAXRECSIZE+1];
      getBytes(rec,n,tmp);
      tmp[m_columns[n].getMaxStringLen()] = 0;
      v = tmp;
    }
    break;
  case DBTYPE_WSTRING    :
  case DBTYPE_WSTRINGN   :
    { wchar_t tmp[MAXRECSIZE+1];
      getBytes(rec,n,tmp);
      tmp[m_columns[n].getMaxStringLen()] = 0;
      v = tmp;
    }
    break;
  default: THROWFIELDNOTSTRING(n);
  }
}
Beispiel #2
0
 virtual unsigned getn(void *dst, unsigned n)
 {
     if (!compressed)
         return getBytes(dst, size*n)/size;
     byte *d = (byte *)dst;
     byte *e = d+(size*n);
     byte *p = (byte *)prev;
     unsigned ret = 0;
     while (d!=e) {
         if (first) {
             if (getBytes(d, size)!=size)
                 break;
             first = false;
         }
         else {
             if (remaining()<maxcompsize) 
                 refill();
             if (remaining()==0)
                 break;
             ptr += DiffExpand(ptr,d,p,size);
         }
         p = d;
         d += size;
         ret++;
     }
     if (ret)    // we got at least 1 so copy to prev
         memcpy(prev,e-size,size);
     return ret;
 }
Beispiel #3
0
void *ffmpegDecode(void *filterParams) {
	struct ffmpegDecode *params = (struct ffmpegDecode *)filterParams;

	/////////////////
	// Decode Loop //
	/////////////////
	AVPacket packet;
	int currentFrame = 1;
	while(av_read_frame(params->formatContext, &packet) >= 0) {
		if(packet.stream_index == params->videoStream) {
			avcodec_decode_video2(
				params->codecContext,
				params->frame,
				&params->frameFinished,
				&packet);

			if(params->frameFinished) {
				currentFrame++;
				if(currentFrame % 500 == 0)
					MkvsynthMessage("Finished Frame %i", currentFrame);
				sws_scale (
					params->resizeContext,
					(uint8_t const * const *)params->frame->data,
					params->frame->linesize,
					0,
					params->codecContext->height,
					params->rgbFrame->data,
					params->rgbFrame->linesize);
			
				params->outputPayload = malloc(getBytes(params->output->metaData));
  			memcpy(params->outputPayload, params->rgbFrame->data[0], getBytes(params->output->metaData));
				putFrame(params->output, params->outputPayload);
			}
		}
		
		av_free_packet(&packet);
	}

	////////////////////////
	// Stream Termination //
	////////////////////////
	putFrame(params->output, NULL);
	
	/////////////////////////
	// Memory Deallocation //
	/////////////////////////
	av_free(params->frame);
	av_free(params->rgbFrame);
	av_free(params->rgbFramePayload);
	avcodec_close(params->codecContext);
	avformat_close_input(&params->formatContext);
	free(params);
	return NULL;
}
Beispiel #4
0
/**
 * Create
 * Create and return a byte array of an HTTP request, built from the variables of this HTTPRequest
 *
 * @return Byte array of this HTTPRequest to be sent over the wire
 */
uint8_t* HTTPRequest::create() {
    // Clear the bytebuffer in the event this isn't the first call of create()
	clear();
    
    // Insert the initial line: <method> <path> <version>\r\n
    std::string mstr = "";
    mstr = methodIntToStr(method);
    if(mstr.empty()) {
        printf("Could not create HTTPRequest, unknown method id: %i\n", method);
        return NULL;
    }
    putLine(mstr + " " + requestUri + " " + version);
    
    // Put all headers
    putHeaders();
    
    // If theres body data, add it now
    if((data != NULL) && dataLen > 0) {
        putBytes(data, dataLen);
    }
    
    // Allocate space for the returned byte array and return it
	uint8_t* createRetData = new uint8_t[size()];
	setReadPos(0);
	getBytes(createRetData, size());
    
    return createRetData;
}
Beispiel #5
0
void *x264Encode(void *filterParams) {
	struct x264EncodeParams *params = (struct x264EncodeParams*)filterParams;

	char fullCommand[1024];
	
	snprintf(fullCommand, sizeof(fullCommand), "x264 - --input-csp rgb --input-depth %i --fps %i/%i --input-res %ix%i %s -o %s",
		getDepth(params->input->metaData),
		params->input->metaData->fpsNumerator,
		params->input->metaData->fpsDenominator,
		params->input->metaData->width,
		params->input->metaData->height,
		params->x264params,
		params->filename);

	FILE *x264Proc = popen(fullCommand, "w");

	MkvsynthFrame *workingFrame = getReadOnlyFrame(params->input);

	while(workingFrame->payload != NULL) {
		fwrite(workingFrame->payload, 1, getBytes(params->input->metaData), x264Proc);
		clearReadOnlyFrame(workingFrame);
		workingFrame = getReadOnlyFrame(params->input);
	}

	pclose(x264Proc);
	free(params);
	return NULL;
}
// convert json to buffer
bool js_FlatUtil_js2flat(JSContext *cx, uint32_t argc, jsval *vp)
{
    JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
    bool ok = true;
    
    if (4 == argc) {
        std::string arg0;
        ok &= jsval_to_std_string(cx, args.get(0), &arg0);
        JSB_PRECONDITION2(ok, cx, false, "js_FlatUtil_js2flat : Error processing arguments");
        
        std::string arg1;
        ok &= jsval_to_std_string(cx, args.get(1), &arg1);
        JSB_PRECONDITION2(ok, cx, false, "js_FlatUtil_js2flat : Error processing arguments");
        
        std::string arg2;
        ok &= jsval_to_std_string(cx, args.get(2), &arg2);
        JSB_PRECONDITION2(ok, cx, false, "js_FlatUtil_js2flat : Error processing arguments");
        
        bool arg3;
        arg3 = JS::ToBoolean(args.get(3));
        
        auto data = FlatUtil::js2flat(arg0, arg1, arg2, arg3);
        
        JSObject* buffer = JS_NewArrayBuffer(cx, static_cast<uint32_t>(data.getSize()));
        uint8_t* bufdata = JS_GetArrayBufferData(buffer);
        memcpy((void*)bufdata, (void*)data.getBytes(), data.getSize());
        jsval jsret = JSVAL_NULL;
        jsret = OBJECT_TO_JSVAL(buffer);
        args.rval().set(jsret);
        return true;
    }
    
    JS_ReportError(cx, "js_FlatUtil_js2flat : wrong number of arguments");
    return false;
}
Beispiel #7
0
/**
 * Create an MMS message structure, containing unformatted message data.
 *
 * @param length The total number of bytes in the buffer.
 * @param buffer The buffer that contains the entire MMS message, which is
 *     composed of both the unformatted message header and message body.
 *
 * @return An <code>MmsMessage</code> structure, containing the unformatted
 *     MMS message data.
 */
MmsMessage* createMmsMessageFromBuffer(char* buffer) {

    MmsMessage* mms = NULL;

    if (buffer != NULL) {

        char* p;
        int index = 0;
        int length;

        mms = (MmsMessage *)pcsl_mem_malloc(sizeof(MmsMessage));
        memset(mms, 0, sizeof(MmsMessage));
        p = buffer;

        /* Get the sender's address. */
        mms->fromAddress = getString(p, &index);

        /* Get the application ID string. */
        mms->appID = getString(p, &index);

        /* Get the reply-to application ID string. */
        mms->replyToAppID = getString(p, &index);

        /* Get the message length and data. */
        length = getInt(p, &index);
        mms->msgLen = length;
        mms->msgBuffer = getBytes(p, &index, length);
    }

    return mms;
}
Beispiel #8
0
    void MapAnimation::init() {
        cocos2d::SpriteFrameCache::getInstance()->addSpriteFramesWithFile("main.plist", "main.png");

        auto fileData = cocos2d::FileUtils::getInstance()->getDataFromFile("animation.json");

        Json::Reader reader;
        m_root = new Json::Value;
        const char *beginDoc = (const char*)(fileData.getBytes());
        const char *endDoc = (const char*)(fileData.getBytes() + fileData.getSize());

        if (!reader.parse(beginDoc, endDoc, *m_root)) {
            cocos2d::MessageBox(reader.getFormatedErrorMessages().c_str(), "Json Parse Error!");
        }

        fileData.clear();
    }
void NetworkUpdater::refreshUI()
{
    // Update current speed
    auto interface = settings->getCurrentInterface().getName();
    auto unit = settings->getCurrentUnit();
    auto realBytes = (qreal)unit.getBytes();

    auto unitPost = " " + unit.getDisplayName() + "/s";

    auto diffDownload = currentData.value(interface).value(NetworkTransferType::Download);
    auto diffUpload = currentData.value(interface).value(NetworkTransferType::Upload);

    auto finalDownload = QString::number(((qreal)diffDownload) / realBytes, 'f', 2);
    auto finalUpload = QString::number(((qreal)diffUpload) / realBytes, 'f', 2);

    auto downloadElement = parent()->findChild<QObject*>("currentDownloadValue");
    downloadElement->setProperty("text", QVariant(finalDownload).toString() + unitPost);

    auto uploadElement = parent()->findChild<QObject*>("currentUploadValue");
    uploadElement->setProperty("text", QVariant(finalUpload).toString() + unitPost);

    // Update graphs
    for (auto& graph : parent()->findChildren<NetworkGraph*>())
    {
        graph->update();

        auto finalMax = QString::number(((qreal)graph->graphMax) / realBytes, 'f', 2);

        graph->parent()->findChild<QObject*>("maxLabel")->setProperty("text", "Max " + QVariant(finalMax).toString() + unitPost);
    }
}
Beispiel #10
0
uint8_t gps_get_time(uint8_t* hour, uint8_t* minute, uint8_t* second)
{
    // Send a NAV-TIMEUTC message to the receiver
    uint8_t request[8] = {0xB5, 0x62, 0x01, 0x21, 0x00, 0x00,
        0x22, 0x67};
        
    sendUBX(request, 8);
    
    while(Serial.available())
      Serial.read();
    Serial.flush();
    uint8_t buf[28];
    if (!getBytes(28,buf))
      return 1;


    // Verify the sync and header bits
    if( buf[0] != 0xB5 || buf[1] != 0x62 )
        return 2;
    if( buf[2] != 0x01 || buf[3] != 0x21 )
        return 3;

    *hour = buf[22];
    *minute = buf[23];
    *second = buf[24];

    return 0;
}
Beispiel #11
0
UBool
CollationKey::operator==(const CollationKey& source) const
{
    return getLength() == source.getLength() &&
            (this == &source ||
             uprv_memcmp(getBytes(), source.getBytes(), getLength()) == 0);
}
Beispiel #12
0
void CMC_ModelData::loadFromTZW(const char *fileName)
{

    // load All materials
    auto data = tzw::Tfile::getInstance()->getData (fileName,true);
    rapidjson::Document d;
    d.Parse((const char *)data.getBytes ());

    auto& materialsObj= d["materials"];
    for(auto iter = materialsObj.Begin ();iter!=materialsObj.End ();iter++)
    {
        auto& materialObj = *iter;
        auto material = new CMC_Material();
        material->loadFromTZW (materialObj);
        addMaterial (material);
    }

    //load all meshes.
    auto& meshesObj = d["meshes"];
    for(auto iter = meshesObj.Begin ();iter!= meshesObj.End ();iter++)
    {
        auto& meshObj = *iter;
        auto mesh = new CMC_MeshData();
        mesh->loadFromTZW (meshObj);
        addMesh (mesh);
    }
}
bool ImageAlphaLut::initWithFile(const std::string file)
{
//    // 打开文件
//    auto fp = fopen(FileUtils::getInstance()->fullPathForFilename(file).c_str(), "rb");
//    // 获取文件大小
//    fseek(fp, 0, SEEK_END);
//    long fs = ftell(fp);
//    rewind(fp);

    auto data = FileUtils::getInstance()->getDataFromFile(file);

    auto buff = data.getBytes();
    data.fastSet(nullptr, 0);

    // 分配文件头信息 BUFF
//    unsigned char * buff = (unsigned char *)malloc(fs);
    // 读取文件头信息
//    size_t rs = fread(buff, sizeof(unsigned char), fs, fp);

//    CCASSERT(rs == fs, "Read file info error");

//    fclose(fp);
    int * p = (int *)buff;

    bool b = initWithBuff(++p);

    CC_SAFE_FREE(buff);

    return b;
}
unsigned MPEG1or2AudioStreamParser::parse(unsigned& numTruncatedBytes) {
  try {
    saveParserState();

    // We expect a MPEG audio header (first 11 bits set to 1) at the start:
    while (((fCurrentFrame.hdr = test4Bytes())&0xFFE00000) != 0xFFE00000) {
      skipBytes(1);
      saveParserState();
    }

    fCurrentFrame.setParamsFromHeader();

    // Copy the frame to the requested destination:
    unsigned frameSize = fCurrentFrame.frameSize + 4; // include header
    if (frameSize > fMaxSize) {
      numTruncatedBytes = frameSize - fMaxSize;
      frameSize = fMaxSize;
    } else {
      numTruncatedBytes = 0;
    }

    getBytes(fTo, frameSize);
    skipBytes(numTruncatedBytes);

    return frameSize;
  } catch (int /*e*/) {
#ifdef DEBUG
    fprintf(stderr, "MPEG1or2AudioStreamParser::parse() EXCEPTION (This is normal behavior - *not* an error)\n");
#endif
    return 0;  // the parsing got interrupted
  }
}
Beispiel #15
0
uint8_t gps_check_lock(uint8_t* lock, uint8_t* sats)
{
    // Construct the request to the GPS
    uint8_t request[8] = {0xB5, 0x62, 0x01, 0x06, 0x00, 0x00,
        0x07, 0x16};
         
    sendUBX(request, 8);
    
    while(Serial.available())
      Serial.read();
    Serial.flush();
    uint8_t buf[60];
    if (!getBytes(60,buf))
      return 1;

    // Verify the sync and header bits
    if( buf[0] != 0xB5 || buf[1] != 0x62 )
        return 2;
    if( buf[2] != 0x01 || buf[3] != 0x06 )
        return 3;

  
    // Return the value if GPSfixOK is set in 'flags'
    if( buf[17] & 0x01 )
        *lock = buf[16];
    else
        *lock = 0;

    *sats = buf[53];
    
    return 0;
}
inline void ByteStreamInFileBE::get32bitsLE(U8* bytes)
{
  getBytes(swapped, 4);
  bytes[0] = swapped[3];
  bytes[1] = swapped[2];
  bytes[2] = swapped[1];
  bytes[3] = swapped[0];
}
Beispiel #17
0
unsigned char* Data::takeBuffer(ssize_t* size)
{
    auto buffer = getBytes();
    if (size)
        *size = getSize();
    fastSet(nullptr, 0);
    return buffer;
}
void MatroskaFileParser::deliverFrameBytes() {
  do {
    MatroskaTrack* track = fOurFile.lookup(fBlockTrackNumber);
    if (track == NULL) break; // shouldn't happen

    MatroskaDemuxedTrack* demuxedTrack = fOurDemux->lookupDemuxedTrack(fBlockTrackNumber);
    if (demuxedTrack == NULL) break; // shouldn't happen

    unsigned const BANK_SIZE = bankSize();
    while (fCurFrameNumBytesToGet > 0) {
      // Hack: We can get no more than BANK_SIZE bytes at a time:
      unsigned numBytesToGet = fCurFrameNumBytesToGet > BANK_SIZE ? BANK_SIZE : fCurFrameNumBytesToGet;
      getBytes(fCurFrameTo, numBytesToGet);
      fCurFrameTo += numBytesToGet;
      fCurFrameNumBytesToGet -= numBytesToGet;
      fCurOffsetWithinFrame += numBytesToGet;
      setParseState();
    }
    while (fCurFrameNumBytesToSkip > 0) {
      // Hack: We can skip no more than BANK_SIZE bytes at a time:
      unsigned numBytesToSkip = fCurFrameNumBytesToSkip > BANK_SIZE ? BANK_SIZE : fCurFrameNumBytesToSkip;
      skipBytes(numBytesToSkip);
      fCurFrameNumBytesToSkip -= numBytesToSkip;
      fCurOffsetWithinFrame += numBytesToSkip;
      setParseState();
    }
#ifdef DEBUG
    fprintf(stderr, "\tdelivered frame #%d: %d bytes", fNextFrameNumberToDeliver, demuxedTrack->frameSize());
    if (track->haveSubframes()) fprintf(stderr, "[offset %d]", fCurOffsetWithinFrame - track->subframeSizeSize - demuxedTrack->frameSize() - demuxedTrack->numTruncatedBytes());
    if (demuxedTrack->numTruncatedBytes() > 0) fprintf(stderr, " (%d bytes truncated)", demuxedTrack->numTruncatedBytes());
    fprintf(stderr, " @%u.%06u (%.06f from start); duration %u us\n", demuxedTrack->presentationTime().tv_sec, demuxedTrack->presentationTime().tv_usec, demuxedTrack->presentationTime().tv_sec+demuxedTrack->presentationTime().tv_usec/1000000.0-fPresentationTimeOffset, demuxedTrack->durationInMicroseconds());
#endif

    if (!track->haveSubframes()
	|| fCurOffsetWithinFrame + track->subframeSizeSize >= fFrameSizesWithinBlock[fNextFrameNumberToDeliver]) {
      // Either we don't have subframes, or there's no more room for another subframe => We're completely done with this frame now:
      ++fNextFrameNumberToDeliver;
      fCurOffsetWithinFrame = 0;
    }
    if (fNextFrameNumberToDeliver == fNumFramesInBlock) {
      // We've delivered all of the frames from this block.  Look for another block next:
      fCurrentParseState = LOOKING_FOR_BLOCK;
    } else {
      fCurrentParseState = DELIVERING_FRAME_WITHIN_BLOCK;
    }

    setParseState();
    FramedSource::afterGetting(demuxedTrack); // completes delivery
    return;
  } while (0);

  // An error occurred.  Try to recover:
#ifdef DEBUG
  fprintf(stderr, "deliverFrameBytes(): Error parsing data; trying to recover...\n");
#endif
  fCurrentParseState = LOOKING_FOR_BLOCK;
}
Beispiel #19
0
ssize_t SipDialogEvent::getLength() const
{
    ssize_t length;
    UtlString tempBody;

    getBytes(&tempBody, &length);

    return length;
}
bool BasePersistenceManager::readHeader(const Common::String &filename) {
	cleanup();

	_saving = false;

	_loadStream = g_system->getSavefileManager()->openForLoading(filename);
	//_buffer = BaseFileManager::getEngineInstance()->readWholeFile(filename, &_bufferSize);
	if (_loadStream) {
		uint32 magic;
		magic = getDWORD();

		if (magic != DCGF_MAGIC) {
			cleanup();
			return STATUS_FAILED;
		}

		magic = getDWORD();

		if (magic == SAVE_MAGIC || magic == SAVE_MAGIC_2) {
			_savedVerMajor = _loadStream->readByte();
			_savedVerMinor = _loadStream->readByte();
			_savedExtMajor = _loadStream->readByte();
			_savedExtMinor = _loadStream->readByte();

			if (magic == SAVE_MAGIC_2) {
				_savedVerBuild = (byte)getDWORD();
				_savedName = getStringObj();

				// load thumbnail
				_thumbnailDataSize = getDWORD();
				if (_thumbnailDataSize > 0) {
					_thumbnailData = new byte[_thumbnailDataSize];
					if (_thumbnailData) {
						getBytes(_thumbnailData, _thumbnailDataSize);
					} else {
						_thumbnailDataSize = 0;
					}
				}
			} else {
				_savedVerBuild = 35;    // last build with ver1 savegames
			}

			uint32 dataOffset = getDWORD();

			_savedDescription = getString();
			_savedTimestamp = getTimeDate();
			_savedPlayTime = _loadStream->readUint32LE();

			_offset = dataOffset;

			return STATUS_OK;
		}
	}

	cleanup();
	return STATUS_FAILED;
}
bool NetworkUpdater::checkQuota()
{
    QSettings qS;
    auto enabled = qS.value("quotaEnabled").toBool();
    if (!enabled)
    {
        return false;
    }

    QDateTime min;
    QDateTime max = QDateTime::currentDateTimeUtc();

    auto type = qS.value("quotaType").toInt();
    if (type == 0)
    {
        min = max.addDays(-1);
    }
    else if (type == 1)
    {
        min = QDateTime(max.date(), QTime(), Qt::UTC);
    }
    else if (type == 2)
    {
        min = QDateTime(QDate(max.date().year(), max.date().month(), 1), QTime(), Qt::UTC);
    }

    auto unit = settings->getUnitForIndex(qS.value("quotaUnit").toInt());
    auto quotaAmount = qS.value("quotaAmount").toULongLong();

    for (auto it = storage->savedData.begin(); it != storage->savedData.end(); ++it)
    {
        auto currentAmount = quint64(0);

        auto value = (*it);
        QMap<QDateTime, NetworkStorage::StoredData>::iterator it2;
        for (it2 = value.begin(); it2 != value.end(); ++it2)
        {
            auto pair = it2;
            if (pair.key() >= min && pair.key() <= max)
            {
                currentAmount += pair.value().dlAmount;
                currentAmount += pair.value().ulAmount;
            }
        }

        currentAmount /= unit.getBytes();

        if (currentAmount >= quotaAmount)
        {
            // Quota exceeded
            return true;
        }
    }

    return false;
}
Beispiel #22
0
byte Elm327::absoluteLoadValue(unsigned int &load){
	byte status;
	byte values[2];
	status=getBytes("01","41","43",values,2);
	if (status != ELM_SUCCESS){
		return status;
	}
	load=((values[0]*256)+values[1])*100/255;
	return ELM_SUCCESS;
}
Beispiel #23
0
byte Elm327::commandEquivalenceRatio(float &ratio){
	byte status;
	byte values[2];
	status=getBytes("01","41","44",values,2);
	if (status != ELM_SUCCESS){
		return status;
	}
	ratio=((values[0]*256)+values[1])/32768;
	return ELM_SUCCESS;
}
Beispiel #24
0
byte Elm327::engineRPM(int &rpm){
	byte status;
	byte values[2];
	status=getBytes("01","41","0C",values,2);
	if (status != ELM_SUCCESS){
		return status;
	}
	rpm=((values[0]*256)+values[1])/4;
	return ELM_SUCCESS;
}
Beispiel #25
0
byte Elm327::ambientAirTemperature(int &temperature){
	byte status;
	byte values[1];
	status=getBytes("01","41","46",values,1);
	if (status != ELM_SUCCESS){
		return status;
	}
	temperature=values[0]-40;
	return ELM_SUCCESS;
}
Beispiel #26
0
byte Elm327::intakeManifoldAbsolutePressure(byte &pressure){
	byte status;
	byte values[1];
	status=getBytes("01","41","0B",values,1);
	if (status != ELM_SUCCESS){
		return status;
	}
	pressure=values[0];
	return ELM_SUCCESS;
}
Beispiel #27
0
byte Elm327::commandedThrottleActuator(byte &position){
	byte status;
	byte values[1];
	status=getBytes("01","41","4C",values,1);
	if (status != ELM_SUCCESS){
		return status;
	}
	position=(100*values[0])/255;
	return ELM_SUCCESS;
}
Beispiel #28
0
byte Elm327::acceleratorPedalPositionF(byte &position){
	byte status;
	byte values[1];
	status=getBytes("01","41","4B",values,1);
	if (status != ELM_SUCCESS){
		return status;
	}
	position=(100*values[0])/255;
	return ELM_SUCCESS;
}
Beispiel #29
0
byte Elm327::absoluteThrottlePositionC(byte &position){
	byte status;
	byte values[1];
	status=getBytes("01","41","48",values,1);
	if (status != ELM_SUCCESS){
		return status;
	}
	position=(100*values[0])/255;
	return ELM_SUCCESS;
}
Beispiel #30
0
byte Elm327::getFuelTrim(const char *pid, int &percent){
	byte status;
	byte values[1];
	status=getBytes("01","41",pid,values,1);
	if (status != ELM_SUCCESS){
		return status;
	}
	percent=(values[0] - 128) * 100/128;
	return ELM_SUCCESS;
}