Class CBORizer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvert the given object into an instance ofCBORItemsubclass.cborizeBigInteger(BigInteger value) Create aCBORBigIntegerinstance with the given value.cborizeBoolean(boolean value) ReturnCBORBoolean.FALSEorCBORBoolean.TRUEaccording to the given value.cborizeByteArray(byte[] value) Create aCBORByteArrayinstance with the given value.cborizeCollection(Collection<?> collection) Create aCBORItemListinstance with the given collection.cborizeDouble(double value) Create aCBORDoubleinstance with the given value.cborizeFloat(float value) Create aCBORFloatinstance with the given value.cborizeInteger(int value) Create aCBORIntegerinstance with the given value.cborizeLong(long value) Create aCBORLonginstance with the given value.cborizeMap(Map<?, ?> map) Create aCBORPairListinstance with the given map.cborizeObject(Object object) Convert the given object into an instance ofCBORItemsubclass.cborizeString(String value) Create aCBORStringinstance with the given value.Get the parser that interprets the CBOR Diagnostic Notation.Get the prefix to indicate that the substring of the string given to thecborizeString(String)method should be interpreted as the CBOR Diagnostic Notation.Set the parser that interprets the CBOR Diagnostic Notation.setDiagnosticNotationPrefix(String prefix) Set the prefix to indicate that the substring of the string given to thecborizeString(String)method should be interpreted as the CBOR Diagnostic Notation.
-
Constructor Details
-
CBORizer
public CBORizer()
-
-
Method Details
-
getDiagnosticNotationPrefix
Get the prefix to indicate that the substring of the string given to thecborizeString(String)method should be interpreted as the CBOR Diagnostic Notation.- Returns:
- The prefix to invoke the CBOR Diagnostic Notation parser.
- Since:
- 1.5
- See Also:
-
setDiagnosticNotationPrefix
Set the prefix to indicate that the substring of the string given to thecborizeString(String)method should be interpreted as the CBOR Diagnostic Notation.For example, if the prefix is
"cbor:"(which is the default value), when"cbor:h'0102'"is given to thecborizeString(String)method, the substring after the prefix, which is"h'0102'"in this example, is passed to the parser'sparseItem(String)method. The parser will generate aCBORByteArrayinstance that contains the two bytes, 0x01 and 0x02.If
nullor an empty string is set as the prefix, it will result in that every non-null string is processed by the parser unconditionally. Therefore, for example, a string"123"will be converted into aCBORIntegerinstance that represents the decimal integer, 123. If 123 needs to be processed as a string,"\"123\""must be given.If a CBOR Diagnostic Notation parser is not set to this
CBORizerinstance, this prefix is not used, and conversion based on the CBOR Diagnostic Notation is not performed.- Parameters:
prefix- The prefix to invoke the CBOR Diagnostic Notation parser.- Returns:
thisobject.- Since:
- 1.5
- See Also:
-
getDiagnosticNotationParser
Get the parser that interprets the CBOR Diagnostic Notation.- Returns:
- The CBOR Diagnostic Notation parser.
- Since:
- 1.5
- See Also:
-
setDiagnosticNotationParser
Set the parser that interprets the CBOR Diagnostic Notation.- Parameters:
parser- The CBOR Diagnostic Notation parser.- Returns:
thisobject.- Since:
- 1.5
- See Also:
-
cborizeBoolean
ReturnCBORBoolean.FALSEorCBORBoolean.TRUEaccording to the given value.- Parameters:
value- A boolean value.- Returns:
CBORBoolean.FALSEorCBORBoolean.TRUE.
-
cborizeInteger
Create aCBORIntegerinstance with the given value.- Parameters:
value- An integer.- Returns:
- A new
CBORIntegerinstance.
-
cborizeLong
-
cborizeBigInteger
Create aCBORBigIntegerinstance with the given value.- Parameters:
value- A big integer. Whennullis given,CBORNull.INSTANCEis returned.- Returns:
- A new
CBORBigIntegerinstance orCBORNull.INSTANCE.
-
cborizeFloat
-
cborizeDouble
Create aCBORDoubleinstance with the given value.- Parameters:
value- A double-precision floating-point number.- Returns:
- A new
CBORDoubleinstance.
-
cborizeByteArray
Create aCBORByteArrayinstance with the given value.- Parameters:
value- A byte array. Whennullis given,CBORNull.INSTANCEis returned.- Returns:
- A new
CBORByteArrayinstance orCBORNull.INSTANCE.
-
cborizeString
Create aCBORStringinstance with the given value.When
nullis given,CBORNull.INSTANCEis returned. Otherwise, aCBORStringinstance that represents the given string is returned.However, if a
CBORDiagnosticNotationParserinstance is set to thisCBORizerinstance (cf.setDiagnosticNotationParser(CBORDiagnosticNotationParser)), and if the prefix of the given string indicates that the string should be interpreted as CBOR Diagnostic Notation (cf.setDiagnosticNotationPrefix(String)), the substring after the prefix is passed to theparseItem(String)method of the parser, and the object returned from the parser is returned from this method.- Parameters:
value- An input string.- Returns:
- A new CBOR item built from the given string. In typical cases,
a
CBORStringinstance that represents the given string is returned.
-
cborizeCollection
Create aCBORItemListinstance with the given collection. Contents in the given collection are converted into instances ofCBORItemsubclasses recursively.- Parameters:
collection- A collection of objects. Whennullis given,CBORNull.INSTANCEis returned.- Returns:
- A new
CBORItemListinstance orCBORNull.INSTANCE.
-
cborizeMap
Create aCBORPairListinstance with the given map. Contents in the given map are converted into instances ofCBORItemsubclasses recursively.- Parameters:
map- A map of key-value pairs. Whennullis given,CBORNull.INSTANCEis returned.- Returns:
- A new
CBORPairListinstance orCBORNull.INSTANCE.
-
cborizeObject
Convert the given object into an instance ofCBORItemsubclass. Conversion is performed recursively as necessary.The implementation of this method delegates conversion to one of other
cborizeXxxmethods according to the class of the object. If the class of the given object is unknown,cborizeString(object.toString())is called.When the given object is already an instance of
CBORItemsubclass, the given object is returned as is.When
nullis given,CBORNull.INSTANCEis returned. -
cborize
Convert the given object into an instance ofCBORItemsubclass. Conversion is performed recursively as necessary.This method is an alias of
cborizeObject(object).
-