Example #1
0
        internal static unsafe void WriteViewRouteKey(byte *keyPtr, string viewName)
        {
            keyPtr[0] = METACF_VIEW_ROUTER_PREFIX;
            var writer = new EntityStoreWriter(keyPtr, 1);

            writer.WriteString(viewName, null);
        }
Example #2
0
        internal static unsafe void WriteAssemblyKey(bool isService, byte *keyPtr, string asmName)
        {
            if (isService)
            {
                keyPtr[0] = METACF_SERVICE_ASSEMBLY_PREFIX;
            }
            else
            {
                keyPtr[0] = METACF_VIEW_ASSEMBLY_PREFIX;
            }

            var writer = new EntityStoreWriter(keyPtr, 1);

            writer.WriteString(asmName, null);
        }
Example #3
0
        /// <summary>
        /// 保存视图模型路由表
        /// </summary>
        /// <param name="viewName">eg: sys.CustomerList</param>
        /// <param name="path">无自定义路由为空,有上级路由;分隔</param>
        internal static ValueTask UpsertViewRoute(string viewName, string path, Transaction txn)
        {
            //TODO:简化Key与Value编码,直接utf8,各减去3字节字符数标记
            IntPtr keyPtr;
            int    keySize   = EntityStoreWriter.CalcStringUtf8Size(viewName) + 1;
            IntPtr dataPtr   = IntPtr.Zero;
            int    valueSize = EntityStoreWriter.CalcStringUtf8Size(path);

            unsafe
            {
                byte *pk = stackalloc byte[keySize];
                KeyUtil.WriteViewRouteKey(pk, viewName);
                keyPtr = new IntPtr(pk);

                if (!string.IsNullOrEmpty(path))
                {
                    dataPtr = NativeApi.NewNativeString(valueSize, out byte *destDataPtr);
                    var sr = new EntityStoreWriter(destDataPtr, 0);
                    sr.WriteString(path, null);
                }
            }

            var req = new ClrInsertRequire
            {
                RaftGroupId      = KeyUtil.META_RAFTGROUP_ID,
                KeyPtr           = keyPtr,
                KeySize          = new IntPtr(keySize),
                DataPtr          = dataPtr,
                SchemaVersion    = 0,
                OverrideIfExists = true,
                DataCF           = -1
            };
            IntPtr reqPtr;

            unsafe { reqPtr = new IntPtr(&req); }
            return(HostApi.ExecKVInsertAsync(txn.Handle, reqPtr));
        }