Skip to content

Commit

Permalink
Merge pull request #69 from charlesroddie/Trimming
Browse files Browse the repository at this point in the history
Trimming
  • Loading branch information
peteroupc authored Oct 20, 2023
2 parents 7fb7dca + 5038a94 commit 75d81ee
Show file tree
Hide file tree
Showing 38 changed files with 937 additions and 590 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
with:
submodules: 'recursive'
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0'
dotnet-version: '7.0'
- name: Test
run: |
dotnet add CBORTest package Microsoft.NET.Test.Sdk # Update is required for GitHubActionsTestLogger to print anything
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ jobs:
# queries: ./path/to/local/query, your-org/your-repo/queries@main

- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0'
dotnet-version: '7.0'
- name: Autobuild
uses: github/codeql-action/autobuild@v2

Expand Down
49 changes: 25 additions & 24 deletions CBOR.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CBORTest", "CBORTest\CBORTest.csproj", "{8FE63143-541E-448D-8337-A98D1FA51541}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Release|Any CPU.Build.0 = Release|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Release|Any CPU.Build.0 = Release|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FDBC18D9-2C43-41BF-A01B-7F87F9C1AEA2}
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B38659A7-A3DB-4CD1-8DFF-641B579E5092}.Release|Any CPU.Build.0 = Release|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44A061F7-B6A8-4FBD-993E-3746E8C42D6B}.Release|Any CPU.Build.0 = Release|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8FE63143-541E-448D-8337-A98D1FA51541}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {FDBC18D9-2C43-41BF-A01B-7F87F9C1AEA2}
SolutionGuid = {AE3EA107-473B-4E31-B14D-F901FE8F17B1}
EndGlobalSection
EndGlobal
36 changes: 24 additions & 12 deletions CBOR/CBOR.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk='Microsoft.NET.Sdk'>
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.0</TargetFrameworks>
<TargetFrameworks>netstandard1.0; net7.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>5.0-alpha1</Version>
<Owners>Peter Occil</Owners>
Expand Down Expand Up @@ -29,26 +29,38 @@ Note that after version 4.5x, the CBOR library's repository will stop including
<AssemblyOriginatorKeyFile>PeterO.snk</AssemblyOriginatorKeyFile>
<Title>CBOR (Concise Binary Object Representation)</Title>
<PackOnBuild>true</PackOnBuild>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet><PackageLicenseExpression>CC0-1.0</PackageLicenseExpression></PropertyGroup>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet><PackageLicenseExpression>CC0-1.0</PackageLicenseExpression>

<PropertyGroup Condition=' &apos;$(Configuration)&apos;==&apos;Debug&apos; '>
<IsTrimmable>true</IsTrimmable>
<LangVersion>11.0</LangVersion>
<PolySharpIncludeRuntimeSupportedAttributes>true</PolySharpIncludeRuntimeSupportedAttributes>
<DefineConstants>MULTI_TARGETING_SUPPORT_ATTRIBUTES</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)'=='Debug' ">
<DebugType>full</DebugType>
<DocumentationFile>bin\Debug\netstandard1.0\CBOR.xml</DocumentationFile>

<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup>
<PropertyGroup Condition=' &apos;$(Configuration)&apos;==&apos;Release&apos; '>
<PropertyGroup Condition=" '$(Configuration)'=='Release' ">
<DebugType>none</DebugType>
<DocumentationFile>bin\Release\netstandard1.0\CBOR.xml</DocumentationFile>

<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet></PropertyGroup>
<CodeAnalysisRuleSet>rules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>

<PackageReference Include='StyleCop.Analyzers' PrivateAssets='All' Version='1.2.0-beta.354'/>
<AdditionalFiles Include='stylecop.json'/>
<AdditionalFiles Include='rules.ruleset'/><PackageReference Include='PeterO.URIUtility' Version='1.0.0'/>
<PackageReference Include="PolySharp" Version="1.13.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.2.0-beta.354" />
<AdditionalFiles Include="stylecop.json" />
<AdditionalFiles Include="rules.ruleset" /><PackageReference Include="PeterO.URIUtility" Version="1.0.0" />

<PackageReference Include='PeterO.Numbers' Version='1.8.2'/>
<PackageReference Include="PeterO.Numbers" Version="1.8.2" />

<PackageReference Include='PeterO.DataUtilities' Version='1.1'/>
<PackageReference Include='Microsoft.CodeAnalysis.NetAnalyzers' PrivateAssets='All' Version='6.0.0'/></ItemGroup>
<PackageReference Include="PeterO.DataUtilities" Version="1.1" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" PrivateAssets="All" Version="7.0.3" /></ItemGroup>
</Project>
8 changes: 4 additions & 4 deletions CBOR/PeterO/Cbor/CBORDataUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,11 @@ internal static CBORObject ParseSmallNumberAsNegative(
8);
} else if (options != null && options.NumberConversion ==
JSONOptions.ConversionMode.Decimal128) {
return CBORObject.FromObject(EDecimal.FromInt32(-digit));
return CBORObject.FromEDecimal(EDecimal.FromInt32(-digit));
} else {
// NOTE: Assumes digit is greater than zero, so PreserveNegativeZeros is
// irrelevant
return CBORObject.FromObject(-digit);
return CBORObject.FromInt(-digit);
}
}

Expand All @@ -325,10 +325,10 @@ internal static CBORObject ParseSmallNumber(int digit, JSONOptions
8);
} else if (options != null && options.NumberConversion ==
JSONOptions.ConversionMode.Decimal128) {
return CBORObject.FromObject(EDecimal.FromInt32(digit));
return CBORObject.FromEDecimal(EDecimal.FromInt32(digit));
} else {
// NOTE: Assumes digit is nonnegative, so PreserveNegativeZeros is irrelevant
return CBORObject.FromObject(digit);
return CBORObject.FromInt(digit);
}
}

