extract all block/parameters data
This commit is contained in:
parent
3c91583ede
commit
cf6f91a324
@ -33,9 +33,40 @@ namespace imc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set members
|
||||||
|
void begin(unsigned long int begin)
|
||||||
|
{
|
||||||
|
if ( end_ <= begin )
|
||||||
|
{
|
||||||
|
throw std::logic_error("parameter: offset of first byte larger than last byte's offset");
|
||||||
|
}
|
||||||
|
begin_ = begin;
|
||||||
|
}
|
||||||
|
void end(unsigned long int end)
|
||||||
|
{
|
||||||
|
if ( end <= begin_ )
|
||||||
|
{
|
||||||
|
throw std::logic_error("parameter: offset of first byte larger than last byte's offset");
|
||||||
|
}
|
||||||
|
end_ = end;
|
||||||
|
}
|
||||||
|
|
||||||
// access members
|
// access members
|
||||||
unsigned long int& begin() { return begin_; }
|
unsigned long int& begin() { return begin_; }
|
||||||
unsigned long int& end() { return end_; }
|
unsigned long int& end() { return end_; }
|
||||||
|
|
||||||
|
// comparison operator
|
||||||
|
bool operator==(const parameter& param)
|
||||||
|
{
|
||||||
|
return ( this->begin_ == param.begin_ && this->end_ == param.end_ );
|
||||||
|
}
|
||||||
|
|
||||||
|
// get info
|
||||||
|
std::string get_info()
|
||||||
|
{
|
||||||
|
return ( std::string("[") + std::to_string(begin_) + std::string(",")
|
||||||
|
+ std::to_string(end_) + std::string("]") );
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// define properties of a raw file block
|
// define properties of a raw file block
|
||||||
@ -72,6 +103,29 @@ namespace imc
|
|||||||
}
|
}
|
||||||
raw_file_ = raw_file;
|
raw_file_ = raw_file;
|
||||||
buffer_ = buffer;
|
buffer_ = buffer;
|
||||||
|
|
||||||
|
parse_parameters();
|
||||||
|
}
|
||||||
|
|
||||||
|
// identify/parse parameters in block
|
||||||
|
void parse_parameters()
|
||||||
|
{
|
||||||
|
// parse entire block and check for separator tokens
|
||||||
|
for ( unsigned long int b = begin_; b < end_; b++ )
|
||||||
|
{
|
||||||
|
if ( buffer_->at(b) == imc::ch_sep_ )
|
||||||
|
{
|
||||||
|
// define range of parameter with first byte = ch_sep_
|
||||||
|
parameters_.push_back(imc::parameter(b,b+1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// set offset of parameters's last byte
|
||||||
|
for ( unsigned long int p = 0; p < parameters_.size()-1; p++ )
|
||||||
|
{
|
||||||
|
parameters_[p].end( parameters_[p+1].begin() - 1 );
|
||||||
|
}
|
||||||
|
// parameters_.back().end(this->end_-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// access members
|
// access members
|
||||||
@ -95,12 +149,20 @@ namespace imc
|
|||||||
// get info string
|
// get info string
|
||||||
std::string get_info(int width = 20)
|
std::string get_info(int width = 20)
|
||||||
{
|
{
|
||||||
|
// summarize parameters in single string
|
||||||
|
std::string prsstr("{");
|
||||||
|
for ( auto par: parameters_ ) prsstr += par.get_info() + std::string(",");
|
||||||
|
prsstr.pop_back();
|
||||||
|
prsstr += std::string("}");
|
||||||
|
|
||||||
|
// construct block info string
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss<<std::setw(width)<<std::left<<"block-key:"<<thekey_.name_<<"\n"
|
ss<<std::setw(width)<<std::left<<"block-key:"<<thekey_.name_<<"\n"
|
||||||
<<std::setw(width)<<std::left<<"begin:"<<begin_<<"\n"
|
<<std::setw(width)<<std::left<<"begin:"<<begin_<<"\n"
|
||||||
<<std::setw(width)<<std::left<<"end:"<<end_<<"\n"
|
<<std::setw(width)<<std::left<<"end:"<<end_<<"\n"
|
||||||
<<std::setw(width)<<std::left<<"rawfile:"<<raw_file_<<"\n"
|
<<std::setw(width)<<std::left<<"rawfile:"<<raw_file_<<"\n"
|
||||||
<<std::setw(width)<<std::left<<"buffersize:"<<buffer_->size()<<"\n";
|
<<std::setw(width)<<std::left<<"buffersize:"<<buffer_->size()<<"\n"
|
||||||
|
<<std::setw(width)<<std::left<<"parameters:"<<prsstr<<"\n";
|
||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@
|
|||||||
|
|
||||||
namespace imc
|
namespace imc
|
||||||
{
|
{
|
||||||
|
// define "magic bytes" announcing critical (=C) non-critical keys (=N)
|
||||||
|
const unsigned char key_crit_ = 0x43, key_non_crit_ = 0x4e;
|
||||||
|
|
||||||
// define properties of marker/key
|
// define properties of marker/key
|
||||||
struct key
|
struct key
|
||||||
|
@ -63,7 +63,7 @@ namespace imc
|
|||||||
if ( *it == ch_bgn_ )
|
if ( *it == ch_bgn_ )
|
||||||
{
|
{
|
||||||
// check for (non)critical key
|
// check for (non)critical key
|
||||||
if ( *(it+1) == 0x43 || *(it+1) == 0x4e )
|
if ( *(it+1) == imc::key_crit_ || *(it+1) == imc::key_non_crit_ )
|
||||||
{
|
{
|
||||||
// compose entire key
|
// compose entire key
|
||||||
std::string newkey = { (char)*(it+1), (char)*(it+2) };
|
std::string newkey = { (char)*(it+1), (char)*(it+2) };
|
||||||
@ -95,10 +95,10 @@ namespace imc
|
|||||||
unsigned long length = std::stoul(leng);
|
unsigned long length = std::stoul(leng);
|
||||||
|
|
||||||
// declare corresponding key and block
|
// declare corresponding key and block
|
||||||
imc::key bkey( (*(it+1)-0x43)==0, newkey,
|
imc::key bkey( *(it+1)==imc::key_crit_ , newkey,
|
||||||
imc::keys.at(newkey).description_, version );
|
imc::keys.at(newkey).description_, version );
|
||||||
imc::block blk(bkey,it-buffer_.begin(),
|
imc::block blk(bkey,it-buffer_.begin(),
|
||||||
it-buffer_.begin()+8+length,
|
it-buffer_.begin()+pos+1+length,
|
||||||
raw_file_, &buffer_);
|
raw_file_, &buffer_);
|
||||||
|
|
||||||
// add block to list
|
// add block to list
|
||||||
@ -107,7 +107,7 @@ namespace imc
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw std::runtime_error( std::string("invalid block or corrupt buffer at byte: ")
|
throw std::runtime_error( std::string("invalid block or corrupt buffer at byte: ")
|
||||||
+ std::to_string(it-buffer_.begin()) );
|
+ std::to_string(it+3-buffer_.begin()) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -166,13 +166,14 @@ int main(int argc, char* argv[])
|
|||||||
try {
|
try {
|
||||||
imcraw.set_file(rawfile);
|
imcraw.set_file(rawfile);
|
||||||
} catch (const std::exception& e ) {
|
} catch (const std::exception& e ) {
|
||||||
std::cerr<<"failed to set raw-file: "<<e.what()<<"\n";
|
std::cerr<<"failed to open and parse raw-file: "<<e.what()<<"\n";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// list blocks
|
// list blocks
|
||||||
for ( imc::block blk: imcraw.blocks() )
|
for ( imc::block blk: imcraw.blocks() )
|
||||||
{
|
{
|
||||||
|
std::cout<<blk.get_key().get_info()<<"\n";
|
||||||
std::cout<<blk.get_info()<<"\n";
|
std::cout<<blk.get_info()<<"\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user