Ignore:
Timestamp:
Apr 5, 2009, 5:52:21 PM (13 years ago)
Author:
charles
Message:

(trunk) Use proper notation for json floating-point and bool types. For backwards compatability, still allow old-style printf strings as doubles, and 0s and 1s as bools.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode.h

    r8112 r8154  
    1414#define TR_BENCODE_H 1
    1515
     16#ifdef __cplusplus
     17extern "C" {
     18#endif
     19
    1620#include <inttypes.h> /* for int64_t */
    1721
     
    2327    TYPE_STR  = 2,
    2428    TYPE_LIST = 4,
    25     TYPE_DICT = 8
     29    TYPE_DICT = 8,
     30    TYPE_BOOL = 16,
     31    TYPE_REAL = 32
    2632};
    2733
     
    3137    union
    3238    {
    33         int64_t i;
    34         struct
     39        uint8_t b; /* bool type */
     40
     41        double d;  /* double type */
     42
     43        int64_t i; /* int type */
     44
     45        struct /* string type */
    3546        {
    3647            size_t i;
    3748            char * s;
    3849        } s;
    39         struct
     50
     51        struct /* list & dict types */
    4052        {
    4153            size_t alloc;
     
    4658} tr_benc;
    4759
    48 #ifdef __cplusplus
    49 extern "C" {
    50 #endif
    51 
    5260/***
    5361****
     
    96104
    97105int       tr_bencInitList( tr_benc *, size_t reserveCount );
     106
     107void      tr_bencInitBool( tr_benc *, int value );
     108
     109void      tr_bencInitReal( tr_benc *, double value );
    98110
    99111/***
     
    173185static TR_INLINE tr_bool tr_bencIsList  ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_LIST ); }
    174186static TR_INLINE tr_bool tr_bencIsString( const tr_benc * b ) { return tr_bencIsType( b, TYPE_STR ); }
     187static TR_INLINE tr_bool tr_bencIsBool  ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_BOOL ); }
     188static TR_INLINE tr_bool tr_bencIsReal  ( const tr_benc * b ) { return tr_bencIsType( b, TYPE_REAL ); }
    175189
    176190/**
Note: See TracChangeset for help on using the changeset viewer.