public int Encode(Car car, DirectBuffer directBuffer, int bufferOffset)
        {
            _car.WrapForEncodeAndApplyHeader(directBuffer, bufferOffset, _messageHeader);

            const int srcOffset = 0;

            car.SerialNumber = 1234;
            car.ModelYear    = 2013;
            car.Available    = BooleanType.T;
            car.Code         = Baseline.Model.A;
            car.SetVehicleCode("CODE12");

            for (int i = 0, size = Car.SomeNumbersLength; i < size; i++)
            {
                car.SetSomeNumbers(i, (uint)i);
            }

            car.Extras              = OptionalExtras.CruiseControl | OptionalExtras.SportsPack;
            car.Engine.Capacity     = 2000;
            car.Engine.NumCylinders = 4;
            car.Engine.SetManufacturerCode("123");
            car.Engine.Efficiency         = 35;
            car.Engine.BoosterEnabled     = BooleanType.T;
            car.Engine.Booster.BoostType  = BoostType.NITROUS;
            car.Engine.Booster.HorsePower = 200;

            var fuelFigures = car.FuelFiguresCount(3);

            fuelFigures.Next();
            fuelFigures.Speed = 30;
            fuelFigures.Mpg   = 35.9f;
            fuelFigures.SetUsageDescription("Urban Cycle");

            fuelFigures.Next();
            fuelFigures.Speed = 55;
            fuelFigures.Mpg   = 49.0f;
            fuelFigures.SetUsageDescription("Combined Cycle");

            fuelFigures.Next();
            fuelFigures.Speed = 75;
            fuelFigures.Mpg   = 40.0f;
            fuelFigures.SetUsageDescription("Highway Cycle");

            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.SetManufacturer("Honda");
            car.SetModel("Civic VTi");
            car.SetActivationCode("code");

            return(car.Size);
        }
コード例 #2
0
ファイル: ExtensionExample.cs プロジェクト: NiinS/forked-sbe
        public 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.T;           // enums are supports
            car.Code         = Extension.Model.A;
            car.SetVehicleCode(VehicleCode, srcOffset); // we set a constant string

            for (int i = 0, size = Car.SomeNumbersLength; i < size; i++)
            {
                car.SetSomeNumbers(i, (uint)i); // this property is defined as a constant length array of integers
            }

            car.Extras = OptionalExtras.CruiseControl | OptionalExtras.SportsPack; // bit set (flag enums in C#) are supported

            // Extension only
            car.CupHolderCount = 119; // sinceVersion = 1

            car.Engine.Capacity     = 2000;
            car.Engine.NumCylinders = 4;
            car.Engine.SetManufacturerCode(ManufacturerCode, srcOffset);
            car.Engine.Efficiency         = 35;
            car.Engine.BoosterEnabled     = BooleanType.T;
            car.Engine.Booster.BoostType  = BoostType.NITROUS;
            car.Engine.Booster.HorsePower = 200;

            // 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.SetManufacturer(Manufacturer, srcOffset, Manufacturer.Length);
            car.SetModel(Model, srcOffset, Model.Length);
            car.SetActivationCode(ActivationCode, srcOffset, ActivationCode.Length);

            return(car.Size);
        }