English 中文(简体)
如何根据散列值识别类型?
原标题:How to identify type by hash value?

所以我有基本的 UDP 服务器, 我实施了一些东西, 比如恢复字节阵列, 确切地说, 它是如何由客户发送的( 如果它被收回了 ) 。 Bassicly, 我有客户端、 服务器和共享的类库, 以及类型, 对象可以从客户端发送到服务器, 反之亦然。 所以现在我想把一些对象序列化, 并发送到服务器/ 客户端 。 但我需要知道是哪类对象被重新恢复了, 以正确消除它。 有两个想法可以解决这个问题 :

  • Make a "handshake". Send data about what object will be send after, its length, class name, etc. And after it retrive actual data and deserialize it. I know to do it, but since it s UDP, this "handshake" could be lost and I need to re-ask it, so there is pretty complicated logic and network over-usage, but I know how to implement this.
  • And second one is identifing type by some hash value. So client sends data which contains hash value of type and piece of data (I will only send my own type s objects, so no need to implement this for C# and Framework types), and I need to determine type by this hash value and server could deserealize it properly.

那么,有什么想法, 如何执行呢?如果我设法避免反省, 因为反省缓慢( 我不在乎大开关的语句, 如果效果更快的话), 它将会是完美的 。

最佳回答

我今天做这个是为了一个我正在研究的原型。

前4字节:以 Int32 表示的组装合格型号名称长度。

下一个 n 字节( 前 4 字节给出 n) : 类型组装合格名称 。

电文其余部分:序列号物体

它的工作就像一个魅力。

问题回答

只要将对象类型数据作为对象数据的一部分, 并使用完全相同的逻辑发送它们。 不要试图在网络一级单独处理它们 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签