예제 #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 byte "insert" operation.
        /// Server inserts value bytes into byte[] bin at byteOffset.
        /// Server does not return a value.
        /// Example:
        /// <ul>
        /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
        /// <li>byteOffset = 1</li>
        /// <li>value = [0b11111111, 0b11000111]</li>
        /// <li>bin result = [0b00000001, 0b11111111, 0b11000111, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
        /// </ul>
        /// </summary>
        public static Operation Insert(BitPolicy policy, string binName, int byteOffset, byte[] value)
        {
            Packer packer = new Packer();

            Init(packer, INSERT, 3);
            packer.PackNumber(byteOffset);
            packer.PackBytes(value);
            packer.PackNumber(policy.flags);
            return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(packer.ToByteArray())));
        }
        /// <summary>
        /// Create bit "setInt" operation.
        /// Server sets value to byte[] bin starting at bitOffset for bitSize. Size must be &lt;= 64.
        /// Server does not return a value.
        /// Example:
        /// <ul>
        /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
        /// <li>bitOffset = 1</li>
        /// <li>bitSize = 8</li>
        /// <li>value = 127</li>
        /// <li>bin result = [0b00111111, 0b11000010, 0b00000011, 0b0000100, 0b00000101]</li>
        /// </ul>
        /// </summary>
        public static Operation SetInt(BitPolicy policy, string binName, int bitOffset, int bitSize, long value)
        {
            Packer packer = new Packer();

            Init(packer, SET_INT, 4);
            packer.PackNumber(bitOffset);
            packer.PackNumber(bitSize);
            packer.PackNumber(value);
            packer.PackNumber(policy.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));
 }
예제 #6
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)));
 }
예제 #7
0
 /// <summary>
 /// Create expression that resizes byte[] to byteSize according to resizeFlags (See <see cref="BitResizeFlags"/>)
 /// and returns byte[].
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010]</li>
 /// <li>byteSize = 4</li>
 /// <li>resizeFlags = 0</li>
 /// <li>returns [0b00000001, 0b01000010, 0b00000000, 0b00000000]</li>
 /// </ul>
 /// </summary>
 /// <example>
 /// <code>
 /// // Resize bin "a" and compare bit count
 /// Exp.EQ(
 ///   BitExp.Count(Exp.Val(0), Exp.Val(3),
 ///     BitExp.Resize(BitPolicy.Default, Exp.Val(4), BitResizeFlags.DEFAULT, Exp.BlobBin("a"))),
 ///   Exp.Val(2))
 /// </code>
 /// </example>
 public static Exp Resize(BitPolicy policy, Exp byteSize, int resizeFlags, Exp bin)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.RESIZE, byteSize, policy.flags, resizeFlags);
     return(AddWrite(bin, bytes));
 }
예제 #8
0
 /// <summary>
 /// Create expression that sets value to byte[] bin starting at bitOffset for bitSize and returns byte[].
 /// BitSize must be &lt;= 64.
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 1</li>
 /// <li>bitSize = 8</li>
 /// <li>value = 127</li>
 /// <li>bin result = [0b00111111, 0b11000010, 0b00000011, 0b0000100, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Exp SetInt(BitPolicy policy, Exp bitOffset, Exp bitSize, Exp value, Exp bin)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.SET_INT, bitOffset, bitSize, value, policy.flags);
     return(AddWrite(bin, bytes));
 }
예제 #9
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));
 }
 /// <summary>
 /// Create bit "and" operation.
 /// Server performs bitwise "and" on value and byte[] bin at bitOffset for bitSize.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 23</li>
 /// <li>bitSize = 9</li>
 /// <li>value = [0b00111100, 0b10000000]</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000010, 0b00000000, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Operation And(BitPolicy policy, string binName, int bitOffset, int bitSize, byte[] value)
 {
     return(CreateOperation(AND, Operation.Type.BIT_MODIFY, binName, bitOffset, bitSize, value, policy.flags));
 }
