Skip to content

Commit

Permalink
edit release notes; code fix; etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Dec 14, 2023
1 parent e3e1f15 commit 76f39de
Show file tree
Hide file tree
Showing 16 changed files with 123 additions and 710 deletions.
10 changes: 8 additions & 2 deletions CBOR/CBOR.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
<PropertyGroup>
<TargetFrameworks>netstandard1.0; net6.0</TargetFrameworks>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Version>5.0-alpha1</Version>
<Version>5.0.0-alpha1</Version>
<Owners>Peter Occil</Owners>
<Description>A C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.</Description>
<Summary>A C# implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949. </Summary>
<Copyright>2021. Written by Peter O. Any copyright to this work is released to the Public Domain. In case this is not possible, this work is also licensed under Creative Commons Zero (CC0).</Copyright>
<Copyright>Written by Peter O. Any copyright to this work is released to the Public Domain. In case this is not possible, this work is also licensed under Creative Commons Zero (CC0).</Copyright>
<Authors>Peter Occil</Authors>
<PackageId>PeterO.Cbor</PackageId>
<PackageLicenseExpression>CC0-1.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/peteroupc/CBOR</PackageProjectUrl>
<PackageReleaseNotes>
Version 5.0:

- Alpha version
- Some deprecated features from earlier versions were obsoleted.
- Attempt to make the library trimmable by making use of reflection optional.

Version 4.5:

