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)); }
public byte[] Request(SprotoProtocolBase protocol, int session) { PackageType.Package package = new PackageType.Package(); int tag = protocol.GetTag(); package.type = tag; package.session = session; ProtocolFunctionDictionary.ProtocolInfo info = ProtocolFunctionDictionary.GetProtocolInfo(tag); if (info.Response != null) { this.sessionDictionary.Add(session, tag); } this.stream.Seek(0, System.IO.SeekOrigin.Begin); int len = package.encode(this.stream); SprotoTypeBase request = protocol.GetRequest(); if (request != null) { len += request.encode(this.stream); } return(this.spack.pack(this.stream.Buffer, len)); }
private int encode_struct(SprotoTypeBase obj) { byte[] data = obj.encode(); this.fill_size(data.Length); this.data.Write(data, 0, data.Length); return(SprotoTypeSize.sizeof_length + data.Length); }
private int encode_struct(SprotoTypeBase obj) { int sz_pos = this.data.Position; this.data.Seek(SprotoTypeSize.sizeof_length, SeekOrigin.Current); int len = obj.encode(this.data); int cur_pos = this.data.Position; this.data.Seek(sz_pos, SeekOrigin.Begin); this.fill_size(len); this.data.Seek(cur_pos, SeekOrigin.Begin); return(SprotoTypeSize.sizeof_length + len); }