dasmig-core 1.2.0
Shared random engine, distributions and data tiers for the dasmig generator libraries
Loading...
Searching...
No Matches
dasmig::core::jsonl_writer Class Reference

Writes one JSON document per line (JSON Lines / NDJSON). More...

#include <sinks.hpp>

Public Member Functions

 jsonl_writer (std::ostream &out)
 Write to out, which must outlive the writer.
 
void write_line (std::string_view json)
 Write one document as a line.
 
template<json_result T>
void operator() (std::uint64_t, const T &item)
 Sink call: write the item's to_json().
 
std::size_t lines () const noexcept
 Lines written so far.
 

Detailed Description

Writes one JSON document per line (JSON Lines / NDJSON).

Use it as the sink of for_each_batch(); results need to_json().

gen.for_each_name(request, {.count = 1000}, 7, out);
Writes one JSON document per line (JSON Lines / NDJSON).
Definition sinks.hpp:301

Definition at line 300 of file sinks.hpp.

Constructor & Destructor Documentation

◆ jsonl_writer()

dasmig::core::jsonl_writer::jsonl_writer ( std::ostream &  out)
inlineexplicit

Write to out, which must outlive the writer.

Parameters
outDestination stream.

Definition at line 305 of file sinks.hpp.

Member Function Documentation

◆ lines()

std::size_t dasmig::core::jsonl_writer::lines ( ) const
inlinenoexcept

Lines written so far.

Returns
The count.

Definition at line 331 of file sinks.hpp.

◆ operator()()

template<json_result T>
void dasmig::core::jsonl_writer::operator() ( std::uint64_t  ,
const T &  item 
)
inline

Sink call: write the item's to_json().

Parameters
itemThe result.

Definition at line 324 of file sinks.hpp.

◆ write_line()

void dasmig::core::jsonl_writer::write_line ( std::string_view  json)
inline

Write one document as a line.

Parameters
jsonCompact JSON; it must not contain a line break.
Exceptions
std::invalid_argumentIf json contains a line break.

Definition at line 310 of file sinks.hpp.


The documentation for this class was generated from the following file: