Exemple #1
0
        public static Abook.AddressBook getAddressBook()
        {
            Abook.AddressBook ab = new Abook.AddressBook();

            //prepare a memory block to get address book binary representation
            UIntPtr abBinarySize = addressBookBinarySize();

            byte[] binData = new byte[(int)abBinarySize];
            int    size    = 0;

            getAddressBook(binData, out size);

            //address book message parser
            Google.Protobuf.MessageParser <Abook.AddressBook> mp = new Google.Protobuf.MessageParser <Abook.AddressBook>(() => new Abook.AddressBook());

            try
            {
                //instantiate Address book from the binary array
                ab = mp.ParseFrom(binData);

                //show received address book
                System.Windows.MessageBox.Show(ab.ToString());

                foreach (var entry in ab.Entry)
                {
                    Console.WriteLine(entry.FirstName);
                }
            }
            catch (Google.Protobuf.InvalidProtocolBufferException e)
            {
                System.Windows.MessageBox.Show(e.Message);
            }

            return(ab);
        }
Exemple #2
0
 private static T ToObject <T>(byte[] buf) where T : Google.Protobuf.IMessage <T>, new()
 {
     if (buf == null)
     {
         return(default(T));
     }
     Google.Protobuf.MessageParser <T> parser = new Google.Protobuf.MessageParser <T>(() => new T());
     return(parser.ParseFrom(buf));
 }
                public M[] AsMsgs <M>(Google.Protobuf.MessageParser <M> p, int at) where M : Google.Protobuf.IMessage <M>
                {
                    var bs = (List <byte[]>)Result[at].Result;

                    M[] rets = new M[bs.Count];
                    for (int i = 0; i < bs.Count; i++)
                    {
                        rets[i] = p.ParseFrom(bs[i]);
                    }
                    return(rets);
                }
