Inheritance: ISizedSpanSerializable, IEquatable
Esempio n. 1
0
 public static void WriteDouble(this IPv2ServerParamsInterface src, Pv2ParamType param, double value)
 {
     if (param is not Pv2DoubleParamType uintType)
     {
         throw new Exception($"Wrong type: want {nameof(Pv2DoubleParamType)}. Got {param.GetType().Name}");
     }
     src.Write(param, (_, v) => uintType.SetValue(v, value));
 }
Esempio n. 2
0
 public static void WriteEnum(this IPv2ServerParamsInterface src, Pv2ParamType param, string value)
 {
     if (param is not Pv2EnumParamType type)
     {
         throw new Exception($"Wrong type: want {nameof(Pv2EnumParamType)}. Got {param.GetType().Name}");
     }
     src.Write(param, (_, v) => type.SetValue(v, value));
 }
Esempio n. 3
0
        public static double ReadDouble(this IPv2ServerParamsInterface src, Pv2ParamType param)
        {
            if (param is not Pv2DoubleParamType uintType)
            {
                throw new Exception($"Wrong type: want {nameof(Pv2DoubleParamType)}. Got {param.GetType().Name}");
            }
            var paramResult = src.Read(param);

            return(uintType.GetValue(paramResult));
        }
Esempio n. 4
0
        public static string ReadEnum(this IPv2ClientParamsInterface src, Pv2ParamType param)
        {
            if (param is not Pv2EnumParamType type)
            {
                throw new Exception($"Wrong type: want {nameof(Pv2EnumParamType)}. Got {param.GetType().Name}");
            }
            var item = src.Read(type);

            return(type.GetValue(item));
        }
Esempio n. 5
0
        public void Deserialize(ref ReadOnlySpan <byte> buffer)
        {
            Index = BinSerialize.ReadPackedUnsignedInteger(ref buffer);
            var typeEnum = (Pv2ParamTypeEnum)BinSerialize.ReadPackedUnsignedInteger(ref buffer);

            Type = Pv2ParamInterface.CreateType(typeEnum);
            var isContainValue = BinSerialize.ReadBool(ref buffer);

            Type.Deserialize(ref buffer);
            Value = null;
            if (!isContainValue)
            {
                return;
            }
            Value = Pv2ParamInterface.CreateValue(typeEnum);
            Value.Deserialize(ref buffer);
        }
Esempio n. 6
0
 public Pv2ParamValueAndTypePair(Pv2ParamType type, Pv2ParamValue value, uint index)
 {
     Index = index;
     Type  = type;
     Value = value;
 }
Esempio n. 7
0
        public static async Task <double> WriteDouble(this IPv2ClientParamsInterface src, Pv2ParamType param,
                                                      double value, CancellationToken cancel = default)
        {
            if (param is not Pv2DoubleParamType uintType)
            {
                throw new Exception($"Wrong type: want {nameof(Pv2DoubleParamType)}. Got {param.GetType().Name}");
            }
            var result = await src.Write(param, (_, val) => uintType.SetValue(val, value), cancel)
                         .ConfigureAwait(false);

            return(uintType.GetValue(result));
        }