mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Add &default_insert attribute for tables
This is based on the discussion in zeek/zeek#2668. Using &default with tables can be confusing as the default value is not inserted. The following example prints an empty table at the end even new Service records was instantiated. type Service: record { occurrences: count &default=0; last_seen: time &default=network_time(); }; global services: table[string] of Service &default=Service(); event zeek_init() { services["http"]$occurrences += 1; services["http"]$last_seen = network_time(); print services; } Changing above &default to &default_insert will insert the newly created default value upon a missed lookup and act less surprising. Other examples that caused confusion previously revolved around table of sets or table of vectors and `add` or `+=` not working as expected. tbl_of_vector["http"] += 1 add tbl_of_set["http"][1];
This commit is contained in:
parent
81ce83590d
commit
431767d04b
22 changed files with 230 additions and 13 deletions
|
@ -0,0 +1,2 @@
|
|||
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
|
||||
error in <...>/table-default-insert-errors.zeek, line 2: &default and &default_insert cannot be used together (&default_insert=a, &default=b)
|
Loading…
Add table
Add a link
Reference in a new issue