Expand Down
34 changes: 17 additions & 17 deletions CBOR/PeterO/Cbor/CBORDataUtilitiesByteArrayString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal static CBORObject ParseJSONNumber(
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble ||
kind == JSONOptions.ConversionMode.IntOrFloat) {
return CBORObject.FromObject(0);
return CBORObject.FromInt(0);
}
} else if (negativeExp) {
// underflow
Expand All @@ -170,7 +170,7 @@ internal static CBORObject ParseJSONNumber(
return !negative ? CBORObject.FromFloatingPointBits(0, 2) :
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble) {
return CBORObject.FromObject(0);
return CBORObject.FromInt(0);
}
} else {
// overflow
Expand All @@ -181,7 +181,7 @@ internal static CBORObject ParseJSONNumber(
negative ? DoubleNegInfinity : DoublePosInfinity,
8);
} else if (kind == JSONOptions.ConversionMode.Decimal128) {
return CBORObject.FromObject(negative ?
return CBORObject.FromEDecimal(negative ?
EDecimal.NegativeInfinity : EDecimal.PositiveInfinity);
}
}
Expand All @@ -203,15 +203,15 @@ internal static CBORObject ParseJSONNumber(
?
CBORObject.FromFloatingPointBits(EFloat.FromInt64(v).ToDoubleBits(), 8) :
kind == JSONOptions.ConversionMode.Decimal128 ?
CBORObject.FromObject(EDecimal.FromInt64(v)) : CBORObject.FromObject(v);
CBORObject.FromEDecimal(EDecimal.FromInt64(v)) : CBORObject.FromInt64(v);
}
}
if (kind == JSONOptions.ConversionMode.Full) {
if (!haveDecimalPoint && !haveExponent) {
EInteger ei = EInteger.FromSubstring(chars, initialOffset, endPos);
return (preserveNegativeZero && ei.IsZero && negative) ?
CBORObject.FromObject(EDecimal.NegativeZero) :
CBORObject.FromObject(ei);
CBORObject.FromEDecimal(EDecimal.NegativeZero) :
CBORObject.FromEInteger(ei);
}
if (!haveExponent && haveDecimalPoint) {
// No more than 18 digits plus one decimal point (which
Expand Down Expand Up @@ -243,12 +243,12 @@ internal static CBORObject ParseJSONNumber(
}
if (digitCount >= 0 && (!negative || lv != 0)) {
if (expo == 0) {
return CBORObject.FromObject(lv);
return CBORObject.FromInt64(lv);
} else {
var cbor = CBORObject.FromArrayBackedObject(
new CBORObject[] {
CBORObject.FromObject(expo),
CBORObject.FromObject(lv),
CBORObject.FromInt(expo),
CBORObject.FromInt64(lv),
});
return cbor.WithTag(4);
}
Expand All @@ -263,15 +263,15 @@ internal static CBORObject ParseJSONNumber(
if (ed.IsZero && negative) {
if (ed.Exponent.IsZero) {
return preserveNegativeZero ?
CBORObject.FromObject(EDecimal.NegativeZero) :
CBORObject.FromObject(0);
CBORObject.FromEDecimal(EDecimal.NegativeZero) :
CBORObject.FromInt(0);
} else {
return !preserveNegativeZero ?
CBORObject.FromObject(ed.Negate()) : CBORObject.FromObject(ed);
CBORObject.FromEDecimal(ed.Negate()) : CBORObject.FromEDecimal(ed);
}
} else {
return ed.Exponent.IsZero ? CBORObject.FromObject(ed.Mantissa) :
CBORObject.FromObject(ed);
return ed.Exponent.IsZero ? CBORObject.FromEInteger(ed.Mantissa) :
CBORObject.FromEDecimal(ed);
}
} else if (kind == JSONOptions.ConversionMode.Double) {
var ef = EFloat.FromString(
Expand All @@ -293,7 +293,7 @@ internal static CBORObject ParseJSONNumber(
if (!preserveNegativeZero && ed.IsNegative && ed.IsZero) {
ed = ed.Negate();
}
return CBORObject.FromObject(ed);
return CBORObject.FromEDecimal(ed);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble) {
var ef = EFloat.FromString(
chars,
Expand All @@ -303,7 +303,7 @@ internal static CBORObject ParseJSONNumber(
long lb = ef.ToDoubleBits();
return (!CBORUtilities.IsBeyondSafeRange(lb) &&
CBORUtilities.IsIntegerValue(lb)) ?
CBORObject.FromObject(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromInt64(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromFloatingPointBits(lb, 8);
} else if (kind == JSONOptions.ConversionMode.IntOrFloat) {
EContext ctx = EContext.Binary64.WithBlankFlags();
Expand All @@ -325,7 +325,7 @@ internal static CBORObject ParseJSONNumber(
// Exact conversion; treat as ConversionMode.IntToFloatFromDouble
return (!CBORUtilities.IsBeyondSafeRange(lb) &&
CBORUtilities.IsIntegerValue(lb)) ?
CBORObject.FromObject(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromInt64(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromFloatingPointBits(lb, 8);
}
} else {
Expand Down
34 changes: 17 additions & 17 deletions CBOR/PeterO/Cbor/CBORDataUtilitiesCharArrayString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ internal static CBORObject ParseJSONNumber(
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble ||
kind == JSONOptions.ConversionMode.IntOrFloat) {
return CBORObject.FromObject(0);
return CBORObject.FromInt(0);
}
} else if (negativeExp) {
// underflow
Expand All @@ -170,7 +170,7 @@ internal static CBORObject ParseJSONNumber(
return !negative ? CBORObject.FromFloatingPointBits(0, 2) :
CBORObject.FromFloatingPointBits(0x8000, 2);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble) {
return CBORObject.FromObject(0);
return CBORObject.FromInt(0);
}
} else {
// overflow
Expand All @@ -181,7 +181,7 @@ internal static CBORObject ParseJSONNumber(
negative ? DoubleNegInfinity : DoublePosInfinity,
8);
} else if (kind == JSONOptions.ConversionMode.Decimal128) {
return CBORObject.FromObject(negative ?
return CBORObject.FromEDecimal(negative ?
EDecimal.NegativeInfinity : EDecimal.PositiveInfinity);
}
}
Expand All @@ -203,15 +203,15 @@ internal static CBORObject ParseJSONNumber(
?
CBORObject.FromFloatingPointBits(EFloat.FromInt64(v).ToDoubleBits(), 8) :
kind == JSONOptions.ConversionMode.Decimal128 ?
CBORObject.FromObject(EDecimal.FromInt64(v)) : CBORObject.FromObject(v);
CBORObject.FromEDecimal(EDecimal.FromInt64(v)) : CBORObject.FromInt64(v);
}
}
if (kind == JSONOptions.ConversionMode.Full) {
if (!haveDecimalPoint && !haveExponent) {
EInteger ei = EInteger.FromSubstring(chars, initialOffset, endPos);
return (preserveNegativeZero && ei.IsZero && negative) ?
CBORObject.FromObject(EDecimal.NegativeZero) :
CBORObject.FromObject(ei);
CBORObject.FromEDecimal(EDecimal.NegativeZero) :
CBORObject.FromEInteger(ei);
}
if (!haveExponent && haveDecimalPoint) {
// No more than 18 digits plus one decimal point (which
Expand Down Expand Up @@ -243,12 +243,12 @@ internal static CBORObject ParseJSONNumber(
}
if (digitCount >= 0 && (!negative || lv != 0)) {
if (expo == 0) {
return CBORObject.FromObject(lv);
return CBORObject.FromInt64(lv);
} else {
var cbor = CBORObject.FromArrayBackedObject(
new CBORObject[] {
CBORObject.FromObject(expo),
CBORObject.FromObject(lv),
CBORObject.FromInt(expo),
CBORObject.FromInt64(lv),
});
return cbor.WithTag(4);
}
Expand All @@ -263,15 +263,15 @@ internal static CBORObject ParseJSONNumber(
if (ed.IsZero && negative) {
if (ed.Exponent.IsZero) {
return preserveNegativeZero ?
CBORObject.FromObject(EDecimal.NegativeZero) :
CBORObject.FromObject(0);
CBORObject.FromEDecimal(EDecimal.NegativeZero) :
CBORObject.FromInt(0);
} else {
return !preserveNegativeZero ?
CBORObject.FromObject(ed.Negate()) : CBORObject.FromObject(ed);
CBORObject.FromEDecimal(ed.Negate()) : CBORObject.FromEDecimal(ed);
}
} else {
return ed.Exponent.IsZero ? CBORObject.FromObject(ed.Mantissa) :
CBORObject.FromObject(ed);
return ed.Exponent.IsZero ? CBORObject.FromEInteger(ed.Mantissa) :
CBORObject.FromEDecimal(ed);
}
} else if (kind == JSONOptions.ConversionMode.Double) {
var ef = EFloat.FromString(
Expand All @@ -293,7 +293,7 @@ internal static CBORObject ParseJSONNumber(
if (!preserveNegativeZero && ed.IsNegative && ed.IsZero) {
ed = ed.Negate();
}
return CBORObject.FromObject(ed);
return CBORObject.FromEDecimal(ed);
} else if (kind == JSONOptions.ConversionMode.IntOrFloatFromDouble) {
var ef = EFloat.FromString(
chars,
Expand All @@ -303,7 +303,7 @@ internal static CBORObject ParseJSONNumber(
long lb = ef.ToDoubleBits();
return (!CBORUtilities.IsBeyondSafeRange(lb) &&
CBORUtilities.IsIntegerValue(lb)) ?
CBORObject.FromObject(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromInt64(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromFloatingPointBits(lb, 8);
} else if (kind == JSONOptions.ConversionMode.IntOrFloat) {
EContext ctx = EContext.Binary64.WithBlankFlags();
Expand All @@ -325,7 +325,7 @@ internal static CBORObject ParseJSONNumber(
// Exact conversion; treat as ConversionMode.IntToFloatFromDouble
return (!CBORUtilities.IsBeyondSafeRange(lb) &&
CBORUtilities.IsIntegerValue(lb)) ?
CBORObject.FromObject(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromInt64(CBORUtilities.GetIntegerValue(lb)) :
CBORObject.FromFloatingPointBits(lb, 8);
}
} else {
Expand Down
Loading

0 comments on commit 75d81ee

Please sign in to comment.