1 #Region "Microsoft.VisualBasic::614fa76c2c5dbda1d1ba5baa07bacfb6, Microsoft.VisualBasic.Core\Net\Tcp\Persistent\Protocols\POST.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 LogonPOST
35     
36     '         Properties: Socket, USER_ID
37     
38     '     Class SendMessagePost
39     
40     '         Properties: [FROM], Message, USER_ID
41     
42     '         Constructor: (+2 OverloadsSub New
43     '         Function: Serialize
44     
45     '     Class BroadcastPOST
46     
47     '         Properties: Message, USER_ID
48     
49     '         Constructor: (+2 OverloadsSub New
50     '         Function: Serialize
51     
52     
53     ' /********************************************************************************/
54
55 #End Region
56
57 Imports System.Xml.Serialization
58 Imports Microsoft.VisualBasic.Language
59 Imports Microsoft.VisualBasic.Net.Protocols
60
61 Namespace Net.Tcp.Persistent.Application.Protocols
62
63     Public Class LogonPOST
64         <XmlAttribute> Public Property USER_ID As Long
65         <XmlAttribute> Public Property Socket As String
66     End Class
67
68     <Serializable> Public Class SendMessagePost : Inherits RawStream
69
70         ''' <summary>
71         ''' 发送这条消息的客户端的在服务器上面的句柄,也可以看作为用户编号,尽管这个编号是经过一些映射操作最终得到的
72         ''' </summary>
73         ''' <returns></returns>
74         <XmlAttribute> Public Property [FROM] As Long
75         <XmlAttribute> Public Property USER_ID As Long
76         <XmlText> Public Property Message As RequestStream
77
78         Sub New(rawStream As Byte())
79             Dim pTemp As Byte() = New Byte(INT64 - 1) {}
80             Dim p As int = 0
81
82             Call Array.ConstrainedCopy(rawStream, p + INT64, pTemp, Scan0, pTemp.Length)
83             FROM = BitConverter.ToInt64(pTemp, Scan0)
84             Call Array.ConstrainedCopy(rawStream, p + INT64, pTemp, Scan0, pTemp.Length)
85             USER_ID = BitConverter.ToInt64(pTemp, Scan0)
86
87             pTemp = New Byte(rawStream.Length - INT64 - INT64 - 1) {}
88             Call Array.ConstrainedCopy(rawStream, p, pTemp, Scan0, pTemp.Length)
89             Message = New RequestStream(pTemp)
90         End Sub
91
92         Sub New()
93         End Sub
94
95         Public Overrides Function Serialize() As Byte()
96             Dim RequestStream As Byte() = Message.Serialize
97             Dim ChunkBuffer As Byte() = New Byte(INT64 + INT64 + RequestStream.Length - 1) {}
98             Dim p As int = 0
99
100             Call Array.ConstrainedCopy(BitConverter.GetBytes(FROM), Scan0, ChunkBuffer, p + INT64, INT64)
101             Call Array.ConstrainedCopy(BitConverter.GetBytes(USER_ID), Scan0, ChunkBuffer, p + INT64, INT64)
102             Call Array.ConstrainedCopy(RequestStream, Scan0, ChunkBuffer, p, RequestStream.Length)
103             Return ChunkBuffer
104         End Function
105     End Class
106
107     Public Class BroadcastPOST : Inherits RawStream
108
109         <XmlAttribute> Public Property USER_ID As Long
110         <XmlText> Public Property Message As RequestStream
111
112         Public Sub New()
113         End Sub
114
115         Sub New(rawStream As Byte())
116             Dim pTemp As Byte() = New Byte(INT64 - 1) {}
117             Call Array.ConstrainedCopy(rawStream, Scan0, pTemp, Scan0, INT64)
118             USER_ID = BitConverter.ToInt64(pTemp, Scan0)
119             pTemp = New Byte(rawStream.Length - INT64 - 1) {}
120             Call Array.ConstrainedCopy(rawStream, INT64, pTemp, Scan0, pTemp.Length)
121             Message = New RequestStream(pTemp)
122         End Sub
123
124         Public Overrides Function Serialize() As Byte()
125             Dim RequestStream As Byte() = Message.Serialize
126             Dim ChunkBuffer As Byte() = New Byte(INT64 + RequestStream.Length - 1) {}
127             Call Array.ConstrainedCopy(BitConverter.GetBytes(USER_ID), Scan0, ChunkBuffer, Scan0, INT64)
128             Call Array.ConstrainedCopy(RequestStream, Scan0, ChunkBuffer, INT64, RequestStream.Length)
129             Return ChunkBuffer
130         End Function
131     End Class
132 End Namespace