Created
August 3, 2012 10:13
-
-
Save astarasikov/3246437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define RPC_PACK_RAW(buffer, idx, pvalue, size) do {\ | |
if (idx + size >= RPC_PAYLOAD_MAX) {\ | |
RPC_ERROR("data too large");\ | |
goto fail; \ | |
}\ | |
memcpy(buffer + idx, pvalue, size);\ | |
idx += size;\ | |
} while (0) | |
#define RPC_PACK(buffer, idx, value) \ | |
RPC_PACK_RAW(buffer, idx, &value, sizeof(value)) | |
#define RPC_PACK_S(buffer, idx, str) do {\ | |
size_t __len = strlen(str) + 1; \ | |
RPC_PACK_RAW(buffer, idx, str, __len); \ | |
} while (0) | |
#define RPC_UNPACK_RAW(buffer, idx, pvalue, size) do {\ | |
if (idx + size >= RPC_PAYLOAD_MAX) {\ | |
RPC_ERROR("data too large");\ | |
goto fail;\ | |
}\ | |
memcpy(pvalue, buffer + idx, size);\ | |
idx += size;\ | |
} while (0) | |
#define RPC_UNPACK(buffer, idx, value) \ | |
RPC_UNPACK_RAW(buffer, idx, &value, sizeof(value)) | |
#define RPC_UNPACK_S(buffer, idx, str) do {\ | |
size_t __len = strlen(buffer + idx) + 1;\ | |
RPC_UNPACK_RAW(buffer, idx, str, __len);\ | |
} while (0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment