nfc_ndef.c
ndef_status_t ndef_parse_next_rec(uint8_t *buf, ndef_record_t *rec, size_t *br)
{
    /* Check parameters are valid */
    if((buf == NULL) || (rec == NULL) || (br == 0))
        return NDEF_E_INVALID_ARGS;

    /* Check the NDEF record has at least the MB or ME set for validity */
    if (NDEF_RECORD_GET_FLAG(*buf, NDEF_RECORD_FLAG_MB) == 0 &&
        NDEF_RECORD_GET_FLAG(*buf, NDEF_RECORD_FLAG_ME) == 0)
        return NDEF_E_NOT_FOUND;

    uint8_t *buf_start = buf;

    rec->header  = *buf++;
    rec->type_len = *buf++;
    
    if (NDEF_RECORD_GET_FLAG(rec->header, NDEF_RECORD_FLAG_SR))
    {
        /* NDEF record is a 'short' sized record, copy the 1-byte 'Paylod Length' field */
        rec->payload_len = *buf++;
    }
    else
    {
        /* NDEF record is a 'normal' sized record, copy the 4-byte 'Payload Length' field */
        rec->payload_len = ntohl(buf);
        buf += sizeof(uint32_t);
    }

    if(NDEF_RECORD_GET_FLAG(rec->header, NDEF_RECORD_FLAG_IL))
        rec->id_len = *buf++;
    else
        rec->id_len = 0;

    rec->type = (rec->type_len == 0) ? NULL : buf;
    buf += rec->type_len;

    rec->id = (rec->id_len == 0) ? NULL : buf;
    buf += rec->id_len;

    rec->payload = (rec->payload_len == 0) ? NULL : buf;
    buf += rec->payload_len;

    rec->total_length = buf - buf_start;

    *br = rec->total_length;

    return NDEF_OK;
}
/*
 * @brief This API parses the next NDEF record found in the buffer.
 */
@brief This API parses the next NDEF record found in the buffer.
@brief This API parses the next NDEF record found in the buffer .
ndef_status_t ndef_parse_next_rec(uint8_t *buf, ndef_record_t *rec, size_t *br)
{
    if((buf == NULL) || (rec == NULL) || (br == 0))
        return NDEF_E_INVALID_ARGS;
    if (NDEF_RECORD_GET_FLAG(*buf, NDEF_RECORD_FLAG_MB) == 0 &&
        NDEF_RECORD_GET_FLAG(*buf, NDEF_RECORD_FLAG_ME) == 0)
        return NDEF_E_NOT_FOUND;
    uint8_t *buf_start = buf;
    rec->header  = *buf++;
    rec->type_len = *buf++;
    if (NDEF_RECORD_GET_FLAG(rec->header, NDEF_RECORD_FLAG_SR))
    {
        rec->payload_len = *buf++;
    }
    else
    {
        rec->payload_len = ntohl(buf);
        buf += sizeof(uint32_t);
    }
    if(NDEF_RECORD_GET_FLAG(rec->header, NDEF_RECORD_FLAG_IL))
        rec->id_len = *buf++;
    else
        rec->id_len = 0;
    rec->type = (rec->type_len == 0) ? NULL : buf;
    buf += rec->type_len;
    rec->id = (rec->id_len == 0) ? NULL : buf;
    buf += rec->id_len;
    rec->payload = (rec->payload_len == 0) ? NULL : buf;
    buf += rec->payload_len;
    rec->total_length = buf - buf_start;
    *br = rec->total_length;
    return NDEF_OK;
}
ndef_status_t ndef_parse_next_rec ( uint8_t * buf , ndef_record_t * rec , size_t * br ) { if ( ( buf == NULL ) || ( rec == NULL ) || ( br == 0 ) ) return NDEF_E_INVALID_ARGS ; if ( NDEF_RECORD_GET_FLAG ( * buf , NDEF_RECORD_FLAG_MB ) == 0 && NDEF_RECORD_GET_FLAG ( * buf , NDEF_RECORD_FLAG_ME ) == 0 ) return NDEF_E_NOT_FOUND ; uint8_t * buf_start = buf ; rec -> header = * buf ++ ; rec -> type_len = * buf ++ ; if ( NDEF_RECORD_GET_FLAG ( rec -> header , NDEF_RECORD_FLAG_SR ) ) { rec -> payload_len = * buf ++ ; } else { rec -> payload_len = ntohl ( buf ) ; buf += sizeof ( uint32_t ) ; } if ( NDEF_RECORD_GET_FLAG ( rec -> header , NDEF_RECORD_FLAG_IL ) ) rec -> id_len = * buf ++ ; else rec -> id_len = 0 ; rec -> type = ( rec -> type_len == 0 ) ? NULL : buf ; buf += rec -> type_len ; rec -> id = ( rec -> id_len == 0 ) ? NULL : buf ; buf += rec -> id_len ; rec -> payload = ( rec -> payload_len == 0 ) ? NULL : buf ; buf += rec -> payload_len ; rec -> total_length = buf - buf_start ; * br = rec -> total_length ; return NDEF_OK ; }
@brief This API parses the next NDEF record found in the buffer.
@brief This API parses the next NDEF record found in the buffer .
/* Check parameters are valid */ /* Check the NDEF record has at least the MB or ME set for validity */ /* NDEF record is a 'short' sized record, copy the 1-byte 'Paylod Length' field */ /* NDEF record is a 'normal' sized record, copy the 4-byte 'Payload Length' field */