Closed l1x closed 4 years ago
Did you try CBORObject.FromObject
?
I did.
let exampleHit = { hitHostname = "google.com"; hitMemoryUsed = 0.1234; hitPage = "index.html"}
let cborTest() =
Console.WriteLine("{0}", "Cbor test")
let cbor = CBORObject.FromObject(exampleHit)
let encoded = cbor.EncodeToBytes()
let buffer = new MemoryStream()
buffer.Write(encoded, 0, encoded.Length)
buffer.Seek(int64(0), SeekOrigin.Begin) |> ignore
let decoded = CBORObject.Read(buffer);
Console.WriteLine("{0}", decoded)
Output:
Cbor test
{}
Maybe I am missing something.
This is currently not supported with just CBORObject.FromObject(obj)
HitType
has only read-only properties, and CBORObject.FromObject
supports read-only properties of a type only if that type is compiler-generated (e.g., in the case of anonymous types). I will see what can be done to support F# types in the next version.
In the meantime, try using the overload that takes a CBORTypeMapper.
Released version 4.1.0 which should address this issue.
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!