Example #1
0
 public CBORJson(CharacterInputWithCount reader, JSONOptions options)
 {
     this.reader              = reader;
     this.sb                  = null;
     this.options             = options;
     this.jsonSequenceMode    = false;
     this.recordSeparatorSeen = false;
 }
Example #2
0
        internal static CBORObject ParseJSONValue(
            CharacterInputWithCount reader,
            JSONOptions options,
            int[] nextChar)
        {
            var cj = new CBORJson(reader, options);

            return(cj.ParseJSON(nextChar));
        }
Example #3
0
        internal static CBORObject[] ParseJSONSequence(
            CharacterInputWithCount reader,
            JSONOptions options,
            int[] nextChar)
        {
            var cj = new CBORJson(reader, options);

            cj.SetJSONSequenceMode();
            bool seenSeparator = cj.SkipRecordSeparators(nextChar, false);

            if (nextChar[0] >= 0 && !seenSeparator)
            {
                // Stream is not empty and did not begin with
                // record separator
                cj.RaiseError("Not a JSON text sequence");
            }
            else if (nextChar[0] < 0 && !seenSeparator)
            {
                // Stream is empty
                return(new CBORObject[0]);
            }
            else if (nextChar[0] < 0)
            {
                // Stream had only record separators, so we found
                // a truncated JSON text
                return(new CBORObject[] { null });
            }
            var list = new List <CBORObject>();

            while (true)
            {
                CBORObject co;
                try {
                    co = cj.ParseJSON(nextChar);
                } catch (CBORException) {
                    cj.SkipToEnd();
                    co = null;
                }
                if (co != null && nextChar[0] >= 0)
                {
                    // End of JSON text not reached
                    cj.SkipToEnd();
                    co = null;
                }
                list.Add(co);
                if (!cj.recordSeparatorSeen)
                {
                    // End of the stream was reached
                    nextChar[0] = -1;
                    break;
                }
                else
                {
                    // A record separator was seen, so
                    // another JSON text follows
                    cj.ResetJSONSequenceMode();
                    cj.SkipRecordSeparators(nextChar, true);
                    if (nextChar[0] < 0)
                    {
                        // Rest of stream had only record separators, so we found
                        // a truncated JSON text
                        list.Add(null);
                        break;
                    }
                }
            }
            return((CBORObject[])list.ToArray());
        }