コード例 #1
0
        /// <summary>
        /// Resets the bulk response for re-use.
        /// </summary>
        public void Reset()
        {
            mTookProxy   = default;
            mErrorsProxy = default;

            if (Items != null)
            {
                mPool.Return(Items);
                Items = null;
            }
        }
            /// <summary>
            /// Initializes the current instance from a JSON document using the specified JSON reader.
            /// </summary>
            /// <param name="data">The UTF-8 encoded JSON document being deserialized.</param>
            /// <param name="reader">The JSON reader used during deserialization.</param>
            internal void InitFromJson(byte[] data, ref Utf8JsonReader reader)
            {
                Debug.Assert(reader.TokenType == JsonTokenType.StartObject);

                string propertyName = null;

                while (reader.Read())
                {
                    switch (reader.TokenType)
                    {
                    case JsonTokenType.PropertyName:
                    {
                        propertyName = mPool.GetStringFromUtf8(reader.ValueSpan);
                        break;
                    }

                    case JsonTokenType.Number:
                    {
                        switch (propertyName)
                        {
                        case "failed":
                            mFailedProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                            break;

                        case "successful":
                            mSuccessfulProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                            break;

                        case "total":
                            mTotalProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                            break;
                        }

                        break;
                    }

                    case JsonTokenType.EndObject:
                    {
                        return;
                    }

                    default:
                    {
                        // unexpected token, skip!
                        reader.Skip();
                        break;
                    }
                    }
                }

                throw new ArgumentException("The reader did not deliver a closing 'EndObject'.");
            }
コード例 #3
0
            public Item_Index_Error Error;             // JSON field: 'error'

            /// <summary>
            /// Resets the item for re-use.
            /// </summary>
            public void Reset()
            {
                mIndexProxy   = new StringPropertyProxy(mPool);
                mTypeProxy    = new StringPropertyProxy(mPool);
                mIdProxy      = new StringPropertyProxy(mPool);
                mVersionProxy = default;
                mResultProxy  = new StringPropertyProxy(mPool);
                mPool.Return(Shards);
                Shards = null;
                mSequenceNumberProxy = default;
                mPrimaryTermProxy    = default;
                mStatusProxy         = default;
                mPool.Return(Error);
                Error = null;
            }
コード例 #4
0
            /// <summary>
            /// Initializes the current instance from a JSON document using the specified JSON reader.
            /// </summary>
            /// <param name="data">The UTF-8 encoded JSON document being deserialized.</param>
            /// <param name="reader">The JSON reader used during deserialization.</param>
            internal void InitFromJson(byte[] data, ref Utf8JsonReader reader)
            {
                Debug.Assert(reader.TokenType == JsonTokenType.StartObject);

                string propertyName = null;

                while (reader.Read())
                {
                    switch (reader.TokenType)
                    {
                    case JsonTokenType.PropertyName:
                    {
                        propertyName = mPool.GetStringFromUtf8(reader.ValueSpan);
                        break;
                    }

                    case JsonTokenType.String:
                    {
                        switch (propertyName)
                        {
                        case "_index":
                            mIndexProxy.Update(data, (int)reader.TokenStartIndex + 1, reader.ValueSpan.Length, true);
                            break;

                        case "_type":
                            mTypeProxy.Update(data, (int)reader.TokenStartIndex + 1, reader.ValueSpan.Length, true);
                            break;

                        case "_id":
                            // changes with every document, do not cache!
                            mIdProxy.Update(data, (int)reader.TokenStartIndex + 1, reader.ValueSpan.Length, false);
                            break;

                        case "result":
                            mResultProxy.Update(data, (int)reader.TokenStartIndex + 1, reader.ValueSpan.Length, true);
                            break;
                        }

                        break;
                    }

                    case JsonTokenType.Number:
                    {
                        switch (propertyName)
                        {
                        case "_version":
                            mVersionProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                            break;

                        case "_seq_no":
                            mSequenceNumberProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                            break;

                        case "_primary_term":
                            mPrimaryTermProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                            break;

                        case "status":
                            mStatusProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                            break;
                        }

                        break;
                    }

                    case JsonTokenType.StartObject:
                    {
                        switch (propertyName)
                        {
                        case "_shards":
                        {
                            var model = mPool.GetBulkResponseItemIndexShards();
                            model.InitFromJson(data, ref reader);
                            Shards = model;
                            break;
                        }

                        case "error":
                        {
                            var model = mPool.GetBulkResponseItemIndexError();
                            model.InitFromJson(data, ref reader);
                            Error = model;
                            break;
                        }

                        default:
                            // unexpected property, skip all children!
                            reader.Skip();
                            break;
                        }

                        break;
                    }

                    case JsonTokenType.EndObject:
                    {
                        return;
                    }

                    default:
                    {
                        // unexpected token, skip!
                        reader.Skip();
                        break;
                    }
                    }
                }

                throw new ArgumentException("The reader did not deliver a closing 'EndObject'.");
            }
            public int Total => mTotalProxy.Value;             // JSON field: 'total'

            /// <summary>
            /// Resets the item for re-use.
            /// </summary>
            public void Reset()
            {
                mFailedProxy     = default;
                mSuccessfulProxy = default;
                mTotalProxy      = default;
            }
コード例 #6
0
        /// <summary>
        /// Reads the response from specified UTF-8 JSON document and initializes the specified response.
        /// Called by <see cref="BulkResponsePool"/> to initialize the response.
        /// </summary>
        /// <param name="data">JSON document to read.</param>
        /// <returns>
        /// The created response.
        /// Call <see cref="ReturnToPool"/> to release it when you're done.
        /// </returns>
        internal void InitFromJson(byte[] data)
        {
            var    reader       = new Utf8JsonReader(data, sJsonReaderOptions);
            string propertyName = null;

            // skip the first curly brace that starts all json documents
            reader.Read();
            Debug.Assert(reader.TokenType == JsonTokenType.StartObject);

            while (reader.Read())
            {
                switch (reader.TokenType)
                {
                case JsonTokenType.PropertyName:
                {
                    propertyName = mPool.GetStringFromUtf8(reader.ValueSpan);
                    break;
                }

                case JsonTokenType.True:
                case JsonTokenType.False:
                {
                    switch (propertyName)
                    {
                    case "errors":
                        mErrorsProxy = new BooleanPropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                        break;
                    }

                    break;
                }

                case JsonTokenType.Number:
                {
                    switch (propertyName)
                    {
                    case "took":
                        mTookProxy = new Int32PropertyProxy(data, (int)reader.TokenStartIndex, reader.ValueSpan.Length);
                        break;
                    }

                    break;
                }

                case JsonTokenType.StartArray:
                {
                    switch (propertyName)
                    {
                    case "items":
                        Items = DeserializeItems(data, ref reader);
                        break;

                    default:
                        // unexpected property, skip all children!
                        reader.Skip();
                        break;
                    }

                    break;
                }

                case JsonTokenType.EndObject:
                {
                    return;
                }

                default:
                {
                    // unexpected token, skip!
                    reader.Skip();
                    break;
                }
                }
            }

            throw new ArgumentException("The reader did not deliver a closing 'EndObject'.");
        }