Exemplo n.º 1
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;
            }
Exemplo n.º 2
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'.");
            }