예제 #1
0
            /// <summary>
            /// Gets the request data as the byte array
            /// </summary>
            /// <returns>Request data</returns>
            public byte[] GetRequestData()
            {
                switch (this.operation)
                {
                case SetDataOperationCode.InterlockedAddIfVersion:
                {
                    byte[] data = this.prevData.Data;
                    if (data.Length != sizeof(long))
                    {
                        throw new InvalidOperationException("data in the node should be able to hold a long");
                    }

                    IoSession ios = new IoSession()
                    {
                        Buffer = data, MaxBytes = data.Length
                    };
                    IoSession res_ios = new IoSession()
                    {
                        Buffer = new byte[data.Length], MaxBytes = data.Length
                    };

                    long prevlong;
                    DataEncodingHelper.Read(ios, out prevlong);
                    prevlong += this.number;
                    ios.Pos   = 0;
                    DataEncodingHelper.Write(prevlong, res_ios);

                    return(res_ios.Buffer);
                }

                case SetDataOperationCode.InterlockedXORIfVersion:
                {
                    byte[] data = this.prevData.Data;
                    if (data.Length != sizeof(long))
                    {
                        throw new InvalidOperationException("data in the node should be able to hold a long");
                    }

                    IoSession ios = new IoSession()
                    {
                        Buffer = data, MaxBytes = data.Length
                    };
                    IoSession res_ios = new IoSession()
                    {
                        Buffer = new byte[data.Length], MaxBytes = data.Length
                    };

                    long prevlong;
                    DataEncodingHelper.Read(ios, out prevlong);
                    prevlong ^= this.number;
                    ios.Pos   = 0;
                    DataEncodingHelper.Write(prevlong, res_ios);

                    return(res_ios.Buffer);
                }

                default:
                    throw new NotImplementedException("I don't understand operation " + this.operation);
                }
            }
예제 #2
0
        /// <summary>
        /// creates a byte[] for SetData representing a "InterlockedSet(value)" operation
        /// </summary>
        /// <param name="value">value to set</param>
        /// <returns>the byte[] with the encoded operation.</returns>
        public ISetDataOperation InterlockedSet(long value)
        {
            IoSession ios = new IoSession()
            {
                Buffer = new byte[sizeof(long)], MaxBytes = Length
            };

            DataEncodingHelper.Write(value, ios);
            return(new SetDataOperation(ios.Buffer));
        }
예제 #3
0
        /// <summary>
        /// creates a byte[] for SetData representing a "InterlockedXOR(value)" operation
        /// </summary>
        /// <param name="value">value to compute the XOR with</param>
        /// <returns>the byte[] with the encoded operation.</returns>
        public ISetDataOperation InterlockedXOR(long value)
        {
            SetDataOperationCode op = SetDataOperationCode.InterlockedXORIfVersion;

            IoSession ios = new IoSession()
            {
                Buffer = new byte[Length], MaxBytes = Length
            };

            DataEncodingHelper.Write(Magic, ios);
            DataEncodingHelper.Write((ushort)op, ios);
            DataEncodingHelper.Write(value, ios);
            return(new SetDataOperation(ios.Buffer));
        }