本文整理汇总了C#中ByteArray.writeByte方法的典型用法代码示例。如果您正苦于以下问题:C# ByteArray.writeByte方法的具体用法?C# ByteArray.writeByte怎么用?C# ByteArray.writeByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ByteArray
的用法示例。
在下文中一共展示了ByteArray.writeByte方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: encode
public static ByteArray encode(Message vo)
{
//result.endian = Endian.BIG_ENDIAN;
ByteArray result = new ByteArray();
result.writeByte(131);
pack(vo, result, ProtoAliasUtil.getAliasByClassName(vo.getClassName()));
if (isEncrypt == false)
{
return result;
}
if (encryptHandler != null)
{
return encryptHandler(result);
}
return result;
}
示例2: send
public void send(Message message)
{
if (message == null) {
return;
}
int packetHeader;
byte id;
ByteArray dataByte = new ByteArray();
//dataByte.position = 0;
dataByte = Message.encode(message);
if (dataByte.Length > 512) {
dataByte.Compress();
id = 1;
} else {
id = 0;
}
packetHeader = 1 + dataByte.Length;
ByteArray sendByte = new ByteArray();
sendByte.writeInt(packetHeader);
sendByte.writeByte(id);
sendByte.writeBytes(dataByte.Buffer, 0,dataByte.Length);
byte[] sendByte2 = new byte[sendByte.Length];
Array.Copy(sendByte.Buffer, 0, sendByte2, 0, sendByte.Length);
_socket.Send(sendByte2);
Debug.Log("SendDATA" + sendByte2.Length);
string msg = "";
for (int i = 0; i < sendByte2.Length; i++)
{
msg += sendByte2[i] + ",";
}
Debug.Log(msg);
}
示例3: send
private void send(Message message)
{
if (message == null)
{
return;
}
Debug.Log("发送协议 " + message.getClassName());
int packetHeader;
byte id;
ByteArray dataByte = new ByteArray();
//dataByte.position = 0;
dataByte = Message.encode(message);
if (dataByte.Length > 512)
{
dataByte.Compress();
id = 1;
}
else
{
id = 0;
}
packetHeader = 1 + dataByte.Length;
ByteArray sendByte = new ByteArray();
sendByte.writeInt(packetHeader);
sendByte.writeByte(id);
sendByte.writeBytes(dataByte.Buffer, 0, dataByte.Length);
byte[] sendByte2 = new byte[sendByte.Length];
Array.Copy(sendByte.Buffer, 0, sendByte2, 0, sendByte.Length);
//stateObj.workSocket.Send(sendByte2);
//Debug.Log("SendDATA" + sendByte2.Length);
string msg = "";
for (int i = 0; i < sendByte2.Length; i++)
{
msg += sendByte2[i] + ",";
}
//Debug.Log(msg);
stateObj.workSocket.BeginSend(sendByte2, 0, sendByte2.Length, SocketFlags.None, new AsyncCallback(SendCallback), stateObj.workSocket);
}
示例4: pack
public static byte[] pack(Message vo, ByteArray result, int alias = 0)
{
string[][] attrs = vo.getAttributes();
int lenT = attrs.Length;
int len = 0;
int i = 0;
int j = 0;
string type;
object voValue;
if (lenT > 255)
{
result.writeByte(105);
result.writeInt(lenT + 1);
}
else
{
result.writeByte(104);
result.writeByte((byte)(lenT + 1));
}
if (alias > 0)
{
result.writeByte(98);
result.writeInt(alias);
}
else
{
result.writeByte(100);
result.writeUTF(vo.getClassName());
}
for (i = 0; i < lenT; i++)
{
type = attrs[i][1].ToString().ToLower();
voValue = vo.getValue(attrs[i][0]);
if (type == "int")
{
result.writeByte(98);
result.writeInt((int)voValue);
}
else if (type == "double" || type == "number")
{
if ((double)voValue < 2147483647 && (double)voValue > -2147483647)
{
result.writeByte(98);
int small = (int)((double)voValue);
result.writeInt(small);
}
else
{
result.writeByte(110);
ByteArray bigB = new ByteArray();
float big = (float)voValue;
while (big > 1)
{
bigB.writeByte(Convert.ToByte((int)big & 0xFF));
big = big / 256;
}
result.writeByte(Convert.ToByte(bigB.Length));
if ((int)voValue > 0)
{
result.writeByte(0);
}
else
{
result.writeByte(1);
}
for (int bigL = 0; bigL <= bigB.Length - 1; bigL++)
{
result.writeByte(bigB.Buffer[bigL]);
}
}
}
else if (type == "String" || type == "string")
{
result.writeByte(107);
result.writeUTF((string)voValue);
}
else if (type == "bool" || type == "boolean")
{
result.writeByte(100);
if ((bool)voValue)
{
result.writeUTF("true");
}
else
{
result.writeUTF("false");
}
}
else if (type == "array")
{
if ((object[])voValue != null)
{
len = ((object[])voValue).Length;
if (len > 0)
{
result.writeByte(108);
result.writeUnsignedInt((uint)len);
string subType = (string)attrs[i][2].ToLower();
//.........这里部分代码省略.........