Skip to content

Commit

Permalink
change to Unlicense; etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
peteroupc committed Aug 8, 2024
1 parent d674868 commit a0e420e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 24 deletions.
6 changes: 3 additions & 3 deletions CBOR/PeterO/Cbor/CBORObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
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):
https://creativecommons.org/publicdomain/zero/1.0/
licensed under the Unlicense: https://unlicense.org/
*/
using System;
Expand Down Expand Up @@ -3267,7 +3266,8 @@ public static CBORObject NewOrderedMap() {
/// <returns>A new CBOR map.</returns>
public static CBORObject FromOrderedMap(IEnumerable<Tuple<CBORObject,
CBORObject >> keysAndValues) {

Check warning on line 3268 in CBOR/PeterO/Cbor/CBORObject.cs

View workflow job for this annotation

GitHub Actions / Core (ubuntu-latest)

Closing generic bracket should not be preceded by a space (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1015.md)

Check warning on line 3268 in CBOR/PeterO/Cbor/CBORObject.cs

View workflow job for this annotation

GitHub Actions / Core (macos-latest)

Closing generic bracket should not be preceded by a space (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1015.md)
var oDict = PropertyMap.NewOrderedDict();
IDictionary<CBORObject, CBORObject> oDict;
oDict = PropertyMap.NewOrderedDict();
foreach (Tuple<CBORObject, CBORObject> kv in keysAndValues) {
oDict.Add(kv.Item1, kv.Item2);
}
Expand Down
25 changes: 19 additions & 6 deletions CBOR/PeterO/Cbor/CBORUuidConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,25 @@ public Guid FromCBORObject(CBORObject obj) {
throw new CBORException("Must have outermost tag 37");
}
_ = ValidateObject(obj);
byte[] b2 = obj.GetByteString();
byte[] bytes = {
b2[3], b2[2], b2[1], b2[0], b2[5], b2[4], b2[7],
b2[6], b2[8], b2[9], b2[10], b2[11], b2[12], b2[13], b2[14], b2[15],
};
return new Guid(bytes);
byte[] bytes = obj.GetByteString();
var guidChars = new char[36];
string hex = "0123456789abcdef";
var index = 0;
for (int i = 0; i < 16; ++i) {
if (i == 4 || i == 6 || i == 8 || i == 10) {
guidChars[index++] = '-';
}
guidChars[index++] = hex[(bytes[i] >> 4) & 15];
guidChars[index++] = hex[bytes[i] & 15];
}
var guidString = new String(guidChars);
// NOTE: Don't use the byte[] constructor of the DotNet Guid class,
// since the bytes may have to be rearranged in order to generate a
// Guid from a UUID; thus the exact Guid generated from a byte string
// by that constructor may differ between little-endian and big-endian
// computers, but I don't have access to a big-endian machine to test
// this hypothesis.
return new Guid(guidString);
}
}
}
2 changes: 1 addition & 1 deletion CBOR/PeterO/DebugUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ licensed under Creative Commons Zero (CC0):
using System.Reflection;
// Use directives rather than the Conditional attribute,
// to avoid the chance of logging statements leaking in release builds
#if DEBUG
#if DEBUGLOG
namespace PeterO {
internal static class DebugUtility {
private static readonly object WriterLock = new object();
Expand Down
23 changes: 15 additions & 8 deletions CBORTest/CBORObjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,13 @@ public static CBORObject TestSucceedingJSON(
}
}

public static void AreShortsEqual(short shortA, short shortB) {
Assert.AreEqual(shortA, shortB);
}
public static void AreLongsEqual(long longA, long longB) {
Assert.AreEqual(longA, longB);
}

public static string CharString(int cp, bool quoted, char[] charbuf) {
var index = 0;
if (quoted) {
Expand Down Expand Up @@ -651,9 +658,9 @@ public void TestAsInt16() {
if (numberinfo["int16"].AsBoolean()) {
int intForShort = TestCommon.StringToInt(
numberinfo["integer"].AsString());
Assert.AreEqual(
AreShortsEqual(
(short)intForShort,
cbornumber.ToObject(typeof(short)));
(short)cbornumber.ToObject(typeof(short)));
} else {
try {
_ = cbornumber.ToObject(typeof(short));
Expand Down Expand Up @@ -856,18 +863,18 @@ public void TestAsInt64() {
CBORObject cbornumbersingle =
ToObjectTest.TestToFromObjectRoundTrip(edec.ToSingle());
if (numberinfo["int64"].AsBoolean()) {
Assert.AreEqual(
AreLongsEqual(
TestCommon.StringToLong(numberinfo["integer"].AsString()),
cbornumber.ToObject(typeof(long)));
(long)cbornumber.ToObject(typeof(long)));
if (isdouble) {
Assert.AreEqual(
AreLongsEqual(
TestCommon.StringToLong(numberinfo["integer"].AsString()),
cbornumberdouble.ToObject(typeof(long)));
(long)cbornumberdouble.ToObject(typeof(long)));
}
if (issingle) {
Assert.AreEqual(
AreLongsEqual(
TestCommon.StringToLong(numberinfo["integer"].AsString()),
cbornumbersingle.ToObject(typeof(long)));
(long)cbornumbersingle.ToObject(typeof(long)));
}
} else {
try {
Expand Down
8 changes: 7 additions & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
Written by Peter O. in 2013 and later. Any copyright to this library is released to the Public Domain. In case this is not possible, this library is also licensed under Creative Commons Zero (CC0): [https://creativecommons.org/publicdomain/zero/1.0/](https://creativecommons.org/publicdomain/zero/1.0/)
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ of a given class into CBOR objects.
cp2=conv.FromCBORObject(cbor);
```

NOTE: All code samples in this section are released to the Public Domain,
as explained in <https://creativecommons.org/publicdomain/zero/1.0/>.
NOTE: All code samples in this section are released under the Unlicense.

Demo
----------
Expand All @@ -293,12 +292,11 @@ CBOR library in the form of a calculator.
About
-----------

Written in 2013-2019 by Peter O.
Written in 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):
[https://creativecommons.org/publicdomain/zero/1.0/](https://creativecommons.org/publicdomain/zero/1.0/)
licensed under the Unlicense: [https://unlicense.org/](https://unlicense.org/)

Release Notes
-----------
Expand Down

0 comments on commit a0e420e

Please sign in to comment.