// PRIVATE // READ INDEX //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: private static org.neo4j.storageengine.api.schema.StoreIndexDescriptor readIndexRule(long id, ByteBuffer source) throws org.neo4j.internal.kernel.api.exceptions.schema.MalformedSchemaRuleException private static StoreIndexDescriptor ReadIndexRule(long id, ByteBuffer source) { IndexProviderDescriptor indexProvider = ReadIndexProviderDescriptor(source); sbyte indexRuleType = source.get(); Optional <string> name; switch (indexRuleType) { case GENERAL_INDEX: { SchemaDescriptor schema = ReadSchema(source); name = ReadRuleName(source); return(IndexDescriptorFactory.forSchema(schema, name, indexProvider).withId(id)); } case UNIQUE_INDEX: { long owningConstraint = source.Long; SchemaDescriptor schema = ReadSchema(source); name = ReadRuleName(source); IndexDescriptor descriptor = IndexDescriptorFactory.uniqueForSchema(schema, name, indexProvider); return(owningConstraint == NO_OWNING_CONSTRAINT_YET?descriptor.WithId(id) : descriptor.WithIds(id, owningConstraint)); } default: throw new MalformedSchemaRuleException(format("Got unknown index rule type '%d'.", indexRuleType)); } }
/// <summary> /// Serialize the provided IndexRule onto the target buffer /// </summary> /// <param name="indexDescriptor"> the StoreIndexDescriptor to serialize </param> /// <exception cref="IllegalStateException"> if the StoreIndexDescriptor is of type unique, but the owning constrain has not been set </exception> public static sbyte[] Serialize(StoreIndexDescriptor indexDescriptor) { ByteBuffer target = ByteBuffer.allocate(LengthOf(indexDescriptor)); target.putInt(LEGACY_LABEL_OR_REL_TYPE_ID); target.put(INDEX_RULE); IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor(); UTF8.putEncodedStringInto(providerDescriptor.Key, target); UTF8.putEncodedStringInto(providerDescriptor.Version, target); switch (indexDescriptor.Type()) { case GENERAL: target.put(GENERAL_INDEX); break; case UNIQUE: target.put(UNIQUE_INDEX); // The owning constraint can be null. See IndexRule.getOwningConstraint() long?owningConstraint = indexDescriptor.OwningConstraint; target.putLong(owningConstraint == null ? NO_OWNING_CONSTRAINT_YET : owningConstraint); break; default: throw new System.NotSupportedException(format("Got unknown index descriptor type '%s'.", indexDescriptor.Type())); } indexDescriptor.Schema().processWith(new SchemaDescriptorSerializer(target)); UTF8.putEncodedStringInto(indexDescriptor.Name, target); return(target.array()); }
/// <summary> /// Compute the byte size needed to serialize the provided IndexRule using serialize. </summary> /// <param name="indexDescriptor"> the StoreIndexDescriptor </param> /// <returns> the byte size of StoreIndexDescriptor </returns> internal static int LengthOf(StoreIndexDescriptor indexDescriptor) { int length = 4; // legacy label or relType id length += 1; // schema rule type IndexProviderDescriptor providerDescriptor = indexDescriptor.ProviderDescriptor(); length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Key); length += UTF8.computeRequiredByteBufferSize(providerDescriptor.Version); length += 1; // index type if (indexDescriptor.Type() == IndexDescriptor.Type.UNIQUE) { length += 8; // owning constraint id } length += indexDescriptor.Schema().computeWith(schemaSizeComputer); length += UTF8.computeRequiredByteBufferSize(indexDescriptor.Name); return(length); }