2018-09-08 01:26:45 +08:00
|
|
|
|
#Region "Microsoft.VisualBasic::640de3ff0a8a3e7fdce5001c46593c75, Microsoft.VisualBasic.Core\ApplicationServices\Tools\Network\Protocol\Streams\VarArray.vb"
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
2018-10-06 01:18:55 +08:00
|
|
|
|
' Author:
|
|
|
|
|
|
'
|
|
|
|
|
|
' asuka (amethyst.asuka@gcmodeller.org)
|
|
|
|
|
|
' xie (genetics@smrucc.org)
|
|
|
|
|
|
' xieguigang (xie.guigang@live.com)
|
|
|
|
|
|
'
|
|
|
|
|
|
' Copyright (c) 2018 GPL3 Licensed
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' GNU GENERAL PUBLIC LICENSE (GPL3)
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
' it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
' the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
' (at your option) any later version.
|
|
|
|
|
|
'
|
|
|
|
|
|
' This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
' but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
' GNU General Public License for more details.
|
|
|
|
|
|
'
|
|
|
|
|
|
' You should have received a copy of the GNU General Public License
|
|
|
|
|
|
' along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
' /********************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
' Summaries:
|
|
|
|
|
|
|
|
|
|
|
|
' Class VarArray
|
|
|
|
|
|
'
|
|
|
|
|
|
' Constructor: (+2 Overloads) Sub New
|
|
|
|
|
|
' Function: Serialize
|
|
|
|
|
|
'
|
|
|
|
|
|
'
|
|
|
|
|
|
' /********************************************************************************/
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
|
|
|
|
|
|
|
|
Imports Microsoft.VisualBasic.Language
|
|
|
|
|
|
Imports Microsoft.VisualBasic.Linq
|
2018-10-06 01:18:55 +08:00
|
|
|
|
Imports Microsoft.VisualBasic.Serialization.BinaryDumping
|
2018-08-02 20:14:48 +08:00
|
|
|
|
|
|
|
|
|
|
Namespace Net.Protocols.Streams.Array
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' The bytes length of the element in thee source sequence is not fixed.
|
|
|
|
|
|
''' (序列里面的元素的长度是不固定的)
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
Public Class VarArray(Of T) : Inherits ArrayAbstract(Of T)
|
|
|
|
|
|
|
2018-10-06 01:18:55 +08:00
|
|
|
|
Sub New(TSerialize As IGetBuffer(Of T), load As IGetObject(Of T))
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Call MyBase.New(TSerialize, load)
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
2018-10-06 01:18:55 +08:00
|
|
|
|
Sub New(raw As Byte(), serilize As IGetBuffer(Of T), load As IGetObject(Of T))
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Call Me.New(serilize, load)
|
|
|
|
|
|
|
|
|
|
|
|
Dim lb As Byte() = New Byte(INT64 - 1) {}
|
|
|
|
|
|
Dim buf As Byte()
|
|
|
|
|
|
Dim i As New Pointer
|
|
|
|
|
|
Dim list As New List(Of T)
|
|
|
|
|
|
Dim l As Long
|
|
|
|
|
|
Dim x As T
|
|
|
|
|
|
|
|
|
|
|
|
Do While raw.Length > i
|
|
|
|
|
|
|
|
|
|
|
|
Call System.Array.ConstrainedCopy(raw, i << INT64, lb, Scan0, INT64)
|
|
|
|
|
|
|
|
|
|
|
|
l = BitConverter.ToInt64(lb, Scan0)
|
|
|
|
|
|
buf = New Byte(l - 1) {}
|
|
|
|
|
|
|
|
|
|
|
|
Call System.Array.ConstrainedCopy(raw, i << buf.Length, buf, Scan0, buf.Length)
|
|
|
|
|
|
|
|
|
|
|
|
x = load(buf)
|
|
|
|
|
|
list += x
|
|
|
|
|
|
Loop
|
|
|
|
|
|
|
|
|
|
|
|
Values = list.ToArray
|
|
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
|
|
''' <summary>
|
|
|
|
|
|
''' Long + T + Long + T
|
|
|
|
|
|
''' 其中Long是一个8字节长度的数组,用来指示T的长度
|
|
|
|
|
|
''' </summary>
|
|
|
|
|
|
''' <returns></returns>
|
|
|
|
|
|
Public Overrides Function Serialize() As Byte()
|
|
|
|
|
|
Dim list As New List(Of Byte)
|
|
|
|
|
|
Dim LQuery = (From ind As SeqValue(Of T)
|
|
|
|
|
|
In Values.SeqIterator.AsParallel
|
|
|
|
|
|
Select ind.i,
|
2018-10-06 01:18:55 +08:00
|
|
|
|
byts = serialization(ind.value)
|
2018-08-02 20:14:48 +08:00
|
|
|
|
Order By i Ascending)
|
|
|
|
|
|
|
|
|
|
|
|
For Each x In LQuery
|
|
|
|
|
|
Dim byts As Byte() = x.byts
|
|
|
|
|
|
Dim l As Long = byts.Length
|
|
|
|
|
|
Dim lb As Byte() = BitConverter.GetBytes(l)
|
|
|
|
|
|
|
|
|
|
|
|
Call list.AddRange(lb)
|
|
|
|
|
|
Call list.AddRange(byts)
|
|
|
|
|
|
Next
|
|
|
|
|
|
|
|
|
|
|
|
Return list.ToArray
|
|
|
|
|
|
End Function
|
|
|
|
|
|
End Class
|
|
|
|
|
|
End Namespace
|