Exemple #4
0
        private byte[] SignDks(IksOutEntity item)
        {
            // Unpack
            var parser = new Google.Protobuf.MessageParser <DiagnosisKeyBatch>(() => new DiagnosisKeyBatch());
            var batch  = parser.ParseFrom(item.Content);

            if (batch == null)
            {
                throw new Exception("TODO Something went wrong");
            }

            var efgsSerializer = new EfgsDiagnosisKeyBatchSerializer();

            return(_Signer.GetSignature(efgsSerializer.Serialize(batch)));
        }
        private void setTcpMessage()
        {
            try
            {
                string subject = BCAppConstants.NATSTopics.NATS_SUBJECT_TCPIP_LOG;

                //指定要執行的動作
                EventHandler <StanMsgHandlerArgs> msgHandler = (senders, args) =>
                {
                    lock (TcpMsgLock)
                    {
                        byte[] arrayByte = args.Message.Data;
                        if (arrayByte == null)
                        {
                            return;
                        }

                        //反序列化
                        Google.Protobuf.MessageParser <EQLOG_INFO> parser = new Google.Protobuf.MessageParser <EQLOG_INFO>(() => new EQLOG_INFO());
                        EQLOG_INFO eqmessage = parser.ParseFrom(arrayByte);

                        LogTitle_TCP logTitleTemp = new LogTitle_TCP()
                        {
                            VH_ID      = eqmessage.VHID,
                            SendRecive = eqmessage.SENDRECEIVE,
                            FunName    = eqmessage.FUNNAME,
                            SeqNo      = eqmessage.SEQNO.ToString(),
                            CmdID      = eqmessage.OHTCCMDID,
                            McsCmdID   = eqmessage.MCSCMDID,
                            ActType    = eqmessage.ACTTYPE,
                            EventType  = eqmessage.EVENTTYPE,
                            Message    = eqmessage.MESSAGE,
                            LogType    = BCAppConstants.LogType.TCP_ForEQ.ToString()
                        };

                        logTitleTemp.Time = eqmessage.TIME;
                        Task.Run(() => logUtility.addLogInfo(logTitleTemp));
                    }
                };

                //訂閱
                app.GetNatsManager().Subscriber(subject, msgHandler, false, true, 0, null);
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
        }
        private void setSystemEvent()
        {
            try
            {
                string subject = BCAppConstants.NATSTopics.NATS_SUBJECT_SYSTEM_LOG;

                //指定要執行的動作
                EventHandler <StanMsgHandlerArgs> msgHandler = (senders, args) =>
                {
                    lock (systemEventLock)
                    {
                        byte[] arrayByte = args.Message.Data;
                        if (arrayByte == null)
                        {
                            return;
                        }

                        //反序列化
                        Google.Protobuf.MessageParser <SYSTEMPROCESS_INFO> parser = new Google.Protobuf.MessageParser <SYSTEMPROCESS_INFO>(() => new SYSTEMPROCESS_INFO());
                        SYSTEMPROCESS_INFO systemEventInfo = parser.ParseFrom(arrayByte);

                        if (systemProcLst.Count > MAX_LOG_MSG_COUNT)
                        {
                            systemProcLst.RemoveAt(systemProcLst.Count - 1);
                        }

                        systemProcLst.Insert(0, systemEventInfo);

                        //更新畫面
                        Adapter.Invoke(new SendOrPostCallback((o1) =>
                        {
                            //dgv_systemLog.DataSource = systemProcLst;
                            uc_grid_SystemLog1.grid_Sys_Log.ItemsSource = systemProcLst;
                        }), null);
                    }
                };

                //訂閱
                app.GetNatsManager().Subscriber(subject, msgHandler, false, true, 0, null);       //當subject有變化,則進行msgHandler的動作
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
        }
        static StackObject *ParseFrom_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Byte[] @data = (System.Byte[]) typeof(System.Byte[]).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.MessageParser <BombFramework.AccPwdRequet> instance_of_this_method = (Google.Protobuf.MessageParser <BombFramework.AccPwdRequet>) typeof(Google.Protobuf.MessageParser <BombFramework.AccPwdRequet>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.ParseFrom(@data);

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Exemple #8
0
        static StackObject *ParseFrom_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.IO.Stream @input = (System.IO.Stream) typeof(System.IO.Stream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.MessageParser <Com.Test.Item.rsp_getItem> instance_of_this_method = (Google.Protobuf.MessageParser <Com.Test.Item.rsp_getItem>) typeof(Google.Protobuf.MessageParser <Com.Test.Item.rsp_getItem>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.ParseFrom(@input);

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
        private void setLineStatus()
        {
            try
            {
                string subject = BCAppConstants.NATSTopics.NATS_SUBJECT_LINE_INFO;
                //指定要執行的動作
                EventHandler <StanMsgHandlerArgs> msgHandler = (senders, args) =>
                {
                    lock (lineStatLock)
                    {
                        byte[] arrayByte = args.Message.Data;
                        if (arrayByte == null)
                        {
                            return;
                        }

                        //反序列化  saveLineInfo
                        Google.Protobuf.MessageParser <LINE_INFO> parser = new Google.Protobuf.MessageParser <LINE_INFO>(() => new LINE_INFO());
                        LINE_INFO lineInfo = parser.ParseFrom(arrayByte);

                        if (SCUtility.isEmpty(sLineID))
                        {
                            sLineID = lineInfo.LineID;
                            //更新Line ID
                            Adapter.Invoke(new SendOrPostCallback((o1) =>
                            {
                                lbl_LineID.Text = lineInfo.LineID;
                            }), null);
                        }
                    }
                };
                //訂閱
                app.GetNatsManager().Subscriber(subject, msgHandler, false, true, 0, null);       //當subject有變化,則進行msgHandler的動作
            }
            catch (Exception ex)
            {
                logger.Error(ex, "Exception");
            }
        }
        private void setSecsMessage()
        {
            string subject = BCAppConstants.NATSTopics.NATS_SUBJECT_SECS_LOG;

            //指定要執行的動作
            EventHandler <StanMsgHandlerArgs> msgHandler = (senders, args) =>
            {
                lock (SecsMsgLock)
                {
                    byte[] arrayByte = args.Message.Data;
                    if (arrayByte == null)
                    {
                        return;
                    }

                    //反序列化
                    Google.Protobuf.MessageParser <HOSTLOG_INFO> parser = new Google.Protobuf.MessageParser <HOSTLOG_INFO>(() => new HOSTLOG_INFO());
                    HOSTLOG_INFO hostmessage = parser.ParseFrom(arrayByte);

                    LogTitle_SECS logTitleTemp = new LogTitle_SECS()
                    {
                        EQ_ID      = hostmessage.EQID,
                        Sx         = hostmessage.SX,
                        Fy         = hostmessage.FY,
                        FunName    = hostmessage.FUNNAME,
                        SendRecive = hostmessage.SENDRECEIVE,
                        DeviceID   = hostmessage.DEVICE,
                        Message    = hostmessage.MESSAGE,
                        LogType    = BCAppConstants.LogType.SECS_ForHost.ToString()
                    };

                    logTitleTemp.Time = hostmessage.TIME;
                    Task.Run(() => logUtility.addLogInfo(logTitleTemp));
                }
            };

            //訂閱
            app.GetNatsManager().Subscriber(subject, msgHandler, false, true, 0, null);
        }
Exemple #11
0
        static StackObject *ParseFrom_1(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.IO.Stream @input = (System.IO.Stream) typeof(System.IO.Stream).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            Google.Protobuf.MessageParser <global::IMessageAdapter.Adaptor> instance_of_this_method = (Google.Protobuf.MessageParser <global::IMessageAdapter.Adaptor>) typeof(Google.Protobuf.MessageParser <global::IMessageAdapter.Adaptor>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.ParseFrom(@input);

            object obj_result_of_this_method = result_of_this_method;

            if (obj_result_of_this_method is CrossBindingAdaptorType)
            {
                return(ILIntepreter.PushObject(__ret, __mStack, ((CrossBindingAdaptorType)obj_result_of_this_method).ILInstance));
            }
            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
        public async Task <object> GetNodes()
        {
            EnsureIsAdmin();
            var ls = new Dictionary <uint, NodeInfo>(); //key=ip

            //1.扫描节点
            var peerStateParser = new Google.Protobuf.MessageParser <PeerState>(() => new PeerState());

            await ScanNodes((kp, ks, vp, vs) =>
            {
                unsafe
                {
                    uint peerId     = 0;
                    byte *peerIdPtr = (byte *)&peerId;
                    byte *keyPtr    = (byte *)kp.ToPointer();
                    peerIdPtr[0]    = keyPtr[2];
                    peerIdPtr[1]    = keyPtr[1];

                    var stream    = new System.IO.UnmanagedMemoryStream((byte *)vp.ToPointer(), vs);
                    var peerState = peerStateParser.ParseFrom(stream);
                    stream.Dispose();

                    var ip        = peerState.Endpoint.Address;
                    byte *ipPtr   = (byte *)&ip;
                    var ipAddress = $"{ipPtr[3]}.{ipPtr[2]}.{ipPtr[1]}.{ipPtr[0]}";
                    var nodeInfo  = new NodeInfo
                    {
                        PeerId    = peerId.ToString("X2"),
                        IPAddress = ipAddress,
                        Port      = (ushort)peerState.Endpoint.Port
                    };
                    ls.Add(ip, nodeInfo);
                }
            });

            //2.获取MetaNodes
            var        peerConfigParser = new Google.Protobuf.MessageParser <PeerConfig>(() => new PeerConfig());
            IntPtr     configData       = NativeApi.GetPeerConfigData();
            var        configDataPtr    = NativeApi.GetStringData(configData);
            var        configDataSize   = NativeApi.GetStringSize(configData);
            PeerConfig peerConfig;

            unsafe
            {
                var stream = new System.IO.UnmanagedMemoryStream((byte *)configDataPtr.ToPointer(), (long)configDataSize);
                peerConfig = peerConfigParser.ParseFrom(stream);
                stream.Dispose();
            }
            NativeApi.FreeNativeString(configData);
            foreach (var meta in peerConfig.MetaNodes)
            {
                ls[meta.Endpoint.Address].IsMeta     = true;
                ls[meta.Endpoint.Address].RaftNodes += 1;
            }

            //3.扫描RaftGroups
            var groupParser = new Google.Protobuf.MessageParser <RaftGroupInfo>(() => new RaftGroupInfo());

            await ScanRaftGroups((kp, ks, vp, vs) =>
            {
                unsafe
                {
                    var stream    = new System.IO.UnmanagedMemoryStream((byte *)vp.ToPointer(), vs);
                    var groupInfo = groupParser.ParseFrom(stream);
                    stream.Dispose();

                    foreach (var peer in groupInfo.Nodes)
                    {
                        ls[peer.Endpoint.Address].RaftNodes += 1;
                    }
                }
            });

            return(ls.Values.ToArray());
        }
 public M AsMsg <M>(Google.Protobuf.MessageParser <M> p, int at) where M : Google.Protobuf.IMessage <M>
 {
     return(p.ParseFrom((byte[])Result[at].Result));
 }
Exemple #14
0
        static int _m_ParseFrom(RealStatePtr L)
        {
            try {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);


                Google.Protobuf.MessageParser gen_to_be_invoked = (Google.Protobuf.MessageParser)translator.FastGetCSObj(L, 1);


                int gen_param_count = LuaAPI.lua_gettop(L);

                if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
                {
                    byte[] _data = LuaAPI.lua_tobytes(L, 2);

                    Google.Protobuf.IMessage gen_ret = gen_to_be_invoked.ParseFrom(_data);
                    translator.PushAny(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && translator.Assignable <Google.Protobuf.ByteString>(L, 2))
                {
                    Google.Protobuf.ByteString _data = (Google.Protobuf.ByteString)translator.GetObject(L, 2, typeof(Google.Protobuf.ByteString));

                    Google.Protobuf.IMessage gen_ret = gen_to_be_invoked.ParseFrom(_data);
                    translator.PushAny(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && translator.Assignable <System.IO.Stream>(L, 2))
                {
                    System.IO.Stream _input = (System.IO.Stream)translator.GetObject(L, 2, typeof(System.IO.Stream));

                    Google.Protobuf.IMessage gen_ret = gen_to_be_invoked.ParseFrom(_input);
                    translator.PushAny(L, gen_ret);



                    return(1);
                }
                if (gen_param_count == 2 && translator.Assignable <Google.Protobuf.CodedInputStream>(L, 2))
                {
                    Google.Protobuf.CodedInputStream _input = (Google.Protobuf.CodedInputStream)translator.GetObject(L, 2, typeof(Google.Protobuf.CodedInputStream));

                    Google.Protobuf.IMessage gen_ret = gen_to_be_invoked.ParseFrom(_input);
                    translator.PushAny(L, gen_ret);



                    return(1);
                }
            } catch (System.Exception gen_e) {
                return(LuaAPI.luaL_error(L, "c# exception:" + gen_e));
            }

            return(LuaAPI.luaL_error(L, "invalid arguments to Google.Protobuf.MessageParser.ParseFrom!"));
        }