Beispiel #1
0
            public long GetValue(ref TableValueReader value)
            {
                int totalSize;
                var ptr = value.Read(StartIndex, out totalSize);

                Debug.Assert(totalSize == sizeof(long), $"{totalSize} == sizeof(long) - {Name}");
                return(Bits.SwapBytes(*(long *)ptr));
            }
Beispiel #2
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);
            }
Beispiel #3
0
            public ByteStringContext.ExternalScope GetSlice(ByteStringContext context, ref TableValueReader value,
                                                            out Slice slice)
            {
                int totalSize;
                var ptr = value.Read(StartIndex, out totalSize);

#if DEBUG
                if (totalSize < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(totalSize), "Size cannot be negative");
                }
#endif
                for (var i = 1; i < Count; i++)
                {
                    int size;
                    value.Read(i + StartIndex, out size);
#if DEBUG
                    if (size < 0)
                    {
                        throw new ArgumentOutOfRangeException(nameof(size), "Size cannot be negative");
                    }
#endif
                    totalSize += size;
                }
#if DEBUG
                if (totalSize < 0 || totalSize > value.Size)
                {
                    throw new ArgumentOutOfRangeException(nameof(value), "Reading a slice that is longer than the value");
                }
                if (totalSize > ushort.MaxValue)
                {
                    throw new ArgumentOutOfRangeException(nameof(totalSize),
                                                          "Reading a slice that too big to be a slice");
                }
#endif
                return(Slice.External(context, ptr, (ushort)totalSize, out slice));
            }
Beispiel #4
0
            public static SchemaIndexDef ReadFrom(ByteStringContext context, byte *location, int size)
            {
                var input    = new TableValueReader(location, size);
                var indexDef = new SchemaIndexDef();

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

                indexDef.Type = (TableIndexType)(*(ulong *)currentPtr);

                currentPtr          = input.Read(1, out currentSize);
                indexDef.StartIndex = *(int *)currentPtr;

                currentPtr     = input.Read(2, out currentSize);
                indexDef.Count = *(int *)currentPtr;

                currentPtr        = input.Read(3, out currentSize);
                indexDef.IsGlobal = Convert.ToBoolean(*currentPtr);

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

                return(indexDef);
            }
Beispiel #5
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);
        }