public void Write(CtpObject value) { switch (value.ValueTypeCode) { case CtpTypeCode.Null: WriteNull(); break; case CtpTypeCode.Integer: WriteInt(value.UnsafeInteger); break; case CtpTypeCode.Single: WriteSingle(value.UnsafeRawUInt32); break; case CtpTypeCode.Double: WriteDouble(value.UnsafeRawUInt64); break; case CtpTypeCode.Numeric: WriteNumeric(value.UnsafeNumeric); break; case CtpTypeCode.CtpTime: WriteTime(value.UnsafeCtpTime); break; case CtpTypeCode.Boolean: WriteBool(value.UnsafeBoolean); break; case CtpTypeCode.Guid: WriteGuid(value.UnsafeGuid); break; case CtpTypeCode.String: WriteString(value.UnsafeString); break; case CtpTypeCode.CtpBuffer: WriteBuffer(value.UnsafeCtpBuffer); break; case CtpTypeCode.CtpCommand: WriteCommand(value.UnsafeCtpCommand); break; default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Reads to the next node. If the next node is the end of the document. False is returned. Otherwise true. /// </summary> /// <returns></returns> public bool Read() { TryAgain: if (m_completed) { return(false); } if (!m_initialized) { m_initialized = true; m_currentNode = m_schema[0]; m_isElementOrArrayNull = false; return(true); } else { if (IsElementOrArrayNull) { m_isElementOrArrayNull = false; m_currentNode = m_currentNode.PairedNode; } else { m_currentNode = m_currentNode.NextNode; } } if (m_currentNode == null) { m_completed = true; return(false); } switch (m_currentNode.Symbol) { case CommandSchemaSymbol.StartArray: int count = (int)m_stream.Read(); if (count < 0) { m_isElementOrArrayNull = true; m_arrayCountStack.Push(0); } else { m_isElementOrArrayNull = false; m_arrayCountStack.Push((int)count); } break; case CommandSchemaSymbol.StartElement: m_isElementOrArrayNull = !m_stream.Read().IsBoolean; break; case CommandSchemaSymbol.Value: m_value = m_stream.Read(); break; case CommandSchemaSymbol.EndElement: return(true); case CommandSchemaSymbol.EndArray: var arrayCount = m_arrayCountStack.Pop() - 1; if (arrayCount <= 0) { return(true); } else { m_arrayCountStack.Push(arrayCount); m_currentNode = m_currentNode.PairedNode; goto TryAgain; } default: throw new ArgumentOutOfRangeException(); } return(true); }