本文整理汇总了C++中TypedData_Get_Struct函数的典型用法代码示例。如果您正苦于以下问题:C++ TypedData_Get_Struct函数的具体用法?C++ TypedData_Get_Struct怎么用?C++ TypedData_Get_Struct使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TypedData_Get_Struct函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: grpc_rb_call_credentials_init_copy
/* Clones CallCredentials instances.
Gives CallCredentials a consistent implementation of Ruby's object copy/dup
protocol. */
static VALUE grpc_rb_call_credentials_init_copy(VALUE copy, VALUE orig) {
grpc_rb_call_credentials *orig_cred = NULL;
grpc_rb_call_credentials *copy_cred = NULL;
if (copy == orig) {
return copy;
}
/* Raise an error if orig is not a credentials object or a subclass. */
if (TYPE(orig) != T_DATA ||
RDATA(orig)->dfree != (RUBY_DATA_FUNC)grpc_rb_call_credentials_free) {
rb_raise(rb_eTypeError, "not a %s",
rb_obj_classname(grpc_rb_cCallCredentials));
}
TypedData_Get_Struct(orig, grpc_rb_call_credentials,
&grpc_rb_call_credentials_data_type, orig_cred);
TypedData_Get_Struct(copy, grpc_rb_call_credentials,
&grpc_rb_call_credentials_data_type, copy_cred);
/* use ruby's MEMCPY to make a byte-for-byte copy of the credentials
* wrapper object. */
MEMCPY(copy_cred, orig_cred, grpc_rb_call_credentials, 1);
return copy;
}
示例2: Message_eq
/*
* call-seq:
* Message.==(other) => boolean
*
* Performs a deep comparison of this message with another. Messages are equal
* if they have the same type and if each field is equal according to the :==
* method's semantics (a more efficient comparison may actually be done if the
* field is of a primitive type).
*/
VALUE Message_eq(VALUE _self, VALUE _other) {
MessageHeader* self;
MessageHeader* other;
TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
TypedData_Get_Struct(_other, MessageHeader, &Message_type, other);
if (self->descriptor != other->descriptor) {
return Qfalse;
}
return layout_eq(self->descriptor->layout,
Message_data(self),
Message_data(other));
}
示例3: Message_deep_copy
// Internal only; used by Google::Protobuf.deep_copy.
VALUE Message_deep_copy(VALUE _self) {
MessageHeader* self;
TypedData_Get_Struct(_self, MessageHeader, &Message_type, self);
VALUE new_msg = rb_class_new_instance(0, NULL, CLASS_OF(_self));
MessageHeader* new_msg_self;
TypedData_Get_Struct(new_msg, MessageHeader, &Message_type, new_msg_self);
layout_deep_copy(self->descriptor->layout,
Message_data(new_msg_self),
Message_data(self));
return new_msg;
}
示例4: kern_async
// default behavior of async (doesn't accept Symbol)
// call-seq:
// async { }
// async Proc.new
static VALUE
kern_async(int argc, VALUE *argv, VALUE self)
{
VALUE obj;
rb_proc_t *proc;
rb_iseq_t *niseq;
rb_scan_args(argc, argv, "01", &obj);
if (!NIL_P(obj)) {
if (!rb_obj_is_proc(obj)) {
VALUE thread = rb_thread_current();
rb_thread_t * th;
TypedData_Get_Struct(thread, rb_thread_t, RTYPEDDATA_TYPE(thread), th);
if (self == th->vm->top_self) {
return mod_async(CLASS_OF(self), obj);
} else {
rb_raise(rb_eTypeError, "wrong argument type (expected Proc)");
}
}
} else if (rb_block_given_p()) {
obj = rb_block_proc();
} else {
rb_raise(rb_eArgError, "Proc or block is required");
}
proc = (rb_proc_t *)DATA_PTR(obj);
// うーーー
niseq = transform(obj);
proc->block.iseq = niseq;
return obj;
}
示例5: grpc_rb_compression_options_to_hash
/* Provides a ruby hash of GRPC core channel argument key-values that
* correspond to the compression settings on this instance. */
VALUE grpc_rb_compression_options_to_hash(VALUE self) {
grpc_rb_compression_options* wrapper = NULL;
grpc_compression_options* compression_options = NULL;
VALUE channel_arg_hash = rb_hash_new();
VALUE key = Qnil;
VALUE value = Qnil;
TypedData_Get_Struct(self, grpc_rb_compression_options,
&grpc_rb_compression_options_data_type, wrapper);
compression_options = wrapper->wrapped;
/* Add key-value pairs to the new Ruby hash. It can be used
* as GRPC core channel arguments. */
if (compression_options->default_level.is_set) {
key = rb_str_new2(GRPC_COMPRESSION_CHANNEL_DEFAULT_LEVEL);
value = INT2NUM((int)compression_options->default_level.level);
rb_hash_aset(channel_arg_hash, key, value);
}
if (compression_options->default_algorithm.is_set) {
key = rb_str_new2(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM);
value = INT2NUM((int)compression_options->default_algorithm.algorithm);
rb_hash_aset(channel_arg_hash, key, value);
}
key = rb_str_new2(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET);
value = INT2NUM((int)compression_options->enabled_algorithms_bitset);
rb_hash_aset(channel_arg_hash, key, value);
return channel_arg_hash;
}
示例6: grpc_rb_server_add_http2_port
/*
call-seq:
// insecure port
insecure_server = Server.new(cq, {'arg1': 'value1'})
insecure_server.add_http2_port('mydomain:50051', :this_port_is_insecure)
// secure port
server_creds = ...
secure_server = Server.new(cq, {'arg1': 'value1'})
secure_server.add_http_port('mydomain:50051', server_creds)
Adds a http2 port to server */
static VALUE grpc_rb_server_add_http2_port(VALUE self, VALUE port,
VALUE rb_creds) {
grpc_rb_server* s = NULL;
grpc_server_credentials* creds = NULL;
int recvd_port = 0;
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s);
if (s->wrapped == NULL) {
rb_raise(rb_eRuntimeError, "destroyed!");
return Qnil;
} else if (TYPE(rb_creds) == T_SYMBOL) {
if (id_insecure_server != SYM2ID(rb_creds)) {
rb_raise(rb_eTypeError, "bad creds symbol, want :this_port_is_insecure");
return Qnil;
}
recvd_port =
grpc_server_add_insecure_http2_port(s->wrapped, StringValueCStr(port));
if (recvd_port == 0) {
rb_raise(rb_eRuntimeError,
"could not add port %s to server, not sure why",
StringValueCStr(port));
}
} else {
creds = grpc_rb_get_wrapped_server_credentials(rb_creds);
recvd_port = grpc_server_add_secure_http2_port(
s->wrapped, StringValueCStr(port), creds);
if (recvd_port == 0) {
rb_raise(rb_eRuntimeError,
"could not add secure port %s to server, not sure why",
StringValueCStr(port));
}
}
return INT2NUM(recvd_port);
}
示例7: grpc_rb_server_init
/*
call-seq:
server = Server.new({'arg1': 'value1'})
Initializes server instances. */
static VALUE grpc_rb_server_init(VALUE self, VALUE channel_args) {
grpc_completion_queue* cq = NULL;
grpc_rb_server* wrapper = NULL;
grpc_server* srv = NULL;
grpc_channel_args args;
MEMZERO(&args, grpc_channel_args, 1);
grpc_ruby_once_init();
cq = grpc_completion_queue_create_for_pluck(NULL);
TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type,
wrapper);
grpc_rb_hash_convert_to_channel_args(channel_args, &args);
srv = grpc_server_create(&args, NULL);
if (args.args != NULL) {
xfree(args.args); /* Allocated by grpc_rb_hash_convert_to_channel_args */
}
if (srv == NULL) {
rb_raise(rb_eRuntimeError, "could not create a gRPC server, not sure why");
}
grpc_server_register_completion_queue(srv, cq, NULL);
wrapper->wrapped = srv;
wrapper->queue = cq;
return self;
}
示例8: grpc_rb_channel_create_call
/* Create a call given a grpc_channel, in order to call method. The request
is not sent until grpc_call_invoke is called. */
static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, VALUE mask,
VALUE method, VALUE host,
VALUE deadline) {
VALUE res = Qnil;
grpc_rb_channel *wrapper = NULL;
grpc_call *call = NULL;
grpc_call *parent_call = NULL;
grpc_completion_queue *cq = NULL;
int flags = GRPC_PROPAGATE_DEFAULTS;
grpc_slice method_slice;
grpc_slice host_slice;
grpc_slice *host_slice_ptr = NULL;
char *tmp_str = NULL;
if (host != Qnil) {
host_slice =
grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host));
host_slice_ptr = &host_slice;
}
if (mask != Qnil) {
flags = NUM2UINT(mask);
}
if (parent != Qnil) {
parent_call = grpc_rb_get_wrapped_call(parent);
}
cq = grpc_completion_queue_create_for_pluck(NULL);
TypedData_Get_Struct(self, grpc_rb_channel, &grpc_channel_data_type, wrapper);
if (wrapper->bg_wrapped == NULL) {
rb_raise(rb_eRuntimeError, "closed!");
return Qnil;
}
method_slice =
grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method));
call = grpc_channel_create_call(wrapper->bg_wrapped->channel, parent_call,
flags, cq, method_slice, host_slice_ptr,
grpc_rb_time_timeval(deadline,
/* absolute time */ 0),
NULL);
if (call == NULL) {
tmp_str = grpc_slice_to_c_string(method_slice);
rb_raise(rb_eRuntimeError, "cannot create call with method %s", tmp_str);
return Qnil;
}
grpc_slice_unref(method_slice);
if (host_slice_ptr != NULL) {
grpc_slice_unref(host_slice);
}
res = grpc_rb_wrap_call(call, cq);
/* Make this channel an instance attribute of the call so that it is not GCed
* before the call. */
rb_ivar_set(res, id_channel, self);
return res;
}
示例9: Message_decode_json
/*
* call-seq:
* MessageClass.decode_json(data) => message
*
* Decodes the given data (as a string containing bytes in protocol buffers wire
* format) under the interpretration given by this message class's definition
* and returns a message object with the corresponding field values.
*/
VALUE Message_decode_json(VALUE klass, VALUE data) {
VALUE descriptor = rb_ivar_get(klass, descriptor_instancevar_interned);
Descriptor* desc = ruby_to_Descriptor(descriptor);
VALUE msgklass = Descriptor_msgclass(descriptor);
VALUE msg_rb;
MessageHeader* msg;
if (TYPE(data) != T_STRING) {
rb_raise(rb_eArgError, "Expected string for JSON data.");
}
// TODO(cfallin): Check and respect string encoding. If not UTF-8, we need to
// convert, because string handlers pass data directly to message string
// fields.
msg_rb = rb_class_new_instance(0, NULL, msgklass);
TypedData_Get_Struct(msg_rb, MessageHeader, &Message_type, msg);
{
stackenv se;
upb_sink sink;
upb_json_parser* parser;
stackenv_init(&se, "Error occurred during parsing: %s");
upb_sink_reset(&sink, get_fill_handlers(desc), msg);
parser = upb_json_parser_create(&se.env, &sink);
upb_bufsrc_putbuf(RSTRING_PTR(data), RSTRING_LEN(data),
upb_json_parser_input(parser));
stackenv_uninit(&se);
}
return msg_rb;
}
示例10: m_poll
/*
* @overload poll(is_stderr: false, timeout: -1)
* Poll a channel for data to read.
* @since 0.1.0
* @param [Boolean] is_stderr A boolean to select the stderr stream.
* @param [Fixnum] timeout A timeout in milliseconds. A negative value means an
* infinite timeout.
* @return [Fixnum, nil] The number of bytes available for reading. +nil+ if
* timed out.
* @see http://api.libssh.org/stable/group__libssh__channel.html
* ssh_channel_poll_timeout
*/
static VALUE m_poll(int argc, VALUE *argv, VALUE self) {
ChannelHolder *holder;
VALUE opts;
const ID table[] = {id_stderr, id_timeout};
VALUE kwvals[sizeof(table) / sizeof(*table)];
struct nogvl_poll_args args;
TypedData_Get_Struct(self, ChannelHolder, &channel_type, holder);
rb_scan_args(argc, argv, "00:", &opts);
rb_get_kwargs(opts, table, 0, 2, kwvals);
if (kwvals[0] == Qundef) {
args.is_stderr = 0;
} else {
args.is_stderr = RTEST(kwvals[0]) ? 1 : 0;
}
if (kwvals[1] == Qundef) {
args.timeout = -1;
} else {
Check_Type(kwvals[1], T_FIXNUM);
args.timeout = FIX2INT(kwvals[1]);
}
args.channel = holder->channel;
rb_thread_call_without_gvl(nogvl_poll, &args, RUBY_UBF_IO, NULL);
RAISE_IF_ERROR(args.rc);
if (args.rc == SSH_EOF) {
return Qnil;
} else {
return INT2FIX(args.rc);
}
}
示例11: get_imf_jpeg_src_mgr
imf_jpeg_src_mgr_t *
get_imf_jpeg_src_mgr(VALUE obj)
{
imf_jpeg_src_mgr_t *srcmgr;
TypedData_Get_Struct(obj, imf_jpeg_src_mgr_t, &imf_jpeg_src_mgr_data_type, srcmgr);
return srcmgr;
}
示例12: rb_grn_column_cache_array_reference
/*
* @overload [](id)
* @param id [Integer, Groonga::Record] The record ID for the
* column value.
*
* @return [Object] The value for the record ID.
*/
static VALUE
rb_grn_column_cache_array_reference (VALUE self, VALUE rb_id)
{
RbGrnColumnCache *rb_grn_column_cache;
grn_id id;
void *value;
size_t value_size = 0;
TypedData_Get_Struct(self,
RbGrnColumnCache,
&data_type,
rb_grn_column_cache);
if (!rb_grn_column_cache->column_cache) {
return Qnil;
}
id = rb_grn_id_from_ruby_object(rb_id,
rb_grn_column_cache->context,
rb_grn_column_cache->table,
self);
value = grn_column_cache_ref(rb_grn_column_cache->context,
rb_grn_column_cache->column_cache,
id,
&value_size);
rb_grn_context_check(rb_grn_column_cache->context, self);
GRN_TEXT_SET_REF(&(rb_grn_column_cache->buffer),
value,
value_size);
return GRNBULK2RVAL(rb_grn_column_cache->context,
&(rb_grn_column_cache->buffer),
rb_grn_column_cache->range,
self);
}
示例13: line_width
/* call-seq: emitter.line_width
*
* Get the preferred line width.
*/
static VALUE line_width(VALUE self)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
return INT2NUM(emitter->best_width);
}
示例14: indentation
/* call-seq: emitter.indentation
*
* Get the indentation level.
*/
static VALUE indentation(VALUE self)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
return INT2NUM(emitter->best_indent);
}
示例15: canonical
/* call-seq: emitter.canonical
*
* Get the output style, canonical or not.
*/
static VALUE canonical(VALUE self)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
return (emitter->canonical == 0) ? Qfalse : Qtrue;
}