public SetMake ( byte src, int srcOffset, int length ) : int | ||
src | byte | |
srcOffset | int | |
length | int | |
return | int |
private static int Encode(Car car, DirectBuffer directBuffer, int bufferOffset) { int srcOffset = 0; car.WrapForEncode(directBuffer, bufferOffset); car.SerialNumber = 1234; car.ModelYear = 2013; car.Available = BooleanType.TRUE; car.Code = Model.A; car.SetVehicleCode(_vehicleCode, srcOffset); for (int i = 0, size = Car.SomeNumbersLength; i < size; i++) { car.SetSomeNumbers(i, i); } car.Extras = OptionalExtras.CruiseControl | OptionalExtras.SunRoof; car.Engine.Capacity = 2000; car.Engine.NumCylinders = 4; car.Engine.SetManufacturerCode(_manufacturerCode, srcOffset); var fuelFigures = car.FuelFiguresCount(3); fuelFigures.Next(); fuelFigures.Speed = 30; fuelFigures.Mpg = 35.9f; fuelFigures.Next(); fuelFigures.Speed = 55; fuelFigures.Mpg = 49.0f; fuelFigures.Next(); fuelFigures.Speed = 75; fuelFigures.Mpg = 40.0f; Car.PerformanceFiguresGroup perfFigures = car.PerformanceFiguresCount(2); perfFigures.Next(); perfFigures.OctaneRating = 95; Car.PerformanceFiguresGroup.AccelerationGroup acceleration = perfFigures.AccelerationCount(3).Next(); acceleration.Mph = 30; acceleration.Seconds = 4.0f; acceleration.Next(); acceleration.Mph = 60; acceleration.Seconds = 7.5f; acceleration.Next(); acceleration.Mph = 100; acceleration.Seconds = 12.2f; perfFigures.Next(); perfFigures.OctaneRating = 99; acceleration = perfFigures.AccelerationCount(3).Next(); acceleration.Mph = 30; acceleration.Seconds = 3.8f; acceleration.Next(); acceleration.Mph = 60; acceleration.Seconds = 7.1f; acceleration.Next(); acceleration.Mph = 100; acceleration.Seconds = 11.8f; car.SetMake(_make, srcOffset, _make.Length); car.SetMake(_model, srcOffset, _model.Length); return car.Size; }
private static int Encode(Car car, DirectBuffer directBuffer, int bufferOffset) { const int srcOffset = 0; // we position the car encoder on the direct buffer, at the correct offset (ie. just after the header) car.WrapForEncode(directBuffer, bufferOffset); car.SerialNumber = 1234; // we set the different fields, just as normal properties and they get written straight to the underlying byte buffer car.ModelYear = 2013; car.Available = BooleanType.TRUE; // enums are supports car.Code = Model.A; car.SetVehicleCode(_vehicleCode, srcOffset); // we set a constant string for (int i = 0, size = Car.SomeNumbersLength; i < size; i++) { car.SetSomeNumbers(i, i); // this property is defined as a constant length array of integers } car.Extras = OptionalExtras.CruiseControl | OptionalExtras.SunRoof; // bit set (flag enums in C#) are supported car.Engine.Capacity = 2000; car.Engine.NumCylinders = 4; car.Engine.SetManufacturerCode(_manufacturerCode, srcOffset); // we have written all the constant length fields, now we can write the repeatable groups var fuelFigures = car.FuelFiguresCount(3); // we specify that we are going to write 3 FueldFigures (the API is not very .NET friendly yet, we will address that) fuelFigures.Next(); // move to the first element fuelFigures.Speed = 30; fuelFigures.Mpg = 35.9f; fuelFigures.Next(); // second fuelFigures.Speed = 55; fuelFigures.Mpg = 49.0f; fuelFigures.Next(); fuelFigures.Speed = 75; fuelFigures.Mpg = 40.0f; Car.PerformanceFiguresGroup perfFigures = car.PerformanceFiguresCount(2); // demonstrates how to create a nested group perfFigures.Next(); perfFigures.OctaneRating = 95; Car.PerformanceFiguresGroup.AccelerationGroup acceleration = perfFigures.AccelerationCount(3).Next(); // this group is going to be nested in the first element of the previous group acceleration.Mph = 30; acceleration.Seconds = 4.0f; acceleration.Next(); acceleration.Mph = 60; acceleration.Seconds = 7.5f; acceleration.Next(); acceleration.Mph = 100; acceleration.Seconds = 12.2f; perfFigures.Next(); perfFigures.OctaneRating = 99; acceleration = perfFigures.AccelerationCount(3).Next(); acceleration.Mph = 30; acceleration.Seconds = 3.8f; acceleration.Next(); acceleration.Mph = 60; acceleration.Seconds = 7.1f; acceleration.Next(); acceleration.Mph = 100; acceleration.Seconds = 11.8f; // once we have written all the repeatable groups we can write the variable length properties (you would use that for strings, byte[], etc) car.SetMake(_make, srcOffset, _make.Length); car.SetMake(_model, srcOffset, _model.Length); return car.Size; }