sc2ai 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/data/sc2ai/protocol/common.proto +5 -5
  3. data/data/sc2ai/protocol/data.proto +22 -22
  4. data/data/sc2ai/protocol/debug.proto +24 -24
  5. data/data/sc2ai/protocol/error.proto +216 -215
  6. data/data/sc2ai/protocol/raw.proto +20 -20
  7. data/data/sc2ai/protocol/sc2api.proto +111 -111
  8. data/data/sc2ai/protocol/score.proto +3 -3
  9. data/data/sc2ai/protocol/spatial.proto +5 -5
  10. data/data/sc2ai/protocol/ui.proto +16 -16
  11. data/exe/sc2ai +0 -3
  12. data/lib/sc2ai/api/data.rb +3 -3
  13. data/lib/sc2ai/connection/connection_listener.rb +3 -3
  14. data/lib/sc2ai/connection/requests.rb +31 -35
  15. data/lib/sc2ai/connection/status_listener.rb +1 -1
  16. data/lib/sc2ai/connection.rb +1 -1
  17. data/lib/sc2ai/local_play/client.rb +2 -2
  18. data/lib/sc2ai/local_play/match.rb +7 -2
  19. data/lib/sc2ai/paths.rb +12 -2
  20. data/lib/sc2ai/player/actions.rb +54 -35
  21. data/lib/sc2ai/player/debug.rb +21 -21
  22. data/lib/sc2ai/player/game_state.rb +11 -18
  23. data/lib/sc2ai/player/geo.rb +54 -64
  24. data/lib/sc2ai/player/units.rb +16 -16
  25. data/lib/sc2ai/player.rb +103 -41
  26. data/lib/sc2ai/ports.rb +1 -1
  27. data/lib/sc2ai/protocol/_meta_documentation.rb +265 -265
  28. data/lib/sc2ai/protocol/common_pb.rb +3865 -15
  29. data/lib/sc2ai/protocol/data_pb.rb +9109 -18
  30. data/lib/sc2ai/protocol/debug_pb.rb +10437 -26
  31. data/lib/sc2ai/protocol/error_pb.rb +1086 -10
  32. data/lib/sc2ai/protocol/extensions/ability_remapable.rb +9 -9
  33. data/lib/sc2ai/protocol/extensions/action.rb +60 -0
  34. data/lib/sc2ai/protocol/extensions/point_2_d.rb +5 -0
  35. data/lib/sc2ai/protocol/extensions/position.rb +10 -35
  36. data/lib/sc2ai/protocol/extensions/power_source.rb +3 -0
  37. data/lib/sc2ai/protocol/extensions/unit.rb +19 -35
  38. data/lib/sc2ai/protocol/query_pb.rb +5025 -17
  39. data/lib/sc2ai/protocol/raw_pb.rb +18350 -27
  40. data/lib/sc2ai/protocol/sc2api_pb.rb +48420 -93
  41. data/lib/sc2ai/protocol/score_pb.rb +5968 -12
  42. data/lib/sc2ai/protocol/spatial_pb.rb +11944 -18
  43. data/lib/sc2ai/protocol/ui_pb.rb +12927 -28
  44. data/lib/sc2ai/unit_group/action_ext.rb +0 -2
  45. data/lib/sc2ai/unit_group/filter_ext.rb +10 -9
  46. data/lib/sc2ai/unit_group/geo_ext.rb +0 -2
  47. data/lib/sc2ai/unit_group.rb +1 -1
  48. data/lib/sc2ai/version.rb +2 -3
  49. data/lib/sc2ai.rb +10 -11
  50. data/lib/templates/ladderzip/bin/ladder.tt +0 -3
  51. data/lib/templates/new/api/common.proto +6 -6
  52. data/lib/templates/new/api/data.proto +23 -20
  53. data/lib/templates/new/api/debug.proto +25 -21
  54. data/lib/templates/new/api/error.proto +217 -215
  55. data/lib/templates/new/api/query.proto +1 -1
  56. data/lib/templates/new/api/raw.proto +16 -14
  57. data/lib/templates/new/api/sc2api.proto +108 -94
  58. data/lib/templates/new/api/score.proto +4 -3
  59. data/lib/templates/new/api/spatial.proto +6 -5
  60. data/lib/templates/new/api/ui.proto +17 -14
  61. data/lib/templates/new/boot.rb.tt +1 -1
  62. data/lib/templates/new/my_bot.rb.tt +1 -1
  63. data/lib/templates/new/run_example_match.rb.tt +2 -2
  64. data/sig/sc2ai.rbs +11005 -1926
  65. metadata +26 -21
  66. data/lib/sc2ai/overrides/kernel.rb +0 -33
  67. data/sig/minaswan.rbs +0 -10323
@@ -1,22 +1,3872 @@
1
+ # encoding: ascii-8bit
2
+ # rubocop:disable all
1
3
  # frozen_string_literal: true
2
- # Generated by the protocol buffer compiler. DO NOT EDIT!
3
- # source: sc2ai/protocol/common.proto
4
4
 
5
- require 'google/protobuf'
5
+ module Api
6
+ module Race
7
+ NO_RACE = 0
8
+ TERRAN = 1
9
+ ZERG = 2
10
+ PROTOSS = 3
11
+ RANDOM = 4
6
12
 
13
+ def self.lookup(val)
14
+ if val == 0
15
+ :NO_RACE
16
+ elsif val == 1
17
+ :TERRAN
18
+ elsif val == 2
19
+ :ZERG
20
+ elsif val == 3
21
+ :PROTOSS
22
+ elsif val == 4
23
+ :RANDOM
24
+ end
25
+ end
7
26
 
8
- descriptor_data = "\n\x1bsc2ai/protocol/common.proto\x12\x03\x41pi\"j\n\x10\x41vailableAbility\x12\x17\n\nability_id\x18\x01 \x01(\x05H\x00\x88\x01\x01\x12\x1b\n\x0erequires_point\x18\x02 \x01(\x08H\x01\x88\x01\x01\x42\r\n\x0b_ability_idB\x11\n\x0f_requires_point\"\x81\x01\n\tImageData\x12\x1b\n\x0e\x62its_per_pixel\x18\x01 \x01(\x05H\x00\x88\x01\x01\x12\x1f\n\x04size\x18\x02 \x01(\x0b\x32\x0c.Api.Size2DIH\x01\x88\x01\x01\x12\x11\n\x04\x64\x61ta\x18\x03 \x01(\x0cH\x02\x88\x01\x01\x42\x11\n\x0f_bits_per_pixelB\x07\n\x05_sizeB\x07\n\x05_data\"4\n\x06PointI\x12\x0e\n\x01x\x18\x01 \x01(\x05H\x00\x88\x01\x01\x12\x0e\n\x01y\x18\x02 \x01(\x05H\x01\x88\x01\x01\x42\x04\n\x02_xB\x04\n\x02_y\"V\n\nRectangleI\x12\x1c\n\x02p0\x18\x01 \x01(\x0b\x32\x0b.Api.PointIH\x00\x88\x01\x01\x12\x1c\n\x02p1\x18\x02 \x01(\x0b\x32\x0b.Api.PointIH\x01\x88\x01\x01\x42\x05\n\x03_p0B\x05\n\x03_p1\"5\n\x07Point2D\x12\x0e\n\x01x\x18\x01 \x01(\x02H\x00\x88\x01\x01\x12\x0e\n\x01y\x18\x02 \x01(\x02H\x01\x88\x01\x01\x42\x04\n\x02_xB\x04\n\x02_y\"I\n\x05Point\x12\x0e\n\x01x\x18\x01 \x01(\x02H\x00\x88\x01\x01\x12\x0e\n\x01y\x18\x02 \x01(\x02H\x01\x88\x01\x01\x12\x0e\n\x01z\x18\x03 \x01(\x02H\x02\x88\x01\x01\x42\x04\n\x02_xB\x04\n\x02_yB\x04\n\x02_z\"5\n\x07Size2DI\x12\x0e\n\x01x\x18\x01 \x01(\x05H\x00\x88\x01\x01\x12\x0e\n\x01y\x18\x02 \x01(\x05H\x01\x88\x01\x01\x42\x04\n\x02_xB\x04\n\x02_y*A\n\x04Race\x12\n\n\x06NoRace\x10\x00\x12\n\n\x06Terran\x10\x01\x12\x08\n\x04Zerg\x10\x02\x12\x0b\n\x07Protoss\x10\x03\x12\n\n\x06Random\x10\x04\x62\x06proto3"
27
+ def self.resolve(val)
28
+ if val == :NO_RACE
29
+ 0
30
+ elsif val == :TERRAN
31
+ 1
32
+ elsif val == :ZERG
33
+ 2
34
+ elsif val == :PROTOSS
35
+ 3
36
+ elsif val == :RANDOM
37
+ 4
38
+ end
39
+ end
40
+ end
9
41
 
10
- pool = Google::Protobuf::DescriptorPool.generated_pool
11
- pool.add_serialized_file(descriptor_data)
42
+ class AvailableAbility
43
+ def self.decode(buff)
44
+ allocate.decode_from(buff.b, 0, buff.bytesize)
45
+ end
12
46
 
