Ejemplo n.º 1
0
            public void Validate(FixedSizeSchemaIndexDef actual)
            {
                if (actual == null)
                {
                    throw new ArgumentNullException(nameof(actual), "Expected an index but received null");
                }

                if (!SliceComparer.Equals(Name, actual.Name))
                {
                    throw new ArgumentException(
                              $"Expected index to have Name='{Name}', got Name='{actual.Name}' instead",
                              nameof(actual));
                }

                if (StartIndex != actual.StartIndex)
                {
                    throw new ArgumentException(
                              $"Expected index {Name} to have StartIndex='{StartIndex}', got StartIndex='{actual.StartIndex}' instead",
                              nameof(actual));
                }

                if (IsGlobal != actual.IsGlobal)
                {
                    throw new ArgumentException(
                              $"Expected index {Name} to have IsGlobal='{IsGlobal}', got IsGlobal='{actual.IsGlobal}' instead",
                              nameof(actual));
                }
            }
Ejemplo n.º 2
0
        public TableSchema DefineFixedSizeIndex(string name, FixedSizeSchemaIndexDef index)
        {
            index.NameAsSlice       = Slice.From(StorageEnvironment.LabelsContext, name, ByteStringType.Immutable);;
            _fixedSizeIndexes[name] = index;

            return(this);
        }
Ejemplo n.º 3
0
        public TableSchema DefineFixedSizeIndex(FixedSizeSchemaIndexDef index)
        {
            if (!index.Name.HasValue || SliceComparer.Equals(Slices.Empty, index.Name))
            {
                throw new ArgumentException("Fixed size index name must be non-empty", nameof(index));
            }

            _fixedSizeIndexes[index.Name] = index;

            return(this);
        }
Ejemplo n.º 4
0
        public static TableSchema ReadFrom(ByteStringContext context, byte *location, int size)
        {
            var input  = new TableValueReader(location, size);
            var schema = new TableSchema();

            // Since there might not be a primary key, we have a moving index to deserialize the schema
            int currentIndex = 0;

            int   currentSize;
            byte *currentPtr = input.Read(currentIndex++, out currentSize);

            bool hasPrimaryKey = Convert.ToBoolean(*currentPtr);

            if (hasPrimaryKey)
            {
                currentPtr = input.Read(currentIndex++, out currentSize);
                var pk = SchemaIndexDef.ReadFrom(context, currentPtr, currentSize);
                schema.DefineKey(pk);
            }

            // Read common schema indexes
            currentPtr = input.Read(currentIndex++, out currentSize);
            int indexCount = *(int *)currentPtr;

            while (indexCount > 0)
            {
                currentPtr = input.Read(currentIndex++, out currentSize);
                var indexSchemaDef = SchemaIndexDef.ReadFrom(context, currentPtr, currentSize);
                schema.DefineIndex(indexSchemaDef);

                indexCount--;
            }

            // Read fixed size schema indexes
            currentPtr = input.Read(currentIndex++, out currentSize);
            indexCount = *(int *)currentPtr;

            while (indexCount > 0)
            {
                currentPtr = input.Read(currentIndex++, out currentSize);
                var fixedIndexSchemaDef = FixedSizeSchemaIndexDef.ReadFrom(context, currentPtr, currentSize);
                schema.DefineFixedSizeIndex(fixedIndexSchemaDef);

                indexCount--;
            }

            return(schema);
        }
Ejemplo n.º 5
0
            public static FixedSizeSchemaIndexDef ReadFrom(ByteStringContext context, byte *location, int size)
            {
                var input  = new TableValueReader(location, size);
                var output = new FixedSizeSchemaIndexDef();

                int   currentSize;
                byte *currentPtr = input.Read(0, out currentSize);

                output.StartIndex = *(int *)currentPtr;

                currentPtr      = input.Read(1, out currentSize);
                output.IsGlobal = Convert.ToBoolean(*currentPtr);

                currentPtr = input.Read(2, out currentSize);
                Slice.From(context, currentPtr, currentSize, ByteStringType.Immutable, out output.Name);

                return(output);
            }
Ejemplo n.º 6
0
 public TableSchema CompressValues(FixedSizeSchemaIndexDef etagSource, bool compress)
 {
     _compressed = compress;
     CompressedEtagSourceIndex = etagSource ?? throw new ArgumentNullException(nameof(etagSource));
     return(this);
 }