trivial: Add helper function for chunking a GBytes

This commit is contained in:
Richard Hughes 2018-05-23 20:47:04 +01:00
parent b04a8778e9
commit ba4ec1a25f
2 changed files with 28 additions and 0 deletions

View File

@ -183,3 +183,27 @@ dfu_chunked_new (const guint8 *data,
} }
return segments; return segments;
} }
/**
* dfu_chunked_new_from_bytes:
* @blob: a #GBytes
* @addr_start: the hardware address offset, or 0
* @page_sz: the hardware page size, or 0
* @packet_sz: the transfer size, or 0
*
* Chunks a linear blob of memory into packets, ensuring each packet does not
* cross a package boundary and is less that a specific transfer size.
*
* Return value: (element-type DfuChunkedPacket): array of packets
**/
GPtrArray *
dfu_chunked_new_from_bytes (GBytes *blob,
guint32 addr_start,
guint32 page_sz,
guint32 packet_sz)
{
gsize sz;
const guint8 *data = g_bytes_get_data (blob, &sz);
return dfu_chunked_new (data, (guint32) sz,
addr_start, page_sz, packet_sz);
}

View File

@ -48,6 +48,10 @@ GPtrArray *dfu_chunked_new (const guint8 *data,
guint32 addr_start, guint32 addr_start,
guint32 page_sz, guint32 page_sz,
guint32 packet_sz); guint32 packet_sz);
GPtrArray *dfu_chunked_new_from_bytes (GBytes *blob,
guint32 addr_start,
guint32 page_sz,
guint32 packet_sz);
G_END_DECLS G_END_DECLS