Skip to content

Commit

Permalink
net/nanocoap: add block slicer init function
Browse files Browse the repository at this point in the history
  • Loading branch information
kb2ma committed Jul 25, 2019
1 parent 229bc14 commit 54d3898
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
12 changes: 12 additions & 0 deletions sys/include/net/nanocoap.h
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,18 @@ static inline void coap_block2_finish(coap_block_slicer_t *slicer)
*/
void coap_block2_init(coap_pkt_t *pkt, coap_block_slicer_t *slicer);

/**
* @brief Initialize a block slicer struct from content information
*
* @param[out] slicer slicer struct to initialize
* @param[in] blknum offset from the beginning of content, in terms of
@p blksize byte blocks
* @param[in] blksize size of each block; must be a power of 2 between 16
* and 2 raised to #NANOCOAP_BLOCK_SIZE_EXP_MAX
*/
void coap_block_slicer_init(coap_block_slicer_t *slicer, size_t blknum,
size_t blksize);

/**
* @brief Add a byte array to a block2 reply.
*
Expand Down
13 changes: 10 additions & 3 deletions sys/net/application_layer/nanocoap/nanocoap.c
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,14 @@ void coap_block_object_init(coap_block1_t *block, size_t blknum, size_t blksize,
block->more = more;
}

void coap_block_slicer_init(coap_block_slicer_t *slicer, size_t blknum,
size_t blksize)
{
slicer->start = blknum * blksize;
slicer->end = slicer->start + blksize;
slicer->cur = 0;
}

void coap_block2_init(coap_pkt_t *pkt, coap_block_slicer_t *slicer)
{
uint32_t blknum;
Expand All @@ -896,9 +904,8 @@ void coap_block2_init(coap_pkt_t *pkt, coap_block_slicer_t *slicer)
szx = NANOCOAP_BLOCK_SIZE_EXP_MAX - 4;
}
}
slicer->start = blknum * coap_szx2size(szx);
slicer->end = slicer->start + coap_szx2size(szx);
slicer->cur = 0;

coap_block_slicer_init(slicer, blknum, coap_szx2size(szx));
}

void coap_block_finish(coap_block_slicer_t *slicer, uint16_t option)
Expand Down

0 comments on commit 54d3898

Please sign in to comment.