diff --git a/CBOR/PeterO/Cbor/CBORObject.cs b/CBOR/PeterO/Cbor/CBORObject.cs
index cc1e9bce..d8d3b568 100644
--- a/CBOR/PeterO/Cbor/CBORObject.cs
+++ b/CBOR/PeterO/Cbor/CBORObject.cs
@@ -607,7 +607,7 @@ public object ToObject(Type t) {
}
///
+ /// path='docs/doc[@name="M:PeterO.Cbor.CBORObject.ToObject(System.Type,PeterO.Cbor.CBORTypeMapper)"]/*'/>
public object ToObject(Type t, CBORTypeMapper mapper) {
if (mapper == null) {
throw new ArgumentNullException(nameof(mapper));
@@ -616,7 +616,7 @@ public object ToObject(Type t, CBORTypeMapper mapper) {
}
///
+ /// path='docs/doc[@name="M:PeterO.Cbor.CBORObject.ToObject(System.Type,PeterO.Cbor.PODOptions)"]/*'/>
public object ToObject(Type t, PODOptions options) {
if (options == null) {
throw new ArgumentNullException(nameof(options));
@@ -625,7 +625,7 @@ public object ToObject(Type t, PODOptions options) {
}
///
+ /// path='docs/doc[@name="M:PeterO.Cbor.CBORObject.ToObject(System.Type,PeterO.Cbor.CBORTypeMapper,PeterO.Cbor.PODOptions)"]/*'/>
public object ToObject(Type t, CBORTypeMapper mapper, PODOptions options) {
if (mapper == null) {
throw new ArgumentNullException(nameof(mapper));
@@ -786,14 +786,6 @@ public static CBORObject FromObject(short value) {
FromObject((long)value);
}
- ///
- public static CBORObject FromObject(char value) {
- // TODO: Consider changing this method's behavior
- char[] valueChar = { value };
- return FromObject(new String(valueChar));
- }
-
///
public static CBORObject FromObject(bool value) {
@@ -958,7 +950,7 @@ internal static CBORObject FromObject(
return FromObject((short)obj);
}
if (obj is char) {
- return FromObject((char)obj);
+ return FromObject((int)(char)obj);
}
if (obj is bool) {
return FromObject((bool)obj);
@@ -1498,17 +1490,6 @@ public static void Write(short value, Stream stream) {
Write((long)value, stream);
}
- ///
- public static void Write(char value, Stream stream) {
- // TODO: Consider changing this method's behavior
- if (value >= 0xd800 && value < 0xe000) {
- throw new ArgumentException("Value is a surrogate code point.");
- }
- char[] valueChar = { value };
- Write(new String(valueChar), stream);
- }
-
///
public static void Write(bool value, Stream stream) {
diff --git a/CBOR/PeterO/Cbor/CBORObjectExtra.cs b/CBOR/PeterO/Cbor/CBORObjectExtra.cs
index 6f9281f4..a7f68a99 100644
--- a/CBOR/PeterO/Cbor/CBORObjectExtra.cs
+++ b/CBOR/PeterO/Cbor/CBORObjectExtra.cs
@@ -241,19 +241,19 @@ public T ToObject() {
}
///
+ /// path='docs/doc[@name="M:PeterO.Cbor.CBORObject.ToObject``1(PeterO.Cbor.CBORTypeMapper)"]/*'/>
public T ToObject(CBORTypeMapper mapper) {
return (T)this.ToObject(typeof(T), mapper);
}
///
+ /// path='docs/doc[@name="M:PeterO.Cbor.CBORObject.ToObject``1(PeterO.Cbor.PODOptions)"]/*'/>
public T ToObject(PODOptions options) {
return (T)this.ToObject(typeof(T), options);
}
///
+ /// path='docs/doc[@name="M:PeterO.Cbor.CBORObject.ToObject``1(PeterO.Cbor.CBORTypeMapper,PeterO.Cbor.PODOptions)"]/*'/>
public T ToObject(CBORTypeMapper mapper, PODOptions options) {
return (T)this.ToObject(typeof(T), mapper, options);
}
diff --git a/CBOR/PeterO/Cbor/CBORReader.cs b/CBOR/PeterO/Cbor/CBORReader.cs
index 7a041880..bcad83a5 100644
--- a/CBOR/PeterO/Cbor/CBORReader.cs
+++ b/CBOR/PeterO/Cbor/CBORReader.cs
@@ -128,29 +128,30 @@ public CBORObject ReadForFirstByte(int firstbyte) {
return cbor;
}
// Special check: Decimal fraction or bigfloat
- if(firstbyte==0xc4 || firstbyte==0xc5){
- int nextbyte=this.stream.ReadByte();
- if(nextbyte!=0x82 && nextbyte!=0x9f)
- throw new CBORException("2-item array expected");
- bool indefArray=(nextbyte==0x9f);
- nextbyte=this.stream.ReadByte();
- if(nextbyte>=0x40){
+ if (firstbyte == 0xc4 || firstbyte == 0xc5) {
+ int nextbyte = this.stream.ReadByte();
+ if (nextbyte != 0x82 && nextbyte != 0x9f) {
+ throw new CBORException("2-item array expected");
+}
+ bool indefArray = nextbyte == 0x9f;
+ nextbyte = this.stream.ReadByte();
+ if (nextbyte >= 0x40) {
throw new CBORException("Major type 0 or 1 or bignum expected");
}
- CBORObject exponent=ReadForFirstByte(nextbyte);
- nextbyte=this.stream.ReadByte();
- if(nextbyte>=0x40 && nextbyte!=0xc2 && nextbyte!=0xc3){
+ CBORObject exponent = this.ReadForFirstByte(nextbyte);
+ nextbyte = this.stream.ReadByte();
+ if (nextbyte >= 0x40 && nextbyte != 0xc2 && nextbyte != 0xc3) {
throw new CBORException("Major type 0 or 1 expected");
}
- CBORObject significand=ReadForFirstByte(nextbyte);
- if(indefArray && this.stream.ReadByte()!=0xff){
+ CBORObject significand = this.ReadForFirstByte(nextbyte);
+ if (indefArray && this.stream.ReadByte() != 0xff) {
throw new CBORException("End of array expected");
}
- CBORObject arr=CBORObject.NewArray()
+ CBORObject arr = CBORObject.NewArray()
.Add(exponent).Add(significand);
return CBORObject.FromObjectAndTag(
arr,
- firstbyte==0xc4 ? 4 : 5);
+ firstbyte == 0xc4 ? 4 : 5);
}
var uadditional = (long)additional;
EInteger bigintAdditional = EInteger.Zero;
diff --git a/CBOR/PeterO/Cbor/CBORTypeMapper.cs b/CBOR/PeterO/Cbor/CBORTypeMapper.cs
index daf344d5..1a83ac49 100644
--- a/CBOR/PeterO/Cbor/CBORTypeMapper.cs
+++ b/CBOR/PeterO/Cbor/CBORTypeMapper.cs
@@ -138,8 +138,8 @@ internal sealed class ConverterInfo {
public object FromObject { get; set; }
- ///
+ /// Gets a value not documented yet.
+ /// A value not documented yet.
public object Converter { get; set; }
}
}
diff --git a/CBOR/PeterO/Cbor/CBORUtilities.cs b/CBOR/PeterO/Cbor/CBORUtilities.cs
index 89f22dd5..6cde577c 100644
--- a/CBOR/PeterO/Cbor/CBORUtilities.cs
+++ b/CBOR/PeterO/Cbor/CBORUtilities.cs
@@ -477,13 +477,13 @@ private static int[] ParseAtomDateTimeString(string str) {
if (bad) {
throw new ArgumentException("Invalid date/time");
}
- int year = (str[0] - '0') * 1000 + (str[1] - '0') * 100 +
+ int year = ((str[0] - '0') * 1000) + (str[1] - '0') * 100 +
(str[2] - '0') * 10 + (str[3] - '0');
- int month = (str[5] - '0') * 10 + (str[6] - '0');
- int day = (str[8] - '0') * 10 + (str[9] - '0');
- int hour = (str[11] - '0') * 10 + (str[12] - '0');
- int minute = (str[14] - '0') * 10 + (str[15] - '0');
- int second = (str[17] - '0') * 10 + (str[18] - '0');
+ int month = ((str[5] - '0') * 10) + (str[6] - '0');
+ int day = ((str[8] - '0') * 10) + (str[9] - '0');
+ int hour = ((str[11] - '0') * 10) + (str[12] - '0');
+ int minute = ((str[14] - '0') * 10) + (str[15] - '0');
+ int second = ((str[17] - '0') * 10) + (str[18] - '0');
var index = 19;
var nanoSeconds = 0;
if (index <= str.Length && str[index] == '.') {
@@ -524,8 +524,8 @@ following RFC 4287 sec. 3.3*/
throw new ArgumentException("Invalid date/time");
}
bool neg = str[index] == '-';
- int tzhour = (str[index + 1] - '0') * 10 + (str[index + 2] - '0');
- int tzminute = (str[index + 4] - '0') * 10 + (str[index + 5] - '0');
+ int tzhour = ((str[index + 1] - '0') * 10) + (str[index + 2] - '0');
+ int tzminute = ((str[index + 4] - '0') * 10) + (str[index + 5] - '0');
if (tzminute >= 60) {
throw new ArgumentException("Invalid date/time");
}
diff --git a/CBOR/PeterO/Cbor/PropertyMap.cs b/CBOR/PeterO/Cbor/PropertyMap.cs
index ac868b05..a94a0cef 100644
--- a/CBOR/PeterO/Cbor/PropertyMap.cs
+++ b/CBOR/PeterO/Cbor/PropertyMap.cs
@@ -553,6 +553,23 @@ public static object TypeToObject(
if (t.Equals(typeof(bool))) {
return objThis.AsBoolean();
}
+ if (t.Equals(typeof(char))) {
+if (objThis.Type == CBORType.TextString) {
+ string s = objThis.AsString();
+ if (s.Length != 1) {
+ throw new CBORException("Can't convert to char");
+}
+ return s[0];
+}
+if (objThis.IsIntegral && objThis.CanTruncatedIntFitInInt32()) {
+ int c = objThis.AsInt32();
+ if (c < 0 || c >= 0x10000) {
+ throw new CBORException("Can't convert to char");
+}
+ return (char)c;
+}
+throw new CBORException("Can't convert to char");
+ }
if (t.Equals(typeof(DateTime))) {
return new CBORDateConverter().FromCBORObject(objThis);
}
@@ -655,8 +672,8 @@ public static object TypeToObject(
isDict = t.IsGenericType;
if (t.IsGenericType) {
Type td = t.GetGenericTypeDefinition();
- isDict = td.Equals(typeof(Dictionary<, >)) ||
- td.Equals(typeof(IDictionary<, >));
+ isDict = td.Equals(typeof(Dictionary<,>)) ||
+ td.Equals(typeof(IDictionary<,>));
}
// DebugUtility.Log("list=" + isDict);
isDict = isDict && t.GetGenericArguments().Length == 2;
@@ -664,7 +681,7 @@ public static object TypeToObject(
if (isDict) {
keyType = t.GetGenericArguments()[0];
valueType = t.GetGenericArguments()[1];
- Type listType = typeof(Dictionary<, >).MakeGenericType(
+ Type listType = typeof(Dictionary<,>).MakeGenericType(
keyType,
valueType);
dictObject = Activator.CreateInstance(listType);
@@ -673,8 +690,8 @@ public static object TypeToObject(
isDict = (t.GetTypeInfo().IsGenericType);
if (t.GetTypeInfo().IsGenericType) {
Type td = t.GetGenericTypeDefinition();
- isDict = (td.Equals(typeof(Dictionary<, >)) ||
- td.Equals(typeof(IDictionary<, >)));
+ isDict = (td.Equals(typeof(Dictionary<,>)) ||
+ td.Equals(typeof(IDictionary<,>)));
}
//DebugUtility.Log("list=" + isDict);
isDict = (isDict && t.GenericTypeArguments.Length == 2);
@@ -682,7 +699,7 @@ public static object TypeToObject(
if (isDict) {
keyType = t.GenericTypeArguments[0];
valueType = t.GenericTypeArguments[1];
- Type listType = typeof(Dictionary<, >).MakeGenericType(
+ Type listType = typeof(Dictionary<,>).MakeGenericType(
keyType,
valueType);
dictObject = Activator.CreateInstance(listType);
diff --git a/CBOR/docs.xml b/CBOR/docs.xml
index 4e1d5105..65c0bb00 100644
--- a/CBOR/docs.xml
+++ b/CBOR/docs.xml
@@ -1439,12 +1439,18 @@
-
- Generates a CBOR string object from a Unicode
- character.The parameter is a
- char object.A CBORObject object.The parameter
- is a surrogate code point.
-
+Generates a CBOR string object from a Unicode character.
+
+ The parameter
+
+ is a char object.
+
+ A CBORObject object.
+
+ The parameter
+
+ is a surrogate code point.
+
@@ -1543,7 +1549,11 @@
- null is converted to CBORObject.Null.
- A CBORObject is returned as itself.
- If the object is of a type corresponding to a type converter mentioned in the parameter, that converter will be used to convert the object to a CBOR object. Type converters can be used to override the default conversion behavior of almost any object.
-- A char is... (to be implemented).
+- A char is converted to an integer (from 0 through 65535),
+and returns a CBOR object of that integer. (This is a change in
+version 4.0 from previous versions, which converted char,
+except surrogate code points from 0xd800 through 0xdfff, into single-character
+text strings.)
- A bool (boolean in Java) is converted to CBORObject.True or CBORObject.False.
- A byte is converted to a CBOR integer from 0 through 255.
- A primitive integer type (int, short, long, as well as sbyte, ushort, uint, and ulong in .NET) is converted to the corresponding CBOR integer.
@@ -2412,10 +2422,10 @@ is less than 0, is the size of this array or greater, or is not a 32-bit signed
-Converts this CBOR object to an object of an arbitrary
+
+ Converts this CBOR object to an object of an arbitrary
type. See the documentation for the overload of this method taking
- a CBORTypeMapper and PODOptions parameters parameters for more information.
- The type, class, or interface that this method's
+ a CBORTypeMapper and PODOptions parameters parameters for more information.The type, class, or interface that this method's
return value will belong to. To express a generic type in Java, see
the example. Note:
For security reasons, an application
@@ -2427,242 +2437,295 @@ is less than 0, is the size of this array or greater, or is not a 32-bit signed
///) or a plain-old-data type (POCO or POJO type)
within the control of the application. If the plain-old-data type
references other data types, those types should likewise meet
- either criterion above.
- This parameter controls which data types are
+ either criterion above.This parameter controls which data types are
eligible for Plain-Old-Data deserialization and includes custom
- converters from CBOR objects to certain data types.
- The converted object.
- The given type
+ converters from CBOR objects to certain data types.The converted object.The given type
, or this object's CBOR type, is not
- supported.
- The parameter
- is null.
- The given object's nesting
+ supported.The parameter
+ is null.The given object's nesting
is too deep, or another error occurred when serializing the
object.
+
-Converts this CBOR object to an object of an
- arbitrary type. The following cases are checked in the logical
- order given (rather than the strict order in which they are
- implemented by this library):
- - If the type is
- CBORObject
- , return this object.
- - If the given
- object is CBORObject.Null
- (with or without tags), returns
- null
- .
- - If the object is of a type corresponding
- to a type converter mentioned in the
- parameter, that converter will be used to convert the CBOR object
- to an object of the given type. Type converters can be used to
- override the default conversion behavior of almost any
- object.
- - If the type is object
- , return this
- object.
- - If the type is char
- ... (To be
- implemented).
- - If the type is bool
- (
- boolean
- in Java), returns the result of AsBoolean.
- - If the type is a primitive integer type ( byte
- ,
- int
- , short
- , long
- , as well as sbyte
- ,
- ushort
- , uint
- , and ulong
- in .NET) or a
- primitive floating-point type ( float
- , double
- , as
- well as decimal
- in .NET), returns the result of the
- corresponding As* method.
- - If the type is String
- , returns the result of AsString.
- - If the type is
- EDecimal
- , EFloat
- , EInteger
- , or
- ERational
- in the PeterO.Numbers
-
- library (in .NET) or the com.github.peteroupc/numbers
-
- artifact (in Java), returns the result of the corresponding
- As* method.
- - If the type is an enumeration (
- Enum
- ///) type this CBOR object is a text string or an
- integer, returns the appropriate enumerated constant. (For example,
- if MyEnum
- includes an entry for MyValue
- , this method
- will return MyEnum.MyValue
- if the CBOR object represents
- "MyValue"
- or the underlying value for MyEnum.MyValue
- .) Note:
- If an integer is converted to a .NET Enum constant,
- and that integer is shared by more than one constant of the same
- type, it is undefined which constant from among them is returned.
- (For example, if MyEnum.Zero = 0
- and MyEnum.Null = 0
- , converting 0 to MyEnum
- may return either
- MyEnum.Zero
- or MyEnum.Null
- .) As a result, .NET Enum
- types with constants that share an underlying value should not be
- passed to this method.
- - If the type is byte[]
- (a
- one-dimensional byte array) and this CBOR object is a byte string,
- returns a byte array which this CBOR byte string's data will be
- copied to. (This method can't be used to encode CBOR data to a byte
- array; for that, use the EncodeToBytes method instead.)
- - If the type is a one-dimensional array type and this CBOR
- object is an array, returns an array containing the items in this
- CBOR object. (Multidimensional arrays to be documented.)
- - If the type is List or the generic or non-generic IList,
- ICollection, or IEnumerable, (or ArrayList, List, Collection, or
- Iterable in Java), and if this CBOR object is an array, returns an
- object conforming to the type, class, or interface passed to this
- method, where the object will contain all items in this CBOR
- array.
- - If the type is Dictionary or the generic or
- non-generic IDictionary (or HashMap or Map in Java), and if this
- CBOR object is a map, returns an object conforming to the type,
- class, or interface passed to this method, where the object will
- contain all keys and values in this CBOR map.
- - If the
- type is an enumeration constant ("enum"), and this CBOR object is
- an integer or text string, returns the enumeration constant with
- the given number or name, respectively. (Enumeration constants made
- up of multiple enumeration constants, as allowed by .NET, can only
- be matched by number this way.) (To be implemented for
- Java.)
- - Type converters (To be implemented).
- - If the type is DateTime
- (or Date
- in Java) ,
- returns a date/time object if the CBOR object's outermost tag is 0
- or 1.
- - If the type is Uri
- (or URI
- in
- Java), returns a URI object if possible.
- - If the type
- is Guid
- (or UUID
- in Java), returns a UUID object if
- possible.
- - Plain-Old-Data deserialization: If the
- object is a type not specially handled above, the type includes a
- zero-argument constructor (default or not), this CBOR object is a
- CBOR map, and the "mapper" parameter allows this type to be
- eligible for Plain-Old-Data deserialization, then this method
- checks the given type for eligible setters as follows:
- - (*) In the .NET version, eligible setters are the public,
- nonstatic setters of properties with a public, nonstatic getter. If
- a class has two properties of the form "X" and "IsX", where "X" is
- any name, or has multiple properties with the same name, those
- properties are ignored.
- - (*) In the Java version,
- eligible setters are public, nonstatic methods starting with "set"
- followed by a character other than a basic digit or lower-case
- letter, that is, other than "a" to "z" or "0" to "9", that take one
- parameter. The class containing an eligible setter must have a
- public, nonstatic method with the same name, but starting with
- "get" or "is" rather than "set", that takes no parameters and does
- not return void. (For example, if a class has "public
- setValue(String)" and "public getValue()", "setValue" is an
- eligible setter. However, "setValue()" and "setValue(String, int)"
- are not eligible setters.) If a class has two otherwise eligible
- setters with the same name, but different parameter type, they are
- not eligible setters.
- - Then, the method creates an
- object of the given type and invokes each eligible setter with the
- corresponding value in the CBOR map, if any. Key names in the map
- are matched to eligible setters according to the rules described in
- the documentation. Note that
- for security reasons, certain types are not supported even if they
- contain eligible setters.
-
- REMARK: A certain
- consistency between .NET and Java and between FromObject and
- ToObject are sought for version 4.0. It is also hoped that--
- - the ToObject method will support deserializing to
- objects consisting of fields and not getters ("getX()" methods),
- both in .NET and in Java, and
- - both FromObject and
- ToObject will be better designed, in version 4.0, so that
- backward-compatible improvements are easier to make.
-
-
- The type, class, or interface that this method's
- return value will belong to. To express a generic type in Java, see
- the example. Note:
- For security reasons, an application
- should not base this parameter on user input or other externally
- supplied data. Whenever possible, this parameter should be either a
- type specially handled by this method (such as int
- or
- String
- ///) or a plain-old-data type (POCO or POJO type)
- within the control of the application. If the plain-old-data type
- references other data types, those types should likewise meet
- either criterion above.
- This parameter controls which data types are
- eligible for Plain-Old-Data deserialization and includes custom
- converters from CBOR objects to certain data types.
- The parameter is a PODOptions object.
- The converted object.
- The given type
- , or this object's CBOR type, is not
- supported.
- The parameter
- is null.
- The given object's nesting
- is too deep, or another error occurred when serializing the
- object.
- Java offers no easy way to express a generic type, at least
- none as easy as C#'s typeof
- operator. The following example,
- written in Java, is a way to specify that the return value will be
- an ArrayList of String objects.
- Type arrayListString = new ParameterizedType() { public Type[]
- getActualTypeArguments() { // Contains one type parameter, String
- return
- new Type[] { String.class }; } public Type getRawType() { /* Raw type is
- ArrayList */ return ArrayList.class; } public Type getOwnerType() {
- return null; } }; ArrayList<String> array =
- (ArrayList<String>) cborArray.ToObject(arrayListString);
-
- By comparison, the C# version is much shorter.
- var array = (List<String>)cborArray.ToObject(
- typeof(List<String>));
-
-
+Converts this CBOR object to an object of an arbitrary type. The
+ following cases are checked in the logical order given (rather than the
+ strict order in which they are implemented by this library):
+
+
+ - If the type is
+ CBORObject
+ , return this object.
+
+ - If the given object is
+ CBORObject.Null
+ (with or without tags), returns
+ null
+ .
+
+ - If the object is of a type corresponding to a type converter mentioned
+ in the
+
+ parameter, that converter will be used to convert the CBOR object to
+ an object of the given type. Type converters can be used to override
+ the default conversion behavior of almost any object.
+
+ - If the type is
+ object
+ , return this object.
+
+ - If the type is
+ char
+ , converts single-character CBOR text strings and CBOR integers from 0
+ through 65535 to a
+ char
+ object and returns that
+ char
+ object.
+
+ - If the type is
+ bool
+ (
+ boolean
+ in Java), returns the result of AsBoolean.
+
+ - If the type is a primitive integer type (
+ byte
+ ,
+ int
+ ,
+ short
+ ,
+ long
+ , as well as
+ sbyte
+ ,
+ ushort
+ ,
+ uint
+ , and
+ ulong
+ in .NET) or a primitive floating-point type (
+ float
+ ,
+ double
+ , as well as
+ decimal
+ in .NET), returns the result of the corresponding As* method.
+
+ - If the type is
+ String
+ , returns the result of AsString.
+
+ - If the type is
+ EDecimal
+ ,
+ EFloat
+ ,
+ EInteger
+ , or
+ ERational
+ in the
+
+ PeterO.Numbers
+
+ library (in .NET) or the
+
+ com.github.peteroupc/numbers
+
+ artifact (in Java), returns the result of the corresponding As*
+ method.
+
+ - If the type is an enumeration (
+ Enum
+ ///) type this CBOR object is a text string or an integer, returns
+ the appropriate enumerated constant. (For example, if
+ MyEnum
+ includes an entry for
+ MyValue
+ , this method will return
+ MyEnum.MyValue
+ if the CBOR object represents
+ "MyValue"
+ or the underlying value for
+ MyEnum.MyValue
+ .)
+ Note:
+ If an integer is converted to a .NET Enum constant, and that integer
+ is shared by more than one constant of the same type, it is undefined
+ which constant from among them is returned. (For example, if
+ MyEnum.Zero = 0
+ and
+ MyEnum.Null = 0
+ , converting 0 to
+ MyEnum
+ may return either
+ MyEnum.Zero
+ or
+ MyEnum.Null
+ .) As a result, .NET Enum types with constants that share an
+ underlying value should not be passed to this method.
+
+ - If the type is
+ byte[]
+ (a one-dimensional byte array) and this CBOR object is a byte string,
+ returns a byte array which this CBOR byte string's data will be copied
+ to. (This method can't be used to encode CBOR data to a byte array;
+ for that, use the EncodeToBytes method instead.)
+
+ - If the type is a one-dimensional or multidimensional array type and
+ this CBOR object is an array, returns an array containing the items in
+ this CBOR object.
+
+ - If the type is List or the generic or non-generic IList, ICollection,
+ or IEnumerable, (or ArrayList, List, Collection, or Iterable in Java),
+ and if this CBOR object is an array, returns an object conforming to
+ the type, class, or interface passed to this method, where the object
+ will contain all items in this CBOR array.
+
+ - If the type is Dictionary or the generic or non-generic IDictionary
+ (or HashMap or Map in Java), and if this CBOR object is a map, returns
+ an object conforming to the type, class, or interface passed to this
+ method, where the object will contain all keys and values in this CBOR
+ map.
+
+ - If the type is an enumeration constant ("enum"), and this CBOR object
+ is an integer or text string, returns the enumeration constant with
+ the given number or name, respectively. (Enumeration constants made up
+ of multiple enumeration constants, as allowed by .NET, can only be
+ matched by number this way.)
+
+ - If the type is
+ DateTime
+ (or
+ Date
+ in Java) , returns a date/time object if the CBOR object's outermost
+ tag is 0 or 1.
+
+ - If the type is
+ Uri
+ (or
+ URI
+ in Java), returns a URI object if possible.
+
+ - If the type is
+ Guid
+ (or
+ UUID
+ in Java), returns a UUID object if possible.
+
+ - Plain-Old-Data deserialization: If the object is a type not specially
+ handled above, the type includes a zero-argument constructor (default
+ or not), this CBOR object is a CBOR map, and the "mapper" parameter
+ allows this type to be eligible for Plain-Old-Data deserialization,
+ then this method checks the given type for eligible setters as
+ follows:
+
+ - (*) In the .NET version, eligible setters are the public, nonstatic
+ setters of properties with a public, nonstatic getter. If a class has
+ two properties of the form "X" and "IsX", where "X" is any name, or
+ has multiple properties with the same name, those properties are
+ ignored.
+
+ - (*) In the Java version, eligible setters are public, nonstatic
+ methods starting with "set" followed by a character other than a basic
+ digit or lower-case letter, that is, other than "a" to "z" or "0" to
+ "9", that take one parameter. The class containing an eligible setter
+ must have a public, nonstatic method with the same name, but starting
+ with "get" or "is" rather than "set", that takes no parameters and
+ does not return void. (For example, if a class has "public
+ setValue(String)" and "public getValue()", "setValue" is an eligible
+ setter. However, "setValue()" and "setValue(String, int)" are not
+ eligible setters.) If a class has two otherwise eligible setters with
+ the same name, but different parameter type, they are not eligible
+ setters.
+
+ - Then, the method creates an object of the given type and invokes each
+ eligible setter with the corresponding value in the CBOR map, if any.
+ Key names in the map are matched to eligible setters according to the
+ rules described in the
+
+ documentation. Note that for security reasons, certain types are not
+ supported even if they contain eligible setters.
+
+
+ REMARK: A certain consistency between .NET and Java and between
+ FromObject and ToObject are sought for version 4.0. It is also hoped
+ that--
+
+
+ - the ToObject method will support deserializing to objects consisting
+ of fields and not getters ("getX()" methods), both in .NET and in
+ Java, and
+
+ - both FromObject and ToObject will be better designed, in version 4.0,
+ so that backward-compatible improvements are easier to make.
+
+
+
+ The type, class, or interface that this method's return value will belong
+ to. To express a generic type in Java, see the example.
+ Note:
+ For security reasons, an application should not base this parameter on
+ user input or other externally supplied data. Whenever possible, this
+ parameter should be either a type specially handled by this method (such
+ as
+ int
+ or
+ String
+ ///) or a plain-old-data type (POCO or POJO type) within the control of
+ the application. If the plain-old-data type references other data types,
+ those types should likewise meet either criterion above.
+
+ This parameter controls which data types are eligible for Plain-Old-Data
+ deserialization and includes custom converters from CBOR objects to
+ certain data types.
+
+ The parameter
+
+ is a PODOptions object.
+
+ The converted object.
+
+ The given type
+
+ , or this object's CBOR type, is not supported.
+
+ The parameter
+
+ is null.
+
+ The given object's nesting is too deep, or another error occurred when
+ serializing the object.
+
+ Java offers no easy way to express a generic type, at least none as easy
+ as C#'s
+ typeof
+ operator. The following example, written in Java, is a way to specify
+ that the return value will be an ArrayList of String objects.
+
+ Type arrayListString = new ParameterizedType() { public Type[]
+ getActualTypeArguments() { // Contains one type parameter, String return
+ new Type[] { String.class }; } public Type getRawType() { /* Raw type is
+ ArrayList */ return ArrayList.class; } public Type getOwnerType() {
+ return null; } }; ArrayList<String> array =
+ (ArrayList<String>) cborArray.ToObject(arrayListString);
+
+ By comparison, the C# version is much shorter.
+
+ var array = (List<String>)cborArray.ToObject(
+ typeof(List<String>));
+
+
-Converts this CBOR object to an object of an arbitrary
+
+ Converts this CBOR object to an object of an arbitrary
type. See the documentation for the overload of this method taking
a CBORTypeMapper and PODOptions parameters for more information. This method
(without a CBORTypeMapper parameter) allows all data types not
otherwise handled to be eligible for Plain-Old-Data
- serialization.
- The type, class, or interface that this method's
+ serialization.The type, class, or interface that this method's
return value will belong to. To express a generic type in Java, see
the example. Note:
For security reasons, an application
@@ -2674,17 +2737,13 @@ is less than 0, is the size of this array or greater, or is not a 32-bit signed
///) or a plain-old-data type (POCO or POJO type)
within the control of the application. If the plain-old-data type
references other data types, those types should likewise meet
- either criterion above.
- The parameter is a PODOptions object.
- The converted object.
- The given type
+ either criterion above.The parameter is a PODOptions object.The converted object.The given type
, or this object's CBOR type, is not
- supported.
- The parameter
- is null.
- The given object's nesting
+ supported.The parameter
+ is null.The given object's nesting
is too deep, or another error occurred when serializing the
object.
+
@@ -2700,12 +2759,11 @@ is less than 0, is the size of this array or greater, or is not a 32-bit signed
-Converts this CBOR object to an object of an arbitrary type.
+
+ Converts this CBOR object to an object of an arbitrary type.
See
for
- further information.
- The parameter is not documented yet.
- The type, class, or interface that this
+ further information.The parameter is not documented yet.The type, class, or interface that this
method's return value will belong to. Note: For security
reasons, an application should not base this parameter on user
input or other externally supplied data. Whenever possible, this
@@ -2713,19 +2771,16 @@ is less than 0, is the size of this array or greater, or is not a 32-bit signed
(such as int or String ) or a plain-old-data type
(POCO type) within the control of the application. If the
plain-old-data type references other data types, those types should
- likewise meet either criterion above.
- The converted object.
- The given type
+ likewise meet either criterion above.The converted object.The given type
"T", or this object's CBOR type, is not supported.
+
-Converts this CBOR object to an object of an arbitrary type.
+
+ Converts this CBOR object to an object of an arbitrary type.
See
for
- further information.
- The parameter is not documented yet.
- The parameter is not documented yet.
- The type, class, or interface that this
+ further information.The parameter is not documented yet.The parameter is not documented yet.The type, class, or interface that this
method's return value will belong to. Note: For security
reasons, an application should not base this parameter on user
input or other externally supplied data. Whenever possible, this
@@ -2733,18 +2788,16 @@ is less than 0, is the size of this array or greater, or is not a 32-bit signed
(such as int or String ) or a plain-old-data type
(POCO type) within the control of the application. If the
plain-old-data type references other data types, those types should
- likewise meet either criterion above.
- The converted object.
- The given type
+ likewise meet either criterion above.The converted object.The given type
"T", or this object's CBOR type, is not supported.
+
-Converts this CBOR object to an object of an arbitrary type.
+
+ Converts this CBOR object to an object of an arbitrary type.
See
for
- further information.
- The parameter is not documented yet.
- The type, class, or interface that this
+ further information.The parameter is not documented yet.The type, class, or interface that this
method's return value will belong to. Note: For security
reasons, an application should not base this parameter on user
input or other externally supplied data. Whenever possible, this
@@ -2752,10 +2805,9 @@ is less than 0, is the size of this array or greater, or is not a 32-bit signed
(such as int or String ) or a plain-old-data type
(POCO type) within the control of the application. If the
plain-old-data type references other data types, those types should
- likewise meet either criterion above.
- The converted object.
- The given type
+ likewise meet either criterion above.The converted object.The given type
"T", or this object's CBOR type, is not supported.
+
@@ -2993,13 +3045,22 @@ CBOR objects to JSON strings, use the The value to write.A writable data stream.The parameter
- is null.The parameter
- is a surrogate code point.An I/O error
- occurred.
-
+Writes a Unicode character as a string in CBOR format to a data stream.
+
+ The value to write.
+
+ A writable data stream.
+
+ The parameter
+
+ is null.
+
+ The parameter
+
+ is a surrogate code point.
+
+ An I/O error occurred.
+
diff --git a/CBORTest/CBORExtraTest.cs b/CBORTest/CBORExtraTest.cs
index ab571185..dceba5d4 100644
--- a/CBORTest/CBORExtraTest.cs
+++ b/CBORTest/CBORExtraTest.cs
@@ -386,7 +386,7 @@ from i in RangeExclusive(0, 10)
[Test]
public void TestMultidimArray() {
- int[, ] arr = { { 0, 1, 99 }, { 2, 3, 299 } };
+ int[,] arr = { { 0, 1, 99 }, { 2, 3, 299 } };
var cbor = CBORObject.FromObject(arr);
Assert.AreEqual(0, cbor[0][0].AsInt32());
Assert.AreEqual(1, cbor[0][1].AsInt32());
@@ -394,9 +394,9 @@ public void TestMultidimArray() {
Assert.AreEqual(2, cbor[1][0].AsInt32());
Assert.AreEqual(3, cbor[1][1].AsInt32());
Assert.AreEqual(299, cbor[1][2].AsInt32());
- var arr2 = cbor.ToObject(typeof(int[, ]));
+ var arr2 = cbor.ToObject(typeof(int[,]));
Assert.AreEqual(arr, arr2);
- int[, , ] arr3 = { { { 0, 1 }, { 99, 100 } }, { { 2, 3 }, { 299, 300 } }
+ int[,,] arr3 = { { { 0, 1 }, { 99, 100 } }, { { 2, 3 }, { 299, 300 } }
};
cbor = CBORObject.FromObject(arr3);
Assert.AreEqual(0, cbor[0][0][0].AsInt32());
@@ -405,7 +405,7 @@ public void TestMultidimArray() {
Assert.AreEqual(100, cbor[0][1][1].AsInt32());
Assert.AreEqual(2, cbor[1][0][0].AsInt32());
Assert.AreEqual(299, cbor[1][1][0].AsInt32());
- var arr4 = cbor.ToObject(typeof(int[, , ]));
+ var arr4 = cbor.ToObject(typeof(int[,,]));
Assert.AreEqual(arr3, arr4);
}
diff --git a/CBORTest/CBORObjectTest.cs b/CBORTest/CBORObjectTest.cs
index 7105b0eb..200dbfcf 100644
--- a/CBORTest/CBORObjectTest.cs
+++ b/CBORTest/CBORObjectTest.cs
@@ -2443,6 +2443,12 @@ public void TestFromObject() {
throw new InvalidOperationException(String.Empty, ex);
}
try {
+ ToObjectTest.TestToFromObjectRoundTrip('\udddd');
+} catch (Exception ex) {
+Assert.Fail(ex.ToString());
+throw new InvalidOperationException(String.Empty, ex);
+}
+ try {
CBORObject.FromObject(CBORObject.NewArray().Keys);
Assert.Fail("Should have failed");
} catch (InvalidOperationException) {
diff --git a/CBORTest/CBORSupplementTest.cs b/CBORTest/CBORSupplementTest.cs
index 3e352a12..d2a1c4c5 100644
--- a/CBORTest/CBORSupplementTest.cs
+++ b/CBORTest/CBORSupplementTest.cs
@@ -160,15 +160,6 @@ public CBORObject ToCBORObject(Uri obj) {
[Test]
public void TestCBORObjectArgumentValidation() {
- try {
- ToObjectTest.TestToFromObjectRoundTrip('\udddd');
- Assert.Fail("Should have failed");
- } catch (ArgumentException) {
-// NOTE: Intentionally empty
-} catch (Exception ex) {
- Assert.Fail(ex.ToString());
- throw new InvalidOperationException(String.Empty, ex);
- }
Assert.AreEqual(
CBORObject.Null,
ToObjectTest.TestToFromObjectRoundTrip((byte[])null));
diff --git a/CBORTest/CBORTest.cs b/CBORTest/CBORTest.cs
index 7e3d58cf..557a9119 100644
--- a/CBORTest/CBORTest.cs
+++ b/CBORTest/CBORTest.cs
@@ -539,9 +539,10 @@ public void TestDecimalFracMantissaMayBeBignum() {
public void TestBigFloatFracMantissaMayBeBignum() {
CBORObject o = CBORTestCommon.FromBytesTestAB(
new byte[] { 0xc5, 0x82, 0x3, 0xc2, 0x41, 1 });
- Assert.AreEqual(
- 0,
- EFloat.FromString("8").CompareTo(o.AsEFloat()));
+ {
+long numberTemp = EFloat.FromString("8").CompareTo(o.AsEFloat());
+Assert.AreEqual(0, numberTemp);
+}
}
[Test]
diff --git a/CBORTest/PODClass.cs b/CBORTest/PODClass.cs
index b6505622..a6a37b46 100644
--- a/CBORTest/PODClass.cs
+++ b/CBORTest/PODClass.cs
@@ -14,7 +14,8 @@ public PODClass() {
}
public bool HasGoodPrivateProp() {
- return this.PrivatePropA == 2;
+ int ppa = this.PrivatePropA;
+ return ppa == 2;
}
private int PrivatePropA { get; }
diff --git a/CBORTest/ToObjectTest.cs b/CBORTest/ToObjectTest.cs
index e0ae5d20..4dd8ff96 100644
--- a/CBORTest/ToObjectTest.cs
+++ b/CBORTest/ToObjectTest.cs
@@ -953,11 +953,6 @@ public void TestAsInt64() {
}
}
[Test]
- public void TestAsSByte() {
- // not implemented yet
- }
- [Test]
- [Ignore]
public void TestAsSingle() {
try {
CBORObject.NewArray().ToObject(typeof(float));
@@ -1022,9 +1017,8 @@ public void TestAsSingle() {
(string)numberinfo["number"].ToObject(typeof(string))));
var f1 = (float)EDecimal.FromString((string)numberinfo["number"].ToObject(typeof(string))).ToSingle();
Object f2 = cbornumber.ToObject(typeof(float));
- if (((object)f1).Equals(f2)) {
- { Assert.Fail();
-}
+ if (!((object)f1).Equals(f2)) {
+ Assert.Fail();
}
}
}
@@ -1195,12 +1189,8 @@ public void TestShortRoundTrip() {
}
[Test]
- [Ignore]
public void TestCharRoundTrip() {
for (var i = 0; i < 0x10000; ++i) {
- if ((i & 0xf800) == 0xd800) {
- continue;
- }
var c = (char)i;
TestToFromObjectRoundTrip(c);
}
diff --git a/docs/PeterO.Cbor.CBORObject.md b/docs/PeterO.Cbor.CBORObject.md
index 061182a9..991a57d8 100644
--- a/docs/PeterO.Cbor.CBORObject.md
+++ b/docs/PeterO.Cbor.CBORObject.md
@@ -104,7 +104,6 @@ The ReadJSON and FromJSONString methods currently have nesting depths of 1000.
* [FromObject(System.Decimal)](#FromObject_System_Decimal)
- Converts a .
* [FromObject(bool)](#FromObject_bool)
- Returns the CBOR true value or false value, depending on "value".
* [FromObject(byte)](#FromObject_byte)
- Generates a CBOR object from a byte (0 to 255).
-* [FromObject(char)](#FromObject_char)
- Generates a CBOR string object from a Unicode character.
* [FromObject(double)](#FromObject_double)
- Generates a CBOR object from a 64-bit floating-point number.
* [FromObject(float)](#FromObject_float)
- Generates a CBOR object from a 32-bit floating-point number.
* [FromObject(int)](#FromObject_int)
- Generates a CBOR object from a 32-bit signed integer.
@@ -198,7 +197,6 @@ The ReadJSON and FromJSONString methods currently have nesting depths of 1000.
* [Write(PeterO.Numbers.ERational, System.IO.Stream)](#Write_PeterO_Numbers_ERational_System_IO_Stream)
- Writes a rational number in CBOR format to a data stream.
* [Write(bool, System.IO.Stream)](#Write_bool_System_IO_Stream)
- Writes a Boolean value in CBOR format to a data stream.
* [Write(byte, System.IO.Stream)](#Write_byte_System_IO_Stream)
- Writes a byte (0 to 255) in CBOR format to a data stream.
-* [Write(char, System.IO.Stream)](#Write_char_System_IO_Stream)
- Writes a Unicode character as a string in CBOR format to a data stream.
* [Write(double, System.IO.Stream)](#Write_double_System_IO_Stream)
- Writes a 64-bit floating-point number in CBOR format to a data stream.
* [Write(float, System.IO.Stream)](#Write_float_System_IO_Stream)
- Writes a 32-bit floating-point number in CBOR format to a data stream.
* [Write(int, System.IO.Stream)](#Write_int_System_IO_Stream)
- Writes a 32-bit signed integer in CBOR format to a data stream.
@@ -1372,29 +1370,6 @@ The following example encodes a text string to a UTF-8 byte array, then uses the
A CBOR byte string object where each byte of the given byte array is copied to a new array, or CBORObject.Null if the value is null.
-
-### FromObject
-
- public static PeterO.Cbor.CBORObject FromObject(
- char value);
-
-Generates a CBOR string object from a Unicode character.
-
-Parameters:
-
- * value: The parameter value
- is a char object.
-
-Return Value:
-
-A CBORObject object.
-
-Exceptions:
-
- * System.ArgumentException:
-The parameter value
- is a surrogate code point.
-
### FromObject
@@ -1555,7 +1530,7 @@ Generates a CBORObject from an arbitrary object, using the given options to cont
* If the object is of a type corresponding to a type converter mentioned in the mapper
parameter, that converter will be used to convert the object to a CBOR object. Type converters can be used to override the default conversion behavior of almost any object.
- * A `char` is... (to be implemented).
+ * A `char` is converted to an integer (from 0 through 65535), and returns a CBOR object of that integer. (This is a change in version 4.0 from previous versions, which converted `char` , except surrogate code points from 0xd800 through 0xdfff, into single-character text strings.)
* A `bool` ( `boolean` in Java) is converted to `CBORObject.True` or `CBORObject.False` .
@@ -2724,27 +2699,13 @@ The given object's nesting is too deep, or another error occurred when serializi
System.Type t,
PeterO.Cbor.CBORTypeMapper mapper);
-Converts this CBOR object to an object of an arbitrary type. See the documentation for the overload of this method taking a CBORTypeMapper parameter for more information. This method (without a CBORTypeMapper parameter) allows all data types not otherwise handled to be eligible for Plain-Old-Data serialization.
-
-Java offers no easy way to express a generic type, at least none as easy as C#'s `typeof` operator. The following example, ritten in Java, is a way to specify that the return value will be n ArrayList of String objects.
-
- Type arrayListString = new ParameterizedType(){ public Type[]
- getActualTypeArguments(){ /* Contains one type parameter, String */
- return new Type[]{ String.class }; } public Type getRawType(){ /* Raw
- type is ArrayList */ return ArrayList.class; } public Type
- getOwnerType(){ return null; } }; ArrayList array =
- (ArrayList) cborArray.ToObject(arrayListString);
-
-By comparison, the C# version is much shorter.
-
- var array = (List)cborArray.ToObject(
- typeof(List));
+Converts this CBOR object to an object of an arbitrary type. See the documentation for the overload of this method taking a CBORTypeMapper and PODOptions parameters parameters for more information.
Parameters:
- * t: The type, class, or interface that this method's return value will belong to. To express a generic type in Java, see the example. Note:For security reasons, an application hould not base this parameter on user input or other externally upplied data. Whenever possible, this parameter should be either a ype specially handled by this method (such as `int` or `String` ) or a plain-old-data type (POCO or POJO type) within he control of the application. If the plain-old-data type eferences other data types, those types should likewise meet ither criterion above.
+ * t: The type, class, or interface that this method's return value will belong to. To express a generic type in Java, see the example. Note:For security reasons, an application hould not base this parameter on user input or other externally upplied data. Whenever possible, this parameter should be either a ype specially handled by this method (such as `int` or `String` ///) or a plain-old-data type (POCO or POJO type) ithin the control of the application. If the plain-old-data type eferences other data types, those types should likewise meet ither criterion above.
- * mapper: A CBORTypeMapper object.
+ * mapper: This parameter controls which data types are eligible for Plain-Old-Data deserialization and includes custom converters from CBOR objects to certain data types.
Return Value:
@@ -2775,42 +2736,40 @@ Converts this CBOR object to an object of an arbitrary type. The following cases
* If the type is `CBORObject` , return this object.
- * If the given object is `CBORObject.Null` (with or without tags), returns `null` .
+ * If the given object is `CBORObject.Null` (with or without tags), returns `null` .
- * If the object is of a type corresponding to a type converter mentioned in the mapper
-parameter, that converter will be used to convert the CBOR object to an object of the given type. Type converters can be used to override the default conversion behavior of almost any object.
+ * If the object is of a type corresponding to a type converter mentioned in the mapper
+parameter, that converter will be used to convert the CBOR object to n object of the given type. Type converters can be used to override he default conversion behavior of almost any object.
- * If the type is `object` , return this bject.
+ * If the type is `object` , return this object.
- * If the type is `char` ... (To be mplemented).
+ * If the type is `char` , converts single-character CBOR text strings and CBOR integers from 0 through 65535 to a `char` object and returns that `char` object.
- * If the type is `bool` ( `boolean` in Java), returns the result of AsBoolean.
+ * If the type is `bool` ( `boolean` in Java), returns the result of AsBoolean.
- * If the type is a primitive integer type ( `byte` , `int` , `short` , `long` , as well as `sbyte` , `ushort` , `uint` , and `ulong` in .NET) or a rimitive floating-point type ( `float` , `double` , as ell as `decimal` in .NET), returns the result of the orresponding As* method.
+ * If the type is a primitive integer type ( `byte` , `int` , `short` , `long` , as well as `sbyte` , `ushort` , `uint` , and `ulong` in .NET) or a primitive floating-point type ( `float` , `double` , as well as `decimal` in .NET), returns the result of the corresponding As* method.
- * If the type is `String` , returns the result of AsString.
+ * If the type is `String` , returns the result of AsString.
- * If the type is `EDecimal` , `EFloat` , `EInteger` , or `ERational` in the `PeterO.Numbers` library (in .NET) or the `com.github.peteroupc/numbers` artifact (in Java), returns the result of the corresponding s* method.
+ * If the type is `EDecimal` , `EFloat` , `EInteger` , or `ERational` in the `PeterO.Numbers` library (in .NET) or the `com.github.peteroupc/numbers` artifact (in Java), returns the result of the corresponding As* ethod.
- * If the type is an enumeration ( `Enum` ///) type this CBOR object is a text string or an nteger, returns the appropriate enumerated constant. (For example, f `MyEnum` includes an entry for `MyValue` , this method ill return `MyEnum.MyValue` if the CBOR object represents `"MyValue"` or the underlying value for `MyEnum.MyValue` .) Note:If an integer is converted to a .NET Enum constant, nd that integer is shared by more than one constant of the same ype, it is undefined which constant from among them is returned. For example, if `MyEnum.Zero = 0` and `MyEnum.Null = 0` , converting 0 to `MyEnum` may return either `MyEnum.Zero` or `MyEnum.Null` .) As a result, .NET Enum ypes with constants that share an underlying value should not be assed to this method.
+ * If the type is an enumeration ( `Enum` ///) type this CBOR object is a text string or an integer, returns he appropriate enumerated constant. (For example, if `MyEnum` includes an entry for `MyValue` , this method will return `MyEnum.MyValue` if the CBOR object represents `"MyValue"` or the underlying value for `MyEnum.MyValue` .)Note:If an integer is converted to a .NET Enum constant, and that integer s shared by more than one constant of the same type, it is undefined hich constant from among them is returned. (For example, if `MyEnum.Zero = 0` and `MyEnum.Null = 0` , converting 0 to `MyEnum` may return either `MyEnum.Zero` or `MyEnum.Null` .) As a result, .NET Enum types with constants that share an nderlying value should not be passed to this method.
- * If the type is `byte[]` (a ne-dimensional byte array) and this CBOR object is a byte string, eturns a byte array which this CBOR byte string's data will be opied to. (This method can't be used to encode CBOR data to a byte rray; for that, use the EncodeToBytes method instead.)
+ * If the type is `byte[]` (a one-dimensional byte array) and this CBOR object is a byte string, eturns a byte array which this CBOR byte string's data will be copied o. (This method can't be used to encode CBOR data to a byte array; or that, use the EncodeToBytes method instead.)
- * If the type is a one-dimensional array type and this CBOR object is an array, returns an array containing the items in this CBOR object. (Multidimensional arrays to be documented.)
+ * If the type is a one-dimensional or multidimensional array type and this CBOR object is an array, returns an array containing the items in this CBOR object.
* If the type is List or the generic or non-generic IList, ICollection, or IEnumerable, (or ArrayList, List, Collection, or Iterable in Java), and if this CBOR object is an array, returns an object conforming to the type, class, or interface passed to this method, where the object will contain all items in this CBOR array.
* If the type is Dictionary or the generic or non-generic IDictionary (or HashMap or Map in Java), and if this CBOR object is a map, returns an object conforming to the type, class, or interface passed to this method, where the object will contain all keys and values in this CBOR map.
- * If the type is an enumeration constant ("enum"), and this CBOR object is an integer or text string, returns the enumeration constant with the given number or name, respectively. (Enumeration constants made up of multiple enumeration constants, as allowed by .NET, can only be matched by number this way.) (To be implemented for Java.)
+ * If the type is an enumeration constant ("enum"), and this CBOR object is an integer or text string, returns the enumeration constant with the given number or name, respectively. (Enumeration constants made up of multiple enumeration constants, as allowed by .NET, can only be matched by number this way.)
- * Type converters (To be implemented).
+ * If the type is `DateTime` (or `Date` in Java) , returns a date/time object if the CBOR object's outermost ag is 0 or 1.
- * If the type is `DateTime` (or `Date` in Java) , eturns a date/time object if the CBOR object's outermost tag is 0 r 1.
+ * If the type is `Uri` (or `URI` in Java), returns a URI object if possible.
- * If the type is `Uri` (or `URI` in ava), returns a URI object if possible.
-
- * If the type is `Guid` (or `UUID` in Java), returns a UUID object if ossible.
+ * If the type is `Guid` (or `UUID` in Java), returns a UUID object if possible.
* Plain-Old-Data deserialization: If the object is a type not specially handled above, the type includes a zero-argument constructor (default or not), this CBOR object is a CBOR map, and the "mapper" parameter allows this type to be eligible for Plain-Old-Data deserialization, then this method checks the given type for eligible setters as follows:
@@ -2818,7 +2777,7 @@ parameter, that converter will be used to convert the CBOR object to an object o
* (*) In the Java version, eligible setters are public, nonstatic methods starting with "set" followed by a character other than a basic digit or lower-case letter, that is, other than "a" to "z" or "0" to "9", that take one parameter. The class containing an eligible setter must have a public, nonstatic method with the same name, but starting with "get" or "is" rather than "set", that takes no parameters and does not return void. (For example, if a class has "public setValue(String)" and "public getValue()", "setValue" is an eligible setter. However, "setValue()" and "setValue(String, int)" are not eligible setters.) If a class has two otherwise eligible setters with the same name, but different parameter type, they are not eligible setters.
- * Then, the method creates an object of the given type and invokes each eligible setter with the corresponding value in the CBOR map, if any. Key names in the map are matched to eligible setters according to the rules described in the [PeterO.Cbor.PODOptions](PeterO.Cbor.PODOptions.md) documentation. Note that for security reasons, certain types are not supported even if they contain eligible setters.
+ * Then, the method creates an object of the given type and invokes each eligible setter with the corresponding value in the CBOR map, if any. Key names in the map are matched to eligible setters according to the rules described in the[PeterO.Cbor.PODOptions](PeterO.Cbor.PODOptions.md)documentation. Note that for security reasons, certain types are not upported even if they contain eligible setters.
REMARK: A certain consistency between .NET and Java and between FromObject and ToObject are sought for version 4.0. It is also hoped that--
@@ -2826,27 +2785,28 @@ REMARK: A certain consistency between .NET and Java and between FromObject and T
* both FromObject and ToObject will be better designed, in version 4.0, so that backward-compatible improvements are easier to make.
-Java offers no easy way to express a generic type, at least none as easy as C#'s `typeof` operator. The following example, ritten in Java, is a way to specify that the return value will be n ArrayList of String objects.
+Java offers no easy way to express a generic type, at least none as easy as C#'s `typeof` operator. The following example, written in Java, is a way to specify hat the return value will be an ArrayList of String objects.
Type arrayListString = new ParameterizedType() { public Type[]
- getActualTypeArguments() { // Contains one type parameter, String return
- new Type[] { String.class }; } public Type getRawType() { /* Raw type is
- ArrayList */ return ArrayList.class; } public Type getOwnerType() {
- return null; } }; ArrayList array =
- (ArrayList) cborArray.ToObject(arrayListString);
+ getActualTypeArguments() { // Contains one type parameter, String return
+ new Type[] { String.class }; } public Type getRawType() { /* Raw type is
+ ArrayList */ return ArrayList.class; } public Type getOwnerType() {
+ return null; } }; ArrayList array =
+ (ArrayList) cborArray.ToObject(arrayListString);
By comparison, the C# version is much shorter.
var array = (List)cborArray.ToObject(
- typeof(List));
+ typeof(List));
Parameters:
- * t: The type, class, or interface that this method's return value will belong to. To express a generic type in Java, see the example. Note:For security reasons, an application hould not base this parameter on user input or other externally upplied data. Whenever possible, this parameter should be either a ype specially handled by this method (such as `int` or `String` ///) or a plain-old-data type (POCO or POJO type) ithin the control of the application. If the plain-old-data type eferences other data types, those types should likewise meet ither criterion above.
+ * t: The type, class, or interface that this method's return value will belong to. To express a generic type in Java, see the example.Note:For security reasons, an application should not base this parameter on ser input or other externally supplied data. Whenever possible, this arameter should be either a type specially handled by this method (such s `int` or `String` ///) or a plain-old-data type (POCO or POJO type) within the control of he application. If the plain-old-data type references other data types, hose types should likewise meet either criterion above.
* mapper: This parameter controls which data types are eligible for Plain-Old-Data deserialization and includes custom converters from CBOR objects to certain data types.
- * options: A PODOptions object.
+ * options: The parameter options
+is a PODOptions object.
Return Value:
@@ -2856,11 +2816,11 @@ The converted object.
* System.NotSupportedException:
The given type t
- , or this object's CBOR type, is not supported.
+, or this object's CBOR type, is not supported.
* System.ArgumentNullException:
The parameter t
- is null.
+is null.
* System.CBORException:
The given object's nesting is too deep, or another error occurred when serializing the object.
@@ -2872,27 +2832,14 @@ The given object's nesting is too deep, or another error occurred when serializi
System.Type t,
PeterO.Cbor.PODOptions options);
-Converts this CBOR object to an object of an arbitrary type. See the documentation for the overload of this method taking a CBORTypeMapper parameter for more information. This method (without a CBORTypeMapper parameter) allows all data types not otherwise handled to be eligible for Plain-Old-Data serialization.
-
-Java offers no easy way to express a generic type, at least none as easy as C#'s `typeof` operator. The following example, ritten in Java, is a way to specify that the return value will be n ArrayList of String objects.
-
- Type arrayListString = new ParameterizedType(){ public Type[]
- getActualTypeArguments(){ /* Contains one type parameter, String */
- return new Type[]{ String.class }; } public Type getRawType(){ /* Raw
- type is ArrayList */ return ArrayList.class; } public Type
- getOwnerType(){ return null; } }; ArrayList array =
- (ArrayList) cborArray.ToObject(arrayListString);
-
-By comparison, the C# version is much shorter.
-
- var array = (List)cborArray.ToObject(
- typeof(List));
+Converts this CBOR object to an object of an arbitrary type. See the documentation for the overload of this method taking a CBORTypeMapper and PODOptions parameters for more information. This method (without a CBORTypeMapper parameter) allows all data types not otherwise handled to be eligible for Plain-Old-Data serialization.
Parameters:
- * t: The type, class, or interface that this method's return value will belong to. To express a generic type in Java, see the example. Note:For security reasons, an application hould not base this parameter on user input or other externally upplied data. Whenever possible, this parameter should be either a ype specially handled by this method (such as `int` or `String` ) or a plain-old-data type (POCO or POJO type) within he control of the application. If the plain-old-data type eferences other data types, those types should likewise meet ither criterion above.
+ * t: The type, class, or interface that this method's return value will belong to. To express a generic type in Java, see the example. Note:For security reasons, an application hould not base this parameter on user input or other externally upplied data. Whenever possible, this parameter should be either a ype specially handled by this method (such as `int` or `String` ///) or a plain-old-data type (POCO or POJO type) ithin the control of the application. If the plain-old-data type eferences other data types, those types should likewise meet ither criterion above.
- * options: A PODOptions object.
+ * options: The parameter options
+ is a PODOptions object.
Return Value:
@@ -2921,7 +2868,8 @@ Converts this CBOR object to an object of an arbitrary type. See**PeterO.Cbor.CB
Parameters:
- * mapper: Not documented yet.
+ * mapper: The parameter mapper
+ is not documented yet.
* <T>: The type, class, or interface that this method's return value will belong to. Note: For security reasons, an application should not base this parameter on user input or other externally supplied data. Whenever possible, this parameter should be either a type specially handled by this method (such as `int` or `String` ) or a plain-old-data type (POCO type) within the control of the application. If the plain-old-data type references other data types, those types should likewise meet either criterion above.
@@ -2945,9 +2893,11 @@ Converts this CBOR object to an object of an arbitrary type. See**PeterO.Cbor.CB
Parameters:
- * mapper: Not documented yet.
+ * mapper: The parameter mapper
+ is not documented yet.
- * options: Not documented yet.
+ * options: The parameter options
+ is not documented yet.
* <T>: The type, class, or interface that this method's return value will belong to. Note: For security reasons, an application should not base this parameter on user input or other externally supplied data. Whenever possible, this parameter should be either a type specially handled by this method (such as `int` or `String` ) or a plain-old-data type (POCO type) within the control of the application. If the plain-old-data type references other data types, those types should likewise meet either criterion above.
@@ -2970,7 +2920,8 @@ Converts this CBOR object to an object of an arbitrary type. See**PeterO.Cbor.CB
Parameters:
- * options: Not documented yet.
+ * options: The parameter options
+ is not documented yet.
* <T>: The type, class, or interface that this method's return value will belong to. Note: For security reasons, an application should not base this parameter on user input or other externally supplied data. Whenever possible, this parameter should be either a type specially handled by this method (such as `int` or `String` ) or a plain-old-data type (POCO type) within the control of the application. If the plain-old-data type references other data types, those types should likewise meet either criterion above.
@@ -3084,34 +3035,6 @@ The parameter stream
* System.IO.IOException:
An I/O error occurred.
-
-### Write
-
- public static void Write(
- char value,
- System.IO.Stream stream);
-
-Writes a Unicode character as a string in CBOR format to a data stream.
-
-Parameters:
-
- * value: The value to write.
-
- * stream: A writable data stream.
-
-Exceptions:
-
- * System.ArgumentNullException:
-The parameter stream
- is null.
-
- * System.ArgumentException:
-The parameter value
- is a surrogate code point.
-
- * System.IO.IOException:
-An I/O error occurred.
-
### Write