text stringlengths 0 2.2M |
|---|
Message::Message(const json::value& root)
|
: json::value(root)
|
{
|
if (find("id") == end())
|
(*this)["id"] = util::randomString(16);
|
if (find("type") == end())
|
(*this)["type"] = "message";
|
assert(is_object());
|
}
|
Message::~Message()
|
{
|
}
|
IPacket* Message::clone() const
|
{
|
return new Message(*this);
|
}
|
ssize_t Message::read(const ConstBuffer& buf)
|
{
|
return read(buf.str()); // refactor
|
}
|
ssize_t Message::read(const std::string& root)
|
{
|
*this = json::value::parse(root.begin(), root.end());
|
return root.length();
|
}
|
void Message::write(Buffer& buf) const
|
{
|
std::string data(dump());
|
// buf.append(data.c_str(), data.size());
|
buf.insert(buf.end(), data.begin(), data.end());
|
}
|
size_t Message::size() const
|
{
|
// KLUDGE: is there a better way?
|
return dump().size();
|
}
|
void Message::print(std::ostream& os) const
|
{
|
os << dump(4);
|
}
|
bool Message::valid() const
|
{
|
return find("type") != end()
|
&& find("id") != end();
|
// && find("from") != end()
|
// && (*this)["from"].get<std::string>().length()
|
}
|
void Message::clear()
|
{
|
json::value::clear();
|
}
|
void Message::clearData()
|
{
|
(*this)["data"].clear();
|
}
|
void Message::clearNotes()
|
{
|
(*this)["notes"].clear();
|
}
|
std::string Message::type() const
|
{
|
return value("type", "message");
|
}
|
std::string Message::id() const
|
{
|
return value("id", "");
|
}
|
Address Message::to() const
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.