Esempio n. 1
0
    void
    fast_encoder_core::encode_segment(const message_cref cref, bool force_reset)
    {
      uint32_t template_id = cref.id();

      info_entry* info = repo_.find(template_id);

      if (info == nullptr) {
        BOOST_THROW_EXCEPTION(fast_dynamic_error("D9") << template_id_info(template_id));
      }

      template_instruction* instruction = std::get<0>(*info);

      if ( force_reset ||  instruction->has_reset_attribute())
        repo_.reset_dictionary();

      bool need_encode_template_id = (active_message_info_ != info);

      encoder_presence_map pmap;
      this->current_ = &pmap;
      pmap.init(&this->strm_, instruction->segment_pmap_size());
      pmap.set_next_bit(need_encode_template_id);

      if (need_encode_template_id)
      {
        active_message_info_ = info;
        strm_.encode(template_id, false, false_type());
      }

      message_cref message(cref.field_storage(0), instruction);
      message_encode_function_t encode = std::get<1>(*info);
      (this->*encode)(message);

      pmap.commit();
    }
Esempio n. 2
0
field_op::field_op(const decimal_field_instruction *inst,
                   const XMLElement *element, arena_allocator &alloc)
    : op_(inst->field_operator()), context_(inst->op_context()),
      initial_value_(inst->initial_value()), alloc_(&alloc) {
  if (element) {
    const XMLElement *field_op_element = find_field_op_element(*element);
    if (field_op_element) {
      parse_field_op(*field_op_element, alloc);
      const char *init_value_str =
          get_optional_attr(*field_op_element, "value", nullptr);

      if (init_value_str) {
        if (strcmp(element->Name(), "exponent") != 0)
          initial_value_.set(boost::lexical_cast<int64_t>(init_value_str));
        else {
          short exp = 128;
          try {
            exp = boost::lexical_cast<short>(init_value_str);
          } catch (...) {
          }

          if (exp > 63 || exp < -63) {
            BOOST_THROW_EXCEPTION(
                fast_dynamic_error("D11")
                << reason_info(std::string("Invalid exponent initial value: ") +
                               init_value_str));
          }
          initial_value_ =
              decimal_value_storage(0, static_cast<uint16_t>(exp)).storage_;
        }
      }
    }
  }
}
Esempio n. 3
0
std::ptrdiff_t
byte_vector_field_instruction::hex2binary(const char* src, unsigned char* target)
{
    unsigned char* dest = target;
    char c = 0;
    int shift_bits = 4;

    for (; *src != '\0'; ++src) {

        char tmp =0;

        if (*src >= '0' && *src <= '9') {
            tmp = (*src - '0');
        }
        else if (*src >= 'A' && *src <= 'F') {
            tmp = (*src - 'A') + '\x0A';
        }
        else if (*src >= 'a' && *src <= 'f') {
            tmp = (*src - 'a') + '\x0a';
        }
        else if (*src == ' ' || *src == '-')
            continue;
        else
            BOOST_THROW_EXCEPTION(fast_dynamic_error("D11") << reason_info("Invalid hexadecimal string" )
                                  << invalid_hexadecimal_digit_error_info(*src)
                                  << from_info(src) );

        c |= (tmp << shift_bits);

        if (shift_bits == 0) {
            *dest++ = c;
            c = 0;
            shift_bits = 4;
        }
        else
            shift_bits = 0;
    }

    if (shift_bits == 0)
        BOOST_THROW_EXCEPTION(fast_dynamic_error("D11") << reason_info("Invalid hexadecimal string, it must contain even number of hexadecimal digits" )
                              << from_info(src) );

    return dest - target;
}