On 12/12/24 09:02, Ales Musil wrote: > > > On Wed, Dec 11, 2024 at 6:28 PM Ilya Maximets <[email protected] > <mailto:[email protected]>> wrote: > > On 12/3/24 13:21, Ales Musil wrote: > > Add helper to truncate the buffer to certain size which might be > > useful if some earlier part of the buffer can be reused multiple > > times without copying the whole buffer. > > > > Signed-off-by: Ales Musil <[email protected] <mailto:[email protected]>> > > --- > > v2: Rebase on top of current main. > > Add comment what the function does and test case. > > Fix the wrong move of data pointer. > > --- > > include/openvswitch/ofpbuf.h | 7 +++++++ > > tests/test-ofpbuf.c | 9 +++++++++ > > 2 files changed, 16 insertions(+) > > > > diff --git a/include/openvswitch/ofpbuf.h b/include/openvswitch/ofpbuf.h > > index 1fc4a3a7f..f16e3d697 100644 > > --- a/include/openvswitch/ofpbuf.h > > +++ b/include/openvswitch/ofpbuf.h > > @@ -292,6 +292,13 @@ static inline bool ofpbuf_oversized(const struct > ofpbuf *ofpacts) > > return (char *)ofpbuf_tail(ofpacts) - (char *)ofpacts->header > > UINT16_MAX; > > } > > > > +/* Removes 'size' bytes from the tail end of 'b'. */ > > +static inline void ofpbuf_truncate(struct ofpbuf *b, size_t size) > > +{ > > + ovs_assert(b->size >= size); > > + b->size = b->size - size; > > +} > > Hi, Ales. I'm just curious if you actually need a 'truncate by' > behavior as opposed to 'truncate to'? Most of other stuff that > involves truncation in OVS uses 'truncate to' semantics, i.e. you > store the size, then do something, then truncate to the original > size. For example, the truncation of a packet on output or a > file truncation with ftruncate, etc. > > Would the 'truncate to' semantic fit better in your use case? > > > Hi Ilya, > > either of those would work and I don't have a strong preference. If you feel > like > I should change this to the 'truncate to' semantics I will send v3 that does > exactly that.
I think, "truncate to" would better align with other APIs, so let's do that. With that, you may also actually use it in OVS in ofpacts_parse() function. Best regards, Ilya Maximets. > > > > Best regards, Ilya Maximets. > > > Thanks, > Ales _______________________________________________ dev mailing list [email protected] https://mail.openvswitch.org/mailman/listinfo/ovs-dev
