Add project files.
This commit is contained in:
1 parent
69125777be
commit
082c25b252
5 files changed
+161
No files matched your search
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BotBridge;
|
||||
|
||||
internal class BotExtHost
|
||||
{
|
||||
|
||||
private readonly Stream _stdIn = Console.OpenStandardInput();
|
||||
private readonly Stream _stdOut = Console.OpenStandardOutput();
|
||||
|
||||
|
||||
public void WriteData(byte[] data)
|
||||
{
|
||||
byte[] dataLength = BitConverter.GetBytes(data.Length);
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
Array.Reverse(dataLength);
|
||||
}
|
||||
_stdOut.Write(dataLength, 0, dataLength.Length);
|
||||
|
||||
_stdOut.Write(data, 0, data.Length);
|
||||
_stdIn.Flush();
|
||||
}
|
||||
|
||||
public byte[] ReadData()
|
||||
{
|
||||
byte[] dataLengthBytes = new byte[4];
|
||||
_stdIn.Read(dataLengthBytes, 0, 4);
|
||||
if (BitConverter.IsLittleEndian)
|
||||
{
|
||||
Array.Reverse(dataLengthBytes);
|
||||
}
|
||||
int dataLength = BitConverter.ToInt32(dataLengthBytes, 0);
|
||||
|
||||
byte[] data = new byte[dataLength];
|
||||
_stdIn.Read(data, 0, dataLength);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user