Skip to content

Commit

Permalink
Change return type to string for some AccessorGenerator.Simple methods
Browse files Browse the repository at this point in the history
  • Loading branch information
TSRBerry committed Dec 12, 2024
1 parent a8d5a03 commit 9633fd3
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions RyuSocks.Generator/Packet/AccessorGenerator.Simple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,49 @@ namespace RyuSocks.Generator.Packet
[SuppressMessage("ReSharper", "RedundantIfElseBlock")]
internal static partial class AccessorGenerator
{
private static string[] GenerateSimpleByteAccessor(PacketFieldModel packetField, bool isGetter)
private static string GenerateSimpleByteAccessor(PacketFieldModel packetField, bool isGetter)
{
if (isGetter)
{
string maybeCast = packetField.FieldType.IsEnum ? $"({packetField.FieldType.Name})" : string.Empty;

return [$"return {maybeCast}this[{packetField.GetOffset()}];"];
return $"return {maybeCast}this[{packetField.GetOffset()}];";
}
else
{
string maybeCastValue = packetField.FieldType.IsEnum ? "(byte)" : string.Empty;

return [$"this[{packetField.GetOffset()}] = {maybeCastValue}value;"];
return $"this[{packetField.GetOffset()}] = {maybeCastValue}value;";
}
}

private static string[] GenerateSimpleSByteAccessor(PacketFieldModel packetField, bool isGetter)
private static string GenerateSimpleSByteAccessor(PacketFieldModel packetField, bool isGetter)
{
if (isGetter)
{
string maybeCast = packetField.FieldType.IsEnum ? $"({packetField.FieldType.Name})" : string.Empty;

return [$"return {maybeCast}(sbyte)this[{packetField.GetOffset()}];"];
return $"return {maybeCast}(sbyte)this[{packetField.GetOffset()}];";
}
else
{
return [$"this[{packetField.GetOffset()}] = (byte)value;"];
return $"this[{packetField.GetOffset()}] = (byte)value;";
}
}

private static string[] GenerateSimpleIntegralAccessor(PacketFieldModel packetField, TypeConverterModel converter, bool isGetter)
private static string GenerateSimpleIntegralAccessor(PacketFieldModel packetField, TypeConverterModel converter, bool isGetter)
{
if (isGetter)
{
string maybeCast = packetField.FieldType.IsEnum ? $"({packetField.FieldType.Name})" : string.Empty;

return [$"return {maybeCast}{converter.GetReaderName(packetField.IsBigEndian)}(this.AsSpan({packetField.GetOffset()}, {converter.Length}));"];
return $"return {maybeCast}{converter.GetReaderName(packetField.IsBigEndian)}(this.AsSpan({packetField.GetOffset()}, {converter.Length}));";
}
else
{
string valueParameter = packetField.FieldType.IsEnum ? $"({packetField.FieldType.ActualType.ToTypeString()})value" : "value";

return [$"{converter.GetWriterName(packetField.IsBigEndian)}(this.AsSpan({packetField.GetOffset()}, {converter.Length}), {valueParameter});"];
return $"{converter.GetWriterName(packetField.IsBigEndian)}(this.AsSpan({packetField.GetOffset()}, {converter.Length}), {valueParameter});";
}
}

Expand Down Expand Up @@ -141,10 +141,10 @@ private static string[] GenerateSimpleAccessor(PacketFieldModel packetField, boo
switch (packetField.FieldType.ActualType)
{
case ActualType.Byte:
source.AppendBlock(GenerateSimpleByteAccessor(packetField, isGetter));
source.AppendLine(GenerateSimpleByteAccessor(packetField, isGetter));
break;
case ActualType.SByte:
source.AppendBlock(GenerateSimpleSByteAccessor(packetField, isGetter));
source.AppendLine(GenerateSimpleSByteAccessor(packetField, isGetter));
break;
case ActualType.Int16:
case ActualType.UInt16:
Expand All @@ -153,7 +153,7 @@ private static string[] GenerateSimpleAccessor(PacketFieldModel packetField, boo
case ActualType.Int64:
case ActualType.UInt64:
var converter = TypeConverter.Map[packetField.FieldType.ActualType];
source.AppendBlock(GenerateSimpleIntegralAccessor(packetField, converter, isGetter));
source.AppendLine(GenerateSimpleIntegralAccessor(packetField, converter, isGetter));
break;
case ActualType.NamedType:
// Only deal with strings here
Expand Down

0 comments on commit 9633fd3

Please # to comment.