Beispiel #1
0
        public static void Serialize <T>(Stream stream, T obj)
        {
            Debug.Assert(_state != null, "State can't be null");
            var description = _state.GetDescription(RuntimeHelpers.GetHashCode(typeof(T)));
            var writer      = FormatterFactory <Writer> .GetFormatter(stream, Encoding);

            writer.Write(description.TypeId);
            ((SpecializedTypeDescription <T>)description).SerializeHanlder(obj, writer);
            FormatterFactory <Writer> .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
        public static object Deserialize(Stream stream)
        {
            var reader = FormatterFactory <Reader> .GetFormatter(stream, Encoding);

            var state  = _state;
            var typeId = reader.ReadShort();

            if (typeId >= state.DescriptionsById.Length)
            {
                state.UnknownTypeId(typeId);
            }
            var description = state.DescriptionsById[typeId];
            var obj         = description.Deserialize(reader);

            FormatterFactory <Reader> .ReleaseFormatter(reader);

            return(obj);
        }