mirror of
https://github.com/zeek/zeek.git
synced 2025-10-03 07:08:19 +00:00
Add the ability to remove surrounding braces from the JSON formatter.
This commit is contained in:
parent
212368b245
commit
b00bd7702f
2 changed files with 13 additions and 3 deletions
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
using namespace threading::formatter;
|
using namespace threading::formatter;
|
||||||
|
|
||||||
JSON::JSON(MsgThread* t, TimeFormat tf) : Formatter(t)
|
JSON::JSON(MsgThread* t, TimeFormat tf) : Formatter(t), surrounding_braces(true)
|
||||||
{
|
{
|
||||||
timestamps = tf;
|
timestamps = tf;
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ JSON::~JSON()
|
||||||
bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
||||||
Value** vals) const
|
Value** vals) const
|
||||||
{
|
{
|
||||||
|
if ( surrounding_braces )
|
||||||
desc->AddRaw("{");
|
desc->AddRaw("{");
|
||||||
|
|
||||||
for ( int i = 0; i < num_fields; i++ )
|
for ( int i = 0; i < num_fields; i++ )
|
||||||
|
@ -41,6 +42,7 @@ bool JSON::Describe(ODesc* desc, int num_fields, const Field* const * fields,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( surrounding_braces )
|
||||||
desc->AddRaw("}");
|
desc->AddRaw("}");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -217,3 +219,8 @@ threading::Value* JSON::ParseValue(const string& s, const string& name, TypeTag
|
||||||
GetThread()->Error("JSON formatter does not support parsing yet.");
|
GetThread()->Error("JSON formatter does not support parsing yet.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void JSON::SurroundingBraces(bool use_braces)
|
||||||
|
{
|
||||||
|
surrounding_braces = use_braces;
|
||||||
|
}
|
||||||
|
|
|
@ -27,8 +27,11 @@ public:
|
||||||
threading::Value** vals) const;
|
threading::Value** vals) const;
|
||||||
virtual threading::Value* ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const;
|
virtual threading::Value* ParseValue(const string& s, const string& name, TypeTag type, TypeTag subtype = TYPE_ERROR) const;
|
||||||
|
|
||||||
|
void SurroundingBraces(bool use_braces);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TimeFormat timestamps;
|
TimeFormat timestamps;
|
||||||
|
bool surrounding_braces;
|
||||||
};
|
};
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue