// decompression // to reconstruct a string from an index we need to traverse the dictionary strings backwards, following each // successive prefix index until this prefix index is the empty index void decompress(FILE * inputFile, FILE * outputFile) { // int prevcode, currcode int previousCode; int currentCode; int nextCode = 256; // start with the same dictionary of 256 characters int firstChar; // prevcode = read in a code previousCode = readBinary(inputFile); if (previousCode == 0) { return; } fputc(previousCode, outputFile); // while (there is still data to read) while ((currentCode = readBinary(inputFile)) > 0) { // currcode = read in a code if (currentCode >= nextCode) { fputc(firstChar = decode(previousCode, outputFile), outputFile); // S+C+S+C+S exception [2.] //printf("%c", firstChar); //appendCharacter(firstChar = decode(previousCode, outputFile)); } else firstChar = decode(currentCode, outputFile); // first character returned! [1.] // add a new code to the string table if (nextCode < dictionarySize) dictionaryArrayAdd(previousCode, firstChar, nextCode++); // prevcode = currcode previousCode = currentCode; } //printf("\n"); }
inline uint64_t readElias2(iterator A, uint64_t & offset) { uint64_t const log_2 = readUnary(A,offset); uint64_t const log_1 = readBinary(A,offset,log_2); uint64_t const n = readBinary(A,offset,log_1); return n; }
void IndexForNativeFormat::read(ReadBuffer & istr, const NameSet & required_columns) { while (!istr.eof()) { blocks.emplace_back(); IndexOfBlockForNativeFormat & block = blocks.back(); readVarUInt(block.num_columns, istr); readVarUInt(block.num_rows, istr); if (block.num_columns < required_columns.size()) throw Exception("Index contain less than required columns", ErrorCodes::INCORRECT_INDEX); for (size_t i = 0; i < block.num_columns; ++i) { IndexOfOneColumnForNativeFormat column_index; readBinary(column_index.name, istr); readBinary(column_index.type, istr); readBinary(column_index.location.offset_in_compressed_file, istr); readBinary(column_index.location.offset_in_decompressed_block, istr); if (required_columns.count(column_index.name)) block.columns.push_back(std::move(column_index)); } if (block.columns.size() < required_columns.size()) throw Exception("Index contain less than required columns", ErrorCodes::INCORRECT_INDEX); if (block.columns.size() > required_columns.size()) throw Exception("Index contain duplicate columns", ErrorCodes::INCORRECT_INDEX); block.num_columns = block.columns.size(); } }
void BlockStreamProfileInfo::read(ReadBuffer & in) { readVarUInt(rows, in); readVarUInt(blocks, in); readVarUInt(bytes, in); readBinary(applied_limit, in); readVarUInt(rows_before_limit, in); readBinary(calculated_rows_before_limit, in); }
inline void SeededSliceExtractor<DataSetWrapperParam>::Parameters::read( Misc::File& file, bool ascii, Visualization::Abstract::VariableManager* variableManager) { if(ascii) { /* Parse the parameter section: */ AsciiParameterFileSectionHash* hash=parseAsciiParameterFileSection<Misc::File>(file); /* Extract the parameters: */ scalarVariableIndex=readScalarVariableNameAscii(hash,"scalarVariable",variableManager); plane=readParameterAscii<Plane>(hash,"plane",plane); seedPoint=readParameterAscii<Point>(hash,"seedPoint",seedPoint); /* Clean up: */ deleteAsciiParameterFileSectionHash(hash); } else { /* Read from binary file: */ readBinary(file,false,variableManager); } /* Get a templatized locator to track the seed point: */ const DataSetWrapper* myDataSet=dynamic_cast<const DataSetWrapper*>(variableManager->getDataSetByScalarVariable(scalarVariableIndex)); if(myDataSet==0) Misc::throwStdErr("SeededSliceExtractor::Parameters::readBinary: Mismatching data set type"); dsl=myDataSet->getDs().getLocator(); locatorValid=dsl.locatePoint(seedPoint); }
void CasmReader::readBinary(charstring Filename, std::shared_ptr<SymbolTable> AlgSymtab, std::shared_ptr<SymbolTable> EnclosingScope) { readBinary( std::make_shared<ReadBackedQueue>(std::make_shared<FileReader>(Filename)), AlgSymtab, EnclosingScope); }
/** * Reads an OcTree from a binary file * @param _filename * */ srs_env_model::EMOcTree::EMOcTree(std::string _filename) : OccupancyOcTreeBase<srs_env_model::EModelTreeNode> (0.1) { // resolution will be set according to tree file itsRoot = new EModelTreeNode(); tree_size++; readBinary(_filename); }
int testReadBinary() { int len; int *r = readBinary(4, 3, &len); showArr(r, len); free(r); return 0; }
PKCS15DODF::PKCS15DODF(ByteArray path, Channel *channel):PKCS15Object(channel) { int ret = 0; if ((ret = select(path)) == 0) { ByteArray dodfData, extra; SCARD_DEBUG("response : %s", selectResponse.toString()); if ((ret = readBinary(0, 0, getFCP()->getFileSize(), dodfData)) == 0) { SCARD_DEBUG("dodfData : %s", dodfData.toString()); parseData(dodfData); } else { SCARD_DEBUG_ERR("readBinary failed, [%d]", ret); } } else { SCARD_DEBUG_ERR("select failed, [%d]", ret); } }
static void ShowBuildTime_File(char *file, char *file4Prn) { autoBlock_t *fileData = readBinary(file); uint index; time_t buildTime; for(index = 0; ; index++) { if( getByte(fileData, index + 0) == 'P' && getByte(fileData, index + 1) == 'E' && getByte(fileData, index + 2) == '\0' && getByte(fileData, index + 3) == '\0' ) break; } index += 8; // ヘッダとか buildTime = getByte(fileData, index + 0) * 0x1 + getByte(fileData, index + 1) * 0x100 + getByte(fileData, index + 2) * 0x10000 + getByte(fileData, index + 3) * 0x1000000; cout("%s %s\n", makeJStamp(getStampDataTime(buildTime), 0), file4Prn); releaseAutoBlock(fileData); }
int main(int argc, char **argv) { if(argc < 2){ printf("No input file given"); exit(0); } K = 5; readBinary(argv[1]); //readFile("uniform_data_16_1000.csv"); initVars(); threshold = 0.001; //printf("Centroids at start:\n"); //printCentroids(); //printf("Starting k-Means\n"); //printDatapoints(); //time_t start = time(NULL); double startTime = get_wall_time(); kMeans(); double endTime = get_wall_time(); printf("%.2f\n", endTime-startTime); printDatapointClusters(); return 0; }
template<typename T> T uniform(T min, T max) { uint32_t i = 0; while(!i) readBinary(i); // no EOF double t = double(i-1)/double(std::numeric_limits<uint32_t>::max()); return min + T((max-min)*t); }
unsigned long chunkArchive::readAny(unsigned char *type, unsigned long *size) { unsigned char id = readByte(); if (type) *type = id; switch ((atoms) (id)) { case CHUNK_BYTE: if (size) *size = 1; return readByte(); break; case CHUNK_SHORT: if (size) *size = 2; return readShort(); break; case CHUNK_LONG: if (size) *size = 4; return readLong(); break; case CHUNK_STRING: return (unsigned long) readString(size); break; case CHUNK_BINARY: return (unsigned long) readBinary(size); break; default: if (size) *size = 0; return 0; } }
static void LoadSaveData(void) { char *file = GetSaveDataFile(); if(existFile(file)) { autoBlock_t *fileData = readBinary(file); char *fileText; autoList_t *lines; autoList_t *sVals; DoMask(fileData); fileText = unbindBlock2Line(fileData); fileText = replaceLine(fileText, "\r\n", "\n", 0); lines = tokenize(fileText, '\n'); sVals = tokenize(getLine(lines, 1), ','); StageNo = toValue(refLine(sVals, 0)); HiScore = toValue(refLine(sVals, 1)); ExtraOpened = getCount(lines) == 3; memFree(fileText); releaseDim(lines, 1); releaseDim(sVals, 1); } memFree(file); }
bool AbstractOccupancyOcTree::readBinary(const std::string& filename){ std::ifstream binary_infile( filename.c_str(), std::ios_base::binary); if (!binary_infile.is_open()){ OCTOMAP_ERROR_STR("Filestream to "<< filename << " not open, nothing read."); return false; } return readBinary(binary_infile); }
void readBinary<std::vector<uint8_t>>(std::vector<uint8_t>& arg, std::istream& in) { size_t len; in.read((char*)&len, sizeof(size_t)); uint8_t tmpVal; for(uint8_t i = 0; i < len; i++) { readBinary(tmpVal, in); arg.push_back(tmpVal); } }
void BinaryFileTreeDataStateBase::loadDataState(const phantom::data& a_Data, uint guid, Node* a_pNode, uint a_uiStateId) { BinaryFileTreeDataBase* pDB = static_cast<BinaryFileTreeDataBase*>(a_pNode->getDataBase()); byte buffer[1000000]; byte* pBuffer = &(buffer[0]); uint uiBufferSize = 0; readBinary(dataPath(a_Data, guid, a_pNode, a_uiStateId), pBuffer, uiBufferSize); a_Data.type()->deserialize(a_Data.address(), (const byte*&)pBuffer, m_uiSerializationFlag, pDB); }
void OcTreePCL::readBinary(const std::string& filename){ std::ifstream binary_infile( filename.c_str(), std::ios_base::binary); if (!binary_infile.is_open()){ std::cerr << "ERROR: Filestream to "<< filename << " not open, nothing read.\n"; return; } else { readBinary(binary_infile); binary_infile.close(); } }
void MonophoneLookup::readBinary( const char *binFName ) { FILE *fd ; if ( (fd = fopen( binFName ,"rb" )) == NULL ) error("MonophoneLookup::readBinary(2) - error opening binFName") ; readBinary( fd ) ; fclose( fd ) ; }
void PersistEngine::read(std::string& str) throw(PersistException) { uint32_t len = 0; read(len); uint8_t *buffer = new uint8_t[len+1]; readBinary(buffer,len); buffer[len] = 0; str = (char*)buffer; delete[] buffer; }
int main(int argc, char *argv[]) { if (argc==4) { printf("Input file 1 will be %s\nInput file 2 will be %s\nOutput file will be %s\n\n", argv[1],argv[2],argv[3]); } else { printf("Wrong number of parameters\n"); return 1; } readBinary(argv[1],argv[2],argv[3]); printf("\n\n\nThis is a read test for output\n\n\n"); testRead(argv[3]); return 0; }
void MifarePlusSL3Commands::readSector(int sector, int start_block, void* buf, size_t buflen, boost::shared_ptr<MifarePlusKey> key, MifarePlusKeyType keytype) { if (buf == NULL || buflen < MIFARE_PLUS_BLOCK_SIZE || buflen % MIFARE_PLUS_BLOCK_SIZE != 0 || buflen / MIFARE_PLUS_BLOCK_SIZE + start_block > getNbBlocks(sector)) { throw EXCEPTION(std::invalid_argument, "Bad buffer parameter. The minimum buffer's length is 16 bytes."); } if (authenticate(sector, key, keytype)) { readBinary(getBlockNo(sector, start_block), static_cast<unsigned char>(buflen / MIFARE_PLUS_BLOCK_SIZE), false, true, true, buf, buflen); } }
int main(int argc, char *argv[]) { if (argc==4) { if((strcmp(argv[1],"H") == 0) || (strcmp(argv[1],"M") == 0) || (strcmp(argv[1],"L") == 0)) { printf("Filter will be %s \nBinary file input will be %s \nBinary file output will be %s \n", argv[1],argv[2],argv[3]); readBinary(argv[1],argv[2],argv[3]); testRead(argv[3]); } else { printf("Invalid filter\n"); return 1; } } else { printf("Wrong number of parameters\n"); return 1; } return 0; }
inline void SeededSliceExtractor<DataSetWrapperParam>::Parameters::read( Comm::MulticastPipe& pipe, Visualization::Abstract::VariableManager* variableManager) { /* Read from multicast pipe: */ readBinary(pipe,true,variableManager); /* Get a templatized locator to track the seed point: */ const DataSetWrapper* myDataSet=dynamic_cast<const DataSetWrapper*>(variableManager->getDataSetByScalarVariable(scalarVariableIndex)); if(myDataSet==0) Misc::throwStdErr("SeededSliceExtractor::Parameters::readBinary: Mismatching data set type"); dsl=myDataSet->getDs().getLocator(); locatorValid=dsl.locatePoint(seedPoint); }
void CasmReader::readTextOrBinary(charstring Filename, std::shared_ptr<SymbolTable> EnclosingScope, std::shared_ptr<SymbolTable> AlgSymtab) { if (AlgSymtab) { std::shared_ptr<Queue> Binary = std::make_shared<ReadBackedQueue>( std::make_shared<FileReader>(Filename)); // Mark the beginning of the stream, so that it doesn't loose the page. ReadCursor Hold(Binary); if (hasBinaryHeader(Binary, AlgSymtab)) return readBinary(Binary, AlgSymtab, EnclosingScope); } if (std::string(Filename) == "-") // Can't reread from stdin, so fail! foundErrors(); else readText(Filename, EnclosingScope); }
bool Client::executeQuery(const InterserverIOEndpointLocation & location, const std::string & query) { ReadBufferFromHTTP::Params params = { {"endpoint", getEndpointId(location.name)}, {"compress", "false"}, {"query", query} }; ReadBufferFromHTTP in{location.host, location.port, params}; bool flag; readBinary(flag, in); assertEOF(in); return flag; }
/*************************************************************************** * int main * Parses command line. Format is: * argv[0] [-v] bin_file * * options: * -v Verbose mode. Prints text output rather than raw output. * *-------------------------------------------------------------------------- * To go into man page: * Name: emu-lejosrun - Emulate lejos RCX code in Unix * * Synosis: emu-lejosrun [-v] bin_file * * Description: Executes a binary file created by the lejos compiler within * Unix rather than in the RCX environment. The Java byte-codes * are executed here, and their actions are listed rather than * executed as they would be on the real RCX device. * * Options: -v Verbose mode. Normally the output is printed in raw * mode. The actual hex values are printed. Using this * option displays more user-friendly output. *-------------------------------------------------------------------------- ***************************************************************************/ int main (int argc, char *argv[]) { int c; char *file = argv[argc - 1]; /* Process any options. */ while(--argc > 0 && (*++argv)[0] == '-') while((c = *++argv[0]) != 0) switch (c) { case 'v': verbose = 1; break; default: printf("%s: unknown option %c\n", argv[0], c); exit(1); } if (argc != 1) { printf ("%s runs a binary dumped by the linker.\n", argv[0]); printf ("Use: %s [-v] binary_file\n", argv[0]); exit (1); } #if DEBUG_STARTUP printf ("Reading binary %s\n", file); #endif readBinary (file); if (gettimeofday(&gStart, NULL)) perror("main: gettimeofday"); timer_handler (SIGALRM); if (setitimer(ITIMER_REAL, &itimer, null) < 0) { printf ("Failed to set interval timer\n"); exit(1); } init_sensors (); last_ad_time = get_sys_time(); run(); itimer.it_value.tv_usec = 0; setitimer(ITIMER_REAL, &itimer, null); signal(SIGALRM, SIG_DFL); exit(0); }
Driver_Mesh::Status DriverSTL_R_SMDS_Mesh::Perform() { // Kernel_Utils::Localizer loc; Status aResult = DRS_OK; if ( myFile.empty() ) { fprintf(stderr, ">> ERREOR : invalid file name \n"); return DRS_FAIL; } SMESH_File file( myFile, /*open=*/false ); if ( !file.open() ) { fprintf(stderr, ">> ERROR : cannot open file %s \n", myFile.c_str()); if ( file.error().empty() ) fprintf(stderr, ">> ERROR : %s \n", file.error().c_str()); return DRS_FAIL; } // we skip the header which is in Ascii for both modes const char* data = file; data += HEADER_SIZE; // we check 128 characters to detect if we have a non-ascii char myIsAscii = Standard_True; for (int i = 0; i < 128; ++i, ++data) { if ( !isascii( *data ) && data < file.end() ) { myIsAscii = Standard_False; break; } } if ( !myMesh ) { fprintf(stderr, ">> ERREOR : cannot create mesh \n"); return DRS_FAIL; } if ( myIsAscii ) aResult = readAscii( file ); else aResult = readBinary( file ); return aResult; }
/// Прочитать настройки из буфера. Они записаны как набор name-value пар, идущих подряд, заканчивающихся пустым name. /// Если выставлен флаг check_readonly, в настройках выставлено readonly, но пришли какие-то изменения кинуть исключение. void Settings::deserialize(ReadBuffer & buf) { auto before_readonly = limits.readonly; while (true) { String name; readBinary(name, buf); /// Пустая строка - это маркер конца настроек. if (name.empty()) break; /// Если readonly = 2, то можно менять настройки, кроме настройки readonly. if (before_readonly == 0 || (before_readonly == 2 && name != "readonly")) set(name, buf); else ignore(name, buf); } }
bool Client::executeQuery(const InterserverIOEndpointLocation & location, const std::string & query) { Poco::URI uri; uri.setScheme("http"); uri.setHost(location.host); uri.setPort(location.port); uri.setQueryParameters( { {"endpoint", getEndpointId(location.name)}, {"compress", "false"}, {"query", query} }); ReadWriteBufferFromHTTP in{uri, Poco::Net::HTTPRequest::HTTP_POST}; bool flag; readBinary(flag, in); assertEOF(in); return flag; }