Skip to content

Commit 24dc02f

Browse files
KrzysFRabdullin
authored andcommitted
Use TuPack.Encoding directly, instead of using TypeSystem.Tuples or Default
1 parent 06ce050 commit 24dc02f

File tree

9 files changed

+35
-26
lines changed

9 files changed

+35
-26
lines changed

FoundationDB.Client/FdbDatabase.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace FoundationDB.Client
3636
using System.Threading;
3737
using System.Threading.Tasks;
3838
using Doxense.Async;
39+
using Doxense.Collections.Tuples;
3940
using Doxense.Diagnostics.Contracts;
4041
using Doxense.Memory;
4142
using Doxense.Serialization.Encoders;
@@ -456,8 +457,8 @@ internal void ChangeRoot(IKeySubspace subspace, IFdbDirectory directory, bool re
456457
lock (this)//TODO: don't use this for locking
457458
{
458459
m_readOnly = readOnly;
459-
m_globalSpace = KeySubspace.Copy(subspace, TypeSystem.Tuples);
460-
m_globalSpaceCopy = KeySubspace.Copy(subspace, TypeSystem.Tuples); // keep another copy
460+
m_globalSpace = subspace.Copy(TuPack.Encoding);
461+
m_globalSpaceCopy = subspace.Copy(TuPack.Encoding); // keep another copy
461462
m_directory = directory == null ? null : new FdbDatabasePartition(this, directory);
462463
}
463464
}

