124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
|
# File 'lib/grpc/orin3/provider/orin3_binary_converter.rb', line 124
def self.deserialize(binary_data)
type_indicator = binary_data[0].ord
case type_indicator
when ORiN3BinaryConverter::DataType::Nil
return nil
when ORiN3BinaryConverter::DataType::Bool
return binary_data[1].ord == 1
when ORiN3BinaryConverter::DataType::UInt8
return binary_data[1].unpack('C').first
when ORiN3BinaryConverter::DataType::Int8
return binary_data[1].unpack('c').first
when ORiN3BinaryConverter::DataType::UInt16
return binary_data[1..2].unpack('S').first
when ORiN3BinaryConverter::DataType::Int16
return binary_data[1..2].unpack('s').first
when ORiN3BinaryConverter::DataType::UInt32
return binary_data[1..4].unpack('L').first
when ORiN3BinaryConverter::DataType::Int32
return binary_data[1..4].unpack('l').first
when ORiN3BinaryConverter::DataType::UInt64
return binary_data[1..8].unpack('Q').first
when ORiN3BinaryConverter::DataType::Int64
return binary_data[1..8].unpack('q').first
when ORiN3BinaryConverter::DataType::Float
return binary_data[1..4].unpack('e').first
when ORiN3BinaryConverter::DataType::Double
return binary_data[1..8].unpack('E').first
when ORiN3BinaryConverter::DataType::String
length = binary_data[1..4].unpack('L').first
string_data = binary_data[5, length].force_encoding('UTF-8')
return string_data
when ORiN3BinaryConverter::DataType::DateTime
timestamp = binary_data[1..8].unpack('q<').first
return Grpc::ORiN3::Provider::DateTimeConverter::from_int64(timestamp)
when ORiN3BinaryConverter::DataType::BoolArray
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i].ord == 1
end
return result
when ORiN3BinaryConverter::DataType::UInt8Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i].unpack('C').first
end
return result
when ORiN3BinaryConverter::DataType::Int8Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i].unpack('c').first
end
return result
when ORiN3BinaryConverter::DataType::UInt16Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 2, 2].unpack('S<').first
end
return result
when ORiN3BinaryConverter::DataType::Int16Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 2, 2].unpack('s<').first
end
return result
when ORiN3BinaryConverter::DataType::UInt32Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 4, 4].unpack('L<').first
end
return result
when ORiN3BinaryConverter::DataType::Int32Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 4, 4].unpack('l<').first
end
return result
when ORiN3BinaryConverter::DataType::UInt64Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 8, 8].unpack('Q<').first
end
return result
when ORiN3BinaryConverter::DataType::Int64Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 8, 8].unpack('q<').first
end
return result
when ORiN3BinaryConverter::DataType::FloatArray
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 4, 4].unpack('e').first
end
return result
when ORiN3BinaryConverter::DataType::DoubleArray
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
result[i] = binary_data[5 + i * 8, 8].unpack('E').first
end
return result
when ORiN3BinaryConverter::DataType::StringArray
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
index = 5
length.times do |i|
if binary_data[index]
string_length = binary_data[index + 1, 4].unpack('L').first
result[i] = binary_data[index + 5, string_length].force_encoding('UTF-8')
index += string_length + 5
else
result[i] = nil
index += 5
end
end
return result
when ORiN3BinaryConverter::DataType::DateTimeArray
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
timestamp = binary_data[5 + i * 8, 8].unpack('q<').first
result[i] = Grpc::ORiN3::Provider::DateTimeConverter::from_int64(timestamp)
end
return result
when ORiN3BinaryConverter::DataType::NullableBoolArray
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + i
if (binary_data[index].ord == 2)
result[i] = nil
else
result[i] = binary_data[index].ord == 1
end
end
return result
when ORiN3BinaryConverter::DataType::NullableUInt8Array
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 2)
if (binary_data[index].ord == 1)
result[i] = binary_data[index + 1].unpack('C').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableInt8Array
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 2)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1].unpack('c').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableUInt16Array
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 3)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 2].unpack('S<').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableInt16Array
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 3)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 2].unpack('s<').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableUInt32Array
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 5)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 4].unpack('L<').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableInt32Array
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 5)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 4].unpack('l<').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableUInt64Array
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 9)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 8].unpack('Q<').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableInt64Array
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 9)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 8].unpack('q<').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableFloatArray
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 5)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 4].unpack('e').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableDoubleArray
length = binary_data[1..4].unpack('L<').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 9)
if binary_data[index].ord == 1
result[i] = binary_data[index + 1, 8].unpack('E').first
end
end
return result
when ORiN3BinaryConverter::DataType::NullableDateTimeArray
length = binary_data[1..4].unpack('L').first
result = Array.new(length, nil)
length.times do |i|
index = 5 + (i * 9)
if binary_data[index].ord == 1
timestamp = binary_data[index + 1, 8].unpack('q<').first
result[i] = Grpc::ORiN3::Provider::DateTimeConverter::from_int64(timestamp)
end
end
return result
else
raise ArgumentError, "Unsupported data type: #{type_indicator}. Binary data: #{binary_data.inspect}"
end
end
|