diff --git a/Parallel/IpcParallel/IDelegate.vb b/Parallel/IpcParallel/IDelegate.vb index f2efc8a..3679ea2 100644 --- a/Parallel/IpcParallel/IDelegate.vb +++ b/Parallel/IpcParallel/IDelegate.vb @@ -65,4 +65,8 @@ Public Class IDelegate Return Nothing End Function + + Public Overrides Function ToString() As String + Return $"{type}::{name}" + End Function End Class \ No newline at end of file diff --git a/Parallel/IpcParallel/Stream/EmitHandler.vb b/Parallel/IpcParallel/Stream/EmitHandler.vb index bf8caf9..73f9afd 100644 --- a/Parallel/IpcParallel/Stream/EmitHandler.vb +++ b/Parallel/IpcParallel/Stream/EmitHandler.vb @@ -22,13 +22,27 @@ Namespace IpcStream Yield (GetType(UShort), Function(s) New MemoryStream(BitConverter.GetBytes(DirectCast(s, UShort)))) Yield (GetType(Boolean), Function(b) New MemoryStream(New Byte() {If(DirectCast(b, Boolean), 1, 0)})) - Yield (GetType(String), Function(s) New MemoryStream(Encoding.UTF8.GetBytes(DirectCast(s, String)))) + Yield (GetType(String), AddressOf stringBuffer) Yield (GetType(Char), Function(c) New MemoryStream(BitConverter.GetBytes(AscW(DirectCast(c, Char))))) Yield (GetType(Byte), Function(b) New MemoryStream({DirectCast(b, Byte)})) Yield (GetType(Date), Function(d) New MemoryStream(BitConverter.GetBytes(DirectCast(d, Date).UnixTimeStamp))) End Function + Private Function stringBuffer(s As Object) As Stream + Dim bytes As Byte() = Encoding.UTF8.GetBytes(DirectCast(s, String)) + Dim ms As New MemoryStream(bytes) + + Return ms + End Function + + Private Function stringBuffer(s As Stream) As Object + Dim bytes As Byte() = s.readAllBytes + Dim str As String = Encoding.UTF8.GetString(bytes) + + Return str + End Function + Public Iterator Function PopulatePrimitiveParsers() As IEnumerable(Of (target As Type, emit As loadBuffer)) Yield (GetType(Integer), Function(i) BitConverter.ToInt32(i.readAllBytes, Scan0)) Yield (GetType(UInteger), Function(i) BitConverter.ToUInt32(i.readAllBytes, Scan0)) @@ -43,7 +57,7 @@ Namespace IpcStream Yield (GetType(UShort), Function(s) BitConverter.ToUInt16(s.readAllBytes, Scan0)) Yield (GetType(Boolean), Function(b) b.readAllBytes()(Scan0) <> 0) - Yield (GetType(String), Function(s) Encoding.UTF8.GetString(s.readAllBytes)) + Yield (GetType(String), AddressOf stringBuffer) Yield (GetType(Char), Function(c) ChrW(BitConverter.ToInt32(c.readAllBytes, Scan0))) Yield (GetType(Byte), Function(b) b.readAllBytes()(Scan0)) @@ -52,8 +66,11 @@ Namespace IpcStream Private Function readAllBytes(buf As Stream) As Byte() - Dim bytes As Byte() = New Byte(buf.Length - 1) {} - Call buf.Read(bytes, Scan0, bytes.Length - 1) + Dim sizeOf As Integer = buf.Length + Dim bytes As Byte() = New Byte(sizeOf - 1) {} + + Call buf.Read(bytes, Scan0, sizeOf) + Return bytes End Function End Module