Message ID | 20241122074909.2719533-1-amusil@redhat.com |
---|---|
State | Superseded |
Headers | show |
Series | [ovs-dev] ofpbuf: Add helper method to truncate the buffer. | expand |
Context | Check | Description |
---|---|---|
ovsrobot/apply-robot | success | apply and check: success |
ovsrobot/github-robot-_Build_and_Test | success | github build: passed |
On Fri, Nov 22, 2024 at 2:49 AM Ales Musil <amusil@redhat.com> 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 <amusil@redhat.com> > --- > include/openvswitch/ofpbuf.h | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/include/openvswitch/ofpbuf.h b/include/openvswitch/ofpbuf.h > index 1fc4a3a7f..bac574548 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; > } > Hello Ales, Especially given that it's not currently used in code, it would be good to have a comment here explaining the use. > +static inline void ofpbuf_truncate(struct ofpbuf *b, size_t size) > +{ > + ovs_assert(b->size >= size); > + b->data = (uint8_t *) b->data - size; I may misunderstand this, but the function is supposed to be removing bytes from the end of the buffer? Then why is b->data modified? Cheers, M > + b->size = b->size - size; > +} > + > #ifdef __cplusplus > } > #endif > -- > 2.47.0 > > _______________________________________________ > dev mailing list > dev@openvswitch.org > https://mail.openvswitch.org/mailman/listinfo/ovs-dev >
On Mon, Dec 2, 2024 at 6:46 PM Mike Pattrick <mkp@redhat.com> wrote: > On Fri, Nov 22, 2024 at 2:49 AM Ales Musil <amusil@redhat.com> 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 <amusil@redhat.com> > > --- > > include/openvswitch/ofpbuf.h | 7 +++++++ > > 1 file changed, 7 insertions(+) > > > > diff --git a/include/openvswitch/ofpbuf.h b/include/openvswitch/ofpbuf.h > > index 1fc4a3a7f..bac574548 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; > > } > > > > Hello Ales, > > Especially given that it's not currently used in code, it would be > good to have a comment here explaining the use. > Hi Mike, yeah I can add a comment to explain what it does. > > +static inline void ofpbuf_truncate(struct ofpbuf *b, size_t size) > > +{ > > + ovs_assert(b->size >= size); > > + b->data = (uint8_t *) b->data - size; > > > I may misunderstand this, but the function is supposed to be removing > bytes from the end of the buffer? Then why is b->data modified? > > You are right that's completely wrong. I'll send v2. > > Cheers, > M > > > + b->size = b->size - size; > > +} > > + > > #ifdef __cplusplus > > } > > #endif > > -- > > 2.47.0 > > > > _______________________________________________ > > dev mailing list > > dev@openvswitch.org > > https://mail.openvswitch.org/mailman/listinfo/ovs-dev > > > > Thanks, Ales
diff --git a/include/openvswitch/ofpbuf.h b/include/openvswitch/ofpbuf.h index 1fc4a3a7f..bac574548 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; } +static inline void ofpbuf_truncate(struct ofpbuf *b, size_t size) +{ + ovs_assert(b->size >= size); + b->data = (uint8_t *) b->data - size; + b->size = b->size - size; +} + #ifdef __cplusplus } #endif
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 <amusil@redhat.com> --- include/openvswitch/ofpbuf.h | 7 +++++++ 1 file changed, 7 insertions(+)