cbor: CBOR implementation for RIOT-OS (SWP)

    cbor: CBOR implementation for RIOT-OS                                                                                                                                                                  
                                                                                                                                                                                                           
    This is a malloc-free implementation of the Concise Binary Object                                                                                                                                      
    Representation (CBOR) data format for the RIOT-OS.                                                                                                                                                     
                                                                                                                                                                                                           
    This implementation mostly stand-alone, and it should be pretty easy to                                                                                                                                
    port to other platforms. We're only using the C STL and some custom                                                                                                                                    
    network-related functionaliy which could be easily replaced by depending                                                                                                                               
    on arpa/inet.h.                                                                                                                                                                                        
                                                                                                                                                                                                           
    The CBOR API is straight-forward to use and provides encoding/decoding                                                                                                                                 
    functionality for all major C types, such as:                                                                                                                                                          
    - int                                                                                                                                                                                                  
    - uint64_t                                                                                                                                                                                             
    - int64_t                                                                                                                                                                                              
    - float                                                                                                                                                                                                
    - double                                                                                                                                                                                               
    - char*                                                                                                                                                                                                
    - struct tm                                                                                                                                                                                            
    - time_t                                                                                                                                                                                               
                                                                                                                                                                                                           
    It is possible to conditionally compile this module via CFLAGS:                                                                                                                                        
    - CBOR_NO_CTIME: All ctime related features removed
    - CBOR_NO_FLOAT: All floating-point related features removed
    - CBOR_NO_STREAM_DECODE: Generic decoding feature removed
      (cbor_stream_decode normally prints out a CBOR data stream to stdout)
You could refactor everything after the trivial case to first find the length, and then use a loop. Something like (untested):
```c
int result;

if (val <= 0xff) {
    major_type |= CBOR_UINT8_FOLLOWS;
    result = 2;
}
else …

CBOR_ENSURE_SIZE(s, result);
s->data[s->pos++] = major_type;
for (int i = result - 1; i >= 0; --i) {
    s->data[s->pos++] = (val >> (8 * i)) & 0xff;
}

return result;
```