rbs 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -0
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +6 -1
  5. data/core/array.rbs +2866 -1086
  6. data/core/basic_object.rbs +150 -30
  7. data/core/binding.rbs +33 -0
  8. data/core/builtin.rbs +4 -4
  9. data/core/class.rbs +43 -5
  10. data/core/comparable.rbs +57 -0
  11. data/core/complex.rbs +170 -4
  12. data/core/constants.rbs +51 -0
  13. data/core/deprecated.rbs +7 -0
  14. data/core/dir.rbs +305 -20
  15. data/core/encoding.rbs +472 -77
  16. data/core/enumerable.rbs +2173 -234
  17. data/core/enumerator.rbs +448 -182
  18. data/core/env.rbs +448 -1
  19. data/core/errno.rbs +1 -10
  20. data/core/errors.rbs +152 -2
  21. data/core/exception.rbs +201 -127
  22. data/core/false_class.rbs +27 -0
  23. data/core/fiber.rbs +118 -37
  24. data/core/fiber_error.rbs +8 -9
  25. data/core/file.rbs +1059 -139
  26. data/core/file_test.rbs +287 -32
  27. data/core/float.rbs +776 -300
  28. data/core/gc.rbs +185 -34
  29. data/core/global_variables.rbs +5 -1
  30. data/core/hash.rbs +1582 -649
  31. data/core/integer.rbs +974 -204
  32. data/core/io/buffer.rbs +710 -0
  33. data/core/io/wait.rbs +29 -8
  34. data/core/io.rbs +2438 -417
  35. data/core/kernel.rbs +2315 -316
  36. data/core/marshal.rbs +37 -2
  37. data/core/match_data.rbs +123 -6
  38. data/core/math.rbs +126 -6
  39. data/core/method.rbs +226 -102
  40. data/core/module.rbs +421 -45
  41. data/core/nil_class.rbs +64 -0
  42. data/core/numeric.rbs +620 -142
  43. data/core/object.rbs +453 -81
  44. data/core/object_space.rbs +92 -2
  45. data/core/proc.rbs +482 -285
  46. data/core/process.rbs +443 -34
  47. data/core/ractor.rbs +232 -9
  48. data/core/random.rbs +151 -52
  49. data/core/range.rbs +885 -160
  50. data/core/rational.rbs +122 -6
  51. data/core/rb_config.rbs +14 -4
  52. data/core/refinement.rbs +44 -0
  53. data/core/regexp.rbs +156 -14
  54. data/core/ruby_vm.rbs +42 -3
  55. data/core/signal.rbs +78 -39
  56. data/core/string.rbs +2123 -567
  57. data/core/string_io.rbs +204 -0
  58. data/core/struct.rbs +283 -28
  59. data/core/symbol.rbs +304 -30
  60. data/core/thread.rbs +1288 -688
  61. data/core/thread_group.rbs +66 -10
  62. data/core/time.rbs +643 -217
  63. data/core/trace_point.rbs +100 -12
  64. data/core/true_class.rbs +24 -0
  65. data/core/unbound_method.rbs +73 -7
  66. data/core/warning.rbs +37 -12
  67. data/docs/CONTRIBUTING.md +40 -34
  68. data/docs/stdlib.md +3 -102
  69. data/lib/rbs/annotate/annotations.rb +197 -0
  70. data/lib/rbs/annotate/formatter.rb +80 -0
  71. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  72. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  73. data/lib/rbs/annotate.rb +6 -0
  74. data/lib/rbs/cli.rb +45 -1
  75. data/lib/rbs/definition_builder.rb +5 -1
  76. data/lib/rbs/location_aux.rb +12 -0
  77. data/lib/rbs/prototype/rb.rb +12 -0
  78. data/lib/rbs/version.rb +1 -1
  79. data/sig/annotate/annotations.rbs +102 -0
  80. data/sig/annotate/formatter.rbs +24 -0
  81. data/sig/annotate/rdoc_annotater.rbs +82 -0
  82. data/sig/annotate/rdoc_source.rbs +30 -0
  83. data/sig/cli.rbs +2 -0
  84. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  85. data/sig/location.rbs +6 -0
  86. data/sig/method_types.rbs +5 -1
  87. data/sig/polyfill.rbs +78 -0
  88. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  89. data/stdlib/abbrev/0/array.rbs +26 -0
  90. data/stdlib/base64/0/base64.rbs +31 -0
  91. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  92. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  93. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  94. data/stdlib/cgi/0/core.rbs +59 -0
  95. data/stdlib/coverage/0/coverage.rbs +164 -2
  96. data/stdlib/csv/0/csv.rbs +2862 -398
  97. data/stdlib/date/0/date.rbs +483 -25
  98. data/stdlib/date/0/date_time.rbs +187 -12
  99. data/stdlib/dbm/0/dbm.rbs +152 -17
  100. data/stdlib/digest/0/digest.rbs +146 -0
  101. data/stdlib/erb/0/erb.rbs +65 -245
  102. data/stdlib/fiber/0/fiber.rbs +73 -91
  103. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  104. data/stdlib/find/0/find.rbs +9 -0
  105. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  106. data/stdlib/io-console/0/io-console.rbs +227 -15
  107. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  108. data/stdlib/json/0/json.rbs +1146 -144
  109. data/stdlib/logger/0/formatter.rbs +24 -0
  110. data/stdlib/logger/0/log_device.rbs +64 -0
  111. data/stdlib/logger/0/logger.rbs +165 -13
  112. data/stdlib/logger/0/period.rbs +10 -0
  113. data/stdlib/logger/0/severity.rbs +26 -0
  114. data/stdlib/monitor/0/monitor.rbs +163 -0
  115. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  116. data/stdlib/net-http/0/net-http.rbs +1492 -683
  117. data/stdlib/nkf/0/nkf.rbs +372 -0
  118. data/stdlib/objspace/0/objspace.rbs +149 -90
  119. data/stdlib/openssl/0/openssl.rbs +8108 -71
  120. data/stdlib/optparse/0/optparse.rbs +487 -19
  121. data/stdlib/pathname/0/pathname.rbs +425 -124
  122. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  123. data/stdlib/prime/0/integer-extension.rbs +20 -2
  124. data/stdlib/prime/0/prime.rbs +88 -21
  125. data/stdlib/pstore/0/pstore.rbs +102 -0
  126. data/stdlib/pty/0/pty.rbs +64 -14
  127. data/stdlib/resolv/0/resolv.rbs +420 -31
  128. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  129. data/stdlib/rubygems/0/config_file.rbs +33 -1
  130. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  131. data/stdlib/rubygems/0/installer.rbs +13 -1
  132. data/stdlib/rubygems/0/path_support.rbs +4 -1
  133. data/stdlib/rubygems/0/platform.rbs +5 -1
  134. data/stdlib/rubygems/0/request_set.rbs +44 -2
  135. data/stdlib/rubygems/0/requirement.rbs +65 -2
  136. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  137. data/stdlib/rubygems/0/source_list.rbs +13 -0
  138. data/stdlib/rubygems/0/specification.rbs +21 -1
  139. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  140. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  141. data/stdlib/rubygems/0/version.rbs +60 -157
  142. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  143. data/stdlib/set/0/set.rbs +420 -106
  144. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  145. data/stdlib/singleton/0/singleton.rbs +20 -0
  146. data/stdlib/socket/0/addrinfo.rbs +210 -9
  147. data/stdlib/socket/0/basic_socket.rbs +103 -11
  148. data/stdlib/socket/0/ip_socket.rbs +31 -9
  149. data/stdlib/socket/0/socket.rbs +586 -38
  150. data/stdlib/socket/0/tcp_server.rbs +22 -2
  151. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  152. data/stdlib/socket/0/udp_socket.rbs +25 -2
  153. data/stdlib/socket/0/unix_server.rbs +22 -2
  154. data/stdlib/socket/0/unix_socket.rbs +45 -5
  155. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  156. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  157. data/stdlib/time/0/time.rbs +208 -116
  158. data/stdlib/timeout/0/timeout.rbs +10 -0
  159. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  160. data/stdlib/tsort/0/cyclic.rbs +1 -0
  161. data/stdlib/tsort/0/interfaces.rbs +1 -0
  162. data/stdlib/tsort/0/tsort.rbs +42 -0
  163. data/stdlib/uri/0/common.rbs +57 -8
  164. data/stdlib/uri/0/file.rbs +55 -109
  165. data/stdlib/uri/0/ftp.rbs +6 -3
  166. data/stdlib/uri/0/generic.rbs +556 -327
  167. data/stdlib/uri/0/http.rbs +26 -115
  168. data/stdlib/uri/0/https.rbs +8 -102
  169. data/stdlib/uri/0/ldap.rbs +143 -137
  170. data/stdlib/uri/0/ldaps.rbs +8 -102
  171. data/stdlib/uri/0/mailto.rbs +3 -0
  172. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  173. data/stdlib/uri/0/ws.rbs +6 -3
  174. data/stdlib/uri/0/wss.rbs +5 -3
  175. data/stdlib/yaml/0/dbm.rbs +151 -87
  176. data/stdlib/yaml/0/store.rbs +6 -0
  177. data/stdlib/zlib/0/zlib.rbs +90 -31
  178. metadata +17 -5
  179. data/lib/rbs/location.rb +0 -221