예제 #11
0
 /// <summary>
 /// Create byte "insert" operation.
 /// Server inserts value bytes into byte[] bin at byteOffset.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>byteOffset = 1</li>
 /// <li>value = [0b11111111, 0b11000111]</li>
 /// <li>bin result = [0b00000001, 0b11111111, 0b11000111, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Operation Insert(BitPolicy policy, string binName, int byteOffset, byte[] value)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.INSERT, byteOffset, value, policy.flags);
     return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(bytes)));
 }
 /// <summary>
 /// Resize a bin to byteSize according to resizeFlags (See <seealso cref="BitResizeFlags"/>).
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010]</li>
 /// <li>byteSize = 4</li>
 /// <li>resizeFlags = 0</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000000, 0b00000000]</li>
 /// </ul>
 /// </summary>
 public static Operation Resize(BitPolicy policy, string binName, int byteSize, BitResizeFlags resizeFlags)
 {
     return(CreateOperation(RESIZE, Operation.Type.BIT_MODIFY, binName, byteSize, policy.flags, (int)resizeFlags));
 }
 /// <summary>
 /// Create bit "right shift" operation.
 /// Server shifts right byte[] bin starting at bitOffset for bitSize.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 0</li>
 /// <li>bitSize = 9</li>
 /// <li>shift = 1</li>
 /// <li>bin result = [0b00000000, 0b11000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Operation Rshift(BitPolicy policy, string binName, int bitOffset, int bitSize, int shift)
 {
     return(CreateOperation(RSHIFT, Operation.Type.BIT_MODIFY, binName, bitOffset, bitSize, shift, policy.flags));
 }
 /// <summary>
 /// Create bit "not" operation.
 /// Server negates byte[] bin starting at bitOffset for bitSize.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 25</li>
 /// <li>bitSize = 6</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000011, 0b01111010, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Operation Not(BitPolicy policy, string binName, int bitOffset, int bitSize)
 {
     return(CreateOperation(NOT, Operation.Type.BIT_MODIFY, binName, bitOffset, bitSize, policy.flags));
 }
예제 #15
0
 /// <summary>
 /// Create expression that inserts value bytes into byte[] bin at byteOffset and returns byte[].
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>byteOffset = 1</li>
 /// <li>value = [0b11111111, 0b11000111]</li>
 /// <li>bin result = [0b00000001, 0b11111111, 0b11000111, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// </ul>
 /// </summary>
 /// <example>
 /// <code>
 /// // Insert bytes into bin "a" and compare bit count
 /// Exp.EQ(
 ///   BitExp.Count(Exp.Val(0), Exp.Val(3),
 ///     BitExp.Insert(BitPolicy.Default, Exp.Val(1), Exp.Val(bytes), Exp.BlobBin("a"))),
 ///   Exp.Val(2))
 /// </code>
 /// </example>
 public static Exp Insert(BitPolicy policy, Exp byteOffset, Exp value, Exp bin)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.INSERT, byteOffset, value, policy.flags);
     return(AddWrite(bin, bytes));
 }
예제 #16
0
 /// <summary>
 /// Create bit "right shift" operation.
 /// Server shifts right byte[] bin starting at bitOffset for bitSize.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 0</li>
 /// <li>bitSize = 9</li>
 /// <li>shift = 1</li>
 /// <li>bin result = [0b00000000, 0b11000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Operation Rshift(BitPolicy policy, string binName, int bitOffset, int bitSize, int shift)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.RSHIFT, bitOffset, bitSize, shift, policy.flags);
     return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(bytes)));
 }
