Distinguish signed, float in type descriptor

* Add a flag to indicate signed integral values and one to indicate
  floating-point values
* Set these flags in the output of idlc
* Use them when printing sample contents to the trace

By encoding the information as flags in reserved bits the actual
serialization and deserialization is unaffected.

Signed-off-by: Erik Boasson <eb@ilities.com>
This commit is contained in:
Erik Boasson 2020-04-18 17:32:56 +02:00 committed by eboasson
parent 2e6ea36fda
commit 5f829684ef
3 changed files with 58 additions and 23 deletions

View file

@ -225,6 +225,13 @@ enum dds_stream_typecode_subtype {
#define DDS_OP_FLAG_KEY 0x01 /* key field: applicable to {1,2,4,8}BY, STR, BST, ARR-of-{1,2,4,8}BY */ #define DDS_OP_FLAG_KEY 0x01 /* key field: applicable to {1,2,4,8}BY, STR, BST, ARR-of-{1,2,4,8}BY */
#define DDS_OP_FLAG_DEF 0x02 /* union has a default case (for DDS_OP_ADR | DDS_OP_TYPE_UNI) */ #define DDS_OP_FLAG_DEF 0x02 /* union has a default case (for DDS_OP_ADR | DDS_OP_TYPE_UNI) */
/* For a union: (1) the discriminator may be a key field; (2) there may be a default value;
and (3) the discriminator can be an integral type (or enumerated - here treated as equivalent).
What it can't be is a floating-point type. So DEF and FP need never be set at the same time.
There are only a few flag bits, so saving one is not such a bad idea. */
#define DDS_OP_FLAG_FP 0x02 /* floating-point: applicable to {4,8}BY and arrays, sequences of them */
#define DDS_OP_FLAG_SGN 0x04 /* signed: applicable to {1,2,4,8}BY and arrays, sequences of them */
/** /**
* Description : Enable or disable write batching. Overrides default configuration * Description : Enable or disable write batching. Overrides default configuration
* setting for write batching (Internal/WriteBatch). * setting for write batching (Internal/WriteBatch).

View file

@ -1995,14 +1995,42 @@ static size_t isprint_runlen (const unsigned char *s, size_t n)
return m; return m;
} }
static bool prtf_simple (char * __restrict *buf, size_t * __restrict bufsize, dds_istream_t * __restrict is, enum dds_stream_typecode type) static bool prtf_simple (char * __restrict *buf, size_t * __restrict bufsize, dds_istream_t * __restrict is, enum dds_stream_typecode type, unsigned flags)
{ {
switch (type) switch (type)
{ {
case DDS_OP_VAL_1BY: return prtf (buf, bufsize, "%"PRIu8, dds_is_get1 (is)); case DDS_OP_VAL_1BY: {
case DDS_OP_VAL_2BY: return prtf (buf, bufsize, "%"PRIu16, dds_is_get2 (is)); const union { int8_t s; uint8_t u; } x = { .u = dds_is_get1 (is) };
case DDS_OP_VAL_4BY: return prtf (buf, bufsize, "%"PRIu32, dds_is_get4 (is)); if (flags & DDS_OP_FLAG_SGN)
case DDS_OP_VAL_8BY: return prtf (buf, bufsize, "%"PRIu64, dds_is_get8 (is)); return prtf (buf, bufsize, "%"PRId8, x.s);
else
return prtf (buf, bufsize, "%"PRIu8, x.u);
}
case DDS_OP_VAL_2BY: {
const union { int16_t s; uint16_t u; } x = { .u = dds_is_get2 (is) };
if (flags & DDS_OP_FLAG_SGN)
return prtf (buf, bufsize, "%"PRId16, x.s);
else
return prtf (buf, bufsize, "%"PRIu16, x.u);
}
case DDS_OP_VAL_4BY: {
const union { int32_t s; uint32_t u; float f; } x = { .u = dds_is_get4 (is) };
if (flags & DDS_OP_FLAG_FP)
return prtf (buf, bufsize, "%g", x.f);
else if (flags & DDS_OP_FLAG_SGN)
return prtf (buf, bufsize, "%"PRId32, x.s);
else
return prtf (buf, bufsize, "%"PRIu32, x.u);
}
case DDS_OP_VAL_8BY: {
const union { int64_t s; uint64_t u; double f; } x = { .u = dds_is_get8 (is) };
if (flags & DDS_OP_FLAG_FP)
return prtf (buf, bufsize, "%g", x.f);
else if (flags & DDS_OP_FLAG_SGN)
return prtf (buf, bufsize, "%"PRId64, x.s);
else
return prtf (buf, bufsize, "%"PRIu64, x.u);
}
case DDS_OP_VAL_STR: case DDS_OP_VAL_BST: return prtf_str (buf, bufsize, is); case DDS_OP_VAL_STR: case DDS_OP_VAL_BST: return prtf_str (buf, bufsize, is);
case DDS_OP_VAL_ARR: case DDS_OP_VAL_SEQ: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU: case DDS_OP_VAL_ARR: case DDS_OP_VAL_SEQ: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU:
abort (); abort ();
@ -2010,7 +2038,7 @@ static bool prtf_simple (char * __restrict *buf, size_t * __restrict bufsize, dd
return false; return false;
} }
static bool prtf_simple_array (char * __restrict *buf, size_t * __restrict bufsize, dds_istream_t * __restrict is, uint32_t num, enum dds_stream_typecode type) static bool prtf_simple_array (char * __restrict *buf, size_t * __restrict bufsize, dds_istream_t * __restrict is, uint32_t num, enum dds_stream_typecode type, unsigned flags)
{ {
bool cont = prtf (buf, bufsize, "{"); bool cont = prtf (buf, bufsize, "{");
switch (type) switch (type)
@ -2033,7 +2061,7 @@ static bool prtf_simple_array (char * __restrict *buf, size_t * __restrict bufsi
{ {
if (i != 0) if (i != 0)
(void) prtf (buf, bufsize, ","); (void) prtf (buf, bufsize, ",");
cont = prtf_simple (buf, bufsize, is, type); cont = prtf_simple (buf, bufsize, is, type, flags);
i++; i++;
} }
} }
@ -2045,7 +2073,7 @@ static bool prtf_simple_array (char * __restrict *buf, size_t * __restrict bufsi
{ {
if (i != 0) if (i != 0)
(void) prtf (buf, bufsize, ","); (void) prtf (buf, bufsize, ",");
cont = prtf_simple (buf, bufsize, is, type); cont = prtf_simple (buf, bufsize, is, type, flags);
} }
break; break;
default: default:
@ -2070,10 +2098,10 @@ static const uint32_t *prtf_seq (char * __restrict *buf, size_t *bufsize, dds_is
switch (subtype) switch (subtype)
{ {
case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY: case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY:
(void) prtf_simple_array (buf, bufsize, is, num, subtype); (void) prtf_simple_array (buf, bufsize, is, num, subtype, DDS_OP_FLAGS (insn));
return ops + 2; return ops + 2;
case DDS_OP_VAL_STR: case DDS_OP_VAL_BST: case DDS_OP_VAL_STR: case DDS_OP_VAL_BST:
(void) prtf_simple_array (buf, bufsize, is, num, subtype); (void) prtf_simple_array (buf, bufsize, is, num, subtype, DDS_OP_FLAGS (insn));
return ops + (subtype == DDS_OP_VAL_STR ? 2 : 3); return ops + (subtype == DDS_OP_VAL_STR ? 2 : 3);
case DDS_OP_VAL_SEQ: case DDS_OP_VAL_ARR: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU: { case DDS_OP_VAL_SEQ: case DDS_OP_VAL_ARR: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU: {
const uint32_t jmp = DDS_OP_ADR_JMP (ops[3]); const uint32_t jmp = DDS_OP_ADR_JMP (ops[3]);
@ -2098,10 +2126,10 @@ static const uint32_t *prtf_arr (char * __restrict *buf, size_t *bufsize, dds_is
switch (subtype) switch (subtype)
{ {
case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY: case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY:
(void) prtf_simple_array (buf, bufsize, is, num, subtype); (void) prtf_simple_array (buf, bufsize, is, num, subtype, DDS_OP_FLAGS (insn));
return ops + 3; return ops + 3;
case DDS_OP_VAL_STR: case DDS_OP_VAL_BST: case DDS_OP_VAL_STR: case DDS_OP_VAL_BST:
(void) prtf_simple_array (buf, bufsize, is, num, subtype); (void) prtf_simple_array (buf, bufsize, is, num, subtype, DDS_OP_FLAGS (insn));
return ops + (subtype == DDS_OP_VAL_STR ? 3 : 5); return ops + (subtype == DDS_OP_VAL_STR ? 3 : 5);
case DDS_OP_VAL_SEQ: case DDS_OP_VAL_ARR: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU: { case DDS_OP_VAL_SEQ: case DDS_OP_VAL_ARR: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU: {
const uint32_t *jsr_ops = ops + DDS_OP_ADR_JSR (ops[3]); const uint32_t *jsr_ops = ops + DDS_OP_ADR_JSR (ops[3]);
@ -2132,7 +2160,7 @@ static const uint32_t *prtf_uni (char * __restrict *buf, size_t *bufsize, dds_is
{ {
case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY: case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY:
case DDS_OP_VAL_STR: case DDS_OP_VAL_BST: case DDS_OP_VAL_STR: case DDS_OP_VAL_BST:
(void) prtf_simple (buf, bufsize, is, valtype); (void) prtf_simple (buf, bufsize, is, valtype, DDS_OP_FLAGS (jeq_op[0]));
break; break;
case DDS_OP_VAL_SEQ: case DDS_OP_VAL_ARR: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU: case DDS_OP_VAL_SEQ: case DDS_OP_VAL_ARR: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU:
(void) dds_stream_print_sample1 (buf, bufsize, is, jeq_op + DDS_OP_ADR_JSR (jeq_op[0]), valtype == DDS_OP_VAL_STU); (void) dds_stream_print_sample1 (buf, bufsize, is, jeq_op + DDS_OP_ADR_JSR (jeq_op[0]), valtype == DDS_OP_VAL_STU);
@ -2161,11 +2189,11 @@ static bool dds_stream_print_sample1 (char * __restrict *buf, size_t * __restric
{ {
case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY: case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY:
case DDS_OP_VAL_STR: case DDS_OP_VAL_STR:
cont = prtf_simple (buf, bufsize, is, DDS_OP_TYPE (insn)); cont = prtf_simple (buf, bufsize, is, DDS_OP_TYPE (insn), DDS_OP_FLAGS (insn));
ops += 2; ops += 2;
break; break;
case DDS_OP_VAL_BST: case DDS_OP_VAL_BST:
cont = prtf_simple (buf, bufsize, is, DDS_OP_TYPE (insn)); cont = prtf_simple (buf, bufsize, is, DDS_OP_TYPE (insn), DDS_OP_FLAGS (insn));
ops += 3; ops += 3;
break; break;
case DDS_OP_VAL_SEQ: case DDS_OP_VAL_SEQ:
@ -2217,10 +2245,10 @@ size_t dds_stream_print_key (dds_istream_t * __restrict is, const struct ddsi_se
{ {
case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY: case DDS_OP_VAL_1BY: case DDS_OP_VAL_2BY: case DDS_OP_VAL_4BY: case DDS_OP_VAL_8BY:
case DDS_OP_VAL_STR: case DDS_OP_VAL_BST: case DDS_OP_VAL_STR: case DDS_OP_VAL_BST:
cont = prtf_simple (&buf, &bufsize, is, DDS_OP_TYPE (*op)); cont = prtf_simple (&buf, &bufsize, is, DDS_OP_TYPE (*op), DDS_OP_FLAGS (*op));
break; break;
case DDS_OP_VAL_ARR: case DDS_OP_VAL_ARR:
cont = prtf_simple_array (&buf, &bufsize, is, op[2], DDS_OP_SUBTYPE (*op)); cont = prtf_simple_array (&buf, &bufsize, is, op[2], DDS_OP_SUBTYPE (*op), DDS_OP_FLAGS (*op));
break; break;
case DDS_OP_VAL_SEQ: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU: case DDS_OP_VAL_SEQ: case DDS_OP_VAL_UNI: case DDS_OP_VAL_STU:
abort (); abort ();

View file

@ -20,15 +20,15 @@ public class BasicType extends AbstractType
{ {
BOOLEAN ("bool", "DDS_OP_TYPE_BOO", "DDS_OP_SUBTYPE_BOO", Alignment.BOOL, "Boolean"), BOOLEAN ("bool", "DDS_OP_TYPE_BOO", "DDS_OP_SUBTYPE_BOO", Alignment.BOOL, "Boolean"),
OCTET ("uint8_t", "DDS_OP_TYPE_1BY", "DDS_OP_SUBTYPE_1BY", Alignment.ONE, "Octet"), OCTET ("uint8_t", "DDS_OP_TYPE_1BY", "DDS_OP_SUBTYPE_1BY", Alignment.ONE, "Octet"),
CHAR ("char", "DDS_OP_TYPE_1BY", "DDS_OP_SUBTYPE_1BY", Alignment.ONE, "Char"), CHAR ("char", "DDS_OP_TYPE_1BY | DDS_OP_FLAG_SGN", "DDS_OP_SUBTYPE_1BY | DDS_OP_FLAG_SGN", Alignment.ONE, "Char"),
SHORT ("int16_t", "DDS_OP_TYPE_2BY", "DDS_OP_SUBTYPE_2BY", Alignment.TWO, "Short"), SHORT ("int16_t", "DDS_OP_TYPE_2BY | DDS_OP_FLAG_SGN", "DDS_OP_SUBTYPE_2BY | DDS_OP_FLAG_SGN", Alignment.TWO, "Short"),
USHORT ("uint16_t", "DDS_OP_TYPE_2BY", "DDS_OP_SUBTYPE_2BY", Alignment.TWO, "UShort"), USHORT ("uint16_t", "DDS_OP_TYPE_2BY", "DDS_OP_SUBTYPE_2BY", Alignment.TWO, "UShort"),
LONG ("int32_t", "DDS_OP_TYPE_4BY", "DDS_OP_SUBTYPE_4BY", Alignment.FOUR, "Long"), LONG ("int32_t", "DDS_OP_TYPE_4BY | DDS_OP_FLAG_SGN", "DDS_OP_SUBTYPE_4BY | DDS_OP_FLAG_SGN", Alignment.FOUR, "Long"),
ULONG ("uint32_t", "DDS_OP_TYPE_4BY", "DDS_OP_SUBTYPE_4BY", Alignment.FOUR, "ULong"), ULONG ("uint32_t", "DDS_OP_TYPE_4BY", "DDS_OP_SUBTYPE_4BY", Alignment.FOUR, "ULong"),
LONGLONG ("int64_t", "DDS_OP_TYPE_8BY", "DDS_OP_SUBTYPE_8BY", Alignment.EIGHT, "LongLong"), LONGLONG ("int64_t", "DDS_OP_TYPE_8BY | DDS_OP_FLAG_SGN", "DDS_OP_SUBTYPE_8BY | DDS_OP_FLAG_SGN", Alignment.EIGHT, "LongLong"),
ULONGLONG ("uint64_t", "DDS_OP_TYPE_8BY", "DDS_OP_SUBTYPE_8BY", Alignment.EIGHT, "ULongLong"), ULONGLONG ("uint64_t", "DDS_OP_TYPE_8BY", "DDS_OP_SUBTYPE_8BY", Alignment.EIGHT, "ULongLong"),
FLOAT ("float", "DDS_OP_TYPE_4BY", "DDS_OP_SUBTYPE_4BY", Alignment.FOUR, "Float"), FLOAT ("float", "DDS_OP_TYPE_4BY | DDS_OP_FLAG_FP", "DDS_OP_SUBTYPE_4BY | DDS_OP_FLAG_FP", Alignment.FOUR, "Float"),
DOUBLE ("double", "DDS_OP_TYPE_8BY", "DDS_OP_SUBTYPE_8BY", Alignment.EIGHT, "Double"), DOUBLE ("double", "DDS_OP_TYPE_8BY | DDS_OP_FLAG_FP", "DDS_OP_SUBTYPE_8BY | DDS_OP_FLAG_FP", Alignment.EIGHT, "Double"),
STRING ("char *", "DDS_OP_TYPE_STR", "DDS_OP_SUBTYPE_STR", Alignment.PTR, "String"); STRING ("char *", "DDS_OP_TYPE_STR", "DDS_OP_SUBTYPE_STR", Alignment.PTR, "String");
public final String cType; public final String cType;