FoundationDB.Client/Layers/Directories/FdbDirectoryLayer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,26 @@ internal FdbDirectoryLayer(IDynamicKeySubspace nodeSubspace, IDynamicKeySubspace
156156
/// <summary>Create an instance of a Directory Layer located under a specific prefix and path</summary>
157157
/// <param name="prefix">Prefix for the content. The nodes will be stored under <paramref name="prefix"/> + &lt;FE&gt;</param>
158158
/// <param name="path">Optional path, if the Directory Layer is not located at the root of the database.</param>
159-
/// <param name="encoding">Optional key encoding scheme. If not specified, will use the <see cref="TypeSystem.Tuples"/> type system by default.</param>
159+
/// <param name="encoding">Optional key encoding scheme. If not specified, will use the <see cref="TuPack"/> encoding by default.</param>
160160
[NotNull]
161161
public static FdbDirectoryLayer Create(Slice prefix, IEnumerable<string> path = null, IKeyEncoding encoding = null)
162162
{
163-
var subspace = KeySubspace.CreateDynamic(prefix, encoding ?? TypeSystem.Tuples);
163+
var subspace = KeySubspace.CreateDynamic(prefix, encoding ?? TuPack.Encoding);
164164
var location = path != null ? ParsePath(path) : STuple.Empty;
165165
return new FdbDirectoryLayer(subspace.Partition[FdbKey.Directory], subspace, location);
166166
}
167167

168168
/// <summary>Create an instance of a Directory Layer located under a specific subspace and path</summary>
169169
/// <param name="subspace">Subspace for the content. The nodes will be stored under <paramref name="subspace"/>.Key + &lt;FE&gt;</param>
170170
/// <param name="path">Optional path, if the Directory Layer is not located at the root of the database.</param>
171-
/// <param name="encoding">Optional key encoding scheme. If not specified, will use the <see cref="TypeSystem.Tuples"/> type system by default.</param>
171+
/// <param name="encoding">Optional key encoding scheme. If not specified, will use the <see cref="TuPack"/> encoding by default.</param>
172172
[NotNull]
173173
public static FdbDirectoryLayer Create(IKeySubspace subspace, IEnumerable<string> path = null, IKeyEncoding encoding = null)
174174
{
175175
if (subspace == null) throw new ArgumentNullException(nameof(subspace));
176176

177177
var location = path != null ? ParsePath(path) : STuple.Empty;
178-
var space = subspace.Using(encoding ?? TypeSystem.Tuples);
178+
var space = subspace.AsDynamic(encoding ?? TuPack.Encoding);
179179
return new FdbDirectoryLayer(space.Partition[FdbKey.Directory], space, location);
180180
}
181181

@@ -932,11 +932,11 @@ private FdbDirectorySubspace ContentsOfNode([NotNull] IKeySubspace node, [NotNul
932932
var prefix = this.NodeSubspace.Keys.Decode<Slice>(node.GetPrefix());
933933
if (layer == FdbDirectoryPartition.LayerId)
934934
{
935-
return new FdbDirectoryPartition(path, relativePath, prefix, this);
935+
return new FdbDirectoryPartition(path, relativePath, prefix, this, TuPack.Encoding);
936936
}
937937
else
938938
{
939-
return new FdbDirectorySubspace(path, relativePath, prefix, this, layer, TypeSystem.Default);
939+
return new FdbDirectorySubspace(path, relativePath, prefix, this, layer, TuPack.Encoding);
940940
}
941941
}
942942

FoundationDB.Client/Layers/Directories/FdbDirectoryPartition.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ namespace FoundationDB.Layers.Directories
3232
using Doxense.Collections.Tuples;
3333
using Doxense.Serialization.Encoders;
3434
using FoundationDB.Client;
35+
using JetBrains.Annotations;
3536

3637
public class FdbDirectoryPartition : FdbDirectorySubspace
3738
{
3839

3940
/// <summary>Returns a slice with the ASCII string "partition"</summary>
4041
public static Slice LayerId => Slice.FromString("partition");
4142

42-
internal FdbDirectoryPartition(ITuple location, ITuple relativeLocation, Slice prefix, FdbDirectoryLayer directoryLayer)
43-
: base(location, relativeLocation, prefix, new FdbDirectoryLayer(FromKey(prefix + FdbKey.Directory).Using(TypeSystem.Default), FromKey(prefix).Using(TypeSystem.Default), location), LayerId, TypeSystem.Default)
43+
internal FdbDirectoryPartition([NotNull] ITuple location, [NotNull] ITuple relativeLocation, Slice prefix, [NotNull] FdbDirectoryLayer directoryLayer, [NotNull] IKeyEncoding keyEncoding)
44+
: base(location, relativeLocation, prefix, new FdbDirectoryLayer(FromKey(prefix + FdbKey.Directory).AsDynamic(keyEncoding), FromKey(prefix).AsDynamic(keyEncoding), location), LayerId, keyEncoding)
4445
{
4546
this.ParentDirectoryLayer = directoryLayer;
4647
}

FoundationDB.Client/Layers/Directories/FdbDirectorySubspace.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace FoundationDB.Layers.Directories
4444
public class FdbDirectorySubspace : DynamicKeySubspace, IFdbDirectory
4545
{
4646

47-
internal FdbDirectorySubspace(ITuple location, ITuple relativeLocation, Slice prefix, FdbDirectoryLayer directoryLayer, Slice layer, IKeyEncoding encoding)
47+
internal FdbDirectorySubspace([NotNull] ITuple location, [NotNull] ITuple relativeLocation, Slice prefix, [NotNull] FdbDirectoryLayer directoryLayer, Slice layer, [NotNull] IKeyEncoding encoding)
4848
: base(prefix, encoding)
4949
{
5050
Contract.Requires(location != null && relativeLocation != null && prefix != null && directoryLayer != null);
@@ -153,7 +153,7 @@ public async Task<FdbDirectorySubspace> ChangeLayerAsync(IFdbTransaction trans,
153153
// set the layer to the new value
154154
await this.DirectoryLayer.ChangeLayerInternalAsync(trans, this.RelativeLocation, newLayer).ConfigureAwait(false);
155155
// and return the new version of the subspace
156-
return new FdbDirectorySubspace(this.Location, this.RelativeLocation, GetKeyPrefix(), this.DirectoryLayer, newLayer, TypeSystem.Default);
156+
return new FdbDirectorySubspace(this.Location, this.RelativeLocation, GetKeyPrefix(), this.DirectoryLayer, newLayer, this.Encoding);
157157
}
158158

159159
/// <summary>Opens a subdirectory with the given <paramref name="path"/>.

FoundationDB.Client/Shared/TypeSystem/Encoders/KeyValueEncoders.Tuples.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ internal class TupleEncoder<T> : IKeyEncoder<T>, IValueEncoder<T>
5050

5151
private TupleEncoder() { }
5252

53-
public IKeyEncoding Encoding => TypeSystem.Tuples;
53+
public IKeyEncoding Encoding => TuPack.Encoding;
5454

5555
public void WriteKeyTo(ref SliceWriter writer, T key)
5656
{
@@ -84,7 +84,7 @@ internal class TupleCompositeEncoder<T1, T2> : CompositeKeyEncoder<T1, T2>
8484

8585
private TupleCompositeEncoder() { }
8686

87-
public override IKeyEncoding Encoding => TypeSystem.Tuples;
87+
public override IKeyEncoding Encoding => TuPack.Encoding;
8888

8989
public override void WriteKeyPartsTo(ref SliceWriter writer, int count, ref (T1, T2) key)
9090
{
@@ -114,7 +114,7 @@ internal class TupleCompositeEncoder<T1, T2, T3> : CompositeKeyEncoder<T1, T2, T
114114

115115
private TupleCompositeEncoder() { }
116116

117-
public override IKeyEncoding Encoding => TypeSystem.Tuples;
117+
public override IKeyEncoding Encoding => TuPack.Encoding;
118118

119119
public override void WriteKeyPartsTo(ref SliceWriter writer, int count, ref (T1, T2, T3) key)
120120
{
@@ -146,7 +146,7 @@ internal class TupleCompositeEncoder<T1, T2, T3, T4> : CompositeKeyEncoder<T1, T
146146

147147
private TupleCompositeEncoder() { }
148148

149-
public override IKeyEncoding Encoding => TypeSystem.Tuples;
149+
public override IKeyEncoding Encoding => TuPack.Encoding;
150150

151151
public override void WriteKeyPartsTo(ref SliceWriter writer, int count, ref (T1, T2, T3, T4) key)
152152
{
@@ -180,7 +180,7 @@ internal class TupleCompositeEncoder<T1, T2, T3, T4, T5> : CompositeKeyEncoder<T
180180

181181
private TupleCompositeEncoder() { }
182182

183-
public override IKeyEncoding Encoding => TypeSystem.Tuples;
183+
public override IKeyEncoding Encoding => TuPack.Encoding;
184184

185185
public override void WriteKeyPartsTo(ref SliceWriter writer, int count, ref (T1, T2, T3, T4, T5) key)
186186
{
@@ -216,7 +216,7 @@ internal class TupleCompositeEncoder<T1, T2, T3, T4, T5, T6> : CompositeKeyEncod
216216

217217
private TupleCompositeEncoder() { }
218218

219-
public override IKeyEncoding Encoding => TypeSystem.Tuples;
219+
public override IKeyEncoding Encoding => TuPack.Encoding;
220220

221221
public override void WriteKeyPartsTo(ref SliceWriter writer, int count, ref (T1, T2, T3, T4, T5, T6) key)
222222
{

FoundationDB.Client/Subspaces/KeySubspace.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,16 @@ public static DynamicKeySubspace CreateDynamic(Slice prefix, [NotNull] IDynamicK
7474
/// <summary>Initializes a new subspace with the given binary <paramref name="prefix"/>, that uses a dynamic key <paramref name="encoding"/>.</summary>
7575
/// <returns>A subspace that can handle keys of any types and size.</returns>
7676
[Pure, NotNull]
77-
public static DynamicKeySubspace CreateDynamic(Slice prefix, [NotNull] IKeyEncoding encoding)
77+
public static DynamicKeySubspace CreateDynamic(Slice prefix, [CanBeNull] IKeyEncoding encoding = null)
7878
{
79-
Contract.NotNull(encoding, nameof(encoding));
80-
return new DynamicKeySubspace(prefix, encoding.GetDynamicEncoder());
79+
return new DynamicKeySubspace(prefix, (encoding ?? TuPack.Encoding).GetDynamicEncoder());
8180
}
8281

8382
/// <summary>Initializes a new subspace with the given binary <paramref name="prefix"/>, that uses a typed key <paramref name="encoding"/>.</summary>
8483
/// <returns>A subspace that can handle keys of type <typeparamref name="T1"/>.</returns>
8584
public static TypedKeySubspace<T1> CreateTyped<T1>(Slice prefix, [CanBeNull] IKeyEncoding encoding = null)
8685
{
87-
return new TypedKeySubspace<T1>(prefix, (encoding ?? TypeSystem.Tuples).GetEncoder<T1>());
86+
return new TypedKeySubspace<T1>(prefix, (encoding ?? TuPack.Encoding).GetEncoder<T1>());
8887
}
8988

9089
/// <summary>Initializes a new subspace with the given binary <paramref name="prefix"/>, that uses a typed key <paramref name="encoder"/>.</summary>
@@ -99,7 +98,7 @@ public static TypedKeySubspace<T1> CreateTyped<T1>(Slice prefix, [NotNull] IKeyE
9998
/// <returns>A subspace that can handle composite keys of type (<typeparamref name="T1"/>, <typeparamref name="T2"/>).</returns>
10099
public static TypedKeySubspace<T1, T2> CreateTyped<T1, T2>(Slice prefix, [CanBeNull] IKeyEncoding encoding = null)
101100
{
102-
return new TypedKeySubspace<T1, T2>(prefix, (encoding ?? TypeSystem.Tuples).GetEncoder<T1, T2>());
101+
return new TypedKeySubspace<T1, T2>(prefix, (encoding ?? TuPack.Encoding).GetEncoder<T1, T2>());
103102
}
104103

105104
/// <summary>Initializes a new subspace with the given binary <paramref name="prefix"/>, that uses a typed key <paramref name="encoder"/>.</summary>
@@ -114,7 +113,7 @@ public static TypedKeySubspace<T1, T2> CreateTyped<T1, T2>(Slice prefix, [NotNul
114113
/// <returns>A subspace that can handle composite keys of type (<typeparamref name="T1"/>, <typeparamref name="T2"/>, <typeparamref name="T3"/>).</returns>
115114
public static TypedKeySubspace<T1, T2, T3> CreateTyped<T1, T2, T3>(Slice prefix, [CanBeNull] IKeyEncoding encoding = null)
116115
{
117-
return new TypedKeySubspace<T1, T2, T3>(prefix, (encoding ?? TypeSystem.Tuples).GetEncoder<T1, T2, T3>());
116+
return new TypedKeySubspace<T1, T2, T3>(prefix, (encoding ?? TuPack.Encoding).GetEncoder<T1, T2, T3>());
118117
}
119118

120119
/// <summary>Initializes a new subspace with the given binary <paramref name="prefix"/>, that uses a typed key <paramref name="encoder"/>.</summary>
@@ -129,7 +128,7 @@ public static TypedKeySubspace<T1, T2, T3> CreateTyped<T1, T2, T3>(Slice prefix,
129128
/// <returns>A subspace that can handle composite keys of type (<typeparamref name="T1"/>, <typeparamref name="T2"/>, <typeparamref name="T3"/>).</returns>
130129
public static TypedKeySubspace<T1, T2, T3, T4> CreateTyped<T1, T2, T3, T4>(Slice prefix, [CanBeNull] IKeyEncoding encoding = null)
131130
{
132-
return new TypedKeySubspace<T1, T2, T3, T4>(prefix, (encoding ?? TypeSystem.Tuples).GetEncoder<T1, T2, T3, T4>());
131+
return new TypedKeySubspace<T1, T2, T3, T4>(prefix, (encoding ?? TuPack.Encoding).GetEncoder<T1, T2, T3, T4>());
133132
}
134133

135134
/// <summary>Initializes a new subspace with the given binary <paramref name="prefix"/>, that uses a typed key <paramref name="encoder"/>.</summary>

FoundationDB.Client/Tuples/Encoding/TupleKeyEncoder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public sealed class TupleKeyEncoder : IDynamicKeyEncoder
4343
private TupleKeyEncoder()
4444
{ }
4545

46-
public IKeyEncoding Encoding => TypeSystem.Tuples;
46+
public IKeyEncoding Encoding => TuPack.Encoding;
4747

4848
public void PackKey<TTuple>(ref SliceWriter writer, TTuple items)
4949
where TTuple : ITuple

FoundationDB.Client/Tuples/Encoding/TupleKeyEncoding.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ namespace Doxense.Collections.Tuples.Encoding
3434
/// <summary>Encoding that uses the Tuple Binary Encoding format</summary>
3535
public sealed class TupleKeyEncoding : IKeyEncoding
3636
{
37+
38+
public static readonly TupleKeyEncoding Instance = new TupleKeyEncoding();
39+
3740
public IDynamicKeyEncoder GetDynamicEncoder()
3841
{
3942
return TupleKeyEncoder.Instance;

FoundationDB.Client/Tuples/TuPack.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace Doxense.Collections.Tuples
3434
using Doxense.Diagnostics.Contracts;
3535
using Doxense.Collections.Tuples.Encoding;
3636
using Doxense.Memory;
37+
using Doxense.Serialization.Encoders;
3738
using FoundationDB.Client;
3839
using JetBrains.Annotations;
3940

@@ -42,6 +43,10 @@ namespace Doxense.Collections.Tuples
4243
public static class TuPack
4344
{
4445

46+
/// <summary>Key Encoding that use the Tuple Binary Encoding</summary>
47+
[NotNull]
48+
public static IKeyEncoding Encoding => TupleKeyEncoding.Instance;
49+
4550
#region Packing...
4651

4752
// Without prefix

0 commit comments

Comments
 (0)