@@ -305,7 +305,7 @@ bool JContainsString(J *rsp, const char *field, const char *substr)
305305//**************************************************************************/
306306/*!
307307 @brief Add a binary to a Note as a Base64-encoded string.
308- @param req The JSON request object.
308+ @param req The JSON object to which the field should be added
309309 @param fieldName The field to set.
310310 @param binaryData The binary data to set.
311311 @param binaryDataLen The length of the binary string.
@@ -329,6 +329,38 @@ bool JAddBinaryToObject(J *req, const char *fieldName, const void *binaryData, u
329329 return true;
330330}
331331
332+ //**************************************************************************/
333+ /*!
334+ @brief Get binary from an object that is expected to be a Base64-encoded string.
335+ @param rsp The JSON object containing the field.
336+ @param fieldName The field to get data from.
337+ @param retBinaryData The binary data object allocated. (Use standard "free" method to free it.)
338+ @param retBinaryDataLen The length of the binary data.
339+ @returns bool. Whether the binary data was allocated and returned.
340+ */
341+ /**************************************************************************/
342+ bool JGetBinaryFromObject (J * rsp , const char * fieldName , uint8_t * * retBinaryData , uint32_t * retBinaryDataLen )
343+ {
344+
345+ char * payload = JGetString (rsp , fieldName );
346+ if (payload [0 ] == '\0' ) {
347+ return false;
348+ }
349+
350+ // Allocate a buffer for the payload
351+ char * p = (char * ) _Malloc (JB64DecodeLen (payload ));
352+ if (p == NULL ) {
353+ return false;
354+ }
355+ uint32_t actualLen = JB64Decode (p , payload );
356+
357+ // Return the binary to the caller
358+ * retBinaryData = p ;
359+ * retBinaryDataLen = actualLen ;
360+ return true;
361+
362+ }
363+
332364//**************************************************************************/
333365/*!
334366 @brief Get the object name.
0 commit comments