Ejemplo n.º 1
0
        internal static void Serialize(BufferWriterStream bufferWriter, object?input, DataContractSerializer serializer)
        {
            if (TraceEnabled)
            {
                TraceSerialize(input, serializer);
            }

            using var writer = XmlDictionaryWriter.CreateBinaryWriter(bufferWriter, null, null, false);
            serializer.WriteObject(writer, input);
        }
Ejemplo n.º 2
0
        public override void Serialize(BufferWriterStream bufferWriter, object?input, Type type)
        {
            if (this.TraceEnabled)
            {
                this.TraceSerialize(input, type);
            }

            var writerOptions = new JsonWriterOptions();

            if (this.Options != null)
            {
                writerOptions.Encoder  = this.Options.Encoder;
                writerOptions.Indented = this.Options.WriteIndented;
            }
            ;

            using var writer = new Utf8JsonWriter((IBufferWriter <byte>)bufferWriter, writerOptions);
            JsonSerializer.Serialize(writer, input, type, this.Options);
        }
        void IRpcSerializer.Serialize(BufferWriterStream bufferWriter, object?input, Type type)
        {
            if (!typeof(T).Equals(type))
            {
                throw new ArgumentException("Types do not match", nameof(type));
            }

            if (input is T typedInput)
            {
                this.Serialize(bufferWriter, typedInput);
            }
            else if (input == null)
            {
                this.Serialize(bufferWriter, default);
            }
            else
            {
                throw new ArgumentException($"'{nameof(input)}' must be of type '{typeof(T)}'.");
            }
        }
Ejemplo n.º 4
0
        public override void Serialize(BufferWriterStream bufferWriter, object?input, Type type)
        {
            var serializer = this.settings != null ? new DataContractSerializer(type, this.settings) : new DataContractSerializer(type);

            Serialize(bufferWriter, input, serializer);
        }
        public override void Serialize(BufferWriterStream bufferWriter, object?input, Type type)
        {
            var typedSerializer = (IRpcSerializer)this.CreateTyped(type, this.ReflectionCreateTyped);

            typedSerializer.Serialize(bufferWriter, input, type);
        }
 public void Serialize(BufferWriterStream bufferWriter, [AllowNull] T input)
 {
     using var state = ProtoBuf.ProtoWriter.State.Create((IBufferWriter <byte>)bufferWriter, this.typeModel);
     state.SerializeRoot(input);
 }