1 #Region "Microsoft.VisualBasic::e0bef81df8c24e1c13abddaa2e5327ac, Microsoft.VisualBasic.Core\ApplicationServices\Parallel\MMFProtocol\Pipeline\PipeBuffer.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Class PipeBuffer
35     
36     '         Properties: byteData, Name
37     
38     '         Constructor: (+1 OverloadsSub New
39     '         Function: Serialize
40     
41     
42     ' /********************************************************************************/
43
44 #End Region
45
46 Imports Microsoft.VisualBasic.Language
47 Imports Microsoft.VisualBasic.Net.Protocols
48 Imports Microsoft.VisualBasic.Text
49
50 Namespace Parallel.MMFProtocol.Pipeline
51
52     Public Class PipeBuffer : Inherits RawStream
53
54         Public Property Name As String
55         Public Property byteData As Byte()
56
57         Sub New(raw As Byte())
58             Dim nameLen As Byte() = New Byte(INT32 - 1) {}
59             Dim p As int = Scan0
60             Call Array.ConstrainedCopy(raw, p + INT32, nameLen, Scan0, INT32)
61
62             Dim len As Integer = BitConverter.ToInt32(nameLen, Scan0)
63             Dim name As Byte() = New Byte(len - 1) {}
64             Call Array.ConstrainedCopy(raw, p + name.Length, name, Scan0, len)
65             Me.Name = System.Text.Encoding.UTF8.GetString(name)
66
67             byteData = New Byte(raw.Length - INT32 - len - 1) {}
68             Call Array.ConstrainedCopy(raw, p, byteData, Scan0, byteData.Length)
69         End Sub
70
71         Public Overrides Function Serialize() As Byte()
72             Dim nameBuf As Byte() = UTF8WithoutBOM.GetBytes(Name)
73             Dim buffer As Byte() = New Byte(INT32 + nameBuf.Length + byteData.Length - 1) {}
74             Dim nameLen As Byte() = BitConverter.GetBytes(nameBuf.Length)
75             Dim p As int = Scan0
76
77             Call Array.ConstrainedCopy(nameLen, Scan0, buffer, p + nameLen.Length, nameLen.Length)
78             Call Array.ConstrainedCopy(nameBuf, Scan0, buffer, p + nameBuf.Length, nameBuf.Length)
79             Call Array.ConstrainedCopy(byteData, Scan0, buffer, p + byteData.Length, byteData.Length)
80
81             Return buffer
82         End Function
83     End Class
84 End Namespace