本文整理汇总了C++中server::fetch_record方法的典型用法代码示例。如果您正苦于以下问题:C++ server::fetch_record方法的具体用法?C++ server::fetch_record怎么用?C++ server::fetch_record使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类server
的用法示例。
在下文中一共展示了server::fetch_record方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_request
void handle_request( const fc::http::request& r, const fc::http::server::response& s )
{
//ilog( "handle request ${r}", ("r",r.path) );
s.add_header( "Connection", "close" );
try {
auto pos = r.path.find( "/", 1 );
auto first_dir = r.path.substr(1,pos);
//ilog( "command: ${command}", ("command",first_dir) );
if( first_dir == "pending" )
{
s.set_status( fc::http::reply::OK );
auto pending_json = fc::json::to_string( _pending );
s.set_length( pending_json.size() );
s.write( pending_json.c_str(), pending_json.size() );
}
else if( first_dir == "update_record" )
{
FC_ASSERT( r.body.size() );
std::string str(r.body.data(),r.body.size());
auto rec = fc::json::from_string( str ).as<signed_name_record>();
_self->update_record( rec );
s.set_status( fc::http::reply::RecordCreated );
s.set_length( 12 );
s.write( "Record Created", 12 );
}
else if( first_dir == "fetch_by_name/" )
{
auto name = r.path.substr( pos+1, std::string::npos );
auto record = _self->fetch_record( name );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( record );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else if( first_dir == "fetch_by_key/" )
{
auto key = r.path.substr( pos+1, std::string::npos );
auto record = _self->fetch_record_by_key( key );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( record );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else if( first_dir == "store_key/" )
{
auto name = r.path.substr( pos+1, std::string::npos );
std::string str(r.body.data(),r.body.size());
auto rec = fc::json::from_string( str ).as<stored_key>();
_self->store_key( name, rec );
s.set_status( fc::http::reply::RecordCreated );
s.set_length( 12 );
s.write( "Record Created", 12 );
}
else if( first_dir == "fetch_key/" )
{
auto user_name = r.path.substr( pos+1, std::string::npos );
auto key_data = _self->fetch_key( user_name );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( key_data );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else if( first_dir == "fetch_block/" )
{
auto block_num = r.path.substr( pos+1, std::string::npos );
auto blk = _self->fetch_block( fc::to_uint64( block_num ) );
s.set_status( fc::http::reply::Found );
auto blkjson = fc::json::to_string( blk );
s.set_length( blkjson.size() );
s.write( blkjson.c_str(), blkjson.size() );
}
else
{
auto dotpos = r.path.find( ".." );
FC_ASSERT( dotpos == std::string::npos );
auto filename = _data_dir / r.path.substr(1,std::string::npos);
if( fc::exists( filename ) )
{
FC_ASSERT( !fc::is_directory( filename ) );
auto file_size = fc::file_size( filename );
FC_ASSERT( file_size != 0 );
fc::file_mapping fm( filename.generic_string().c_str(), fc::read_only );
fc::mapped_region mr( fm, fc::read_only, 0, fc::file_size( filename ) );
s.set_status( fc::http::reply::OK );
s.set_length( file_size );
s.write( (const char*)mr.get_address(), mr.get_size() );
return;
}
s.set_status( fc::http::reply::NotFound );
s.set_length( 9 );
s.write( "Not Found", 9 );
}
//.........这里部分代码省略.........