我正在尝试从Github的OsmSharp.Samples测试一个名为Android.Routing.Offline的示例项目。
在屏幕上两次点击后(第一次只获得GeoCoordinate)我在Router.cs中得到一个ProtoBuf.ProtoException
private static IBasicRouterDataSource<CHEdgeData> _graph;
public static void Initialize()
{
var routingSerializer = new CHEdgeDataDataSourceSerializer();
_graph = routingSerializer.Deserialize(
Assembly.GetExecutingAssembly().GetManifestResourceStream(@"Android.Routing.Offline.kempen-big.contracted.mobile.routing"));
}
public static Route Calculate(GeoCoordinate from, GeoCoordinate to)
{
try
{
lock(_graph)
{
var router = Router.CreateCHFrom(_graph, new CHRouter(), new OsmRoutingInterpreter());
// The exception happens here below
var fromResolved = router.Resolve(Vehicle.Car, from);
var toResolved = router.Resolve(Vehicle.Car, to);
if(fromResolved != null && toResolved !=null)
{
return router.Calculate(Vehicle.Car, fromResolved, toResolved);
}
}
}
catch(Exception ex)
{
OsmSharp.Logging.Log.TraceEvent("Router", OsmSharp.Logging.TraceEventType.Critical, "Unhandled exception occured: {0}", ex.ToString());
}
return null;
}
例外:
> {ProtoBuf.ProtoException: Invalid wire-type; this usually means you
> have over-written a file without truncating or setting the length; see
> http://stackoverflow.com/q/2152978/23354 at
> ProtoBuf.ProtoReader.ReadSingle () ...
我没有覆盖该文件(kempen-big.contracted.mobile.routing),只是将其添加为项目中的链接文件。我有什么想法可以解决这个问题吗?
答案 0 :(得分:0)
嗯,首先要尝试的是检查您正在阅读的Stream
的内容(通过GetManifestResourceStream
)是否包含您期望的内容,而不是某些包装或其他损坏的内容一塌糊涂。如果你有一些校验和算法,你可以运行:太棒了!只检查.Length
将是一个很好的开始。否则,您可以通过获取十六进制来欺骗(仅用于验证内容):
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
string hex = BitConverter.ToString(
ms.GetBuffer(), 0, (int)ms.Length);
// dump this string, and compare it to the same output run on the
// oringal file; they should be identical
}
请注意,这会复制内存中的内容,纯粹是因为我们可以获得byte[]
(超大)来获取十六进制 - 它不适用于&#34;真实&#34;代码,但在您确定内容正确之前,所有其他投注均已关闭。我强烈怀疑您发现内容不与原始文件中的内容相同。请注意,我还隐式假设原始文件在反序列化方面工作正常。如果原始文件无法正常工作:所有投注均已关闭。