public void DecodeRequestContent(Request req) { if (req.ParameterTypes.Length > 0) { if (req.Version == TarsCodecsConstant.VERSION) { if (req.Parameters == null) req.Parameters = new object[req.ParameterTypes.Length]; //todo buffer to byte[] TarsInputStream jis = new TarsInputStream((byte[])req.Buffer); //todo charset for (int i = 0; i < req.ParameterTypes.Length; i++) { Type type = TarsHelper.GetSourceType(req.ParameterTypes[i].ParameterType); req.Parameters[i] = jis.Read(type, i, false); } } else if (req.Version == TarsCodecsConstant.VERSION3 || req.Version == TarsCodecsConstant.VERSION2) { if (req.Parameters == null) throw new ArgumentException("params name should not be empty"); UniAttribute unaIn = new UniAttribute(req.Version); unaIn.Decode((byte[])req.Buffer); for (int i = 0; i < req.ParameterTypes.Length; i++) { req.Parameters[i] = unaIn.GetByType(req.ParameterTypes[i].Name, TarsHelper.GetSourceType(req.ParameterTypes[i].ParameterType)); } } else { throw new TarsException(RpcStatusCode.ServerDecodeErr, "un supported protocol, version = " + req.Version); } req.Buffer = null; } }
public void TestArray() { UniAttribute client = new UniAttribute(); byte[] aByte = new byte[] { 1, 2, 3, 4, 5, 6 }; client.Put("aByte", aByte); client.Put("aEmpty", new byte[0]); client.Put("aint", new int[] { 11, 22, 33, 44, 55, 66, 77, 88, 99, 10, 1111 }); byte[] buffer = client.Encode(); UniAttribute de = new UniAttribute(); de.Decode(buffer); aByte = de.Get <byte[]>("aByte"); byte[] aEmpty = de.Get <byte[]>("aEmpty"); int[] aint = de.Get <int[]>("aint"); }
public void TestBasicType() { UniAttribute client = new UniAttribute(); client.Put("short", (short)-123); client.Put("int", -1); client.Put("long", -1L); client.Put("ushort", (ushort)1234); client.Put("uint", (uint)1324234); client.Put("ulong", (ulong)123432455); client.Put("float", 1.23f); client.Put("double", (double)3.1415926); byte[] buffer = client.Encode(); UniAttribute de = new UniAttribute(); de.Decode(buffer); short sh = 0; sh = de.Get <short>("short"); int i = 0; i = de.Get <int>("int"); long l = 0; l = de.Get <long>("long"); ushort ush = 0; ush = (ushort)de.Get <ushort>("ushort"); uint ui = 0; ui = de.Get <uint>("uint"); ulong ul = 0; ul = de.Get <ulong>("ulong"); float f = 0.0f; f = de.Get <float>("float"); double d = 0.0; d = de.Get <double>("double"); }
public void TestTars() { UniAttribute client = new UniAttribute(); TestFriendlInfo tfi = new TestFriendlInfo(); tfi.dictTest = new Dictionary <int, string>(); for (int i = 0; i < 3; i++) { tfi.dictTest.Add(i, "v" + (i + 1)); } tfi.friend_count = 3; tfi.getfriendCount = 4; tfi.getgroupCount = 5; tfi.group_count = 6; tfi.groupid = 7; tfi.groupstartIndex = 13; tfi.ifGetGroupInfo = 0; tfi.ifReflush = 1; tfi.reqtype = 4321; tfi.startIndex = 32; tfi.totoal_friend_count = 3; tfi.totoal_group_count = 43; tfi.uin = 3214123; tfi.vecFriendInfo = new List <FriendInfo>(); for (int j = 0; j < 3; j++) { FriendInfo fi = new FriendInfo(); fi.faceId = (byte)j; fi.friendUin = j + 100; fi.groupId = (byte)(j + 13); fi.remark = "hello " + j; fi.sqqtype = (byte)j; fi.status = (byte)j; tfi.vecFriendInfo.Add(fi); } client.Put("TestFriendlInfo", tfi); byte[] buffer = client.Encode(); UniAttribute de = new UniAttribute(); de.Decode(buffer); TestFriendlInfo detfi = de.Get <TestFriendlInfo>("TestFriendlInfo"); }