private static int GetStateAfterContainer(IonType newContainer) { if (newContainer == IonType.None) { return(StateBeforeAnnotationDatagram); } Debug.Assert(newContainer.IsContainer(), "newContainer IsContainer is false"); switch (newContainer) { default: // should not happen throw new IonException($"{newContainer} is no container"); case IonType.Struct: case IonType.List: return(StateAfterValueContents); case IonType.Sexp: return(StateBeforeAnnotationSexp); case IonType.Datagram: return(StateBeforeAnnotationDatagram); } }
private static int GetStateAtContainerStart(IonType container) { if (container == IonType.None) { return(StateBeforeAnnotationDatagram); } Debug.Assert(container.IsContainer(), "container isContainer is false"); switch (container) { default: // should not happen throw new IonException($"{container} is no container"); case IonType.Struct: return(StateBeforeFieldName); case IonType.List: return(StateBeforeAnnotationContained); case IonType.Sexp: return(StateBeforeAnnotationSexp); case IonType.Datagram: return(StateBeforeAnnotationDatagram); } }
private void WriteContainerRecursively(IonType type, IIonReader reader) { Debug.Assert(type.IsContainer(), "type IsContainer is false"); this.StepIn(type); reader.StepIn(); while ((type = reader.MoveNext()) != IonType.None) { this.WriteValueRecursively(type, reader); } reader.StepOut(); this.StepOut(); }
public void StepIn(IonType type) { if (!type.IsContainer()) { throw new IonException($"Cannot step into {type}"); } this.PrepareValue(); // Wrapup the current writes if (this.containerStack.Count > 0) { var writeList = this.dataBuffer.Wrapup(); Debug.Assert(ReferenceEquals(writeList, this.containerStack.Peek().Sequence), "writeList does not equal Sequence"); } var pushedContainer = this.containerStack.PushContainer(this.GetContainerType(type)); this.dataBuffer.StartStreak(pushedContainer.Sequence); }
public void StepIn(IonType type) { if (!type.IsContainer()) { throw new IonException($"Cannot step into {type}"); } PrepareValue(); //wrapup the current writes if (_containerStack.Count > 0) { var writeList = _dataBuffer.Wrapup(); Debug.Assert(ReferenceEquals(writeList, _containerStack.Peek().Sequence)); } var pushedContainer = _containerStack.PushContainer(type == IonType.Struct ? ContainerType.Struct : ContainerType.Sequence); _dataBuffer.StartStreak(pushedContainer.Sequence); }
private void InternalWriteValue(IIonReader reader, int depth = 0) { IonType type = reader.CurrentType; if (type == IonType.None) { return; } if (depth > 0) { string fieldName = reader.CurrentFieldName; if (fieldName != null) { this.SetFieldName(fieldName); } } foreach (var annotation in reader.GetTypeAnnotations()) { this.AddTypeAnnotationSymbol(annotation); } if (reader.CurrentIsNull) { this.WriteNull(type); } else { switch (type) { case IonType.Bool: this.WriteBool(reader.BoolValue()); break; case IonType.Int: this.WriteInt(reader.BigIntegerValue()); break; case IonType.Float: this.WriteFloat(reader.DoubleValue()); break; case IonType.Decimal: this.WriteDecimal(reader.DecimalValue()); break; case IonType.Timestamp: this.WriteTimestamp(reader.TimestampValue()); break; case IonType.Symbol: this.WriteSymbolToken(reader.SymbolValue()); break; case IonType.String: this.WriteString(reader.StringValue()); break; case IonType.Clob: this.WriteClob(reader.NewByteArray()); break; case IonType.Blob: this.WriteBlob(reader.NewByteArray()); break; case IonType.List: this.StepIn(IonType.List); break; case IonType.Sexp: this.StepIn(IonType.Sexp); break; case IonType.Struct: this.StepIn(IonType.Struct); break; default: throw new InvalidOperationException("Unexpected type '" + type + "'"); } if (type.IsContainer()) { reader.StepIn(); this.InternalWriteValues(reader, depth + 1); this.StepOut(); reader.StepOut(); } } }