public override IDictionary <K, V> Deserialize(IByteBuffer buffer, TarsConvertOptions options) { switch (options.TarsType) { case TarsStructType.Map: { int size = buffer.ReadInt(); var dict = new Dictionary <K, V>(size); var op = options.Create(); for (int i = 0; i < size; ++i) { headHandler.ReadHead(buffer, op); var k = convert.Deserialize <K>(buffer, op); headHandler.ReadHead(buffer, op); var v = convert.Deserialize <V>(buffer, op); if (dict.ContainsKey(k)) { dict[k] = v; } else { dict.Add(k, v); } } return(dict); } default: throw new TarsDecodeException($"DictionaryTarsConvert can not deserialize {options}"); } }
public override void Serialize(IList <T> obj, IByteBuffer buffer, TarsConvertOptions options) { if (obj != null) { headHandler.Reserve(buffer, 8); headHandler.WriteHead(buffer, TarsStructType.List, options.Tag); buffer.WriteInt(obj.Count); var op = options.Create(); op.Tag = 0; foreach (var item in obj) { convert.Serialize(item, buffer, op); } } }
public override T Deserialize(IByteBuffer buffer, TarsConvertOptions options) { if (options.TarsType == TarsStructType.StructBegin) { var op = options.Create(); headHandler.ReadHead(buffer, op); var result = new T(); while (op.TarsType != TarsStructType.StructEnd) { var p = properties[op.Tag]; p.SetValue(result, convert.Deserialize(buffer, p.GetMemberInfo().PropertyType, op)); headHandler.ReadHead(buffer, op); } return(result); } else { throw new TarsDecodeException($"StructTarsConvert can not deserialize {options}"); } }
public override IList <T> Deserialize(IByteBuffer buffer, TarsConvertOptions options) { switch (options.TarsType) { case TarsStructType.List: { int size = buffer.ReadInt(); var list = new List <T>(size); var op = options.Create(); for (int i = 0; i < size; ++i) { headHandler.ReadHead(buffer, op); var t = convert.Deserialize(buffer, op); list.Add(t); } return(list); } default: throw new TarsDecodeException($"DictionaryTarsConvert can not deserialize {options}"); } }
private void DeserializeV1(IByteBuffer buffer, TarsConvertOptions options, Response resp) { while (buffer.IsReadable()) { headHandler.ReadHead(buffer, options); switch (options.Tag) { case 2: resp.PacketType = byteConvert.Deserialize(buffer, options); break; case 3: resp.RequestId = intConvert.Deserialize(buffer, options); break; case 4: resp.MessageType = intConvert.Deserialize(buffer, options); break; case 5: resp.ResultStatusCode = (RpcStatusCode)intConvert.Deserialize(buffer, options); var funcData = clientCallBack.FindRpcMethod(resp.RequestId); if (funcData.HasValue) { var(servantName, funcName) = funcData.Value; resp.ServantName = servantName; resp.FuncName = funcName; var(method, isOneway, outParameters, codec, version, serviceType) = rpcMetadata.FindRpcMethod(resp.ServantName, resp.FuncName); resp.ReturnValueType = method.ReturnParameter; resp.ReturnParameterTypes = outParameters; resp.ReturnParameters = new object[outParameters.Length]; } break; case 6: var contentBuffer = bufferConvert.Deserialize(buffer, options); if (resp.ResultStatusCode == RpcStatusCode.ServerSuccess) { var op = options.Create(); var len = resp.ReturnParameterTypes.Length; var returnType = resp.ReturnValueType.ParameterType; do { headHandler.ReadHead(contentBuffer, op); switch (op.Tag) { case 0: resp.ReturnValue = convertRoot.Deserialize(contentBuffer, returnType, op); break; default: var index = op.Tag - 1; resp.ReturnParameters[index] = convertRoot.Deserialize(contentBuffer, resp.ReturnParameterTypes[index].ParameterType, op); break; } }while (contentBuffer.IsReadable() && op.Tag >= 0 && op.Tag <= len); if (returnType == typeof(Task)) { resp.ReturnValue = convertRoot.Deserialize(contentBuffer, returnType, options); } } break; case 7: resp.Status = dictConvert.Deserialize(buffer, options); break; case 8: resp.ResultDesc = stringConvert.Deserialize(buffer, options); break; case 9: resp.Context = dictConvert.Deserialize(buffer, options); break; } } }