当前位置: 首页>>代码示例>>C++>>正文


C++ decode函数代码示例

本文整理汇总了C++中decode函数的典型用法代码示例。如果您正苦于以下问题:C++ decode函数的具体用法?C++ decode怎么用?C++ decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: decode

	inline static std::string decode(const std::string& s)
	{
		return decode(s.c_str(), s.size());
	}
开发者ID:mbits-os,项目名称:libbase,代码行数:4,代码来源:utils.hpp

示例2: decode

static int decode(FILE *in, FILE *out) {
    struct hexfile_decoder *hfd = NULL;
    struct decoder decoder = {
        .base = 0,
        .file = out,
        .eof = 0,
        .position = 0,
    };
    char buffer[4096];
    int ret;
    size_t nbytes;

    ret = hexfile_decoder_new(hfd_callback, &decoder, &hfd);
    if (ret < 0) {
        fprintf(stderr, "failed to create hexfile decoder\n");
        _exit(2);
    }

    while ((nbytes = fread(buffer, 1, sizeof(buffer), in)) > 0) {
        ret = hexfile_decoder_feed(hfd, buffer, nbytes);
        if (ret < 0) {
            fprintf(stderr, "failed to decode hexfile\n");
            _exit(2);
        }
    }

    ret = hexfile_decoder_close(&hfd);
    if (ret < 0) {
        fprintf(stderr, "failed to close hexfile decoder\n");
        _exit(2);
    }

    if (!decoder.eof) {
        fprintf(stderr, "no EOF record\n");
        _exit(1);
    }

    return 0;
}

struct mapper {
    unsigned base, start, end;
    FILE *file;
    int eof;
};

static void map_print(const struct mapper *mapper) {
    if (mapper->end > mapper->start)
        fprintf(mapper->file, "0x%08x-0x%08x\n", mapper->start, mapper->end);
}

static int map_callback(void *ctx,
                        unsigned char type, unsigned offset,
                        unsigned char *data, size_t length) {
    struct mapper *mapper = (struct mapper*)ctx;

    (void)data;

    if (mapper->eof) {
        errno = EINVAL;
        return -1;
    }

    if (type == 0x00) {
        /* data record */
        unsigned new_position, new_end;

        new_position = (mapper->base + offset) & ~0xf;
        new_end = (new_position + length) | 0xf;

        if (new_position < mapper->start || new_position > mapper->end + 1) {
            map_print(mapper);
            mapper->start = new_position;
            mapper->end = new_end;
        } else if (new_end > mapper->end) {
            mapper->end = new_end;
        }

        return 0;
    } else if (type == 0x01) {
        /* EOF record */
        mapper->eof = 1;
        return 0;
    } else if (type >= 0x10) {
        /* switch memory bank */
        unsigned new_base = (type - 0x10) * BANK_SIZE;

        if (mapper->end != new_base) {
            map_print(mapper);
            mapper->start = mapper->end = new_base;
        }

        mapper->base = new_base;
        return 0;
    } else {
        errno = ENOSYS;
        return -1;
    }
}

//.........这里部分代码省略.........
开发者ID:kaklik,项目名称:loggertools,代码行数:101,代码来源:hexfile-tool.c

示例3: clear