예제 #17
0
 /// <summary>
 /// Create expression that removes bytes from byte[] bin at byteOffset for byteSize and returns byte[].
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>byteOffset = 2</li>
 /// <li>byteSize = 3</li>
 /// <li>bin result = [0b00000001, 0b01000010]</li>
 /// </ul>
 /// </summary>
 /// <example>
 /// <code>
 /// // Remove bytes from bin "a" and compare bit count
 /// Exp.EQ(
 ///   BitExp.Count(Exp.Val(0), Exp.Val(3),
 ///     BitExp.Remove(BitPolicy.Default, Exp.Val(2), Exp.Val(3), Exp.BlobBin("a"))),
 ///   Exp.Val(2))
 /// </code>
 /// </example>
 public static Exp Remove(BitPolicy policy, Exp byteOffset, Exp byteSize, Exp bin)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.REMOVE, byteOffset, byteSize, policy.flags);
     return(AddWrite(bin, bytes));
 }
예제 #18
0
 /// <summary>
 /// Create bit "setInt" operation.
 /// Server sets value to byte[] bin starting at bitOffset for bitSize. Size must be &lt;= 64.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 1</li>
 /// <li>bitSize = 8</li>
 /// <li>value = 127</li>
 /// <li>bin result = [0b00111111, 0b11000010, 0b00000011, 0b0000100, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Operation SetInt(BitPolicy policy, string binName, int bitOffset, int bitSize, long value)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.SET_INT, bitOffset, bitSize, value, policy.flags);
     return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(bytes)));
 }
예제 #19
0
 /// <summary>
 /// Create expression that negates byte[] bin starting at bitOffset for bitSize and returns byte[].
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 25</li>
 /// <li>bitSize = 6</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000011, 0b01111010, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Exp Not(BitPolicy policy, Exp bitOffset, Exp bitSize, Exp bin)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.NOT, bitOffset, bitSize, policy.flags);
     return(AddWrite(bin, bytes));
 }
예제 #20
0
 /// <summary>
 /// Create byte "resize" operation.
 /// Server resizes byte[] to byteSize according to resizeFlags.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010]</li>
 /// <li>byteSize = 4</li>
 /// <li>resizeFlags = 0</li>
 /// <li>bin result = [0b00000001, 0b01000010, 0b00000000, 0b00000000]</li>
 /// </ul>
 /// </summary>
 public static Operation Resize(BitPolicy policy, string binName, int byteSize, BitResizeFlags resizeFlags)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.RESIZE, byteSize, policy.flags, (int)resizeFlags);
     return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(bytes)));
 }
예제 #21
0
 /// <summary>
 /// Create expression that shifts right byte[] bin starting at bitOffset for bitSize and returns byte[].
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 0</li>
 /// <li>bitSize = 9</li>
 /// <li>shift = 1</li>
 /// <li>bin result = [0b00000000, 0b11000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// </ul>
 /// </summary>
 public static Exp Rshift(BitPolicy policy, Exp bitOffset, Exp bitSize, Exp shift, Exp bin)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.RSHIFT, bitOffset, bitSize, shift, policy.flags);
     return(AddWrite(bin, bytes));
 }
예제 #22
0
 /// <summary>
 /// Create byte "remove" operation.
 /// Server removes bytes from byte[] bin at byteOffset for byteSize.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>byteOffset = 2</li>
 /// <li>byteSize = 3</li>
 /// <li>bin result = [0b00000001, 0b01000010]</li>
 /// </ul>
 /// </summary>
 public static Operation Remove(BitPolicy policy, string binName, int byteOffset, int byteSize)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.REMOVE, byteOffset, byteSize, policy.flags);
     return(new Operation(Operation.Type.BIT_MODIFY, binName, Value.Get(bytes)));
 }
 /// <summary>
 /// Create byte "remove" operation.
 /// Server removes bytes from byte[] bin at byteOffset for byteSize.
 /// Server does not return a value.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>byteOffset = 2</li>
 /// <li>byteSize = 3</li>
 /// <li>bin result = [0b00000001, 0b01000010]</li>
 /// </ul>
 /// </summary>
 public static Operation Remove(BitPolicy policy, string binName, int byteOffset, int byteSize)
 {
     return(CreateOperation(REMOVE, Operation.Type.BIT_MODIFY, binName, byteOffset, byteSize, policy.flags));
 }