/// <summary> /// Write a Date value /// </summary> /// <param name="writer">The text writer to write the output to.</param> /// <param name="value">Date value to be written.</param> internal static void WriteValue(TextWriter writer, Date value) { Debug.Assert(writer != null, "writer != null"); JsonValueUtils.WriteQuoted(writer, value.ToString()); }
/// <summary> /// Write a byte array. /// </summary> /// <param name="value">Byte array to be written.</param> public void WriteValue(byte[] value) { this.WriteValueSeparator(); JsonValueUtils.WriteValue(this.writer, value); }
/// <summary> /// Write a TimeSpan value. /// </summary> /// <param name="writer">The text writer to write the output to.</param> /// <param name="value">TimeSpan value to be written.</param> internal static void WriteValue(TextWriter writer, TimeSpan value) { Debug.Assert(writer != null, "writer != null"); JsonValueUtils.WriteQuoted(writer, EdmValueWriter.DurationAsXml(value)); }
/// <summary> /// Write a Date value /// </summary> /// <param name="value">Date value to be written.</param> public void WriteValue(TimeOfDay value) { this.WriteValueSeparator(); JsonValueUtils.WriteValue(this.writer, value); }
/// <summary> /// Write a string value. /// </summary> /// <param name="value">String value to be written.</param> public void WriteValue(string value) { this.WriteValueSeparator(); JsonValueUtils.WriteValue(this.writer, value, ref this.buffer); }
/// <summary> /// Writes a DateTimeOffset value /// </summary> /// <param name="value">DateTimeOffset value to be written.</param> public void WriteValue(DateTimeOffset value) { this.WriteValueSeparator(); JsonValueUtils.WriteValue(this.writer, value, ODataJsonDateTimeFormat.ISO8601DateTime); }
/// <summary> /// Write a byte array. /// </summary> /// <param name="value">Byte array to be written.</param> public void WriteValue(byte[] value) { this.WriteValueSeparator(); JsonValueUtils.WriteValue(this.writer, value, ref this.buffer, ArrayPool); }
/// <summary> /// Returns the string value with special characters escaped. /// </summary> /// <param name="writer">The text writer to write the output to.</param> /// <param name="inputString">Input string value.</param> /// <param name="buffer">Char buffer to use for streaming data</param> internal static void WriteEscapedJsonString(TextWriter writer, string inputString, ref char[] buffer) { Debug.Assert(writer != null, "writer != null"); Debug.Assert(inputString != null, "The string value must not be null."); writer.Write(JsonConstants.QuoteCharacter); int firstIndex; if (!JsonValueUtils.CheckIfStringHasSpecialChars(inputString, out firstIndex)) { writer.Write(inputString); } else { int inputStringLength = inputString.Length; Debug.Assert(firstIndex < inputStringLength, "First index of the special character should be within the string"); buffer = BufferUtils.InitializeBufferIfRequired(buffer); int bufferLength = buffer.Length; int bufferIndex = 0; int currentIndex = 0; // Let's copy and flush strings up to the first index of the special char while (currentIndex < firstIndex) { int subStrLength = firstIndex - currentIndex; Debug.Assert(subStrLength > 0, "SubStrLength should be greater than 0 always"); // If the first index of the special character is larger than the buffer length, // flush everything to the buffer first and reset the buffer to the next chunk. // Otherwise copy to the buffer and go on from there. if (subStrLength >= bufferLength) { inputString.CopyTo(currentIndex, buffer, 0, bufferLength); writer.Write(buffer, 0, bufferLength); currentIndex += bufferLength; } else { inputString.CopyTo(currentIndex, buffer, 0, subStrLength); bufferIndex = subStrLength; currentIndex += subStrLength; } } for (; currentIndex < inputStringLength; currentIndex++) { char c = inputString[currentIndex]; string escapedString = JsonValueUtils.SpecialCharToEscapedStringMap[c]; // Append the unhandled characters (that do not require special treament) // to the buffer. if (escapedString == null) { buffer[bufferIndex] = c; bufferIndex++; } else { // Okay, an unhandled character was deteced. // First lets check if we can fit it in the existing buffer, if not, // flush the current buffer and reset. Add the escaped string to the buffer // and continue. int escapedStringLength = escapedString.Length; Debug.Assert(escapedStringLength <= bufferLength, "Buffer should be larger than the escaped string"); if ((bufferIndex + escapedStringLength) > bufferLength) { writer.Write(buffer, 0, bufferIndex); bufferIndex = 0; } escapedString.CopyTo(0, buffer, bufferIndex, escapedStringLength); bufferIndex += escapedStringLength; } if (bufferIndex >= bufferLength) { Debug.Assert(bufferIndex == bufferLength, "We should never encounter a situation where the buffer index is greater than the buffer length"); writer.Write(buffer, 0, bufferIndex); bufferIndex = 0; } } if (bufferIndex > 0) { writer.Write(buffer, 0, bufferIndex); } } writer.Write(JsonConstants.QuoteCharacter); }
/// <summary> /// Write a byte array. /// </summary> /// <param name="value">Byte array to be written.</param> public void WriteValue(byte[] value) { this.WriteValueSeparator(); JsonValueUtils.WriteValue(this.writer, value, this.wrappedBuffer, this.ArrayPool); }
/// <summary> /// Write a string value. /// </summary> /// <param name="value">String value to be written.</param> public void WriteValue(string value) { this.WriteValueSeparator(); JsonValueUtils.WriteValue(this.writer, value, this.stringEscapeOption, this.wrappedBuffer, this.ArrayPool); }