I'm attempting to implement a protocol standard and I'm having a bit of trouble with their concept of conditional fields. They are defined as fields that are present or absent depending on some condition. The example they give is as follows:
uint16 Pressure;
enum VehicleType { car = 0, motorbike = 1};
struct TirePressureInfo {
VehicleType type;
select (type)
{
case car:
Pressure frontLeft;
Pressure frontRight;
Pressure rearLeft;
Pressure rearRight;
case motorbike:
Pressure front;
Pressure rear;
}
}
I'm unaware of anyway to make this work in C, or if it's even possible. I can't think of anyway to implement this. One thing to note, is this is going to be implemented in a Linux Kernel Module, so I'm a bit restricted there as well.
struct {
uint8 protocol_version;
ContentType type;
select (type) {
case unsecured :
opaque data<var>;
case signed, signed_partial_payload,
signed_external_payload:
SignedData signed_data;
case signed_wsa:
SignedWsa signed_wsa;
case encrypted :
EncryptedData encrypted_data;
case crl_request :
CrlRequest crl_request;
case crl :
Crl crl;
case other_value:
opaque data<var>;
}
} 1609Dot2Data;
struct {
SignerIdentifierType type;
select (type) {
case self: ;
case certificate_digest_with_ecdsap224 :
case certificate_digest_with_ecdsap256 :
HashedId8 digest;
opaque data<var>;
case certificate:
Certificate certificate;
case certificate_chain:
Certificate certificates<var>;
case certificate_digest_with_other_algorithm :
Signer signer;
PKAlgorithm algorithm;
HashedId8 digest;
case other_value:
opaque id<var>;
}
} SignerIdentifier;