コード例 #1
0
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
            internal static int CalculateSize <T>(T value, FieldCodec <T> codec)
            {
                int fieldLength = codec.CalculateSizeWithTag(value);

                return(CodedOutputStream.ComputeLengthSize(fieldLength) + fieldLength);
            }
コード例 #3
0
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
        // 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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
        // 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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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
ファイル: FieldCodec.cs プロジェクト: leancloud/csharp-sdk
 /// <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));
 }