Class: Capnp::Struct
- Inherits:
-
Object
show all
- Extended by:
- T::Helpers, T::Sig
- Defined in:
- lib/capnp/runtime/struct.rb
Direct Known Subclasses
Schema::Annotation, Schema::Brand, Schema::Brand::Binding, Schema::Brand::Scope, Schema::CapnpVersion, Schema::CodeGeneratorRequest, Schema::CodeGeneratorRequest::RequestedFile, Schema::CodeGeneratorRequest::RequestedFile::Import, Schema::Enumerant, Schema::Field, Schema::Field::GroupGroup, Schema::Field::GroupOrdinal, Schema::Field::GroupSlot, Schema::Method, Schema::Node, Schema::Node::GroupAnnotation, Schema::Node::GroupConst, Schema::Node::GroupEnum, Schema::Node::GroupInterface, Schema::Node::GroupStruct, Schema::Node::NestedNode, Schema::Node::Parameter, Schema::Node::SourceInfo, Schema::Node::SourceInfo::Member, Schema::Superclass, Schema::Type, Schema::Type::GroupAnyPointer, Schema::Type::GroupAnyPointer::GroupImplicitMethodParameter, Schema::Type::GroupAnyPointer::GroupParameter, Schema::Type::GroupAnyPointer::GroupUnconstrained, Schema::Type::GroupEnum, Schema::Type::GroupInterface, Schema::Type::GroupList, Schema::Type::GroupStruct, Schema::Value
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data, data_size, pointers, pointers_size) ⇒ Struct
Returns a new instance of Struct.
12
13
14
15
16
17
|
# File 'lib/capnp/runtime/struct.rb', line 12
def initialize(data, data_size, pointers, pointers_size)
@data = data
@data_size = data_size
@pointers = pointers
@pointers_size = pointers_size
end
|
Class Method Details
.decode_pointer(pointer_ref) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/capnp/runtime/struct.rb', line 23
def self.decode_pointer(pointer_ref)
data = pointer_ref.read_bytes(0, Capnp::WORD_SIZE)
parts = T.cast(data.unpack("l<S<S<"), [Integer, Integer, Integer])
pointer_type = parts[0] & 0b11
raise Capnp::Error.new("Pointer has type #{pointer_type}") unless pointer_type == 0
parts[0] >>= 2
parts
end
|
.from_pointer(pointer_ref) ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/capnp/runtime/struct.rb', line 39
def self.from_pointer(pointer_ref)
pointer_ref, content_ref = pointer_ref.segment.message.dereference_pointer(pointer_ref)
offset_words, data_words, pointers_words = decode_pointer(pointer_ref)
return new(Capnp::Reference::EMPTY, 0, Capnp::Reference::EMPTY, 0) if offset_words == -1
return nil if offset_words.zero? && data_words.zero? && pointers_words.zero?
data_size = data_words * Capnp::WORD_SIZE
if content_ref.nil?
data_offset = (offset_words + 1) * Capnp::WORD_SIZE
data_ref = pointer_ref.offset_position(data_offset)
else
data_ref = content_ref
end
pointers_size = pointers_words * Capnp::WORD_SIZE
pointers_ref = data_ref.offset_position(data_size)
new(data_ref, data_size, pointers_ref, pointers_size)
end
|
Instance Method Details
#to_obj ⇒ Object
69
70
|
# File 'lib/capnp/runtime/struct.rb', line 69
def to_obj
end
|