Example #1
0
 /// <summary>
 /// Creates a codec for a wrapper type of a struct - which must be Int32, Int64, UInt32, UInt64,
 /// Bool, Single or Double.
 /// </summary>
 public static FieldCodec<T?> ForStructWrapper<T>(uint tag) where T : struct
 {
     var nestedCodec = WrapperCodecs.GetCodec<T>();
     return new FieldCodec<T?>(
         input => WrapperCodecs.Read<T>(input, nestedCodec),
         (output, value) => WrapperCodecs.Write<T>(output, value.Value, nestedCodec),
         value => value == null ? 0 : WrapperCodecs.CalculateSize<T>(value.Value, nestedCodec),
         tag,
         null); // Default value for the wrapper
 }
Example #2
0
 /// <summary>
 /// Creates a codec for a wrapper type of a class - which must be string or ByteString.
 /// </summary>
 public static FieldCodec<T> ForClassWrapper<T>(uint tag) where T : class
 {
     var nestedCodec = WrapperCodecs.GetCodec<T>();
     return new FieldCodec<T>(
         input => WrapperCodecs.Read<T>(input, nestedCodec),
         (output, value) => WrapperCodecs.Write<T>(output, value, nestedCodec),
         value => WrapperCodecs.CalculateSize<T>(value, nestedCodec),
         tag,
         null); // Default value for the wrapper
 }
Example #3
0
        /// <summary>
        /// Creates a codec for a wrapper type of a class - which must be string or ByteString.
        /// </summary>
        public static FieldCodec <T> ForClassWrapper <T>(uint tag) where T : class
        {
            var nestedCodec = WrapperCodecs.GetCodec <T>();

            return(new FieldCodec <T>(
                       input => WrapperCodecs.Read <T>(input, nestedCodec),
                       (output, value) => WrapperCodecs.Write <T>(output, value, nestedCodec),
                       (CodedInputStream i, ref T v) => v = WrapperCodecs.Read <T>(i, nestedCodec),
                       (ref T v, T v2) => { v = v2; return v == null; },
                       value => WrapperCodecs.CalculateSize <T>(value, nestedCodec),
                       tag, 0,
                       null)); // Default value for the wrapper
        }
Example #4
0
        /// <summary>
        /// Creates a codec for a wrapper type of a class - which must be string or ByteString.
        /// </summary>
        public static FieldCodec <T> ForClassWrapper <T>(uint tag) where T : class
        {
            var nestedCodec = WrapperCodecs.GetCodec <T>();

            return(new FieldCodec <T>(
                       (ref ParseContext ctx) => WrapperCodecs.Read <T>(ref ctx, nestedCodec),
                       (ref WriteContext output, T value) => WrapperCodecs.Write <T>(ref output, value, nestedCodec),
                       (ref ParseContext ctx, ref T v) => v = WrapperCodecs.Read <T>(ref ctx, nestedCodec),
                       (ref T v, T v2) => { v = v2; return v == null; },
                       value => WrapperCodecs.CalculateSize <T>(value, nestedCodec),
                       tag, 0,
                       null)); // Default value for the wrapper
        }
Example #5
0
        /// <summary>
        /// Creates a codec for a wrapper type of a struct - which must be Int32, Int64, UInt32, UInt64,
        /// Bool, Single or Double.
        /// </summary>
        public static FieldCodec <T?> ForStructWrapper <T>(uint tag) where T : struct
        {
            var nestedCodec = WrapperCodecs.GetCodec <T>();

            return(new FieldCodec <T?>(
                       input => WrapperCodecs.Read <T>(input, nestedCodec),
                       (output, value) => WrapperCodecs.Write <T>(output, value.Value, nestedCodec),
                       (CodedInputStream i, ref T? v) => v = WrapperCodecs.Read <T>(i, nestedCodec),
                       (ref T? v, T? v2) => { if (v2.HasValue)
                                              {
                                                  v = v2;
                                              }
                                              return v.HasValue; },
                       value => value == null ? 0 : WrapperCodecs.CalculateSize <T>(value.Value, nestedCodec),
                       tag, 0,
                       null)); // Default value for the wrapper
        }
Example #6
0
        /// <summary>
        /// Creates a codec for a wrapper type of a struct - which must be Int32, Int64, UInt32, UInt64,
        /// Bool, Single or Double.
        /// </summary>
        public static FieldCodec <T?> ForStructWrapper <T>(uint tag) where T : struct
        {
            var nestedCodec = WrapperCodecs.GetCodec <T>();

            return(new FieldCodec <T?>(
                       WrapperCodecs.GetReader <T>(),
                       (ref WriteContext output, T? value) => WrapperCodecs.Write <T>(ref output, value.Value, nestedCodec),
                       (ref ParseContext ctx, ref T? v) => v = WrapperCodecs.Read <T>(ref ctx, nestedCodec),
                       (ref T? v, T? v2) => { if (v2.HasValue)
                                              {
                                                  v = v2;
                                              }
                                              return v.HasValue; },
                       value => value == null ? 0 : WrapperCodecs.CalculateSize <T>(value.Value, nestedCodec),
                       tag, 0,
                       null)); // Default value for the wrapper
        }