コード例 #1
0
ファイル: SprotoRpc.cs プロジェクト: dingdalong/Test_Unity
            public byte[] Invoke <T>(SprotoTypeBase request = null, long?session = null)
            {
                int tag = protocol[typeof(T)];

                ProtocolFunctionDictionary.MetaInfo info = protocol[tag];
#if (!INCLUDE_IL2CPP)
                if (request != null && request.GetType() != info.Request.Key)
                {
                    throw new Exception("request type: " + request.GetType().ToString() + "not is expected. [" + info.Request.Key.GetType().ToString() + "]");
                }
#endif
                package.clear();
                package.type = tag;

                if (session != null)
                {
                    rpc.sessionDictionary.Add((long)session, info.Response.Value);
                    package.session = (long)session;
                }

                stream.Seek(0, System.IO.SeekOrigin.Begin);
                int len = package.encode(stream);

                if (request != null)
                {
                    len += request.encode(stream);
                }

                return(spack.pack(stream.Buffer, len));
            }
コード例 #2
0
 private SprotoTypeBase _gen(KeyValuePair <Type, typeFunc> field, int tag, byte[] buffer, int offset = 0)
 {
     if (field.Value != null)
     {
         SprotoTypeBase obj = field.Value(buffer, offset);
         if (obj.GetType() != field.Key)
         {
             throw new Exception("sproto type: " + obj.GetType().ToString() + "not is expected. [" + field.Key.ToString() + "]");
         }
         return(obj);
     }
     return(null);
 }
コード例 #3
0
        static private SprotoTypeBase _gen(Dictionary <int, KeyValuePair <Type, typeFunc> > dictionary, int tag, byte[] buffer, int offset = 0)
        {
            KeyValuePair <Type, typeFunc> v;

            if (dictionary.TryGetValue(tag, out v))
            {
                SprotoTypeBase obj = v.Value(buffer, offset);
                if (obj.GetType() != v.Key)
                {
                    SprotoTypeSize.error("sproto type: " + obj.GetType().ToString() + "not is expected. [" + v.Key.ToString() + "]");
                }
                return(obj);
            }

            return(null);
        }