Giter VIP home page Giter VIP logo

cbor's People

Contributors

anders9ustafsson avatar charlesroddie avatar erikmav avatar peteroupc avatar richardschneider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cbor's Issues

Different output from VS2022

We are getting CBOR serialization when running NUnit tests in VS2022 different from VS2019 (non-preview).

image

Will add to this post as we investigate.

Premature end of data

The application uses serialized (Cbor) and compressed (DeflateStream) files that are read like:

using (var stream = File.OpenRead(path))
{
    using (var deflateStream = new DeflateStream(stream, CompressionMode.Decompress, true))
        return Deserialize(1, deflateStream);
}

in .net 4 everything is fine, but after the migration to dotnet 6 an error began "Premature end of data" to appear

This place throws the error

class CBORReader

public CBORObject ReadForFirstByte(int firstbyte) {
...
  // Read fixed-length data
  byte[] data = null;
  if (expectedLength != 0) {
    data = new byte[expectedLength];
    // include the first byte because GetFixedLengthObject
    // will assume it exists for some head bytes
    data[0] = unchecked((byte)firstbyte);
    if (expectedLength > 1 &&
      this.stream.Read(data, 1, expectedLength - 1) != expectedLength
      - 1) {
      throw new CBORException("Premature end of data");
    }
    ...
  }

I don’t know what has changed in the implementation of DeflateStream, but this.stream.Read(data, 1, expectedLength - 1) at some point 1 byte is read instead of 2, and code does not expect this

That's if this place is rewritten like:

// include the first byte because GetFixedLengthObject
// will assume it exists for some head bytes
data[0] = unchecked((byte)firstbyte);
if (expectedLength > 1)
{
    var totalRead = 0;
    while (totalRead !=expectedLength-1)
    {
        var read = this.stream.Read(data, 1, expectedLength - totalRead - 1);
        if (read == 0)
            throw new CBORException("Premature end of data");
        totalRead += read;
    }

}

this fix issue.

this.stream.Read should be less optimistic

CBOR C# library with VS 2010

Hi, I want to compile cbor library with VS 2010. I was not able to load one of project CBOR in solution. however, I fixed loading issue but still lots of compilation errors and file missing issues. is there any another way to compile this cbor project with VS 2010?

Compatibility of CBORType.Number in newer versions

I'm looking to upgrade from v3.4.0 to the latest v4.0.1.
The documentation suggests that CBORType.Number has been deprecated. However, after the upgrade to 4.0.1, i see that usage for a Number object compiles correctly but fails logically. In my case with v4.0.1 sampleObject.Type == CBORType.Number compiles successfully but returns false while with v3.4.0 it returns true. This breaks my code functionality without build failure. However, sampleObject.IsNumber returns true as expected. If the intention to leave CBORType.Number in the newer version is for backward compatibility, shouldn't it be supported for functionality too? Please provide some insight on other similar changes as well in the upgrades.

CBOR Byte String Support

The CBOR Spec (RFC7049) defines Major type 2 as a byte string. This is different than Major type 4, and array of data items.

I have an application where the client need a string transported as a byte string.
In JSON the message is:
Json: {"len":1156,"off":0,"data":[48,61,66,84,54,49,48,10,49,61,10,50,61,101,56,48,51,10,51,61,57,56,51,97,10,52,61,52,48,101,50,48,49,48,48,10,53,61,48,48,10,54,61,48,48,48,48,48,48,48,48,10,55,61,51,99,48,48,48,48,48,48,10,56,61,48,49,10,57,61,48,48,10,97,61,48,48,10,98,61,49,46,49,52,46,56,10,99,61,83,82,69,81,10,100,61,67,69,51,68,50,54,52,54,69,67,65,55,10,101,61,99,57,101,51,48,49,48,48,10,102,61,48,46,48,10,49,48,61,102,100,51,54,51,55,48,48,48,48,48,48,48,48,48,48,10,49,49,61,48,48,48,48,102,101,52,50,10,49,50,61,48,48,48,48,102,101,52,50,10,49,51,61,48,48,48,48,48,48,99,51,10,49,52,61,48,48,48,48,48,48,99,51,10,49,53,61,48,48,48,48,56,48,98,102,10,49,54],"name":"/ext/params.txt"}

Converted to CBOR
A4 63 6C 65 6E 19 04 84 63 6F 66 66 00 64 64 61 74 61 98 D0 18 30 18 3D 18 42 18 54 18 36 18 31 18 30 0A 18 31 18 3D 0A 18 32 18 3D 18 65 18 38 18 30 18 33 0A 18 33 18 3D 18 39 18 38 18 33 18 61 0A 18 34 18 3D 18 34 18 30 18 65 18 32 18 30 18 31 18 30 18 30 0A 18 35 18 3D 18 30 18 30 0A 18 36 18 3D 18 30 18 30 18 30 18 30 18 30 18 30 18 30 18 30 0A 18 37 18 3D 18 33 18 63 18 30 18 30 18 30 18 30 18 30 18 30 0A 18 38 18 3D 18 30 18 31 0A 18 39 18 3D 18 30 18 30 0A 18 61 18 3D 18 30 18 30 0A 18 62 18 3D 18 31 18 2E 18 31 18 34 18 2E 18 38 0A 18 63 18 3D 18 53 18 52 18 45 18 51 0A 18 64 18 3D 18 43 18 45 18 33 18 44 18 32 18 36 18 34 18 36 18 45 18 43 18 41 18 37 0A 18 65 18 3D 18 63 18 39 18 65 18 33 18 30 18 31 18 30 18 30 0A 18 66 18 3D 18 30 18 2E 18 30 0A 18 31 18 30 18 3D 18 66 18 64 18 33 18 36 18 33 18 37 18 30 18 30 18 30 18 30 18 30 18 30 18 30 18 30 18 30 18 30 0A 18 31 18 31 18 3D 18 30 18 30 18 30 18 30 18 66 18 65 18 34 18 32 0A 18 31 18 32 18 3D 18 30 18 30 18 30 18 30 18 66 18 65 18 34 18 32 0A 18 31 18 33 18 3D 18 30 18 30 18 30 18 30 18 30 18 30 18 63 18 33 0A 18 31 18 34 18 3D 18 30 18 30 18 30 18 30 18 30 18 30 18 63 18 33 0A 18 31 18 35 18 3D 18 30 18 30 18 30 18 30 18 38 18 30 18 62 18 66 0A 18 31 18 36 64 6E 61 6D 65 6F 2F 65 78 74 2F 70 61 72 61 6D 73 2E 74 78 74

Pasting this into cbor.me the json array is being converted to a data array. (98 D0 # array(208)). I do not see an option to encode the data as a byte string. Maybe I missed it, I apologize in advance if this is the case. Would this be possible to add?

CBORObject.ToObject when destination type contains IReadOnlyXxxx properties

When the destination type has e.g. IReadOnlyCollection properties CBOR.Object.ToObject fails with a CBORException.

For example:

    public class Tests
    {
        [Test]
        public void ToObjectWithReadOnly()
        {
            var foo = new Foo
            {
                Bars = new List<Bar> {new Bar {Strings = new List<string> {"Mumbo", "Jumbo"}}}
            };

            var stream = new MemoryStream();
            CBORObject.FromObject(foo).WriteTo(stream);
            stream.Position = 0;
            CBORObject.Read(stream).ToObject(foo.GetType()); // Throws
        }
    }

    public class Foo
    {
        public IReadOnlyCollection<Bar> Bars { get; set; }
    }

    public class Bar
    {
        public IReadOnlyList<string> Strings { get; set; }
    }

Changing the Foo and Bar property types to List makes it work. I would however prefer to use IReadOnlyCollection/List if possible.
Would it be possible to support IReadOnlyCollection/List in much the same way as (I)List is supported today?

Could not load file or assembly 'Numbers'

Error from PeterO.Cbor 4.1.1.

Could not load file or assembly 'Numbers, Version=1.6.0.0, Culture=neutral, PublicKeyToken=9cd62db60ea5554c'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
   at PeterO.Cbor.CBORObject.WriteTo(Stream stream, CBOREncodeOptions options)
   at PeterO.Cbor.CBORObject.EncodeToBytes(CBOREncodeOptions options)

4.1.0 is OK.

This is tested in a UWP project.

Flags enum doesn't pass the IsDefined Check

A Flags enum will never pass an IsDefined check.
Problem is in PeterO.Cbor.PropertyMap.ObjectToEnum

Stacktrace
PeterO.Cbor.CBORException: Unrecognized enum value: 4161
   at PeterO.Cbor.PropertyMap.ObjectToEnum(CBORObject obj, Type enumType)
   at PeterO.Cbor.PropertyMap.TypeToObject(CBORObject objThis, Type t, CBORTypeMapper mapper, PODOptions options, Int32 depth)
   at PeterO.Cbor.CBORObject.ToObject(Type t, CBORTypeMapper mapper, PODOptions options, Int32 depth)
   at PeterO.Cbor.PropertyMap.ObjectWithProperties(Type t, IEnumerable`1 keysValues, CBORTypeMapper mapper, PODOptions options, Int32 depth)

This could be a way to fix it.

edit: cc: @peteroupc

CBOR NumberConverstion=Double Issue

I am working on an API between a mobile app and BLE device that uses the Zephyr OS. The implementation does not have support for half float (0xf9).
To attempt to get around this issue, I set the number conversation to be double. My understanding is that all numbers should then be forced into a CBOR double (oxfb).
https://peteroupc.github.io/CBOR/docs/PeterO.Cbor.JSONOptions.ConversionMode.html

string msg = {"p1": 220.7351, "p2": 1.0}
JSONOptions jo = new JSONOptions("numberconversion=double");
obj1 = CBORObject.FromJSONString(msg, jo);
byte[] msgBytes = obj1.EncodeToBytes();
//msgBytes =  A2 62 70 31 FB 40 6B 97 85 F0 6F 69 44 62 70 32 F9 3C 00

Putting the output into a CBOR viewer (http://cbor.me/) we get the following result:
A2 # map(2)
62 # text(2)
7031 # "p1"
FB 406B9785F06F6944 # primitive(4641970442455705924)
62 # text(2)
7032 # "p2"
F9 3C00 # primitive(15360)

What should be noted above is that the 1.0 value is still encoded as a half-float (oxf9), even though the conversation specified it to be a double.

NuGet updates lead to StyleCop warnings

If I update PeterO.Cbor from 3.5.0 to 3.5.1 and PeterO.Numbers from 1.4.1 to 1.4.2, as suggested by NuGet in VS2019, I immediately get a large number of unwanted StyleCop warnings - I don't see why yet - anyone else?
Jim

Comparison and equality operators for CBORObject and CBORNumber

In version 4.0, PeterO.Cbor.CBORObject will implement a total ordering in its CompareTo method (unlike before when two numbers of different kinds may still compare as equal).

  • CBORObject will also implement the "<", "<=", ">=", and ">" operators that call into CompareTo.
  • But should CBORObject also implement the "==" and "!=" operators to call Equals, as FXCop rule CA1036 suggests?
    • Advantages: Consistent with other four operators, and notion of equality becomes consistent with Equals and CompareTo.
    • Disadvantages: Heavyweight, since CBOR objects can have arbitrary size. These two operators do a reference equality by default, which is much faster, and changing them to do a value equality can cause performance issues for users that relied on the reference equality behavior of these operators and will make the .NET version of this library inconsistent with the Java version.

In version 4.0, the new PeterO.Cbor.CBORNumber will also have a CompareTo method, but will not do a total ordering, but a numerical comparison (meaning that two objects with different contents are equal if they express the same number).

  • CBORNumber will also implement the "<", "<=", ">=", and ">" operators.
  • But how should CBORNumber implement those operators — as a numerical comparison or as a total ordering?
  • And should CBORNumber implement the "==" and "!=" operators, and if so, how?

See also:

MicrosoftDocs/visualstudio-docs#3728

Assembly does not have a strong signature.

I would like to apply a strong signature to my assemblies, however since I am referencing the CBOR (and indirectly NUMBERS) projects and they are not strongly signed it will not work.

Please release a new version with a strong signature.

Change in ToString from 3.x to 4.0

string x = CBORObject.True.ToString();

results in "21" not in "true"

I just upgraded due to the security issue and am having this problem when doing comparisons on strings produced. The output of "{1:21}" is really not the same as "{1:true}"

Async version?

Hi,

Thanks for the library. I'm wondering if you have any plans to work on the async support?

Nullable types

I get CBORException when calling ToObject for a type containing nullable property (like int?). Interesting that FromObject works just fine for the same type. Is it expected behavior and CBOR just doesn't support nullable types?

Object serialization/deserialization and using integers as map keys

First, thanks for making this cbor implementation available. 😊

I am working on a C# application which needs to communicate cbor with an embedded device (which is under development). Due to constraints on the embedded device it has been suggested that the cbor map keys could be integers rather than utf8 strings.
I have been playing around with PeterO.Cbor, and what I would like to do is to use C# pocos and have them serialized/deserialized to/from cbor. So far the poco property names gets serialized as utf8 keys in the cbor maps, but what I am hoping for is integer keys.

Is there a way with the current PeterO.Cbor package to do C# poco serialization/deserialization using integers as keys in the cbor maps?
If not, is it something that the package could support out of the box in a future release – or something that the package could allow through client side extensions?
😊

From Bytes to Object to JSON and back

Hello Sir

I am having trouble to use your tools decoding from bytes to Object to JSON.

        byte[] bytes = ToBytes("a201187b021901c8");     //

        CBORObject obj1 = CBORObject.DecodeFromBytes(bytes);
        string w = obj1.ToJSONString();
        CBORObject obj2 = CBORObject.FromJSONString(w);

        byte[] f = obj1.EncodeToBytes();
        byte[] r = obj2.EncodeToBytes();

I would expect the two byte arrays f and r to be completely identical but they are not.
Do You have a comment on that?

Ole

DateTimeKind.Utc

CBOR decodes any DateTime with Kind set to UTC. I would suggest to use Unspecified instead.

Separate C# and Java

Hi, would it be possible to separate these two rather distant implementations?

Null-handling behavior of certain As* methods of CBORObject

CBORObject's AsEInteger, AsEDecimal, AsEFloat, AsERational, and AsString currently throw an exception when the CBOR object is CBORObject.Null. Should these methods instead convert CBORObject.Null to null? (If so, why?)

I don't mind if the answer is no, since I can then document the null-check idiom—

  • cbor.IsNull ? null : cbor.AsEInteger(), or
  • (cbor==null || cbor.IsNull) ? null : cbor.AsEInteger(),

for AsEInteger and likewise for the other four methods. Is there a better null-check idiom here?

Unable to encode value as half-float

Trying to convert either a double or a single to a half float using the ICBORConverter, but not sure how to flag the value as a half float instead of a double.

Expected double header, but found F9

Describe the bug

Can't deserialize CBOR bytes using https://github.com/Kotlin/kotlinx.serialization if serialized object has a field with double value without fractional part.

To Reproduce

C#

  public class Data2
  {
      public double Field { get; set; }
  }

Kotlin

@Serializable
data class Data2(val field: Double)

Works:

var works = CBORObject.FromObject(new Data2 { Field = 66.77 }).EncodeToBytes()
var res1 = Cbor.Default.decodeFromByteArray<Data2>(works)

Exception 'Expected double header, but found F9':
var doesntWork = CBORObject.FromObject(new Data2 { Field = 66 }).EncodeToBytes()
var res2 = Cbor.Default.decodeFromByteArray<Data2>(doesntWork)

However it worked fine with 4.0 beta1. Tested on all versions after 4.0 beta1 - crashes with that exception.

Environment

  • Kotlin version: 1.4
  • Library version on Kotlin side: org.jetbrains.kotlinx:kotlinx-serialization-cbor:1.0.0-RC
  • Library version on C# side: 4.2

Typed CBORObject.FromInt etc.

Currently to convert a primitive to CBOR, CBORObject.FromObject is used which has a lot of overloads. This gives a lack of safety, as overload resolution is affected by op_Implicit, and also has an obj overload which makes it extra unsafe.

Instead there should be added FromInt, FromInt64, FromChar, FromArray, FromGuid etc..

seems like a issue with the conversion/map

Hi Peter
Consider the following code snippets
1.
var cborObj = CBORObject.NewMap()
 .Add(1, 3)
 .Add(2, 4);
 string jsonStr = cborObj.ToJSONString();

2.
cborObj = CBORObject.NewMap()
.Add("1", 3)
.Add("2", 4);
jsonStr = cborObj.ToJSONString();

The both will give a JSON string
{
"1": 4,
"2": 2
}
But in the first one I have put int value as key. In second string value.
Also when we consider JSON the key needs to be in string format.

The advantage of fist option is less bytes when we convert in to bytes (EncodeToBytes()) But the problem I we can't create a C# class property name as an integer hence can't do the object conversion.

So seems like a issue with the conversion/map. Could you please correct the same or let me know I am wrong.

Vineeth

Decode CBORObject back to any arbitrary object

Hi Peter,

I am trying to use PeterO.CBOR package to encode/decode an arbitrary object to/from CBOR. My object has two values: one is an array of byte strings, the second one is just an integer.
Encoding the object to CBOR is working fine. But I have problem to decode the CBOR object back to my original object. I couldn’t find an API to support the decoding to the original object directly. So I came up with an alternative approach: use CBORObject.ToJSONString() to get a JSON string firstly, then use NewtonSoft.JsonConvert.DeserializeObject() to de-serialize the JSON string to the specified type.

CBORObject.ToJSONString() states that byte strings are converted to Base64 URL without whitespace or padding by default. A byte string will instead be converted to traditional base64 without whitespace or padding if it has tag 22, or base16 for tag 23. I am curious why you don’t include the padding by default, which makes the JSON string invalid length. I looked at the source code, there is no options to makeCBORObject.ToJSONString() to include the padding. Maybe I missed something here. Could you please let me know if there is a way I can include the padding in the JSON string produced by CBORObject.ToJSONString()? My second question is that how can I set the tag (22) to just one value inside my object during encoding using CBORObject.FromObjectAndTag(), which sets the tag to the entire object not just one element in the map, because I need to CBORObject.ToJSONString() to return traditional base64 instead of base64 URL.

Thank you!

How to tag the ByteString inside an array

I have an array of byteStrings, defined as follows:

var array = new List<byte[]>();
array.Add(byteString1);
array.Add(byteString2);
array.Add(byteString3);
var cborWithTag = CBORObject.FromObjectAndTagarray, 22);

The array was tagged 22 in cborWithTag. But each byteString in the array is not tagged properly, the value is still -1.

I want to CBORObject.ToJSONString() to encode the byteString to base64. How can I achieve it?

Extracting ByteString tag and value from CBORObject?

Ok, first of all your lib is great so thank you for that!
I'm very new to cbor, and trying to figure out how to decode some data.
Based of some python implementation which might be irrelevant:

tag, crc32 = cbor.loads(s)
s = tag.value
assert binascii.crc32(s) == crc32, 'crc32 checksum don\'t match.'
return cls(*cbor.loads(s))

I'm trying to do the same with your CBOR lib
I have some input data as bytes:

82d818584283581ce6c6f5f8275a769f4e2ce9fadbddc50f350ce3f32a552b48e9f98875a101581e581cca3e553c9c63c582084f2c432080796b930659ece479af1ac72a1e98001a681a9d13

  var cbor = CBORObject.DecodeFromBytes(bytes);
  // i.e.  
  // {[24(h'83581CE6C6F5F8275A769F4E2CE9FADBDDC50F350CE3F32A552B48E9F98875A101581E581CCA3E553C9C63C582084F2C432080796B930659ECE479AF1AC72A1E9800'), 1746574611]}
  if (cbor.Count == 2)
  {
    CBORObject[] cborArray = cbor.Values.ToArray();
    if (cborArray[1].Type == CBORType.Number) // the checksum crc32
    {
       var crc32 = cborArray[1].AsUInt32();  // Number: 1746574611
       CBORObject cborByteStringWithTag = cborArray[0]; // ByteString: {24(h'83581CE6C6F5F8275A769F4E2CE9FADBDDC50F350CE3F32A552B48E9F98875A101581E581CCA3E553C9C63C582084F2C432080796B930659ECE479AF1AC72A1E9800')}
        // How to extract the tag and the '8358...' hex  string?
    }
  }

How do I handle the cborByteStringWithTag? trying to access the Values property throws an exception.
The Only way I see it can be done right now is to manually parse the {24(h'8358...')} myself.

Am I missing anything? Thanks!

Preserve case of property names

The property names are always converted to camelCase, when using CBORObject.FromObject(object).
Can the case of the names be presevered?

Base64 needs padding at the end

According to RFC 4648 section 4.0 - Base 64 encoding. Padding at the end of the data is performed using the '=' character.

CBORObject.ToJSONString() converts a byte string to traditional base64 without whitespace or padding if it has 22. This seems to be a bug.

How much map key ordering is needed by CBOR protocols?

Currently, when my library writes out CBOR objects, either as byte arrays, to streams, or as JSON, it does not guarantee that map keys are sorted.

I want to gauge the level of map key ordering required to support important protocols being widely deployed.

Do COSE, Web Authentication, or other important CBOR protocols care about the order in which CBOR map keys are written out by a CBOR implementation — such that not ensuring a specific order of map keys could lead to incorrect results, or that different results could occur if map keys appear in one order than if they appear in another? do a byte-by-byte comparison of serialized CBOR objects that could include CBOR maps (or similar comparisons involving such serializations), such that an implementation that writes out CBOR map keys in an undefined order is less interoperable than one that writes out those keys in a well-defined order?

I am aware that protocols could use CBOR maps with keys of any or all of the following types:

  • Nonnegative integers.
  • Negative and nonnegative integers.
  • Strings.
  • Floating-point numbers.
  • Arrays and/or maps.
  • Serialized byte strings of CBOR objects.
  • Arbitrary byte arrays.

The kind of map keys used also dictates the level of map key ordering needed.

The level of CBOR map key ordering required is also dictated by whether CBOR protocols—

  • serialize maps whose keys and values are limited to strings, integers, and byte arrays,
  • serialize arrays of maps,
  • serialize maps whose keys and/or values can themselves be maps, or
  • serialize maps in some other way.

Could not load file or assembly 'CBOR'

I've loaded the following libraries:

  • PeterO.Numbers.1.0.2\lib\netstandard1.0\Numbers.dll'
  • PeterO.Cbor.3.0.3\lib\netstandard1.0\CBOR.dll'

but I'm getting the following error:
Exception calling "GeneratePSK" with "2" argument(s): "Could not load file or assembly 'CBOR, Version=3.0.0.0, Culture=neutral, PublicKeyTok
en=9cd62db60ea5554c' or one of its dependencies. The system cannot find the file specified."

for this part of the following code

Any ideas?
/Stefan

Efficient way to pass in immutable/non-array collections

CBORObject.FromObject has an overload taking arrays:

    public static CBORObject FromObject(CBORObject[] array) {
      if (array == null) {
        return CBORObject.Null;
      }
      IList<CBORObject> list = new List<CBORObject>();
      foreach (CBORObject cbor in array) {
        list.Add(cbor);
      }
      return new CBORObject(CBORObjectTypeArray, list);
    }

There is an additional collection created here: since array is mutable it cannot be trusted to be used directly, so it is duplicated into an List.

Passing in collections other than arrays take a further collection creation, as they first need to be converted to arrays since that is the only overload.

It would be good to have an efficient way to pass in an ImmutableArray<CBORObject>, or one of the interfaces that it supports: ICollection<T>, IEnumerable<T>, IList<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, IImmutableList<T>.

This could be done by taking an IEnumerable<T> and using the current approach. That would only be one collection creation, copying to a List.

If it used one of the immutable interfaces internally (ImmutableArray, IImmutableList), then no copying would be needed, as the input could be used directly without risk of changes.

MostInnerTag not in the drop?

I was going to try and get rid of all of my BigInteger warnings so I tried to switch from InnermostTag to MostInnerTag as suggested by the copy of the source code that I have suggests. However, it appears that this is not in the most recent drop of the binaries.

Unable to load assembly

All loaded through nuget, v3.0.0. All files present, but I get:

System.IO.FileLoadException occurred
HResult=0x80131045
Message=Could not load file or assembly 'CBOR, Version=3.0.0.0, Culture=neutral, PublicKeyToken=9cd62db60ea5554c' or one of its dependencies. Strong name signature could not be verified. The assembly may have been tampered with, or it was delay signed but not fully signed with the correct private key. (Exception from HRESULT: 0x80131045)

Noticed that this only occurs when running tests with ReSharper.

How to convert a type in F# to CBORobject?

I was wondering if there is a way to convert a simple type in F# to a CBORobject.

type HitType = {
hitHostname : string;
hitMemoryUsed : float;
hitPage : string;
}

Let me know if this is supported by this project. Thanks!

A Bug in the namespace

Dear Peter,

you have a bug in your Java namespace. And the Junit libary is not in the repository. Can you fix this?

Thanks.

Parser for CBOR Diagnostics

Feature Request:

Have you ever considered adding the reverse of the ToString function so that one could parse CBOR diagnositic text back into CBOR binary? This is a much easier form to edit for files and I often use it for that. I have written a fast and dirty version for myself, but it would be nice if there was one in the package.

Improving FromObject and ToObject

Currently, FromObject and ToObject (the latter of which was added in version 3.4.0-alpha1, a prerelease) support converting CBOR objects to and from a wide variety of natively supported types, as well as to and from arbitrary classes known as POD classes (better known as POCOs in .NET or POJOs in Java).

However, both methods currently leave much to be desired. For example, there are certain inconsistencies between FromObject and ToObject, as well as between the .NET and Java versions of both methods. Some of these inconsistencies have to remain in version 3.x for backward compatibility. These inconsistencies and other issues are further explained in the documentation:

There are important questions that should be answered to help improve FromObject and ToObject in version 4.0 and possibly in version 3.4, taking into consideration how both methods currently behave.

  • What data types (source and destination) should both methods support?
  • How should both methods convert POD classes to and from CBOR objects in .NET? In Java?
  • What source-type-to-destination-type conversions should ToObject support?
  • How should the ToObject method behave if data is of the wrong type (e.g., when the source is a string but the destination is a number) or if data is a number that's unsupported for the destination type (e.g., how should the converter behave if the source is say 67.59, but the destination stores only integers? should the converter round to the nearest number, truncate fractions, raise an exception, something else?)
  • How can FromObject and ToObject be designed for better forward compatibility in version 4.0 and later?

Props prefixed with "Is" are not decoded

I translated this {"isFoo": true} to HEX here https://cbor.me/. It gave me this A1656973466F6FF5
Then I tried to decode it

public class Test
{
    public bool IsFoo { get; set; }
}

var test = CBORObject.DecodeFromBytes(Convert.FromHexString("A1656973466F6FF5")).ToObject<Test>();

And I got object with IsFoo false.

If I rename IsFoo to Foo all works well.

Make PCL version of CBOR

Dear Peter,

many thanks for sharing this library. I originally found it when commenting on a question in StackOverflow.

I am a big proponent of making C# libraries as portable as possible, ideally creating Portable Class Libraries that can be consumed by a multitude of targets, such as Windows Store apps, Windows Phone, Silverlight and now even Xamarin.iOS and Xamarin.Android.

I cloned the CBOR library, and I came to the conclusion that your library can easily be turned into a PCL targeting .NET Framework 4.5, Windows Store apps, Windows Phone 8 and Silverlight 5. The only things you would need to do are:

  • Remove the line [assembly: ComVisible(false)] from AssemblyInfo.cs
  • Remove all serialization code from CBORException.cs

If you are interested but would like some help with this I can even provide you with a proper pull request. Is there any particular Visual Studio version you would like me to use in that case?

Best regards,
Anders @ Cureos

[Error] PeterO type or namespace could not be found.

I am just giving a try at utilizing your repo with demo hello.cs program. But I end up with the following issues.

  1. Attribute "PeterO.Cbor" is not reflecting as others in color. Please refer to the below code.
    image

  2. Error during execution of hello.cs program. Please find the same from the below snapshot.
    image

Additional Info:

  1. Visual Studio Code version details
    image

  2. CBOR.csproj installed state
    image

  3. dotnet restore command output
    image

Could you please correct me on this issue and let me know where I went wrong.

Swamy

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.