当前位置: 首页>>代码示例>>C#>>正文


C# ByteArray.writeByte方法代码示例

本文整理汇总了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;
 }
开发者ID:ucjedpfmd,项目名称:U3DGame,代码行数:16,代码来源:Message.cs

示例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);
 }
开发者ID:ucjedpfmd,项目名称:U3DGame,代码行数:32,代码来源:Connection.cs

示例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);
 }
开发者ID:ucjedpfmd,项目名称:U3DGame,代码行数:38,代码来源:Connection2.cs

示例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();
//.........这里部分代码省略.........
开发者ID:ucjedpfmd,项目名称:U3DGame,代码行数:101,代码来源:Message.cs


注:本文中的ByteArray.writeByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。