示例#1
0
 /// <summary>
 /// 向服务器发送消息
 /// </summary>
 public bool Send(Message msg)
 {
     try
     {
         byte[] sendBuf = PackUtil.Pack(msg);
         socket.Send(sendBuf);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
示例#2
0
 /// <summary>
 /// Create expression that removes map item identified by rank.
 /// </summary>
 public static Exp RemoveByRank(Exp rank, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.REMOVE_BY_RANK, (int)MapReturnType.NONE, rank, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#3
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)));
 }
示例#4
0
 /// <summary>
 /// Create bit "right scan" operation.
 /// Server returns integer bit offset of the last specified value bit in byte[] bin
 /// starting at bitOffset for bitSize.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 32</li>
 /// <li>bitSize = 8</li>
 /// <li>value = true</li>
 /// <li>returns 7</li>
 /// </ul>
 /// </summary>
 public static Operation Rscan(string binName, int bitOffset, int bitSize, bool value)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.RSCAN, bitOffset, bitSize, value);
     return(new Operation(Operation.Type.BIT_READ, binName, Value.Get(bytes)));
 }
示例#5
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)));
 }
示例#6
0
 /// <summary>
 /// Create expression that increments list[index] by value.
 /// Value expression should resolve to a number.
 /// </summary>
 public static Exp Increment(ListPolicy policy, Exp index, Exp value, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.INCREMENT, index, value, policy.attributes, policy.flags, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#7
0
 /// <summary>
 /// Create expression that inserts value to specified index of list.
 /// </summary>
 public static Exp Insert(ListPolicy policy, Exp index, Exp value, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.INSERT, index, value, policy.flags, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#8
0
 /// <summary>
 /// Create expression that appends list items to end of list.
 /// </summary>
 public static Exp Append(ListPolicy policy, Exp value, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.APPEND, value, policy.attributes, policy.flags, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#9
0
 /// <summary>
 /// Create expression that sorts list according to sortFlags.
 /// </summary>
 /// <param name="sortFlags">sort flags. See <see cref="ListSortFlags"/>.</param>
 /// <param name="bin">bin or list value expression</param>
 /// <param name="ctx">optional context path for nested CDT</param>
 public static Exp Sort(int sortFlags, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.SORT, sortFlags, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#10
0
 /// <summary>
 /// Create expression that removes all items in list.
 /// </summary>
 public static Exp Clear(Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.CLEAR, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#11
0
 /// <summary>
 /// Create expression that selects map item identified by index and returns selected data specified by
 /// returnType.
 /// </summary>
 public static Exp GetByIndex(MapReturnType returnType, Exp.Type valueType, Exp index, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_INDEX, (int)returnType, index, ctx);
     return(AddRead(bin, bytes, valueType));
 }
示例#12
0
 /// <summary>
 /// Create expression that selects map items nearest to value and greater by relative rank with a count limit.
 /// Expression returns selected data specified by returnType.
 /// <para>
 /// Examples for map [{4=2},{9=10},{5=15},{0=17}]:
 /// <ul>
 /// <li>(value,rank,count) = [selected items]</li>
 /// <li>(11,1,1) = [{0=17}]</li>
 /// <li>(11,-1,1) = [{9=10}]</li>
 /// </ul>
 /// </para>
 /// </summary>
 public static Exp GetByValueRelativeRankRange(MapReturnType returnType, Exp value, Exp rank, Exp count, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_VALUE_REL_RANK_RANGE, (int)returnType, value, rank, count, ctx);
     return(AddRead(bin, bytes, GetValueType(returnType)));
 }
示例#13
0
 /// <summary>
 /// Create expression that selects map items nearest to key and greater by index with a count limit.
 /// Expression returns selected data specified by returnType.
 /// <para>
 /// Examples for ordered map [{0=17},{4=2},{5=15},{9=10}]:
 /// <ul>
 /// <li>(value,index,count) = [selected items]</li>
 /// <li>(5,0,1) = [{5=15}]</li>
 /// <li>(5,1,2) = [{9=10}]</li>
 /// <li>(5,-1,1) = [{4=2}]</li>
 /// <li>(3,2,1) = [{9=10}]</li>
 /// <li>(3,-2,2) = [{0=17}]</li>
 /// </ul>
 /// </para>
 /// </summary>
 public static Exp GetByKeyRelativeIndexRange(MapReturnType returnType, Exp key, Exp index, Exp count, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_KEY_REL_INDEX_RANGE, (int)returnType, key, index, count, ctx);
     return(AddRead(bin, bytes, GetValueType(returnType)));
 }
示例#14
0
 /// <summary>
 /// Create expression that selects map items identified by keys and returns selected data specified by
 /// returnType.
 /// </summary>
 public static Exp GetByKeyList(MapReturnType returnType, Exp keys, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_KEY_LIST, (int)returnType, keys, ctx);
     return(AddRead(bin, bytes, GetValueType(returnType)));
 }
示例#15
0
 /// <summary>
 /// Create expression that selects map item identified by key and returns selected data
 /// specified by returnType.
 /// </summary>
 /// <example>
 /// <code>
 /// // Map bin "a" contains key "B"
 /// Exp.GT(
 ///   MapExp.GetByKey(MapReturnType.COUNT, Type.INT, Exp.Val("B"), Exp.MapBin("a")),
 ///   Exp.Val(0));
 /// </code>
 /// </example>
 /// <param name="returnType">metadata attributes to return. See <see cref="MapReturnType"/> </param>
 /// <param name="valueType">		expected type of return value </param>
 /// <param name="key">			map key expression </param>
 /// <param name="bin">			bin or map value expression </param>
 /// <param name="ctx">			optional context path for nested CDT </param>
 public static Exp GetByKey(MapReturnType returnType, Exp.Type valueType, Exp key, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(MapOperation.GET_BY_KEY, (int)returnType, key, ctx);
     return(AddRead(bin, bytes, valueType));
 }
示例#16
0
 /// <summary>
 /// Create expression that selects list item identified by rank and returns selected
 /// data specified by returnType.
 /// </summary>
 /// <example>
 /// <code>
 /// // Player with lowest score.
 /// ListExp.GetByRank(ListReturnType.VALUE, Type.STRING, Exp.Val(0), Exp.ListBin("a"))
 /// </code>
 /// </example>
 /// <param name="returnType">metadata attributes to return. See <see cref="ListReturnType"/></param>
 /// <param name="valueType">expected type of return value</param>
 /// <param name="rank">rank expression</param>
 /// <param name="bin">list bin or list value expression</param>
 /// <param name="ctx">optional context path for nested CDT</param>
 public static Exp GetByRank(ListReturnType returnType, Exp.Type valueType, Exp rank, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.GET_BY_RANK, (int)returnType, rank, ctx);
     return(AddRead(bin, bytes, valueType));
 }
