📄 msg.cs
字号:
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace WindowsApplication1
{
/// <summary>
/// Msg 的摘要说明。
/// </summary>
public struct ErpMessage
{
public byte Kind;
public string Msg;
public ErpMessage(byte kind,string msg)
{
Kind=kind;
Msg=msg;
}
}
/// <summary>
/// 管道中的数据定义
/// </summary>
public struct RPIPEMessage
{
public UInt32 Size;
public byte Kind;
public UInt32 Count;
public char[] Data; //8095长度
private RPIPEMessage(string str)
{
Size=0;
Kind=1;
Count=0;
Data=new char[8095];
}
public RPIPEMessage(byte msgKind,string str)
{
this.Size=0;
this.Kind=msgKind;
byte[] bytes=System.Text.Encoding.UTF8.GetBytes(str);
if (bytes.Length>8095)
{
byte[] bts=new byte[8096];
Array.Copy(bytes,0,bts,0,8096);
bytes=bts;
}
this.Data =System.Text.Encoding.UTF8.GetChars(bytes);
this.Count =( UInt32)bytes.Length;
this.Size =(UInt32)Marshal.SizeOf(this.Kind)+(UInt32)Marshal.SizeOf(this.Size)+(UInt32)Marshal.SizeOf(this.Count)+this.Count+3;
}
public static RPIPEMessage GetMessage(byte[] bytes)
{
RPIPEMessage msg=new RPIPEMessage("");
if (bytes.Length<9) return msg;
msg.Size =BitConverter.ToUInt32(bytes,0);
msg.Count =BitConverter.ToUInt32(bytes,4);
msg.Kind =bytes[8];
string str=System.Text.Encoding.UTF8.GetString(bytes,9,(int)msg.Count);
msg.Data =System.Text.Encoding.UTF8.GetChars(System.Text.Encoding.UTF8.GetBytes(str));
return msg;
}
public byte[] GetBytes()
{
byte[] bytes=new byte[this.Size];
BitConverter.GetBytes(this.Size).CopyTo(bytes,0);
BitConverter.GetBytes(this.Count).CopyTo(bytes,4);
BitConverter.GetBytes(this.Kind).CopyTo(bytes,8);
byte[] bts=System.Text.Encoding.UTF8.GetBytes(this.Data);
bts.CopyTo(bytes,9);
return bytes;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -