示例#1
0
        /// <exception cref="System.IO.IOException" />
        public DefaultPortableWriter(PortableSerializer serializer, ObjectDataOutput @out, IClassDefinition cd)
        {
            _serializer    = serializer;
            _out           = @out;
            _cd            = cd;
            _writtenFields = new HashSet <string>(); //cd.GetFieldCount()
            _begin         = @out.Position;
            // room for final offset
            @out.WriteZeroBytes(4);
            @out.WriteInt(cd.GetFieldCount());
            _offset = @out.Position;
            // one additional for raw data
            var fieldIndexesLength = (cd.GetFieldCount() + 1) * BytesExtensions.SizeOfInt;

            @out.WriteZeroBytes(fieldIndexesLength);
        }
示例#2
0
        internal SerializationService(IInputOutputFactory inputOutputFactory, int version,
                                      IDictionary <int, IDataSerializableFactory> dataSerializableFactories,
                                      IDictionary <int, IPortableFactory> portableFactories, ICollection <IClassDefinition> classDefinitions,
                                      SerializerHooks hooks,
                                      IEnumerable <ISerializerDefinitions> definitions,
                                      bool checkClassDefErrors, IPartitioningStrategy partitioningStrategy, int initialOutputBufferSize,
                                      ILoggerFactory loggerFactory)
        {
            _logger                    = loggerFactory.CreateLogger <SerializationService>();
            _inputOutputFactory        = inputOutputFactory;
            GlobalPartitioningStrategy = partitioningStrategy;
            _outputBufferSize          = initialOutputBufferSize;
            _bufferPoolThreadLocal     = new BufferPoolThreadLocal(this);
            _portableContext           = new PortableContext(this, version);

            // create data serializer (will be added as constant)
            var dataSerializer = new DataSerializer(hooks, dataSerializableFactories, loggerFactory);

            _dataSerializerAdapter = CreateSerializerAdapter <IIdentifiedDataSerializable>(dataSerializer);

            // create portable serializer (will be added as constant)
            _portableSerializer        = new PortableSerializer(_portableContext, portableFactories);
            _portableSerializerAdapter = CreateSerializerAdapter <IPortable>(_portableSerializer);

            // create the serializer of null objects (will be added as constant)
            _nullSerializerAdapter = CreateSerializerAdapter <object>(new NullSerializer());

            // create the serializable adapter (will be added as constant)
            _serializableSerializerAdapter = CreateSerializerAdapter <object>(new SerializableSerializer());

            // add defined serializers
            foreach (var definition in definitions)
            {
                definition.AddSerializers(this);
            }

            // add constant serializers
            AddMoreSerializers();

            // add class definitions
            RegisterClassDefinitions(classDefinitions, checkClassDefErrors);
        }
示例#3
0
        public DefaultPortableReader(PortableSerializer serializer, IBufferObjectDataInput @in, IClassDefinition cd)
        {
            _in        = @in;
            Serializer = serializer;
            Cd         = cd;
            int fieldCount;

            try
            {
                // final position after portable is read
                _finalPosition = @in.ReadInt();
                // field count
                fieldCount = @in.ReadInt();
            }
            catch (IOException e)
            {
                throw new SerializationException(e);
            }
            if (fieldCount != cd.GetFieldCount())
            {
                throw new InvalidOperationException("Field count[" + fieldCount + "] in stream does not match " + cd);
            }
            _offset = @in.Position;
        }