Beispiel #1
0
    public void onReceivedTCP(TcpMessage message)
    {
        MsgPack msgpack = new MsgPack();

        msgpack.DecodeFromBytes(message.getContent());

        StringBuilder builder = new StringBuilder();

        builder.Append("[");
        builder.Append("c: ");
        builder.Append(msgpack.ForcePathObject("c").AsString);
        builder.Append(", ");
        builder.Append("d: [");
        foreach (MsgPack item in msgpack.ForcePathObject("d"))
        {
            if (item.ValueType != MsgPackType.Array)
            {
                builder.Append(item.AsString);
                builder.Append(", ");
            }
            else
            {
                builder.Append("[");
                foreach (MsgPack i in item)
                {
                    builder.Append(i.AsString);
                    builder.Append(", ");
                }
                builder.Append("]");
            }
        }
        builder.Append("]");

        clientLog(builder.ToString());
    }
    public static void writeToStream(TcpMessage message, BinaryWriter writer)
    {
        byte[] lengthBuffer = BitConverter.GetBytes(message.getLength());

        if (BitConverter.IsLittleEndian)
        {
            Array.Reverse(lengthBuffer);
        }

        writer.Write(lengthBuffer);
        writer.Write(message.getContent());
    }