示例#1
0
文件: LZ78.cpp 项目: mhss/pcc
void LZ78::decoding(File &file, Alphabet &alpha, Stream &stream, int textSize) {
	lista.clear();
	lista.reserve(101 + textSize / 5);
	
	char c;
	while(! file.terminated) {
		int pos = deserialize_int(file);
		int idx = deserialize_int(file);
		
		// Se há algo a ser adicionado (ou seja, se não é a raiz)
		if(pos)
			push_recursive(stream, pos - 1);
		
		c = alpha.getChar(idx);
		
		// Terminal
		if(c == '\0') break;
		
		// Atualiza a lista
		lista.push_back(make_pair(pos, c));
		
		// Escreve o caractere
		stream.write(c);
	}
}
示例#2
0
request_data deserialize_request(unsigned char* c) {
	request_data req; 
	req.time = static_cast<unsigned int> (deserialize_int(c)); 
	req.method = (HttpMethod)c[4]; 
	req.receiver_ip.s_addr = deserialize_int(c+5); 
	for (int i = 0; i < 4; ++i) req.response[i] = c[9+i];
	return req; 
}
示例#3
0
struct pool_val *deserialize_string(char **f, struct pool *p, int type) {
	struct pool_val *ret;
	int len;

	deserialize_int(f, &len);
	ret = pool(p, *f, type);
	*f += len;

	return ret;
}
void Test_serialize_int(CuTest * tc){

    printf("Int serialization tests and experiments \n");
    printf("maximum int = %d\n",INT_MAX);
    printf("size of int in bytes= %zu\n",sizeof(int));
    int a = 18505;
    int value;
    unsigned char buffer[sizeof(int)];

    serialize_int(buffer,a);
    printf(" serialized is %s\n",buffer);
    deserialize_int(buffer,&value);
    printf(" deserialized is %d\n",value);
    CuAssertIntEquals(tc,value,a);
    a = INT_MAX;
    serialize_int(buffer,a);
    deserialize_int(buffer,&value);
    CuAssertIntEquals(tc,value,a);
    a = INT_MIN;
    serialize_int(buffer,a);
    deserialize_int(buffer,&value);
    CuAssertIntEquals(tc,value,a);
}
示例#5
0
文件: ldbsim.c 项目: mdcallag/mytools
void page_check_checksum(char* page) {
    if (!checksum_verify)
      return;
    else {
      int computed_cs = adler32(0, (unsigned char*) page + PAGE_DATA_OFFSET, PAGE_DATA_BYTES);
      int stored_cs = (int) deserialize_int(page + PAGE_CHECKSUM_OFFSET);
      /* int stored_page_num = (int) deserialize_int(page + PAGE_NUM_OFFSET); */

      if (checksum_assert && computed_cs != stored_cs) {
        fprintf(stderr,
                "Cannot validate page, checksum stored(%d) and computed(%d)\n",
                stored_cs, computed_cs);
        exit(-1);
      }
    }
}
    int ObSqlGetParam::deserialize_rowkeys(const char* buf, const int64_t data_len,
      int64_t& pos)
    {
      int ret         = OB_SUCCESS;
      int64_t size    = 0;
      int64_t i       = 0;
      ObRowkey rowkey;
      ObObj tmp_objs[OB_MAX_ROWKEY_COLUMN_NUMBER];

      if (NULL == buf || data_len <= 0 || pos > data_len)
      {
        TBSYS_LOG(WARN, "invalid param, buf=%p, data_len=%ld, pos=%ld",
                  buf, data_len, pos);
        ret = OB_INVALID_ARGUMENT;
      }
      else
      {
        if (OB_SUCCESS != (ret = deserialize_int(buf, data_len, pos, size)))
        {
          TBSYS_LOG(WARN, "fail to deserialize_int(rowkey size). buf=%p, data_len=%ld, pos=%ld, ret=%d",
              buf, data_len, pos, ret);
        }
        else
        {
          rowkey.assign(tmp_objs, OB_MAX_ROWKEY_COLUMN_NUMBER);
          for (i = 0; i < size; i++)
          {
            //deserialize rowkey
            if (OB_SUCCESS != (ret = rowkey.deserialize(buf, data_len, pos)))
            {
              TBSYS_LOG(WARN, "fail to deserialize rowkey. buf=%p, data_len=%ld, pos=%ld, i=%ld, size=%ld",
                  buf, data_len, pos, i, size);
            }
            else if (OB_SUCCESS != (ret = add_rowkey(rowkey, true)))
            {
              TBSYS_LOG(WARN, "fail to add deserialized rowkey to get param. ret=%d, i=%ld, size=%ld", ret, i, size);
            }
          }
        }
      }
      return ret;
    }
