Skip to content

Commit add010d

Browse files
committed
specialize save member function instead of using a separate saveJSON
1 parent 7895257 commit add010d

File tree

3 files changed

+15
-19
lines changed

3 files changed

+15
-19
lines changed

core/include/core/G3Frame.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ class G3Frame {
103103
template <class A> void save(A &ar, unsigned) const;
104104
template <class A> void load(A &ar, unsigned);
105105

106-
// JSON representation of a frame (if JSON output is enabled, otherwise
107-
// outputs valid JSON telling you that JSON output isn't enabled)
108-
template <typename T> void saveJSON(T &os) const;
109-
std::string asJSON() const;
106+
// JSON representation of a frame (if JSON output is enabled, otherwise
107+
// outputs valid JSON telling you that JSON output isn't enabled)
108+
std::string asJSON() const;
110109

111110
// Routines for handling the stored serialized copies of data.
112111
// These are all const because they only manipulate caches and

core/src/G3Frame.cxx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,15 +264,13 @@ void G3Frame::save(A &ar, unsigned v) const
264264
ar << make_nvp("crc", crc);
265265
}
266266

267-
template<typename T>
268-
void G3Frame::saveJSON(T & os) const
269-
{
270267
#ifdef SPT3G_ENABLE_JSON_OUTPUT
268+
template<>
269+
void G3Frame::save(cereal::JSONOutputArchive &ar, unsigned v) const
270+
{
271271
using cereal::make_nvp;
272-
uint32_t version(1), size(map_.size());
272+
uint32_t size(map_.size());
273273

274-
cereal::JSONOutputArchive ar(os);
275-
ar << make_nvp("version", version);
276274
ar << make_nvp("size", size);
277275
std::string typestr(1,(char) type);
278276
ar << make_nvp("type", typestr);
@@ -282,16 +280,19 @@ void G3Frame::saveJSON(T & os) const
282280
ar << make_nvp("name", i->first);
283281
ar << make_nvp("val", i->second.frameobject);
284282
}
285-
#else
286-
os << " {error: \"spt3g-software compiled without JSON support\"}" << std::endl;
287-
#endif
288283
}
284+
#endif
289285

290286
std::string
291287
G3Frame::asJSON() const
292288
{
293289
std::stringstream str;
294-
saveJSON(str);
290+
#ifdef SPT3G_ENABLE_JSON_OUTPUT
291+
cereal::JSONOutputArchive ar(str);
292+
ar << cereal::make_nvp("frame", *this);
293+
#else
294+
str << "{error: \"spt3g_software compiled without JSON support\"}" << std::endl;
295+
#endif
295296
return str.str();
296297
}
297298

@@ -425,10 +426,6 @@ template void G3Frame::saves(std::ostringstream &) const;
425426

426427
G3_SPLIT_SERIALIZABLE_CODE(G3Frame);
427428

428-
template void G3Frame::saveJSON(std::ostream &) const;
429-
template void G3Frame::saveJSON(std::ostringstream &) const;
430-
template void G3Frame::saveJSON(boost::iostreams::filtering_ostream &) const;
431-
432429
G3FramePtr
433430
g3frame_char_constructor(std::string max_4_chars)
434431
{

serve/src/spt3g-json-serve-files.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static void handle_g3(const httplib::Request & req, httplib::Response & resp)
262262

263263
frame.loads(ifs);
264264
if (i++ >= n_skip) {
265-
frame.saveJSON(os);
265+
os << frame.asJSON();
266266
first = false;
267267
}
268268
if (n_frames_to_read > 0 && i >= n_frames_to_read + n_skip)

0 commit comments

Comments
 (0)