////////////////////////////////////////////////////////////////////////////////
// Attempt an FF4 parse first, using Task::parse, and in the event of an error
// try a legacy parse (F3, FF2).  Note that FF1 is no longer supported.
//
// start --> [ --> Att --> ] --> end
//              ^       |
//              +-------+
//
void Task::parse (const std::string& input)
{
  std::string copy;
  if (input[input.length () - 1] == '\n')
    copy = input.substr (0, input.length () - 1);
  else
    copy = input;

  try
  {
    clear ();

    Nibbler n (copy);
    std::string line;
    if (n.skip     ('[')       &&
        n.getUntil (']', line) &&
        n.skip     (']')       &&
        n.depleted ())
    {
      if (line.length () == 0)
        throw std::string (STRING_RECORD_EMPTY);

      Nibbler nl (line);
      std::string name;
      std::string value;
      while (!nl.depleted ())
      {
        if (nl.getUntil (':', name) &&
            nl.skip (':')           &&
            nl.getQuoted ('"', value))
        {
          // Experimental legacy value translation of 'recur:m' --> 'recur:mo'.
          if (name == "recur" &&
              digitsOnly (value.substr (0, value.length () - 1)) &&
              value[value.length () - 1] == 'm')
            value += 'o';

          if (name.substr (0, 11) == "annotation_")
            ++annotation_count;

          (*this)[name] = decode (json::decode (value));
        }

        nl.skip (' ');
      }

      std::string remainder;
      nl.getUntilEOS (remainder);
      if (remainder.length ())
        throw std::string (STRING_RECORD_JUNK_AT_EOL);
    }
    else
      throw std::string (STRING_RECORD_NOT_FF4);
  }

  catch (const std::string&)
  {
    legacyParse (copy);
  }

  recalc_urgency = true;
}
开发者ID:nigeil,项目名称:task,代码行数:70,代码来源:Task.cpp

示例4: ctx

        default_parse_context ctx(&retval);

        _parse(
            ctx,
            std::istreambuf_iterator<char>(is_.rdbuf()),
            std::istreambuf_iterator<char>(),
            &error_
        );

        return std::move(retval);
    }

    inline std::istream& operator>>(std::istream& is_, value& x_)
    {
        set_last_error(std::string());
        std::string err;

        x_ = decode(is_, err);

        if (!err.empty())
        {
            set_last_error(err);
            is_.setstate(std::ios::failbit);
        }

        return is_;
    }

} // end of json namespace
} // end of reactive namespace
开发者ID:Bulliby,项目名称:Reactive,代码行数:30,代码来源:decode.hpp

示例5: sizeof

