Skip to content

Commit

Permalink
chore: Reformat and bump version to 0.6.0-alpha6
Browse files Browse the repository at this point in the history
  • Loading branch information
bojidar-bg committed Jan 18, 2021
1 parent 377230b commit 63e3865
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 96 deletions.
2 changes: 1 addition & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies {
}

application {
version = "0.6.0-alpha5"
version = "0.6.0-alpha6"
mainClass.set("com.obecto.perper.fabric.Main")
description = "Perper Fabric"
}
Expand Down
2 changes: 1 addition & 1 deletion fabric/src/main/kotlin/cache/CallData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class CallData(
var callerAgentDelegate: String,
var caller: String,
var finished: Boolean,
var localToData: Boolean
var localToData: Boolean,
)
2 changes: 1 addition & 1 deletion fabric/src/main/kotlin/cache/StreamListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ class StreamListener(
var stream: String,
var parameter: Int,
var filter: Map<String, Any?>,
var replay: Boolean,
var localToData: Boolean,
var replay: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ class StreamItemNotification(
var parameter: Int,
var cache: String,
var key: Long,
var ephemeral: Boolean
var ephemeral: Boolean,
) : Notification()
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private static void _addToFilter(Dictionary<string, object?> filter, Expression
throw new NotImplementedException("Support for comparing two fields is not implemented yet.");
if (fieldNameLeft == null && fieldNameRight == null)
throw new NotImplementedException("Expected a field/property on one side of the equality test.");
var fieldName = string.Join('.', (fieldNameLeft != null ? fieldNameLeft : fieldNameRight)!);
var fieldName = string.Join(".", (fieldNameLeft != null ? fieldNameLeft : fieldNameRight)!);
var fieldValue = fieldNameLeft != null ? _parseFieldValue(binary.Right) : _parseFieldValue(binary.Left);
filter.Add(fieldName, fieldValue);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
<LangVersion>8</LangVersion>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>0.6.0-alpha5</PackageVersion>
<PackageVersion>0.6.0-alpha6</PackageVersion>
<Authors>Obecto EOOD</Authors>
<RepositoryUrl>https://github.com/obecto/perper</RepositoryUrl>
<Title>Perper Functions</Title>
<Description>Azure Functions Extension for Perper</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/obecto/perper</PackageProjectUrl>
<RepositoryType>Git</RepositoryType>
<!-- <TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks> -->
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public FieldOrPropertyInfo(PropertyInfo property)
public object? GetValue(object obj) => Member switch { FieldInfo fi => fi.GetValue(obj), PropertyInfo pi => pi.GetValue(obj) };
public void SetValue(object obj, object? value)
{
switch(Member)
switch (Member)
{
case FieldInfo fi: fi.SetValue(obj, value); break;
case PropertyInfo pi: pi.SetValue(obj, value); break;
Expand Down Expand Up @@ -119,57 +119,57 @@ private TypeData GetTypeData(Type type)
case var primitive when PerperTypeUtils.IsPrimitiveType(value.GetType()): return primitive;

case Array arr:
{
var serialized = new object?[arr.Length];
for (var i = 0; i < arr.Length; i++)
{
serialized[i] = Serialize(arr.GetValue(i));
var serialized = new object?[arr.Length];
for (var i = 0; i < arr.Length; i++)
{
serialized[i] = Serialize(arr.GetValue(i));
}
return serialized;
}
return serialized;
}
case var tuple when PerperTypeUtils.IsTupleType(tuple.GetType()):
{
// Cannot use ITuple cast since it doesn't work in netstandard2
var typeData = GetTypeData(tuple.GetType());
var serialized = new object?[typeData.Properties.Count];
for (var i = 0; i < typeData.Properties.Count; i++)
{
var tupleElement = typeData.Properties[i].GetValue(tuple);
serialized[i] = Serialize(tupleElement);
// Cannot use ITuple cast since it doesn't work in netstandard2
var typeData = GetTypeData(tuple.GetType());
var serialized = new object?[typeData.Properties.Count];
for (var i = 0; i < typeData.Properties.Count; i++)
{
var tupleElement = typeData.Properties[i].GetValue(tuple);
serialized[i] = Serialize(tupleElement);
}
return serialized;
}
return serialized;
}
case IDictionary dictionary:
{
var serialized = new Hashtable();
foreach (DictionaryEntry? entry in dictionary)
{
serialized[Serialize(entry?.Key)!] = Serialize(entry?.Value);
var serialized = new Hashtable();
foreach (DictionaryEntry? entry in dictionary)
{
serialized[Serialize(entry?.Key)!] = Serialize(entry?.Value);
}
return serialized;
}
return serialized;
}
case ICollection collection:
{
var serialized = new ArrayList();
foreach (object? item in collection)
{
serialized.Add(Serialize(item));
var serialized = new ArrayList();
foreach (object? item in collection)
{
serialized.Add(Serialize(item));
}
return serialized;
}
return serialized;
}
case var anonymous when PerperTypeUtils.IsAnonymousType(value.GetType()):
{
var anonymousType = anonymous.GetType();
{
var anonymousType = anonymous.GetType();

var builder = _binary.GetBuilder(anonymousType.GUID.ToString());
var builder = _binary.GetBuilder(anonymousType.GUID.ToString());

foreach (var property in anonymousType.GetProperties())
{
builder.SetField(property.Name, property.GetValue(anonymous));
}
foreach (var property in anonymousType.GetProperties())
{
builder.SetField(property.Name, property.GetValue(anonymous));
}

return builder.Build();
}
return builder.Build();
}

case PerperDynamicObject dynamicObject: return dynamicObject.BinaryObject;

Expand All @@ -188,76 +188,76 @@ private TypeData GetTypeData(Type type)
case var primitive when PerperTypeUtils.IsPrimitiveType(serialized.GetType()) && serialized.GetType() == type: return primitive;

case Array arr when type.IsArray:
{
var elementType = type.GetElementType()!;
var value = Array.CreateInstance(elementType, arr.Length);
for (var i = 0; i < arr.Length; i++)
{
value.SetValue(Deserialize(arr.GetValue(i), elementType), i);
var elementType = type.GetElementType()!;
var value = Array.CreateInstance(elementType, arr.Length);
for (var i = 0; i < arr.Length; i++)
{
value.SetValue(Deserialize(arr.GetValue(i), elementType), i);
}
return value;
}
return value;
}

case Array arr when PerperTypeUtils.IsTupleType(type):
{
// Can potentitially rework this to use TypeData, similar to the code serializing tuples
var types = type.GetGenericArguments();
var parameters = new object?[types.Length];
for (var i = 0; i < types.Length && i < arr.Length; i++)
{
parameters[i] = Deserialize(arr.GetValue(i), types[i]);
// Can potentitially rework this to use TypeData, similar to the code serializing tuples
var types = type.GetGenericArguments();
var parameters = new object?[types.Length];
for (var i = 0; i < types.Length && i < arr.Length; i++)
{
parameters[i] = Deserialize(arr.GetValue(i), types[i]);
}
return Activator.CreateInstance(type, parameters);
}
return Activator.CreateInstance(type, parameters);
}

case IDictionary dictionary:
{
// NOTE: Can cache keyType, valueType, and finalType for type
var dictionaryTypes = PerperTypeUtils.GetGenericInterface(type, typeof(IDictionary<,>))?.GetGenericArguments() ?? new []{typeof(object), typeof(object)};
var keyType = dictionaryTypes[0];
var valueType = dictionaryTypes[1];
var finalType = type.IsInterface ? typeof(Dictionary<,>).MakeGenericType(keyType, valueType) : type;

var value = (IDictionary)Activator.CreateInstance(finalType)!;
foreach (DictionaryEntry? entry in dictionary)
{
value[Deserialize(entry?.Key, keyType)!] = Deserialize(entry?.Value, valueType);
// NOTE: Can cache keyType, valueType, and finalType for type
var dictionaryTypes = PerperTypeUtils.GetGenericInterface(type, typeof(IDictionary<,>))?.GetGenericArguments() ?? new[] { typeof(object), typeof(object) };
var keyType = dictionaryTypes[0];
var valueType = dictionaryTypes[1];
var finalType = type.IsInterface ? typeof(Dictionary<,>).MakeGenericType(keyType, valueType) : type;

var value = (IDictionary)Activator.CreateInstance(finalType)!;
foreach (DictionaryEntry? entry in dictionary)
{
value[Deserialize(entry?.Key, keyType)!] = Deserialize(entry?.Value, valueType);
}
return value;
}
return value;
}

case ICollection collection:
{
// NOTE: Can cache elementType, finalType, and addMethod for type
var elementType = PerperTypeUtils.GetGenericInterface(type, typeof(ICollection<>))?.GetGenericArguments()?[0] ?? typeof(object);
var finalType = type.IsAssignableFrom(typeof(List<>).MakeGenericType(elementType)) ? typeof(List<>).MakeGenericType(elementType) : type;

var addMethod = finalType.GetMethod(nameof(ICollection<object>.Add))!;

var value = (ICollection) Activator.CreateInstance(finalType)!;
foreach (object? item in collection)
{
addMethod.Invoke(value, new object?[] { Deserialize(item, elementType) });
// NOTE: Can cache elementType, finalType, and addMethod for type
var elementType = PerperTypeUtils.GetGenericInterface(type, typeof(ICollection<>))?.GetGenericArguments()?[0] ?? typeof(object);
var finalType = type.IsAssignableFrom(typeof(List<>).MakeGenericType(elementType)) ? typeof(List<>).MakeGenericType(elementType) : type;

var addMethod = finalType.GetMethod(nameof(ICollection<object>.Add))!;

var value = (ICollection)Activator.CreateInstance(finalType)!;
foreach (object? item in collection)
{
addMethod.Invoke(value, new object?[] { Deserialize(item, elementType) });
}
return value;
}
return value;
}

case string stringValue when type == typeof(BigInteger):
return BigInteger.Parse(stringValue);

case IBinaryObject binaryObject:
{
if (type == typeof(PerperDynamicObject) || Guid.TryParse(binaryObject.GetBinaryType().TypeName, out var typeGuid))
{
return new PerperDynamicObject(binaryObject);
if (type == typeof(PerperDynamicObject) || Guid.TryParse(binaryObject.GetBinaryType().TypeName, out var typeGuid))
{
return new PerperDynamicObject(binaryObject);
}
else
{
// NOTE: Can cache deserializeMethod for type
var deserializeMethod = typeof(IBinaryObject).GetMethod(nameof(IBinaryObject.Deserialize))!.MakeGenericMethod(type);
return deserializeMethod.Invoke(binaryObject, new object[] { });
}
}
else
{
// NOTE: Can cache deserializeMethod for type
var deserializeMethod = typeof(IBinaryObject).GetMethod(nameof(IBinaryObject.Deserialize))!.MakeGenericMethod(type);
return deserializeMethod.Invoke(binaryObject, new object[] { });
}
}

default: return serialized;
}
Expand All @@ -284,7 +284,8 @@ public Dictionary<string, string> GetQueriableFields(Type type)
{
var name = property.Name;
var typeName = PerperTypeUtils.GetJavaTypeName(property.Type);
if (typeName != null) {
if (typeName != null)
{
result[name] = typeName;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static bool IsPrimitiveType(Type type)
while (type.IsArray)
{
type = type.GetElementType()!;
arrayNesting ++;
arrayNesting++;
}
if (!javaTypeNames.TryGetValue(type, out var result))
{
Expand Down

0 comments on commit 63e3865

Please sign in to comment.