예제 #1
0
 public void WriteValuePart(int part)
 {
     if (!_inPartialColumn)
     {
         throw new InvalidOperationException("WriteValueStart must be called before WriteValuePart.");
     }
     String8.FromInteger(part, _typeConversionBuffer).WriteTo(_stream);
 }
예제 #2
0
 public void String8_FromInteger()
 {
     byte[] buffer = new byte[20];
     Assert.AreEqual("0", String8.FromInteger(0, buffer).ToString());
     Assert.AreEqual("00", String8.FromInteger(0, buffer, 1, 2).ToString());
     Assert.AreEqual("9", String8.FromInteger(9, buffer).ToString());
     Assert.AreEqual("-1", String8.FromInteger(-1, buffer).ToString());
     Assert.AreEqual("-10", String8.FromInteger(-10, buffer, 1).ToString());
     Assert.AreEqual("99", String8.FromInteger(99, buffer).ToString());
     Assert.AreEqual("0099", String8.FromInteger(99, buffer, 0, 4).ToString());
     Assert.AreEqual("100", String8.FromInteger(100, buffer).ToString());
     Assert.AreEqual("-999", String8.FromInteger(-999, buffer).ToString());
     Assert.AreEqual("123456789", String8.FromInteger(123456789, buffer).ToString());
     Assert.AreEqual(int.MaxValue.ToString(), String8.FromInteger(int.MaxValue, buffer).ToString());
     Assert.AreEqual(int.MinValue.ToString(), String8.FromInteger(int.MinValue, buffer).ToString());
 }
예제 #3
0
        public void SetColumns(IEnumerable <string> columnNames)
        {
            if (_columnCount != 0)
            {
                throw new InvalidOperationException("SetColumns may only be called once on a JsonTabularWriter.");
            }

            //  {
            //     "colIndex": {
            s_beforeColumnNames.WriteTo(_stream);

            int columnIndex = 0;

            foreach (string columnName in columnNames)
            {
                int length = String8.GetLength(columnName);
                if (_typeConversionBuffer == null || _typeConversionBuffer.Length < length)
                {
                    _typeConversionBuffer = new byte[length];
                }

                // ,
                if (columnIndex > 0)
                {
                    s_valueDelimiter.WriteTo(_stream);
                }

                // "ColumnName"
                _stream.WriteByte(UTF8.Quote);
                WriteEscaped(String8.Convert(columnName, _typeConversionBuffer));
                _stream.WriteByte(UTF8.Quote);

                // : 0
                _stream.WriteByte(UTF8.Colon);
                _stream.WriteByte(UTF8.Space);
                String8.FromInteger(columnIndex, _typeConversionBuffer).WriteTo(_stream);
                columnIndex++;
            }

            // },
            // "rows": {
            s_afterColumnNames.WriteTo(_stream);

            _columnCount = columnIndex;
        }
예제 #4
0
 public void Write(int value)
 {
     // Numbers are written without quotes and never need escaping. "ColumnName": -1234
     WriteColumnSeparator();
     String8.FromInteger(value, _typeConversionBuffer).WriteTo(_stream);
 }
예제 #5
0
 public void Write(int value)
 {
     Write(String8.FromInteger(value, _convertBuffer));
 }
예제 #6
0
 public void WriteValuePart(int part)
 {
     WriteValuePart(String8.FromInteger(part, _convertBuffer));
 }
예제 #7
0
 /// <summary>
 ///  Write an integer as part of a single cell value.
 ///  Callers must call WriteValueStart and WriteValueEnd around WriteValuePart calls.
 /// </summary>
 /// <param name="part">Value to write</param>
 public void WriteValuePart(int part)
 {
     WriteValuePart(String8.FromInteger(part, _typeConversionBuffer));
 }
예제 #8
0
 /// <summary>
 ///  Write an integer to the current row.
 ///  The value is converted without allocations.
 /// </summary>
 /// <param name="value">Value to write</param>
 public void Write(int value)
 {
     Write(String8.FromInteger(value, _typeConversionBuffer));
 }