本文整理汇总了C++中MessageHeader::encodedLength方法的典型用法代码示例。如果您正苦于以下问题:C++ MessageHeader::encodedLength方法的具体用法?C++ MessageHeader::encodedLength怎么用?C++ MessageHeader::encodedLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageHeader
的用法示例。
在下文中一共展示了MessageHeader::encodedLength方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: encodeHdrAndMsg
virtual std::uint64_t encodeHdrAndMsg()
{
MessageHeader hdr;
Msg msg;
hdr.wrap(m_buffer, 0, 0, sizeof(m_buffer))
.blockLength(Msg::sbeBlockLength())
.templateId(Msg::sbeTemplateId())
.schemaId(Msg::sbeSchemaId())
.version(Msg::sbeSchemaVersion());
msg.wrapForEncode(m_buffer, hdr.encodedLength(), sizeof(m_buffer));
msg.structure()
.enumOne(EnumOne::Value10)
.zeroth(42)
.setOne().clear().bit0(false).bit16(true).bit26(false);
msg.structure()
.inner()
.first(101)
.second(202);
return hdr.encodedLength() + msg.encodedLength();
}
示例2: encodeHdrAndMsg
std::uint64_t encodeHdrAndMsg()
{
MessageHeader hdr;
TestMessage1 msg;
hdr.wrap(m_buffer, 0, 0, sizeof(m_buffer))
.blockLength(TestMessage1::sbeBlockLength())
.templateId(TestMessage1::sbeTemplateId())
.schemaId(TestMessage1::sbeSchemaId())
.version(TestMessage1::sbeSchemaVersion());
msg.wrapForEncode(m_buffer, hdr.encodedLength(), sizeof(m_buffer));
TestMessage1::Entries &entries = msg.entriesCount(2);
entries.next()
.tagGroup1(10)
.tagGroup2(20);
entries.next()
.tagGroup1(30)
.tagGroup2(40);
return hdr.encodedLength() + msg.encodedLength();
}
示例3: encodeHdrAndMsg
std::uint64_t encodeHdrAndMsg()
{
MessageHeader hdr;
MsgName msg;
hdr.wrap(m_buffer, 0, 0, sizeof(m_buffer))
.blockLength(MsgName::sbeBlockLength())
.templateId(MsgName::sbeTemplateId())
.schemaId(MsgName::sbeSchemaId())
.version(MsgName::sbeSchemaVersion());
msg.wrapForEncode(m_buffer, hdr.encodedLength(), sizeof(m_buffer));
msg.field1(187);
msg.field2().clear()
.choice1(true);
MsgName::GrName &grp = msg.grNameCount(2);
grp.next()
.grField1(10)
.grField2(20);
grp.next()
.grField1(30)
.grField2(40);
return hdr.encodedLength() + msg.encodedLength();
}
示例4: main
int main(int argc, const char* argv[])
{
char buffer[2048];
MessageHeader hdr;
Car car;
std::size_t encodeHdrLength = encodeHdr(hdr, car, buffer, 0, sizeof(buffer));
std::size_t encodeMsgLength = encodeCar(car, buffer, hdr.encodedLength(), sizeof(buffer));
cout << "Encoded Lengths are " << encodeHdrLength << " + " << encodeMsgLength << endl;
std::size_t decodeHdrLength = decodeHdr(hdr, buffer, 0, sizeof(buffer));
std::size_t decodeMsgLength = decodeCar(car, buffer, hdr.encodedLength(), hdr.blockLength(), hdr.version(), sizeof(buffer));
cout << "Decoded Lengths are " << decodeHdrLength << " + " << decodeMsgLength << endl;
if (encodeHdrLength != decodeHdrLength)
{
cerr << "Encode/Decode header lengths do not match\n";
return EXIT_FAILURE;
}
if (encodeMsgLength != decodeMsgLength)
{
cerr << "Encode/Decode message lengths do not match\n";
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
示例5: decodeHdr
std::size_t decodeHdr(MessageHeader &hdr, char *buffer, std::uint64_t offset, std::uint64_t bufferLength)
{
hdr.wrap(buffer, offset, messageHeaderVersion, bufferLength);
// decode the header
cout << "messageHeader.blockLength=" << hdr.blockLength() << endl;
cout << "messageHeader.templateId=" << hdr.templateId() << endl;
cout << "messageHeader.schemaId=" << hdr.schemaId() << endl;
cout << "messageHeader.schemaVersion=" << hdr.version() << endl;
cout << "messageHeader.encodedLength=" << hdr.encodedLength() << endl;
return hdr.encodedLength();
}
示例6: encodeHdr
static std::uint64_t encodeHdr(MessageHeader& hdr)
{
hdr.blockLength(Car::sbeBlockLength())
.templateId(Car::sbeTemplateId())
.schemaId(Car::sbeSchemaId())
.version(Car::sbeSchemaVersion());
return hdr.encodedLength();
}
示例7: encodeHdr
std::size_t encodeHdr(MessageHeader &hdr, Car &car, char *buffer, std::uint64_t offset, std::uint64_t bufferLength)
{
// encode the header
hdr.wrap(buffer, offset, messageHeaderVersion, bufferLength)
.blockLength(Car::sbeBlockLength())
.templateId(Car::sbeTemplateId())
.schemaId(Car::sbeSchemaId())
.version(Car::sbeSchemaVersion());
return hdr.encodedLength();
}
示例8: encodeHdrAndCar
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();
}
示例9: hdr
TEST_F(CodeGenTest, shouldbeAbleUseOnStackCodecsAndGroupForEach)
{
char buffer[BUFFER_LEN];
MessageHeader hdr(buffer, sizeof(buffer), 0);
Car car(buffer + hdr.encodedLength(), sizeof(buffer) - hdr.encodedLength());
std::uint64_t hdrSz = encodeHdr(hdr);
std::uint64_t carSz = encodeCar(car);
EXPECT_EQ(hdrSz, expectedHeaderSize);
EXPECT_EQ(carSz, expectedCarSize);
const MessageHeader hdrDecoder(buffer, hdrSz, 0);
EXPECT_EQ(hdrDecoder.blockLength(), Car::sbeBlockLength());
EXPECT_EQ(hdrDecoder.templateId(), Car::sbeTemplateId());
EXPECT_EQ(hdrDecoder.schemaId(), Car::sbeSchemaId());
EXPECT_EQ(hdrDecoder.version(), Car::sbeSchemaVersion());
EXPECT_EQ(hdrDecoder.encodedLength(), expectedHeaderSize);
Car carDecoder(buffer + hdrDecoder.encodedLength(), carSz, hdrDecoder.blockLength(), hdrDecoder.version());
CallbacksForEach cbs;
Car::FuelFigures &fuelFigures = carDecoder.fuelFigures();
EXPECT_EQ(fuelFigures.count(), FUEL_FIGURES_COUNT);
#if __cplusplus >= 201103L
fuelFigures.forEach([&](Car::FuelFigures &figures)
{
cbs.countOfFuelFigures++;
char tmp[256];
figures.getUsageDescription(tmp, sizeof(tmp));
});
#else
fuelFigures.forEach(cbs);
#endif
Car::PerformanceFigures &performanceFigures = carDecoder.performanceFigures();
EXPECT_EQ(performanceFigures.count(), PERFORMANCE_FIGURES_COUNT);
#if __cplusplus >= 201103L
performanceFigures.forEach([&](Car::PerformanceFigures&figures)
{
Car::PerformanceFigures::Acceleration acceleration = figures.acceleration();
cbs.countOfPerformanceFigures++;
acceleration.forEach([&](Car::PerformanceFigures::Acceleration&)
{
cbs.countOfAccelerations++;
});
});
#else
performanceFigures.forEach(cbs);
#endif
EXPECT_EQ(cbs.countOfFuelFigures, FUEL_FIGURES_COUNT);
EXPECT_EQ(cbs.countOfPerformanceFigures, PERFORMANCE_FIGURES_COUNT);
EXPECT_EQ(cbs.countOfAccelerations, ACCELERATION_COUNT * PERFORMANCE_FIGURES_COUNT);
char tmp[256];
EXPECT_EQ(carDecoder.getMake(tmp, sizeof(tmp)), MAKE_LENGTH);
EXPECT_EQ(std::string(tmp, MAKE_LENGTH), MAKE);
EXPECT_EQ(carDecoder.getModel(tmp, sizeof(tmp)), MODEL_LENGTH);
EXPECT_EQ(std::string(tmp, MODEL_LENGTH), MODEL);
EXPECT_EQ(carDecoder.getMake(tmp, sizeof(tmp)), ACTIVATION_CODE_LENGTH);
EXPECT_EQ(std::string(tmp, ACTIVATION_CODE_LENGTH), ACTIVATION_CODE);
EXPECT_EQ(carDecoder.encodedLength(), expectedCarSize);
}