示例#1
0
        private static byte[] PackMath
        (
            int command,
            BitPolicy policy,
            int bitOffset,
            int bitSize,
            long value,
            bool signed,
            BitOverflowAction action
        )
        {
            Packer packer = new Packer();

            // Pack.init() only required when CTX is used and server does not support CTX for bit operations.
            // Pack.init(packer, ctx);
            packer.PackArrayBegin(6);
            packer.PackNumber(command);
            packer.PackNumber(bitOffset);
            packer.PackNumber(bitSize);
            packer.PackNumber(value);
            packer.PackNumber(policy.flags);

            int flags = (int)action;

            if (signed)
            {
                flags |= INT_FLAGS_SIGNED;
            }
            packer.PackNumber(flags);
            return(packer.ToByteArray());
        }
        private static Operation CreateMathOperation
        (
            int command,
            BitPolicy policy,
            string binName,
            int bitOffset,
            int bitSize,
            long value,
            bool signed,
            BitOverflowAction action
        )
        {
            Packer packer = new Packer();

            Init(packer, command, 5);
            packer.PackNumber(bitOffset);
            packer.PackNumber(bitSize);
            packer.PackNumber(value);
            packer.PackNumber(policy.flags);

            int flags = (int)action;

            if (signed)
            {
                flags |= INT_FLAGS_SIGNED;
            }
            packer.PackNumber(flags);
            return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
 /// <summary>
 /// Create bit "subtract" operation.
 /// Server subtracts value from byte[] bin starting at bitOffset for bitSize. BitSize must be &lt;= 64.
 /// Signed indicates if bits should be treated as a signed number.
 /// If add overflows/underflows, <seealso cref="BitOverflowAction"/> is used.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 24</li>
 /// <li>bitSize = 16</li>
 /// <li>value = 128</li>
 /// <li>signed = false</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000011, 0b0000011, 0b10000101]</li>
 /// </ul>
 /// </summary>
 public static Operation Subtract
 (
     BitPolicy policy,
     string binName,
     int bitOffset,
     int bitSize,
     long value,
     bool signed,
     BitOverflowAction action
 )
 {
     return(CreateMathOperation(SUBTRACT, policy, binName, bitOffset, bitSize, value, signed, action));
 }
示例#4
0
 /// <summary>
 /// Create bit "subtract" operation.
 /// Server subtracts value from byte[] bin starting at bitOffset for bitSize. BitSize must be &lt;= 64.
 /// Signed indicates if bits should be treated as a signed number.
 /// If add overflows/underflows, <seealso cref="BitOverflowAction"/> is used.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 24</li>
 /// <li>bitSize = 16</li>
 /// <li>value = 128</li>
 /// <li>signed = false</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000011, 0b0000011, 0b10000101]</li>
 /// </ul>
 /// </summary>
 public static Operation Subtract
 (
     BitPolicy policy,
     string binName,
     int bitOffset,
     int bitSize,
     long value,
     bool signed,
     BitOverflowAction action
 )
 {
     byte[] bytes = BitOperation.PackMath(BitOperation.SUBTRACT, policy, bitOffset, bitSize, value, signed, action);
     return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(bytes)));
 }
示例#5
0
 /// <summary>
 /// Create expression that subtracts value from byte[] bin starting at bitOffset for bitSize and returns byte[].
 /// BitSize must be &lt;= 64. Signed indicates if bits should be treated as a signed number.
 /// If add overflows/underflows, <see cref="BitOverflowAction"/> is used.
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 24</li>
 /// <li>bitSize = 16</li>
 /// <li>value = 128</li>
 /// <li>signed = false</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000011, 0b0000011, 0b10000101]</li>
 /// </ul>
 /// </summary>
 public static Exp Subtract(BitPolicy policy, Exp bitOffset, Exp bitSize, Exp value, bool signed, BitOverflowAction action, Exp bin)
 {
     byte[] bytes = PackMath(BitOperation.SUBTRACT, policy, bitOffset, bitSize, value, signed, action);
     return(AddWrite(bin, bytes));
 }