Revision e42a6889 gruel/src/lib/pmt/pmt_serialize.cc

b/gruel/src/lib/pmt/pmt_serialize.cc
24 24
#endif
25 25
#include <vector>
26 26
#include <gruel/pmt.h>
27
#include <iostream>
27 28
#include "pmt_int.h"
28 29
#include "gruel/pmt_serial_tags.h"
29 30

......
213 214
  return t != std::streambuf::traits_type::eof();
214 215
}
215 216

217
static bool
218
deserialize_tuple(pmt_t *tuple, std::streambuf &sb)
219
{
220
    std::cout << "deserialize_tuple\n";
221
    uint32_t nitems;
222
    bool ok = deserialize_untagged_u32(&nitems, sb);
223
    pmt_t list(PMT_NIL);
224
    std::cout << "nitems: " << nitems << "\n";
225
    for(uint32_t i=0; i<nitems; i++){   
226
        std::cout << "deserialize_tuple :: recursive call to pmt_deserialize\n";
227
        pmt_t item = pmt_deserialize( sb );
228
        pmt_print(item);
229
        if(pmt_eq(list, PMT_NIL)){
230
            list = pmt_list1(item);
231
        } else {
232
            list = pmt_list_add(list, item);
233
        }
234
    }
235
    (*tuple) = pmt_to_tuple(list);
236
    return ok;
237
}
238

216 239

217 240
/*
218 241
 * Write portable byte-serial representation of \p obj to \p sb
......
300 323
  if (pmt_is_dict(obj))
301 324
    throw pmt_notimplemented("pmt_serialize (dict)", obj);
302 325

326
  if (pmt_is_tuple(obj)){
327
    size_t tuple_len = pmt::pmt_length(obj);
328
    ok = serialize_untagged_u8(PST_COMPLEX, sb);
329
    ok &= serialize_untagged_u32(tuple_len, sb);
330
    for(size_t i=0; i<tuple_len; i++){
331
        ok &= pmt_serialize(pmt_tuple_ref(obj, i), sb);
332
    }
333
    return ok;
334
  }
335
  //throw pmt_notimplemented("pmt_serialize (tuple)", obj);
303 336

304 337
  throw pmt_notimplemented("pmt_serialize (?)", obj);
305 338
}
......
369 402
      goto error;
370 403
    return pmt_make_rectangular( r,i );
371 404
    }
405
    
406
  case PST_TUPLE:
407
    {
408
    pmt_t tuple;
409
    if(!deserialize_tuple(&tuple, sb));
410
      goto error;
411
    return tuple;
412
    }
372 413

373 414
  case PST_VECTOR:
374 415
  case PST_DICT:

Also available in: Unified diff