openusb_parse_data

OpenUSB Developers Guide
Prev |  | Next

# `openusb_parse_data`

## Name

`openusb_parse_data` -- Unpack arbitrary little endian raw data

## Synopsis

``void openusb_parse_data`(char *format, uint8_t *data, uint32_t datalen, void *structure, uint32_t structlen, uint32_t *count);`

## Parameters

`format` A character string indicating the format that application requires. Character 'b' represents one byte, 'w' for word and 'd' for dword(4 bytes). Specially, character '.' indicates skipping one byte of source data.

`data` Little endian raw data that will be parsed.

`datalen` Length of data.

`structure` Address of the returned structure where the unpacked data will be stored

`structlen` Length of structure.

`count` Number of bytes parsed.

## Description

`openusb_parse_data()` can parse little endian raw data and convert it to structured data. It's basically used to parse USB descriptors.

For exampe, to parse a descriptor such as:

        	struct test_descr {
        		uint8_t		a;
        		uint16_t	b;
        		uint8_t		c;
        		uint32_t	d;
        	};

The application would call:

            	rv = openusb_parse_data("bwbd", buffer, sizeof (buffer), (void *)&descr,
        		sizeof (descr), &count);

## Return Value

OPENUSB_SUCCESS - Parse data successfully.

OPENUSB_PARSE_ERROR - Error happened during parsing.

OPENUSB_BADARG - Invalid argument. `Format, data, structure or count` is NULL pointer.

## See Also

Prev | Home | Next
`openusb_get_raw_desc, openusb_free_raw_desc, openusb_parse_device_desc, openusb_parse_config_desc, openusb_parse_interface_desc, openusb_parse_endpoint_desc` | Up | USB Data Transfer