/* Pack values defined by a type string into a buffer. The buffer must have large enough space. */
int type_string_pack(const char *type_str, char *const values[], u8 *data)
/* Pack values defined by a type string into a buffer. The buffer must have large enough space. */
int type_string_pack(const char *type_str, char *const values[], u8 *data)
{
	size_t offset;
	u32 value;
	for (offset = 0; *type_str; type_str++, values++) {
		value = simple_strtoul(values[0], NULL, 0);
		switch (*type_str) {
		case 'b':
			data[offset] = value;
			offset += 1;
			break;
		case 'w':
			put_unaligned_be16(value, data + offset);
			offset += 2;
			break;
		case 'd':
			put_unaligned_be32(value, data + offset);
			offset += 4;
			break;
		default:
			return -1;
		}
	}
	return 0;
}