spir.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <stdio.h>
  2. #include "spir.hpp"
  3. #include "spir_ffi.h"
  4. void SPIR::init(uint32_t num_threads)
  5. {
  6. spir_init(num_threads);
  7. }
  8. SPIR_Client::SPIR_Client(uint8_t r, string &pub_params)
  9. {
  10. ClientNewRet ret = spir_client_new(r);
  11. pub_params.assign(ret.pub_params.data, ret.pub_params.len);
  12. spir_vecdata_free(ret.pub_params);
  13. this->client = ret.client;
  14. }
  15. SPIR_Client::~SPIR_Client()
  16. {
  17. spir_client_free(this->client);
  18. }
  19. string SPIR_Client::preproc(uint32_t num_preproc)
  20. {
  21. VecData msg = spir_client_preproc(this->client, num_preproc);
  22. string ret(msg.data, msg.len);
  23. spir_vecdata_free(msg);
  24. return ret;
  25. }
  26. void SPIR_Client::preproc_finish(const string &server_preproc)
  27. {
  28. spir_client_preproc_finish(this->client, server_preproc.data(),
  29. server_preproc.length());
  30. }
  31. SPIR_Server::SPIR_Server(uint8_t r, const string &pub_params)
  32. {
  33. this->server = spir_server_new(r, pub_params.data(),
  34. pub_params.length());
  35. }
  36. SPIR_Server::~SPIR_Server()
  37. {
  38. spir_server_free(this->server);
  39. }
  40. string SPIR_Server::preproc_process(const string &msg)
  41. {
  42. VecData retmsg = spir_server_preproc_process(this->server, msg.data(),
  43. msg.length());
  44. string ret(retmsg.data, retmsg.len);
  45. spir_vecdata_free(retmsg);
  46. return ret;
  47. }