[Bro] appending to a vector

Seth Hall seth at icir.org
Wed Jun 19 09:42:26 PDT 2013


On Jun 19, 2013, at 12:14 PM, David Mandelberg <david at mandelberg.org> wrote:

> What's the recommended way to append to a vector?

Many (most?) of us strongly dislike vectors in Bro.  It's likely something that will be improved in the next couple of releases if I had to make a guess. :)

> The documentation 
> says vectors are like tables, so I tried the below code, but it gives 
> some errors.
> 
> const foo: vector of double = vector() &redef;
> 
> redef foo += {
>     [|foo|] = 42.0
> };


Hm, I don't know about this if you add more than a single element at a time because the length wouldn't be right.

If you are using our git master you can use a new construct that was recently added for creating types containers.

type DoubleVector: vector of double;
const foo = DoubleVector([0] = 42.0, [1] = 43.0, [2] = 44.0);

Generally though you're going to run into weird poorly defined edge cases like this with vectors, when they were added to Bro it was in a sort of ad-hoc fashion and not fully thought out except for the use case in which they were originally used. (the code I gave above may not even work, I haven't tested it!)

  .Seth

--
Seth Hall
International Computer Science Institute
(Bro) because everyone has a network
http://www.bro.org/





More information about the Bro mailing list