コード例 #1
0
        /// <summary>Visit the different tokens of a packed tuple</summary>
        /// <param name="reader">Reader positionned at the start of a packed tuple</param>
        /// <param name="visitor">Lambda called for each segment of a tuple. Returns true to continue parsing, or false to stop</param>
        /// <returns>Number of tokens that have been visited until either <paramref name="visitor"/> returned false, or <paramref name="reader"/> reached the end.</returns>
        public static T VisitNext <T>(ref TupleReader reader, Func <Slice, TupleSegmentType, T> visitor)
        {
            if (!reader.Input.HasMore)
            {
                throw new InvalidOperationException("The reader has already reached the end");
            }
            var token = TupleParser.ParseNext(ref reader);

            return(visitor(token, TupleTypes.DecodeSegmentType(ref token)));
        }
コード例 #2
0
 /// <summary>Skip a number of tokens</summary>
 /// <param name="reader">Cursor in the packed tuple to decode</param>
 /// <param name="count">Number of tokens to skip</param>
 /// <returns>True if there was <paramref name="count"/> tokens, false if the reader was too small.</returns>
 /// <remarks>Even if this method return true, you need to check that the reader has not reached the end before reading more token!</remarks>
 public static bool Skip(ref TupleReader reader, int count)
 {
     while (count-- > 0)
     {
         if (!reader.Input.HasMore)
         {
             return(false);
         }
         var token = TupleParser.ParseNext(ref reader);
         if (token.IsNull)
         {
             return(false);
         }
     }
     return(true);
 }