ADTF  3.18.2
(Legacy) Accessing Data with a Decoder/Codec
Remarks
This package is deprecated and is only there for binary compatibility reason. Use the DDL Library instead and have a look at the ADTF Media Description SDK and DDL and ADTF 3.

Let's take a look at a basic structure:

<struct alignment="4" name="tTest" version="1" ddlversion="2.0">
<element name="bBool" type="tBool" arraysize="1">
<serialized byteorder="LE" bytepos="0" bitpos="0" numbits="8"/>
<deserialized alignment="1"/>
</element>
<element name="nInt8" type="tInt8" arraysize="1">
<serialized byteorder="LE" bytepos="1" bitpos="0" numbits="8"/>
<deserialized alignment="1"/>
</element>
<element name="nUInt32" type="tUInt32" arraysize="1">
<serialized byteorder="LE" bytepos="2" bitpos="0" numbits="32"/>
<deserialized alignment="4"/>
</element>
<element name="fFloat32" type="tFloat32" arraysize="1">
<serialized byteorder="LE" bytepos="6" bitpos="0" numbits="32"/>
<deserialized alignment="4"/>
</element>
</struct>

Decoding

Read access is handled with the cDecoder class:

double ReadData(const void* pConstData, size_t nDataSize)
{
// this should of course be cached (as a member etc.)
cCodecFactory oFactory("tTest", "<adtf:ddl>....");
auto oDecoder = oFactory.MakeDecoderFor(pConstData, nDataSize);
adtf_util::cVariant oValue;
// for name based lookup use the access_element namespace
{
oValue = access_element::get_value(oDecoder, "fFloat32");
}
// alternativley you can of course use indexed based lookup
{
oDecoder.GetElementValue(3, oValue);
}
return oValue;
}
tResult get_value(const T &oDecoder, const A_UTILS_NS::cString &strElementName, void *pValue)
Get the value of an element by name.

Encoding

Write access is handled with the cCodec class:

void WriteData(void* pData, size_t nDataSize, double fData)
{
// this should of course be cached (as a member etc.)
cCodecFactory oFactory("tTest", "<adtf:ddl>....");
auto oCodec = oFactory.MakeCodecFor(pData, nDataSize);
// name based lookup
access_element::set_value(oCodec, "fFloat32", fData);
// or index based
oCodec.SetElementValue(3, fData);
}
tResult set_value(T &oCodec, const A_UTILS_NS::cString &strElementName, const void *pValue)
Set the value of an element by name.

Selecting the Data Representation

By default decoders/codecs are created for the deserialized representation. To create them for the serialized representation pass the correct parameters to the Make... methods.

auto oDecoder = oFactory.MakeDecoderFor(pConstData, nDataSize,

Inspection

You can inspect the struct handled by a decoder/codec with the help of cStaticDecoder::GetElement:

void DumpElements(const cStaticDecoder& oDecoder)
{
for (size_t nElement = 0; nElement < oDecoder.GetElementCount(); ++nElement)
{
const tStructElement* pElement;
oDecoder.GetElement(nElement, pElement);
std::cout << pElement->name << std::endl;
}
}

Transformation

Converting between the representations can be done with serialization::transform:

tSize nSerializedSize = oDecoder.GetBufferSize(tDataRepresentation::Serialized);
tUInt8* pBuffer = new tUInt8[nSerializedSize];
auto Codec = oDecoder.MakeCodecFor(pBuffer, nSerializedSize, tDataRepresentation::Serialized);
serialization::transform(oDecoder, oCodec);
uint8_t tUInt8
type definition for unsigned integer values (8bit) (platform and compiler independent type).
size_t tSize
type definition for a array size values, map size values etc.
tResult transform(const Decoder &oDecoder, Encoder &oEncoder)
Copies all elements from a decoder to a codec.

There is also a convienence method serialization::transform_to_buffer that handles the allocation of memory for you with the help of an adtf_util::cMemoryBlock.