compiler/cpp/src/generate/t_hs_generator.cc
/**
 * Serialize a container by writing out the header followed by
 * data and then a footer.
 */
Serialize a container by writing out the header followed by
data and then a footer.
Serialize a container by writing out the header followed by data and then a footer .
void t_hs_generator::generate_deserialize_container(ofstream &out,
                                                    t_type* ttype) {
  string size = tmp("_size");
  string ktype = tmp("_ktype");
  string vtype = tmp("_vtype");
  string etype = tmp("_etype");
  string con = tmp("_con");
  t_field fsize(g_type_i32, size);
  t_field fktype(g_type_byte, ktype);
  t_field fvtype(g_type_byte, vtype);
  t_field fetype(g_type_byte, etype);
  if (ttype->is_map()) {
    out << "(let {f 0 = return []; f n = do {k <- ";
    generate_deserialize_type(out,((t_map*)ttype)->get_key_type());
    out << "; v <- ";
    generate_deserialize_type(out,((t_map*)ttype)->get_val_type());
    out << ";r <- f (n-1); return $ (k,v):r}} in do {(" << ktype << "," << vtype << "," << size << ") <- readMapBegin iprot; l <- f " << size << "; return $ Map.fromList l})";
  } else if (ttype->is_set()) {
    out << "(let {f 0 = return []; f n = do {v <- ";
    generate_deserialize_type(out,((t_map*)ttype)->get_key_type());
    out << ";r <- f (n-1); return $ v:r}} in do {(" << etype << "," << size << ") <- readSetBegin iprot; l <- f " << size << "; return $ Set.fromList l})";
  } else if (ttype->is_list()) {
    out << "(let f n = Vector.replicateM (fromIntegral n) (";
    generate_deserialize_type(out,((t_map*)ttype)->get_key_type());
    out << ") in do {(" << etype << "," << size << ") <- readListBegin iprot; f " << size << "})";
  }
}
void t_hs_generator :: generate_deserialize_container ( ofstream & out , t_type * ttype ) { string size = tmp ( " " ) ; string ktype = tmp ( " " ) ; string vtype = tmp ( " " ) ; string etype = tmp ( " " ) ; string con = tmp ( " " ) ; t_field fsize ( g_type_i32 , size ) ; t_field fktype ( g_type_byte , ktype ) ; t_field fvtype ( g_type_byte , vtype ) ; t_field fetype ( g_type_byte , etype ) ; if ( ttype -> is_map ( ) ) { out << " " ; generate_deserialize_type ( out , ( ( t_map * ) ttype ) -> get_key_type ( ) ) ; out << " " ; generate_deserialize_type ( out , ( ( t_map * ) ttype ) -> get_val_type ( ) ) ; out << " " << ktype << " " << vtype << " " << size << " " << size << " " ; } else if ( ttype -> is_set ( ) ) { out << " " ; generate_deserialize_type ( out , ( ( t_map * ) ttype ) -> get_key_type ( ) ) ; out << " " << etype << " " << size << " " << size << " " ; } else if ( ttype -> is_list ( ) ) { out << " " ; generate_deserialize_type ( out , ( ( t_map * ) ttype ) -> get_key_type ( ) ) ; out << " " << etype << " " << size << " " << size << " " ; } }
Serialize a container by writing out the header followed by
 data and then a footer.
Serialize a container by writing out the header followed by data and then a footer .
// Declare variables, read header