Aw unzip
Jump to navigation
Jump to search
Minimum requirements | ||
---|---|---|
Added in version 4.2 | ||
SDK | build 70 |
int aw_unzip (unsigned char *data_out, unsigned int *len_out, unsigned char *data_in, unsigned int len_in);
Description
Decompresses the input data into the output buffer.
Callback
None (returns immediately)
Notes
This is a wrapper for uncompress which is part of the zlib compression library.
Arguments
- data_out
- Output buffer.
- len_out
- On entry, it must point to the total size of the output buffer, which must be large enough to hold the entire uncompressed data. On return, it points to the actual size of the uncompressed data, provided that the call was successful.
- data_in
- Input buffer.
- len_in
- Length of the input data.
Argument attributes
None
Return values
- RC_SUCCESS
- RC_INVALID_ARGUMENT
- A pointer was NULL, or a length was 0.
- RC_Z_DATA_ERROR
- Input data was corrupted.
- RC_Z_MEM_ERROR
- Memory could not be allocated for processing.
- RC_Z_BUF_ERROR
- Not enough room in the output buffer.
Returned attributes
None
Usage
Request and keep up to date with the custom avatar definition of neighbors.
void handle_cav (int rc) { unsigned char *in; unsigned int len_in; unsigned char out[40940]; unsigned int len_out; unsigned int i; if (rc != RC_SUCCESS) { printf ("Unable to query custom avatar (reason %d)\n", rc); return; } printf ("Received custom avatar of session #%d (citizen #%d)\n", aw_int (AW_CAV_SESSION), aw_int (AW_CAV_CITIZEN)); in = (unsigned char*)aw_data (AW_CAV_DEFINITION, &len_in); len_out = sizeof (out); rc = aw_unzip (out, &len_out, in, len_in); if (rc != RC_SUCCESS) { printf ("Unable to uncompress data (%d)\n", rc); return; } out[len_out] = '\0'; printf ("Compressed data: "); for (i = 0; i < len_in; i++) printf ("%2.2x", in[i]); printf ("\n"); printf ("Uncompressed data: \"%s\"\n", out); printf ("Data was uncompressed from %d to %d bytes\n", len_in, len_out); } void handle_avatar_add (void) { /* request custom avatar of neighbors who use one */ if (aw_int (AW_AVATAR_TYPE) == AW_CUSTOM_AVATAR) aw_cav_request (aw_int (AW_AVATAR_CITIZEN), aw_int (AW_AVATAR_SESSION)); } void handle_avatar_change (void) { /* request custom avatar of neighbors who change to one from a different avatar type */ /* if (aw_int (AW_AVATAR_TYPE) == AW_CUSTOM_AVATAR) if (_previous_avatar_type_of (aw_int (AW_AVATAR_SESSION) != AW_CUSTOM_AVATAR) aw_cav_request (aw_int (AW_AVATAR_CITIZEN), aw_int (AW_AVATAR_SESSION)); */ } void handle_cav_definition_change (void) { /* request custom avatar of a neighbor when it gets changed */ aw_cav_request (aw_int (AW_CAV_CITIZEN), aw_int (AW_CAV_SESSION)); } aw_callback_set (AW_CALLBACK_CAV, handle_cav); aw_event_set (AW_EVENT_AVATAR_ADD, handle_avatar_add); aw_event_set (AW_EVENT_AVATAR_CHANGE, handle_avatar_change); aw_event_set (AW_EVENT_CAV_DEFINITION_CHANGE, handle_cav_definition_change);