public void WriteObject(BlittableJsonReaderObject obj)
        {
            if (obj == null)
            {
                WriteNull();
                return;
            }

            WriteStartObject();
            var props = obj.GetPropertiesByInsertionOrder();
            var prop  = new BlittableJsonReaderObject.PropertyDetails();

            for (int i = 0; i < props.Length; i++)
            {
                if (i != 0)
                {
                    WriteComma();
                }

                obj.GetPropertyByIndex(props[i], ref prop);
                WritePropertyName(prop.Name);

                WriteValue(prop.Token & BlittableJsonReaderBase.TypesMask, prop.Value);
            }

            WriteEndObject();
        }
Beispiel #2
0
        public void WriteObject(BlittableJsonReaderObject obj)
        {
            if (obj == null)
            {
                WriteNull();
                return;
            }

            WriteStartObject();

            var prop = new BlittableJsonReaderObject.PropertyDetails();

            using (var buffer = obj.GetPropertiesByInsertionOrder())
            {
                var props = buffer.Properties;
                for (int i = 0; i < props.Count; i++)
                {
                    if (i != 0)
                    {
                        WriteComma();
                    }

                    obj.GetPropertyByIndex(props.Array[i + props.Offset], ref prop);
                    WritePropertyName(prop.Name);

                    WriteValue(prop.Token & BlittableJsonReaderBase.TypesMask, prop.Value);
                }
            }


            WriteEndObject();
        }
Beispiel #3
0
        public void WriteObjectOrdered(BlittableJsonReaderObject obj)
        {
            WriteStartObject();
            var props = obj.GetPropertiesByInsertionOrder();

            for (int i = 0; i < props.Length; i++)
            {
                if (i != 0)
                {
                    WriteComma();
                }

                var prop = obj.GetPropertyByIndex(props[i]);
                WritePropertyName(prop.Item1);

                WriteValue(prop.Item3 & BlittableJsonReaderBase.TypesMask, prop.Item2, originalPropertyOrder: true);
            }

            WriteEndObject();
        }
Beispiel #4
0
        protected bool Equals(BlittableJsonReaderObject other)
        {
            if (_propCount != other._propCount)
            {
                return(false);
            }

            if (_propCount == 0)
            {
                return(true);
            }

            if (_isRoot == false && other._isRoot == false)
            {
                var buffer = new PropertiesInsertionBuffer();

                GetPropertiesByInsertionOrder(buffer);

                var dataStart = _objStart - buffer.Offsets[0];
                var dataSize  = _objStart - dataStart;

                other.GetPropertiesByInsertionOrder(buffer);

                var otherDataStart = other._objStart - buffer.Offsets[0];
                var otherDataSize  = other._objStart - otherDataStart;

                if (dataSize == otherDataSize && dataSize < int.MaxValue)
                {
                    if (Memory.CompareInline(dataStart, otherDataStart, (int)dataSize) == 0)
                    {
                        // data of property values is the same, we also need to check names of properties
                        // they as are defined in root so it requires separate check

                        return(HasSamePropertyNames(other));
                    }
                }
            }
            else if (_isRoot && other._isRoot)
            {
                if (_size == other.Size && Memory.CompareInline(_mem, other._mem, _size) == 0)
                {
                    return(true);
                }
            }

            foreach (var propertyName in GetPropertyNames())
            {
                if (other.TryGetMember(propertyName, out object result) == false)
                {
                    return(false);
                }

                var current = this[propertyName];

                if (current == null && result == null)
                {
                    continue;
                }

                if ((current?.Equals(result) ?? false) == false)
                {
                    return(false);
                }
            }

            return(true);
        }