我正在使用Python编写的代码移植到Scala。bencode Scala任何类型
此python代码[0,{}]
创建一个整数和字典的列表。
在这种情况下的字典将有字符串的键,但值可以是一个int或一个字符串。
我想在Scala中做类似的事情。我相信我将不得不这样做:
List[Any] = (<int>, scala.collection.mutable.Map[String, Any](...))
我打算对此列表进行编码,以便“任何”的基本类型很重要。如何更改类型以使列表可以被编码?
不是你的问题的答案,但我看到有人写了Scala bencode库,如[pyronicide](https://github.com/pyronicide/scala- bencode),并在[storrent]的层次结构中(https://github.com/danluu/storrent/blob /master/src/main/scala/Bencode.scala),或者[有趣的博客文章](http://covariantblabbering.blogspot.com/2014/05/the-beaty-of-parsing-combinators-and.html )。所以你可以在那里找到一些好点子。 – wwkudu 2014-12-04 02:02:15