Exemple #1
0
 static void WriteNonZeroInt32(ref ProtoWriter.State state, int field, int value)
 {   // since Proto3 doesn't write zeros by default, neither will we
     if (value != 0)
     {
         state.WriteFieldHeader(field, WireType.Varint);
         state.WriteInt32(value);
     }
 }
Exemple #2
0
 void ISerializer <ScaledTicks> .Write(ref ProtoWriter.State state, ScaledTicks value)
 {
     if (value.Value != 0)
     {
         state.WriteFieldHeader(ScaledTicks.FieldTimeSpanValue, WireType.SignedVarint);
         state.WriteInt64(value.Value);
     }
     if (value.Scale != TimeSpanScale.Days)
     {
         state.WriteFieldHeader(ScaledTicks.FieldTimeSpanScale, WireType.Varint);
         state.WriteInt32((int)value.Scale);
     }
     if (value.Kind != DateTimeKind.Unspecified)
     {
         state.WriteFieldHeader(ScaledTicks.FieldTimeSpanKind, WireType.Varint);
         state.WriteInt32((int)value.Kind);
     }
 }
Exemple #3
0
 private static void WriteSecondsNanos(ref ProtoWriter.State state, long seconds, int nanos, bool isTimestamp)
 {
     NormalizeSecondsNanoseconds(ref seconds, ref nanos, isTimestamp);
     if (seconds != 0)
     {
         state.WriteFieldHeader(1, WireType.Varint);
         state.WriteInt64(seconds);
     }
     if (nanos != 0)
     {
         state.WriteFieldHeader(2, WireType.Varint);
         state.WriteInt32(nanos);
     }
 }
        public static void WriteValue(int fieldIndex, object value, ProtoWriter.State protoWriter)
        {
            if (value == null)
            {
                return;
            }
            switch (value)
            {
            case bool boolean:
                protoWriter.WriteFieldHeader(fieldIndex, WireType.Varint);
                protoWriter.WriteBoolean(boolean);
                break;

            case DateTime dateTime:
                protoWriter.WriteFieldHeader(fieldIndex, WireType.StartGroup);
                BclHelpers.WriteDateTime(ref protoWriter, dateTime);
                break;

            case int intValue:
                protoWriter.WriteFieldHeader(fieldIndex, WireType.Varint);
                protoWriter.WriteInt32(intValue);
                break;

            case short shortValue:
                protoWriter.WriteFieldHeader(fieldIndex, WireType.Varint);
                protoWriter.WriteInt16(shortValue);
                break;

            case double doubleValue:
                protoWriter.WriteFieldHeader(fieldIndex, WireType.Fixed64);
                protoWriter.WriteDouble(doubleValue);
                break;

            case string stringValue:
                protoWriter.WriteFieldHeader(fieldIndex, WireType.String);
                protoWriter.WriteString(stringValue);
                break;

            case Guid guidValue:
                protoWriter.WriteFieldHeader(fieldIndex, WireType.StartGroup);
                BclHelpers.WriteGuid(ref protoWriter, guidValue);
                break;

            default:
                throw new ProtoException("Unrecognized data type");
            }
        }
Exemple #5
0
 public void Write(ref ProtoWriter.State state, object value)
 {
     state.WriteInt32((int)value);
 }