PackU16() 개인적인 정적인 메소드

Encodes a U16 into a buffer at a location in Big Endian order.
private static PackU16 ( byte buffer, int position, ushort value ) : void
buffer byte
position int
value ushort
리턴 void
예제 #1
0
        /// <summary>
        /// Packs a payload to the given buffer.
        /// </summary>
        internal static int PackPayload(
            byte[] buffer,
            ushort sequence,
            byte[] data,
            ushort dataLength)
        {
            buffer[0] = (byte)NetPacketType.Payload;
            NetEncoding.PackU16(buffer, 1, sequence);
            int position = NetEncoding.PAYLOAD_HEADER_SIZE;

            Array.Copy(data, 0, buffer, position, dataLength);
            return(position + dataLength);
        }
예제 #2
0
        /// <summary>
        /// Packs a notification prepended with that notification's length.
        /// </summary>
        private static int PackNotification(
            byte[] buffer,
            int position,
            byte[] data,
            ushort dataLength)
        {
            // For notifications we add the length since there may be multiple
            NetEncoding.PackU16(buffer, position, dataLength);
            position += NetEncoding.NOTIFICATION_HEADER_SIZE;

            Array.Copy(data, 0, buffer, position, dataLength);
            return(NetEncoding.NOTIFICATION_HEADER_SIZE + dataLength);
        }
예제 #3
0
        /// <summary>
        /// Packs a series of notifications into the buffer.
        /// </summary>
        internal static int PackCarrier(
            byte[] buffer,
            ushort notificationAck,
            ushort notificationSeq,
            IEnumerable <NetEvent> notifications)
        {
            int notificationHeaderSize = NetEncoding.NOTIFICATION_HEADER_SIZE;

            // Pack header
            buffer[0] = (byte)NetPacketType.Carrier;
            NetEncoding.PackU16(buffer, 1, notificationAck);
            NetEncoding.PackU16(buffer, 3, notificationSeq);
            int position = NetEncoding.CARRIER_HEADER_SIZE;

            // Pack notifications
            int dataPacked  = 0;
            int maxDataPack = NetEncoding.MAX_NOTIFICATION_PACK;

            foreach (NetEvent notification in notifications)
            {
                // See if we can fit the notification
                int packedSize = notificationHeaderSize + notification.EncodedLength;
                if ((dataPacked + packedSize) > maxDataPack)
                {
                    break;
                }

                // Pack the notification data
                int packSize =
                    NetEncoding.PackNotification(
                        buffer,
                        position,
                        notification.EncodedData,
                        notification.EncodedLength);

                // Increment counters
                dataPacked += packSize;
                position   += packSize;
            }

            return(position);
        }