/* * _event_marshall * * marshall event packet * * Returns length written to buffer on success, -1 on error */ static int _event_marshall(struct cerebro_event *event, char *buf, unsigned int buflen) { int bufPtrlen, n, c = 0; char *bufPtr; assert(event && buf && buflen >= CEREBRO_EVENT_HEADER_LEN); memset(buf, '\0', buflen); c += Marshall_int32(event->version, buf + c, buflen - c); c += Marshall_u_int32(event->err_code, buf + c, buflen - c); bufPtr = event->nodename; bufPtrlen = sizeof(event->nodename); c += Marshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c); bufPtr = event->event_name; bufPtrlen = sizeof(event->event_name); c += Marshall_buffer(bufPtr, bufPtrlen, buf + c, buflen - c); if ((n = marshall_data(event->event_value_type, event->event_value_len, event->event_value, buf + c, buflen - c, NULL)) < 0) goto cleanup; c += n; return c; cleanup: return -1; }
/* * _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; }