Class CBORizer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConvert the given object into an instance ofCBORItem
subclass.cborizeBigInteger
(BigInteger value) Create aCBORBigInteger
instance with the given value.cborizeBoolean
(boolean value) ReturnCBORBoolean.FALSE
orCBORBoolean.TRUE
according to the given value.cborizeByteArray
(byte[] value) Create aCBORByteArray
instance with the given value.cborizeCollection
(Collection<?> collection) Create aCBORItemList
instance with the given collection.cborizeDouble
(double value) Create aCBORDouble
instance with the given value.cborizeFloat
(float value) Create aCBORFloat
instance with the given value.cborizeInteger
(int value) Create aCBORInteger
instance with the given value.cborizeLong
(long value) Create aCBORLong
instance with the given value.cborizeMap
(Map<?, ?> map) Create aCBORPairList
instance with the given map.cborizeObject
(Object object) Convert the given object into an instance ofCBORItem
subclass.cborizeString
(String value) Create aCBORString
instance 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 aCBORByteArray
instance that contains the two bytes, 0x01 and 0x02.If
null
or 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 aCBORInteger
instance 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
CBORizer
instance, 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:
this
object.- 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:
this
object.- Since:
- 1.5
- See Also:
-
cborizeBoolean
ReturnCBORBoolean.FALSE
orCBORBoolean.TRUE
according to the given value.- Parameters:
value
- A boolean value.- Returns:
CBORBoolean.FALSE
orCBORBoolean.TRUE
.
-
cborizeInteger
Create aCBORInteger
instance with the given value.- Parameters:
value
- An integer.- Returns:
- A new
CBORInteger
instance.
-
cborizeLong
-
cborizeBigInteger
Create aCBORBigInteger
instance with the given value.- Parameters:
value
- A big integer. Whennull
is given,CBORNull.INSTANCE
is returned.- Returns:
- A new
CBORBigInteger
instance orCBORNull.INSTANCE
.
-
cborizeFloat
-
cborizeDouble
Create aCBORDouble
instance with the given value.- Parameters:
value
- A double-precision floating-point number.- Returns:
- A new
CBORDouble
instance.
-
cborizeByteArray
Create aCBORByteArray
instance with the given value.- Parameters:
value
- A byte array. Whennull
is given,CBORNull.INSTANCE
is returned.- Returns:
- A new
CBORByteArray
instance orCBORNull.INSTANCE
.
-
cborizeString
Create aCBORString
instance with the given value.When
null
is given,CBORNull.INSTANCE
is returned. Otherwise, aCBORString
instance that represents the given string is returned.However, if a
CBORDiagnosticNotationParser
instance is set to thisCBORizer
instance (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
CBORString
instance that represents the given string is returned.
-
cborizeCollection
Create aCBORItemList
instance with the given collection. Contents in the given collection are converted into instances ofCBORItem
subclasses recursively.- Parameters:
collection
- A collection of objects. Whennull
is given,CBORNull.INSTANCE
is returned.- Returns:
- A new
CBORItemList
instance orCBORNull.INSTANCE
.
-
cborizeMap
Create aCBORPairList
instance with the given map. Contents in the given map are converted into instances ofCBORItem
subclasses recursively.- Parameters:
map
- A map of key-value pairs. Whennull
is given,CBORNull.INSTANCE
is returned.- Returns:
- A new
CBORPairList
instance orCBORNull.INSTANCE
.
-
cborizeObject
Convert the given object into an instance ofCBORItem
subclass. Conversion is performed recursively as necessary.The implementation of this method delegates conversion to one of other
cborizeXxx
methods 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
CBORItem
subclass, the given object is returned as is.When
null
is given,CBORNull.INSTANCE
is returned. -
cborize
Convert the given object into an instance ofCBORItem
subclass. Conversion is performed recursively as necessary.This method is an alias of
cborizeObject
(object)
.
-