Пример #1
0
        /// <summary>
        /// Create expression that writes each map item to map bin.
        /// </summary>
        public static Exp PutItems(MapPolicy policy, Exp map, Exp bin, params CTX[] ctx)
        {
            Packer packer = new Packer();

            if (policy.flags != 0)
            {
                PackUtil.Init(packer, ctx);
                packer.PackArrayBegin(4);
                packer.PackNumber(MapOperation.PUT_ITEMS);
                map.Pack(packer);
                packer.PackNumber(policy.attributes);
                packer.PackNumber(policy.flags);
            }
            else
            {
                if (policy.itemsCommand == MapOperation.REPLACE_ITEMS)
                {
                    // Replace doesn't allow map attributes because it does not create on non-existing key.
                    PackUtil.Init(packer, ctx);
                    packer.PackArrayBegin(2);
                    packer.PackNumber(policy.itemsCommand);
                    map.Pack(packer);
                }
                else
                {
                    PackUtil.Init(packer, ctx);
                    packer.PackArrayBegin(3);
                    packer.PackNumber(policy.itemsCommand);
                    map.Pack(packer);
                    packer.PackNumber(policy.attributes);
                }
            }
            byte[] bytes = packer.ToByteArray();
            return(AddWrite(bin, bytes, ctx));
        }
Пример #2
0
        internal static byte[] PackRangeOperation(int command, int returnType, Exp begin, Exp end, CTX[] ctx)
        {
            Packer packer = new Packer();

            PackUtil.Init(packer, ctx);
            packer.PackArrayBegin((end != null) ? 4 : 3);
            packer.PackNumber(command);
            packer.PackNumber(returnType);

            if (begin != null)
            {
                begin.Pack(packer);
            }
            else
            {
                packer.PackNil();
            }

            if (end != null)
            {
                end.Pack(packer);
            }
            return(packer.ToByteArray());
        }