Example #1
0
 /// <summary>Create a new subspace from a binary prefix</summary>
 /// <param name="prefix">Prefix of the new subspace</param>
 /// <param name="encoder">Encoder that will be used by this subspace</param>
 /// <param name="context">Context that controls the lifetime of this subspace</param>
 internal DynamicKeySubspace(Slice prefix, IDynamicKeyEncoder encoder, ISubspaceContext context)
     : base(prefix, context)
 {
     Contract.Requires(encoder != null);
     this.KeyEncoder = encoder;
     this.Partition  = new DynamicPartition(this);
 }
Example #2
0
 public FdbDynamicSubspacePartition([NotNull] IFdbDynamicSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoder, nameof(encoder));
     this.Subspace = subspace;
     this.Encoder  = encoder;
 }
Example #3
0
        /// <summary>Pack a tuple into a key, using the specified encoder</summary>
        public static Slice Pack <TTuple>(this IDynamicKeyEncoder encoder, TTuple tuple)
            where TTuple : IVarTuple
        {
            var writer = new SliceWriter(checked (tuple.Count * 8));

            encoder.PackKey(ref writer, tuple);
            return(writer.ToSlice());
        }
 public static IFdbDynamicSubspace CreateDynamic(Slice slice, [NotNull] IDynamicKeyEncoder encoder)
 {
     if (encoder == null)
     {
         throw new ArgumentNullException("encoder");
     }
     return(new FdbDynamicSubspace(slice, encoder));
 }
 /// <summary>Create a new subspace from a binary prefix</summary>
 /// <param name="prefix">Prefix of the new subspace</param>
 /// <param name="encoder">Encoder that will be used by this subspace</param>
 internal DynamicKeySubspace(Slice prefix, [NotNull] IDynamicKeyEncoder encoder)
     : base(prefix)
 {
     Contract.Requires(encoder != null);
     this.Encoding   = encoder.Encoding;
     this.KeyEncoder = encoder;
     this.Keys       = new DynamicKeys(this, encoder);
     this.Partition  = new DynamicPartition(this);
 }
 public static IFdbDynamicSubspace CreateDynamic <TKey>([NotNull] TKey key, IDynamicKeyEncoder encoder)
     where TKey : IFdbKey
 {
     if (key == null)
     {
         throw new ArgumentNullException("key");
     }
     if (encoder == null)
     {
         throw new ArgumentNullException("encoder");
     }
     return(new FdbDynamicSubspace(key.ToFoundationDbKey(), encoder));
 }
 public FdbDynamicSubspacePartition([NotNull] IFdbDynamicSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     if (subspace == null)
     {
         throw new ArgumentNullException("subspace");
     }
     if (encoder == null)
     {
         throw new ArgumentNullException("encoder");
     }
     this.Subspace = subspace;
     this.Encoder  = encoder;
 }
		internal FdbDirectorySubspace(IFdbTuple location, IFdbTuple relativeLocation, Slice prefix, FdbDirectoryLayer directoryLayer, Slice layer, IDynamicKeyEncoder encoder)
			: base(prefix, encoder)
		{
			Contract.Requires(location != null && relativeLocation != null && prefix != null && directoryLayer != null);
			if (layer.IsNull) layer = Slice.Empty;

			this.DirectoryLayer = directoryLayer;
			this.Location = location;
			this.RelativeLocation = relativeLocation;
			this.Layer = layer;
			this.Path = location.ToArray<string>();

			Contract.Ensures(this.DirectoryLayer != null && this.Location != null && this.RelativeLocation != null && this.Path != null);
			Contract.Ensures(this.RelativeLocation.Count <= this.Location.Count && this.Location.EndsWith(this.RelativeLocation));
		}
 /// <summary>Create a new subspace from a binary prefix</summary>
 /// <param name="rawPrefix">Prefix of the new subspace</param>
 /// <param name="copy">If true, take a copy of the prefix</param>
 /// <param name="encoder">Type System used to encode keys in this subspace (optional, will use Tuple Encoding by default)</param>
 internal FdbDynamicSubspace(Slice rawPrefix, bool copy, IDynamicKeyEncoder encoder)
     :  base(rawPrefix, copy)
 {
     this.m_encoder = encoder ?? TypeSystem.Default.GetDynamicEncoder();
 }
 public FdbDynamicSubspace(Slice rawPrefix, IDynamicKeyEncoder encoder)
     : this(rawPrefix, true, encoder)
 {
 }
Example #11
0
 public FdbDynamicSubspaceKeys([NotNull] IFdbSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.Requires(subspace != null && encoder != null);
     this.Subspace = subspace;
     this.Encoder  = encoder;
 }
Example #12
0
        private static                               T[] BatchDecode <T>(IEnumerable <Slice> packed, IFdbSubspace subspace, IDynamicKeyEncoder encoder, Func <Slice, IDynamicKeyEncoder, T> decode)
        {
            var coll = packed as ICollection <Slice>;

            if (coll != null)
            {
                var res = new T[coll.Count];
                int p   = 0;
                foreach (var data in packed)
                {
                    res[p++] = decode(subspace.ExtractKey(data), encoder);
                }
                Contract.Assert(p == res.Length);
                return(res);
            }
            else
            {
                var res = new List <T>();
                foreach (var data in packed)
                {
                    res.Add(decode(subspace.ExtractKey(data), encoder));
                }
                return(res.ToArray());
            }
        }
 public static DynamicKeySubspace CreateDynamic(Slice prefix, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(encoder, nameof(encoder));
     return(new DynamicKeySubspace(prefix, encoder));
 }
 public static IFdbDynamicSubspace CreateDynamic(Slice slice, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(encoder, nameof(encoder));
     return(new FdbDynamicSubspace(slice, encoder));
 }
 internal DynamicKeys(DynamicKeySubspace parent, IDynamicKeyEncoder encoder)
 {
     Contract.Requires(parent != null && encoder != null);
     this.Parent  = parent;
     this.Encoder = encoder;
 }
Example #16
0
        internal FdbDirectorySubspace(IFdbTuple location, IFdbTuple relativeLocation, Slice prefix, FdbDirectoryLayer directoryLayer, Slice layer, IDynamicKeyEncoder encoder)
            : base(prefix, encoder)
        {
            Contract.Requires(location != null && relativeLocation != null && prefix != null && directoryLayer != null);
            if (layer.IsNull)
            {
                layer = Slice.Empty;
            }

            this.DirectoryLayer   = directoryLayer;
            this.Location         = location;
            this.RelativeLocation = relativeLocation;
            this.Layer            = layer;
            this.Path             = location.ToArray <string>();

            Contract.Ensures(this.DirectoryLayer != null && this.Location != null && this.RelativeLocation != null && this.Path != null);
            Contract.Ensures(this.RelativeLocation.Count <= this.Location.Count && this.Location.EndsWith(this.RelativeLocation));
        }
Example #17
0
 public IFdbDynamicSubspace ByKey(T value, [NotNull] IDynamicKeyEncoder encoder)
 {
     return(FdbSubspace.CreateDynamic(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value)), encoder));
 }
 public static IDynamicKeySubspace UsingEncoder(this IKeySubspace subspace, IDynamicKeyEncoder encoder, ISubspaceContext?context = null)
 {
     Contract.NotNull(subspace);
     Contract.NotNull(encoder);
     return(new DynamicKeySubspace(subspace.GetPrefix(), encoder, context ?? subspace.Context));
 }
 internal FdbDirectoryPartition(FdbDirectoryLayer.DirectoryDescriptor descriptor, FdbDirectoryLayer.PartitionDescriptor parent, IDynamicKeyEncoder keyEncoder, ISubspaceContext?context)
     : base(descriptor, keyEncoder, context)
 {
     Contract.NotNull(parent, nameof(parent));
     this.Parent = parent;
 }
 public static IFdbDynamicSubspace CopyDynamic([NotNull] IFdbSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     if (encoder == null)
     {
         throw new ArgumentNullException("encoder");
     }
     return(new FdbDynamicSubspace(subspace.Key, true, encoder));
 }
