aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-09-06 14:15:11 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-09-06 14:15:11 +0800
commit329b7e21ea915f4579581570ee6ae821eaeaef69 (patch)
treecccbba673d9529599754a544f78fa869edab01db /src
parent5d6ecea7ad17251f90fe4fc0a1f1937d0eac47b5 (diff)
downloaddexon-bls-329b7e21ea915f4579581570ee6ae821eaeaef69.tar
dexon-bls-329b7e21ea915f4579581570ee6ae821eaeaef69.tar.gz
dexon-bls-329b7e21ea915f4579581570ee6ae821eaeaef69.tar.bz2
dexon-bls-329b7e21ea915f4579581570ee6ae821eaeaef69.tar.lz
dexon-bls-329b7e21ea915f4579581570ee6ae821eaeaef69.tar.xz
dexon-bls-329b7e21ea915f4579581570ee6ae821eaeaef69.tar.zst
dexon-bls-329b7e21ea915f4579581570ee6ae821eaeaef69.zip
use defer
Diffstat (limited to 'src')
-rw-r--r--src/bls_if.cpp25
1 files changed, 25 insertions, 0 deletions
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 <iostream>
+#include <sstream>
+#include <memory.h>
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);