@@ -0,0 +1,710 @@
1
+ %a{annotate:rdoc:skip}
2
+ class IO
3
+ # <!-- rdoc-file=io_buffer.c -->
4
+ # IO::Buffer is a low-level efficient buffer for input/output. There are three
5
+ # ways of using buffer:
6
+ #
7
+ # * Create an empty buffer with ::new, fill it with data using #copy or
8
+ # #set_value, #set_string, get data with #get_string;
9
+ # * Create a buffer mapped to some string with ::for, then it could be used
10
+ # both for reading with #get_string or #get_value, and writing (writing will
11
+ # change the source string, too);
12
+ # * Create a buffer mapped to some file with ::map, then it could be used for
13
+ # reading and writing the underlying file.
14
+ #
15
+ #
16
+ # Interaction with string and file memory is performed by efficient low-level C
17
+ # mechanisms like `memcpy`.
18
+ #
19
+ # The class is meant to be an utility for implementing more high-level
20
+ # mechanisms like Fiber::SchedulerInterface#io_read and
21
+ # Fiber::SchedulerInterface#io_write.
22
+ #
23
+ # **Examples of usage:**
24
+ #
25
+ # Empty buffer:
26
+ #
27
+ # buffer = IO::Buffer.new(8) # create empty 8-byte buffer
28
+ # # =>
29
+ # # #<IO::Buffer 0x0000555f5d1a5c50+8 INTERNAL>
30
+ # # ...
31
+ # buffer
32
+ # # =>
33
+ # # <IO::Buffer 0x0000555f5d156ab0+8 INTERNAL>
34
+ # # 0x00000000 00 00 00 00 00 00 00 00
35
+ # buffer.set_string('test', 2) # put there bytes of the "test" string, starting from offset 2
36
+ # # => 4
37
+ # buffer.get_string # get the result
38
+ # # => "\x00\x00test\x00\x00"
39
+ #
40
+ # Buffer from string:
41
+ #
42
+ # string = 'data'
43
+ # buffer = IO::Buffer.for(str)
44
+ # # =>
45
+ # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
46
+ # # ...
47
+ # buffer
48
+ # # =>
49
+ # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
50
+ # # 0x00000000 64 61 74 61 data
51
+ #
52
+ # buffer.get_string(2) # read content starting from offset 2
53
+ # # => "ta"
54
+ # buffer.set_string('---', 1) # write content, starting from offset 1
55
+ # # => 3
56
+ # buffer
57
+ # # =>
58
+ # # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE>
59
+ # # 0x00000000 64 2d 2d 2d d---
60
+ # string # original string changed, too
61
+ # # => "d---"
62
+ #
63
+ # Buffer from file:
64
+ #
65
+ # File.write('test.txt', 'test data')
66
+ # # => 9
67
+ # buffer = IO::Buffer.map(File.open('test.txt'))
68
+ # # =>
69
+ # # #<IO::Buffer 0x00007f3f0768c000+9 MAPPED IMMUTABLE>
70
+ # # ...
71
+ # buffer.get_string(5, 2) # read 2 bytes, starting from offset 5
72
+ # # => "da"
73
+ # buffer.set_string('---', 1) # attempt to write
74
+ # # in `set_string': Buffer is not writable! (IO::Buffer::AccessError)
75
+ #
76
+ # # To create writable file-mapped buffer
77
+ # # Open file for read-write, pass size, offset, and flags=0
78
+ # buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 9, 0, 0)
79
+ # buffer.set_string('---', 1)
80
+ # # => 3 -- bytes written
81
+ # File.read('test.txt')
82
+ # # => "t--- data"
83
+ #
84
+ # **The class is experimental and the interface is subject to change.**
85
+ #
86
+ class Buffer
87
+ include Comparable
88
+
89
+ # <!--
90
+ # rdoc-file=io_buffer.c
91
+ # - IO::Buffer.for(string) -> io_buffer
92
+ # -->
93
+ # Creates a IO::Buffer from the given string's memory. The buffer remains
94
+ # associated with the string, and writing to a buffer will update the string's
95
+ # contents.
96
+ #
97
+ # Until #free is invoked on the buffer, either explicitly or via the garbage
98
+ # collector, the source string will be locked and cannot be modified.
99
+ #
100
+ # If the string is frozen, it will create a read-only buffer which cannot be
101
+ # modified.
102
+ #
103
+ # string = 'test'
104
+ # buffer = IO::Buffer.for(str)
105
+ # buffer.external? #=> true
106
+ #
107
+ # buffer.get_string(0, 1)
108
+ # # => "t"
109
+ # string
110
+ # # => "best"
111
+ #
112
+ # buffer.resize(100)
113
+ # # in `resize': Cannot resize external buffer! (IO::Buffer::AccessError)
114
+ #
115
+ def self.for: (String) -> Buffer
116
+
117
+ # <!--
118
+ # rdoc-file=io_buffer.c
119
+ # - IO::Buffer.map(file, [size, [offset, [flags]]]) -> io_buffer
120
+ # -->
121
+ # Create an IO::Buffer for reading from `file` by memory-mapping the file.
122
+ # `file_io` should be a `File` instance, opened for reading.
123
+ #
124
+ # Optional `size` and `offset` of mapping can be specified.
125
+ #
126
+ # By default, the buffer would be immutable (read only); to create a writable
127
+ # mapping, you need to open a file in read-write mode, and explicitly pass
128
+ # `flags` argument without IO::Buffer::IMMUTABLE.
129
+ #
130
+ # File.write('test.txt', 'test')
131
+ #
132
+ # buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY)
133
+ # # => #<IO::Buffer 0x00000001014a0000+4 MAPPED READONLY>
134
+ #
135
+ # buffer.readonly? # => true
136
+ #
137
+ # buffer.get_string
138
+ # # => "test"
139
+ #
140
+ # buffer.set_string('b', 0)
141
+ # # `set_string': Buffer is not writable! (IO::Buffer::AccessError)
142
+ #
143
+ # # create read/write mapping: length 4 bytes, offset 0, flags 0
144
+ # buffer = IO::Buffer.map(File.open('test.txt', 'r+'), 4, 0)
145
+ # buffer.set_string('b', 0)
146
+ # # => 1
147
+ #
148
+ # # Check it
149
+ # File.read('test.txt')
150
+ # # => "best"
151
+ #
152
+ # Note that some operating systems may not have cache coherency between mapped
153
+ # buffers and file reads.
154
+ #
155
+ def self.map: (File file, ?Integer? size, ?Integer offset, ?Integer flags) -> Buffer
156
+
157
+ public
158
+
159
+ # <!--
160
+ # rdoc-file=io_buffer.c
161
+ # - <=>(other) -> true or false
162
+ # -->
163
+ # Buffers are compared by size and exact contents of the memory they are
164
+ # referencing using `memcmp`.
165
+ #
166
+ def <=>: (Buffer) -> Integer
167
+
168
+ # <!--
169
+ # rdoc-file=io_buffer.c
170
+ # - clear(value = 0, [offset, [length]]) -> self
171
+ # -->
172
+ # Fill buffer with `value`, starting with `offset` and going for `length` bytes.
173
+ #
174
+ # buffer = IO::Buffer.for('test')
175
+ # # =>
176
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
177
+ # # 0x00000000 74 65 73 74 test
178
+ #
179
+ # buffer.clear
180
+ # # =>
181
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
182
+ # # 0x00000000 00 00 00 00 ....
183
+ #
184
+ # buf.clear(1) # fill with 1
185
+ # # =>
186
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
187
+ # # 0x00000000 01 01 01 01 ....
188
+ #
189
+ # buffer.clear(2, 1, 2) # fill with 2, starting from offset 1, for 2 bytes
190
+ # # =>
191
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
192
+ # # 0x00000000 01 02 02 01 ....
193
+ #
194
+ # buffer.clear(2, 1) # fill with 2, starting from offset 1
195
+ # # =>
196
+ # # <IO::Buffer 0x00007fca40087c38+4 SLICE>
197
+ # # 0x00000000 01 02 02 02 ....
198
+ #
199
+ def clear: (?Integer value, ?Integer offset, ?Integer length) -> self
200
+
201
+ # <!--
202
+ # rdoc-file=io_buffer.c
203
+ # - copy(source, [offset, [length, [source_offset]]]) -> size
204
+ # -->
205
+ # Efficiently copy data from a source IO::Buffer into the buffer, at `offset`
206
+ # using `memcpy`. For copying String instances, see #set_string.
207
+ #
208
+ # buffer = IO::Buffer.new(32)
209
+ # # =>
210
+ # # #<IO::Buffer 0x0000555f5ca22520+32 INTERNAL>
211
+ # # 0x00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
212
+ # # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ *
213
+ #
214
+ # buffer.copy(IO::Buffer.for("test"), 8)
215
+ # # => 4 -- size of data copied
216
+ # buffer
217
+ # # =>
218
+ # # #<IO::Buffer 0x0000555f5cf8fe40+32 INTERNAL>
219
+ # # 0x00000000 00 00 00 00 00 00 00 00 74 65 73 74 00 00 00 00 ........test....
220
+ # # 0x00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ *
221
+ #
222
+ # #copy can be used to put data into strings associated with buffer:
223
+ #
224
+ # string= "data: "
225
+ # # => "data: "
226
+ # buffer = IO::Buffer.for(str)
227
+ # buffer.copy(IO::Buffer.for("test"), 5)
228
+ # # => 4
229
+ # string
230
+ # # => "data:test"
231
+ #
232
+ # Attempt to copy into a read-only buffer will fail:
233
+ #
234
+ # File.write('test.txt', 'test')
235
+ # buffer = IO::Buffer.map(File.open('test.txt'), nil, 0, IO::Buffer::READONLY)
236
+ # buffer.copy(IO::Buffer.for("test"), 8)
237
+ # # in `copy': Buffer is not writable! (IO::Buffer::AccessError)
238
+ #
239
+ # See ::map for details of creation of mutable file mappings, this will work:
240
+ #
241
+ # buffer = IO::Buffer.map(File.open('test.txt', 'r+'))
242
+ # buffer.copy("boom", 0)
243
+ # # => 4
244
+ # File.read('test.txt')
245
+ # # => "boom"
246
+ #
247
+ # Attempt to copy the data which will need place outside of buffer's bounds will
248
+ # fail:
249
+ #
250
+ # buffer = IO::Buffer.new(2)
251
+ # buffer.copy('test', 0)
252
+ # # in `copy': Specified offset+length exceeds source size! (ArgumentError)
253
+ #
254
+ def copy: (Buffer source, ?Integer offset, ?Integer length, ?Integer source_offset) -> Integer
255
+
256
+ # <!--
257
+ # rdoc-file=io_buffer.c
258
+ # - external? -> true or false
259
+ # -->
260
+ # If the buffer is _external_, meaning it references from memory which is not
261
+ # allocated or mapped by the buffer itself.
262
+ #
263
+ # A buffer created using ::for has an external reference to the string's
264
+ # memory.
265
+ #
266
+ # External buffer can't be resized.
267
+ #
268
+ def empty?: () -> bool
269
+
270
+ # <!--
271
+ # rdoc-file=io_buffer.c
272
+ # - external?()
273
+ # -->
274
+ #
275
+ def external?: () -> bool
276
+
277
+ # <!--
278
+ # rdoc-file=io_buffer.c
279
+ # - free -> self
280
+ # -->
281
+ # If the buffer references memory, release it back to the operating system.
282
+ # * for a *mapped* buffer (e.g. from file): unmap.
283
+ # * for a buffer created from scratch: free memory.
284
+ # * for a buffer created from string: undo the association.
285
+ #
286
+ #
287
+ # After the buffer is freed, no further operations can't be performed on it.
288
+ #
289
+ # buffer = IO::Buffer.for('test')
290
+ # buffer.free
291
+ # # => #<IO::Buffer 0x0000000000000000+0 NULL>
292
+ #
293
+ # buffer.get_value(:U8, 0)
294
+ # # in `get_value': The buffer is not allocated! (IO::Buffer::AllocationError)
295
+ #
296
+ # buffer.get_string
297
+ # # in `get_string': The buffer is not allocated! (IO::Buffer::AllocationError)
298
+ #
299
+ # buffer.null?
300
+ # # => true
301
+ #
302
+ # You can resize a freed buffer to re-allocate it.
303
+ #
304
+ def free: () -> self
305
+
306
+ # <!--
307
+ # rdoc-file=io_buffer.c
308
+ # - get_string([offset, [length, [encoding]]]) -> string
309
+ # -->
310
+ # Read a chunk or all of the buffer into a string, in the specified `encoding`.
311
+ # If no encoding is provided `Encoding::BINARY` is used.
312
+ #
313
+ # buffer = IO::Buffer.for('test')
314
+ # buffer.get_string
315
+ # # => "test"
316
+ # buffer.get_string(2)
317
+ # # => "st"
318
+ # buffer.get_string(2, 1)
319
+ # # => "s"
320
+ #
321
+ def get_string: (?Integer offset, ?Integer length, ?Encoding encoding) -> String
322
+
323
+ # <!--
324
+ # rdoc-file=io_buffer.c
325
+ # - get_value(type, offset) -> numeric
326
+ # -->
327
+ # Read from buffer a value of `type` at `offset`. `type` should be one of
328
+ # symbols:
329
+ #
330
+ # * `:U8`: unsigned integer, 1 byte
331
+ # * `:S8`: signed integer, 1 byte
332
+ # * `:u16`: unsigned integer, 2 bytes, little-endian
333
+ # * `:U16`: unsigned integer, 2 bytes, big-endian
334
+ # * `:s16`: signed integer, 2 bytes, little-endian
335
+ # * `:S16`: signed integer, 2 bytes, big-endian
336
+ # * `:u32`: unsigned integer, 4 bytes, little-endian
337
+ # * `:U32`: unsigned integer, 4 bytes, big-endian
338
+ # * `:s32`: signed integer, 4 bytes, little-endian
339
+ # * `:S32`: signed integer, 4 bytes, big-endian
340
+ # * `:u64`: unsigned integer, 8 bytes, little-endian
341
+ # * `:U64`: unsigned integer, 8 bytes, big-endian
342
+ # * `:s64`: signed integer, 8 bytes, little-endian
343
+ # * `:S64`: signed integer, 8 bytes, big-endian
344
+ # * `:f32`: float, 4 bytes, little-endian
345
+ # * `:F32`: float, 4 bytes, big-endian
346
+ # * `:f64`: double, 8 bytes, little-endian
347
+ # * `:F64`: double, 8 bytes, big-endian
348
+ #
349
+ #
350
+ # Example:
351
+ #
352
+ # string = [1.5].pack('f')
353
+ # # => "\x00\x00\xC0?"
354
+ # IO::Buffer.for(string).get_value(:f32, 0)
355
+ # # => 1.5
356
+ #
357
+ def get_value: (int_get_type, Integer offset) -> Integer
358
+ | (float_get_type, Integer offset) -> Float
359
+
360
+ type int_get_type = :U8 | :S8
361
+ | :u16 | :U16 | :s16 | :S16
362
+ | :u32 | :U32 | :s32 | :S32
363
+ | :u64 | :U64 | :s64 | :S64
364
+
365
+ type float_get_type = :f32 | :F32 | :f64 | :F64
366
+
367
+ # <!--
368
+ # rdoc-file=io_buffer.c
369
+ # - hexdump()
370
+ # -->
371
+ #
372
+ def hexdump: () -> String
373
+
374
+ # <!--
375
+ # rdoc-file=io_buffer.c
376
+ # - inspect()
377
+ # -->
378
+ #
379
+ def inspect: () -> String
380
+
381
+ # <!--
382
+ # rdoc-file=io_buffer.c
383
+ # - internal? -> true or false
384
+ # -->
385
+ # If the buffer is *internal*, meaning it references memory allocated by the
386
+ # buffer itself.
387
+ #
388
+ # An internal buffer is not associated with any external memory (e.g. string) or
389
+ # file mapping.
390
+ #
391
+ # Internal buffers are created using ::new and is the default when the requested
392
+ # size is less than the IO::Buffer::PAGE_SIZE and it was not requested to be
393
+ # mapped on creation.
394
+ #
395
+ # Internal buffers can be resized, and such an operation will typically
396
+ # invalidate all slices, but not always.
397
+ #
398
+ def internal?: () -> bool
399
+
400
+ # <!--
401
+ # rdoc-file=io_buffer.c
402
+ # - locked { ... }
403
+ # -->
404
+ # Allows to process a buffer in exclusive way, for concurrency-safety. While the
405
+ # block is performed, the buffer is considered locked, and no other code can
406
+ # enter the lock. Also, locked buffer can't be changed with #resize or #free.
407
+ #
408
+ # buffer = IO::Buffer.new(4)
409
+ # buffer.locked? #=> false
410
+ #
411
+ # Fiber.schedule do
412
+ # buffer.locked do
413
+ # buffer.write(io) # theoretical system call interface
414
+ # end
415
+ # end
416
+ #
417
+ # Fiber.schedule do
418
+ # # in `locked': Buffer already locked! (IO::Buffer::LockedError)
419
+ # buffer.locked do
420
+ # buffer.set_string(...)
421
+ # end
422
+ # end
423
+ #
424
+ # The following operations acquire a lock: #resize, #free.
425
+ #
426
+ # Locking is not thread safe. It is designed as a safety net around non-blocking
427
+ # system calls. You can only share a buffer between threads with appropriate
428
+ # synchronisation techniques.
429
+ #
430
+ def locked: [A] () { (IO::Buffer) -> A } -> A
431
+
432
+ # <!--
433
+ # rdoc-file=io_buffer.c
434
+ # - locked? -> true or false
435
+ # -->
436
+ # If the buffer is *locked*, meaning it is inside #locked block execution.
437
+ # Locked buffer can't be resized or freed, and another lock can't be acquired on
438
+ # it.
439
+ #
440
+ # Locking is not thread safe, but is a semantic used to ensure buffers don't
441
+ # move while being used by a system call.
442
+ #
443
+ # buffer.locked do
444
+ # buffer.write(io) # theoretical system call interface
445
+ # end
446
+ #
447
+ def locked?: () -> bool
448
+
449
+ # <!--
450
+ # rdoc-file=io_buffer.c
451
+ # - mapped? -> true or false
452
+ # -->
453
+ # If the buffer is *mapped*, meaning it references memory mapped by the buffer.
454
+ #
455
+ # Mapped buffers are either anonymous, if created by ::new with the
456
+ # IO::Buffer::MAPPED flag or if the size was at least IO::Buffer::PAGE_SIZE, or
457
+ # backed by a file if created with ::map.
458
+ #
459
+ # Mapped buffers can usually be resized, and such an operation will typically
460
+ # invalidate all slices, but not always.
461
+ #
462
+ def mapped?: () -> bool
463
+
464
+ # <!--
465
+ # rdoc-file=io_buffer.c
466
+ # - null? -> true or false
467
+ # -->
468
+ # If the buffer was freed with #free or was never allocated in the first place.
469
+ #
470
+ def null?: () -> bool
471
+
472
+ # <!--
473
+ # rdoc-file=io_buffer.c
474
+ # - pread(p1, p2, p3)
475
+ # -->
476
+ #
477
+ def pread: (untyped, untyped, untyped) -> untyped
478
+
479
+ # <!--
480
+ # rdoc-file=io_buffer.c
481
+ # - pwrite(p1, p2, p3)
482
+ # -->
483
+ #
484
+ def pwrite: (untyped, untyped, untyped) -> untyped
485
+
486
+ # <!--
487
+ # rdoc-file=io_buffer.c
488
+ # - read(p1, p2)
489
+ # -->
490
+ #
491
+ def read: (untyped, untyped) -> untyped
492
+
493
+ # <!--
494
+ # rdoc-file=io_buffer.c
495
+ # - readonly?()
496
+ # -->
497
+ #
498
+ def readonly?: () -> bool
499
+
500
+ # <!--
501
+ # rdoc-file=io_buffer.c
502
+ # - resize(new_size) -> self
503
+ # -->
504
+ # Resizes a buffer to a `new_size` bytes, preserving its content. Depending on
505
+ # the old and new size, the memory area associated with the buffer might be
506
+ # either extended, or rellocated at different address with content being copied.
507
+ #
508
+ # buffer = IO::Buffer.new(4)
509
+ # buffer.set_string("test", 0)
510
+ # buffer.resize(8) # resize to 8 bytes
511
+ # # =>
512
+ # # #<IO::Buffer 0x0000555f5d1a1630+8 INTERNAL>
513
+ # # 0x00000000 74 65 73 74 00 00 00 00 test....
514
+ #
515
+ # External buffer (created with ::for), and locked buffer can not be resized.
516
+ #
517
+ def resize: (Integer) -> self
518
+
519
+ # <!--
520
+ # rdoc-file=io_buffer.c
521
+ # - set_string(*args)
522
+ # -->
523
+ #
524
+ def set_string: (*untyped) -> untyped
525
+
526
+ # <!--
527
+ # rdoc-file=io_buffer.c
528
+ # - set_value(type, offset, value) -> offset
529
+ # -->
530
+ # Write to a buffer a `value` of `type` at `offset`. `type` should be one of
531
+ # symbols described in #get_value.
532
+ #
533
+ # buffer = IO::Buffer.new(8)
534
+ # # =>
535
+ # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
536
+ # # 0x00000000 00 00 00 00 00 00 00 00
537
+ # buffer.set_value(:U8, 1, 111)
538
+ # # => 1
539
+ # buffer
540
+ # # =>
541
+ # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
542
+ # # 0x00000000 00 6f 00 00 00 00 00 00 .o......
543
+ #
544
+ # Note that if the `type` is integer and `value` is Float, the implicit
545
+ # truncation is performed:
546
+ #
547
+ # buffer = IO::Buffer.new(8)
548
+ # buffer.set_value(:U32, 0, 2.5)
549
+ # buffer
550
+ # # =>
551
+ # # #<IO::Buffer 0x0000555f5c9a2d50+8 INTERNAL>
552
+ # # 0x00000000 00 00 00 02 00 00 00 00
553
+ # # ^^ the same as if we'd pass just integer 2
554
+ #
555
+ def set_value: (int_get_type | float_get_type, Integer offset, Float | Integer value) -> Integer
556
+
557
+ # <!--
558
+ # rdoc-file=io_buffer.c
559
+ # - size -> integer
560
+ # -->
561
+ # Returns the size of the buffer that was explicitly set (on creation with ::new
562
+ # or on #resize), or deduced on buffer's creation from string or file.
563
+ #
564
+ def size: () -> Integer
565
+
566
+ # <!--
567
+ # rdoc-file=io_buffer.c
568
+ # - slice(offset, length) -> io_buffer
569
+ # -->
570
+ # Produce another IO::Buffer which is a slice (or view into) the current one
571
+ # starting at `offset` bytes and going for `length` bytes.
572
+ #
573
+ # The slicing happens without copying of memory, and the slice keeps being
574
+ # associated with the original buffer's source (string, or file), if any.
575
+ #
576
+ # Raises RuntimeError if the <tt>offset+length<tt> is out of the current
577
+ # buffer's bounds.
578
+ #
579
+ # string = 'test'
580
+ # buffer = IO::Buffer.for(string)
581
+ #
582
+ # slice = buffer.slice(1, 2)
583
+ # # =>
584
+ # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
585
+ # # 0x00000000 65 73 es
586
+ #
587
+ # # Put "o" into 0s position of the slice
588
+ # slice.set_string('o', 0)
589
+ # slice
590
+ # # =>
591
+ # # #<IO::Buffer 0x00007fc3d34ebc49+2 SLICE>
592
+ # # 0x00000000 6f 73 os
593
+ #
594
+ # # it is also visible at position 1 of the original buffer
595
+ # buffer
596
+ # # =>
597
+ # # #<IO::Buffer 0x00007fc3d31e2d80+4 SLICE>
598
+ # # 0x00000000 74 6f 73 74 tost
599
+ #
600
+ # # ...and original string
601
+ # string
602
+ # # => tost
603
+ #
604
+ def slice: (Integer offset, Integer length) -> Buffer
605
+
606
+ # <!--
607
+ # rdoc-file=io_buffer.c
608
+ # - to_s -> string
609
+ # -->
610
+ # Short representation of the buffer. It includes the address, size and symbolic
611
+ # flags. This format is subject to change.
612
+ #
613
+ # puts IO::Buffer.new(4) # uses to_s internally
614
+ # # #<IO::Buffer 0x000055769f41b1a0+4 INTERNAL>
615
+ #
616
+ def to_s: () -> String
617
+
618
+ # <!--
619
+ # rdoc-file=io_buffer.c
620
+ # - transfer -> new_io_buffer
621
+ # -->
622
+ # Transfers ownership to a new buffer, deallocating the current one.
623
+ #
624
+ # buffer = IO::Buffer.new('test')
625
+ # other = buffer.transfer
626
+ # other
627
+ # # =>
628
+ # # #<IO::Buffer 0x00007f136a15f7b0+4 SLICE>
629
+ # # 0x00000000 74 65 73 74 test
630
+ # buffer
631
+ # # =>
632
+ # # #<IO::Buffer 0x0000000000000000+0 NULL>
633
+ # buffer.null?
634
+ # # => true
635
+ #
636
+ def transfer: () -> Buffer
637
+
638
+ # <!--
639
+ # rdoc-file=io_buffer.c
640
+ # - valid? -> true or false
641
+ # -->
642
+ # Returns whether the buffer data is accessible.
643
+ #
644
+ # A buffer becomes invalid if it is a slice of another buffer which has been
645
+ # freed.
646
+ #
647
+ def valid?: () -> bool
648
+
649
+ # <!--
650
+ # rdoc-file=io_buffer.c
651
+ # - write(p1, p2)
652
+ # -->
653
+ #
654
+ def write: (untyped, untyped) -> untyped
655
+
656
+ private
657
+
658
+ # <!--
659
+ # rdoc-file=io_buffer.c
660
+ # - IO::Buffer.new([size = DEFAULT_SIZE, [flags = 0]]) -> io_buffer
661
+ # -->
662
+ # Create a new zero-filled IO::Buffer of `size` bytes. By default, the buffer
663
+ # will be *internal*: directly allocated chunk of the memory. But if the
664
+ # requested `size` is more than OS-specific IO::Bufer::PAGE_SIZE, the buffer
665
+ # would be allocated using the virtual memory mechanism (anonymous `mmap` on
666
+ # Unix, `VirtualAlloc` on Windows). The behavior can be forced by passing
667
+ # IO::Buffer::MAPPED as a second parameter.
668
+ #
669
+ # Examples
670
+ #
671
+ # buffer = IO::Buffer.new(4)
672
+ # # =>
673
+ # # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL>
674
+ # # 0x00000000 00 00 00 00 ....
675
+ #
676
+ # buffer.get_string(0, 1) # => "\x00"
677
+ #
678
+ # buffer.set_string("test")
679
+ # buffer
680
+ # # =>
681
+ # # #<IO::Buffer 0x000055b34497ea10+4 INTERNAL>
682
+ # # 0x00000000 74 65 73 74 test
683
+ #
684
+ def initialize: (?Integer size, ?Integer flags) -> void
685
+
686
+ BIG_ENDIAN: Integer
687
+
688
+ DEFAULT_SIZE: Integer
689
+
690
+ EXTERNAL: Integer
691
+
692
+ HOST_ENDIAN: Integer
693
+
694
+ INTERNAL: Integer
695
+
696
+ LITTLE_ENDIAN: Integer
697
+
698
+ LOCKED: Integer
699
+
700
+ MAPPED: Integer
701
+
702
+ NETWORK_ENDIAN: Integer
703
+
704
+ PAGE_SIZE: Integer
705
+
706
+ PRIVATE: Integer
707
+
708
+ READONLY: Integer
709
+ end
710
+ end