Ejemplo n.º 1
0
            public ByteStringContext.Scope GetSlice(ByteStringContext context, TableValueBuilder value,
                                                    out Slice slice)
            {
                if (Count == 1)
                {
                    return(value.SliceFromLocation(context, StartIndex, out slice));
                }

                int totalSize = value.SizeOf(StartIndex);

                for (int i = 1; i < Count; i++)
                {
                    totalSize += value.SizeOf(i + StartIndex);
                }
#if DEBUG
                if (totalSize < 0)
                {
                    throw new ArgumentOutOfRangeException(nameof(totalSize), "Size cannot be negative");
                }
#endif
                ByteString ret;
                var        scope = context.Allocate(totalSize, out ret);
                try
                {
                    var   ptr = ret.Ptr;
                    Slice val;
                    using (value.SliceFromLocation(context, StartIndex, out val))
                    {
                        val.CopyTo(ptr);
                        ptr += val.Size;
                    }
                    for (var i = 1; i < Count; i++)
                    {
                        using (value.SliceFromLocation(context, i + StartIndex, out val))
                        {
                            val.CopyTo(ptr);
                            ptr += val.Size;
                        }
                    }
                    slice = new Slice(ret);
                    return(scope);
                }
                catch (Exception)
                {
                    scope.Dispose();
                    throw;
                }
            }
Ejemplo n.º 2
0
 public long GetValue(ByteStringContext context, TableValueBuilder value)
 {
     using (value.SliceFromLocation(context, StartIndex, out Slice slice))
     {
         return(Bits.SwapBytes(*(long *)slice.Content.Ptr));
     }
 }
Ejemplo n.º 3
0
        public long Set(TableValueBuilder builder)
        {
            // The ids returned from this function MUST NOT be stored outside of the transaction.
            // These are merely for manipulation within the same transaction, and WILL CHANGE afterwards.
            long  id;
            Slice key;
            bool  exists;

            using (builder.SliceFromLocation(_tx.Allocator, _schema.Key.StartIndex, out key))
            {
                exists = TryFindIdFromPrimaryKey(key, out id);
            }

            if (exists)
            {
                id = Update(id, builder);
                return(id);
            }

            return(Insert(builder));
        }