Skip to content

Commit 4d9a764

Browse files
committed
Added missing to bytes converters
Closes #42
1 parent c1d1b86 commit 4d9a764

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/LightningDB/Converters/DefaultConverters.cs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,41 @@ public class DefaultConverters
1414
public void RegisterDefault(LightningEnvironment environment)
1515
{
1616
var store = environment.ConverterStore;
17-
store.AddConvertToBytes<int>((db, x) => BitConverter.GetBytes(x));
18-
store.AddConvertToBytes<string>((db, x) => db.Encoding.GetBytes(x));
17+
18+
store.AddConvertToBytes<Guid>((db, x) => x.ToByteArray());
19+
store.AddConvertToBytes<Double>((db, x) => BitConverter.GetBytes(x));
20+
store.AddConvertToBytes<Single>((db, x) => BitConverter.GetBytes(x));
21+
store.AddConvertToBytes<Boolean>((db, x) => BitConverter.GetBytes(x));
22+
store.AddConvertToBytes<Int16>((db, x) => BitConverter.GetBytes(x));
23+
store.AddConvertToBytes<Int32>((db, x) => BitConverter.GetBytes(x));
24+
store.AddConvertToBytes<Int64>((db, x) => BitConverter.GetBytes(x));
25+
store.AddConvertToBytes<UInt16>((db, x) => BitConverter.GetBytes(x));
26+
store.AddConvertToBytes<UInt32>((db, x) => BitConverter.GetBytes(x));
27+
store.AddConvertToBytes<UInt64>((db, x) => BitConverter.GetBytes(x));
28+
store.AddConvertToBytes<Char>((db, x) => BitConverter.GetBytes(x));
29+
store.AddConvertToBytes<Byte>((db, x) => new [] { x });
30+
store.AddConvertToBytes<SByte>((db, x) => new[] { (byte) x });
31+
store.AddConvertToBytes<String>((db, x) => db.Encoding.GetBytes(x));
1932
store.AddConvertToBytes<byte[]>((db, x) => x);
2033

21-
convertFromBytesWithCorrectSize(store, (db, x) => new Guid(x), 16);
22-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToDouble(x, 0));
23-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToSingle(x, 0));
24-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToBoolean(x, 0));
25-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToInt16(x, 0));
26-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToInt32(x, 0));
27-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToInt64(x, 0));
28-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToUInt16(x, 0));
29-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToUInt32(x, 0));
30-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToUInt64(x, 0));
31-
convertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToChar(x, 0));
32-
convertFromBytesWithCorrectSize(store, (db, x) => x[0]);
33-
convertFromBytesWithCorrectSize(store, (db, x) => (SByte)x[0]);
34+
ConvertFromBytesWithCorrectSize(store, (db, x) => new Guid(x), 16);
35+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToDouble(x, 0));
36+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToSingle(x, 0));
37+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToBoolean(x, 0));
38+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToInt16(x, 0));
39+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToInt32(x, 0));
40+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToInt64(x, 0));
41+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToUInt16(x, 0));
42+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToUInt32(x, 0));
43+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToUInt64(x, 0));
44+
ConvertFromBytesWithCorrectSize(store, (db, x) => BitConverter.ToChar(x, 0));
45+
ConvertFromBytesWithCorrectSize(store, (db, x) => x[0]);
46+
ConvertFromBytesWithCorrectSize(store, (db, x) => (SByte)x[0]);
3447
store.AddConvertFromBytes((db, x) => db.Encoding.GetString(x));
48+
store.AddConvertFromBytes((db, x) => x);
3549
}
3650

37-
private void convertFromBytesWithCorrectSize<TTo>(ConverterStore store, Func<LightningDatabase, byte[], TTo> convert, int? size = null) where TTo : struct
51+
private void ConvertFromBytesWithCorrectSize<TTo>(ConverterStore store, Func<LightningDatabase, byte[], TTo> convert, int? size = null) where TTo : struct
3852
{
3953
var func = convert.EnsureCorrectSize(size);
4054
store.AddConvertFromBytes(func);

0 commit comments

Comments
 (0)