示例#7
0
int traverse_zooms(int geomfd[4], off_t geom_size[4], char *metabase, unsigned *file_bbox, struct pool **file_keys, unsigned *midx, unsigned *midy, char **layernames, int maxzoom, int minzoom, sqlite3 *outdb, double droprate, int buffer, const char *fname, const char *tmpdir, double gamma, int nlayers, char *prevent) {
	int i;
	for (i = 0; i <= maxzoom; i++) {
		long long most = 0;

		FILE *sub[4];
		int subfd[4];
		int j;
		for (j = 0; j < 4; j++) {
			char geomname[strlen(tmpdir) + strlen("/geom2.XXXXXXXX") + 1];
			sprintf(geomname, "%s/geom%d.XXXXXXXX", tmpdir, j);
			subfd[j] = mkstemp(geomname);
			//printf("%s\n", geomname);
			if (subfd[j] < 0) {
				perror(geomname);
				exit(EXIT_FAILURE);
			}
			sub[j] = fopen(geomname, "wb");
			if (sub[j] == NULL) {
				perror(geomname);
				exit(EXIT_FAILURE);
			}
			unlink(geomname);
		}

		long long todo = 0;
		long long along = 0;
		for (j = 0; j < 4; j++) {
			todo += geom_size[j];
		}

		for (j = 0; j < 4; j++) {
			if (geomfd[j] < 0) {
				// only one source file for zoom level 0
				continue;
			}
			if (geom_size[j] == 0) {
				continue;
			}

			// printf("%lld of geom_size\n", (long long) geom_size[j]);

			char *geom = mmap(NULL, geom_size[j], PROT_READ, MAP_PRIVATE, geomfd[j], 0);
			if (geom == MAP_FAILED) {
				perror("mmap geom");
				exit(EXIT_FAILURE);
			}

			char *geomstart = geom;
			char *end = geom + geom_size[j];

			while (geom < end) {
				int z;
				unsigned x, y;

				deserialize_int(&geom, &z);
				deserialize_uint(&geom, &x);
				deserialize_uint(&geom, &y);

				// fprintf(stderr, "%d/%u/%u\n", z, x, y);

				long long len = write_tile(&geom, metabase, file_bbox, z, x, y, z == maxzoom ? full_detail : low_detail, maxzoom, file_keys, layernames, outdb, droprate, buffer, fname, sub, minzoom, maxzoom, todo, geomstart, along, gamma, nlayers, prevent);

				if (len < 0) {
					return i - 1;
				}

				if (z == maxzoom && len > most) {
					*midx = x;
					*midy = y;
					most = len;
				}
			}

			if (munmap(geomstart, geom_size[j]) != 0) {
				perror("munmap geom");
			}
			along += geom_size[j];
		}

		for (j = 0; j < 4; j++) {
			close(geomfd[j]);
			fclose(sub[j]);

			struct stat geomst;
			if (fstat(subfd[j], &geomst) != 0) {
				perror("stat geom\n");
				exit(EXIT_FAILURE);
			}

			geomfd[j] = subfd[j];
			geom_size[j] = geomst.st_size;
		}
	}

	fprintf(stderr, "\n");
	return maxzoom;
}
示例#8
0
command deserialize_command(unsigned char* c) {
	command comm;
	comm.type = (CommandType)c[0]; 
	comm.time = static_cast<time_t> (deserialize_int(c+1)); 
	return comm; 
}