Ejemplo n.º 1
0
 /// <summary>
 /// Note: msgType and msgId are left to zero
 /// </summary>
 internal unsafe TrinityMessage(byte *buffer, int offset, int size)
 {
     Size           = TrinityProtocol.MsgHeader + size;
     Buffer         = (byte *)CMemory.C_malloc((ulong)Size);
     *(int *)Buffer = TrinityProtocol.TrinityMsgHeader + size;
     Memory.Copy(buffer, offset, Buffer + TrinityProtocol.MsgHeader, 0, size);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Used for constructing a Response message.
 /// </summary>
 /// <param name="errorCode">A 32-bit Trinity error code.</param>
 internal TrinityMessage(TrinityErrorCode errorCode)
 {
     Size           = TrinityProtocol.MsgHeader;
     Buffer         = (byte *)CMemory.C_malloc((ulong)Size);
     *(int *)Buffer = TrinityProtocol.TrinityMsgHeader;
     *(int *)(Buffer + TrinityProtocol.TrinityMsgHeader) = (int)errorCode;
 }
Ejemplo n.º 3
0
 internal TrinityMessage(TrinityMessageType msgType, ushort msgId, int size)
 {
     Size           = TrinityProtocol.MsgHeader + size;
     Buffer         = (byte *)CMemory.C_malloc((ulong)Size);
     *(int *)Buffer = TrinityProtocol.TrinityMsgHeader + size;
     *(Buffer + TrinityProtocol.MsgTypeOffset)         = (byte)msgType;
     *(ushort *)(Buffer + TrinityProtocol.MsgIdOffset) = msgId;
 }
Ejemplo n.º 4
0
        internal static void _serialize(byte **message, int *sizes, int count, out byte *buf, out int len)
        {
            len = 0;
            for (int i = 0; i < count; ++i)
            {
                len += sizes[i];
            }

            buf = (byte *)CMemory.C_malloc((ulong)len);
            byte *p = buf;

            for (int i = 0; i < count; ++i)
            {
                CMemory.C_memcpy((void *)p, (void *)*message, (ulong)*sizes);
                p += *sizes;
                ++message;
                ++sizes;
            }
        }
Ejemplo n.º 5
0
 internal TrinityResponse(int size)
 {
     Buffer = (byte *)CMemory.C_malloc((ulong)size);
     Size   = size;
     Offset = TrinityProtocol.TrinityMsgHeader;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Allocate a TrinityMessage whose buffer length is the specified size
 /// </summary>
 /// <param name="size">Message buffer length</param>
 internal unsafe TrinityMessage(int size)
 {
     Size           = size;
     Buffer         = (byte *)CMemory.C_malloc((ulong)size);
     *(int *)Buffer = size - TrinityProtocol.SocketMsgHeader;
 }