Vowpal Wabbit
model_parser.cc
Go to the documentation of this file.
1 #include "model_parser.h"
2 
3 namespace vw_slim
4 {
5 model_parser::model_parser(const char* model, size_t length)
6  : _model_begin(model), _model(model), _model_end(model + length), _checksum(0)
7 {
8 #ifdef MODEL_PARSER_DEBUG
9  std::cout << "moder_parser("
10  << "0x" << std::hex << std::setw(8) << (uint64_t)_model_begin << "-" << std::hex << std::setw(8)
11  << (uint64_t)_model_end << ")" << std::dec;
12 #endif
13 }
14 
15 const char* model_parser::position() { return _model; }
16 
17 uint32_t model_parser::checksum() { return _checksum; }
18 
19 int model_parser::read(const char* field_name, size_t field_length, const char** ret)
20 { // check if we're inside the buffer
21  const char* new_model = _model + field_length;
22  if (new_model > _model_end)
24 
25 #ifdef MODEL_PARSER_DEBUG
26  std::fstream log("vwslim-debug.log", std::fstream::app);
27  log << "reading " << field_name << std::endl;
28 #endif
29 
30  *ret = _model;
31  // advance begin
32  _model = new_model;
33 
34  return S_VW_PREDICT_OK;
35 }
36 
37 int model_parser::skip(size_t bytes)
38 {
39  const char* new_model = _model + bytes;
40  if (new_model > _model_end)
42 
43  if (bytes > 0)
44  _checksum = (uint32_t)uniform_hash(_model, bytes, _checksum);
45 
46  _model = new_model;
47 
48  return S_VW_PREDICT_OK;
49 }
50 } // namespace vw_slim
#define S_VW_PREDICT_OK
const char * _model
Definition: model_parser.h:23
VW_STD14_CONSTEXPR uint64_t uniform_hash(const void *key, size_t len, uint64_t seed)
Definition: hash.h:67
const char * _model_begin
Definition: model_parser.h:22
int read(const char *field_name, size_t field_length, const char **ret)
Definition: model_parser.cc:19
#define E_VW_PREDICT_ERR_INVALID_MODEL
int skip(size_t bytes)
Definition: model_parser.cc:37
model_parser(const char *model, size_t length)
Definition: model_parser.cc:5
const char * position()
Definition: model_parser.cc:15
const char * _model_end
Definition: model_parser.h:24