kgiusti commented on a change in pull request #558: Dispatch 1403
URL: https://github.com/apache/qpid-dispatch/pull/558#discussion_r319113438
##########
File path: include/qpid/dispatch/buffer.h
##########
@@ -176,6 +178,161 @@ static inline unsigned char *qd_buffer_at(const
qd_buffer_t *buf, size_t len)
}
+//
+// API for handling data that spans one or more buffers
+//
+
+/**
+ * Represents a span of data within a buffer chain.
+ * The buffer and cursor fields are guaranteed to be !null if length > 0.
+ */
+typedef struct qd_buffered_data_t {
+ qd_buffer_t *buffer; // head of buffer chain
+ unsigned char *cursor; // start of first byte of data in 'buffer'
+ size_t length; // total number of bytes of data in chain
+} qd_buffered_data_t;
+
+
+/**
+ * Allocate a buffered data instance from the pool
+ * @param head Start of buffered data
+ * @param offset To start of data from qd_buffer_base(head)
+ * @param length Number of bytes in field
+ */
+qd_buffered_data_t *qd_buffered_data(qd_buffer_t *head, size_t offset, size_t
length);
+
+
+/**
+ * Free an allocated qd_buffer_data_t
+ * @param bdata A pointer to the qd_buffered_data_t to free. Note that the
+ * underlying buffer chain is not freed.
+ */
+void qd_buffered_data_free(qd_buffered_data_t *bdata);
+
+
+/**
+ * Copy n bytes of data from start of buffer chain (cursor) into buffer.
+ * Advance the cursor past the last byte copied.
+ * @param bdata Buffered data
+ * @param buffer Destination for copied bytes
+ * @param n Number of bytes to copy
+ * @return Number of bytes actually copied, which may be < n if length of
+ * buffered data is shorter than n.
+ */
+static inline size_t qd_buffered_data_copy(qd_buffered_data_t *bdata, unsigned
char *buffer, size_t n)
+{ return 0; }
+
+/**
+ * Compare the first n bytes in the buffered data to contents of buffer.
+ * Advance the cursor past the last byte copied. If matched advance the
cursor past the nth byte.
+ * @param bdata Buffered data
+ * @param buffer Data to compare
+ * @param n Number of bytes to compare
+ * @return true if match.
+ */
+static inline bool qd_buffered_data_equal(qd_buffered_data_t *bdata, const
unsigned char *buffer, size_t n)
+{ return true; }
+
+/**
+ * Move the cursor n bytes forward (e.g. skip the first n bytes).
+ * @param bdata Buffered data
+ * @param n Number of bytes to skip
+ * @return Actual number of bytes skipped. May be < n if buffered data is
shorter than n.
+ */
+static inline bool qd_buffered_data_advance(qd_buffered_data_t *bdata, const
unsigned char *buffer, size_t n)
+{ return true; }
+
+
+/**
+ * Extract the unsigned byte at the current cursor, and advance to the next
byte
+ * @param bdata Buffered data
+ * @param octet Location to write the unsigned byte
+ * @return true if octet set, false if no data available (length == 0)
+ */
+static inline bool qd_buffered_data_octet(qd_buffered_data_t *bdata, uint8_t
*octet)
+{ return true; }
+
+
+/**
+ * Extract the unsigned 32 bit integer at the current cursor and advance past
it.
+ * Converts the result into host byte order.
+ * @param bdata Buffered data
+ * @param uinteger32 Location to write the integer
+ * @return true on success, false if length < 4 octets (cursor is not moved)
+ */
+static inline bool qd_buffered_data_uint32(qd_buffered_data_t *bdata, uint32_t
*uinteger32)
+{ return true; }
+
+
+//////////////////////////////////////
+// API for processing buffered data
+//////////////////////////////////////
+
+
+/**
+ * Callback provided by the caller for processing data in a buffer chain.
+ * @param context Caller provided handle
+ * @param data Start of data (contiguous)
+ * @param length Number of contiguous bytes starting at data
+ * @return The number of bytes processed by the handler:
+ * If != to length:
+ * if < 0 a non-recoverable error occurred. Processing is aborted.
+ * if (> 0 && < length) handler is done and no further callbacks will be
made
Review comment:
Should be "if (>= 0 && " ....
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]