Skip to content

Instantly share code, notes, and snippets.

@astarasikov
Created August 3, 2012 10:13
Show Gist options
  • Save astarasikov/3246437 to your computer and use it in GitHub Desktop.
Save astarasikov/3246437 to your computer and use it in GitHub Desktop.
#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