public static void WriteObject(this CborWriter writer, CborObject @object) { if (@object is CborTextString text) { writer.WriteTextString(text.Value); } else if (@object is CborByteString data) { writer.WriteByteString(data.Value); } else if (@object is CborBoolean boolean) { writer.WriteBoolean(boolean.Value); } else if (@object is CborInteger number) { writer.WriteInt64(number.Value); } else if (@object is CborMap map) { writer.WriteMap(map); } else if (@object is CborArray array) { writer.WriteArray(array); } else if (@object.Type == CborType.Null) { writer.WriteNull(); } else { throw new Exception($"Unknown type. Was {@object.Type}"); } }
public override void Write(ref CborWriter writer, TI[]?value, LengthMode lengthMode) { if (value == null) { writer.WriteNull(); return; } WriterContext context = new WriterContext { array = value, lengthMode = lengthMode != LengthMode.Default ? lengthMode : _options.ArrayLengthMode }; writer.WriteArray(this, ref context); }
void ICborConverter <CborArray?> .Write(ref CborWriter writer, CborArray?value, LengthMode lengthMode) { if (value == null) { writer.WriteNull(); return; } ArrayWriterContext arrayWriterContext = new ArrayWriterContext { array = value, lengthMode = lengthMode != LengthMode.Default ? lengthMode : _options.ArrayLengthMode }; writer.WriteArray(this, ref arrayWriterContext); }
public override CborWriter Write(CborWriter writer) { base.Write(writer); writer.WriteArray(Value.Count()); foreach (var cborObject in Value) { cborObject.Write(writer); } return writer; }