stackoverflowers。
我基本上想知道是否有人对我应该如何继续进行提示。我已经在使用 BinaryWriter 序列化常规原始类型(通过长度前缀字节数组)。通常我只会将另一个实体添加到我拥有的原始类型字典中,但我希望能够序列化一个不确定的锯齿状数组;不管是System.Byte[][]
不是System.Byte[][][][][][]
我需要一种方法来为所有数组的长度加上前缀,还需要一种方法来告诉反序列化器有多少个数组。
我只是在想一个好方法来做到这一点,但我整天都在尝试。
只是我想出的一个片段(它根本不完整,但也许你明白我的概念方法);
Private Sub WriteArray(Writer As BinaryWriter, Type As Byte, Array As Array)
Writer.Write(Array.GetLength(0)) 'Writing length so we know how many arrays there are.
Dim Current As Type = Array.GetType() 'Getting the type of the (jagged-)array
If Current.HasElementType AndAlso Current.GetElementType.IsArray Then 'Checking whether it's a jagged-array.
Writer.Write(True) 'Writing true; which represents that it's a jagged-array.
For Each A As Array In Array
WriteArray(Writer, Type, A) 'Looping through the same method until...
Next
Else '... It's not jagged. -- This way is problematic; most of the times there are multiple jagged-arrays.
Writer.Write(False) 'Not jagged.
Select Case Type
Case 0 '0 = byte, I use other bytes for strings/integers/etc.
For Each Obj As Byte In Array
Writer.Write(Obj) 'Because it's not jagged we can finally write the bytes
Next
End Select
End If
End Sub
希望看到您参与讨论,并且我们可能会提出解决方案。