Skip to content

Commit 05fb748

Browse files
committed
kernel/os_mbuf: Add new helpers
This adds new helpers to append and consume mbuf data in a more convinient way
1 parent e776386 commit 05fb748

File tree

1 file changed

+166
-0
lines changed

1 file changed

+166
-0
lines changed

kernel/os/include/os/os_mbuf.h

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,95 @@ struct os_mbuf *os_mbuf_off(const struct os_mbuf *om, int off,
440440
*/
441441
int os_mbuf_copydata(const struct os_mbuf *om, int off, int len, void *dst);
442442

443+
/**
444+
* Extracts data from the beginning of an mbuf into a flat buffer, consuming it in the process.
445+
*
446+
* @param om The mbuf chain to extract data from
447+
* @param len The length of the data to copy
448+
* @param dst The destination buffer to copy into
449+
*
450+
* @return 0 on success;
451+
* -1 if the mbuf does not contain enough data.
452+
*/
453+
int os_mbuf_consume_data(struct os_mbuf *om, int len, void *dst);
454+
455+
/**
456+
* Extracts little endian 32-bit value from the beginning of an mbuf, consuming it in the process.
457+
*
458+
* @param om The mbuf chain to extract data from
459+
* @param dst The destination variable to copy into
460+
*
461+
* @return 0 on success;
462+
* -1 if the mbuf does not contain enough data.
463+
*/
464+
int os_mbuf_consume_le32(struct os_mbuf *om, uint32_t *dst);
465+
466+
/**
467+
* Extracts big endian 32-bit value from the beginning of an mbuf, consuming it in the process.
468+
*
469+
* @param om The mbuf chain to extract data from
470+
* @param dst The destination variable to copy into
471+
*
472+
* @return 0 on success;
473+
* -1 if the mbuf does not contain enough data.
474+
*/
475+
int os_mbuf_consume_be32(struct os_mbuf *om, uint32_t *dst);
476+
477+
/**
478+
* Extracts little endian 24-bit value from the beginning of an mbuf, consuming it in the process.
479+
*
480+
* @param om The mbuf chain to extract data from
481+
* @param dst The destination variable to copy into (stored in a 32-bit container)
482+
*
483+
* @return 0 on success;
484+
* -1 if the mbuf does not contain enough data.
485+
*/
486+
int os_mbuf_consume_le24(struct os_mbuf *om, uint32_t *dst);
487+
488+
/**
489+
* Extracts big endian 24-bit value from the beginning of an mbuf, consuming it in the process.
490+
*
491+
* @param om The mbuf chain to extract data from
492+
* @param dst The destination variable to copy into (stored in a 32-bit container)
493+
*
494+
* @return 0 on success;
495+
* -1 if the mbuf does not contain enough data.
496+
*/
497+
int os_mbuf_consume_be24(struct os_mbuf *om, uint32_t *dst);
498+
499+
/**
500+
* Extracts little endian 16-bit value from the beginning of an mbuf, consuming it in the process.
501+
*
502+
* @param om The mbuf chain to extract data from
503+
* @param dst The destination variable to copy into
504+
*
505+
* @return 0 on success;
506+
* -1 if the mbuf does not contain enough data.
507+
*/
508+
int os_mbuf_consume_le16(struct os_mbuf *om, uint16_t *dst);
509+
510+
/**
511+
* Extracts big endian 16-bit value from the beginning of an mbuf, consuming it in the process.
512+
*
513+
* @param om The mbuf chain to extract data from
514+
* @param dst The destination variable to copy into
515+
*
516+
* @return 0 on success;
517+
* -1 if the mbuf does not contain enough data.
518+
*/
519+
int os_mbuf_consume_be16(struct os_mbuf *om, uint16_t *dst);
520+
521+
/**
522+
* Extracts 8-bit value from the beginning of an mbuf, consuming it in the process.
523+
*
524+
* @param om The mbuf chain to extract data from
525+
* @param dst The destination variable to copy into
526+
*
527+
* @return 0 on success;
528+
* -1 if the mbuf does not contain enough data.
529+
*/
530+
int os_mbuf_consume_u8(struct os_mbuf *om, uint8_t *dst);
531+
443532
/**
444533
* @brief Calculates the length of an mbuf chain.
445534
*
@@ -466,6 +555,83 @@ uint16_t os_mbuf_len(const struct os_mbuf *om);
466555
*/
467556
int os_mbuf_append(struct os_mbuf *om, const void *data, uint16_t len);
468557

558+
/**
559+
* Append 32-bit little endian value onto a mbuf
560+
*
561+
* @param om The mbuf to append the data onto
562+
* @param val 32-bit value to append
563+
*
564+
* @return 0 on success;
565+
* an error code on failure
566+
*/
567+
int os_mbuf_append_le32(struct os_mbuf *om, uint32_t val);
568+
569+
/**
570+
* Append 32-bit big endian value onto a mbuf
571+
*
572+
* @param om The mbuf to append the data onto
573+
* @param val 32-bit value to append
574+
*
575+
* @return 0 on success;
576+
* an error code on failure
577+
*/
578+
int os_mbuf_append_be32(struct os_mbuf *om, uint32_t val);
579+
580+
/**
581+
* Append 24-bit little endian value onto a mbuf
582+
*
583+
* @param om The mbuf to append the data onto
584+
* @param val 24-bit value to append
585+
*
586+
* @return 0 on success;
587+
* an error code on failure
588+
*/
589+
int os_mbuf_append_le24(struct os_mbuf *om, uint32_t val);
590+
591+
/**
592+
* Append 24-bit big endian value onto a mbuf
593+
*
594+
* @param om The mbuf to append the data onto
595+
* @param val 24-bit value to append
596+
*
597+
* @return 0 on success;
598+
* an error code on failure
599+
*/
600+
int os_mbuf_append_be24(struct os_mbuf *om, uint32_t val);
601+
602+
/**
603+
* Append 16-bit little endian value onto a mbuf
604+
*
605+
* @param om The mbuf to append the data onto
606+
* @param val 16-bit value to append
607+
*
608+
* @return 0 on success;
609+
* an error code on failure
610+
*/
611+
int os_mbuf_append_le16(struct os_mbuf *om, uint16_t val);
612+
613+
/**
614+
* Append 16-bit big endian value onto a mbuf
615+
*
616+
* @param om The mbuf to append the data onto
617+
* @param val 16-bit value to append
618+
*
619+
* @return 0 on success;
620+
* an error code on failure
621+
*/
622+
int os_mbuf_append_be16(struct os_mbuf *om, uint16_t val);
623+
624+
/**
625+
* Append 8-bit value onto a mbuf
626+
*
627+
* @param om The mbuf to append the data onto
628+
* @param val 8-bit value to append
629+
*
630+
* @return 0 on success;
631+
* an error code on failure
632+
*/
633+
int os_mbuf_append_u8(struct os_mbuf *om, uint8_t val);
634+
469635
/**
470636
* Reads data from one mbuf and appends it to another. On error, the specified
471637
* data range may be partially appended. Neither mbuf is required to contain

0 commit comments

Comments
 (0)