0

スタックオーバーフラワー。

基本的に、これについてどのように進めるべきかについて誰かがヒントを持っているかどうか疑問に思っています. BinaryWriter を使用して、通常のプリミティブ型を既にシリアル化しています (長さのプレフィックスとしてバイト配列を使用)。通常、私は持っているprimitivetypesディクショナリに別のエンティティを追加するだけですが、不定のギザギザ配列をシリアル化できるようにしたいと考えています。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

ディスカッションに参加していただき、解決策を見つけられることを願っています。

4

0 に答える 0