yeptris 0.6.64.0-riscv64-linux-gnu
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.adoc +150 -0
- data/ext/build_windows_native.rb +60 -0
- data/ext/libyeptris/extconf.rb +57 -0
- data/ext/yeptris_native/cbor_ruby.c +198 -0
- data/ext/yeptris_native/extconf.rb +99 -0
- data/ext/yeptris_native/json_ruby.c +414 -0
- data/ext/yeptris_native/version.h +29 -0
- data/ext/yeptris_native/yeptris_native.c +507 -0
- data/lib/yeptris/3.3/native.so +0 -0
- data/lib/yeptris/cbor.rb +169 -0
- data/lib/yeptris/document.rb +319 -0
- data/lib/yeptris/ffi.rb +572 -0
- data/lib/yeptris/json/descriptor.rb +266 -0
- data/lib/yeptris/json.rb +502 -0
- data/lib/yeptris/materializer.rb +389 -0
- data/lib/yeptris/node.rb +482 -0
- data/lib/yeptris/psych/class_loader.rb +24 -0
- data/lib/yeptris/psych/coder_shim.rb +55 -0
- data/lib/yeptris/psych/drop_in.rb +63 -0
- data/lib/yeptris/psych/encodable.rb +14 -0
- data/lib/yeptris/psych/handler.rb +95 -0
- data/lib/yeptris/psych/parser.rb +114 -0
- data/lib/yeptris/psych/scalar_scanner.rb +149 -0
- data/lib/yeptris/psych/tree_builder.rb +119 -0
- data/lib/yeptris/psych/visitors.rb +670 -0
- data/lib/yeptris/psych.rb +796 -0
- data/lib/yeptris/schema.rb +253 -0
- data/lib/yeptris/validation.rb +320 -0
- data/lib/yeptris/valueml.rb +477 -0
- data/lib/yeptris/yaml/descriptor.rb +56 -0
- data/lib/yeptris/yaml.rb +668 -0
- data/lib/yeptris.rb +130 -0
- data/libyeptris.so +0 -0
- data/vendor/libyeptris/CMakeLists.txt +280 -0
- data/vendor/libyeptris/cmake/yeptris-config.cmake.in +5 -0
- data/vendor/libyeptris/cmake/yeptris.pc.in +11 -0
- data/vendor/libyeptris/src/CMakeLists.txt +183 -0
- data/vendor/libyeptris/src/include/yeptris/api.h +32 -0
- data/vendor/libyeptris/src/include/yeptris/cbor.h +174 -0
- data/vendor/libyeptris/src/include/yeptris/dom.h +196 -0
- data/vendor/libyeptris/src/include/yeptris/emit.h +128 -0
- data/vendor/libyeptris/src/include/yeptris/error.h +42 -0
- data/vendor/libyeptris/src/include/yeptris/events.h +171 -0
- data/vendor/libyeptris/src/include/yeptris/json.h +57 -0
- data/vendor/libyeptris/src/include/yeptris/json.hpp +258 -0
- data/vendor/libyeptris/src/include/yeptris/jsonc_compat.h +115 -0
- data/vendor/libyeptris/src/include/yeptris/marshal.h +75 -0
- data/vendor/libyeptris/src/include/yeptris/parse.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/plan.h +100 -0
- data/vendor/libyeptris/src/include/yeptris/resolve.h +81 -0
- data/vendor/libyeptris/src/include/yeptris/schema.h +121 -0
- data/vendor/libyeptris/src/include/yeptris/tape.h +128 -0
- data/vendor/libyeptris/src/include/yeptris/types.h +38 -0
- data/vendor/libyeptris/src/include/yeptris/validate.h +401 -0
- data/vendor/libyeptris/src/include/yeptris/values.h +108 -0
- data/vendor/libyeptris/src/include/yeptris/version.h.in +29 -0
- data/vendor/libyeptris/src/include/yeptris/visit.h +77 -0
- data/vendor/libyeptris/src/include/yeptris/yajl_compat.h +135 -0
- data/vendor/libyeptris/src/include/yeptris.h +24 -0
- data/vendor/libyeptris/src/yeptris/build.c +393 -0
- data/vendor/libyeptris/src/yeptris/cbor/cbor.h +35 -0
- data/vendor/libyeptris/src/yeptris/cbor/decode.c +1054 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode.c +836 -0
- data/vendor/libyeptris/src/yeptris/cbor/encode_priv.h +32 -0
- data/vendor/libyeptris/src/yeptris/cbor/from_marshal.c +982 -0
- data/vendor/libyeptris/src/yeptris/cbor/sink.h +36 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.c +41 -0
- data/vendor/libyeptris/src/yeptris/common/chartype.h +77 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.c +81 -0
- data/vendor/libyeptris/src/yeptris/common/cpu.h +40 -0
- data/vendor/libyeptris/src/yeptris/common/error.c +65 -0
- data/vendor/libyeptris/src/yeptris/common/error.h +81 -0
- data/vendor/libyeptris/src/yeptris/common/mutex.h +45 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.c +275 -0
- data/vendor/libyeptris/src/yeptris/common/nametab.h +68 -0
- data/vendor/libyeptris/src/yeptris/common/port.h +74 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.c +49 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text.h +342 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_avx2.c +672 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_neon.c +793 -0
- data/vendor/libyeptris/src/yeptris/common/simd_text_scalar.c +324 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.c +34 -0
- data/vendor/libyeptris/src/yeptris/common/string_view.h +93 -0
- data/vendor/libyeptris/src/yeptris/doc.h +86 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.c +1312 -0
- data/vendor/libyeptris/src/yeptris/dom/dom.h +332 -0
- data/vendor/libyeptris/src/yeptris/dom/hpool.c +107 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.c +173 -0
- data/vendor/libyeptris/src/yeptris/dom/mapindex.h +61 -0
- data/vendor/libyeptris/src/yeptris/dom/mutate.c +431 -0
- data/vendor/libyeptris/src/yeptris/dom/ytape.c +2323 -0
- data/vendor/libyeptris/src/yeptris/dom/ytape.h +96 -0
- data/vendor/libyeptris/src/yeptris/emit/emit.c +670 -0
- data/vendor/libyeptris/src/yeptris/emit/float/api.h +43 -0
- data/vendor/libyeptris/src/yeptris/emit/float/dragon.c +405 -0
- data/vendor/libyeptris/src/yeptris/emit/float/floatint.h +231 -0
- data/vendor/libyeptris/src/yeptris/emit/float/fpconv.c +428 -0
- data/vendor/libyeptris/src/yeptris/emit/float/print.c +396 -0
- data/vendor/libyeptris/src/yeptris/emit/style.c +21 -0
- data/vendor/libyeptris/src/yeptris/emit/style.h +32 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.c +1951 -0
- data/vendor/libyeptris/src/yeptris/emit/writer.h +111 -0
- data/vendor/libyeptris/src/yeptris/encoding/bom.c +31 -0
- data/vendor/libyeptris/src/yeptris/encoding/encoding.h +63 -0
- data/vendor/libyeptris/src/yeptris/encoding/transcode.c +157 -0
- data/vendor/libyeptris/src/yeptris/encoding/utf8_validate.c +178 -0
- data/vendor/libyeptris/src/yeptris/events/capture.c +166 -0
- data/vendor/libyeptris/src/yeptris/events/capture.h +39 -0
- data/vendor/libyeptris/src/yeptris/events/iterparse.c +298 -0
- data/vendor/libyeptris/src/yeptris/events/pull.c +117 -0
- data/vendor/libyeptris/src/yeptris/events/push.c +151 -0
- data/vendor/libyeptris/src/yeptris/events/recorder.c +144 -0
- data/vendor/libyeptris/src/yeptris/events/values.c +630 -0
- data/vendor/libyeptris/src/yeptris/events/values_priv.h +53 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.c +86 -0
- data/vendor/libyeptris/src/yeptris/events/yaml_compat.h +90 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/jsonc_compat.c +687 -0
- data/vendor/libyeptris/src/yeptris/jsonapi/yajl_compat.c +728 -0
- data/vendor/libyeptris/src/yeptris/marshal/to_json.c +650 -0
- data/vendor/libyeptris/src/yeptris/marshal.c +988 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.c +20 -0
- data/vendor/libyeptris/src/yeptris/memory/allocator.h +43 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.c +150 -0
- data/vendor/libyeptris/src/yeptris/memory/arena.h +52 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.c +133 -0
- data/vendor/libyeptris/src/yeptris/memory/pool.h +36 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.c +6528 -0
- data/vendor/libyeptris/src/yeptris/parse/engine.h +96 -0
- data/vendor/libyeptris/src/yeptris/parse/events.h +137 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.c +374 -0
- data/vendor/libyeptris/src/yeptris/parse/numbers.h +33 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.c +435 -0
- data/vendor/libyeptris/src/yeptris/parse/scalars.h +87 -0
- data/vendor/libyeptris/src/yeptris/parse/stream_iter.c +358 -0
- data/vendor/libyeptris/src/yeptris/parse.c +1074 -0
- data/vendor/libyeptris/src/yeptris/plan.c +824 -0
- data/vendor/libyeptris/src/yeptris/resolve/compat11.c +339 -0
- data/vendor/libyeptris/src/yeptris/resolve/core12.c +153 -0
- data/vendor/libyeptris/src/yeptris/resolve/full12.c +201 -0
- data/vendor/libyeptris/src/yeptris/resolve/json12.c +109 -0
- data/vendor/libyeptris/src/yeptris/resolve/resolver.h +103 -0
- data/vendor/libyeptris/src/yeptris/resolve/tags.c +250 -0
- data/vendor/libyeptris/src/yeptris/scan/json.c +839 -0
- data/vendor/libyeptris/src/yeptris/scan/json.h +116 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.c +862 -0
- data/vendor/libyeptris/src/yeptris/scan/scan.h +177 -0
- data/vendor/libyeptris/src/yeptris/schema.c +309 -0
- data/vendor/libyeptris/src/yeptris/tape.c +2375 -0
- data/vendor/libyeptris/src/yeptris/tape_in.h +39 -0
- data/vendor/libyeptris/src/yeptris/validate/compile.c +306 -0
- data/vendor/libyeptris/src/yeptris/validate/internal.h +347 -0
- data/vendor/libyeptris/src/yeptris/validate/jsonschema.c +1922 -0
- data/vendor/libyeptris/src/yeptris/validate/output.c +246 -0
- data/vendor/libyeptris/src/yeptris/validate/regexp.c +1600 -0
- data/vendor/libyeptris/src/yeptris/validate/registry.c +118 -0
- data/vendor/libyeptris/src/yeptris/validate/resources.c +601 -0
- data/vendor/libyeptris/src/yeptris/validate/stream.c +1155 -0
- data/vendor/libyeptris/src/yeptris/validate/validate.c +1043 -0
- data/vendor/libyeptris/src/yeptris/version.c +7 -0
- data/vendor/libyeptris/src/yeptris/visit/dom_visit.c +115 -0
- data/vendor/libyeptris/src/yeptris/visit/json_visit.c +293 -0
- data/vendor/libyeptris/src/yeptris/visit/yaml_visit.c +127 -0
- metadata +221 -0
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# The Descriptor plan walk (yeptris#293 slice two, over the C plan
|
|
4
|
+
# ABI of libyeptris v0.6.3): compile a row shape once, then apply it
|
|
5
|
+
# to a JSON document in ONE native pass producing typed COLUMNS —
|
|
6
|
+
# the engine never materializes the intermediate Ruby Hash/Array
|
|
7
|
+
# tree (lutaml-model's hydration reads columns, not trees).
|
|
8
|
+
#
|
|
9
|
+
# descriptor = Yeptris::JSON::Descriptor.build(
|
|
10
|
+
# kind: :seq, # or :map with path: — the rows container
|
|
11
|
+
# children: [
|
|
12
|
+
# { name: "id", kind: :int },
|
|
13
|
+
# { name: "name", kind: :str },
|
|
14
|
+
# ])
|
|
15
|
+
# result = descriptor.walk(json)
|
|
16
|
+
# result.column("id") # => [1, 2, ...] (nil where null/missing)
|
|
17
|
+
# result.to_a # => [{ "id" => 1, "name" => "x" }, ...]
|
|
18
|
+
#
|
|
19
|
+
# Vocabulary alignment with Leptris::XML::Descriptor (the shape
|
|
20
|
+
# vocabulary lutaml-model shares across engines): :collection at the
|
|
21
|
+
# root is the rows container (the seq form), :scalar is the string
|
|
22
|
+
# leaf. Slice one covers rows of scalar leaves — nested plans, the
|
|
23
|
+
# YAML leg, and partial descriptors ride the board item
|
|
24
|
+
# (TODO.restructure/87).
|
|
25
|
+
class Yeptris::JSON::Descriptor
|
|
26
|
+
class Error < ::Yeptris::JSON::Error; end
|
|
27
|
+
|
|
28
|
+
# spec leaf kinds → the C column kind codes (plan.h)
|
|
29
|
+
LEAF_KINDS = {
|
|
30
|
+
int: 0,
|
|
31
|
+
float: 1,
|
|
32
|
+
str: 2,
|
|
33
|
+
bool: 3,
|
|
34
|
+
scalar: 2, # leptris's string-value row kind
|
|
35
|
+
}.freeze
|
|
36
|
+
private_constant :LEAF_KINDS
|
|
37
|
+
|
|
38
|
+
# root forms: the rows container's shape (:collection is leptris's
|
|
39
|
+
# name for a repeated-rows container)
|
|
40
|
+
ROOT_KINDS = %i[seq map collection].freeze
|
|
41
|
+
private_constant :ROOT_KINDS
|
|
42
|
+
|
|
43
|
+
LEAF_SPEC_NAMES = %w[int float str bool].freeze
|
|
44
|
+
private_constant :LEAF_SPEC_NAMES
|
|
45
|
+
|
|
46
|
+
class Handle < ::FFI::AutoPointer
|
|
47
|
+
def self.release(ptr)
|
|
48
|
+
::Yeptris::FFI.yeptris_plan_free(ptr)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# +kind+: :seq (rows are the root array) or :map (rows live under
|
|
53
|
+
# +path:+'s value). +path+: a String, or an Array of Strings for a
|
|
54
|
+
# segmented (nested) path. +children+: the leaf columns; each row
|
|
55
|
+
# is a mapping, every child names one typed column.
|
|
56
|
+
def self.build(kind:, path: nil, children:)
|
|
57
|
+
handle, names = compile_handle(kind, path, children)
|
|
58
|
+
new(handle, names)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# The compile half of .build (shared with the YAML subclass's
|
|
62
|
+
# build — ONE owner of the spec grammar). Returns the owned handle
|
|
63
|
+
# and the leaf names.
|
|
64
|
+
def self.compile_handle(kind, path, children)
|
|
65
|
+
unless ROOT_KINDS.include?(kind)
|
|
66
|
+
raise ArgumentError, "kind must be one of #{ROOT_KINDS.inspect}, got #{kind.inspect}"
|
|
67
|
+
end
|
|
68
|
+
unless children.is_a?(::Array) && !children.empty?
|
|
69
|
+
raise ArgumentError, "children must be a non-empty Array"
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
leaves = children.map do |child|
|
|
73
|
+
name = child[:name]
|
|
74
|
+
code = LEAF_KINDS[child[:kind]]
|
|
75
|
+
if code.nil?
|
|
76
|
+
raise ArgumentError,
|
|
77
|
+
"leaf kind must be one of #{LEAF_KINDS.keys.inspect}, got #{child[:kind].inspect}"
|
|
78
|
+
end
|
|
79
|
+
unless name.is_a?(::String) && !name.empty?
|
|
80
|
+
raise ArgumentError, "leaf name must be a non-empty String, got #{name.inspect}"
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
{ "name" => name, "kind" => LEAF_SPEC_NAMES[code] }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
case path
|
|
87
|
+
when nil then nil
|
|
88
|
+
when ::String then spec_path = path
|
|
89
|
+
when ::Array
|
|
90
|
+
unless path.all? { |seg| seg.is_a?(::String) && !seg.empty? }
|
|
91
|
+
raise ArgumentError, "path segments must be non-empty Strings"
|
|
92
|
+
end
|
|
93
|
+
spec_path = path
|
|
94
|
+
else
|
|
95
|
+
raise ArgumentError, "path must be a String or an Array of Strings"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
spec = { "kind" => kind == :map ? "map" : "seq", "children" => leaves }
|
|
99
|
+
spec["path"] = spec_path unless spec_path.nil?
|
|
100
|
+
|
|
101
|
+
# the spec is strict JSON (the C compiler parses it through the
|
|
102
|
+
# strict JSON DOM); compile once, the engine owns the copy
|
|
103
|
+
spec_json = ::JSON.generate(spec)
|
|
104
|
+
st = ::FFI::MemoryPointer.new(:int)
|
|
105
|
+
raw = ::Yeptris::FFI.yeptris_plan_compile(spec_json, spec_json.bytesize, st)
|
|
106
|
+
if raw.null?
|
|
107
|
+
raise Error, "plan compile failed (status=#{st.read_int}): #{spec_json}"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
[Handle.new(raw), leaves.map { |leaf| leaf["name"] }]
|
|
111
|
+
end
|
|
112
|
+
private_class_method :compile_handle
|
|
113
|
+
|
|
114
|
+
attr_reader :names # the planned leaf names, in spec order
|
|
115
|
+
|
|
116
|
+
# @api private — handles come from .build
|
|
117
|
+
def initialize(handle, names)
|
|
118
|
+
@handle = handle
|
|
119
|
+
@names = names.dup.freeze
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Applies the plan to +json+ (String or IO): parse the tape, one C
|
|
123
|
+
# plan pass, bulk-read the typed columns. The returned PlanResult
|
|
124
|
+
# is standalone Ruby (nothing borrowed from the document).
|
|
125
|
+
def walk(json)
|
|
126
|
+
src = ::Yeptris.read_input(json).to_s
|
|
127
|
+
tape = ::Yeptris::FFI::JsonTape.new
|
|
128
|
+
rc = ::Yeptris::FFI.yeptris_parse_json_tape(src, src.bytesize, tape)
|
|
129
|
+
raise ::Yeptris::JSON::ParseError, ::Yeptris::FFI.last_error_message if rc != ::Yeptris::FFI::OK
|
|
130
|
+
|
|
131
|
+
begin
|
|
132
|
+
st = ::FFI::MemoryPointer.new(:int)
|
|
133
|
+
raw = ::Yeptris::FFI.yeptris_tape_plan_walk(tape, @handle, st)
|
|
134
|
+
if raw.null?
|
|
135
|
+
raise Error,
|
|
136
|
+
"plan walk failed (status=#{st.read_int}) — the document shape " \
|
|
137
|
+
"disagrees with the plan"
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
begin
|
|
141
|
+
PlanResult.read(raw, src, @names)
|
|
142
|
+
ensure
|
|
143
|
+
::Yeptris::FFI.yeptris_plan_result_free(raw)
|
|
144
|
+
end
|
|
145
|
+
ensure
|
|
146
|
+
::Yeptris::FFI.yeptris_tape_free(tape)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
def column_count
|
|
151
|
+
::Yeptris::FFI.yeptris_plan_column_count(@handle)
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# The eager columnar result of Descriptor#walk: typed Ruby columns
|
|
155
|
+
# keyed by leaf name, plus the row-hash conveniences. Nothing here
|
|
156
|
+
# borrows C memory.
|
|
157
|
+
class PlanResult
|
|
158
|
+
# @api private — one bulk read per column; the C result is freed
|
|
159
|
+
# on return (PlanResult owns plain Ruby data)
|
|
160
|
+
def self.read(raw, src, names)
|
|
161
|
+
rows = ::Yeptris::FFI.yeptris_plan_result_rows(raw)
|
|
162
|
+
columns = {}
|
|
163
|
+
names.each_with_index do |name, c|
|
|
164
|
+
kind = ::Yeptris::FFI.yeptris_plan_result_kind(raw, c)
|
|
165
|
+
columns[name] = read_column(raw, c, kind, rows, src)
|
|
166
|
+
end
|
|
167
|
+
new(rows, names, columns)
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
def self.read_column(raw, c, kind, rows, src)
|
|
171
|
+
return [] if rows.zero?
|
|
172
|
+
|
|
173
|
+
nulls = ::Yeptris::FFI.yeptris_plan_result_nulls(raw, c).read_bytes(rows).unpack("C*")
|
|
174
|
+
has_nulls = nulls.include?(1)
|
|
175
|
+
case kind
|
|
176
|
+
when 0 # int: the unpacked lane IS the column when no nulls
|
|
177
|
+
ints = ::Yeptris::FFI.yeptris_plan_result_ints(raw, c).read_bytes(rows * 8).unpack("q<*")
|
|
178
|
+
return ints unless has_nulls
|
|
179
|
+
|
|
180
|
+
Array.new(rows) { |i| nulls[i] == 1 ? nil : ints[i] }
|
|
181
|
+
when 1
|
|
182
|
+
floats = ::Yeptris::FFI.yeptris_plan_result_floats(raw, c).read_bytes(rows * 8).unpack("E*")
|
|
183
|
+
return floats unless has_nulls
|
|
184
|
+
|
|
185
|
+
Array.new(rows) { |i| nulls[i] == 1 ? nil : floats[i] }
|
|
186
|
+
when 3 # bool: 0/1 → false/true (always maps)
|
|
187
|
+
ints = ::Yeptris::FFI.yeptris_plan_result_ints(raw, c).read_bytes(rows * 8).unpack("q<*")
|
|
188
|
+
Array.new(rows) { |i| nulls[i] == 1 ? nil : ints[i] == 1 }
|
|
189
|
+
else # str: spans into the source, escapes decoded on the Ruby side
|
|
190
|
+
offs = ::Yeptris::FFI.yeptris_plan_result_str_offs(raw, c).read_bytes(rows * 4).unpack("V*")
|
|
191
|
+
lens = ::Yeptris::FFI.yeptris_plan_result_str_lens(raw, c).read_bytes(rows * 4).unpack("V*")
|
|
192
|
+
decode = ::Yeptris::JSON.method(:decode_span)
|
|
193
|
+
Array.new(rows) { |i| nulls[i] == 1 ? nil : decode.call(src, offs[i], lens[i]) }
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
private_class_method :read_column
|
|
197
|
+
|
|
198
|
+
# @api private — the DOM leg's read: typed lanes as above; str
|
|
199
|
+
# columns materialize from the (ptr,len) views into the document
|
|
200
|
+
def self.read_dom(raw, names)
|
|
201
|
+
rows = ::Yeptris::FFI.yeptris_plan_result_rows(raw)
|
|
202
|
+
columns = {}
|
|
203
|
+
names.each_with_index do |name, c|
|
|
204
|
+
kind = ::Yeptris::FFI.yeptris_plan_result_kind(raw, c)
|
|
205
|
+
if kind == 2
|
|
206
|
+
nulls = ::Yeptris::FFI.yeptris_plan_result_nulls(raw, c).read_bytes(rows).unpack("C*")
|
|
207
|
+
base = ::FFI::Pointer.new(::Yeptris::FFI.yeptris_plan_result_strs(raw, c))
|
|
208
|
+
stride = ::Yeptris::FFI::PlanStr.size
|
|
209
|
+
columns[name] = Array.new(rows) do |i|
|
|
210
|
+
next nil if nulls[i] == 1
|
|
211
|
+
|
|
212
|
+
v = ::Yeptris::FFI::PlanStr.new(base + i * stride)
|
|
213
|
+
v[:p].read_bytes(v[:len]).force_encoding(Encoding::UTF_8)
|
|
214
|
+
end
|
|
215
|
+
else
|
|
216
|
+
columns[name] = read_column(raw, c, kind, rows, nil)
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
new(rows, names, columns)
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
def initialize(rows, names, columns)
|
|
223
|
+
@rows = rows
|
|
224
|
+
@names = names
|
|
225
|
+
@columns = columns
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
def rows
|
|
229
|
+
@rows
|
|
230
|
+
end
|
|
231
|
+
alias count rows
|
|
232
|
+
|
|
233
|
+
# The planned leaf names, in spec order.
|
|
234
|
+
def names
|
|
235
|
+
@names.dup
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
# One typed column: an Array of rows values (nil where the leaf
|
|
239
|
+
# was null, missing, or shape-mismatched).
|
|
240
|
+
def column(name)
|
|
241
|
+
@columns.fetch(name) { raise ArgumentError, "no planned column #{name.inspect}" }
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# Row +i+ as a Hash of the planned leaves (nil out of range).
|
|
245
|
+
def at(i)
|
|
246
|
+
return nil if i >= @rows || i.negative?
|
|
247
|
+
|
|
248
|
+
row = {}
|
|
249
|
+
@names.each { |n| row[n] = @columns[n][i] }
|
|
250
|
+
row
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
# Rows as Hashes — the tree-shaped convenience; column readers
|
|
254
|
+
# are the allocation-lean path.
|
|
255
|
+
def to_a
|
|
256
|
+
Array.new(@rows) { |i| at(i) }
|
|
257
|
+
end
|
|
258
|
+
alias to_ruby to_a # leptris's eager-tree vocabulary
|
|
259
|
+
|
|
260
|
+
def each_row(&block)
|
|
261
|
+
return enum_for(:each_row) unless block
|
|
262
|
+
|
|
263
|
+
@rows.times { |i| block.call(at(i)) }
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|