示例#17
0
 /// <summary>
 /// Create expression that selects "count" list items starting at specified rank and returns
 /// selected data specified by returnType.
 /// </summary>
 public static Exp GetByRankRange(ListReturnType returnType, Exp rank, Exp count, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.GET_BY_RANK_RANGE, (int)returnType, rank, count, ctx);
     return(AddRead(bin, bytes, GetValueType(returnType)));
 }
示例#18
0
 /// <summary>
 /// Create expression that removes list items identified by values.
 /// </summary>
 public static Exp RemoveByValueList(Exp values, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.REMOVE_BY_VALUE_LIST, (int)ListReturnType.NONE, values, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#19
0
 /// <summary>
 /// Create expression that appends list items to end of list.
 /// </summary>
 public static Exp AppendItems(ListPolicy policy, Exp list, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.APPEND_ITEMS, list, policy.attributes, policy.flags, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#20
0
 /// <summary>
 /// Create expression that removes list items nearest to value and greater by relative rank.
 /// <para>
 /// Examples for ordered list [0,4,5,9,11,15]:
 /// <ul>
 /// <li>(value,rank) = [removed items]</li>
 /// <li>(5,0) = [5,9,11,15]</li>
 /// <li>(5,1) = [9,11,15]</li>
 /// <li>(5,-1) = [4,5,9,11,15]</li>
 /// <li>(3,0) = [4,5,9,11,15]</li>
 /// <li>(3,3) = [11,15]</li>
 /// <li>(3,-3) = [0,4,5,9,11,15]</li>
 /// </ul>
 /// </para>
 /// </summary>
 public static Exp RemoveByValueRelativeRankRange(Exp value, Exp rank, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.REMOVE_BY_VALUE_REL_RANK_RANGE, (int)ListReturnType.NONE, value, rank, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#21
0
 /// <summary>
 /// Create expression that inserts each input list item starting at specified index of list.
 /// </summary>
 public static Exp InsertItems(ListPolicy policy, Exp index, Exp list, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.INSERT_ITEMS, index, list, policy.flags, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#22
0
 /// <summary>
 /// Create expression that removes "count" list items starting at specified index.
 /// </summary>
 public static Exp RemoveByIndexRange(Exp index, Exp count, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.REMOVE_BY_INDEX_RANGE, (int)ListReturnType.NONE, index, count, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#23
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)));
 }
示例#24
0
 /// <summary>
 /// Create expression that removes "count" list items starting at specified rank.
 /// </summary>
 public static Exp RemoveByRankRange(Exp rank, Exp count, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.REMOVE_BY_RANK_RANGE, (int)ListReturnType.NONE, rank, count, ctx);
     return(AddWrite(bin, bytes, ctx));
 }
