Example #1
0
#pragma warning disable IDE0051 // Remove unused private members
        private void ManuallyWrittenSerializeCallbackStructSimple(CallbackStructSimple obj, ref ProtoWriter.State state)
#pragma warning restore IDE0051 // Remove unused private members
        {
            obj.OnSerializing();
            string bar = obj.Bar;

            if (bar != null)
            {
                state.WriteFieldHeader(1, WireType.String);
                state.WriteString(bar);
            }
            obj.OnSerialized();
        }
        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");
            }
        }
 public void Write(ref ProtoWriter.State state, MyMessage value)
 {
     state.WriteString(12, value.Y);
     state.WriteInt32Varint(42, value.X);
 }
 void ISerializer <string> .Write(ref ProtoWriter.State state, string value) => state.WriteString(value);
Example #5
0
 void ISerializer <IPAddress> .Write(ref ProtoWriter.State state, IPAddress value)
 => state.WriteString(IPAddressFormat(value));
Example #6
0
 public void Write(ref ProtoWriter.State state, object value)
 {
     state.WriteString((string)value);
 }
 public void Write(ref ProtoWriter.State state, object value)
 {
     state.WriteString(value.ToString());
 }