std::size_t encodeCar(Car &car, char *buffer, std::uint64_t offset, std::uint64_t bufferLength) { car.wrapForEncode(buffer, offset, bufferLength) .serialNumber(1234) .modelYear(2013) .available(BooleanType::T) .code(Model::A) .putVehicleCode(VEHICLE_CODE); for (std::uint64_t i = 0, size = car.someNumbersLength(); i < size; i++) { car.someNumbers(i, static_cast<std::int32_t>(i)); } car.extras().clear() .cruiseControl(true) .sportsPack(true) .sunRoof(false); car.engine() .capacity(2000) .numCylinders((short)4) .putManufacturerCode(MANUFACTURER_CODE); Car::FuelFigures& fuelFigures = car.fuelFiguresCount(3); fuelFigures .next().speed(30).mpg(35.9f) .putUsageDescription("Urban Cycle", 11); fuelFigures .next().speed(55).mpg(49.0f) .putUsageDescription("Combined Cycle", 14); fuelFigures .next().speed(75).mpg(40.0f) .putUsageDescription("Highway Cycle", 13); Car::PerformanceFigures &performanceFigures = car.performanceFiguresCount(2); performanceFigures.next() .octaneRating((short)95) .accelerationCount(3) .next().mph(30).seconds(4.0f) .next().mph(60).seconds(7.5f) .next().mph(100).seconds(12.2f); performanceFigures.next() .octaneRating((short)99) .accelerationCount(3) .next().mph(30).seconds(3.8f) .next().mph(60).seconds(7.1f) .next().mph(100).seconds(11.8f); car.putMake(MAKE, 5) .putModel(MODEL, 9) .putActivationCode("deadbeef", 8); return car.encodedLength(); }
void encodeCar(Car &car, char *buffer, int offset) { car.wrapForEncode(buffer, offset) .serialNumber(1234) .modelYear(2013) .available(BooleanType::TRUE) .code(Model::A) .putVehicleCode(VEHICLE_CODE); for (int i = 0, size = car.someNumbersLength(); i < size; i++) { car.someNumbers(i, i); } car.extras().clear() .cruiseControl(true) .sportsPack(true) .sunRoof(false); car.engine() .capacity(2000) .numCylinders((short)4) .putManufacturerCode(MANUFACTURER_CODE); car.fuelFiguresCount(3) .next().speed(30).mpg(35.9f) .next().speed(55).mpg(49.0f) .next().speed(75).mpg(40.0f); Car::PerformanceFigures &performanceFigures = car.performanceFiguresCount(2); performanceFigures.next() .octaneRating((short)95) .accelerationCount(3) .next().mph(30).seconds(4.0f) .next().mph(60).seconds(7.5f) .next().mph(100).seconds(12.2f); performanceFigures.next() .octaneRating((short)99) .accelerationCount(3) .next().mph(30).seconds(3.8f) .next().mph(60).seconds(7.1f) .next().mph(100).seconds(11.8f); car.putMake(MAKE, strlen(MAKE)); car.putModel(MODEL, strlen(MODEL)); }
virtual std::uint64_t encodeHdrAndCar() { MessageHeader hdr; Car car; hdr.wrap(m_buffer, 0, 0, sizeof(m_buffer)) .blockLength(Car::sbeBlockLength()) .templateId(Car::sbeTemplateId()) .schemaId(Car::sbeSchemaId()) .version(Car::sbeSchemaVersion()); car.wrapForEncode(m_buffer, hdr.encodedLength(), sizeof(m_buffer)) .serialNumber(SERIAL_NUMBER) .modelYear(MODEL_YEAR) .available(AVAILABLE) .code(CODE) .putVehicleCode(VEHICLE_CODE); for (std::uint64_t i = 0; i < Car::someNumbersLength(); i++) { car.someNumbers(i, static_cast<std::int32_t>(i)); } car.extras().clear() .cruiseControl(CRUISE_CONTROL) .sportsPack(SPORTS_PACK) .sunRoof(SUNROOF); car.engine() .capacity(engineCapacity) .numCylinders(engineNumCylinders) .putManufacturerCode(MANUFACTURER_CODE); Car::FuelFigures& fuelFigures = car.fuelFiguresCount(FUEL_FIGURES_COUNT); fuelFigures .next().speed(fuel1Speed).mpg(fuel1Mpg); fuelFigures.putUsageDescription( FUEL_FIGURES_1_USAGE_DESCRIPTION, static_cast<int>(strlen(FUEL_FIGURES_1_USAGE_DESCRIPTION))); fuelFigures .next().speed(fuel2Speed).mpg(fuel2Mpg); fuelFigures.putUsageDescription( FUEL_FIGURES_2_USAGE_DESCRIPTION, static_cast<int>(strlen(FUEL_FIGURES_2_USAGE_DESCRIPTION))); fuelFigures .next().speed(fuel3Speed).mpg(fuel3Mpg); fuelFigures.putUsageDescription( FUEL_FIGURES_3_USAGE_DESCRIPTION, static_cast<int>(strlen(FUEL_FIGURES_3_USAGE_DESCRIPTION))); Car::PerformanceFigures &perfFigs = car.performanceFiguresCount(PERFORMANCE_FIGURES_COUNT); perfFigs.next() .octaneRating(perf1Octane) .accelerationCount(ACCELERATION_COUNT) .next().mph(perf1aMph).seconds(perf1aSeconds) .next().mph(perf1bMph).seconds(perf1bSeconds) .next().mph(perf1cMph).seconds(perf1cSeconds); perfFigs.next() .octaneRating(perf2Octane) .accelerationCount(ACCELERATION_COUNT) .next().mph(perf2aMph).seconds(perf2aSeconds) .next().mph(perf2bMph).seconds(perf2bSeconds) .next().mph(perf2cMph).seconds(perf2cSeconds); car.putMake(MAKE, static_cast<int>(strlen(MAKE))); car.putModel(MODEL, static_cast<int>(strlen(MODEL))); car.putActivationCode(ACTIVATION_CODE, static_cast<int>(strlen(ACTIVATION_CODE))); return hdr.encodedLength() + car.encodedLength(); }
void decodeCar(Car &car, char *buffer, int offset, int actingBlockLength, int actingVersion) { car.wrapForDecode(buffer, offset, actingBlockLength, actingVersion); std::string sb; sb.append("\ncar.serialNumberId=").append(format(Car::serialNumberSchemaId())); sb.append("\ncar.modelYearId=").append(format(Car::modelYearSchemaId())); sb.append("\ncar.availableId=").append(format(Car::availableSchemaId())); sb.append("\ncar.codeId=").append(format(Car::codeSchemaId())); sb.append("\ncar.someNumbersId=").append(format(Car::someNumbersSchemaId())); sb.append("\ncar.vehicleCodeId=").append(format(Car::vehicleCodeSchemaId())); sb.append("\ncar.extrasId=").append(format(Car::extrasSchemaId())); sb.append("\ncar.engineId=").append(format(Car::engineSchemaId())); sb.append("\ncar.fuelFiguresId=").append(format(Car::fuelFiguresSchemaId())); sb.append("\ncar.fuelFigures.speedId=").append(format(Car::FuelFigures::speedSchemaId())); sb.append("\ncar.fuelFigures.mpgId=").append(format(Car::FuelFigures::mpgSchemaId())); sb.append("\ncar.performanceFiguresId=").append(format(Car::performanceFiguresSchemaId())); sb.append("\ncar.performanceFigures.octaneRatingId=").append(format(Car::PerformanceFigures::octaneRatingSchemaId())); sb.append("\ncar.performanceFigures.accelerationId=").append(format(Car::PerformanceFigures::accelerationSchemaId())); sb.append("\ncar.performanceFigures.acceleration.mphId=").append(format(Car::PerformanceFigures::Acceleration::mphSchemaId())); sb.append("\ncar.performanceFigures.acceleration.secondsId=").append(format(Car::PerformanceFigures::Acceleration::secondsSchemaId())); sb.append("\ncar.makeId=").append(format(Car::makeSchemaId())); sb.append("\ncar.makeCharacterEncoding=").append(Car::makeCharacterEncoding()); sb.append("\ncar.makeMetaAttribute.SEMANTIC_TYPE=").append(Car::makeMetaAttribute(MetaAttribute::SEMANTIC_TYPE)); sb.append("\ncar.modelId=").append(format(Car::modelSchemaId())); sb.append("\ncar.modelCharacterEncoding=").append(Car::modelCharacterEncoding()); sb.append("\n"); sb.append("\ncar.serialNumber=").append(format((int)car.serialNumber())); sb.append("\ncar.modelYear=").append(format((int)car.modelYear())); sb.append("\ncar.available=").append(format(car.available())); sb.append("\ncar.code=").append(format(car.code())); sb.append("\ncar.someNumbers="); for (int i = 0, size = Car::someNumbersLength(); i < size; i++) { sb.append(format(car.someNumbers(i))).append(", "); } sb.append("\ncar.vehicleCodeLength=").append(format((int)car.vehicleCodeLength())); sb.append("\ncar.vehicleCode="); for (int i = 0, size = Car::vehicleCodeLength(); i < size; i++) { sb.append(format((char)car.vehicleCode(i))); } OptionalExtras &extras = car.extras(); sb.append("\ncar.extras.cruiseControl=").append(format(extras.cruiseControl())); sb.append("\ncar.extras.sportsPack=").append(format(extras.sportsPack())); sb.append("\ncar.extras.sunRoof=").append(format(extras.sunRoof())); Engine &engine = car.engine(); sb.append("\ncar.engine.capacity=").append(format((int)engine.capacity())); sb.append("\ncar.engine.numCylinders=").append(format((int)engine.numCylinders())); sb.append("\ncar.engine.maxRpm=").append(format((int)engine.maxRpm())); sb.append("\ncar.engine.manufacturerCodeLength=").append(format((int)engine.manufacturerCodeLength())); sb.append("\ncar.engine.manufacturerCode="); for (int i = 0, size = Engine::manufacturerCodeLength(); i < size; i++) { sb.append(format((char)engine.manufacturerCode(i))); } char tmp[1024]; int bytesCopied = engine.getFuel(tmp, sizeof(tmp)); sb.append("\ncar.engine.fuelLength=").append(format(bytesCopied)); sb.append("\ncar.engine.fuel=").append(tmp, bytesCopied); Car::FuelFigures &fuelFigures = car.fuelFigures(); while (fuelFigures.hasNext()) { fuelFigures.next(); sb.append("\ncar.fuelFigures.speed=").append(format((int)fuelFigures.speed())); sb.append("\ncar.fuelFigures.mpg=").append(format((double)fuelFigures.mpg())); } Car::PerformanceFigures &performanceFigures = car.performanceFigures(); while (performanceFigures.hasNext()) { performanceFigures.next(); sb.append("\ncar.performanceFigures.octaneRating=").append(format((int)performanceFigures.octaneRating())); Car::PerformanceFigures::Acceleration &acceleration = performanceFigures.acceleration(); while (acceleration.hasNext()) { acceleration.next(); sb.append("\ncar.performanceFigures.acceleration.mph=").append(format((int)acceleration.mph())); sb.append("\ncar.performanceFigures.acceleration.seconds=").append(format((double)acceleration.seconds())); } } bytesCopied = car.getMake(tmp, sizeof(tmp)); sb.append("\ncar.makeLength=").append(format((int)bytesCopied)); sb.append("\ncar.make=").append(tmp, bytesCopied); bytesCopied = car.getModel(tmp, sizeof(tmp)); sb.append("\ncar.modelLength=").append(format((int)bytesCopied)); sb.append("\ncar.model=").append(tmp, bytesCopied); cout << sb << endl; }
std::size_t decodeCar( Car &car, char *buffer, std::uint64_t offset, std::uint64_t actingBlockLength, std::uint64_t actingVersion, std::uint64_t bufferLength) { car.wrapForDecode(buffer, offset, actingBlockLength, actingVersion, bufferLength); std::cout.setf(std::ios::fixed); std::cout << "\ncar.serialNumberId=" << Car::serialNumberId(); std::cout << "\ncar.modelYearId=" << Car::modelYearId(); std::cout << "\ncar.availableId=" << Car::availableId(); std::cout << "\ncar.codeId=" << Car::codeId(); std::cout << "\ncar.someNumbersId=" << Car::someNumbersId(); std::cout << "\ncar.vehicleCodeId=" << Car::vehicleCodeId(); std::cout << "\ncar.extrasId=" << Car::extrasId(); std::cout << "\ncar.engineId=" << Car::engineId(); std::cout << "\ncar.fuelFiguresId=" << Car::fuelFiguresId(); std::cout << "\ncar.fuelFigures.speedId=" << Car::FuelFigures::speedId(); std::cout << "\ncar.fuelFigures.mpgId=" << Car::FuelFigures::mpgId(); std::cout << "\ncar.fuelFigures.usageDescriptionId=" << Car::FuelFigures::usageDescriptionId(); std::cout << "\ncar.performanceFiguresId=" << Car::performanceFiguresId(); std::cout << "\ncar.performanceFigures.octaneRatingId=" << Car::PerformanceFigures::octaneRatingId(); std::cout << "\ncar.performanceFigures.accelerationId=" << Car::PerformanceFigures::accelerationId(); std::cout << "\ncar.performanceFigures.acceleration.mphId=" << Car::PerformanceFigures::Acceleration::mphId(); std::cout << "\ncar.performanceFigures.acceleration.secondsId=" << Car::PerformanceFigures::Acceleration::secondsId(); std::cout << "\ncar.makeId=" << Car::makeId(); std::cout << "\ncar.makeCharacterEncoding=" << Car::makeCharacterEncoding(); std::cout << "\ncar.modelId=" << Car::modelId(); std::cout << "\ncar.modelCharacterEncoding=" << Car::modelCharacterEncoding(); std::cout << "\ncar.activationCodeId=" << Car::activationCodeId(); std::cout << "\ncar.activationCodeCharacterEncoding=" << Car::activationCodeCharacterEncoding(); std::cout << "\n"; std::cout << "\ncar.serialNumber=" << car.serialNumber(); std::cout << "\ncar.modelYear=" << car.modelYear(); std::cout << "\ncar.available=" << format(car.available()); std::cout << "\ncar.code=" << format(car.code()); std::cout << "\ncar.someNumbers="; std::string separator(""); for (std::uint64_t i = 0; i < Car::someNumbersLength(); i++) { std::cout << separator << car.someNumbers(i); separator = ", "; } std::cout << "\ncar.vehicleCode="; separator = ""; for (std::uint64_t i = 0; i < Car::vehicleCodeLength(); i++) { std::cout << separator << car.vehicleCode(i); separator = ", "; } OptionalExtras &extras = car.extras(); std::cout << "\ncar.extras.cruiseControl=" << format(extras.cruiseControl()); std::cout << "\ncar.extras.sportsPack=" << format(extras.sportsPack()); std::cout << "\ncar.extras.sunRoof=" << format(extras.sunRoof()); std::cout << "\ncar.discountedModel=" << format(car.discountedModel()); Engine &engine = car.engine(); std::cout << "\ncar.engine.capacity=" << (int)engine.capacity(); std::cout << "\ncar.engine.numCylinders=" << (int)engine.numCylinders(); std::cout << "\ncar.engine.maxRpm=" << (int)engine.maxRpm(); std::cout << "\ncar.engine.manufacturerCodeLength=" << (int)engine.manufacturerCodeLength(); std::cout << "\ncar.engine.manufacturerCode="; separator = ""; for (std::uint64_t i = 0; i < Engine::manufacturerCodeLength(); i++) { std::cout << separator << engine.manufacturerCode(i); separator = ", "; } char tmp[1024]; std::uint64_t bytesCopied = engine.getFuel(tmp, sizeof(tmp)); std::cout << "\ncar.engine.fuelLength=" << bytesCopied; std::cout << "\ncar.engine.fuel=" << std::string(tmp, bytesCopied); Car::FuelFigures &fuelFigures = car.fuelFigures(); while (fuelFigures.hasNext()) { fuelFigures.next(); std::cout << "\ncar.fuelFigures.speed=" << (int)fuelFigures.speed(); std::cout << "\ncar.fuelFigures.mpg=" << std::setprecision(1) << (double)fuelFigures.mpg(); std::string usageDesc = fuelFigures.getUsageDescriptionAsString(); std::cout << "\ncar.fuelFigures.usageDescriptionLength=" << usageDesc.length(); std::cout << "\ncar.fuelFigures.usageDescription=" << usageDesc; } Car::PerformanceFigures &performanceFigures = car.performanceFigures(); while (performanceFigures.hasNext()) { performanceFigures.next(); std::cout << "\ncar.performanceFigures.octaneRating=" << (std::uint64_t)performanceFigures.octaneRating(); Car::PerformanceFigures::Acceleration &acceleration = performanceFigures.acceleration(); while (acceleration.hasNext()) { acceleration.next(); std::cout << "\ncar.performanceFigures.acceleration.mph=" << acceleration.mph(); std::cout << "\ncar.performanceFigures.acceleration.seconds=" << std::setprecision(1) << acceleration.seconds(); } } bytesCopied = car.getMake(tmp, sizeof(tmp)); std::cout << "\ncar.makeLength=" << bytesCopied; std::cout << "\ncar.make=" << std::string(tmp, bytesCopied); bytesCopied = car.getModel(tmp, sizeof(tmp)); std::cout << "\ncar.modelLength=" << bytesCopied; std::cout << "\ncar.model=" << std::string(tmp, bytesCopied); bytesCopied = car.getActivationCode(tmp, sizeof(tmp)); std::cout << "\ncar.activationCodeLength=" << bytesCopied; std::cout << "\ncar.activationCode=" << std::string(tmp, bytesCopied); std::cout << "\ncar.encodedLength=" << (int)car.encodedLength() << "\n"; return car.encodedLength(); }