Ejemplo n.º 1
0
        /// <summary>
        /// Updates the type structure and metadata for the specified writer.
        /// </summary>
        /// <param name="writer">The writer.</param>
        /// <param name="isNewSchema">Whether the current schema is know to be new.</param>
        public void UpdateWriterStructure(BinaryWriter writer, bool isNewSchema)
        {
            if (_curStructUpdates != null)
            {
                // The following line assumes that cluster meta update will succeed (BinaryProcessor.PutBinaryTypes).
                _desc.UpdateWriteStructure(_curStructPath, _curStructUpdates);

                var marsh = writer.Marshaller;

                var metaHnd = marsh.GetBinaryTypeHandler(_desc);

                if (metaHnd != null)
                {
                    foreach (var u in _curStructUpdates)
                    {
                        metaHnd.OnFieldWrite(u.FieldId, u.FieldName, u.FieldType);
                    }

                    var fields = metaHnd.OnObjectWriteFinished();

                    // A new schema may be added, but no new fields.
                    // In this case, we should still call SaveMetadata even if fields are null
                    writer.SaveMetadata(_desc, fields);
                }
            }
            else if (_desc.WriterTypeStructure == null)
            {
                // Empty object (no fields).
                // Null WriterTypeStructure indicates that meta has never been sent for this type.
                writer.Marshaller.GetBinaryTypeHandler(_desc);
                writer.SaveMetadata(_desc, null);
                _desc.UpdateWriteStructure(_curStructPath, null);
            }
            else if (isNewSchema && _portStruct != null && !_portStruct.IsPathEnd(_curStructPath, _curStructAction))
            {
                // Subset of current schema is a different schema and should be saved.
                writer.SaveMetadata(_desc, null);
            }
        }