Beispiel #1
0
        public static void Serialize(Stream stream, object obj)
        {
            Debug.Assert(_state != null, "State can't be null");

            if (obj == null)
            {
                _state.InstanceCannotBeNull();
            }

            var description = _state.GetDescription(obj.GetType());

            if (description == null)
            {
                _state.TypeNotSupported(obj.GetType());
            }

            var writer = WriterPool.GetFormatter(stream, Encoding);

            try
            {
                writer.Write(description.TypeId);
                description.Serialize(writer, obj);
            }
            finally
            {
                WriterPool.ReleaseFormatter(writer);
            }
        }
Beispiel #2
0
        public static void Serialize(Stream stream, object obj)
        {
            Debug.Assert(_state != null, "State can't be null");
            var description = _state.GetDescription(obj.GetType());
            var writer      = FormatterFactory <Writer> .GetFormatter(stream, Encoding);

            writer.Write(description.TypeId);
            description.Serialize(writer, obj);
            FormatterFactory <Writer> .ReleaseFormatter(writer);
        }
Beispiel #3
0
        private static void RegisterPrimitiveTypes(SerializerState state)
        {
            var primitiveTypes = BuilderFactory.GetPrimitiveTypes().ToArray();

            for (ushort i = 0; i < primitiveTypes.Length; i++)
            {
                if (state.GetDescription(primitiveTypes[i]) == null)
                {
                    var description = CreateTypeDescription(typeof(SimpleTypeDescription <>), primitiveTypes[i], i, primitiveTypes[i], state);
                    state.AddDescription(primitiveTypes[i], description);
                    description.Build();
                }
            }
        }