int wrap_marshall_buffer(WRAPPERS_ARGS, const char *val, unsigned int vallen, char *buf, unsigned int buflen) { int rv; assert(file && function); if (!val || !buf) WRAPPERS_ERR_INVALID_PARAMETERS("marshall_buffer"); if ((rv = marshall_buffer(val, vallen, buf, buflen)) <= 0) WRAPPERS_ERR_ERRNO("marshall_buffer"); return rv; }
/* * _event_server_request_marshall * * Marshall contents of a event server request * * Returns length written to buffer on success, -1 on error */ static int _event_server_request_marshall(cerebro_t handle, struct cerebro_event_server_request *req, char *buf, unsigned int buflen) { int n, bufPtrlen, c = 0; char *bufPtr; if (!buf || buflen < CEREBRO_EVENT_SERVER_REQUEST_PACKET_LEN) { CEREBRO_DBG(("invalid parameters")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } memset(buf, '\0', buflen); if ((n = marshall_int32(req->version, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; bufPtr = req->event_name; bufPtrlen = sizeof(req->event_name); if ((n = marshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_buffer")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if ((n = marshall_u_int32(req->flags, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; return c; }
/* * _metric_control_request_marshall * * Marshall contents of a metric control request * * Returns length written to buffer on success, -1 on error */ static int _metric_control_request_marshall(cerebro_t handle, struct cerebro_metric_control_request *req, char *buf, unsigned int buflen) { int n, errnum, bufPtrlen, c = 0; char *bufPtr; if (!buf || buflen < CEREBRO_METRIC_CONTROL_REQUEST_HEADER_LEN) { CEREBRO_DBG(("invalid parameters")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } memset(buf, '\0', buflen); if ((n = marshall_int32(req->version, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if ((n = marshall_int32(req->command, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if ((n = marshall_u_int32(req->flags, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_u_int32")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; bufPtr = req->metric_name; bufPtrlen = sizeof(req->metric_name); if ((n = marshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c)) <= 0) { CEREBRO_DBG(("marshall_buffer")); handle->errnum = CEREBRO_ERR_INTERNAL; return -1; } c += n; if ((n = marshall_data(req->metric_value_type, req->metric_value_len, req->metric_value, buf + c, buflen - c, &errnum)) < 0) { handle->errnum = errnum; return -1; } c += n; return c; }