On Sat Nov 30 16:25:40 2024 +0000, Rémi Bernon wrote:
We usually use X as a temporary macro, I don't see why XX is better if not necessary. Also in this case with only a couple of cases and the need to redefine it, it doesn't seem very helpful to have a macro in the first place. The default cases for UINT/INT/UUID also looks wrong. What about:
static SIZE_T sdp_type_size( SDP_TYPE type, SDP_SPECIFICTYPE st ) { switch (type) { case SDP_TYPE_NIL: return 0; case SDP_TYPE_UINT: case SDP_TYPE_INT: case SDP_TYPE_UUID: switch (st) { case SDP_ST_UINT8: case SDP_ST_INT8: return 1; case SDP_ST_UINT16: case SDP_ST_INT16: case SDP_ST_UUID16: return 2; case SDP_ST_UINT32: case SDP_ST_INT32: /* case SDP_ST_UUID32: */ return 4; case SDP_ST_UINT64: case SDP_ST_INT64: return 8; case SDP_ST_UINT128: case SDP_ST_INT128: case SDP_ST_UUID128: return 16; default: FIXME( "Unexpected type %#x/%#x\n", type, st ); return 0; } case SDP_TYPE_BOOLEAN: return 1; case SDP_TYPE_STRING: case SDP_TYPE_SEQUENCE: case SDP_TYPE_ALTERNATIVE: case SDP_TYPE_URL: case SDP_TYPE_CONTAINER: return sizeof(BYTE *) + sizeof(ULONG); default: FIXME( "Unexpected type %#x\n", type ); return 0; } }
I would even be fine with `return 1 << ((st >> 8) & 0x7);` for the INT/UINT/UUID case as it seems to be how specific types are encoded.
Oops, forgot about UINT/INT8. Getting the size from masking the specific type is much cleaner, indeed. I've simplified the function now. As far a `default` in case of an unexpected type value is concerned, it shouldn't be necessary. `test_BluetoothSdpGetElementData` already tests the type and specific type fields, which will catch any unexpected values.