dwg_encode_object (Dwg_Object *restrict obj, Bit_Chain *hdl_dat, Bit_Chain *str_dat,
                   Bit_Chain *dat)
{
  int error = 0;
  Dwg_Object_Object *ord = obj->tio.object;

  VERSIONS (R_2000, R_2007)
  {
    obj->bitsize_pos = bit_position (dat);
    bit_write_RL (dat, obj->bitsize);
    LOG_INFO ("bitsize: " FORMAT_RL " [RL] (@%lu.%u)\n", obj->bitsize,
              dat->byte - 4, dat->bit);
  }
  if (obj->bitsize)
    obj->hdlpos = bit_position (dat) + obj->bitsize; // the handle stream offset
  SINCE (R_2007) { obj_string_stream (dat, obj, str_dat); }

  bit_write_H (dat, &obj->handle);
  LOG_TRACE ("handle: " FORMAT_H " [H 5]\n", ARGS_H (obj->handle));
  error |= dwg_encode_eed (dat, obj);

  VERSIONS (R_13, R_14)
  {
    obj->bitsize_pos = bit_position (dat);
    bit_write_RL (dat, obj->bitsize);
    LOG_INFO ("bitsize: " FORMAT_RL " [RL] (@%lu.%u)\n", obj->bitsize,
              dat->byte - 4, dat->bit);
  }

  bit_write_BL (dat, ord->num_reactors);
  LOG_TRACE ("num_reactors: " FORMAT_BL " [BL]\n", ord->num_reactors);
  SINCE (R_2004)
  {
    bit_write_B (dat, ord->xdic_missing_flag);
    LOG_TRACE ("xdic_missing_flag: " FORMAT_B " [B]\n",
               ord->xdic_missing_flag);
  }
  SINCE (R_2013)
  {
    bit_write_B (dat, ord->has_ds_binary_data);
    LOG_TRACE ("has_ds_binary_data: " FORMAT_B " [B]\n",
               ord->has_ds_binary_data);
  }
  return error;
}
dwg_encode_object (Dwg_Object *restrict obj, Bit_Chain *hdl_dat, Bit_Chain *str_dat,
                   Bit_Chain *dat)
{
  int error = 0;
  Dwg_Object_Object *ord = obj->tio.object;

  VERSIONS (R_2000, R_2007)
  {
    obj->bitsize_pos = bit_position (dat);
    bit_write_RL (dat, obj->bitsize);
    LOG_INFO ("bitsize: " FORMAT_RL " [RL] (@%lu.%u)\n", obj->bitsize,
              dat->byte - 4, dat->bit);
  }
  if (obj->bitsize)
    obj->hdlpos = bit_position (dat) + obj->bitsize;  
  SINCE (R_2007) { obj_string_stream (dat, obj, str_dat); }

  bit_write_H (dat, &obj->handle);
  LOG_TRACE ("handle: " FORMAT_H " [H 5]\n", ARGS_H (obj->handle));
  error |= dwg_encode_eed (dat, obj);

  VERSIONS (R_13, R_14)
  {
    obj->bitsize_pos = bit_position (dat);
    bit_write_RL (dat, obj->bitsize);
    LOG_INFO ("bitsize: " FORMAT_RL " [RL] (@%lu.%u)\n", obj->bitsize,
              dat->byte - 4, dat->bit);
  }

  bit_write_BL (dat, ord->num_reactors);
  LOG_TRACE ("num_reactors: " FORMAT_BL " [BL]\n", ord->num_reactors);
  SINCE (R_2004)
  {
    bit_write_B (dat, ord->xdic_missing_flag);
    LOG_TRACE ("xdic_missing_flag: " FORMAT_B " [B]\n",
               ord->xdic_missing_flag);
  }
  SINCE (R_2013)
  {
    bit_write_B (dat, ord->has_ds_binary_data);
    LOG_TRACE ("has_ds_binary_data: " FORMAT_B " [B]\n",
               ord->has_ds_binary_data);
  }
  return error;
}