bool Encoder::encode()

in hessian2/basic_codec/number_codec.cc [61:91]


bool Encoder::encode(const double &value) {
  int32_t int_value = static_cast<int32_t>(value);
  if (int_value == value) {
    if (int_value == 0) {
      writer_->writeByte(0x5b);
      return true;
    }

    if (int_value == 1) {
      writer_->writeByte(0x5c);
      return true;
    }

    if (int_value >= -0x80 && int_value < 0x80) {
      writer_->writeByte(0x5d);
      writer_->writeBE<int8_t>(int_value);
      return true;
    }

    if (int_value >= -0x8000 && int_value < 0x8000) {
      writer_->writeByte(0x5e);
      writer_->writeBE<int8_t>(int_value >> 8);
      writer_->writeBE<uint8_t>(int_value);
      return true;
    }
  }

  writer_->writeByte(0x44);
  writeBEDouble(writer_, value);
  return true;
}