private void WriteElement(Stream stream, IBEncodedObject elem) { switch (elem.Type) { case BEncodeType.Dictionary: WriteDictionary(stream, (BDictionary)elem); break; case BEncodeType.List: WriteList(stream, (BList)elem); break; case BEncodeType.Number: WriteNumber(stream, (BNumber)elem); break; case BEncodeType.String: WriteString(stream, (BString)elem); break; default: throw new NotSupportedException($"Element type {elem.Type.ToString()} is not supported"); } }
/// <summary> /// Serialize object into stream /// </summary> /// <param name="stream">Stream, to serialize to</param> /// <param name="obj"></param> public void Serialize(Stream stream, IBEncodedObject obj) { WriteElement(stream, obj); }