Example #21
0
 /// <summary>Return a version of this subspace, which uses a different type system to produces the keys and values</summary>
 /// <param name="subspace">Instance of a generic subspace</param>
 /// <param name="encoder">Custom key encoder</param>
 /// <returns>Subspace equivalent to <paramref name="subspace"/>, but augmented with a specific TypeSystem</returns>
 public static IFdbDynamicSubspace UsingEncoder([NotNull] this IFdbSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     if (subspace == null)
     {
         throw new ArgumentNullException("subspace");
     }
     if (encoder == null)
     {
         throw new ArgumentNullException("encoder");
     }
     return(FdbSubspace.CopyDynamic(subspace, encoder));
 }
		public FdbDynamicSubspace(Slice rawPrefix, IDynamicKeyEncoder encoder)
			: this(rawPrefix, true, encoder)
		{ }
		/// <summary>Create a new subspace from a binary prefix</summary>
		/// <param name="rawPrefix">Prefix of the new subspace</param>
		/// <param name="copy">If true, take a copy of the prefix</param>
		/// <param name="encoder">Type System used to encode keys in this subspace (optional, will use Tuple Encoding by default)</param>
		internal FdbDynamicSubspace(Slice rawPrefix, bool copy, IDynamicKeyEncoder encoder)
			:  base (rawPrefix, copy)
		{
			this.m_encoder = encoder ?? TypeSystem.Default.GetDynamicEncoder();
		}
 /// <summary>Returns the same view but using a different Type System</summary>
 /// <param name="encoder">Type System that will code keys in this new view</param>
 /// <returns>Review that will partition this subspace using a different Type System</returns>
 /// <remarks>
 /// This should only be used for one-off usages where creating a new subspace just to encode one key would be overkill.
 /// If you are calling this in a loop, consider creating a new subspace using that encoder.
 /// </remarks>
 public FdbDynamicSubspacePartition UsingEncoder([NotNull] IDynamicKeyEncoder encoder)
 {
     return(new FdbDynamicSubspacePartition(this.Subspace, encoder));
 }
 public static IFdbDynamicSubspace CopyDynamic([NotNull] IFdbSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(encoder, nameof(encoder));
     return(new FdbDynamicSubspace(subspace.Key, true, encoder));
 }
 public static IDynamicKeySubspace CreateDynamic(Slice prefix, IDynamicKeyEncoder encoder, ISubspaceContext?context = null)
 {
     Contract.NotNull(encoder);
     return(new DynamicKeySubspace(prefix, encoder, context ?? SubspaceContext.Default));
 }
Example #27
0
 public IFdbDynamicSubspace ByKey(T1 value1, T2 value2, IDynamicKeyEncoder encoder)
 {
     return(FdbSubspace.CreateDynamic(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value1, value2)), encoder));
 }
Example #28
0
 public IFdbDynamicSubspace ByKey(T1 value1, T2 value2, T3 value3, T4 value4, [NotNull] IDynamicKeyEncoder encoder)
 {
     return(FdbSubspace.CreateDynamic(this.Subspace.ConcatKey(this.Encoder.EncodeKey(value1, value2, value3, value4)), encoder));
 }
 public static IDynamicKeySubspace UsingEncoder([NotNull] this IKeySubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoder, nameof(encoder));
     return(new DynamicKeySubspace(subspace.GetPrefix(), encoder.Encoding));
 }
 public static DynamicKeySubspace Copy(this IKeySubspace subspace, IDynamicKeyEncoder encoder, ISubspaceContext?context = null)
 {
     Contract.NotNull(subspace);
     Contract.NotNull(encoder);
     return(new DynamicKeySubspace(StealPrefix(subspace), encoder, context ?? subspace.Context));
 }
 public static DynamicKeySubspace Copy([NotNull] this IKeySubspace subspace, IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoder, nameof(encoder));
     return(new DynamicKeySubspace(StealPrefix(subspace), encoder));
 }
 internal FdbDirectorySubspace(FdbDirectoryLayer.DirectoryDescriptor descriptor, IDynamicKeyEncoder encoder, ISubspaceContext?context)
     : base(descriptor.Prefix, encoder, context ?? SubspaceContext.Default)
 {
     Contract.Requires(descriptor?.Partition != null);
     this.Descriptor = descriptor;
 }
Example #33
0
 public static IFdbDynamicSubspace UsingEncoder([NotNull] this IFdbSubspace subspace, [NotNull] IDynamicKeyEncoder encoder)
 {
     Contract.NotNull(subspace, nameof(subspace));
     Contract.NotNull(encoder, nameof(encoder));
     return(FdbSubspace.CopyDynamic(subspace, encoder));
 }