LCOV - code coverage report
Current view: top level - src - cbor_dart_item.dart (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 2 4 50.0 %
Date: 2017-04-06 Functions: 0 0 -

          Line data    Source code
       1             : /*
       2             :  * Package : Cbor
       3             :  * Author : S. Hamblett <steve.hamblett@linux.com>
       4             :  * Date   : 12/12/2016
       5             :  * Copyright :  S.Hamblett
       6             :  */
       7             : 
       8             : part of cbor;
       9             : 
      10             : /// The Dart types an item can have.
      11             : enum dartTypes {
      12             :   dtInt,
      13             :   dtDouble,
      14             :   dtMap,
      15             :   dtList,
      16             :   dtBuffer,
      17             :   dtNull,
      18             :   dtString,
      19             :   dtBool,
      20             :   dtUndefined,
      21             :   dtNone
      22             : }
      23             : 
      24             : /// If the type is dtBuffer or dtString a hint at what the
      25             : /// data may contain.
      26             : enum dataHints {
      27             :   base64Url,
      28             :   base64,
      29             :   base16,
      30             :   encodedCBOR,
      31             :   uri,
      32             :   unassigned,
      33             :   selfDescCBOR,
      34             :   mime,
      35             :   regex,
      36             :   bigfloat,
      37             :   decFraction,
      38             :   error,
      39             :   none,
      40             :   dateTimeString,
      41             :   dateTimeEpoch
      42             : }
      43             : 
      44             : /// The CBOR Dart item class.
      45             : /// Objects of this class are produced by the standard
      46             : /// stack listener class by the decode process.
      47             : class DartItem {
      48             :   /// The item data.
      49             :   dynamic data = null;
      50             : 
      51             :   /// Target size is what we expect the size to
      52             :   /// be.
      53             :   int targetSize = 0;
      54             : 
      55             :   /// The item type, one of the major types.
      56             :   dartTypes type = dartTypes.dtNone;
      57             : 
      58             :   /// Is the type complete, i,e is its actual size
      59             :   /// equql to its target size.
      60             :   bool complete = false;
      61             : 
      62             :   /// Possible type usage hint for buffer or string types.
      63             :   /// See RFC 7049 for more details. Also used to indicate
      64             :   /// an error condition in which case the data field will
      65             :   /// contain a string representation of the error.
      66             :   dataHints hint = dataHints.none;
      67             : 
      68             :   /// Actual size
      69             :   int size() {
      70           0 :     return data.length;
      71             :   }
      72             : 
      73             :   /// Awaiting a map key for Map types.
      74             :   bool awaitingMapKey = false;
      75             : 
      76             :   /// Awaiting a map value for Map types.
      77             :   bool awaitingMapValue = false;
      78             : 
      79             :   /// The last key value inserted into a map
      80             :   dynamic lastMapKey;
      81             : 
      82             :   /// Ignore indicator. Used to indicate the item
      83             :   /// should be ignored during stack traversal, the
      84             :   /// item has been used as a partial build area for
      85             :   /// another stack item for instance.
      86             :   bool ignore = false;
      87             : 
      88             :   /// Helper functions
      89             : 
      90             :   bool isIncompleteList() {
      91           9 :     if ((type == dartTypes.dtList) && !complete) {
      92             :       return true;
      93             :     }
      94             :     return false;
      95             :   }
      96             : 
      97             :   bool isIncompleteMap() {
      98           8 :     if ((type == dartTypes.dtMap) && !complete) {
      99             :       return true;
     100             :     }
     101             :     return false;
     102             :   }
     103             : 
     104             :   bool awaitingMapEntry() {
     105           0 :     if (awaitingMapValue || awaitingMapKey) {
     106             :       return true;
     107             :     }
     108             :     return false;
     109             :   }
     110             : }

Generated by: LCOV version 1.10