void ofxRemoteUIServer::updateServer(float dt){

	timeCounter += dt;
	broadcastTime += dt;
	timeSinceLastReply  += dt;

	if(readyToSend){
		if (timeCounter > updateInterval){
			timeCounter = 0.0f;
			//vector<string> changes = scanForUpdatedParamsAndSync(); //sends changed params to client
			//cout << "ofxRemoteUIServer: sent " << ofToString(changes.size()) << " updates to client" << endl;
			//sendUpdateForParamsInList(changes);
		}
	}

	//let everyone know I exist and which is my port, every now and then
	if(broadcastTime > OFXREMOTEUI_BORADCAST_INTERVAL){
		if(doBroadcast){
			broadcastTime = 0.0f;
			if (computerName.size() == 0){
				#ifdef OF_AVAILABLE
					Poco::Environment e;
					computerName = e.nodeName();

					char pathbuf[2048];
					uint32_t  bufsize = sizeof(pathbuf);
					#ifdef TARGET_OSX
						_NSGetExecutablePath(pathbuf, &bufsize);
						Poco::Path p = Poco::Path(pathbuf);
						binaryName = p[p.depth()];
					#endif
					#ifdef TARGET_WIN32						
						GetModuleFileNameA( NULL, pathbuf, bufsize ); //no iea why, but GetModuleFileName() is not defined?
						Poco::Path p = Poco::Path(pathbuf);
						binaryName = p[p.depth()];
					#endif
				#endif
			}
			ofxOscMessage m;
			m.addIntArg(port); //0
			m.addStringArg(computerName); //1
			m.addStringArg(binaryName);	//2
			broadcastSender.sendMessage(m);
		}
	}

	while( oscReceiver.hasWaitingMessages() ){// check for waiting messages from client

		ofxOscMessage m;
		oscReceiver.getNextMessage(&m);
		if (!readyToSend){ // if not connected, connect to our friend so we can talk back
			connect(m.getRemoteIp(), port + 1);
		}

		DecodedMessage dm = decode(m);
		RemoteUIServerCallBackArg cbArg; // to notify our "delegate"
		cbArg.host = m.getRemoteIp();
		switch (dm.action) {

			case HELO_ACTION: //if client says hi, say hi back
				sendHELLO();
				if(callBack != NULL){
					cbArg.action = CLIENT_CONNECTED;
					callBack(cbArg);
				}
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says HELLO!"  << endl;
				onScreenNotifications.addNotification("CONNECTED (" + cbArg.host +  ")!");
				break;

			case REQUEST_ACTION:{ //send all params to client
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " sends REQU!"  << endl;
				vector<string>paramsList = getAllParamNamesList();
				syncAllParamsToPointers();
				sendUpdateForParamsInList(paramsList);
				sendREQU(true); //once all send, confirm to close the REQU
			}
				break;

			case SEND_PARAM_ACTION:{ //client is sending us an updated val
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " sends SEND!"  << endl;
				updateParamFromDecodedMessage(m, dm);
				if(callBack != NULL){
					cbArg.action = CLIENT_UPDATED_PARAM;
					cbArg.paramName = dm.paramName;
					cbArg.param = params[dm.paramName];  //copy the updated param to the callbakc arg
					callBack(cbArg);
				}
			}
				break;

			case CIAO_ACTION:{
				if(verbose_) cout << "ofxRemoteUIServer: " << m.getRemoteIp() << " says CIAO!" << endl;
				sendCIAO();
				onScreenNotifications.addNotification("DISCONNECTED (" + cbArg.host +  ")!");
				if(callBack != NULL){
					cbArg.action = CLIENT_DISCONNECTED;
					callBack(cbArg);
				}
				clearOscReceiverMsgQueue();
				readyToSend = false;
//.........这里部分代码省略.........
开发者ID:chemabc,项目名称:ofxRemoteUI,代码行数:101,代码来源:ofxRemoteUIServer.cpp

示例6: checksum

 unsigned short checksum() const { return decode(2, 3); }
开发者ID:fcrick,项目名称:RepSnapper,代码行数:1,代码来源:icmp_header.hpp

示例7: sequence_number

 unsigned short sequence_number() const { return decode(6, 7); }
开发者ID:fcrick,项目名称:RepSnapper,代码行数:1,代码来源:icmp_header.hpp

示例8: fetch_decode

static inline decode_t fetch_decode(cpu_t *pcpu) {
    return decode(fetch_checked(pcpu), pcpu);
}
开发者ID:NextGenIntelligence,项目名称:interpreters-comparison,代码行数:3,代码来源:subroutined.c

示例9: decode

type_id value::type() const { return decode().type(); }
开发者ID:Barba-studio,项目名称:qpid-proton,代码行数:1,代码来源:value.cpp

示例10: main

int main(int argc, char *argv[]) {
  int i, j;
  char err[256];
  size_t err_len = sizeof(err);
  int chunkSize = 1024;
  int numDataUnits = 6;
  int numParityUnits = 3;
  unsigned char** dataUnits;
  unsigned char** parityUnits;
  IsalEncoder* pEncoder;
  int erasedIndexes[2];
  unsigned char* allUnits[MMAX];
  IsalDecoder* pDecoder;
  unsigned char* decodingOutput[2];
  unsigned char** backupUnits;

  if (0 == build_support_erasurecode()) {
    printf("The native library isn't available, skipping this test\n");
    return 0; // Normal, not an error
  }

  load_erasurecode_lib(err, err_len);
  if (strlen(err) > 0) {
    printf("Loading erasurecode library failed: %s\n", err);
    return -1;
  }

  printf("Performing erasure code test\n");

  dataUnits = calloc(numDataUnits, sizeof(unsigned char*));
  parityUnits = calloc(numParityUnits, sizeof(unsigned char*));
  backupUnits = calloc(numParityUnits, sizeof(unsigned char*));

  // Allocate and generate data units
  srand(135);
  for (i = 0; i < numDataUnits; i++) {
    dataUnits[i] = calloc(chunkSize, sizeof(unsigned char));
    for (j = 0; j < chunkSize; j++) {
      dataUnits[i][j] = rand();
    }
  }

  // Allocate and initialize parity units
  for (i = 0; i < numParityUnits; i++) {
    parityUnits[i] = calloc(chunkSize, sizeof(unsigned char));
    for (j = 0; j < chunkSize; j++) {
      parityUnits[i][j] = 0;
    }
  }

  pEncoder = (IsalEncoder*)malloc(sizeof(IsalEncoder));
  memset(pEncoder, 0, sizeof(*pEncoder));
  initEncoder(pEncoder, numDataUnits, numParityUnits);
  encode(pEncoder, dataUnits, parityUnits, chunkSize);

  pDecoder = (IsalDecoder*)malloc(sizeof(IsalDecoder));
  memset(pDecoder, 0, sizeof(*pDecoder));
  initDecoder(pDecoder, numDataUnits, numParityUnits);

  memcpy(allUnits, dataUnits, numDataUnits * (sizeof (unsigned char*)));
  memcpy(allUnits + numDataUnits, parityUnits,
                            numParityUnits * (sizeof (unsigned char*)));

  erasedIndexes[0] = 1;
  erasedIndexes[1] = 7;

  backupUnits[0] = allUnits[1];
  backupUnits[1] = allUnits[7];

  allUnits[0] = NULL; // Not to read
  allUnits[1] = NULL;
  allUnits[7] = NULL;

  decodingOutput[0] = malloc(chunkSize);
  decodingOutput[1] = malloc(chunkSize);

  decode(pDecoder, allUnits, erasedIndexes, 2, decodingOutput, chunkSize);

  for (i = 0; i < pDecoder->numErased; i++) {
    if (0 != memcmp(decodingOutput[i], backupUnits[i], chunkSize)) {
      fprintf(stderr, "Decoding failed\n\n");
      dumpDecoder(pDecoder);
      return -1;
    }
  }

  dumpDecoder(pDecoder);
  fprintf(stdout, "Successfully done, passed!\n\n");

  return 0;
}
开发者ID:Jerry-Xin,项目名称:hadoop,代码行数:91,代码来源:erasure_code_test.c

示例11: decode

int RsDecode::decode(BYTE * data, int length)
{
	return decode(data, length, false);
}
开发者ID:dragen1860,项目名称:qrdecoder,代码行数:4,代码来源:RsDecode.cpp

示例12: decode

Ref<Result> ByQuadrantReader::decode(Ref<BinaryBitmap> image){
  return decode(image, DecodeHints::DEFAULT_HINT);
}
开发者ID:Karry,项目名称:sailfish-barcode,代码行数:3,代码来源:ByQuadrantReader.cpp

示例13: TestLSB

void TestLSB()
{
	encode();
	decode();
}
开发者ID:EQ4,项目名称:libaudiotool,代码行数:5,代码来源:testlsb.cpp

示例14: cbc_mct

int cbc_mct(char *filename, FILE *file) {
    char line[1024], name[64], value[1024];

    uint8_t KEY[256], IV[AES_BLOCK_LEN];
    uint8_t CT[AES_BLOCK_LEN], PT[AES_BLOCK_LEN];
    uint8_t block[AES_BLOCK_LEN], prev[AES_BLOCK_LEN];

    enum { head, params } section = head;
    enum { encrypt, decrypt } mode;
    uint32_t lineno = 0, start = 0, tests = 0, count = 0;
    bool done = true;

    struct { param key, iv, ct, pt; } expected;
    void (*op)(aes_key *, uint8_t *, uint8_t *, size_t, uint8_t*);
    aes_key aes_key;

    while (fgets(line, sizeof(line), file)) {
        lineno++;
        switch (line[0]) {
            case '#':
                break;
            case '\n':
            case '\r':
                if (!done && section == params) {
                    tests++;
                    if (count == 0) {
                        memcpy(KEY, expected.key.value, expected.key.len);
                        memcpy(IV, expected.iv.value, expected.iv.len);
                        memcpy(PT, expected.pt.value, expected.pt.len);
                        memcpy(CT, expected.ct.value, expected.pt.len);
                    }

                    aesni_set_key(&aes_key, KEY, expected.key.len);
                    memcpy(block, IV, expected.iv.len);

                    uint8_t *SRC, *DST;

                    if (mode == encrypt) {
                        op  = &aesni_cbc_enc;
                        SRC = PT;
                        DST = CT;
                    } else {
                        op  = &aesni_cbc_dec;
                        SRC = CT;
                        DST = PT;
                    }

                    for (int j = 0; j < 1000; j++) {
                        memcpy(prev, DST, AES_BLOCK_LEN);
                        op(&aes_key, DST, SRC, AES_BLOCK_LEN, block);
                        memcpy(SRC, j == 0 ? IV : prev, AES_BLOCK_LEN);
                    }

                    if (count != 0) {
                        if (memcmp(KEY, expected.key.value, expected.key.len)) {
                            fail("FAILURE (KEY) %s @ %d\n", filename, start);
                        }
                        if (memcmp(IV, expected.iv.value, expected.iv.len)) {
                            fail("FAILURE (IV) %s @ %d\n", filename, start);
                        }
                        param *expected_p = (mode == encrypt ? &expected.ct : &expected.pt);
                        if (memcmp(DST, expected_p->value, expected_p->len)) {
                            fail("FAILURE (CIPHERTEXT) %s @ %d\n", filename, start);
                        }
                    }

                    uint8_t *K = KEY;
                    int y = abs(expected.key.len - 32);
                    for (int x = y; x < 16; x++) *K++ ^= prev[x];
                    for (int x = 0; x < 16; x++) *K++ ^=  DST[x];

                    memcpy(IV, DST, AES_BLOCK_LEN);

                    start = lineno + 1;
                    count++;
                    done = true;
                }
                break;
            case '[':
                if (section != head) {
                    section = head;
                    expected.key.len = expected.iv.len = 0;
                    expected.pt.len  = expected.ct.len = 0;
                    count   = 0;
                }
                parse_kv(line, name, value);
                if (!strcmp(name, "ENCRYPT")) mode = encrypt;
                if (!strcmp(name, "DECRYPT")) mode = decrypt;
                break;
            default:
                if (section != params) {
                    section = params;
                    start   = lineno;
                }
                parse_kv(line, name, value);
                if (!strcmp(name, "KEY"))        decode(name, value, &expected.key);
                if (!strcmp(name, "IV"))         decode(name, value, &expected.iv);
                if (!strcmp(name, "PLAINTEXT"))  decode(name, value, &expected.pt);
                if (!strcmp(name, "CIPHERTEXT")) decode(name, value, &expected.ct);
                if (!strcmp(name, "COUNT")) {
//.........这里部分代码省略.........
开发者ID:GrmpCerber,项目名称:crypto,代码行数:101,代码来源:cbc_mct.c

示例15: main

int main(int argc, char *argv[])
{
    pid_t pid = getpid();
    int str_end,hash_beg,i = 0, sm, lo, rs, dr, hash_len;
    char dir[200],report[1000],mdString[40]= {0}, *parcel, tmp[100], *from_str, *from_str_tmp, *hash_et, *help_ptr, *arglist_sm[100], *arglist_lo[100], *arglist_rs[100], *arglist_dr[100];
    unsigned char *hash_cand = malloc(50*sizeof(char));
    t_elements parsed_elements;
    sprintf(dir,"%s%d_log.log",LOG_DIR,pid);
    FILE *log = fopen(dir,"w");
    if(log == NULL) exit(-4);
    from_str_tmp = malloc(sizeof(char)*100000);
    sprintf(tmp, "/tmp/%d/", pid);
    mkdir(tmp, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    chdir(tmp);
    fprintf(log, "PID: %d, dir changed\nthats what we got:\n", pid);
    do
    {
        from_str_tmp[i] = getc(stdin);
        fputc(from_str_tmp[i],log);
        if(from_str_tmp[i] == '-' && from_str_tmp[i-1] == '-')
        {
            str_end=i-1;
            hash_beg=i+1;
            from_str_tmp[str_end]=0;
        }
    }
    while(from_str_tmp[i++] != EOF);
    hash_et = from_str_tmp + sizeof(char)*hash_beg;
    hash_et[40]=0;
    from_str_tmp += 8*sizeof(char);
    from_str = curl_decode(from_str_tmp);
    help_ptr = from_str;
    from_str_tmp = decode(from_str); /*base64 conversion*/
    fprintf(log,"\nAfter url_decode:%s",from_str);
    //\r\n
    from_str=from_str_tmp;
    fprintf(log,"\nhashed string:%s\n",help_ptr);
    HMAC(EVP_sha1(),SALT, strlen(SALT), (unsigned char*)help_ptr, strlen(help_ptr),hash_cand,(unsigned int*)&hash_len);
    for(i = 0; i < 20; i++)
        sprintf(&mdString[i*2], "%02x",hash_cand[i]);
    //FIXME leaks everywhere
    if(strcmp(mdString,hash_et)==0)
    {
        fprintf(log,"\nhash correct\n");
        fprintf(log,"decoded string: %s\n", from_str);
        printf("Content-Type: text/plain;charset=us-ascii\n\n");
    }
    else
    {
        fprintf(log, "%s\n%s\n hash incorrect\n",mdString,hash_et);
        printf("Content-Type: text/html\nStatus: 422 Bad Request\n\n");
        free(hash_cand);
        free(from_str);
        fclose(log);
        exit(-1);
    }
    /*we have now string to parse*/
    cJSON *root = cJSON_Parse(from_str);
    if (!root)
    {
        fprintf(log,"Error before: [%s]\n", cJSON_GetErrorPtr());
    }
    fprintf(log,"exec part\n");
    parse_into_elements(&parsed_elements, root, log);
    fflush(NULL);
    lo = make_arglist_for_login(arglist_lo, parsed_elements);
    fork_exec_with_inp_redir(arglist_lo, 1, "whatever");
    sm = make_arglist_for_submit_and_run(arglist_sm, parsed_elements, arglist_lo[4]);
    fork_exec_with_inp_redir(arglist_sm, 1, "num.txt");
    rs = make_arglist_for_run_status(arglist_rs, parsed_elements, arglist_lo[4]);
    int rep_num;
    if((rep_num=wait_for_report(5, arglist_rs, parsed_elements.status))==-1)
    {
        strcpy(parsed_elements.status,"error");
        strcpy(report,"ejudge marking error");
    }
    else
    {
        int flag=0,some;
        some = submit_checked(parsed_elements.status, ejudge_common);
        if(strcmp(parsed_elements.status,"OK")==0)
        {
            strcpy(parsed_elements.status,"ok");
            flag=1;
        }
        else if(submit_checked(parsed_elements.status, ejudge_error)!=-1)
        {
            strcpy(parsed_elements.status,"error");
            strcpy(report,ejudge_detailed[some]);
            if(some == 1) flag = 2; /*let report be when compilation error*/
        }
        else
        {
            strcpy(parsed_elements.status, "fail");
            flag=1;
        }
        if(flag)
        {
            dr = make_arglist_for_dump_report(arglist_dr, parsed_elements, arglist_lo[4]); //BACKTRACE part
            fork_exec_with_inp_redir(arglist_dr, 1, "return_report.xml");
//.........这里部分代码省略.........
开发者ID:leonshting,项目名称:ejudge_connector,代码行数:101,代码来源:first.c


注:本文中的decode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。