Statistics
| Branch: | Revision:

grapes / include / trade_msg_la.h @ master

History | View | Annotate | Download (1.98 KB)

1 15790844 Luca Abeni
/** @file trade_msg_la.h
2
 *
3 b9e0d721 MarcoBiazzini
 * @brief Chunk Delivery API - Lower Abstraction
4 15790844 Luca Abeni
 *
5
 * The Chunk Delivery LA provides the primitives to encode the send operation of a Chunk to a target Peer and decode the Chunk reception from a Peer. The former returns a bit stream obteined by the encoding of the Chunk to send, it is the packet that will be sent. The latter decode a packet received, the bit stream, in the corresponding Chunk.
6 62ecdd02 Luca Abeni
 * See @link chunk_encoding_test.c chunk_encoding_test.c @endlink for an usage example
7
 *
8
 */
9 a40a8d81 MarcoBiazzini
10 62ecdd02 Luca Abeni
/** @example chunk_encoding_test.c
11
 * 
12
 * A test program showing how to use the chunk encoding and decoding API.
13
 *
14 15790844 Luca Abeni
 */
15 62ecdd02 Luca Abeni
16 729826c9 Csaba Kiraly
/**
17
 * @brief Size of the chunk header in bytes.
18
 */
19
#define CHUNK_HEADER_SIZE 20
20
21 15790844 Luca Abeni
 /**
22 85c4b598 MarcoBiazzini
  * @brief Encode a sequence of information, filling the buffer with the corresponding bit stream.
23 15790844 Luca Abeni
  * 
24
  * Encode a sequence of information given as parameters and fills a buffer (given as parameter) with the corresponding bit stream.
25
  * The main reason to encode a return the bit stream is the possibility to either send directly a packet with the encoded bit stream, or 
26
  * add this bit stream in piggybacking
27
  * 
28
  * @param[in] c Chunk to send 
29
  * @param[in] buff Buffer that will be filled with the bit stream obtained as a coding of the above parameters
30
  * @param[in] buff_len length of the buffer that will contain the bit stream
31
  * @return the lenght of the encoded bitstream (in bytes) on success, <0 on error
32
  */
33
int encodeChunk(const struct chunk *c, uint8_t *buff, int buff_len);
34
35
/**
36 edd2bc82 MarcoBiazzini
  * @brief Decode the bit stream.
37
  *
38 15790844 Luca Abeni
  * Decode the bit stream contained int the buffer, filling the other parameters. This is the dual of the encode function.
39
  *  
40
  * @param[in] c Chunks that has been transmitted
41
  * @param[in] buff Buffer which contain the bit stream to decode, filling the above parameters
42
  * @param[in] buff_len length of the buffer that contain the bit stream
43
  * @return 0 on success, <0 on error
44
  */
45
int decodeChunk(struct chunk *c, const uint8_t *buff, int buff_len);