示例#1
0
 /// <summary>
 /// Retrieves a codec suitable for an sint32 field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <int> ForSInt32(uint tag)
 {
     return(FieldCodec.ForSInt32(tag, 0));
 }
示例#2
0
            internal static int CalculateSize <T>(T value, FieldCodec <T> codec)
            {
                int fieldLength = codec.CalculateSizeWithTag(value);

                return(CodedOutputStream.ComputeLengthSize(fieldLength) + fieldLength);
            }
示例#3
0
 /// <summary>
 /// Retrieves a codec suitable for a bool field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <bool> ForBool(uint tag)
 {
     return(FieldCodec.ForBool(tag, false));
 }
示例#4
0
 internal static void Write <T>(ref WriteContext ctx, T value, FieldCodec <T> codec)
 {
     ctx.WriteLength(codec.CalculateSizeWithTag(value));
     codec.WriteTagAndValue(ref ctx, value);
 }
示例#5
0
 /// <summary>
 /// Retrieves a codec suitable for a bytes field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <ByteString> ForBytes(uint tag)
 {
     return(FieldCodec.ForBytes(tag, ByteString.Empty));
 }
示例#6
0
        // Enums are tricky. We can probably use expression trees to build these delegates automatically,
        // but it's easy to generate the code for it.

        /// <summary>
        /// Retrieves a codec suitable for an enum field with the given tag.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <param name="toInt32">A conversion function from <see cref="Int32"/> to the enum type.</param>
        /// <param name="fromInt32">A conversion function from the enum type to <see cref="Int32"/>.</param>
        /// <returns>A codec for the given tag.</returns>
        public static FieldCodec <T> ForEnum <T>(uint tag, Func <T, int> toInt32, Func <int, T> fromInt32)
        {
            return(FieldCodec.ForEnum(tag, toInt32, fromInt32, default(T)));
        }
示例#7
0
        // TODO: Avoid the "dual hit" of lambda expressions: create open delegates instead. (At least test...)

        /// <summary>
        /// Retrieves a codec suitable for a string field with the given tag.
        /// </summary>
        /// <param name="tag">The tag.</param>
        /// <returns>A codec for the given tag.</returns>
        public static FieldCodec <string> ForString(uint tag)
        {
            return(FieldCodec.ForString(tag, ""));
        }
示例#8
0
 /// <summary>
 /// Retrieves a codec suitable for a double field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <double> ForDouble(uint tag)
 {
     return(FieldCodec.ForDouble(tag, 0));
 }
示例#9
0
 /// <summary>
 /// Retrieves a codec suitable for a float field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <float> ForFloat(uint tag)
 {
     return(FieldCodec.ForFloat(tag, 0));
 }
示例#10
0
 /// <summary>
 /// Retrieves a codec suitable for a uint64 field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <ulong> ForUInt64(uint tag)
 {
     return(FieldCodec.ForUInt64(tag, 0));
 }
示例#11
0
 /// <summary>
 /// Retrieves a codec suitable for an sfixed64 field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <long> ForSFixed64(uint tag)
 {
     return(FieldCodec.ForSFixed64(tag, 0));
 }
示例#12
0
 /// <summary>
 /// Retrieves a codec suitable for a fixed32 field with the given tag.
 /// </summary>
 /// <param name="tag">The tag.</param>
 /// <returns>A codec for the given tag.</returns>
 public static FieldCodec <uint> ForFixed32(uint tag)
 {
     return(FieldCodec.ForFixed32(tag, 0));
 }