forked from aeron-io/simple-binary-encoding
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCar.cs
More file actions
647 lines (510 loc) · 17.9 KB
/
Car.cs
File metadata and controls
647 lines (510 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
/* Generated SBE (Simple Binary Encoding) message codec */
using System;
using Adaptive.SimpleBinaryEncoding;
namespace Baseline
{
public class Car : IMessageFlyweight
{
public const ushort TemplateId = (ushort)1;
public const byte TemplateVersion = (byte)0;
public const ushort BlockLength = (ushort)41;
private readonly IMessageFlyweight _parentMessage;
private DirectBuffer _buffer;
private int _offset;
private int _position;
private int _actingBlockLength;
private int _actingVersion;
public int Offset { get { return _offset; } }
public Car()
{
_parentMessage = this;
}
public void WrapForEncode(DirectBuffer buffer, int offset)
{
_buffer = buffer;
_offset = offset;
_actingBlockLength = BlockLength;
_actingVersion = TemplateVersion;
Position = offset + _actingBlockLength;
}
public void WrapForDecode(DirectBuffer buffer, int offset,
int actingBlockLength, int actingVersion)
{
_buffer = buffer;
_offset = offset;
_actingBlockLength = actingBlockLength;
_actingVersion = actingVersion;
Position = offset + _actingBlockLength;
}
public int Size
{
get
{
return _position - _offset;
}
}
public int Position
{
get
{
return _position;
}
set
{
_buffer.CheckPosition(_position);
_position = value;
}
}
public const int SerialNumberSchemaId = 1;
public const uint SerialNumberNullVal = 4294967294U;
public const uint SerialNumberMinVal = 0U;
public const uint SerialNumberMaxVal = 4294967293U;
public uint SerialNumber
{
get
{
return _buffer.Uint32GetLittleEndian(_offset + 0);
}
set
{
_buffer.Uint32PutLittleEndian(_offset + 0, value);
}
}
public const int ModelYearSchemaId = 2;
public const ushort ModelYearNullVal = (ushort)65535;
public const ushort ModelYearMinVal = (ushort)0;
public const ushort ModelYearMaxVal = (ushort)65534;
public ushort ModelYear
{
get
{
return _buffer.Uint16GetLittleEndian(_offset + 4);
}
set
{
_buffer.Uint16PutLittleEndian(_offset + 4, value);
}
}
public const int AvailableSchemaId = 3;
public BooleanType Available
{
get
{
return (BooleanType)_buffer.Uint8Get(_offset + 6);
}
set
{
_buffer.Uint8Put(_offset + 6, (byte)value);
}
}
public const int CodeSchemaId = 4;
public Model Code
{
get
{
return (Model)_buffer.CharGet(_offset + 7);
}
set
{
_buffer.CharPut(_offset + 7, (byte)value);
}
}
public const int SomeNumbersSchemaId = 5;
public const int SomeNumbersNullVal = -2147483648;
public const int SomeNumbersMinVal = -2147483647;
public const int SomeNumbersMaxVal = 2147483647;
public const int SomeNumbersLength = 5;
public int GetSomeNumbers(int index)
{
if (index < 0 || index >= 5)
{
throw new IndexOutOfRangeException("index out of range: index=" + index);
}
return _buffer.Int32GetLittleEndian(_offset + 8 + (index * 4));
}
public void SetSomeNumbers(int index, int value)
{
if (index < 0 || index >= 5)
{
throw new IndexOutOfRangeException("index out of range: index=" + index);
}
_buffer.Int32PutLittleEndian(_offset + 8 + (index * 4), value);
}
public const int VehicleCodeSchemaId = 6;
public const byte VehicleCodeNullVal = (byte)0;
public const byte VehicleCodeMinVal = (byte)32;
public const byte VehicleCodeMaxVal = (byte)126;
public const int VehicleCodeLength = 6;
public byte GetVehicleCode(int index)
{
if (index < 0 || index >= 6)
{
throw new IndexOutOfRangeException("index out of range: index=" + index);
}
return _buffer.CharGet(_offset + 28 + (index * 1));
}
public void SetVehicleCode(int index, byte value)
{
if (index < 0 || index >= 6)
{
throw new IndexOutOfRangeException("index out of range: index=" + index);
}
_buffer.CharPut(_offset + 28 + (index * 1), value);
}
public const string VehicleCodeCharacterEncoding = "UTF-8";
public int GetVehicleCode(byte[] dst, int dstOffset)
{
const int length = 6;
if (dstOffset < 0 || dstOffset > (dst.Length - length))
{
throw new IndexOutOfRangeException("dstOffset out of range for copy: offset=" + dstOffset);
}
_buffer.GetBytes(_offset + 28, dst, dstOffset, length);
return length;
}
public void SetVehicleCode(byte[] src, int srcOffset)
{
const int length = 6;
if (srcOffset < 0 || srcOffset > (src.Length - length))
{
throw new IndexOutOfRangeException("srcOffset out of range for copy: offset=" + srcOffset);
}
_buffer.SetBytes(_offset + 28, src, srcOffset, length);
}
public const int ExtrasSchemaId = 7;
public OptionalExtras Extras
{
get
{
return (OptionalExtras)_buffer.Uint8Get(_offset + 34);
}
set
{
_buffer.Uint8Put(_offset + 34, (byte)value);
}
}
public const int EngineSchemaId = 8;
private readonly Engine _engine = new Engine();
public Engine Engine
{
get
{
_engine.Wrap(_buffer, _offset + 35, _actingVersion);
return _engine;
}
}
private readonly FuelFiguresGroup _fuelFigures = new FuelFiguresGroup();
public const long FuelFiguresSchemaId = 9;
public FuelFiguresGroup FuelFigures
{
get
{
_fuelFigures.WrapForDecode(_parentMessage, _buffer, _actingVersion);
return _fuelFigures;
}
}
public FuelFiguresGroup FuelFiguresCount(int count)
{
_fuelFigures.WrapForEncode(_parentMessage, _buffer, count);
return _fuelFigures;
}
public class FuelFiguresGroup : IGroupFlyweight<FuelFiguresGroup>
{
private readonly GroupSizeEncoding _dimensions = new GroupSizeEncoding();
private IMessageFlyweight _parentMessage;
private DirectBuffer _buffer;
private int _blockLength;
private int _actingVersion;
private int _count;
private int _index;
private int _offset;
public void WrapForDecode(IMessageFlyweight parentMessage, DirectBuffer buffer, int actingVersion)
{
_parentMessage = parentMessage;
_buffer = buffer;
_dimensions.Wrap(buffer, parentMessage.Position, actingVersion);
_count = _dimensions.NumInGroup;
_blockLength = _dimensions.BlockLength;
_actingVersion = actingVersion;
_index = -1;
const int dimensionsHeaderSize = 3;
_parentMessage.Position = parentMessage.Position + dimensionsHeaderSize;
}
public void WrapForEncode(IMessageFlyweight parentMessage, DirectBuffer buffer, int count)
{
_parentMessage = parentMessage;
_buffer = buffer;
_dimensions.Wrap(buffer, parentMessage.Position, _actingVersion);
_dimensions.NumInGroup = (byte)count;
_dimensions.BlockLength = (ushort)6;
_index = -1;
_count = count;
_blockLength = 6;
const int dimensionsHeaderSize = 3;
parentMessage.Position = parentMessage.Position + dimensionsHeaderSize;
}
public int Count { get { return _count; } }
public bool HasNext { get { return _index + 1 < _count; } }
public FuelFiguresGroup Next()
{
if (_index + 1 >= _count)
{
throw new InvalidOperationException();
}
_offset = _parentMessage.Position;
_parentMessage.Position = _offset + _blockLength;
++_index;
return this;
}
public const int SpeedSchemaId = 10;
public const ushort SpeedNullVal = (ushort)65535;
public const ushort SpeedMinVal = (ushort)0;
public const ushort SpeedMaxVal = (ushort)65534;
public ushort Speed
{
get
{
return _buffer.Uint16GetLittleEndian(_offset + 0);
}
set
{
_buffer.Uint16PutLittleEndian(_offset + 0, value);
}
}
public const int MpgSchemaId = 11;
public const float MpgNullVal = float.NaN;
public const float MpgMinVal = 1.401298464324817E-45f;
public const float MpgMaxVal = 3.4028234663852886E38f;
public float Mpg
{
get
{
return _buffer.FloatGetLittleEndian(_offset + 2);
}
set
{
_buffer.FloatPutLittleEndian(_offset + 2, value);
}
}
}
private readonly PerformanceFiguresGroup _performanceFigures = new PerformanceFiguresGroup();
public const long PerformanceFiguresSchemaId = 12;
public PerformanceFiguresGroup PerformanceFigures
{
get
{
_performanceFigures.WrapForDecode(_parentMessage, _buffer, _actingVersion);
return _performanceFigures;
}
}
public PerformanceFiguresGroup PerformanceFiguresCount(int count)
{
_performanceFigures.WrapForEncode(_parentMessage, _buffer, count);
return _performanceFigures;
}
public class PerformanceFiguresGroup : IGroupFlyweight<PerformanceFiguresGroup>
{
private readonly GroupSizeEncoding _dimensions = new GroupSizeEncoding();
private IMessageFlyweight _parentMessage;
private DirectBuffer _buffer;
private int _blockLength;
private int _actingVersion;
private int _count;
private int _index;
private int _offset;
public void WrapForDecode(IMessageFlyweight parentMessage, DirectBuffer buffer, int actingVersion)
{
_parentMessage = parentMessage;
_buffer = buffer;
_dimensions.Wrap(buffer, parentMessage.Position, actingVersion);
_count = _dimensions.NumInGroup;
_blockLength = _dimensions.BlockLength;
_actingVersion = actingVersion;
_index = -1;
const int dimensionsHeaderSize = 3;
_parentMessage.Position = parentMessage.Position + dimensionsHeaderSize;
}
public void WrapForEncode(IMessageFlyweight parentMessage, DirectBuffer buffer, int count)
{
_parentMessage = parentMessage;
_buffer = buffer;
_dimensions.Wrap(buffer, parentMessage.Position, _actingVersion);
_dimensions.NumInGroup = (byte)count;
_dimensions.BlockLength = (ushort)1;
_index = -1;
_count = count;
_blockLength = 1;
const int dimensionsHeaderSize = 3;
parentMessage.Position = parentMessage.Position + dimensionsHeaderSize;
}
public int Count { get { return _count; } }
public bool HasNext { get { return _index + 1 < _count; } }
public PerformanceFiguresGroup Next()
{
if (_index + 1 >= _count)
{
throw new InvalidOperationException();
}
_offset = _parentMessage.Position;
_parentMessage.Position = _offset + _blockLength;
++_index;
return this;
}
public const int OctaneRatingSchemaId = 13;
public const byte OctaneRatingNullVal = (byte)255;
public const byte OctaneRatingMinVal = (byte)90;
public const byte OctaneRatingMaxVal = (byte)110;
public byte OctaneRating
{
get
{
return _buffer.Uint8Get(_offset + 0);
}
set
{
_buffer.Uint8Put(_offset + 0, value);
}
}
private readonly AccelerationGroup _acceleration = new AccelerationGroup();
public const long AccelerationSchemaId = 14;
public AccelerationGroup Acceleration
{
get
{
_acceleration.WrapForDecode(_parentMessage, _buffer, _actingVersion);
return _acceleration;
}
}
public AccelerationGroup AccelerationCount(int count)
{
_acceleration.WrapForEncode(_parentMessage, _buffer, count);
return _acceleration;
}
public class AccelerationGroup : IGroupFlyweight<AccelerationGroup>
{
private readonly GroupSizeEncoding _dimensions = new GroupSizeEncoding();
private IMessageFlyweight _parentMessage;
private DirectBuffer _buffer;
private int _blockLength;
private int _actingVersion;
private int _count;
private int _index;
private int _offset;
public void WrapForDecode(IMessageFlyweight parentMessage, DirectBuffer buffer, int actingVersion)
{
_parentMessage = parentMessage;
_buffer = buffer;
_dimensions.Wrap(buffer, parentMessage.Position, actingVersion);
_count = _dimensions.NumInGroup;
_blockLength = _dimensions.BlockLength;
_actingVersion = actingVersion;
_index = -1;
const int dimensionsHeaderSize = 3;
_parentMessage.Position = parentMessage.Position + dimensionsHeaderSize;
}
public void WrapForEncode(IMessageFlyweight parentMessage, DirectBuffer buffer, int count)
{
_parentMessage = parentMessage;
_buffer = buffer;
_dimensions.Wrap(buffer, parentMessage.Position, _actingVersion);
_dimensions.NumInGroup = (byte)count;
_dimensions.BlockLength = (ushort)6;
_index = -1;
_count = count;
_blockLength = 6;
const int dimensionsHeaderSize = 3;
parentMessage.Position = parentMessage.Position + dimensionsHeaderSize;
}
public int Count { get { return _count; } }
public bool HasNext { get { return _index + 1 < _count; } }
public AccelerationGroup Next()
{
if (_index + 1 >= _count)
{
throw new InvalidOperationException();
}
_offset = _parentMessage.Position;
_parentMessage.Position = _offset + _blockLength;
++_index;
return this;
}
public const int MphSchemaId = 15;
public const ushort MphNullVal = (ushort)65535;
public const ushort MphMinVal = (ushort)0;
public const ushort MphMaxVal = (ushort)65534;
public ushort Mph
{
get
{
return _buffer.Uint16GetLittleEndian(_offset + 0);
}
set
{
_buffer.Uint16PutLittleEndian(_offset + 0, value);
}
}
public const int SecondsSchemaId = 16;
public const float SecondsNullVal = float.NaN;
public const float SecondsMinVal = 1.401298464324817E-45f;
public const float SecondsMaxVal = 3.4028234663852886E38f;
public float Seconds
{
get
{
return _buffer.FloatGetLittleEndian(_offset + 2);
}
set
{
_buffer.FloatPutLittleEndian(_offset + 2, value);
}
}
}
}
public const int MakeSchemaId = 17;
public const string MakeCharacterEncoding = "UTF-8";
public int GetMake(byte[] dst, int dstOffset, int length)
{
const int sizeOfLengthField = 1;
int lengthPosition = Position;
Position = lengthPosition + sizeOfLengthField;
int dataLength = _buffer.Uint8Get(lengthPosition);
int bytesCopied = Math.Min(length, dataLength);
_buffer.GetBytes(Position, dst, dstOffset, bytesCopied);
Position = Position + dataLength;
return bytesCopied;
}
public int SetMake(byte[] src, int srcOffset, int length)
{
const int sizeOfLengthField = 1;
int lengthPosition = Position;
_buffer.Uint8Put(lengthPosition, (byte)length);
Position = lengthPosition + sizeOfLengthField;
_buffer.SetBytes(Position, src, srcOffset, length);
Position = Position + length;
return length;
}
public const int ModelSchemaId = 18;
public const string ModelCharacterEncoding = "UTF-8";
public int GetModel(byte[] dst, int dstOffset, int length)
{
const int sizeOfLengthField = 1;
int lengthPosition = Position;
Position = lengthPosition + sizeOfLengthField;
int dataLength = _buffer.Uint8Get(lengthPosition);
int bytesCopied = Math.Min(length, dataLength);
_buffer.GetBytes(Position, dst, dstOffset, bytesCopied);
Position = Position + dataLength;
return bytesCopied;
}
public int SetModel(byte[] src, int srcOffset, int length)
{
const int sizeOfLengthField = 1;
int lengthPosition = Position;
_buffer.Uint8Put(lengthPosition, (byte)length);
Position = lengthPosition + sizeOfLengthField;
_buffer.SetBytes(Position, src, srcOffset, length);
Position = Position + length;
return length;
}
}
}