compiler/cpp/src/generate/t_hs_generator.cc
/**
 * Deserializes a field of any type.
 */
Deserializes a field of any type.
Deserializes a field of any type .
void t_hs_generator::generate_deserialize_type(ofstream &out,
                                               t_type* type) {
  type = get_true_type(type);
  if (type->is_void())
    throw "CANNOT GENERATE DESERIALIZE CODE FOR void TYPE";
  if (type->is_struct() || type->is_xception()) {
    generate_deserialize_struct(out, (t_struct*)type);
  } else if (type->is_container()) {
    generate_deserialize_container(out, type);
  } else if (type->is_base_type()) {
    t_base_type::t_base tbase = ((t_base_type*)type)->get_base();
    switch (tbase) {
    case t_base_type::TYPE_VOID:
      throw "compiler error: cannot serialize void field in a struct";
      break;
    case t_base_type::TYPE_STRING:
      out << (((t_base_type*)type)->is_binary() ? "readBinary" : "readString");
      break;
    case t_base_type::TYPE_BOOL:
      out << "readBool";
      break;
    case t_base_type::TYPE_BYTE:
      out << "readByte";
      break;
    case t_base_type::TYPE_I16:
      out << "readI16";
      break;
    case t_base_type::TYPE_I32:
      out << "readI32";
      break;
    case t_base_type::TYPE_I64:
      out << "readI64";
      break;
    case t_base_type::TYPE_DOUBLE:
      out << "readDouble";
      break;
    default:
      throw "compiler error: no PHP name for base type " + t_base_type::t_base_name(tbase);
    }
    out << " iprot";
  } else if (type->is_enum()) {
    string ename = capitalize(type->get_name());
    out << "(do {i <- readI32 iprot; return $ toEnum $ fromIntegral i})";
  } else {
    printf("DO NOT KNOW HOW TO DESERIALIZE TYPE '%s'\n",
           type->get_name().c_str());
  }
}
void t_hs_generator :: generate_deserialize_type ( ofstream & out , t_type * type ) { type = get_true_type ( type ) ; if ( type -> is_void ( ) ) throw " " ; if ( type -> is_struct ( ) || type -> is_xception ( ) ) { generate_deserialize_struct ( out , ( t_struct * ) type ) ; } else if ( type -> is_container ( ) ) { generate_deserialize_container ( out , type ) ; } else if ( type -> is_base_type ( ) ) { t_base_type :: t_base tbase = ( ( t_base_type * ) type ) -> get_base ( ) ; switch ( tbase ) { case t_base_type :: TYPE_VOID : throw " " ; break ; case t_base_type :: TYPE_STRING : out << ( ( ( t_base_type * ) type ) -> is_binary ( ) ? " " : " " ) ; break ; case t_base_type :: TYPE_BOOL : out << " " ; break ; case t_base_type :: TYPE_BYTE : out << " " ; break ; case t_base_type :: TYPE_I16 : out << " " ; break ; case t_base_type :: TYPE_I32 : out << " " ; break ; case t_base_type :: TYPE_I64 : out << " " ; break ; case t_base_type :: TYPE_DOUBLE : out << " " ; break ; default : throw " " + t_base_type :: t_base_name ( tbase ) ; } out << " " ; } else if ( type -> is_enum ( ) ) { string ename = capitalize ( type -> get_name ( ) ) ; out << " " ; } else { printf ( " \n " , type -> get_name ( ) . c_str ( ) ) ; } }
Deserializes a field of any type.
Deserializes a field of any type .