Exemplo n.º 1
0
otError Header::AppendUriQueryOption(const char *aUriQuery)
{
    Option coapOption;

    coapOption.mNumber = OT_COAP_OPTION_URI_QUERY;
    coapOption.mLength = static_cast<uint16_t>(strlen(aUriQuery));
    coapOption.mValue  = reinterpret_cast<const uint8_t *>(aUriQuery);

    return AppendOption(coapOption);
}
Exemplo n.º 2
0
otError Header::AppendUriPathOptions(const char *aUriPath)
{
    otError error = OT_ERROR_NONE;
    const char *cur = aUriPath;
    const char *end;
    Header::Option coapOption;

    coapOption.mNumber = OT_COAP_OPTION_URI_PATH;

    while ((end = strchr(cur, '/')) != NULL)
    {
        coapOption.mLength = static_cast<uint16_t>(end - cur);
        coapOption.mValue = reinterpret_cast<const uint8_t *>(cur);
        SuccessOrExit(error = AppendOption(coapOption));
        cur = end + 1;
    }

    coapOption.mLength = static_cast<uint16_t>(strlen(cur));
    coapOption.mValue = reinterpret_cast<const uint8_t *>(cur);
    SuccessOrExit(error = AppendOption(coapOption));

exit:
    return error;
}
Exemplo n.º 3
0
otError Message::AppendUriPathOptions(const char *aUriPath)
{
    otError     error = OT_ERROR_NONE;
    const char *cur   = aUriPath;
    const char *end;

    while ((end = strchr(cur, '/')) != NULL)
    {
        SuccessOrExit(error = AppendOption(OT_COAP_OPTION_URI_PATH, static_cast<uint16_t>(end - cur), cur));
        cur = end + 1;
    }

    SuccessOrExit(error = AppendStringOption(OT_COAP_OPTION_URI_PATH, cur));

exit:
    return error;
}
Exemplo n.º 4
0
otError Message::AppendUintOption(uint16_t aNumber, uint32_t aValue)
{
    uint16_t length = sizeof(aValue);
    uint8_t *value;

    aValue = Encoding::BigEndian::HostSwap32(aValue);
    value  = reinterpret_cast<uint8_t *>(&aValue);

    // skip preceding zeros
    while (value[0] == 0 && length > 0)
    {
        value++;
        length--;
    }

    return AppendOption(aNumber, length, value);
}
Exemplo n.º 5
0
otError Header::AppendUintOption(uint16_t aNumber, uint32_t aValue)
{
    Option coapOption;

    aValue = Encoding::BigEndian::HostSwap32(aValue);
    coapOption.mNumber = aNumber;
    coapOption.mLength = 4;
    coapOption.mValue = reinterpret_cast<uint8_t *>(&aValue);

    // skip preceding zeros
    while (coapOption.mValue[0] == 0 && coapOption.mLength > 0)
    {
        coapOption.mValue++;
        coapOption.mLength--;
    }

    return AppendOption(coapOption);
}
Exemplo n.º 6
0
otError Message::AppendStringOption(uint16_t aNumber, const char *aValue)
{
    return AppendOption(aNumber, static_cast<uint16_t>(strlen(aValue)), aValue);
}