示例#25
0
 /// <summary>
 /// Create bit "count" operation.
 /// Server returns integer count of set bits from byte[] bin starting at bitOffset for bitSize.
 /// Example:
 /// <ul>
 /// <li>bin = [0b00000001, 0b01000010, 0b00000011, 0b00000100, 0b00000101]</li>
 /// <li>bitOffset = 20</li>
 /// <li>bitSize = 4</li>
 /// <li>returns 2</li>
 /// </ul>
 /// </summary>
 public static Operation Count(string binName, int bitOffset, int bitSize)
 {
     byte[] bytes = PackUtil.Pack(BitOperation.COUNT, bitOffset, bitSize);
     return(new Operation(Operation.Type.BIT_READ, binName, Value.Get(bytes)));
 }
示例#26
0
 /// <summary>
 /// Create expression that returns list size.
 /// </summary>
 /// <example>
 /// <code>
 /// // List bin "a" size > 7
 /// Exp.GT(ListExp.Size(Exp.ListBin("a")), Exp.Val(7))
 /// </code>
 /// </example>
 public static Exp Size(Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.SIZE, ctx);
     return(AddRead(bin, bytes, Exp.Type.INT));
 }
示例#27
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)));
 }
示例#28
0
 /// <summary>
 /// Create expression that selects list items identified by values and returns selected data
 /// specified by returnType.
 /// </summary>
 public static Exp GetByValueList(ListReturnType returnType, Exp values, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.GET_BY_VALUE_LIST, (int)returnType, values, ctx);
     return(AddRead(bin, bytes, GetValueType(returnType)));
 }
示例#29
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)));
 }
示例#30
0
 /// <summary>
 /// Create expression that selects list items starting at specified index to the end of list
 /// and returns selected data specified by returnType.
 /// </summary>
 public static Exp GetByIndexRange(ListReturnType returnType, Exp index, Exp bin, params CTX[] ctx)
 {
     byte[] bytes = PackUtil.Pack(ListOperation.GET_BY_INDEX_RANGE, (int)returnType, index, ctx);
     return(AddRead(bin, bytes, GetValueType(returnType)));
 }