13
- module Api
14
- AvailableAbility = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.AvailableAbility").msgclass
15
- ImageData = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.ImageData").msgclass
16
- PointI = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.PointI").msgclass
17
- RectangleI = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.RectangleI").msgclass
18
- Point2D = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.Point2D").msgclass
19
- Point = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.Point").msgclass
20
- Size2DI = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.Size2DI").msgclass
21
- Race = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Api.Race").enummodule
47
+ def self.encode(obj)
48
+ obj._encode("".b)
49
+ end
50
+ # required field readers
51
+
52
+ # optional field readers
53
+
54
+ attr_reader :ability_id
55
+
56
+ attr_reader :requires_point
57
+
58
+ # BEGIN writers for optional fields
59
+
60
+ def ability_id=(v)
61
+ unless -2_147_483_648 <= v && v <= 2_147_483_647
62
+ raise RangeError,
63
+ "Value (#{v}) for field ability_id is out of bounds (-2147483648..2147483647)"
64
+ end
65
+
66
+ @_bitmask |= 0x0000000000000001
67
+ @ability_id = v
68
+ end
69
+
70
+ def requires_point=(v)
71
+ @_bitmask |= 0x0000000000000002
72
+ @requires_point = v
73
+ end
74
+ # END writers for optional fields
75
+
76
+ def initialize(ability_id: nil, requires_point: nil)
77
+ @_bitmask = 0
78
+
79
+ if ability_id == nil
80
+ @ability_id = 0
81
+ else
82
+ unless -2_147_483_648 <= ability_id && ability_id <= 2_147_483_647
83
+ raise RangeError,
84
+ "Value (#{ability_id}) for field ability_id is out of bounds (-2147483648..2147483647)"
85
+ end
86
+ @_bitmask |= 0x0000000000000001
87
+ @ability_id = ability_id
88
+ end
89
+
90
+ if requires_point == nil
91
+ @requires_point = false
92
+ else
93
+ @_bitmask |= 0x0000000000000002
94
+ @requires_point = requires_point
95
+ end
96
+ end
97
+
98
+ def to_proto(_options = {})
99
+ self.class.encode(self)
100
+ end
101
+
102
+ def has_ability_id?
103
+ (@_bitmask & 0x0000000000000001) == 0x0000000000000001
104
+ end
105
+
106
+ def has_requires_point?
107
+ (@_bitmask & 0x0000000000000002) == 0x0000000000000002
108
+ end
109
+
110
+ def decode_from(buff, index, len)
111
+ @_bitmask = 0
112
+
113
+ @ability_id = 0
114
+ @requires_point = false
115
+
116
+ return self if index >= len
117
+ ## PULL_UINT64
118
+ tag =
119
+ if (byte0 = buff.getbyte(index)) < 0x80
120
+ index += 1
121
+ byte0
122
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
123
+ index += 2
124
+ (byte1 << 7) | (byte0 & 0x7F)
125
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
126
+ index += 3
127
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
128
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
129
+ index += 4
130
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
131
+ (byte0 & 0x7F)
132
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
133
+ index += 5
134
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
135
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
136
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
137
+ index += 6
138
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
139
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
140
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
141
+ index += 7
142
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
143
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
144
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
145
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
146
+ index += 8
147
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
148
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
149
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
150
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
151
+ index += 9
152
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
153
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
154
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
155
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
156
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
157
+ index += 10
158
+
159
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
160
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
161
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
162
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
163
+ else
164
+ raise "integer decoding error"
165
+ end
166
+
167
+ ## END PULL_UINT64
168
+
169
+ found = true
170
+ while true
171
+ # If we have looped around since the last found tag this one is
172
+ # unexpected, so discard it and continue.
173
+ if !found
174
+ wire_type = tag & 0x7
175
+ case wire_type
176
+ when 0
177
+ i = 0
178
+ while true
179
+ newbyte = buff.getbyte(index)
180
+ index += 1
181
+ break if newbyte.nil? || newbyte < 0x80
182
+ i += 1
183
+ break if i > 9
184
+ end
185
+ when 1
186
+ index += 8
187
+ when 2
188
+ ## PULL_BYTES
189
+ value =
190
+ if (byte0 = buff.getbyte(index)) < 0x80
191
+ index += 1
192
+ byte0
193
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
194
+ index += 2
195
+ (byte1 << 7) | (byte0 & 0x7F)
196
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
197
+ index += 3
198
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
199
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
200
+ index += 4
201
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
202
+ (byte0 & 0x7F)
203
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
204
+ index += 5
205
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) |
206
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
207
+ (byte0 & 0x7F)
208
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
209
+ index += 6
210
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) |
211
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
212
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
213
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
214
+ index += 7
215
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) |
216
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
217
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
218
+ (byte0 & 0x7F)
219
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
220
+ index += 8
221
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) |
222
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
223
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
224
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
225
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
226
+ index += 9
227
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) |
228
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
229
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
230
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
231
+ (byte0 & 0x7F)
232
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
233
+ index += 10
234
+
235
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
236
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
237
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
238
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
239
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
240
+ else
241
+ raise "integer decoding error"
242
+ end
243
+
244
+ buff.byteslice(index, value)
245
+ index += value
246
+
247
+ ## END PULL_BYTES
248
+ when 5
249
+ index += 4
250
+ else
251
+ raise "unknown wire type #{wire_type}"
252
+ end
253
+ return self if index >= len
254
+ ## PULL_UINT64
255
+ tag =
256
+ if (byte0 = buff.getbyte(index)) < 0x80
257
+ index += 1
258
+ byte0
259
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
260
+ index += 2
261
+ (byte1 << 7) | (byte0 & 0x7F)
262
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
263
+ index += 3
264
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
265
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
266
+ index += 4
267
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
268
+ (byte0 & 0x7F)
269
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
270
+ index += 5
271
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
272
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
273
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
274
+ index += 6
275
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
276
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
277
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
278
+ index += 7
279
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
280
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
281
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
282
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
283
+ index += 8
284
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
285
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
286
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
287
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
288
+ index += 9
289
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
290
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
291
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
292
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
293
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
294
+ index += 10
295
+
296
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
297
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
298
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
299
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
300
+ else
301
+ raise "integer decoding error"
302
+ end
303
+
304
+ ## END PULL_UINT64
305
+ end
306
+ found = false
307
+
308
+ if tag == 0x8
309
+ found = true
310
+ ## PULL_INT32
311
+ @ability_id =
312
+ if (byte0 = buff.getbyte(index)) < 0x80
313
+ index += 1
314
+ byte0
315
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
316
+ index += 2
317
+ (byte1 << 7) | (byte0 & 0x7F)
318
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
319
+ index += 3
320
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
321
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
322
+ index += 4
323
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
324
+ (byte0 & 0x7F)
325
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
326
+ index += 5
327
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
328
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
329
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
330
+ index += 6
331
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
332
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
333
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
334
+ index += 7
335
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
336
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
337
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
338
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
339
+ index += 8
340
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
341
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
342
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
343
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
344
+ index += 9
345
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
346
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
347
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
348
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
349
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
350
+ index += 10
351
+
352
+ # Negative 32 bit integers are still encoded with 10 bytes
353
+ # handle 2's complement negative numbers
354
+ # If the top bit is 1, then it must be negative.
355
+ -(
356
+ (
357
+ (
358
+ ~(
359
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
360
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
361
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
362
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
363
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
364
+ )
365
+ ) & 0xFFFF_FFFF
366
+ ) + 1
367
+ )
368
+ else
369
+ raise "integer decoding error"
370
+ end
371
+
372
+ ## END PULL_INT32
373
+
374
+ @_bitmask |= 0x0000000000000001
375
+ return self if index >= len
376
+ ## PULL_UINT64
377
+ tag =
378
+ if (byte0 = buff.getbyte(index)) < 0x80
379
+ index += 1
380
+ byte0
381
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
382
+ index += 2
383
+ (byte1 << 7) | (byte0 & 0x7F)
384
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
385
+ index += 3
386
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
387
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
388
+ index += 4
389
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
390
+ (byte0 & 0x7F)
391
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
392
+ index += 5
393
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
394
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
395
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
396
+ index += 6
397
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
398
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
399
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
400
+ index += 7
401
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
402
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
403
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
404
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
405
+ index += 8
406
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
407
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
408
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
409
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
410
+ index += 9
411
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
412
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
413
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
414
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
415
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
416
+ index += 10
417
+
418
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
419
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
420
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
421
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
422
+ else
423
+ raise "integer decoding error"
424
+ end
425
+
426
+ ## END PULL_UINT64
427
+ end
428
+ if tag == 0x10
429
+ found = true
430
+ ## PULL BOOLEAN
431
+ @requires_point = (buff.getbyte(index) == 1)
432
+ index += 1
433
+ ## END PULL BOOLEAN
434
+
435
+ @_bitmask |= 0x0000000000000002
436
+ return self if index >= len
437
+ ## PULL_UINT64
438
+ tag =
439
+ if (byte0 = buff.getbyte(index)) < 0x80
440
+ index += 1
441
+ byte0
442
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
443
+ index += 2
444
+ (byte1 << 7) | (byte0 & 0x7F)
445
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
446
+ index += 3
447
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
448
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
449
+ index += 4
450
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
451
+ (byte0 & 0x7F)
452
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
453
+ index += 5
454
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
455
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
456
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
457
+ index += 6
458
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
459
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
460
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
461
+ index += 7
462
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
463
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
464
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
465
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
466
+ index += 8
467
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
468
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
469
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
470
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
471
+ index += 9
472
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
473
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
474
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
475
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
476
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
477
+ index += 10
478
+
479
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
480
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
481
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
482
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
483
+ else
484
+ raise "integer decoding error"
485
+ end
486
+
487
+ ## END PULL_UINT64
488
+ end
489
+
490
+ return self if index >= len
491
+ end
492
+ end
493
+ def _encode(buff)
494
+ val = @ability_id
495
+ if val != 0
496
+ buff << 0x08
497
+
498
+ while val != 0
499
+ byte = val & 0x7F
500
+
501
+ val >>= 7
502
+ # This drops the top bits,
503
+ # Otherwise, with a signed right shift,
504
+ # we get infinity one bits at the top
505
+ val &= (1 << 57) - 1
506
+
507
+ byte |= 0x80 if val != 0
508
+ buff << byte
509
+ end
510
+ end
511
+
512
+ val = @requires_point
513
+ if val == true
514
+ buff << 0x10
515
+
516
+ buff << 1
517
+ elsif val == false
518
+ # Default value, encode nothing
519
+ else
520
+ raise "bool values should be true or false"
521
+ end
522
+
523
+ buff
524
+ end
525
+
526
+ def to_h
527
+ result = {}
528
+ result["ability_id".to_sym] = @ability_id
529
+ result["requires_point".to_sym] = @requires_point
530
+ result
531
+ end
532
+ end
533
+ class ImageData
534
+ def self.decode(buff)
535
+ allocate.decode_from(buff.b, 0, buff.bytesize)
536
+ end
537
+
538
+ def self.encode(obj)
539
+ obj._encode("".b)
540
+ end
541
+ # required field readers
542
+
543
+ # optional field readers
544
+
545
+ attr_reader :bits_per_pixel
546
+
547
+ attr_reader :size
548
+
549
+ attr_reader :data
550
+
551
+ # BEGIN writers for optional fields
552
+
553
+ def bits_per_pixel=(v)
554
+ unless -2_147_483_648 <= v && v <= 2_147_483_647
555
+ raise RangeError,
556
+ "Value (#{v}) for field bits_per_pixel is out of bounds (-2147483648..2147483647)"
557
+ end
558
+
559
+ @_bitmask |= 0x0000000000000001
560
+ @bits_per_pixel = v
561
+ end
562
+
563
+ def size=(v)
564
+ @_bitmask |= 0x0000000000000002
565
+ @size = v
566
+ end
567
+
568
+ def data=(v)
569
+ @_bitmask |= 0x0000000000000004
570
+ @data = v
571
+ end
572
+ # END writers for optional fields
573
+
574
+ def initialize(bits_per_pixel: nil, size: nil, data: nil)
575
+ @_bitmask = 0
576
+
577
+ if bits_per_pixel == nil
578
+ @bits_per_pixel = 0
579
+ else
580
+ unless -2_147_483_648 <= bits_per_pixel &&
581
+ bits_per_pixel <= 2_147_483_647
582
+ raise RangeError,
583
+ "Value (#{bits_per_pixel}) for field bits_per_pixel is out of bounds (-2147483648..2147483647)"
584
+ end
585
+ @_bitmask |= 0x0000000000000001
586
+ @bits_per_pixel = bits_per_pixel
587
+ end
588
+
589
+ if size == nil
590
+ @size = nil
591
+ else
592
+ @_bitmask |= 0x0000000000000002
593
+ @size = size
594
+ end
595
+
596
+ if data == nil
597
+ @data = ""
598
+ else
599
+ @_bitmask |= 0x0000000000000004
600
+ @data = data
601
+ end
602
+ end
603
+
604
+ def to_proto(_options = {})
605
+ self.class.encode(self)
606
+ end
607
+
608
+ def has_bits_per_pixel?
609
+ (@_bitmask & 0x0000000000000001) == 0x0000000000000001
610
+ end
611
+
612
+ def has_size?
613
+ (@_bitmask & 0x0000000000000002) == 0x0000000000000002
614
+ end
615
+
616
+ def has_data?
617
+ (@_bitmask & 0x0000000000000004) == 0x0000000000000004
618
+ end
619
+
620
+ def decode_from(buff, index, len)
621
+ @_bitmask = 0
622
+
623
+ @bits_per_pixel = 0
624
+ @size = nil
625
+ @data = ""
626
+
627
+ return self if index >= len
628
+ ## PULL_UINT64
629
+ tag =
630
+ if (byte0 = buff.getbyte(index)) < 0x80
631
+ index += 1
632
+ byte0
633
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
634
+ index += 2
635
+ (byte1 << 7) | (byte0 & 0x7F)
636
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
637
+ index += 3
638
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
639
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
640
+ index += 4
641
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
642
+ (byte0 & 0x7F)
643
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
644
+ index += 5
645
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
646
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
647
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
648
+ index += 6
649
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
650
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
651
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
652
+ index += 7
653
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
654
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
655
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
656
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
657
+ index += 8
658
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
659
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
660
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
661
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
662
+ index += 9
663
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
664
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
665
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
666
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
667
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
668
+ index += 10
669
+
670
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
671
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
672
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
673
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
674
+ else
675
+ raise "integer decoding error"
676
+ end
677
+
678
+ ## END PULL_UINT64
679
+
680
+ found = true
681
+ while true
682
+ # If we have looped around since the last found tag this one is
683
+ # unexpected, so discard it and continue.
684
+ if !found
685
+ wire_type = tag & 0x7
686
+ case wire_type
687
+ when 0
688
+ i = 0
689
+ while true
690
+ newbyte = buff.getbyte(index)
691
+ index += 1
692
+ break if newbyte.nil? || newbyte < 0x80
693
+ i += 1
694
+ break if i > 9
695
+ end
696
+ when 1
697
+ index += 8
698
+ when 2
699
+ ## PULL_BYTES
700
+ value =
701
+ if (byte0 = buff.getbyte(index)) < 0x80
702
+ index += 1
703
+ byte0
704
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
705
+ index += 2
706
+ (byte1 << 7) | (byte0 & 0x7F)
707
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
708
+ index += 3
709
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
710
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
711
+ index += 4
712
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
713
+ (byte0 & 0x7F)
714
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
715
+ index += 5
716
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) |
717
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
718
+ (byte0 & 0x7F)
719
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
720
+ index += 6
721
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) |
722
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
723
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
724
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
725
+ index += 7
726
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) |
727
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
728
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
729
+ (byte0 & 0x7F)
730
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
731
+ index += 8
732
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) |
733
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
734
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
735
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
736
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
737
+ index += 9
738
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) |
739
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
740
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
741
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
742
+ (byte0 & 0x7F)
743
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
744
+ index += 10
745
+
746
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
747
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
748
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
749
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
750
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
751
+ else
752
+ raise "integer decoding error"
753
+ end
754
+
755
+ buff.byteslice(index, value)
756
+ index += value
757
+
758
+ ## END PULL_BYTES
759
+ when 5
760
+ index += 4
761
+ else
762
+ raise "unknown wire type #{wire_type}"
763
+ end
764
+ return self if index >= len
765
+ ## PULL_UINT64
766
+ tag =
767
+ if (byte0 = buff.getbyte(index)) < 0x80
768
+ index += 1
769
+ byte0
770
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
771
+ index += 2
772
+ (byte1 << 7) | (byte0 & 0x7F)
773
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
774
+ index += 3
775
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
776
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
777
+ index += 4
778
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
779
+ (byte0 & 0x7F)
780
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
781
+ index += 5
782
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
783
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
784
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
785
+ index += 6
786
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
787
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
788
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
789
+ index += 7
790
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
791
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
792
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
793
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
794
+ index += 8
795
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
796
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
797
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
798
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
799
+ index += 9
800
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
801
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
802
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
803
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
804
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
805
+ index += 10
806
+
807
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
808
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
809
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
810
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
811
+ else
812
+ raise "integer decoding error"
813
+ end
814
+
815
+ ## END PULL_UINT64
816
+ end
817
+ found = false
818
+
819
+ if tag == 0x8
820
+ found = true
821
+ ## PULL_INT32
822
+ @bits_per_pixel =
823
+ if (byte0 = buff.getbyte(index)) < 0x80
824
+ index += 1
825
+ byte0
826
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
827
+ index += 2
828
+ (byte1 << 7) | (byte0 & 0x7F)
829
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
830
+ index += 3
831
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
832
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
833
+ index += 4
834
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
835
+ (byte0 & 0x7F)
836
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
837
+ index += 5
838
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
839
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
840
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
841
+ index += 6
842
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
843
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
844
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
845
+ index += 7
846
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
847
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
848
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
849
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
850
+ index += 8
851
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
852
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
853
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
854
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
855
+ index += 9
856
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
857
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
858
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
859
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
860
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
861
+ index += 10
862
+
863
+ # Negative 32 bit integers are still encoded with 10 bytes
864
+ # handle 2's complement negative numbers
865
+ # If the top bit is 1, then it must be negative.
866
+ -(
867
+ (
868
+ (
869
+ ~(
870
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
871
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
872
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
873
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
874
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
875
+ )
876
+ ) & 0xFFFF_FFFF
877
+ ) + 1
878
+ )
879
+ else
880
+ raise "integer decoding error"
881
+ end
882
+
883
+ ## END PULL_INT32
884
+
885
+ @_bitmask |= 0x0000000000000001
886
+ return self if index >= len
887
+ ## PULL_UINT64
888
+ tag =
889
+ if (byte0 = buff.getbyte(index)) < 0x80
890
+ index += 1
891
+ byte0
892
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
893
+ index += 2
894
+ (byte1 << 7) | (byte0 & 0x7F)
895
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
896
+ index += 3
897
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
898
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
899
+ index += 4
900
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
901
+ (byte0 & 0x7F)
902
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
903
+ index += 5
904
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
905
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
906
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
907
+ index += 6
908
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
909
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
910
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
911
+ index += 7
912
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
913
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
914
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
915
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
916
+ index += 8
917
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
918
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
919
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
920
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
921
+ index += 9
922
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
923
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
924
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
925
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
926
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
927
+ index += 10
928
+
929
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
930
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
931
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
932
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
933
+ else
934
+ raise "integer decoding error"
935
+ end
936
+
937
+ ## END PULL_UINT64
938
+ end
939
+ if tag == 0x12
940
+ found = true
941
+ ## PULL_MESSAGE
942
+ ## PULL_UINT64
943
+ msg_len =
944
+ if (byte0 = buff.getbyte(index)) < 0x80
945
+ index += 1
946
+ byte0
947
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
948
+ index += 2
949
+ (byte1 << 7) | (byte0 & 0x7F)
950
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
951
+ index += 3
952
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
953
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
954
+ index += 4
955
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
956
+ (byte0 & 0x7F)
957
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
958
+ index += 5
959
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
960
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
961
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
962
+ index += 6
963
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
964
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
965
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
966
+ index += 7
967
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
968
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
969
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
970
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
971
+ index += 8
972
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
973
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
974
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
975
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
976
+ index += 9
977
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
978
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
979
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
980
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
981
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
982
+ index += 10
983
+
984
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
985
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
986
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
987
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
988
+ else
989
+ raise "integer decoding error"
990
+ end
991
+
992
+ ## END PULL_UINT64
993
+
994
+ @size =
995
+ Api::Size2DI.allocate.decode_from(buff, index, index += msg_len)
996
+ ## END PULL_MESSAGE
997
+
998
+ @_bitmask |= 0x0000000000000002
999
+ return self if index >= len
1000
+ ## PULL_UINT64
1001
+ tag =
1002
+ if (byte0 = buff.getbyte(index)) < 0x80
1003
+ index += 1
1004
+ byte0
1005
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1006
+ index += 2
1007
+ (byte1 << 7) | (byte0 & 0x7F)
1008
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1009
+ index += 3
1010
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1011
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1012
+ index += 4
1013
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1014
+ (byte0 & 0x7F)
1015
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1016
+ index += 5
1017
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1018
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1019
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1020
+ index += 6
1021
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1022
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1023
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1024
+ index += 7
1025
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1026
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1027
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1028
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1029
+ index += 8
1030
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1031
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1032
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1033
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1034
+ index += 9
1035
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1036
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1037
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1038
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1039
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1040
+ index += 10
1041
+
1042
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1043
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1044
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1045
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1046
+ else
1047
+ raise "integer decoding error"
1048
+ end
1049
+
1050
+ ## END PULL_UINT64
1051
+ end
1052
+ if tag == 0x1a
1053
+ found = true
1054
+ ## PULL_BYTES
1055
+ value =
1056
+ if (byte0 = buff.getbyte(index)) < 0x80
1057
+ index += 1
1058
+ byte0
1059
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1060
+ index += 2
1061
+ (byte1 << 7) | (byte0 & 0x7F)
1062
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1063
+ index += 3
1064
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1065
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1066
+ index += 4
1067
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1068
+ (byte0 & 0x7F)
1069
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1070
+ index += 5
1071
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1072
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1073
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1074
+ index += 6
1075
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1076
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1077
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1078
+ index += 7
1079
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1080
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1081
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1082
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1083
+ index += 8
1084
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1085
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1086
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1087
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1088
+ index += 9
1089
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1090
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1091
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1092
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1093
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1094
+ index += 10
1095
+
1096
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1097
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1098
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1099
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1100
+ else
1101
+ raise "integer decoding error"
1102
+ end
1103
+
1104
+ @data = buff.byteslice(index, value)
1105
+ index += value
1106
+
1107
+ ## END PULL_BYTES
1108
+
1109
+ @_bitmask |= 0x0000000000000004
1110
+ return self if index >= len
1111
+ ## PULL_UINT64
1112
+ tag =
1113
+ if (byte0 = buff.getbyte(index)) < 0x80
1114
+ index += 1
1115
+ byte0
1116
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1117
+ index += 2
1118
+ (byte1 << 7) | (byte0 & 0x7F)
1119
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1120
+ index += 3
1121
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1122
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1123
+ index += 4
1124
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1125
+ (byte0 & 0x7F)
1126
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1127
+ index += 5
1128
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1129
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1130
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1131
+ index += 6
1132
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1133
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1134
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1135
+ index += 7
1136
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1137
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1138
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1139
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1140
+ index += 8
1141
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1142
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1143
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1144
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1145
+ index += 9
1146
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1147
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1148
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1149
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1150
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1151
+ index += 10
1152
+
1153
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1154
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1155
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1156
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1157
+ else
1158
+ raise "integer decoding error"
1159
+ end
1160
+
1161
+ ## END PULL_UINT64
1162
+ end
1163
+
1164
+ return self if index >= len
1165
+ end
1166
+ end
1167
+ def _encode(buff)
1168
+ val = @bits_per_pixel
1169
+ if val != 0
1170
+ buff << 0x08
1171
+
1172
+ while val != 0
1173
+ byte = val & 0x7F
1174
+
1175
+ val >>= 7
1176
+ # This drops the top bits,
1177
+ # Otherwise, with a signed right shift,
1178
+ # we get infinity one bits at the top
1179
+ val &= (1 << 57) - 1
1180
+
1181
+ byte |= 0x80 if val != 0
1182
+ buff << byte
1183
+ end
1184
+ end
1185
+
1186
+ val = @size
1187
+ if val
1188
+ buff << 0x12
1189
+
1190
+ # Save the buffer size before appending the submessage
1191
+ current_len = buff.bytesize
1192
+
1193
+ # Write a single dummy byte to later store encoded length
1194
+ buff << 42 # "*"
1195
+ val._encode(buff)
1196
+
1197
+ # Calculate the submessage's size
1198
+ submessage_size = buff.bytesize - current_len - 1
1199
+
1200
+ # Hope the size fits in one byte
1201
+ byte = submessage_size & 0x7F
1202
+ submessage_size >>= 7
1203
+ byte |= 0x80 if submessage_size > 0
1204
+ buff.setbyte(current_len, byte)
1205
+
1206
+ # If the sub message was bigger
1207
+ if submessage_size > 0
1208
+ current_len += 1
1209
+
1210
+ # compute how much we need to shift
1211
+ encoded_int_len = 0
1212
+ remaining_size = submessage_size
1213
+ while remaining_size != 0
1214
+ remaining_size >>= 7
1215
+ encoded_int_len += 1
1216
+ end
1217
+
1218
+ # Make space in the string with dummy bytes
1219
+ buff.bytesplice(current_len, 0, "*********", 0, encoded_int_len)
1220
+
1221
+ # Overwrite the dummy bytes with the encoded length
1222
+ while submessage_size != 0
1223
+ byte = submessage_size & 0x7F
1224
+ submessage_size >>= 7
1225
+ byte |= 0x80 if submessage_size > 0
1226
+ buff.setbyte(current_len, byte)
1227
+ current_len += 1
1228
+ end
1229
+ end
1230
+
1231
+ buff
1232
+ end
1233
+
1234
+ val = @data
1235
+ if ((bs = val.bytesize) > 0)
1236
+ buff << 0x1a
1237
+ len = bs
1238
+ while len != 0
1239
+ byte = len & 0x7F
1240
+ len >>= 7
1241
+ byte |= 0x80 if len > 0
1242
+ buff << byte
1243
+ end
1244
+
1245
+ buff.concat(val.b)
1246
+ end
1247
+
1248
+ buff
1249
+ end
1250
+
1251
+ def to_h
1252
+ result = {}
1253
+ result["bits_per_pixel".to_sym] = @bits_per_pixel
1254
+ result["size".to_sym] = @size.to_h
1255
+ result["data".to_sym] = @data
1256
+ result
1257
+ end
1258
+ end
1259
+ class PointI
1260
+ def self.decode(buff)
1261
+ allocate.decode_from(buff.b, 0, buff.bytesize)
1262
+ end
1263
+
1264
+ def self.encode(obj)
1265
+ obj._encode("".b)
1266
+ end
1267
+ # required field readers
1268
+
1269
+ # optional field readers
1270
+
1271
+ attr_reader :x
1272
+
1273
+ attr_reader :y
1274
+
1275
+ # BEGIN writers for optional fields
1276
+
1277
+ def x=(v)
1278
+ unless -2_147_483_648 <= v && v <= 2_147_483_647
1279
+ raise RangeError,
1280
+ "Value (#{v}) for field x is out of bounds (-2147483648..2147483647)"
1281
+ end
1282
+
1283
+ @_bitmask |= 0x0000000000000001
1284
+ @x = v
1285
+ end
1286
+
1287
+ def y=(v)
1288
+ unless -2_147_483_648 <= v && v <= 2_147_483_647
1289
+ raise RangeError,
1290
+ "Value (#{v}) for field y is out of bounds (-2147483648..2147483647)"
1291
+ end
1292
+
1293
+ @_bitmask |= 0x0000000000000002
1294
+ @y = v
1295
+ end
1296
+ # END writers for optional fields
1297
+
1298
+ def initialize(x: nil, y: nil)
1299
+ @_bitmask = 0
1300
+
1301
+ if x == nil
1302
+ @x = 0
1303
+ else
1304
+ unless -2_147_483_648 <= x && x <= 2_147_483_647
1305
+ raise RangeError,
1306
+ "Value (#{x}) for field x is out of bounds (-2147483648..2147483647)"
1307
+ end
1308
+ @_bitmask |= 0x0000000000000001
1309
+ @x = x
1310
+ end
1311
+
1312
+ if y == nil
1313
+ @y = 0
1314
+ else
1315
+ unless -2_147_483_648 <= y && y <= 2_147_483_647
1316
+ raise RangeError,
1317
+ "Value (#{y}) for field y is out of bounds (-2147483648..2147483647)"
1318
+ end
1319
+ @_bitmask |= 0x0000000000000002
1320
+ @y = y
1321
+ end
1322
+ end
1323
+
1324
+ def to_proto(_options = {})
1325
+ self.class.encode(self)
1326
+ end
1327
+
1328
+ def has_x?
1329
+ (@_bitmask & 0x0000000000000001) == 0x0000000000000001
1330
+ end
1331
+
1332
+ def has_y?
1333
+ (@_bitmask & 0x0000000000000002) == 0x0000000000000002
1334
+ end
1335
+
1336
+ def decode_from(buff, index, len)
1337
+ @_bitmask = 0
1338
+
1339
+ @x = 0
1340
+ @y = 0
1341
+
1342
+ return self if index >= len
1343
+ ## PULL_UINT64
1344
+ tag =
1345
+ if (byte0 = buff.getbyte(index)) < 0x80
1346
+ index += 1
1347
+ byte0
1348
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1349
+ index += 2
1350
+ (byte1 << 7) | (byte0 & 0x7F)
1351
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1352
+ index += 3
1353
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1354
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1355
+ index += 4
1356
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1357
+ (byte0 & 0x7F)
1358
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1359
+ index += 5
1360
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1361
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1362
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1363
+ index += 6
1364
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1365
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1366
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1367
+ index += 7
1368
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1369
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1370
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1371
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1372
+ index += 8
1373
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1374
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1375
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1376
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1377
+ index += 9
1378
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1379
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1380
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1381
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1382
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1383
+ index += 10
1384
+
1385
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1386
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1387
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1388
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1389
+ else
1390
+ raise "integer decoding error"
1391
+ end
1392
+
1393
+ ## END PULL_UINT64
1394
+
1395
+ found = true
1396
+ while true
1397
+ # If we have looped around since the last found tag this one is
1398
+ # unexpected, so discard it and continue.
1399
+ if !found
1400
+ wire_type = tag & 0x7
1401
+ case wire_type
1402
+ when 0
1403
+ i = 0
1404
+ while true
1405
+ newbyte = buff.getbyte(index)
1406
+ index += 1
1407
+ break if newbyte.nil? || newbyte < 0x80
1408
+ i += 1
1409
+ break if i > 9
1410
+ end
1411
+ when 1
1412
+ index += 8
1413
+ when 2
1414
+ ## PULL_BYTES
1415
+ value =
1416
+ if (byte0 = buff.getbyte(index)) < 0x80
1417
+ index += 1
1418
+ byte0
1419
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1420
+ index += 2
1421
+ (byte1 << 7) | (byte0 & 0x7F)
1422
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1423
+ index += 3
1424
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1425
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1426
+ index += 4
1427
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1428
+ (byte0 & 0x7F)
1429
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1430
+ index += 5
1431
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) |
1432
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1433
+ (byte0 & 0x7F)
1434
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1435
+ index += 6
1436
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) |
1437
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1438
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1439
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1440
+ index += 7
1441
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) |
1442
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1443
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1444
+ (byte0 & 0x7F)
1445
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1446
+ index += 8
1447
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) |
1448
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1449
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1450
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1451
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1452
+ index += 9
1453
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) |
1454
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1455
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1456
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1457
+ (byte0 & 0x7F)
1458
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1459
+ index += 10
1460
+
1461
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
1462
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1463
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1464
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1465
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1466
+ else
1467
+ raise "integer decoding error"
1468
+ end
1469
+
1470
+ buff.byteslice(index, value)
1471
+ index += value
1472
+
1473
+ ## END PULL_BYTES
1474
+ when 5
1475
+ index += 4
1476
+ else
1477
+ raise "unknown wire type #{wire_type}"
1478
+ end
1479
+ return self if index >= len
1480
+ ## PULL_UINT64
1481
+ tag =
1482
+ if (byte0 = buff.getbyte(index)) < 0x80
1483
+ index += 1
1484
+ byte0
1485
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1486
+ index += 2
1487
+ (byte1 << 7) | (byte0 & 0x7F)
1488
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1489
+ index += 3
1490
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1491
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1492
+ index += 4
1493
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1494
+ (byte0 & 0x7F)
1495
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1496
+ index += 5
1497
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1498
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1499
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1500
+ index += 6
1501
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1502
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1503
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1504
+ index += 7
1505
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1506
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1507
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1508
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1509
+ index += 8
1510
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1511
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1512
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1513
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1514
+ index += 9
1515
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1516
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1517
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1518
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1519
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1520
+ index += 10
1521
+
1522
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1523
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1524
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1525
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1526
+ else
1527
+ raise "integer decoding error"
1528
+ end
1529
+
1530
+ ## END PULL_UINT64
1531
+ end
1532
+ found = false
1533
+
1534
+ if tag == 0x8
1535
+ found = true
1536
+ ## PULL_INT32
1537
+ @x =
1538
+ if (byte0 = buff.getbyte(index)) < 0x80
1539
+ index += 1
1540
+ byte0
1541
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1542
+ index += 2
1543
+ (byte1 << 7) | (byte0 & 0x7F)
1544
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1545
+ index += 3
1546
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1547
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1548
+ index += 4
1549
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1550
+ (byte0 & 0x7F)
1551
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1552
+ index += 5
1553
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1554
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1555
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1556
+ index += 6
1557
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1558
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1559
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1560
+ index += 7
1561
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1562
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1563
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1564
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1565
+ index += 8
1566
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1567
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1568
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1569
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1570
+ index += 9
1571
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1572
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1573
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1574
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1575
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1576
+ index += 10
1577
+
1578
+ # Negative 32 bit integers are still encoded with 10 bytes
1579
+ # handle 2's complement negative numbers
1580
+ # If the top bit is 1, then it must be negative.
1581
+ -(
1582
+ (
1583
+ (
1584
+ ~(
1585
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
1586
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1587
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1588
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1589
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1590
+ )
1591
+ ) & 0xFFFF_FFFF
1592
+ ) + 1
1593
+ )
1594
+ else
1595
+ raise "integer decoding error"
1596
+ end
1597
+
1598
+ ## END PULL_INT32
1599
+
1600
+ @_bitmask |= 0x0000000000000001
1601
+ return self if index >= len
1602
+ ## PULL_UINT64
1603
+ tag =
1604
+ if (byte0 = buff.getbyte(index)) < 0x80
1605
+ index += 1
1606
+ byte0
1607
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1608
+ index += 2
1609
+ (byte1 << 7) | (byte0 & 0x7F)
1610
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1611
+ index += 3
1612
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1613
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1614
+ index += 4
1615
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1616
+ (byte0 & 0x7F)
1617
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1618
+ index += 5
1619
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1620
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1621
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1622
+ index += 6
1623
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1624
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1625
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1626
+ index += 7
1627
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1628
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1629
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1630
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1631
+ index += 8
1632
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1633
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1634
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1635
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1636
+ index += 9
1637
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1638
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1639
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1640
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1641
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1642
+ index += 10
1643
+
1644
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1645
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1646
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1647
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1648
+ else
1649
+ raise "integer decoding error"
1650
+ end
1651
+
1652
+ ## END PULL_UINT64
1653
+ end
1654
+ if tag == 0x10
1655
+ found = true
1656
+ ## PULL_INT32
1657
+ @y =
1658
+ if (byte0 = buff.getbyte(index)) < 0x80
1659
+ index += 1
1660
+ byte0
1661
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1662
+ index += 2
1663
+ (byte1 << 7) | (byte0 & 0x7F)
1664
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1665
+ index += 3
1666
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1667
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1668
+ index += 4
1669
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1670
+ (byte0 & 0x7F)
1671
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1672
+ index += 5
1673
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1674
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1675
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1676
+ index += 6
1677
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1678
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1679
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1680
+ index += 7
1681
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1682
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1683
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1684
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1685
+ index += 8
1686
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1687
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1688
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1689
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1690
+ index += 9
1691
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1692
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1693
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1694
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1695
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1696
+ index += 10
1697
+
1698
+ # Negative 32 bit integers are still encoded with 10 bytes
1699
+ # handle 2's complement negative numbers
1700
+ # If the top bit is 1, then it must be negative.
1701
+ -(
1702
+ (
1703
+ (
1704
+ ~(
1705
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
1706
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1707
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1708
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1709
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1710
+ )
1711
+ ) & 0xFFFF_FFFF
1712
+ ) + 1
1713
+ )
1714
+ else
1715
+ raise "integer decoding error"
1716
+ end
1717
+
1718
+ ## END PULL_INT32
1719
+
1720
+ @_bitmask |= 0x0000000000000002
1721
+ return self if index >= len
1722
+ ## PULL_UINT64
1723
+ tag =
1724
+ if (byte0 = buff.getbyte(index)) < 0x80
1725
+ index += 1
1726
+ byte0
1727
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1728
+ index += 2
1729
+ (byte1 << 7) | (byte0 & 0x7F)
1730
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1731
+ index += 3
1732
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1733
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1734
+ index += 4
1735
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1736
+ (byte0 & 0x7F)
1737
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1738
+ index += 5
1739
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1740
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1741
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1742
+ index += 6
1743
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1744
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1745
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1746
+ index += 7
1747
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1748
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1749
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1750
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1751
+ index += 8
1752
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1753
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1754
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1755
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1756
+ index += 9
1757
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1758
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1759
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1760
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1761
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1762
+ index += 10
1763
+
1764
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1765
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1766
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1767
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1768
+ else
1769
+ raise "integer decoding error"
1770
+ end
1771
+
1772
+ ## END PULL_UINT64
1773
+ end
1774
+
1775
+ return self if index >= len
1776
+ end
1777
+ end
1778
+ def _encode(buff)
1779
+ val = @x
1780
+ if val != 0
1781
+ buff << 0x08
1782
+
1783
+ while val != 0
1784
+ byte = val & 0x7F
1785
+
1786
+ val >>= 7
1787
+ # This drops the top bits,
1788
+ # Otherwise, with a signed right shift,
1789
+ # we get infinity one bits at the top
1790
+ val &= (1 << 57) - 1
1791
+
1792
+ byte |= 0x80 if val != 0
1793
+ buff << byte
1794
+ end
1795
+ end
1796
+
1797
+ val = @y
1798
+ if val != 0
1799
+ buff << 0x10
1800
+
1801
+ while val != 0
1802
+ byte = val & 0x7F
1803
+
1804
+ val >>= 7
1805
+ # This drops the top bits,
1806
+ # Otherwise, with a signed right shift,
1807
+ # we get infinity one bits at the top
1808
+ val &= (1 << 57) - 1
1809
+
1810
+ byte |= 0x80 if val != 0
1811
+ buff << byte
1812
+ end
1813
+ end
1814
+
1815
+ buff
1816
+ end
1817
+
1818
+ def to_h
1819
+ result = {}
1820
+ result["x".to_sym] = @x
1821
+ result["y".to_sym] = @y
1822
+ result
1823
+ end
1824
+ end
1825
+ class RectangleI
1826
+ def self.decode(buff)
1827
+ allocate.decode_from(buff.b, 0, buff.bytesize)
1828
+ end
1829
+
1830
+ def self.encode(obj)
1831
+ obj._encode("".b)
1832
+ end
1833
+ # required field readers
1834
+
1835
+ # optional field readers
1836
+
1837
+ attr_reader :p0
1838
+
1839
+ attr_reader :p1
1840
+
1841
+ # BEGIN writers for optional fields
1842
+
1843
+ def p0=(v)
1844
+ @_bitmask |= 0x0000000000000001
1845
+ @p0 = v
1846
+ end
1847
+
1848
+ def p1=(v)
1849
+ @_bitmask |= 0x0000000000000002
1850
+ @p1 = v
1851
+ end
1852
+ # END writers for optional fields
1853
+
1854
+ def initialize(p0: nil, p1: nil)
1855
+ @_bitmask = 0
1856
+
1857
+ if p0 == nil
1858
+ @p0 = nil
1859
+ else
1860
+ @_bitmask |= 0x0000000000000001
1861
+ @p0 = p0
1862
+ end
1863
+
1864
+ if p1 == nil
1865
+ @p1 = nil
1866
+ else
1867
+ @_bitmask |= 0x0000000000000002
1868
+ @p1 = p1
1869
+ end
1870
+ end
1871
+
1872
+ def to_proto(_options = {})
1873
+ self.class.encode(self)
1874
+ end
1875
+
1876
+ def has_p0?
1877
+ (@_bitmask & 0x0000000000000001) == 0x0000000000000001
1878
+ end
1879
+
1880
+ def has_p1?
1881
+ (@_bitmask & 0x0000000000000002) == 0x0000000000000002
1882
+ end
1883
+
1884
+ def decode_from(buff, index, len)
1885
+ @_bitmask = 0
1886
+
1887
+ @p0 = nil
1888
+ @p1 = nil
1889
+
1890
+ return self if index >= len
1891
+ ## PULL_UINT64
1892
+ tag =
1893
+ if (byte0 = buff.getbyte(index)) < 0x80
1894
+ index += 1
1895
+ byte0
1896
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1897
+ index += 2
1898
+ (byte1 << 7) | (byte0 & 0x7F)
1899
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1900
+ index += 3
1901
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1902
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1903
+ index += 4
1904
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1905
+ (byte0 & 0x7F)
1906
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1907
+ index += 5
1908
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1909
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1910
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1911
+ index += 6
1912
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1913
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1914
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1915
+ index += 7
1916
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1917
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1918
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1919
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1920
+ index += 8
1921
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1922
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1923
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1924
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
1925
+ index += 9
1926
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
1927
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1928
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1929
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1930
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
1931
+ index += 10
1932
+
1933
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
1934
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
1935
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1936
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1937
+ else
1938
+ raise "integer decoding error"
1939
+ end
1940
+
1941
+ ## END PULL_UINT64
1942
+
1943
+ found = true
1944
+ while true
1945
+ # If we have looped around since the last found tag this one is
1946
+ # unexpected, so discard it and continue.
1947
+ if !found
1948
+ wire_type = tag & 0x7
1949
+ case wire_type
1950
+ when 0
1951
+ i = 0
1952
+ while true
1953
+ newbyte = buff.getbyte(index)
1954
+ index += 1
1955
+ break if newbyte.nil? || newbyte < 0x80
1956
+ i += 1
1957
+ break if i > 9
1958
+ end
1959
+ when 1
1960
+ index += 8
1961
+ when 2
1962
+ ## PULL_BYTES
1963
+ value =
1964
+ if (byte0 = buff.getbyte(index)) < 0x80
1965
+ index += 1
1966
+ byte0
1967
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
1968
+ index += 2
1969
+ (byte1 << 7) | (byte0 & 0x7F)
1970
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
1971
+ index += 3
1972
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1973
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
1974
+ index += 4
1975
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1976
+ (byte0 & 0x7F)
1977
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
1978
+ index += 5
1979
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) |
1980
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1981
+ (byte0 & 0x7F)
1982
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
1983
+ index += 6
1984
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) |
1985
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1986
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1987
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
1988
+ index += 7
1989
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) |
1990
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
1991
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
1992
+ (byte0 & 0x7F)
1993
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
1994
+ index += 8
1995
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) |
1996
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
1997
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
1998
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
1999
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2000
+ index += 9
2001
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) |
2002
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2003
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2004
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2005
+ (byte0 & 0x7F)
2006
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2007
+ index += 10
2008
+
2009
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
2010
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2011
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2012
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2013
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2014
+ else
2015
+ raise "integer decoding error"
2016
+ end
2017
+
2018
+ buff.byteslice(index, value)
2019
+ index += value
2020
+
2021
+ ## END PULL_BYTES
2022
+ when 5
2023
+ index += 4
2024
+ else
2025
+ raise "unknown wire type #{wire_type}"
2026
+ end
2027
+ return self if index >= len
2028
+ ## PULL_UINT64
2029
+ tag =
2030
+ if (byte0 = buff.getbyte(index)) < 0x80
2031
+ index += 1
2032
+ byte0
2033
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2034
+ index += 2
2035
+ (byte1 << 7) | (byte0 & 0x7F)
2036
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2037
+ index += 3
2038
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2039
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2040
+ index += 4
2041
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2042
+ (byte0 & 0x7F)
2043
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2044
+ index += 5
2045
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2046
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2047
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2048
+ index += 6
2049
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2050
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2051
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2052
+ index += 7
2053
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2054
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2055
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2056
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2057
+ index += 8
2058
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2059
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2060
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2061
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2062
+ index += 9
2063
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2064
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2065
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2066
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2067
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2068
+ index += 10
2069
+
2070
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2071
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2072
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2073
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2074
+ else
2075
+ raise "integer decoding error"
2076
+ end
2077
+
2078
+ ## END PULL_UINT64
2079
+ end
2080
+ found = false
2081
+
2082
+ if tag == 0xa
2083
+ found = true
2084
+ ## PULL_MESSAGE
2085
+ ## PULL_UINT64
2086
+ msg_len =
2087
+ if (byte0 = buff.getbyte(index)) < 0x80
2088
+ index += 1
2089
+ byte0
2090
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2091
+ index += 2
2092
+ (byte1 << 7) | (byte0 & 0x7F)
2093
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2094
+ index += 3
2095
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2096
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2097
+ index += 4
2098
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2099
+ (byte0 & 0x7F)
2100
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2101
+ index += 5
2102
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2103
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2104
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2105
+ index += 6
2106
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2107
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2108
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2109
+ index += 7
2110
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2111
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2112
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2113
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2114
+ index += 8
2115
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2116
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2117
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2118
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2119
+ index += 9
2120
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2121
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2122
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2123
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2124
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2125
+ index += 10
2126
+
2127
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2128
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2129
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2130
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2131
+ else
2132
+ raise "integer decoding error"
2133
+ end
2134
+
2135
+ ## END PULL_UINT64
2136
+
2137
+ @p0 = Api::PointI.allocate.decode_from(buff, index, index += msg_len)
2138
+ ## END PULL_MESSAGE
2139
+
2140
+ @_bitmask |= 0x0000000000000001
2141
+ return self if index >= len
2142
+ ## PULL_UINT64
2143
+ tag =
2144
+ if (byte0 = buff.getbyte(index)) < 0x80
2145
+ index += 1
2146
+ byte0
2147
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2148
+ index += 2
2149
+ (byte1 << 7) | (byte0 & 0x7F)
2150
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2151
+ index += 3
2152
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2153
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2154
+ index += 4
2155
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2156
+ (byte0 & 0x7F)
2157
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2158
+ index += 5
2159
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2160
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2161
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2162
+ index += 6
2163
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2164
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2165
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2166
+ index += 7
2167
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2168
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2169
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2170
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2171
+ index += 8
2172
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2173
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2174
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2175
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2176
+ index += 9
2177
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2178
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2179
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2180
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2181
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2182
+ index += 10
2183
+
2184
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2185
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2186
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2187
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2188
+ else
2189
+ raise "integer decoding error"
2190
+ end
2191
+
2192
+ ## END PULL_UINT64
2193
+ end
2194
+ if tag == 0x12
2195
+ found = true
2196
+ ## PULL_MESSAGE
2197
+ ## PULL_UINT64
2198
+ msg_len =
2199
+ if (byte0 = buff.getbyte(index)) < 0x80
2200
+ index += 1
2201
+ byte0
2202
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2203
+ index += 2
2204
+ (byte1 << 7) | (byte0 & 0x7F)
2205
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2206
+ index += 3
2207
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2208
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2209
+ index += 4
2210
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2211
+ (byte0 & 0x7F)
2212
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2213
+ index += 5
2214
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2215
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2216
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2217
+ index += 6
2218
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2219
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2220
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2221
+ index += 7
2222
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2223
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2224
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2225
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2226
+ index += 8
2227
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2228
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2229
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2230
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2231
+ index += 9
2232
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2233
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2234
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2235
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2236
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2237
+ index += 10
2238
+
2239
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2240
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2241
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2242
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2243
+ else
2244
+ raise "integer decoding error"
2245
+ end
2246
+
2247
+ ## END PULL_UINT64
2248
+
2249
+ @p1 = Api::PointI.allocate.decode_from(buff, index, index += msg_len)
2250
+ ## END PULL_MESSAGE
2251
+
2252
+ @_bitmask |= 0x0000000000000002
2253
+ return self if index >= len
2254
+ ## PULL_UINT64
2255
+ tag =
2256
+ if (byte0 = buff.getbyte(index)) < 0x80
2257
+ index += 1
2258
+ byte0
2259
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2260
+ index += 2
2261
+ (byte1 << 7) | (byte0 & 0x7F)
2262
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2263
+ index += 3
2264
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2265
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2266
+ index += 4
2267
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2268
+ (byte0 & 0x7F)
2269
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2270
+ index += 5
2271
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2272
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2273
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2274
+ index += 6
2275
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2276
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2277
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2278
+ index += 7
2279
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2280
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2281
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2282
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2283
+ index += 8
2284
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2285
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2286
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2287
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2288
+ index += 9
2289
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2290
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2291
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2292
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2293
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2294
+ index += 10
2295
+
2296
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2297
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2298
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2299
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2300
+ else
2301
+ raise "integer decoding error"
2302
+ end
2303
+
2304
+ ## END PULL_UINT64
2305
+ end
2306
+
2307
+ return self if index >= len
2308
+ end
2309
+ end
2310
+ def _encode(buff)
2311
+ val = @p0
2312
+ if val
2313
+ buff << 0x0a
2314
+
2315
+ # Save the buffer size before appending the submessage
2316
+ current_len = buff.bytesize
2317
+
2318
+ # Write a single dummy byte to later store encoded length
2319
+ buff << 42 # "*"
2320
+ val._encode(buff)
2321
+
2322
+ # Calculate the submessage's size
2323
+ submessage_size = buff.bytesize - current_len - 1
2324
+
2325
+ # Hope the size fits in one byte
2326
+ byte = submessage_size & 0x7F
2327
+ submessage_size >>= 7
2328
+ byte |= 0x80 if submessage_size > 0
2329
+ buff.setbyte(current_len, byte)
2330
+
2331
+ # If the sub message was bigger
2332
+ if submessage_size > 0
2333
+ current_len += 1
2334
+
2335
+ # compute how much we need to shift
2336
+ encoded_int_len = 0
2337
+ remaining_size = submessage_size
2338
+ while remaining_size != 0
2339
+ remaining_size >>= 7
2340
+ encoded_int_len += 1
2341
+ end
2342
+
2343
+ # Make space in the string with dummy bytes
2344
+ buff.bytesplice(current_len, 0, "*********", 0, encoded_int_len)
2345
+
2346
+ # Overwrite the dummy bytes with the encoded length
2347
+ while submessage_size != 0
2348
+ byte = submessage_size & 0x7F
2349
+ submessage_size >>= 7
2350
+ byte |= 0x80 if submessage_size > 0
2351
+ buff.setbyte(current_len, byte)
2352
+ current_len += 1
2353
+ end
2354
+ end
2355
+
2356
+ buff
2357
+ end
2358
+
2359
+ val = @p1
2360
+ if val
2361
+ buff << 0x12
2362
+
2363
+ # Save the buffer size before appending the submessage
2364
+ current_len = buff.bytesize
2365
+
2366
+ # Write a single dummy byte to later store encoded length
2367
+ buff << 42 # "*"
2368
+ val._encode(buff)
2369
+
2370
+ # Calculate the submessage's size
2371
+ submessage_size = buff.bytesize - current_len - 1
2372
+
2373
+ # Hope the size fits in one byte
2374
+ byte = submessage_size & 0x7F
2375
+ submessage_size >>= 7
2376
+ byte |= 0x80 if submessage_size > 0
2377
+ buff.setbyte(current_len, byte)
2378
+
2379
+ # If the sub message was bigger
2380
+ if submessage_size > 0
2381
+ current_len += 1
2382
+
2383
+ # compute how much we need to shift
2384
+ encoded_int_len = 0
2385
+ remaining_size = submessage_size
2386
+ while remaining_size != 0
2387
+ remaining_size >>= 7
2388
+ encoded_int_len += 1
2389
+ end
2390
+
2391
+ # Make space in the string with dummy bytes
2392
+ buff.bytesplice(current_len, 0, "*********", 0, encoded_int_len)
2393
+
2394
+ # Overwrite the dummy bytes with the encoded length
2395
+ while submessage_size != 0
2396
+ byte = submessage_size & 0x7F
2397
+ submessage_size >>= 7
2398
+ byte |= 0x80 if submessage_size > 0
2399
+ buff.setbyte(current_len, byte)
2400
+ current_len += 1
2401
+ end
2402
+ end
2403
+
2404
+ buff
2405
+ end
2406
+
2407
+ buff
2408
+ end
2409
+
2410
+ def to_h
2411
+ result = {}
2412
+ result["p0".to_sym] = @p0.to_h
2413
+ result["p1".to_sym] = @p1.to_h
2414
+ result
2415
+ end
2416
+ end
2417
+ class Point2D
2418
+ def self.decode(buff)
2419
+ allocate.decode_from(buff.b, 0, buff.bytesize)
2420
+ end
2421
+
2422
+ def self.encode(obj)
2423
+ obj._encode("".b)
2424
+ end
2425
+ # required field readers
2426
+
2427
+ # optional field readers
2428
+
2429
+ attr_reader :x
2430
+
2431
+ attr_reader :y
2432
+
2433
+ # BEGIN writers for optional fields
2434
+
2435
+ def x=(v)
2436
+ @_bitmask |= 0x0000000000000001
2437
+ @x = v
2438
+ end
2439
+
2440
+ def y=(v)
2441
+ @_bitmask |= 0x0000000000000002
2442
+ @y = v
2443
+ end
2444
+ # END writers for optional fields
2445
+
2446
+ def initialize(x: nil, y: nil)
2447
+ @_bitmask = 0
2448
+
2449
+ if x == nil
2450
+ @x = 0.0
2451
+ else
2452
+ @_bitmask |= 0x0000000000000001
2453
+ @x = x
2454
+ end
2455
+
2456
+ if y == nil
2457
+ @y = 0.0
2458
+ else
2459
+ @_bitmask |= 0x0000000000000002
2460
+ @y = y
2461
+ end
2462
+ end
2463
+
2464
+ def to_proto(_options = {})
2465
+ self.class.encode(self)
2466
+ end
2467
+
2468
+ def has_x?
2469
+ (@_bitmask & 0x0000000000000001) == 0x0000000000000001
2470
+ end
2471
+
2472
+ def has_y?
2473
+ (@_bitmask & 0x0000000000000002) == 0x0000000000000002
2474
+ end
2475
+
2476
+ def decode_from(buff, index, len)
2477
+ @_bitmask = 0
2478
+
2479
+ @x = 0.0
2480
+ @y = 0.0
2481
+
2482
+ return self if index >= len
2483
+ ## PULL_UINT64
2484
+ tag =
2485
+ if (byte0 = buff.getbyte(index)) < 0x80
2486
+ index += 1
2487
+ byte0
2488
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2489
+ index += 2
2490
+ (byte1 << 7) | (byte0 & 0x7F)
2491
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2492
+ index += 3
2493
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2494
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2495
+ index += 4
2496
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2497
+ (byte0 & 0x7F)
2498
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2499
+ index += 5
2500
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2501
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2502
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2503
+ index += 6
2504
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2505
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2506
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2507
+ index += 7
2508
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2509
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2510
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2511
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2512
+ index += 8
2513
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2514
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2515
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2516
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2517
+ index += 9
2518
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2519
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2520
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2521
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2522
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2523
+ index += 10
2524
+
2525
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2526
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2527
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2528
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2529
+ else
2530
+ raise "integer decoding error"
2531
+ end
2532
+
2533
+ ## END PULL_UINT64
2534
+
2535
+ found = true
2536
+ while true
2537
+ # If we have looped around since the last found tag this one is
2538
+ # unexpected, so discard it and continue.
2539
+ if !found
2540
+ wire_type = tag & 0x7
2541
+ case wire_type
2542
+ when 0
2543
+ i = 0
2544
+ while true
2545
+ newbyte = buff.getbyte(index)
2546
+ index += 1
2547
+ break if newbyte.nil? || newbyte < 0x80
2548
+ i += 1
2549
+ break if i > 9
2550
+ end
2551
+ when 1
2552
+ index += 8
2553
+ when 2
2554
+ ## PULL_BYTES
2555
+ value =
2556
+ if (byte0 = buff.getbyte(index)) < 0x80
2557
+ index += 1
2558
+ byte0
2559
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2560
+ index += 2
2561
+ (byte1 << 7) | (byte0 & 0x7F)
2562
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2563
+ index += 3
2564
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2565
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2566
+ index += 4
2567
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2568
+ (byte0 & 0x7F)
2569
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2570
+ index += 5
2571
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) |
2572
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2573
+ (byte0 & 0x7F)
2574
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2575
+ index += 6
2576
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) |
2577
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2578
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2579
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2580
+ index += 7
2581
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) |
2582
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2583
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2584
+ (byte0 & 0x7F)
2585
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2586
+ index += 8
2587
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) |
2588
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2589
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2590
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2591
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2592
+ index += 9
2593
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) |
2594
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2595
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2596
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2597
+ (byte0 & 0x7F)
2598
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2599
+ index += 10
2600
+
2601
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
2602
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2603
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2604
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2605
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2606
+ else
2607
+ raise "integer decoding error"
2608
+ end
2609
+
2610
+ buff.byteslice(index, value)
2611
+ index += value
2612
+
2613
+ ## END PULL_BYTES
2614
+ when 5
2615
+ index += 4
2616
+ else
2617
+ raise "unknown wire type #{wire_type}"
2618
+ end
2619
+ return self if index >= len
2620
+ ## PULL_UINT64
2621
+ tag =
2622
+ if (byte0 = buff.getbyte(index)) < 0x80
2623
+ index += 1
2624
+ byte0
2625
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2626
+ index += 2
2627
+ (byte1 << 7) | (byte0 & 0x7F)
2628
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2629
+ index += 3
2630
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2631
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2632
+ index += 4
2633
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2634
+ (byte0 & 0x7F)
2635
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2636
+ index += 5
2637
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2638
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2639
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2640
+ index += 6
2641
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2642
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2643
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2644
+ index += 7
2645
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2646
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2647
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2648
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2649
+ index += 8
2650
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2651
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2652
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2653
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2654
+ index += 9
2655
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2656
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2657
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2658
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2659
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2660
+ index += 10
2661
+
2662
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2663
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2664
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2665
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2666
+ else
2667
+ raise "integer decoding error"
2668
+ end
2669
+
2670
+ ## END PULL_UINT64
2671
+ end
2672
+ found = false
2673
+
2674
+ if tag == 0xd
2675
+ found = true
2676
+ @x = buff.unpack1("e", offset: index)
2677
+ index += 4
2678
+ @_bitmask |= 0x0000000000000001
2679
+ return self if index >= len
2680
+ ## PULL_UINT64
2681
+ tag =
2682
+ if (byte0 = buff.getbyte(index)) < 0x80
2683
+ index += 1
2684
+ byte0
2685
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2686
+ index += 2
2687
+ (byte1 << 7) | (byte0 & 0x7F)
2688
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2689
+ index += 3
2690
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2691
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2692
+ index += 4
2693
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2694
+ (byte0 & 0x7F)
2695
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2696
+ index += 5
2697
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2698
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2699
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2700
+ index += 6
2701
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2702
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2703
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2704
+ index += 7
2705
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2706
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2707
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2708
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2709
+ index += 8
2710
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2711
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2712
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2713
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2714
+ index += 9
2715
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2716
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2717
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2718
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2719
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2720
+ index += 10
2721
+
2722
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2723
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2724
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2725
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2726
+ else
2727
+ raise "integer decoding error"
2728
+ end
2729
+
2730
+ ## END PULL_UINT64
2731
+ end
2732
+ if tag == 0x15
2733
+ found = true
2734
+ @y = buff.unpack1("e", offset: index)
2735
+ index += 4
2736
+ @_bitmask |= 0x0000000000000002
2737
+ return self if index >= len
2738
+ ## PULL_UINT64
2739
+ tag =
2740
+ if (byte0 = buff.getbyte(index)) < 0x80
2741
+ index += 1
2742
+ byte0
2743
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2744
+ index += 2
2745
+ (byte1 << 7) | (byte0 & 0x7F)
2746
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2747
+ index += 3
2748
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2749
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2750
+ index += 4
2751
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2752
+ (byte0 & 0x7F)
2753
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2754
+ index += 5
2755
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2756
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2757
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2758
+ index += 6
2759
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2760
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2761
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2762
+ index += 7
2763
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2764
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2765
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2766
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2767
+ index += 8
2768
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2769
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2770
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2771
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2772
+ index += 9
2773
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2774
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2775
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2776
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2777
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2778
+ index += 10
2779
+
2780
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2781
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2782
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2783
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2784
+ else
2785
+ raise "integer decoding error"
2786
+ end
2787
+
2788
+ ## END PULL_UINT64
2789
+ end
2790
+
2791
+ return self if index >= len
2792
+ end
2793
+ end
2794
+ def _encode(buff)
2795
+ val = @x
2796
+ if val != 0
2797
+ buff << 0x0d
2798
+
2799
+ [val].pack("e", buffer: buff)
2800
+ end
2801
+
2802
+ val = @y
2803
+ if val != 0
2804
+ buff << 0x15
2805
+
2806
+ [val].pack("e", buffer: buff)
2807
+ end
2808
+
2809
+ buff
2810
+ end
2811
+
2812
+ def to_h
2813
+ result = {}
2814
+ result["x".to_sym] = @x
2815
+ result["y".to_sym] = @y
2816
+ result
2817
+ end
2818
+ end
2819
+ class Point
2820
+ def self.decode(buff)
2821
+ allocate.decode_from(buff.b, 0, buff.bytesize)
2822
+ end
2823
+
2824
+ def self.encode(obj)
2825
+ obj._encode("".b)
2826
+ end
2827
+ # required field readers
2828
+
2829
+ # optional field readers
2830
+
2831
+ attr_reader :x
2832
+
2833
+ attr_reader :y
2834
+
2835
+ attr_reader :z
2836
+
2837
+ # BEGIN writers for optional fields
2838
+
2839
+ def x=(v)
2840
+ @_bitmask |= 0x0000000000000001
2841
+ @x = v
2842
+ end
2843
+
2844
+ def y=(v)
2845
+ @_bitmask |= 0x0000000000000002
2846
+ @y = v
2847
+ end
2848
+
2849
+ def z=(v)
2850
+ @_bitmask |= 0x0000000000000004
2851
+ @z = v
2852
+ end
2853
+ # END writers for optional fields
2854
+
2855
+ def initialize(x: nil, y: nil, z: nil)
2856
+ @_bitmask = 0
2857
+
2858
+ if x == nil
2859
+ @x = 0.0
2860
+ else
2861
+ @_bitmask |= 0x0000000000000001
2862
+ @x = x
2863
+ end
2864
+
2865
+ if y == nil
2866
+ @y = 0.0
2867
+ else
2868
+ @_bitmask |= 0x0000000000000002
2869
+ @y = y
2870
+ end
2871
+
2872
+ if z == nil
2873
+ @z = 0.0
2874
+ else
2875
+ @_bitmask |= 0x0000000000000004
2876
+ @z = z
2877
+ end
2878
+ end
2879
+
2880
+ def to_proto(_options = {})
2881
+ self.class.encode(self)
2882
+ end
2883
+
2884
+ def has_x?
2885
+ (@_bitmask & 0x0000000000000001) == 0x0000000000000001
2886
+ end
2887
+
2888
+ def has_y?
2889
+ (@_bitmask & 0x0000000000000002) == 0x0000000000000002
2890
+ end
2891
+
2892
+ def has_z?
2893
+ (@_bitmask & 0x0000000000000004) == 0x0000000000000004
2894
+ end
2895
+
2896
+ def decode_from(buff, index, len)
2897
+ @_bitmask = 0
2898
+
2899
+ @x = 0.0
2900
+ @y = 0.0
2901
+ @z = 0.0
2902
+
2903
+ return self if index >= len
2904
+ ## PULL_UINT64
2905
+ tag =
2906
+ if (byte0 = buff.getbyte(index)) < 0x80
2907
+ index += 1
2908
+ byte0
2909
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2910
+ index += 2
2911
+ (byte1 << 7) | (byte0 & 0x7F)
2912
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2913
+ index += 3
2914
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2915
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2916
+ index += 4
2917
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2918
+ (byte0 & 0x7F)
2919
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2920
+ index += 5
2921
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2922
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2923
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2924
+ index += 6
2925
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2926
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2927
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
2928
+ index += 7
2929
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2930
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2931
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2932
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
2933
+ index += 8
2934
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2935
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2936
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2937
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
2938
+ index += 9
2939
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
2940
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
2941
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2942
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2943
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
2944
+ index += 10
2945
+
2946
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
2947
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
2948
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
2949
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2950
+ else
2951
+ raise "integer decoding error"
2952
+ end
2953
+
2954
+ ## END PULL_UINT64
2955
+
2956
+ found = true
2957
+ while true
2958
+ # If we have looped around since the last found tag this one is
2959
+ # unexpected, so discard it and continue.
2960
+ if !found
2961
+ wire_type = tag & 0x7
2962
+ case wire_type
2963
+ when 0
2964
+ i = 0
2965
+ while true
2966
+ newbyte = buff.getbyte(index)
2967
+ index += 1
2968
+ break if newbyte.nil? || newbyte < 0x80
2969
+ i += 1
2970
+ break if i > 9
2971
+ end
2972
+ when 1
2973
+ index += 8
2974
+ when 2
2975
+ ## PULL_BYTES
2976
+ value =
2977
+ if (byte0 = buff.getbyte(index)) < 0x80
2978
+ index += 1
2979
+ byte0
2980
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
2981
+ index += 2
2982
+ (byte1 << 7) | (byte0 & 0x7F)
2983
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
2984
+ index += 3
2985
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
2986
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
2987
+ index += 4
2988
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2989
+ (byte0 & 0x7F)
2990
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
2991
+ index += 5
2992
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) |
2993
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
2994
+ (byte0 & 0x7F)
2995
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
2996
+ index += 6
2997
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) |
2998
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
2999
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3000
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3001
+ index += 7
3002
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) |
3003
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3004
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3005
+ (byte0 & 0x7F)
3006
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3007
+ index += 8
3008
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) |
3009
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3010
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3011
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3012
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3013
+ index += 9
3014
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) |
3015
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3016
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3017
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3018
+ (byte0 & 0x7F)
3019
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3020
+ index += 10
3021
+
3022
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
3023
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3024
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3025
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3026
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3027
+ else
3028
+ raise "integer decoding error"
3029
+ end
3030
+
3031
+ buff.byteslice(index, value)
3032
+ index += value
3033
+
3034
+ ## END PULL_BYTES
3035
+ when 5
3036
+ index += 4
3037
+ else
3038
+ raise "unknown wire type #{wire_type}"
3039
+ end
3040
+ return self if index >= len
3041
+ ## PULL_UINT64
3042
+ tag =
3043
+ if (byte0 = buff.getbyte(index)) < 0x80
3044
+ index += 1
3045
+ byte0
3046
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3047
+ index += 2
3048
+ (byte1 << 7) | (byte0 & 0x7F)
3049
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3050
+ index += 3
3051
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3052
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3053
+ index += 4
3054
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3055
+ (byte0 & 0x7F)
3056
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3057
+ index += 5
3058
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3059
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3060
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3061
+ index += 6
3062
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3063
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3064
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3065
+ index += 7
3066
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3067
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3068
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3069
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3070
+ index += 8
3071
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3072
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3073
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3074
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3075
+ index += 9
3076
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3077
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3078
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3079
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3080
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3081
+ index += 10
3082
+
3083
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3084
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3085
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3086
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3087
+ else
3088
+ raise "integer decoding error"
3089
+ end
3090
+
3091
+ ## END PULL_UINT64
3092
+ end
3093
+ found = false
3094
+
3095
+ if tag == 0xd
3096
+ found = true
3097
+ @x = buff.unpack1("e", offset: index)
3098
+ index += 4
3099
+ @_bitmask |= 0x0000000000000001
3100
+ return self if index >= len
3101
+ ## PULL_UINT64
3102
+ tag =
3103
+ if (byte0 = buff.getbyte(index)) < 0x80
3104
+ index += 1
3105
+ byte0
3106
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3107
+ index += 2
3108
+ (byte1 << 7) | (byte0 & 0x7F)
3109
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3110
+ index += 3
3111
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3112
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3113
+ index += 4
3114
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3115
+ (byte0 & 0x7F)
3116
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3117
+ index += 5
3118
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3119
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3120
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3121
+ index += 6
3122
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3123
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3124
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3125
+ index += 7
3126
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3127
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3128
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3129
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3130
+ index += 8
3131
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3132
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3133
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3134
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3135
+ index += 9
3136
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3137
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3138
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3139
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3140
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3141
+ index += 10
3142
+
3143
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3144
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3145
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3146
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3147
+ else
3148
+ raise "integer decoding error"
3149
+ end
3150
+
3151
+ ## END PULL_UINT64
3152
+ end
3153
+ if tag == 0x15
3154
+ found = true
3155
+ @y = buff.unpack1("e", offset: index)
3156
+ index += 4
3157
+ @_bitmask |= 0x0000000000000002
3158
+ return self if index >= len
3159
+ ## PULL_UINT64
3160
+ tag =
3161
+ if (byte0 = buff.getbyte(index)) < 0x80
3162
+ index += 1
3163
+ byte0
3164
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3165
+ index += 2
3166
+ (byte1 << 7) | (byte0 & 0x7F)
3167
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3168
+ index += 3
3169
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3170
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3171
+ index += 4
3172
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3173
+ (byte0 & 0x7F)
3174
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3175
+ index += 5
3176
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3177
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3178
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3179
+ index += 6
3180
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3181
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3182
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3183
+ index += 7
3184
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3185
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3186
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3187
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3188
+ index += 8
3189
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3190
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3191
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3192
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3193
+ index += 9
3194
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3195
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3196
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3197
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3198
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3199
+ index += 10
3200
+
3201
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3202
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3203
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3204
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3205
+ else
3206
+ raise "integer decoding error"
3207
+ end
3208
+
3209
+ ## END PULL_UINT64
3210
+ end
3211
+ if tag == 0x1d
3212
+ found = true
3213
+ @z = buff.unpack1("e", offset: index)
3214
+ index += 4
3215
+ @_bitmask |= 0x0000000000000004
3216
+ return self if index >= len
3217
+ ## PULL_UINT64
3218
+ tag =
3219
+ if (byte0 = buff.getbyte(index)) < 0x80
3220
+ index += 1
3221
+ byte0
3222
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3223
+ index += 2
3224
+ (byte1 << 7) | (byte0 & 0x7F)
3225
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3226
+ index += 3
3227
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3228
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3229
+ index += 4
3230
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3231
+ (byte0 & 0x7F)
3232
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3233
+ index += 5
3234
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3235
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3236
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3237
+ index += 6
3238
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3239
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3240
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3241
+ index += 7
3242
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3243
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3244
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3245
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3246
+ index += 8
3247
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3248
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3249
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3250
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3251
+ index += 9
3252
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3253
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3254
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3255
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3256
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3257
+ index += 10
3258
+
3259
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3260
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3261
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3262
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3263
+ else
3264
+ raise "integer decoding error"
3265
+ end
3266
+
3267
+ ## END PULL_UINT64
3268
+ end
3269
+
3270
+ return self if index >= len
3271
+ end
3272
+ end
3273
+ def _encode(buff)
3274
+ val = @x
3275
+ if val != 0
3276
+ buff << 0x0d
3277
+
3278
+ [val].pack("e", buffer: buff)
3279
+ end
3280
+
3281
+ val = @y
3282
+ if val != 0
3283
+ buff << 0x15
3284
+
3285
+ [val].pack("e", buffer: buff)
3286
+ end
3287
+
3288
+ val = @z
3289
+ if val != 0
3290
+ buff << 0x1d
3291
+
3292
+ [val].pack("e", buffer: buff)
3293
+ end
3294
+
3295
+ buff
3296
+ end
3297
+
3298
+ def to_h
3299
+ result = {}
3300
+ result["x".to_sym] = @x
3301
+ result["y".to_sym] = @y
3302
+ result["z".to_sym] = @z
3303
+ result
3304
+ end
3305
+ end
3306
+ class Size2DI
3307
+ def self.decode(buff)
3308
+ allocate.decode_from(buff.b, 0, buff.bytesize)
3309
+ end
3310
+
3311
+ def self.encode(obj)
3312
+ obj._encode("".b)
3313
+ end
3314
+ # required field readers
3315
+
3316
+ # optional field readers
3317
+
3318
+ attr_reader :x
3319
+
3320
+ attr_reader :y
3321
+
3322
+ # BEGIN writers for optional fields
3323
+
3324
+ def x=(v)
3325
+ unless -2_147_483_648 <= v && v <= 2_147_483_647
3326
+ raise RangeError,
3327
+ "Value (#{v}) for field x is out of bounds (-2147483648..2147483647)"
3328
+ end
3329
+
3330
+ @_bitmask |= 0x0000000000000001
3331
+ @x = v
3332
+ end
3333
+
3334
+ def y=(v)
3335
+ unless -2_147_483_648 <= v && v <= 2_147_483_647
3336
+ raise RangeError,
3337
+ "Value (#{v}) for field y is out of bounds (-2147483648..2147483647)"
3338
+ end
3339
+
3340
+ @_bitmask |= 0x0000000000000002
3341
+ @y = v
3342
+ end
3343
+ # END writers for optional fields
3344
+
3345
+ def initialize(x: nil, y: nil)
3346
+ @_bitmask = 0
3347
+
3348
+ if x == nil
3349
+ @x = 0
3350
+ else
3351
+ unless -2_147_483_648 <= x && x <= 2_147_483_647
3352
+ raise RangeError,
3353
+ "Value (#{x}) for field x is out of bounds (-2147483648..2147483647)"
3354
+ end
3355
+ @_bitmask |= 0x0000000000000001
3356
+ @x = x
3357
+ end
3358
+
3359
+ if y == nil
3360
+ @y = 0
3361
+ else
3362
+ unless -2_147_483_648 <= y && y <= 2_147_483_647
3363
+ raise RangeError,
3364
+ "Value (#{y}) for field y is out of bounds (-2147483648..2147483647)"
3365
+ end
3366
+ @_bitmask |= 0x0000000000000002
3367
+ @y = y
3368
+ end
3369
+ end
3370
+
3371
+ def to_proto(_options = {})
3372
+ self.class.encode(self)
3373
+ end
3374
+
3375
+ def has_x?
3376
+ (@_bitmask & 0x0000000000000001) == 0x0000000000000001
3377
+ end
3378
+
3379
+ def has_y?
3380
+ (@_bitmask & 0x0000000000000002) == 0x0000000000000002
3381
+ end
3382
+
3383
+ def decode_from(buff, index, len)
3384
+ @_bitmask = 0
3385
+
3386
+ @x = 0
3387
+ @y = 0
3388
+
3389
+ return self if index >= len
3390
+ ## PULL_UINT64
3391
+ tag =
3392
+ if (byte0 = buff.getbyte(index)) < 0x80
3393
+ index += 1
3394
+ byte0
3395
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3396
+ index += 2
3397
+ (byte1 << 7) | (byte0 & 0x7F)
3398
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3399
+ index += 3
3400
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3401
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3402
+ index += 4
3403
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3404
+ (byte0 & 0x7F)
3405
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3406
+ index += 5
3407
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3408
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3409
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3410
+ index += 6
3411
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3412
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3413
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3414
+ index += 7
3415
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3416
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3417
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3418
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3419
+ index += 8
3420
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3421
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3422
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3423
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3424
+ index += 9
3425
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3426
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3427
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3428
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3429
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3430
+ index += 10
3431
+
3432
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3433
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3434
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3435
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3436
+ else
3437
+ raise "integer decoding error"
3438
+ end
3439
+
3440
+ ## END PULL_UINT64
3441
+
3442
+ found = true
3443
+ while true
3444
+ # If we have looped around since the last found tag this one is
3445
+ # unexpected, so discard it and continue.
3446
+ if !found
3447
+ wire_type = tag & 0x7
3448
+ case wire_type
3449
+ when 0
3450
+ i = 0
3451
+ while true
3452
+ newbyte = buff.getbyte(index)
3453
+ index += 1
3454
+ break if newbyte.nil? || newbyte < 0x80
3455
+ i += 1
3456
+ break if i > 9
3457
+ end
3458
+ when 1
3459
+ index += 8
3460
+ when 2
3461
+ ## PULL_BYTES
3462
+ value =
3463
+ if (byte0 = buff.getbyte(index)) < 0x80
3464
+ index += 1
3465
+ byte0
3466
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3467
+ index += 2
3468
+ (byte1 << 7) | (byte0 & 0x7F)
3469
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3470
+ index += 3
3471
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3472
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3473
+ index += 4
3474
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3475
+ (byte0 & 0x7F)
3476
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3477
+ index += 5
3478
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) |
3479
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3480
+ (byte0 & 0x7F)
3481
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3482
+ index += 6
3483
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) |
3484
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3485
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3486
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3487
+ index += 7
3488
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) |
3489
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3490
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3491
+ (byte0 & 0x7F)
3492
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3493
+ index += 8
3494
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) |
3495
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3496
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3497
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3498
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3499
+ index += 9
3500
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) |
3501
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3502
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3503
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3504
+ (byte0 & 0x7F)
3505
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3506
+ index += 10
3507
+
3508
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
3509
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3510
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3511
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3512
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3513
+ else
3514
+ raise "integer decoding error"
3515
+ end
3516
+
3517
+ buff.byteslice(index, value)
3518
+ index += value
3519
+
3520
+ ## END PULL_BYTES
3521
+ when 5
3522
+ index += 4
3523
+ else
3524
+ raise "unknown wire type #{wire_type}"
3525
+ end
3526
+ return self if index >= len
3527
+ ## PULL_UINT64
3528
+ tag =
3529
+ if (byte0 = buff.getbyte(index)) < 0x80
3530
+ index += 1
3531
+ byte0
3532
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3533
+ index += 2
3534
+ (byte1 << 7) | (byte0 & 0x7F)
3535
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3536
+ index += 3
3537
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3538
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3539
+ index += 4
3540
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3541
+ (byte0 & 0x7F)
3542
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3543
+ index += 5
3544
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3545
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3546
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3547
+ index += 6
3548
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3549
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3550
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3551
+ index += 7
3552
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3553
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3554
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3555
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3556
+ index += 8
3557
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3558
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3559
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3560
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3561
+ index += 9
3562
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3563
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3564
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3565
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3566
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3567
+ index += 10
3568
+
3569
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3570
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3571
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3572
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3573
+ else
3574
+ raise "integer decoding error"
3575
+ end
3576
+
3577
+ ## END PULL_UINT64
3578
+ end
3579
+ found = false
3580
+
3581
+ if tag == 0x8
3582
+ found = true
3583
+ ## PULL_INT32
3584
+ @x =
3585
+ if (byte0 = buff.getbyte(index)) < 0x80
3586
+ index += 1
3587
+ byte0
3588
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3589
+ index += 2
3590
+ (byte1 << 7) | (byte0 & 0x7F)
3591
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3592
+ index += 3
3593
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3594
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3595
+ index += 4
3596
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3597
+ (byte0 & 0x7F)
3598
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3599
+ index += 5
3600
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3601
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3602
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3603
+ index += 6
3604
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3605
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3606
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3607
+ index += 7
3608
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3609
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3610
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3611
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3612
+ index += 8
3613
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3614
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3615
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3616
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3617
+ index += 9
3618
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3619
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3620
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3621
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3622
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3623
+ index += 10
3624
+
3625
+ # Negative 32 bit integers are still encoded with 10 bytes
3626
+ # handle 2's complement negative numbers
3627
+ # If the top bit is 1, then it must be negative.
3628
+ -(
3629
+ (
3630
+ (
3631
+ ~(
3632
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
3633
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3634
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3635
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3636
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3637
+ )
3638
+ ) & 0xFFFF_FFFF
3639
+ ) + 1
3640
+ )
3641
+ else
3642
+ raise "integer decoding error"
3643
+ end
3644
+
3645
+ ## END PULL_INT32
3646
+
3647
+ @_bitmask |= 0x0000000000000001
3648
+ return self if index >= len
3649
+ ## PULL_UINT64
3650
+ tag =
3651
+ if (byte0 = buff.getbyte(index)) < 0x80
3652
+ index += 1
3653
+ byte0
3654
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3655
+ index += 2
3656
+ (byte1 << 7) | (byte0 & 0x7F)
3657
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3658
+ index += 3
3659
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3660
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3661
+ index += 4
3662
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3663
+ (byte0 & 0x7F)
3664
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3665
+ index += 5
3666
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3667
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3668
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3669
+ index += 6
3670
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3671
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3672
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3673
+ index += 7
3674
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3675
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3676
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3677
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3678
+ index += 8
3679
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3680
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3681
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3682
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3683
+ index += 9
3684
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3685
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3686
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3687
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3688
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3689
+ index += 10
3690
+
3691
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3692
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3693
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3694
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3695
+ else
3696
+ raise "integer decoding error"
3697
+ end
3698
+
3699
+ ## END PULL_UINT64
3700
+ end
3701
+ if tag == 0x10
3702
+ found = true
3703
+ ## PULL_INT32
3704
+ @y =
3705
+ if (byte0 = buff.getbyte(index)) < 0x80
3706
+ index += 1
3707
+ byte0
3708
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3709
+ index += 2
3710
+ (byte1 << 7) | (byte0 & 0x7F)
3711
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3712
+ index += 3
3713
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3714
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3715
+ index += 4
3716
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3717
+ (byte0 & 0x7F)
3718
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3719
+ index += 5
3720
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3721
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3722
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3723
+ index += 6
3724
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3725
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3726
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3727
+ index += 7
3728
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3729
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3730
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3731
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3732
+ index += 8
3733
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3734
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3735
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3736
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3737
+ index += 9
3738
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3739
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3740
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3741
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3742
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3743
+ index += 10
3744
+
3745
+ # Negative 32 bit integers are still encoded with 10 bytes
3746
+ # handle 2's complement negative numbers
3747
+ # If the top bit is 1, then it must be negative.
3748
+ -(
3749
+ (
3750
+ (
3751
+ ~(
3752
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) |
3753
+ ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3754
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3755
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3756
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3757
+ )
3758
+ ) & 0xFFFF_FFFF
3759
+ ) + 1
3760
+ )
3761
+ else
3762
+ raise "integer decoding error"
3763
+ end
3764
+
3765
+ ## END PULL_INT32
3766
+
3767
+ @_bitmask |= 0x0000000000000002
3768
+ return self if index >= len
3769
+ ## PULL_UINT64
3770
+ tag =
3771
+ if (byte0 = buff.getbyte(index)) < 0x80
3772
+ index += 1
3773
+ byte0
3774
+ elsif (byte1 = buff.getbyte(index + 1)) < 0x80
3775
+ index += 2
3776
+ (byte1 << 7) | (byte0 & 0x7F)
3777
+ elsif (byte2 = buff.getbyte(index + 2)) < 0x80
3778
+ index += 3
3779
+ (byte2 << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3780
+ elsif (byte3 = buff.getbyte(index + 3)) < 0x80
3781
+ index += 4
3782
+ (byte3 << 21) | ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) |
3783
+ (byte0 & 0x7F)
3784
+ elsif (byte4 = buff.getbyte(index + 4)) < 0x80
3785
+ index += 5
3786
+ (byte4 << 28) | ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3787
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3788
+ elsif (byte5 = buff.getbyte(index + 5)) < 0x80
3789
+ index += 6
3790
+ (byte5 << 35) | ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3791
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3792
+ elsif (byte6 = buff.getbyte(index + 6)) < 0x80
3793
+ index += 7
3794
+ (byte6 << 42) | ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3795
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3796
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3797
+ elsif (byte7 = buff.getbyte(index + 7)) < 0x80
3798
+ index += 8
3799
+ (byte7 << 49) | ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3800
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3801
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3802
+ elsif (byte8 = buff.getbyte(index + 8)) < 0x80
3803
+ index += 9
3804
+ (byte8 << 56) | ((byte7 & 0x7F) << 49) | ((byte6 & 0x7F) << 42) |
3805
+ ((byte5 & 0x7F) << 35) | ((byte4 & 0x7F) << 28) |
3806
+ ((byte3 & 0x7F) << 21) | ((byte2 & 0x7F) << 14) |
3807
+ ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3808
+ elsif (byte9 = buff.getbyte(index + 9)) < 0x80
3809
+ index += 10
3810
+
3811
+ (byte9 << 63) | ((byte8 & 0x7F) << 56) | ((byte7 & 0x7F) << 49) |
3812
+ ((byte6 & 0x7F) << 42) | ((byte5 & 0x7F) << 35) |
3813
+ ((byte4 & 0x7F) << 28) | ((byte3 & 0x7F) << 21) |
3814
+ ((byte2 & 0x7F) << 14) | ((byte1 & 0x7F) << 7) | (byte0 & 0x7F)
3815
+ else
3816
+ raise "integer decoding error"
3817
+ end
3818
+
3819
+ ## END PULL_UINT64
3820
+ end
3821
+
3822
+ return self if index >= len
3823
+ end
3824
+ end
3825
+ def _encode(buff)
3826
+ val = @x
3827
+ if val != 0
3828
+ buff << 0x08
3829
+
3830
+ while val != 0
3831
+ byte = val & 0x7F
3832
+
3833
+ val >>= 7
3834
+ # This drops the top bits,
3835
+ # Otherwise, with a signed right shift,
3836
+ # we get infinity one bits at the top
3837
+ val &= (1 << 57) - 1
3838
+
3839
+ byte |= 0x80 if val != 0
3840
+ buff << byte
3841
+ end
3842
+ end
3843
+
3844
+ val = @y
3845
+ if val != 0
3846
+ buff << 0x10
3847
+
3848
+ while val != 0
3849
+ byte = val & 0x7F
3850
+
3851
+ val >>= 7
3852
+ # This drops the top bits,
3853
+ # Otherwise, with a signed right shift,
3854
+ # we get infinity one bits at the top
3855
+ val &= (1 << 57) - 1
3856
+
3857
+ byte |= 0x80 if val != 0
3858
+ buff << byte
3859
+ end
3860
+ end
3861
+
3862
+ buff
3863
+ end
3864
+
3865
+ def to_h
3866
+ result = {}
3867
+ result["x".to_sym] = @x
3868
+ result["y".to_sym] = @y
3869
+ result
3870
+ end
3871
+ end
22
3872
  end