|
69 | 69 | * without such synchronization.</p> <p>One kind of CBOR object is |
70 | 70 | * called a map, or a list of key-value pairs. Keys can be any kind of |
71 | 71 | * CBOR object, including numbers, strings, arrays, and maps. However, |
72 | | - * text strings are the most suitable to ((use instanceof keys) ? |
73 | | - * (keys)use : null); other kinds of CBOR object are much better used as |
74 | | - * map values instead, keeping in mind that some of them are not thread |
75 | | - * safe without synchronizing reads and writes to them.</p> <p>To find |
76 | | - * the type of a CBOR object, call its Type property (or "getType()" in |
77 | | - * Java). The return value can be Number, Boolean, SimpleValue, or |
78 | | - * TextString for immutable CBOR objects, and Array, Map, or ByteString |
79 | | - * for mutable CBOR objects.</p> <p><b>Nesting Depth:</b></p> <p>The |
80 | | - * DecodeFromBytes method can only read objects with a limited maximum |
81 | | - * depth of arrays and maps nested within other arrays and maps. The |
82 | | - * code sets this maximum depth to 500 (allowing more than enough |
83 | | - * nesting for most purposes), but it's possible that stack overflows in |
84 | | - * some runtimes might lower the effective maximum nesting depth. When |
85 | | - * the nesting depth goes above 500, the DecodeFromBytes method throws a |
86 | | - * CBORException.</p> |
| 72 | + * text strings are the most suitable to use as keys; other kinds of |
| 73 | + * CBOR object are much better used as map values instead, keeping in |
| 74 | + * mind that some of them are not thread safe without synchronizing |
| 75 | + * reads and writes to them.</p> <p>To find the type of a CBOR object, |
| 76 | + * call its Type property (or "getType()" in Java). The return value can |
| 77 | + * be Number, Boolean, SimpleValue, or TextString for immutable CBOR |
| 78 | + * objects, and Array, Map, or ByteString for mutable CBOR objects.</p> |
| 79 | + * <p><b>Nesting Depth:</b></p> <p>The DecodeFromBytes method can only |
| 80 | + * read objects with a limited maximum depth of arrays and maps nested |
| 81 | + * within other arrays and maps. The code sets this maximum depth to 500 |
| 82 | + * (allowing more than enough nesting for most purposes), but it's |
| 83 | + * possible that stack overflows in some runtimes might lower the |
| 84 | + * effective maximum nesting depth. When the nesting depth goes above |
| 85 | + * 500, the DecodeFromBytes method throws a CBORException.</p> |
87 | 86 | */ |
88 | 87 | public final class CBORObject implements Comparable<CBORObject> { |
89 | 88 | private static CBORObject ConstructSimpleValue(int v) { |
@@ -1048,7 +1047,33 @@ public static <TKey, TValue> CBORObject FromObject(Map<TKey, |
1048 | 1047 | } |
1049 | 1048 |
|
1050 | 1049 | /** |
1051 | | - * |
| 1050 | + * Generates a CBORObject from an arbitrary object. The following types are |
| 1051 | + * specially handled by this method: null , primitive types, strings, |
| 1052 | + * CBORObject , ExtendedDecimal , ExtendedFloat , ExtendedRational, the |
| 1053 | + * custom BigInteger , lists, arrays, enumerations (<code>Enum</code> |
| 1054 | + * objects), and maps.<p>In the .NET version, if the object is a type |
| 1055 | + * not specially handled by this method, returns a CBOR map with the |
| 1056 | + * values of each of its read/write properties (or all properties in the |
| 1057 | + * case of an anonymous type). Properties are converted to their |
| 1058 | + * camel-case names (meaning if a name starts with A to Z, that letter |
| 1059 | + * is lower-cased). If the property name begins with the word "Is", that |
| 1060 | + * word is deleted from the name. Also, .NET <code>Enum</code> objects will be |
| 1061 | + * converted to their integer values, and a multidimensional array is |
| 1062 | + * converted to an array of arrays.</p> <p>In the Java version, if the |
| 1063 | + * object is a type not specially handled by this method, this method |
| 1064 | + * checks the CBOR object for methods starting with the word "get" or |
| 1065 | + * "is" that take no parameters, and returns a CBOR map with one entry |
| 1066 | + * for each such method found. For each method found, the starting word |
| 1067 | + * "get" or "is" is deleted from its name, and the name is converted to |
| 1068 | + * camel case (meaning if a name starts with A to Z, that letter is |
| 1069 | + * lower-cased). Also, Java <code>Enum</code> objects will be converted to the |
| 1070 | + * result of their name method.</p> <p>If the input is a byte array, the |
| 1071 | + * byte array is copied to a new byte array. (This method can't be used |
| 1072 | + * to decode CBOR data from a byte array; for that, use the |
| 1073 | + * DecodeFromBytes method instead.).</p> |
| 1074 | + * @param obj An arbitrary object. |
| 1075 | + * @return A CBOR object corresponding to the given object. Returns |
| 1076 | + * CBORObject.Null if the object is null. |
1052 | 1077 | */ |
1053 | 1078 | public static CBORObject FromObject(Object obj) { |
1054 | 1079 | if (obj == null) { |
|
0 commit comments