cdpf.tcc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Templated method implementations for cdpf.hpp
  2. // I/O for CDPFs
  3. // Read the DPF from the output stream. You can use this to read DPFs
  4. // from files or from the network.
  5. template <typename T>
  6. T& operator>>(T &is, CDPF &cdpf)
  7. {
  8. is.read((char *)&cdpf.seed, sizeof(cdpf.seed));
  9. cdpf.whichhalf = get_lsb(cdpf.seed);
  10. uint8_t depth = VALUE_BITS - 7;
  11. cdpf.cw.clear();
  12. for (uint8_t i=0; i<depth; ++i) {
  13. DPFnode cw;
  14. is.read((char *)&cw, sizeof(cw));
  15. cdpf.cw.push_back(cw);
  16. }
  17. value_t cfbits = 0;
  18. is.read((char *)&cfbits, BITBYTES(depth));
  19. cdpf.cfbits = cfbits;
  20. is.read((char *)&cdpf.leaf_cwr, sizeof(cdpf.leaf_cwr));
  21. is.read((char *)&cdpf.as_target, sizeof(cdpf.as_target));
  22. is.read((char *)&cdpf.xs_target, sizeof(cdpf.xs_target));
  23. return is;
  24. }
  25. // Write the DPF to the output stream. You can use this to write DPFs
  26. // to files or over the network.
  27. template <typename T>
  28. T& operator<<(T &os, const CDPF &cdpf)
  29. {
  30. os.write((const char *)&cdpf.seed, sizeof(cdpf.seed));
  31. uint8_t depth = VALUE_BITS - 7;
  32. for (uint8_t i=0; i<depth; ++i) {
  33. os.write((const char *)&cdpf.cw[i], sizeof(cdpf.cw[i]));
  34. }
  35. os.write((const char *)&cdpf.cfbits, BITBYTES(depth));
  36. os.write((const char *)&cdpf.leaf_cwr, sizeof(cdpf.leaf_cwr));
  37. os.write((const char *)&cdpf.as_target, sizeof(cdpf.as_target));
  38. os.write((const char *)&cdpf.xs_target, sizeof(cdpf.xs_target));
  39. return os;
  40. }