/* static */ CNetCacheAPI::EReadResult SNetCacheAPIImpl::ReadBuffer( IReader& reader, char* buf_ptr, size_t buf_size, size_t* n_read, size_t blob_size) { size_t bytes_read; size_t total_bytes_read = 0; while (buf_size > 0) { ERW_Result rw_res = reader.Read(buf_ptr, buf_size, &bytes_read); if (rw_res == eRW_Success) { total_bytes_read += bytes_read; buf_ptr += bytes_read; buf_size -= bytes_read; } else if (rw_res == eRW_Eof) { break; } else { NCBI_THROW(CNetServiceException, eCommunicationError, "Error while reading BLOB"); } } if (n_read != NULL) *n_read = total_bytes_read; return total_bytes_read == blob_size ? CNetCacheAPI::eReadComplete : CNetCacheAPI::eReadPart; }
void Package::Read(IReader & reader) { reader.Read((byte_t*)&_uuid,sizeof(_uuid)); reader.Read((byte_t*)&_version.Major,sizeof(lemon::uint16_t)); reader.Read((byte_t*)&_version.Minor,sizeof(lemon::uint16_t)); reader.Read((byte_t*)&_version.Build,sizeof(lemon::uint16_t)); reader.Read((byte_t*)&_version.Reversion,sizeof(lemon::uint16_t)); _version.Major = ntohs(_version.Major); _version.Minor = ntohs(_version.Minor); _version.Build = ntohs(_version.Build); _version.Reversion = ntohs(_version.Reversion); lemon::uint8_t tables; reader.Read(&tables,sizeof(tables)); for(size_t i = 0; i < tables; ++ i) { char locale[6] = {0}; reader.Read((byte_t*)locale,5); ResourceTable & table =_resourceTables[lemon::from_utf8(locale)]; table.Read(reader); } }
void ResourceTable::Read(IReader & reader) { lemon::uint16_t i18nTextTableSize = 0; lemon::uint16_t traceMessageTableSize = 0; lemon::uint16_t traceCatalogTableSize = 0; lemon::uint16_t errorMessageTableSize = 0; lemon::uint16_t stringTableSize = 0; reader.Read((byte_t*)&i18nTextTableSize,sizeof(i18nTextTableSize)); reader.Read((byte_t*)&traceMessageTableSize,sizeof(traceMessageTableSize)); reader.Read((byte_t*)&traceCatalogTableSize,sizeof(traceCatalogTableSize)); reader.Read((byte_t*)&errorMessageTableSize,sizeof(errorMessageTableSize)); reader.Read((byte_t*)&stringTableSize,sizeof(stringTableSize)); i18nTextTableSize = htons(i18nTextTableSize); traceMessageTableSize = htons(traceMessageTableSize); traceCatalogTableSize = htons(traceCatalogTableSize); errorMessageTableSize = htons(errorMessageTableSize); stringTableSize = htons(stringTableSize); std::vector<I18nText> texts; for(size_t i = 0; i < i18nTextTableSize; ++ i) { I18nText text; reader.Read((byte_t*)&text.key,sizeof(text.key)); reader.Read((byte_t*)&text.Message,sizeof(text.Message)); text.key = ntohl(text.key); text.Message = ntohl(text.Message); texts.push_back(text); } for(size_t i = 0; i < traceMessageTableSize; ++ i) { TraceMessage text; reader.Read((byte_t*)&text.Id,sizeof(text.Id)); reader.Read((byte_t*)&text.Message,sizeof(text.Message)); text.Id = ntohl(text.Id); text.Message = ntohl(text.Message); _traceMessageTable[text.Id] = text; } for(size_t i = 0; i < traceCatalogTableSize; ++ i) { TraceCatalog text; reader.Read((byte_t*)&text.Value,sizeof(text.Value)); reader.Read((byte_t*)&text.Name,sizeof(text.Name)); reader.Read((byte_t*)&text.Description,sizeof(text.Description)); text.Value = ntohl(text.Value); text.Name = ntohl(text.Name); text.Description = ntohl(text.Description); _traceCatalogTable[text.Value] = text; } for(size_t i = 0; i < errorMessageTableSize; ++ i) { ErrorMessage text; reader.Read((byte_t*)&text.Code,sizeof(text.Code)); reader.Read((byte_t*)&text.Name,sizeof(text.Name)); reader.Read((byte_t*)&text.Description,sizeof(text.Description)); text.Code = ntohl(text.Code); text.Name = ntohl(text.Name); text.Description = ntohl(text.Description); _errorMessageTable[text.Code] = text; } StringTable table; table.Read(stringTableSize, reader); for(size_t i = 0 ; i < table.Items(); ++ i) { tuple<const lemon::byte_t*,size_t> result = table.Get((lemon::uint32_t)i); lemon::String val = lemon::from_utf8((const char*)get<0>(result)); _stringTable.Push(__cbuf(val.c_str())); } for(size_t i = 0; i < i18nTextTableSize; ++ i) { _textTable[(const char_t*)get<0>(_stringTable.Get(texts[i].key))] = texts[i]; } }