ceph_json: add template specializations

Missing template specializations for data types that
needed for 32 bit compilation

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
This commit is contained in:
Yehuda Sadeh 2013-03-28 13:11:58 -07:00
parent 9a8ea420f7
commit 9a07ee3784
2 changed files with 70 additions and 0 deletions

View File

@ -325,6 +325,62 @@ void decode_json_obj(unsigned long& val, JSONObj *obj)
}
}
void decode_json_obj(long long& val, JSONObj *obj)
{
string s = obj->get_data();
const char *start = s.c_str();
char *p;
errno = 0;
val = strtoll(start, &p, 10);
/* Check for various possible errors */
if ((errno == ERANGE && (val == LLONG_MAX || val == LLONG_MIN)) ||
(errno != 0 && val == 0)) {
throw JSONDecoder::err("failed to parse number");
}
if (p == start) {
throw JSONDecoder::err("failed to parse number");
}
while (*p != '\0') {
if (!isspace(*p)) {
throw JSONDecoder::err("failed to parse number");
}
p++;
}
}
void decode_json_obj(unsigned long long& val, JSONObj *obj)
{
string s = obj->get_data();
const char *start = s.c_str();
char *p;
errno = 0;
val = strtoull(start, &p, 10);
/* Check for various possible errors */
if ((errno == ERANGE && val == ULLONG_MAX) ||
(errno != 0 && val == 0)) {
throw JSONDecoder::err("failed to number");
}
if (p == start) {
throw JSONDecoder::err("failed to parse number");
}
while (*p != '\0') {
if (!isspace(*p)) {
throw JSONDecoder::err("failed to parse number");
}
p++;
}
}
void decode_json_obj(int& val, JSONObj *obj)
{
long l;
@ -397,6 +453,16 @@ void encode_json(const char *name, unsigned long val, Formatter *f)
f->dump_int(name, val);
}
void encode_json(const char *name, unsigned long long val, Formatter *f)
{
f->dump_int(name, val);
}
void encode_json(const char *name, long long val, Formatter *f)
{
f->dump_int(name, val);
}
void encode_json(const char *name, const utime_t& val, Formatter *f)
{
f->dump_stream(name) << val;

View File

@ -127,6 +127,8 @@ static inline void decode_json_obj(string& val, JSONObj *obj)
val = obj->get_data();
}
void decode_json_obj(unsigned long long& val, JSONObj *obj);
void decode_json_obj(long long& val, JSONObj *obj);
void decode_json_obj(unsigned long& val, JSONObj *obj);
void decode_json_obj(long& val, JSONObj *obj);
void decode_json_obj(unsigned& val, JSONObj *obj);
@ -252,6 +254,8 @@ void encode_json(const char *name, long val, Formatter *f);
void encode_json(const char *name, unsigned long val, Formatter *f);
void encode_json(const char *name, const utime_t& val, Formatter *f);
void encode_json(const char *name, const bufferlist& bl, Formatter *f);
void encode_json(const char *name, long long val, Formatter *f);
void encode_json(const char *name, long long unsigned val, Formatter *f);
template<class K, class V>
void encode_json_map(const char *name, const char *index_name,