Example #1
0
        private void WriteBlittableInstance(BlittableObjectInstance obj, bool isRoot, bool filterProperties)
        {
            if (obj.DocumentId != null &&
                _usageMode == BlittableJsonDocumentBuilder.UsageMode.None)
            {
                var metadata = obj.GetOrCreate(Constants.Documents.Metadata.Key);
                metadata.Put(Constants.Documents.Metadata.Id, obj.DocumentId, false);
            }
            if (obj.Blittable != null)
            {
                foreach (var propertyIndex in obj.Blittable.GetPropertiesByInsertionOrder())
                {
                    var prop = new BlittableJsonReaderObject.PropertyDetails();

                    obj.Blittable.GetPropertyByIndex(propertyIndex, ref prop);

                    var existInObject = obj.OwnValues.Remove(prop.Name, out var modifiedValue);

                    if (existInObject == false && obj.Deletes?.Contains(prop.Name) == true)
                    {
                        continue;
                    }

                    if (ShouldFilterProperty(filterProperties, prop.Name))
                    {
                        continue;
                    }

                    _writer.WritePropertyName(prop.Name);

                    if (existInObject && modifiedValue.Changed)
                    {
                        WriteJsonValue(obj, isRoot, prop.Name, modifiedValue.Value);
                    }
                    else
                    {
                        _writer.WriteValue(prop.Token & BlittableJsonReaderBase.TypesMask, prop.Value);
                    }
                }
            }

            foreach (var modificationKvp in obj.OwnValues)
            {
                var propertyName = modificationKvp.Key;
                if (ShouldFilterProperty(filterProperties, propertyName))
                {
                    continue;
                }

                if (modificationKvp.Value.Changed == false)
                {
                    continue;
                }

                _writer.WritePropertyName(propertyName);
                var blittableObjectProperty = modificationKvp.Value;
                WriteJsonValue(obj, isRoot, propertyName, blittableObjectProperty.Value);
            }
        }
Example #2
0
        private void WriteBlittableInstance(BlittableObjectInstance obj, bool isRoot, bool filterProperties)
        {
            HashSet <string> modifiedProperties = null;

            if (obj.DocumentId != null &&
                _usageMode == BlittableJsonDocumentBuilder.UsageMode.None)
            {
                var metadata = obj.GetOrCreate(Constants.Documents.Metadata.Key);
                metadata.Set(Constants.Documents.Metadata.Id, obj.DocumentId, false);
            }
            if (obj.Blittable != null)
            {
                var propertiesByInsertionOrder = obj.Blittable.GetPropertiesByInsertionOrder();
                for (int i = 0; i < propertiesByInsertionOrder.Properties.Count; i++)
                {
                    var prop      = new BlittableJsonReaderObject.PropertyDetails();
                    var propIndex = propertiesByInsertionOrder.Properties[i];
                    obj.Blittable.GetPropertyByIndex(propIndex, ref prop);

                    BlittableObjectInstance.BlittableObjectProperty modifiedValue = default;
                    JsValue key           = prop.Name.ToString();
                    var     existInObject = obj.OwnValues?
                                            .TryGetValue(key, out modifiedValue) == true;

                    if (existInObject == false && obj.Deletes?.Contains(key) == true)
                    {
                        continue;
                    }

                    if (existInObject)
                    {
                        modifiedProperties ??= new HashSet <string>();

                        modifiedProperties.Add(prop.Name);
                    }

                    if (ShouldFilterProperty(filterProperties, prop.Name))
                    {
                        continue;
                    }

                    _writer.WritePropertyName(prop.Name);

                    if (existInObject && modifiedValue.Changed)
                    {
                        WriteJsonValue(obj, isRoot, prop.Name, modifiedValue.Value);
                    }
                    else
                    {
                        _writer.WriteValue(prop.Token & BlittableJsonReaderBase.TypesMask, prop.Value);
                    }
                }
            }

            if (obj.OwnValues == null)
            {
                return;
            }

            foreach (var modificationKvp in obj.OwnValues)
            {
                //We already iterated through those properties while iterating the original properties set.
                if (modifiedProperties != null && modifiedProperties.Contains(modificationKvp.Key.AsString()))
                {
                    continue;
                }

                var propertyName         = modificationKvp.Key;
                var propertyNameAsString = propertyName.AsString();
                if (ShouldFilterProperty(filterProperties, propertyNameAsString))
                {
                    continue;
                }

                if (modificationKvp.Value.Changed == false)
                {
                    continue;
                }

                _writer.WritePropertyName(propertyNameAsString);
                var blittableObjectProperty = modificationKvp.Value;
                WriteJsonValue(obj, isRoot, propertyNameAsString, blittableObjectProperty.Value);
            }
        }