mirror of
https://github.com/zeek/zeek.git
synced 2025-10-10 10:38:20 +00:00
read vector.
still missing: enums, empty fields for optional parameters.
This commit is contained in:
parent
fb5f26e7fc
commit
821878835a
5 changed files with 83 additions and 36 deletions
|
@ -244,12 +244,10 @@ bool InputMgr::IsCompatibleType(BroType* t, bool atomic_only)
|
||||||
|
|
||||||
case TYPE_VECTOR:
|
case TYPE_VECTOR:
|
||||||
{
|
{
|
||||||
return false; // do me...
|
if ( atomic_only )
|
||||||
|
return false;
|
||||||
|
|
||||||
//if ( atomic_only )
|
return IsCompatibleType(t->AsVectorType()->YieldType(), true);
|
||||||
// return false;
|
|
||||||
//
|
|
||||||
//return IsCompatibleType(t->AsVectorType()->YieldType());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -342,7 +340,9 @@ bool InputMgr::UnrollRecordType(vector<LogField*> *fields, const RecordType *rec
|
||||||
field->name = nameprepend + rec->FieldName(i);
|
field->name = nameprepend + rec->FieldName(i);
|
||||||
field->type = rec->FieldType(i)->Tag();
|
field->type = rec->FieldType(i)->Tag();
|
||||||
if ( field->type == TYPE_TABLE ) {
|
if ( field->type == TYPE_TABLE ) {
|
||||||
field->set_type = rec->FieldType(i)->AsSetType()->Indices()->PureType()->Tag();
|
field->subtype = rec->FieldType(i)->AsSetType()->Indices()->PureType()->Tag();
|
||||||
|
} else if ( field->type == TYPE_VECTOR ) {
|
||||||
|
field->subtype = rec->FieldType(i)->AsVectorType()->YieldType()->Tag();
|
||||||
}
|
}
|
||||||
|
|
||||||
fields->push_back(field);
|
fields->push_back(field);
|
||||||
|
@ -870,6 +870,13 @@ int InputMgr::GetLogValLength(const LogVal* val) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TYPE_VECTOR: {
|
||||||
|
for ( int i = 0; i < val->val.vector_val.size; i++ ) {
|
||||||
|
length += GetLogValLength(val->val.vector_val.vals[i]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
reporter->InternalError("unsupported type %d for GetLogValLength", val->type);
|
reporter->InternalError("unsupported type %d for GetLogValLength", val->type);
|
||||||
}
|
}
|
||||||
|
@ -936,6 +943,15 @@ int InputMgr::CopyLogVal(char *data, const int startpos, const LogVal* val) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TYPE_VECTOR: {
|
||||||
|
int length = 0;
|
||||||
|
for ( int i = 0; i < val->val.vector_val.size; i++ ) {
|
||||||
|
length += CopyLogVal(data, startpos+length, val->val.vector_val.vals[i]);
|
||||||
|
}
|
||||||
|
return length;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
reporter->InternalError("unsupported type %d for CopyLogVal", val->type);
|
reporter->InternalError("unsupported type %d for CopyLogVal", val->type);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1039,6 +1055,21 @@ Val* InputMgr::LogValToVal(const LogVal* val, TypeTag request_type) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case TYPE_VECTOR: {
|
||||||
|
assert ( val->val.vector_val.size > 1 ); // implement empty vector...
|
||||||
|
|
||||||
|
// all entries have to have the same type...
|
||||||
|
TypeTag type = val->val.vector_val.vals[0]->type;
|
||||||
|
VectorType* vt = new VectorType(base_type(type));
|
||||||
|
VectorVal* v = new VectorVal(vt);
|
||||||
|
for ( int i = 0; i < val->val.vector_val.size; i++ ) {
|
||||||
|
assert( val->val.vector_val.vals[i]->type == type);
|
||||||
|
v->Assign(i, LogValToVal( val->val.set_val.vals[i], type ), 0);
|
||||||
|
}
|
||||||
|
return v;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
case TYPE_ENUM:
|
case TYPE_ENUM:
|
||||||
reporter->InternalError("Sorry, Enum reading does not yet work, missing internal inferface");
|
reporter->InternalError("Sorry, Enum reading does not yet work, missing internal inferface");
|
||||||
|
|
||||||
|
|
|
@ -11,20 +11,20 @@ FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, int
|
||||||
position = arg_position;
|
position = arg_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_set_type, int arg_position)
|
FieldMapping::FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position)
|
||||||
: name(arg_name), type(arg_type), set_type(arg_set_type)
|
: name(arg_name), type(arg_type), subtype(arg_subtype)
|
||||||
{
|
{
|
||||||
position = arg_position;
|
position = arg_position;
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldMapping::FieldMapping(const FieldMapping& arg)
|
FieldMapping::FieldMapping(const FieldMapping& arg)
|
||||||
: name(arg.name), type(arg.type), set_type(arg.set_type)
|
: name(arg.name), type(arg.type), subtype(arg.subtype)
|
||||||
{
|
{
|
||||||
position = arg.position;
|
position = arg.position;
|
||||||
}
|
}
|
||||||
|
|
||||||
FieldMapping FieldMapping::setType() {
|
FieldMapping FieldMapping::subType() {
|
||||||
return FieldMapping(name, set_type, position);
|
return FieldMapping(name, subtype, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputReaderAscii::InputReaderAscii()
|
InputReaderAscii::InputReaderAscii()
|
||||||
|
@ -91,7 +91,7 @@ bool InputReaderAscii::ReadHeader() {
|
||||||
const LogField* field = fields[i];
|
const LogField* field = fields[i];
|
||||||
if ( field->name == s ) {
|
if ( field->name == s ) {
|
||||||
// cool, found field. note position
|
// cool, found field. note position
|
||||||
FieldMapping f(field->name, field->type, field->set_type, i);
|
FieldMapping f(field->name, field->type, field->subtype, i);
|
||||||
columnMap.push_back(f);
|
columnMap.push_back(f);
|
||||||
wantFields++;
|
wantFields++;
|
||||||
break; // done with searching
|
break; // done with searching
|
||||||
|
@ -112,7 +112,7 @@ bool InputReaderAscii::ReadHeader() {
|
||||||
if ( wantFields != (int) num_fields ) {
|
if ( wantFields != (int) num_fields ) {
|
||||||
// we did not find all fields?
|
// we did not find all fields?
|
||||||
// :(
|
// :(
|
||||||
Error("One of the requested fields could not be found in the input data file");
|
Error(Fmt("One of the requested fields could not be found in the input data file. Found %d fields, wanted %d", wantFields, num_fields));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,25 +199,40 @@ LogVal* InputReaderAscii::EntryToVal(string s, FieldMapping field) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case TYPE_TABLE: {
|
case TYPE_TABLE:
|
||||||
// construct a table from entry...
|
case TYPE_VECTOR:
|
||||||
// for the moment assume, that entries are split by ",".
|
// First - common initialization
|
||||||
|
// Then - initialization for table.
|
||||||
if ( s == "-" ) {
|
// Then - initialization for vector.
|
||||||
// empty
|
// Then - common stuff
|
||||||
val->val.set_val.size = 0;
|
{
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// how many entries do we have...
|
// how many entries do we have...
|
||||||
unsigned int length = 1;
|
unsigned int length = 1;
|
||||||
for ( unsigned int i = 0; i < s.size(); i++ )
|
for ( unsigned int i = 0; i < s.size(); i++ )
|
||||||
if ( s[i] == ',') length++;
|
if ( s[i] == ',') length++;
|
||||||
|
|
||||||
unsigned int pos = 0;
|
unsigned int pos = 0;
|
||||||
|
|
||||||
LogVal** lvals = new LogVal* [length];
|
LogVal** lvals = new LogVal* [length];
|
||||||
val->val.set_val.vals = lvals;
|
|
||||||
val->val.set_val.size = length;
|
if ( field.type == TYPE_TABLE ) {
|
||||||
|
// construct a table from entry...
|
||||||
|
// for the moment assume, that entries are split by ",".
|
||||||
|
|
||||||
|
/* Fix support for emtyp tables if ( s == "-" ) {
|
||||||
|
// empty
|
||||||
|
val->val.set_val.size = 0;
|
||||||
|
break;
|
||||||
|
} */
|
||||||
|
|
||||||
|
val->val.set_val.vals = lvals;
|
||||||
|
val->val.set_val.size = length;
|
||||||
|
} else if ( field.type == TYPE_VECTOR ) {
|
||||||
|
val->val.vector_val.vals = lvals;
|
||||||
|
val->val.vector_val.size = length;
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
istringstream splitstream(s);
|
istringstream splitstream(s);
|
||||||
while ( splitstream ) {
|
while ( splitstream ) {
|
||||||
|
@ -232,7 +247,7 @@ LogVal* InputReaderAscii::EntryToVal(string s, FieldMapping field) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
LogVal* newval = EntryToVal(element, field.setType());
|
LogVal* newval = EntryToVal(element, field.subType());
|
||||||
if ( newval == 0 ) {
|
if ( newval == 0 ) {
|
||||||
Error("Error while reading set");
|
Error("Error while reading set");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -243,6 +258,7 @@ LogVal* InputReaderAscii::EntryToVal(string s, FieldMapping field) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if ( pos != length ) {
|
if ( pos != length ) {
|
||||||
Error("Internal error while parsing set: did not find all elements");
|
Error("Internal error while parsing set: did not find all elements");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -12,15 +12,15 @@
|
||||||
struct FieldMapping {
|
struct FieldMapping {
|
||||||
string name;
|
string name;
|
||||||
TypeTag type;
|
TypeTag type;
|
||||||
TypeTag set_type;
|
TypeTag subtype;
|
||||||
int position;
|
int position;
|
||||||
|
|
||||||
FieldMapping(const string& arg_name, const TypeTag& arg_type, int arg_position);
|
FieldMapping(const string& arg_name, const TypeTag& arg_type, int arg_position);
|
||||||
FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_set_type, int arg_position);
|
FieldMapping(const string& arg_name, const TypeTag& arg_type, const TypeTag& arg_subtype, int arg_position);
|
||||||
FieldMapping(const FieldMapping& arg);
|
FieldMapping(const FieldMapping& arg);
|
||||||
FieldMapping() { position = -1; }
|
FieldMapping() { position = -1; }
|
||||||
|
|
||||||
FieldMapping setType();
|
FieldMapping subType();
|
||||||
bool IsEmpty() { return position == -1; }
|
bool IsEmpty() { return position == -1; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -83,16 +83,16 @@ bool LogField::Read(SerializationFormat* fmt)
|
||||||
int t;
|
int t;
|
||||||
int it;
|
int it;
|
||||||
|
|
||||||
bool success = (fmt->Read(&name, "name") && fmt->Read(&t, "type") && fmt->Read(&it, "set_type") );
|
bool success = (fmt->Read(&name, "name") && fmt->Read(&t, "type") && fmt->Read(&it, "subtype") );
|
||||||
type = (TypeTag) t;
|
type = (TypeTag) t;
|
||||||
set_type = (TypeTag) it;
|
subtype = (TypeTag) it;
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogField::Write(SerializationFormat* fmt) const
|
bool LogField::Write(SerializationFormat* fmt) const
|
||||||
{
|
{
|
||||||
return (fmt->Write(name, "name") && fmt->Write((int)type, "type") && fmt->Write((int)set_type, "set_type"));
|
return (fmt->Write(name, "name") && fmt->Write((int)type, "type") && fmt->Write((int)subtype, "subtype"));
|
||||||
}
|
}
|
||||||
|
|
||||||
LogVal::~LogVal()
|
LogVal::~LogVal()
|
||||||
|
|
|
@ -15,12 +15,12 @@ class SerializationFormat;
|
||||||
struct LogField {
|
struct LogField {
|
||||||
string name;
|
string name;
|
||||||
TypeTag type;
|
TypeTag type;
|
||||||
// needed by input framework. otherwise it cannot determine the inner type of a set.
|
// needed by input framework. otherwise it cannot determine the inner type of a set or vector.
|
||||||
TypeTag set_type;
|
TypeTag subtype;
|
||||||
|
|
||||||
LogField() { }
|
LogField() { }
|
||||||
LogField(const LogField& other)
|
LogField(const LogField& other)
|
||||||
: name(other.name), type(other.type), set_type(other.set_type) { }
|
: name(other.name), type(other.type), subtype(other.subtype) { }
|
||||||
|
|
||||||
// (Un-)serialize.
|
// (Un-)serialize.
|
||||||
bool Read(SerializationFormat* fmt);
|
bool Read(SerializationFormat* fmt);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue