|
|
|
@ -218,7 +218,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<string> ForString(uint tag, string defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<string>(input => input.ReadString(), (output, value) => output.WriteString(value), CodedOutputStream.ComputeStringSize, tag); |
|
|
|
|
return new FieldCodec<string>(input => input.ReadString(), (output, value) => output.WriteString(value), CodedOutputStream.ComputeStringSize, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -229,7 +229,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<ByteString> ForBytes(uint tag, ByteString defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<ByteString>(input => input.ReadBytes(), (output, value) => output.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag); |
|
|
|
|
return new FieldCodec<ByteString>(input => input.ReadBytes(), (output, value) => output.WriteBytes(value), CodedOutputStream.ComputeBytesSize, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -240,7 +240,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<bool> ForBool(uint tag, bool defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<bool>(input => input.ReadBool(), (output, value) => output.WriteBool(value), CodedOutputStream.BoolSize, tag); |
|
|
|
|
return new FieldCodec<bool>(input => input.ReadBool(), (output, value) => output.WriteBool(value), CodedOutputStream.BoolSize, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -251,7 +251,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<int> ForInt32(uint tag, int defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<int>(input => input.ReadInt32(), (output, value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag); |
|
|
|
|
return new FieldCodec<int>(input => input.ReadInt32(), (output, value) => output.WriteInt32(value), CodedOutputStream.ComputeInt32Size, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -262,7 +262,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<int> ForSInt32(uint tag, int defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<int>(input => input.ReadSInt32(), (output, value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag); |
|
|
|
|
return new FieldCodec<int>(input => input.ReadSInt32(), (output, value) => output.WriteSInt32(value), CodedOutputStream.ComputeSInt32Size, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -273,7 +273,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<uint> ForFixed32(uint tag, uint defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<uint>(input => input.ReadFixed32(), (output, value) => output.WriteFixed32(value), 4, tag); |
|
|
|
|
return new FieldCodec<uint>(input => input.ReadFixed32(), (output, value) => output.WriteFixed32(value), 4, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -284,7 +284,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<int> ForSFixed32(uint tag, int defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<int>(input => input.ReadSFixed32(), (output, value) => output.WriteSFixed32(value), 4, tag); |
|
|
|
|
return new FieldCodec<int>(input => input.ReadSFixed32(), (output, value) => output.WriteSFixed32(value), 4, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -295,7 +295,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<uint> ForUInt32(uint tag, uint defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<uint>(input => input.ReadUInt32(), (output, value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag); |
|
|
|
|
return new FieldCodec<uint>(input => input.ReadUInt32(), (output, value) => output.WriteUInt32(value), CodedOutputStream.ComputeUInt32Size, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -306,7 +306,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<long> ForInt64(uint tag, long defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<long>(input => input.ReadInt64(), (output, value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag); |
|
|
|
|
return new FieldCodec<long>(input => input.ReadInt64(), (output, value) => output.WriteInt64(value), CodedOutputStream.ComputeInt64Size, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -317,7 +317,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<long> ForSInt64(uint tag, long defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<long>(input => input.ReadSInt64(), (output, value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag); |
|
|
|
|
return new FieldCodec<long>(input => input.ReadSInt64(), (output, value) => output.WriteSInt64(value), CodedOutputStream.ComputeSInt64Size, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -328,7 +328,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<ulong> ForFixed64(uint tag, ulong defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<ulong>(input => input.ReadFixed64(), (output, value) => output.WriteFixed64(value), 8, tag); |
|
|
|
|
return new FieldCodec<ulong>(input => input.ReadFixed64(), (output, value) => output.WriteFixed64(value), 8, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -339,7 +339,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<long> ForSFixed64(uint tag, long defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<long>(input => input.ReadSFixed64(), (output, value) => output.WriteSFixed64(value), 8, tag); |
|
|
|
|
return new FieldCodec<long>(input => input.ReadSFixed64(), (output, value) => output.WriteSFixed64(value), 8, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -350,7 +350,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<ulong> ForUInt64(uint tag, ulong defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<ulong>(input => input.ReadUInt64(), (output, value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag); |
|
|
|
|
return new FieldCodec<ulong>(input => input.ReadUInt64(), (output, value) => output.WriteUInt64(value), CodedOutputStream.ComputeUInt64Size, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -361,7 +361,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<float> ForFloat(uint tag, float defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<float>(input => input.ReadFloat(), (output, value) => output.WriteFloat(value), CodedOutputStream.FloatSize, tag); |
|
|
|
|
return new FieldCodec<float>(input => input.ReadFloat(), (output, value) => output.WriteFloat(value), CodedOutputStream.FloatSize, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -372,7 +372,7 @@ namespace Google.Protobuf |
|
|
|
|
/// <returns>A codec for the given tag.</returns> |
|
|
|
|
public static FieldCodec<double> ForDouble(uint tag, double defaultValue) |
|
|
|
|
{ |
|
|
|
|
return new FieldCodec<double>(input => input.ReadDouble(), (output, value) => output.WriteDouble(value), CodedOutputStream.DoubleSize, tag); |
|
|
|
|
return new FieldCodec<double>(input => input.ReadDouble(), (output, value) => output.WriteDouble(value), CodedOutputStream.DoubleSize, tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Enums are tricky. We can probably use expression trees to build these delegates automatically, |
|
|
|
@ -391,7 +391,7 @@ namespace Google.Protobuf |
|
|
|
|
return new FieldCodec<T>(input => fromInt32( |
|
|
|
|
input.ReadEnum()), |
|
|
|
|
(output, value) => output.WriteEnum(toInt32(value)), |
|
|
|
|
value => CodedOutputStream.ComputeEnumSize(toInt32(value)), tag); |
|
|
|
|
value => CodedOutputStream.ComputeEnumSize(toInt32(value)), tag, defaultValue); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
@ -689,7 +689,8 @@ namespace Google.Protobuf |
|
|
|
|
Func<CodedInputStream, T> reader, |
|
|
|
|
Action<CodedOutputStream, T> writer, |
|
|
|
|
int fixedSize, |
|
|
|
|
uint tag) : this(reader, writer, _ => fixedSize, tag) |
|
|
|
|
uint tag, |
|
|
|
|
T defaultValue) : this(reader, writer, _ => fixedSize, tag, defaultValue) |
|
|
|
|
{ |
|
|
|
|
FixedSize = fixedSize; |
|
|
|
|
} |
|
|
|
@ -699,7 +700,7 @@ namespace Google.Protobuf |
|
|
|
|
Action<CodedOutputStream, T> writer, |
|
|
|
|
Func<T, int> sizeCalculator, |
|
|
|
|
uint tag, |
|
|
|
|
uint endTag = 0) : this(reader, writer, (CodedInputStream i, ref T v) => v = reader(i), (ref T v, T v2) => { v = v2; return true; }, sizeCalculator, tag, endTag, DefaultDefault) |
|
|
|
|
T defaultValue) : this(reader, writer, (CodedInputStream i, ref T v) => v = reader(i), (ref T v, T v2) => { v = v2; return true; }, sizeCalculator, tag, 0, defaultValue) |
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|