From 329b7e21ea915f4579581570ee6ae821eaeaef69 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 6 Sep 2016 15:15:11 +0900 Subject: use defer --- src/bls_if.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/bls_if.cpp b/src/bls_if.cpp index 163996c..8dc99f8 100644 --- a/src/bls_if.cpp +++ b/src/bls_if.cpp @@ -1,6 +1,8 @@ #include "bls.hpp" #include "bls_if.h" #include +#include +#include void blsInit(void) { @@ -26,6 +28,29 @@ void blsIdPut(const blsId *id) std::cout << *(const bls::Id*)id << std::endl; } +int blsIdSetStr(blsId *id, const char *buf, size_t bufSize) + try +{ + std::istringstream iss(std::string(buf, bufSize)); + iss >> *(bls::Id*)id; + return 0; +} catch (std::exception& e) { + return 1; +} + +size_t blsIdGetStr(const blsId *id, char *buf, size_t maxBufSize) + try +{ + std::ostringstream oss; + oss << *(const bls::Id*)id; + std::string s = oss.str(); + if (s.size() > maxBufSize) return 0; + memcpy(buf, s.c_str(), s.size()); + return s.size(); +} catch (std::exception& e) { + return 0; +} + void blsIdSet(blsId *id, const uint64_t *p) { ((bls::Id*)id)->set(p); -- cgit v1.2.3