Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Protobuf网络禁用搜索_C#_Protobuf Net_Bzip2 - Fatal编程技术网

C# Protobuf网络禁用搜索

C# Protobuf网络禁用搜索,c#,protobuf-net,bzip2,C#,Protobuf Net,Bzip2,我正在网络客户机/服务器应用程序中使用protobuf net。每个数据包都使用BZIP2输入/输出流压缩,以压缩我的消息。这已经运行了好几个星期,但是我最近修改了服务器的对象,并且得到了一个异常,BZip2Input流不支持查找(它不支持)。我想这是因为protobuf检测到它可以跳过一些字段,并尝试方便地这样做 有没有办法禁用此行为,并通过读取数据强制protobuf net跳过字段?(不寻求) 更新:在下面添加了完整的堆栈跟踪。根据您的评论,流的CanSeek回调中一定有bug。你觉得怎么

我正在网络客户机/服务器应用程序中使用protobuf net。每个数据包都使用BZIP2输入/输出流压缩,以压缩我的消息。这已经运行了好几个星期,但是我最近修改了服务器的对象,并且得到了一个异常,BZip2Input流不支持查找(它不支持)。我想这是因为protobuf检测到它可以跳过一些字段,并尝试方便地这样做

有没有办法禁用此行为,并通过读取数据强制protobuf net跳过字段?(不寻求)

更新:在下面添加了完整的堆栈跟踪。根据您的评论,流的CanSeek回调中一定有bug。你觉得怎么样

Server First Chance Exception: BZip2InputStream Seek n
ot supported Stack Trace:    at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.S
eek(Int64 offset, SeekOrigin origin)
Server_NewRequestReceived Exception: System.NotSupportedException: BZip2InputStream Seek not supported
   at ICSharpCode.SharpZipLib.BZip2.BZip2InputStream.Seek(Int64 offset, origin)
   at ProtoBuf.ProtoReader.Seek(Stream source, Int32 count, Byte[] buffer)
   at ProtoBuf.ProtoReader.SkipField()
   at proto_2(Object, ProtoReader)
   at ProtoBuf.Serializers.CompiledSerializer.ProtoBuf.Serializers.IProtoSeriali    zer.Read(Object value, ProtoReader source)
   at ProtoBuf.Meta.RuntimeTypeModel.Deserialize(Int32 key, Object value, source)
   at ProtoBuf.Meta.TypeModel.TryDeserializeAuxiliaryType(ProtoReader reader, format, Int32 tag, Type type, ref Object value, Boolean skipOtherFields, asListItem, Boolean autoCreate, Boolean insideList)
   at ProtoBuf.Meta.TypeModel.TryDeserializeList(TypeModel model, ader, DataFormat format, Int32 tag, Type listType, Type itemType, ref Object value)

   at ProtoBuf.Meta.TypeModel.TryDeserializeAuxiliaryType(ProtoReader reader, format, Int32 tag, Type type, ref Object value, Boolean skipOtherFields, asListItem, Boolean autoCreate, Boolean insideList)
   at ProtoBuf.Meta.TypeModel.DeserializeCore(ProtoReader reader, Type type, value, Boolean noAutoCreate)
   at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type, SerializationContext context)
   at ProtoBuf.Meta.TypeModel.Deserialize(Stream source, Object value, Type type)
   at ProtoBuf.Serializer.Deserialize(Stream source)

创建这个类是为了避开SharpZipLib bug

    public class NonSeekableStreamWrapper : Stream
    {
        public Stream BaseStream { get; private set; }

        public NonSeekableStreamWrapper(Stream baseStream)
        {
            BaseStream = baseStream;
        }

        public override void Flush()
        {
            BaseStream.Flush();
        }

        public override long Seek(long offset, SeekOrigin origin)
        {
            return BaseStream.Seek(offset, origin);
        }

        public override void SetLength(long value)
        {
            BaseStream.SetLength(value);
        }

        public override int Read(byte[] buffer, int offset, int count)
        {
            return BaseStream.Read(buffer, offset, count);
        }

        public override void Write(byte[] buffer, int offset, int count)
        {
            BaseStream.Write(buffer, offset, count);
        }

        public override bool CanRead
        {
            get { return true; }
        }

        public override bool CanSeek
        {
            get { return false; }
        }

        public override bool CanWrite
        {
            get { return false; }
        }

        public override long Length
        {
            get { return BaseStream.Length; }
        }

        public override long Position { get; set; }
    }

这很有趣。当这种情况发生时,我对完整的stacktrace非常感兴趣,因为AFAIK会为此检查正确的API,例如(从
ProtoReader.Seek

所以不,它目前没有这样的选择,因为它相信流会说出真相。当然,这可能只是我的一个bug,因此请求stacktrace

如果这是一个真正的“东西”,那么可能会增加这样一个机制


编辑:是的,这是SharpZipLib中
BZip2InputStream.cs
中的一个bug;它有:

    /// <summary>
    /// Gets a value indicating whether the current stream supports seeking.
    /// </summary>
    public override bool CanSeek {
        get {
            return baseStream.CanSeek;
        }
    }
//
///获取一个值,该值指示当前流是否支持查找。
/// 
公共覆盖布尔搜索{
得到{
返回baseStream.CanSeek;
}
}
但它也有:

    /// <summary>
    /// Set the streams position.  This operation is not supported and will throw a NotSupportedException
    /// </summary>
    /// <param name="offset">A byte offset relative to the <paramref name="origin"/> parameter.</param>
    /// <param name="origin">A value of type <see cref="SeekOrigin"/> indicating the reference point used to obtain the new position.</param>
    /// <returns>The new position of the stream.</returns>
    /// <exception cref="NotSupportedException">Any access</exception>
    public override long Seek(long offset, SeekOrigin origin)
    {
        throw new NotSupportedException("BZip2InputStream Seek not supported");
    }
//
///设置流位置。此操作不受支持,将引发NotSupportedException
/// 
///相对于参数的字节偏移量。
///指示用于获取新位置的参考点的类型值。
///河流的新位置。
///任何访问
公共覆盖长寻道(长偏移,参见原始坐标系)
{
抛出新的NotSupportedException(“BZip2InputStream查找不受支持”);
}
因此,它可以从不搜索,但它声称如果基流可以,它可以


它应该报告
false
而不是回显基流的
CanSeek

请参见编辑:这肯定是
BZip2InputStream中的一个bug
一件小事,但很高兴看到有人能够在不大惊小怪的情况下创建流装饰器。我很乐意在我的答案中添加一个,但只是:很高兴看到,ta。谢谢Marc-我刚刚将问题提交给SharpZipLib,同时,我正在编写一个简单的不可查找流包装器,以便CanSeek函数返回false。是的-我可能应该自己分叉/修复它。。。只是在这么多项目中使用他们的nuget软件包,我想首先给他们一个机会。
if (source.CanSeek)
{
    source.Seek(count, SeekOrigin.Current);
    // ...
}
else
{
    // ... does it the hard way, even if that means a Read loop
}