- Add support for JSON Pointers and JSON Patches
Expand Down
2 changes: 1 addition & 1 deletion CBOR/PeterO/Cbor/CBORDoubleBits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public long AsInt64(object obj) {
return 0;
}
if (neg && b == (0x43eL << 52)) {
return long.MinValue;
return Int64.MinValue;
}
if ((b >> 52) >= 0x43e) {
throw new OverflowException("This object's value is out of range");
Expand Down
12 changes: 6 additions & 6 deletions CBOR/PeterO/Cbor/CBORInteger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class CBORInteger : ICBORNumber
{
public object Abs(object obj) {
var val = (long)obj;
return (val == int.MinValue) ? (EInteger.One << 63) : ((val < 0) ?
return (val == Int32.MinValue) ? (EInteger.One << 63) : ((val < 0) ?
-val : obj);
}

Expand Down Expand Up @@ -54,7 +54,7 @@ public float AsSingle(object obj) {

public bool CanFitInDouble(object obj) {
var intItem = (long)obj;
if (intItem == long.MinValue) {
if (intItem == Int64.MinValue) {
return true;
}
intItem = (intItem < 0) ? -intItem : intItem;
Expand All @@ -66,7 +66,7 @@ public bool CanFitInDouble(object obj) {

public bool CanFitInInt32(object obj) {
var val = (long)obj;
return val >= int.MinValue && val <= int.MaxValue;
return val >= Int32.MinValue && val <= Int32.MaxValue;
}

public bool CanFitInInt64(object obj) {
Expand All @@ -75,7 +75,7 @@ public bool CanFitInInt64(object obj) {

public bool CanFitInSingle(object obj) {
var intItem = (long)obj;
if (intItem == long.MinValue) {
if (intItem == Int64.MinValue) {
return true;
}
intItem = (intItem < 0) ? -intItem : intItem;
Expand All @@ -87,7 +87,7 @@ public bool CanFitInSingle(object obj) {

public bool CanTruncatedIntFitInInt32(object obj) {
var val = (long)obj;
return val >= int.MinValue && val <= int.MaxValue;
return val >= Int32.MinValue && val <= Int32.MaxValue;
}

public bool CanTruncatedIntFitInUInt64(object obj) {
Expand Down Expand Up @@ -133,7 +133,7 @@ public bool IsNumberZero(object obj) {
}

public object Negate(object obj) {
return (((long)obj) == long.MinValue) ? (EInteger.One << 63) :
return (((long)obj) == Int64.MinValue) ? (EInteger.One << 63) :
(-(long)obj);
}

Expand Down
1 change: 0 additions & 1 deletion CBOR/PeterO/Cbor/CBORUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,6 @@ public static int DoubleToHalfPrecisionIfSameValue(long bits) {
return ((mant & ((1L << 42) - 1)) == 0) ? (sign | 0x7c00 | newmant) :
-1;
} else if (exp == 0 && mant == 0) { // positive or negative zero
always fits in half precision
return sign;
} else if (sexp >= 31) { // overflow
return -1;
Expand Down
2 changes: 1 addition & 1 deletion CBOR/PeterO/Cbor/SharedRefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public CBORObject GetObject(long smallIndex) {
if (smallIndex < 0) {
throw new CBORException("Unexpected index");
}
if (smallIndex > int.MaxValue) {
if (smallIndex > Int32.MaxValue) {

Check failure on line 28 in CBOR/PeterO/Cbor/SharedRefs.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'Int32' does not exist in the current context

Check failure on line 28 in CBOR/PeterO/Cbor/SharedRefs.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'Int32' does not exist in the current context

Check failure on line 28 in CBOR/PeterO/Cbor/SharedRefs.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'Int32' does not exist in the current context

Check failure on line 28 in CBOR/PeterO/Cbor/SharedRefs.cs

View workflow job for this annotation

GitHub Actions / Analyze (csharp)

The name 'Int32' does not exist in the current context

Check failure on line 28 in CBOR/PeterO/Cbor/SharedRefs.cs

View workflow job for this annotation

GitHub Actions / Core (ubuntu-latest)

The name 'Int32' does not exist in the current context
throw new CBORException("Index " + smallIndex +
" is bigger than supported ");
}
Expand Down
23 changes: 20 additions & 3 deletions CBOR/docs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3353,8 +3353,7 @@

</doc>
<doc name="M:PeterO.Cbor.CBORObject.FromFloat(System.Single)">

<summary>Generates a CBOR object from a 32-bit floating-point
<summary>Generates a CBOR object from a 32-bit floating-point
number. The input value can be a not-a-number (NaN) value (such as
<c>Single.NaN</c> in DotNet or Float.NaN in Java); however, NaN
values have multiple forms that are equivalent for many
Expand All @@ -3369,7 +3368,6 @@
<param name='value'>The parameter <paramref name='value'/> is a
32-bit floating-point number.</param>
<returns>A CBOR object generated from the given number.</returns>

</doc>
<doc name="M:PeterO.Cbor.CBORObject.FromFloatingPointBits(System.Int64,System.Int32)">

Expand Down Expand Up @@ -4178,6 +4176,25 @@
<exception cref='ArgumentException'>The parameter <paramref name='simpleValue'/> is less than 0, greater than 255, or from 24
through 31.</exception>

</doc>
<doc name="M:PeterO.Cbor.CBORObject.FromSingle(System.Single)">

<summary>Generates a CBOR object from a 32-bit floating-point
number. The input value can be a not-a-number (NaN) value (such as
<c>Single.NaN</c> in DotNet or Float.NaN in Java); however, NaN
values have multiple forms that are equivalent for many
applications' purposes, and <c>Single.NaN</c> / <c>Float.NaN</c> is
only one of these equivalent forms. In fact,
<c>CBORObject.FromSingle(Single.NaN)</c> or
<c>CBORObject.FromSingle(Float.NaN)</c> could produce a
CBOR-encoded object that differs between DotNet and Java, because
<c>Single.NaN</c> / <c>Float.NaN</c> may have a different form in
DotNet and Java (for example, the NaN value's sign may be negative
in DotNet, but positive in Java).</summary>
<param name='value'>The parameter <paramref name='value'/> is a
32-bit floating-point number.</param>
<returns>A CBOR object generated from the given number.</returns>

</doc>
<doc name="M:PeterO.Cbor.CBORObject.FromString(System.String)">

Expand Down
8 changes: 4 additions & 4 deletions CBORTest/BEncodingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ public static void DoTestString(string value) {
public void TestLong() {
DoTestLong(0);
DoTestLong(-1);
DoTestLong(int.MinValue);
DoTestLong(int.MaxValue);
DoTestLong(long.MinValue);
DoTestLong(long.MaxValue);
DoTestLong(Int32.MinValue);
DoTestLong(Int32.MaxValue);
DoTestLong(Int64.MinValue);
DoTestLong(Int64.MaxValue);
}

[Test]
Expand Down
10 changes: 6 additions & 4 deletions CBORTest/CBORNumberTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,14 @@ public void TestEncodingZeros() {
ToObjectTest.TestToFromObjectRoundTrip(-0.0);
ToObjectTest.TestToFromObjectRoundTrip(-0.0f);

TestCommon.CompareTestEqual(ToCN(0.0),
CBORObject.FromDouble(-0.0).AsNumber().Negate());
TestCommon.CompareTestEqual(
ToCN(0.0),
CBORObject.FromDouble(-0.0).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(-0.0),
CBORObject.FromDouble(0.0).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(0.0f),
CBORObject.FromSingle(-0.0f).AsNumber().Negate());
TestCommon.CompareTestEqual(
ToCN(0.0f),
CBORObject.FromSingle(-0.0f).AsNumber().Negate());
TestCommon.CompareTestEqual(ToCN(-0.0f),
CBORObject.FromSingle(0.0f).AsNumber().Negate());

Expand Down
14 changes: 7 additions & 7 deletions CBORTest/RandomGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public int NegativeBinomial(int trials, double p) {
return 0;
}
if (p == 0.0) {
return int.MaxValue;
return Int32.MaxValue;
}
var count = 0;
if (p == 0.5) {
Expand Down Expand Up @@ -410,7 +410,7 @@ public int UniformInt(int minInclusive, int maxExclusive) {
return minInclusive + this.UniformInt(maxExclusive - minInclusive);
} else {
long diff = maxExclusive - minInclusive;
return diff <= int.MaxValue ? minInclusive +
return diff <= Int32.MaxValue ? minInclusive +
this.UniformInt((int)diff) : (int)(minInclusive + this.UniformLong(diff));
}
}
Expand All @@ -433,9 +433,9 @@ public long UniformLong(long minInclusive, long maxExclusive) {
if (minInclusive >= 0) {
return minInclusive + this.UniformLong(maxExclusive - minInclusive);
} else {
if ((maxExclusive < 0 && long.MaxValue + maxExclusive <
if ((maxExclusive < 0 && Int64.MaxValue + maxExclusive <
minInclusive) ||
(maxExclusive > 0 && long.MinValue + maxExclusive > minInclusive) ||
(maxExclusive > 0 && Int64.MinValue + maxExclusive > minInclusive) ||
minInclusive - maxExclusive < 0) {
var b = new byte[8];
while (true) {
Expand Down Expand Up @@ -502,7 +502,7 @@ public int UniformInt(int maxExclusive) {
return ib;
}
int maxexc;
maxexc = int.MaxValue / maxExclusive * maxExclusive;
maxexc = Int32.MaxValue / maxExclusive * maxExclusive;
while (true) {
_ = this.valueIrg.GetBytes(b, 0, 4);
ib = b[0] & 0xff;
Expand Down Expand Up @@ -542,7 +542,7 @@ public long UniformLong(long maxExclusive) {
throw new ArgumentException("maxExclusive(" + maxExclusive +
") is less than 0");
}
if (maxExclusive <= int.MaxValue) {
if (maxExclusive <= Int32.MaxValue) {
return this.UniformInt((int)maxExclusive);
}
if (this.valueIrg is IRandomGenExtended rge) {
Expand All @@ -551,7 +551,7 @@ public long UniformLong(long maxExclusive) {

long maxexc;
var b = new byte[8];
maxexc = long.MaxValue / maxExclusive * maxExclusive;
maxexc = Int64.MaxValue / maxExclusive * maxExclusive;
while (true) {
_ = this.valueIrg.GetBytes(b, 0, 8);
long lb = b[0] & 0xffL;
Expand Down
6 changes: 3 additions & 3 deletions CBORTest/RandomObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static long RandomInt64(IRandomGenExtended rand) {
}

public static double RandomDouble(IRandomGenExtended rand, int exponent) {
if (exponent == int.MaxValue) {
if (exponent == Int32.MaxValue) {
if (rand == null) {
throw new ArgumentNullException(nameof(rand));
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public static float RandomSingle(IRandomGenExtended rand) {
}

public static float RandomSingle(IRandomGenExtended rand, int exponent) {
if (exponent == int.MaxValue) {
if (exponent == Int32.MaxValue) {
if (rand == null) {
throw new ArgumentNullException(nameof(rand));
}
Expand Down Expand Up @@ -586,7 +586,7 @@ public static string RandomDecimalString(
}
}
var bufferSize = (int)Math.Min(
int.MaxValue,
Int32.MaxValue,
8 + count + afterPointCount + exponentCount);
var sb = new StringBuilder(bufferSize);
if (r.GetInt32(2) == 0) {
Expand Down
22 changes: 22 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,28 @@
Release notes
---------------------

### Version 4.5.3

- More bug fixes, including a fix to a problem that can occur when reading from compressed or network streams

### Version 4.5.2

- Bug and regression fixes

### Version 4.5.1

- Fix reported security issue

### Version 4.5:

- Add support for JSON Pointers and JSON Patches
- Add option to keep map key order when decoding CBOR and JSON
- Add option to write JSON using only ASCII characters
- CBORObject.ToString renders strings as ASCII
- Add support for deserializing CBOR objects to IReadOnlyList, IReadOnlyCollection, and ReadOnlyDictionary

Note that after version 4.5x, the CBOR library's repository will stop including special projects for .NET 2.0 and .NET 4.0, leaving the .NET-Standard project for building the library.

### Version 4.4.2

- Performance improvements in some cases, especially involving date/time conversions
Expand Down
2 changes: 2 additions & 0 deletions docs/APIDocs.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@
* [PeterO.Cbor.JSONOptions.ConversionMode](PeterO.Cbor.JSONOptions.ConversionMode.md) - Specifies how JSON numbers are converted to CBOR objects when decoding JSON (such as via FromJSONString or ReadJSON ).

* [PeterO.Cbor.PODOptions](PeterO.Cbor.PODOptions.md) - Options for controlling how certain DotNET or Java objects, such as so-called "plain old data" objects (better known as POCOs in DotNET or POJOs in Java), are converted to CBOR objects.

* [PeterO.DataUtilities](PeterO.DataUtilities.md) -
2 changes: 2 additions & 0 deletions docs/PeterO.Cbor.CBORDataUtilities.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Contains methods useful for reading and writing data, with a focus on CBOR.
* <code>[ParseJSONNumber(char[], int, int, PeterO.Cbor.JSONOptions)](#ParseJSONNumber_char_int_int_PeterO_Cbor_JSONOptions)</code> - Parses a number from a sequence of char s whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
* <code>[ParseJSONNumber(char[], PeterO.Cbor.JSONOptions)](#ParseJSONNumber_char_PeterO_Cbor_JSONOptions)</code> - Parses a number from a sequence of char s whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
* <code>[ParseJSONNumber(string)](#ParseJSONNumber_string)</code> - Parses a number whose format follows the JSON specification.
* <code>[ParseJSONNumber(string, bool, bool)](#ParseJSONNumber_string_bool_bool)</code> - <b>Deprecated:</b> Call the one-argument version of this method instead. If this method call used positiveOnly = true, check that the string does not begin with '-' before calling that version. If this method call used integersOnly = true, check that the string does not contain '.', 'E', or 'e' before calling that version.
* <code>[ParseJSONNumber(string, bool, bool, bool)](#ParseJSONNumber_string_bool_bool_bool)</code> - <b>Deprecated:</b> Instead, call ParseJSONNumber(str, jsonoptions) with a JSONOptions that sets preserveNegativeZero to the desired value, either true or false. If this method call used positiveOnly = true, check that the string does not begin with '-' before calling that version. If this method call used integersOnly = true, check that the string does not contain '.', 'E', or 'e' before calling that version.
* <code>[ParseJSONNumber(string, int, int)](#ParseJSONNumber_string_int_int)</code> - Parses a number whose format follows the JSON specification (RFC 8259) from a portion of a text string, and converts that number to a CBOR object.
* <code>[ParseJSONNumber(string, int, int, PeterO.Cbor.JSONOptions)](#ParseJSONNumber_string_int_int_PeterO_Cbor_JSONOptions)</code> - Parses a number whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
* <code>[ParseJSONNumber(string, PeterO.Cbor.JSONOptions)](#ParseJSONNumber_string_PeterO_Cbor_JSONOptions)</code> - Parses a number whose format follows the JSON specification (RFC 8259) and converts that number to a CBOR object.
Expand Down
17 changes: 0 additions & 17 deletions docs/PeterO.Cbor.CBORNumber.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ An instance of a number that CBOR or certain CBOR tags can represent. For this p
* <code>[ToByteIfExact()](#ToByteIfExact)</code> - Converts this number's value to a byte (from 0 to 255) if it can fit in a byte (from 0 to 255) without rounding to a different numerical value.
* <code>[ToByteUnchecked()](#ToByteUnchecked)</code> - Converts this number's value to an integer by discarding its fractional part, and returns the least-significant bits of its two's-complement form as a byte (from 0 to 255).
* <code>[ToCBORObject()](#ToCBORObject)</code> - Converts this object's value to a CBOR object.
* <code>[ToDecimal()](#ToDecimal)</code> - Converts this number's value to a CLR decimal.
* <code>[ToEDecimal()](#ToEDecimal)</code> - Converts this object to a decimal number.
* <code>[ToEFloat()](#ToEFloat)</code> - Converts this object to an arbitrary-precision binary floating point number.
* <code>[ToEInteger()](#ToEInteger)</code> - Converts this object to an arbitrary-precision integer.
Expand Down Expand Up @@ -678,22 +677,6 @@ Converts this object's value to a CBOR object.

A CBOR object that stores this object's value.

<a id="ToDecimal"></a>
### ToDecimal

public decimal ToDecimal();

Converts this number's value to a CLR decimal.

<b>Return Value:</b>

This number's value, converted to a decimal as though by `(decimal)this.ToEDecimal()` .

<b>Exceptions:</b>

* System.OverflowException:
This value is infinity or not-a-number.

<a id="ToEDecimal"></a>
### ToEDecimal

Expand Down
Loading

0 comments on commit 76f39de

Please sign in to comment.