does rssl*ToString add 0 in the end of returned string in RsslBuffer.data

Does rssl*ToString add 0 in the end of returned string in RsslBuffer.data so it's a proper C string? API does not mentioned that. Want to double check here.

Best Answer

  • Steven McCoy
    Answer ✓

    Some do, some do not, it is not documented in the reference guide. Some can only be inferred from the example usage.

    One function returning a C String in a RsslBuffer:

    rsslDateTimeToString(&fidDateTimeBuf, RSSL_DT_DATETIME, &fidDateTimeValue);
    printf("%s\n", fidDateTimeBuf.data);

    Another returning only a buffer:

    fidStateBuf.data = (char*)alloca(stateBufLen);
    fidStateBuf.length = stateBufLen;
    rsslStateToString(&fidStateBuf, &fidStateValue);
    printf("%.*s\n", fidStateBuf.length, fidStateBuf.data);

    Also some API completely ignore the apparent RsslBuffer standard signature and do return a C-String.

    const char* rsslQosTimelinessToString(RsslUInt8 value)
    {
    switch (value)
    {
    case RSSL_QOS_TIME_UNSPECIFIED: return "Unspecified";
    case RSSL_QOS_TIME_REALTIME: return "Realtime";
    case RSSL_QOS_TIME_DELAYED_UNKNOWN: return "DelayedByUnknown";
    case RSSL_QOS_TIME_DELAYED: return "DelayedByTimeInfo";
    default: return "Unknown QosTimeliness";
    }
    }

Answers

  • I have tried to debug the rsslStateToString function. The RsslBuffer.data always contains the null termination, even though the example code uses the RsslBuffer.length to print string.

    image

    I think rssl*ToString functions should generally add the 0 at the end of string of the rsslBuffer.data.