本文整理汇总了C++中GRPC_SLICE_START_PTR函数的典型用法代码示例。如果您正苦于以下问题:C++ GRPC_SLICE_START_PTR函数的具体用法?C++ GRPC_SLICE_START_PTR怎么用?C++ GRPC_SLICE_START_PTR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GRPC_SLICE_START_PTR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: grpc_run_batch_stack_cleanup
/* grpc_run_batch_stack_cleanup ensures the run_batch_stack is properly
* cleaned up */
static void grpc_run_batch_stack_cleanup(run_batch_stack *st) {
size_t i = 0;
grpc_metadata_array_destroy(&st->send_metadata);
grpc_metadata_array_destroy(&st->send_trailing_metadata);
grpc_metadata_array_destroy(&st->recv_metadata);
grpc_metadata_array_destroy(&st->recv_trailing_metadata);
if (GRPC_SLICE_START_PTR(st->send_status_details) != NULL) {
grpc_slice_unref(st->send_status_details);
}
if (GRPC_SLICE_START_PTR(st->recv_status_details) != NULL) {
grpc_slice_unref(st->recv_status_details);
}
if (st->recv_message != NULL) {
grpc_byte_buffer_destroy(st->recv_message);
}
for (i = 0; i < st->op_num; i++) {
if (st->ops[i].op == GRPC_OP_SEND_MESSAGE) {
grpc_byte_buffer_destroy(st->ops[i].data.send_message.send_message);
}
}
}
示例2: verify_jwt_signature
static int verify_jwt_signature(EVP_PKEY *key, const char *alg,
grpc_slice signature, grpc_slice signed_data) {
EVP_MD_CTX *md_ctx = EVP_MD_CTX_create();
const EVP_MD *md = evp_md_from_alg(alg);
int result = 0;
GPR_ASSERT(md != NULL); /* Checked before. */
if (md_ctx == NULL) {
gpr_log(GPR_ERROR, "Could not create EVP_MD_CTX.");
goto end;
}
if (EVP_DigestVerifyInit(md_ctx, NULL, md, NULL, key) != 1) {
gpr_log(GPR_ERROR, "EVP_DigestVerifyInit failed.");
goto end;
}
if (EVP_DigestVerifyUpdate(md_ctx, GRPC_SLICE_START_PTR(signed_data),
GRPC_SLICE_LENGTH(signed_data)) != 1) {
gpr_log(GPR_ERROR, "EVP_DigestVerifyUpdate failed.");
goto end;
}
if (EVP_DigestVerifyFinal(md_ctx, GRPC_SLICE_START_PTR(signature),
GRPC_SLICE_LENGTH(signature)) != 1) {
gpr_log(GPR_ERROR, "JWT signature verification failed.");
goto end;
}
result = 1;
end:
if (md_ctx != NULL) EVP_MD_CTX_destroy(md_ctx);
return result;
}
示例3: test_load_small_file
static void test_load_small_file(void) {
FILE *tmp = NULL;
grpc_slice slice;
grpc_slice slice_with_null_term;
grpc_error *error;
char *tmp_name;
const char *blah = "blah";
LOG_TEST_NAME("test_load_small_file");
tmp = gpr_tmpfile(prefix, &tmp_name);
GPR_ASSERT(tmp_name != NULL);
GPR_ASSERT(tmp != NULL);
GPR_ASSERT(fwrite(blah, 1, strlen(blah), tmp) == strlen(blah));
fclose(tmp);
error = grpc_load_file(tmp_name, 0, &slice);
GPR_ASSERT(error == GRPC_ERROR_NONE);
GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == strlen(blah));
GPR_ASSERT(!memcmp(GRPC_SLICE_START_PTR(slice), blah, strlen(blah)));
error = grpc_load_file(tmp_name, 1, &slice_with_null_term);
GPR_ASSERT(error == GRPC_ERROR_NONE);
GPR_ASSERT(GRPC_SLICE_LENGTH(slice_with_null_term) == (strlen(blah) + 1));
GPR_ASSERT(strcmp((const char *)GRPC_SLICE_START_PTR(slice_with_null_term),
blah) == 0);
remove(tmp_name);
gpr_free(tmp_name);
grpc_slice_unref(slice);
grpc_slice_unref(slice_with_null_term);
}
示例4: grpc_split_slices
void grpc_split_slices(grpc_slice_split_mode mode, grpc_slice *src_slices,
size_t src_slice_count, grpc_slice **dst_slices,
size_t *dst_slice_count) {
size_t i, j;
size_t length;
switch (mode) {
case GRPC_SLICE_SPLIT_IDENTITY:
*dst_slice_count = src_slice_count;
*dst_slices = gpr_malloc(sizeof(grpc_slice) * src_slice_count);
for (i = 0; i < src_slice_count; i++) {
(*dst_slices)[i] = src_slices[i];
grpc_slice_ref((*dst_slices)[i]);
}
break;
case GRPC_SLICE_SPLIT_MERGE_ALL:
*dst_slice_count = 1;
length = 0;
for (i = 0; i < src_slice_count; i++) {
length += GRPC_SLICE_LENGTH(src_slices[i]);
}
*dst_slices = gpr_malloc(sizeof(grpc_slice));
**dst_slices = grpc_slice_malloc(length);
length = 0;
for (i = 0; i < src_slice_count; i++) {
memcpy(GRPC_SLICE_START_PTR(**dst_slices) + length,
GRPC_SLICE_START_PTR(src_slices[i]),
GRPC_SLICE_LENGTH(src_slices[i]));
length += GRPC_SLICE_LENGTH(src_slices[i]);
}
break;
case GRPC_SLICE_SPLIT_ONE_BYTE:
length = 0;
for (i = 0; i < src_slice_count; i++) {
length += GRPC_SLICE_LENGTH(src_slices[i]);
}
*dst_slice_count = length;
*dst_slices = gpr_malloc(sizeof(grpc_slice) * length);
length = 0;
for (i = 0; i < src_slice_count; i++) {
for (j = 0; j < GRPC_SLICE_LENGTH(src_slices[i]); j++) {
(*dst_slices)[length] = grpc_slice_sub(src_slices[i], j, j + 1);
length++;
}
}
break;
}
}
示例5: zlib_body
static int zlib_body(z_stream* zs, grpc_slice_buffer* input,
grpc_slice_buffer* output,
int (*flate)(z_stream* zs, int flush)) {
int r;
int flush;
size_t i;
grpc_slice outbuf = grpc_slice_malloc(OUTPUT_BLOCK_SIZE);
const uInt uint_max = ~(uInt)0;
GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max);
zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf);
zs->next_out = GRPC_SLICE_START_PTR(outbuf);
flush = Z_NO_FLUSH;
for (i = 0; i < input->count; i++) {
if (i == input->count - 1) flush = Z_FINISH;
GPR_ASSERT(GRPC_SLICE_LENGTH(input->slices[i]) <= uint_max);
zs->avail_in = (uInt)GRPC_SLICE_LENGTH(input->slices[i]);
zs->next_in = GRPC_SLICE_START_PTR(input->slices[i]);
do {
if (zs->avail_out == 0) {
grpc_slice_buffer_add_indexed(output, outbuf);
outbuf = grpc_slice_malloc(OUTPUT_BLOCK_SIZE);
GPR_ASSERT(GRPC_SLICE_LENGTH(outbuf) <= uint_max);
zs->avail_out = (uInt)GRPC_SLICE_LENGTH(outbuf);
zs->next_out = GRPC_SLICE_START_PTR(outbuf);
}
r = flate(zs, flush);
if (r < 0 && r != Z_BUF_ERROR /* not fatal */) {
gpr_log(GPR_INFO, "zlib error (%d)", r);
goto error;
}
} while (zs->avail_out == 0);
if (zs->avail_in) {
gpr_log(GPR_INFO, "zlib: not all input consumed");
goto error;
}
}
GPR_ASSERT(outbuf.refcount);
outbuf.data.refcounted.length -= zs->avail_out;
grpc_slice_buffer_add_indexed(output, outbuf);
return 1;
error:
grpc_slice_unref(outbuf);
return 0;
}
示例6: grpc_chttp2_window_update_create
grpc_slice grpc_chttp2_window_update_create(
uint32_t id, uint32_t window_update, grpc_transport_one_way_stats *stats) {
static const size_t frame_size = 13;
grpc_slice slice = GRPC_SLICE_MALLOC(frame_size);
stats->header_bytes += frame_size;
uint8_t *p = GRPC_SLICE_START_PTR(slice);
GPR_ASSERT(window_update);
*p++ = 0;
*p++ = 0;
*p++ = 4;
*p++ = GRPC_CHTTP2_FRAME_WINDOW_UPDATE;
*p++ = 0;
*p++ = (uint8_t)(id >> 24);
*p++ = (uint8_t)(id >> 16);
*p++ = (uint8_t)(id >> 8);
*p++ = (uint8_t)(id);
*p++ = (uint8_t)(window_update >> 24);
*p++ = (uint8_t)(window_update >> 16);
*p++ = (uint8_t)(window_update >> 8);
*p++ = (uint8_t)(window_update);
return slice;
}
示例7: GRPC_SLICE_START_PTR
grpc_error *grpc_chttp2_ping_parser_parse(grpc_exec_ctx *exec_ctx, void *parser,
grpc_chttp2_transport *t,
grpc_chttp2_stream *s,
grpc_slice slice, int is_last) {
uint8_t *const beg = GRPC_SLICE_START_PTR(slice);
uint8_t *const end = GRPC_SLICE_END_PTR(slice);
uint8_t *cur = beg;
grpc_chttp2_ping_parser *p = parser;
while (p->byte != 8 && cur != end) {
p->opaque_8bytes[p->byte] = *cur;
cur++;
p->byte++;
}
if (p->byte == 8) {
GPR_ASSERT(is_last);
if (p->is_ack) {
grpc_chttp2_ack_ping(exec_ctx, t, p->opaque_8bytes);
} else {
grpc_slice_buffer_add(&t->qbuf,
grpc_chttp2_ping_create(1, p->opaque_8bytes));
grpc_chttp2_initiate_write(exec_ctx, t, false, "ping response");
}
}
return GRPC_ERROR_NONE;
}
示例8: grpc_empty_slice
/* Takes ownership of creds_path if not NULL. */
static grpc_error *create_default_creds_from_path(
grpc_exec_ctx *exec_ctx, char *creds_path, grpc_call_credentials **creds) {
grpc_json *json = NULL;
grpc_auth_json_key key;
grpc_auth_refresh_token token;
grpc_call_credentials *result = NULL;
grpc_slice creds_data = grpc_empty_slice();
grpc_error *error = GRPC_ERROR_NONE;
if (creds_path == NULL) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("creds_path unset");
goto end;
}
error = grpc_load_file(creds_path, 0, &creds_data);
if (error != GRPC_ERROR_NONE) {
goto end;
}
json = grpc_json_parse_string_with_len(
(char *)GRPC_SLICE_START_PTR(creds_data), GRPC_SLICE_LENGTH(creds_data));
if (json == NULL) {
error = grpc_error_set_str(
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Failed to parse JSON"),
GRPC_ERROR_STR_RAW_BYTES, grpc_slice_ref_internal(creds_data));
goto end;
}
/* First, try an auth json key. */
key = grpc_auth_json_key_create_from_json(json);
if (grpc_auth_json_key_is_valid(&key)) {
result =
grpc_service_account_jwt_access_credentials_create_from_auth_json_key(
exec_ctx, key, grpc_max_auth_token_lifetime());
if (result == NULL) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"grpc_service_account_jwt_access_credentials_create_from_auth_json_"
"key failed");
}
goto end;
}
/* Then try a refresh token if the auth json key was invalid. */
token = grpc_auth_refresh_token_create_from_json(json);
if (grpc_auth_refresh_token_is_valid(&token)) {
result =
grpc_refresh_token_credentials_create_from_auth_refresh_token(token);
if (result == NULL) {
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
"grpc_refresh_token_credentials_create_from_auth_refresh_token "
"failed");
}
goto end;
}
end:
GPR_ASSERT((result == NULL) + (error == GRPC_ERROR_NONE) == 1);
if (creds_path != NULL) gpr_free(creds_path);
grpc_slice_unref_internal(exec_ctx, creds_data);
if (json != NULL) grpc_json_destroy(json);
*creds = result;
return error;
}
示例9: test_load_big_file
static void test_load_big_file(void) {
FILE *tmp = NULL;
grpc_slice slice;
grpc_error *error;
char *tmp_name;
static const size_t buffer_size = 124631;
unsigned char *buffer = gpr_malloc(buffer_size);
unsigned char *current;
size_t i;
LOG_TEST_NAME("test_load_big_file");
memset(buffer, 42, buffer_size);
tmp = gpr_tmpfile(prefix, &tmp_name);
GPR_ASSERT(tmp != NULL);
GPR_ASSERT(tmp_name != NULL);
GPR_ASSERT(fwrite(buffer, 1, buffer_size, tmp) == buffer_size);
fclose(tmp);
error = grpc_load_file(tmp_name, 0, &slice);
GPR_ASSERT(error == GRPC_ERROR_NONE);
GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == buffer_size);
current = GRPC_SLICE_START_PTR(slice);
for (i = 0; i < buffer_size; i++) {
GPR_ASSERT(current[i] == 42);
}
remove(tmp_name);
gpr_free(tmp_name);
grpc_slice_unref(slice);
gpr_free(buffer);
}
示例10: flush_write_staging_buffer
static void flush_write_staging_buffer(secure_endpoint *ep, uint8_t **cur,
uint8_t **end) {
grpc_slice_buffer_add(&ep->output_buffer, ep->write_staging_buffer);
ep->write_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE);
*cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer);
*end = GRPC_SLICE_END_PTR(ep->write_staging_buffer);
}
示例11: grpcsharp_batch_context_recv_status_on_client_details
GPR_EXPORT const char* GPR_CALLTYPE
grpcsharp_batch_context_recv_status_on_client_details(
const grpcsharp_batch_context* ctx, size_t* details_length) {
*details_length =
GRPC_SLICE_LENGTH(ctx->recv_status_on_client.status_details);
return (char*)GRPC_SLICE_START_PTR(ctx->recv_status_on_client.status_details);
}
示例12: create_jwt
void create_jwt(const char *json_key_file_path, const char *service_url,
const char *scope) {
grpc_auth_json_key key;
char *jwt;
grpc_slice json_key_data;
GPR_ASSERT(GRPC_LOG_IF_ERROR(
"load_file", grpc_load_file(json_key_file_path, 1, &json_key_data)));
key = grpc_auth_json_key_create_from_string(
(const char *)GRPC_SLICE_START_PTR(json_key_data));
grpc_slice_unref(json_key_data);
if (!grpc_auth_json_key_is_valid(&key)) {
fprintf(stderr, "Could not parse json key.\n");
exit(1);
}
jwt = grpc_jwt_encode_and_sign(
&key, service_url == NULL ? GRPC_JWT_OAUTH2_AUDIENCE : service_url,
grpc_max_auth_token_lifetime(), scope);
grpc_auth_json_key_destruct(&key);
if (jwt == NULL) {
fprintf(stderr, "Could not create JWT.\n");
exit(1);
}
fprintf(stdout, "%s\n", jwt);
gpr_free(jwt);
}
示例13: grpc_slice_rchr
int grpc_slice_rchr(grpc_slice s, char c) {
const char *b = (const char *)GRPC_SLICE_START_PTR(s);
int i;
for (i = (int)GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--)
;
return i;
}
示例14: grpcsharp_batch_context_recv_message_next_slice_peek
/*
* Gets the next slice from recv_message byte buffer.
* Returns 1 if a slice was get successfully, 0 if there are no more slices to
* read. Set slice_len to the length of the slice and the slice_data_ptr to
* point to slice's data. Caller must ensure that the byte buffer being read
* from stays alive as long as the data of the slice are being accessed
* (grpc_byte_buffer_reader_peek method is used internally)
*
* Remarks:
* Slices can only be iterated once.
* Initializes recv_message_buffer_reader if it was not initialized yet.
*/
GPR_EXPORT int GPR_CALLTYPE
grpcsharp_batch_context_recv_message_next_slice_peek(
grpcsharp_batch_context* ctx, size_t* slice_len, uint8_t** slice_data_ptr) {
*slice_len = 0;
*slice_data_ptr = NULL;
if (!ctx->recv_message) {
return 0;
}
if (!ctx->recv_message_reader) {
ctx->recv_message_reader = &ctx->reserved_recv_message_reader;
GPR_ASSERT(grpc_byte_buffer_reader_init(ctx->recv_message_reader,
ctx->recv_message));
}
grpc_slice* slice_ptr;
if (!grpc_byte_buffer_reader_peek(ctx->recv_message_reader, &slice_ptr)) {
return 0;
}
/* recv_message buffer must not be deleted before all the data is read */
*slice_len = GRPC_SLICE_LENGTH(*slice_ptr);
*slice_data_ptr = GRPC_SLICE_START_PTR(*slice_ptr);
return 1;
}
示例15: flush_read_staging_buffer
static void flush_read_staging_buffer(secure_endpoint *ep, uint8_t **cur,
uint8_t **end) {
grpc_slice_buffer_add(ep->read_buffer, ep->read_staging_buffer);
ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
*cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer);
*end = GRPC_SLICE_END_PTR(ep->read_staging_buffer);
}