├── .gitattributes
├── .github
└── workflows
│ ├── codeql-analysis.yml
│ └── maven.yml
├── .gitignore
├── LICENSE.md
├── README.md
├── api
├── Home.md
├── com.upokecenter.cbor.CBORDataUtilities.md
├── com.upokecenter.cbor.CBORDateConverter.ConversionType.md
├── com.upokecenter.cbor.CBORDateConverter.md
├── com.upokecenter.cbor.CBOREncodeOptions.md
├── com.upokecenter.cbor.CBORException.md
├── com.upokecenter.cbor.CBORNumber.NumberKind.md
├── com.upokecenter.cbor.CBORNumber.md
├── com.upokecenter.cbor.CBORObject.md
├── com.upokecenter.cbor.CBORType.md
├── com.upokecenter.cbor.CBORTypeMapper.md
├── com.upokecenter.cbor.ICBORConverter.md
├── com.upokecenter.cbor.ICBORToFromConverter.md
├── com.upokecenter.cbor.JSONOptions.ConversionMode.md
├── com.upokecenter.cbor.JSONOptions.md
└── com.upokecenter.cbor.PODOptions.md
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── upokecenter
│ └── cbor
│ ├── Base64.java
│ ├── CBORCanonical.java
│ ├── CBORDataUtilities.java
│ ├── CBORDataUtilitiesByteArrayString.java
│ ├── CBORDataUtilitiesCharArrayString.java
│ ├── CBORDataUtilitiesTextString.java
│ ├── CBORDateConverter.java
│ ├── CBORDoubleBits.java
│ ├── CBOREInteger.java
│ ├── CBOREncodeOptions.java
│ ├── CBORException.java
│ ├── CBORExtendedDecimal.java
│ ├── CBORExtendedFloat.java
│ ├── CBORExtendedRational.java
│ ├── CBORInteger.java
│ ├── CBORJson.java
│ ├── CBORJson2.java
│ ├── CBORJson3.java
│ ├── CBORJsonWriter.java
│ ├── CBORNumber.java
│ ├── CBORObject.java
│ ├── CBORReader.java
│ ├── CBORType.java
│ ├── CBORTypeMapper.java
│ ├── CBORUriConverter.java
│ ├── CBORUtilities.java
│ ├── CBORUuidConverter.java
│ ├── CharacterInputWithCount.java
│ ├── CharacterReader.java
│ ├── ICBORConverter.java
│ ├── ICBORNumber.java
│ ├── ICBORToFromConverter.java
│ ├── ICharacterInput.java
│ ├── JSONOptions.java
│ ├── JSONPatch.java
│ ├── JSONPointer.java
│ ├── OptionsParser.java
│ ├── PODOptions.java
│ ├── PropertyMap.java
│ ├── SharedRefs.java
│ ├── StringOutput.java
│ └── StringRefs.java
└── test
├── java
└── com
│ └── upokecenter
│ ├── test
│ ├── AppResources.java
│ ├── BEncoding.java
│ ├── BEncodingTest.java
│ ├── Base64.java
│ ├── CBORDataUtilitiesTest.java
│ ├── CBORExceptionTest.java
│ ├── CBORGenerator.java
│ ├── CBORNumberTest.java
│ ├── CBORObjectTest.java
│ ├── CBORPlistWriter.java
│ ├── CBORSupplementTest.java
│ ├── CBORTest.java
│ ├── CBORTestCommon.java
│ ├── CBORTypeMapperTest.java
│ ├── CBORWriterHelper.java
│ ├── CPOD.java
│ ├── CPOD2.java
│ ├── CPOD3.java
│ ├── DateTest.java
│ ├── FieldClass.java
│ ├── JSONGenerator.java
│ ├── JSONPatch.java
│ ├── JSONPointer.java
│ ├── JSONWithComments.java
│ ├── JavaSpecificTest.java
│ ├── LimitedMemoryStream.java
│ ├── MiniCBOR.java
│ ├── PODClass.java
│ ├── RandomNumerics.java
│ ├── RandomObjects.java
│ ├── StringAndBigInt.java
│ ├── StringOutput.java
│ ├── TestCommon.java
│ └── ToObjectTest.java
│ └── util
│ ├── IRandomGen.java
│ ├── IRandomGenExtended.java
│ ├── QueryStringHelper.java
│ ├── QueryStringHelperCBOR.java
│ ├── RandomGenerator.java
│ └── XorShift128Plus.java
└── resources
└── Resources.properties
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 | *.cs eol=lf
3 | *.java eol=lf
4 | *.js eol=lf
5 | *.rb eol=lf
6 | *.py eol=lf
7 | *.php eol=lf
8 | *.c eol=lf
9 | *.h eol=lf
10 | *.cc eol=lf
11 | *.hh eol=lf
12 | *.cpp eol=lf
13 | *.cxx eol=lf
14 | *.md eol=lf
15 | *.sln eol=lf
16 | *.config eol=lf
17 | *.csproj eol=lf
18 | *.vbproj eol=lf
19 | *.fsproj eol=lf
20 | *.dbproj eol=lf
21 | *.nuspec eol=lf
22 | *.html eol=lf
23 | *.htm eol=lf
24 | *.css eol=lf
25 | *.less eol=lf
26 | *.xml eol=lf
27 | *.ruleset eol=lf
28 | *.yml eol=lf
29 | .gitattributes eol=lf
30 | .gitignore eol=lf
31 | .npmignore eol=lf
32 | *.cs diff=csharp
33 | *.sln merge=union
34 | *.csproj merge=union
35 | *.vbproj merge=union
36 | *.fsproj merge=union
37 | *.dbproj merge=union
38 |
--------------------------------------------------------------------------------
/.github/workflows/codeql-analysis.yml:
--------------------------------------------------------------------------------
1 | # For most projects, this workflow file will not need changing; you simply need
2 | # to commit it to your repository.
3 | #
4 | # You may wish to alter this file to override the set of languages analyzed,
5 | # or to provide custom queries or build logic.
6 | #
7 | # ******** NOTE ********
8 | # We have attempted to detect the languages in your repository. Please check
9 | # the `language` matrix defined below to confirm you have the correct set of
10 | # supported CodeQL languages.
11 | #
12 | name: "CodeQL"
13 |
14 | on:
15 | push:
16 | branches: [ master ]
17 | pull_request:
18 | # The branches below must be a subset of the branches above
19 | branches: [ master ]
20 | schedule:
21 | - cron: '40 7 * * 0'
22 |
23 | jobs:
24 | analyze:
25 | name: Analyze
26 | runs-on: ubuntu-latest
27 | permissions:
28 | actions: read
29 | contents: read
30 | security-events: write
31 |
32 | strategy:
33 | fail-fast: false
34 | matrix:
35 | language: [ 'java' ]
36 | # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
37 | # Learn more:
38 | # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
39 |
40 | steps:
41 | - name: Checkout repository
42 | uses: actions/checkout@v2
43 |
44 | # Initializes the CodeQL tools for scanning.
45 | - name: Initialize CodeQL
46 | uses: github/codeql-action/init@v3
47 | with:
48 | languages: ${{ matrix.language }}
49 | # If you wish to specify custom queries, you can do so here or in a config file.
50 | # By default, queries listed here will override any specified in a config file.
51 | # Prefix the list here with "+" to use these queries and those in the config file.
52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main
53 |
54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
55 | # If this step fails, then you should remove it and run the build manually (see later)
56 | - name: Autobuild
57 | uses: github/codeql-action/autobuild@v3
58 |
59 | # ℹ️ Command-line programs to run using the OS shell.
60 | # 📚 https://git.io/JvXDl
61 |
62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
63 | # and modify them (or add more) to build your code if your project
64 | # uses a compiled language
65 |
66 | #- run: |
67 | # make bootstrap
68 | # make release
69 |
70 | - name: Perform CodeQL Analysis
71 | uses: github/codeql-action/analyze@v3
72 |
--------------------------------------------------------------------------------
/.github/workflows/maven.yml:
--------------------------------------------------------------------------------
1 | # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3 |
4 | # This workflow uses actions that are not certified by GitHub.
5 | # They are provided by a third-party and are governed by
6 | # separate terms of service, privacy policy, and support
7 | # documentation.
8 |
9 | name: Java CI with Maven
10 |
11 | on:
12 | push:
13 | branches: [ "master" ]
14 | pull_request:
15 | branches: [ "master" ]
16 |
17 | jobs:
18 | build:
19 |
20 | runs-on: ubuntu-latest
21 |
22 | steps:
23 | - uses: actions/checkout@v3
24 | - name: Set up JDK 17
25 | uses: actions/setup-java@v3
26 | with:
27 | java-version: '17'
28 | distribution: 'temurin'
29 | cache: maven
30 | - name: Build with Maven
31 | run: mvn -B package --file pom.xml
32 |
33 | permissions:
34 | contents: read
35 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.Cache
2 | *.Settings
3 | *.bat
4 | *.cache
5 | *.class
6 | *.jar
7 | *.log
8 | *.map
9 | *.nupkg
10 | *.pyc
11 | *.sdsettings
12 | *.shf*
13 | *.suo
14 | *.user
15 | *.userprefs
16 | *.versionsBackup
17 | .classpath
18 | .nuget/
19 | .pmd
20 | .project
21 | .settings/
22 | .vs/
23 | CBORTest/OpenCover/
24 | CBORTest/ProfilingSessions/
25 | CBORTest/bin/
26 | CBORTest/obj/
27 | Help/
28 | ProfilingSessions/
29 | TestResults/
30 | bin/
31 | encoding/
32 | encodingfldr/
33 | js/*.ht*
34 | js/DecTest.*
35 | obj/
36 | packages/
37 | release.properties
38 | target/
39 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | This is free and unencumbered software released into the public domain.
2 |
3 | Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
4 |
5 | In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.
6 |
7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CBOR
2 |
3 | [](https://search.maven.org/#search|ga|1|g%3A%22com.upokecenter%22%20AND%20a%3A%22cbor%22)
4 |
5 | ---
6 |
7 | A Java implementation of Concise Binary Object Representation, a general-purpose binary data format defined in RFC 8949. According to that RFC, CBOR's data model "is an extended version of the JSON data model", supporting many more types of data than JSON. "CBOR was inspired by MessagePack", but "is not intended as a version of or replacement for MessagePack."
8 |
9 | This implementation was written by Peter O. and is released to the Public Domain under the [CC0 Declaration](https://creativecommons.org/publicdomain/zero/1.0/).
10 |
11 | This implementation also doubles as a reader and writer of JSON, and can convert data from JSON to CBOR and back.
12 |
13 | Finally, this implementation supports arbitrary-precision binary and decimal floating-point numbers and rational numbers with arbitrary-precision components.
14 |
15 | ## How to Install
16 |
17 | Starting with version 0.23.0, the Java implementation is available
18 | as an [artifact](https://search.maven.org/#search|ga|1|g%3A%22com.upokecenter%22%20AND%20a%3A%22cbor%22) in the Central Repository. To add this library to a Maven
19 | project, add the following to the `dependencies` section in your `pom.xml` file:
20 |
21 | ```xml
22 |
23 | com.upokecenter
24 | cbor
25 | 5.0.0-alpha2
26 |
27 | ```
28 |
29 | In other Java-based environments, the library can be referred to by its
30 | group ID (`com.upokecenter`), artifact ID (`cbor`), and version, as given earlier. A nonrelease version of this library is `5.0.0-alpha` rather than the version number given earlier.
31 |
32 | ## Documentation
33 |
34 | This library defines one class, called CBORObject, that allows you to read and
35 | write CBOR objects to and from data streams and byte arrays, and to convert JSON
36 | text to CBOR objects and back.
37 |
38 | **See the [Java API documentation](https://peteroupc.github.io/CBOR/api/).**
39 |
40 | ## Examples
41 |
42 | Reading data from a file.
43 |
44 | ```java
45 | // Java
46 | // Open the file stream
47 | try (FileInputStream stream = new FileInputStream("object.cbor")) {
48 | // Read the CBOR object from the stream
49 | var cbor = CBORObject.Read(stream);
50 | // At this point, the object is read, but the file stream might
51 | // not have ended yet. Here, the code may choose to read another
52 | // CBOR object, check for the end of the stream, or just ignore the
53 | // rest of the file. The following is an example of checking for the
54 | // end of the stream.
55 | if (stream.getChannel().position() != stream.getChannel().size()) {
56 | // The end of the stream wasn't reached yet.
57 | } else {
58 | // The end of the stream was reached.
59 | }
60 | }
61 | ```
62 |
63 | Writing multiple objects to a file, including arbitrary objects:
64 |
65 | ```java
66 | // Java
67 | // This example uses the "try-with-resources" statement from Java 7.
68 | // This example writes different kinds of objects in CBOR
69 | // format to the same file.
70 | try (FileOutputStream stream = new FileOutputStream("object.cbor")) {
71 | CBORObject.Write(true, stream);
72 | CBORObject.Write(422.5, stream);
73 | CBORObject.Write("some string", stream);
74 | CBORObject.Write(CBORObject.Undefined, stream);
75 | CBORObject.NewArray().Add(42).WriteTo(stream);
76 | }
77 | ```
78 |
79 | NOTE: All code samples in this section are released to the Public Domain,
80 | as explained in .
81 |
82 | ## Source Code
83 |
84 | Source code is available in the [project page](https://github.com/peteroupc/CBOR-Java).
85 |
86 | ## About
87 |
88 | Written in 2013-2016 by Peter O.
89 |
90 | Any copyright to this work is released to the Public Domain.
91 | In case this is not possible, this work is also
92 | licensed under the Unlicense: [https://unlicense.org/](https://unlicense.org/)
93 |
94 | ## Signing Key
95 |
96 | Release versions, in the Central Repository, of the Java version of this library are signed with the following signing key.
97 |
98 | - ID: `Peter Occil (Maven key) `
99 | - Fingerprint: 1A82D51407003717A4171AAC87522D618F2B2338
100 |
101 | ## Release Notes
102 |
103 | For release notes, see the [CBOR .NET repository](https://github.com/peteroupc/CBOR).
104 |
105 | The [commit history](https://github.com/peteroupc/CBOR-Java/commits/master)
106 | contains details on code changes in previous versions.
107 |
108 | ## Acknowledgments
109 |
110 | For acknowledgments, see the [CBOR .NET repository](https://github.com/peteroupc/CBOR).
111 |
112 | I thank all users who sent issues to this repository.
113 |
--------------------------------------------------------------------------------
/api/Home.md:
--------------------------------------------------------------------------------
1 | # API Documentation
2 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.CBORDateConverter.ConversionType.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.CBORDateConverter.ConversionType
2 |
3 | public static enum CBORDateConverter.ConversionType extends Enum
4 |
5 | Conversion type for date-time conversion.
6 |
7 | ## Nested Classes
8 |
9 | ## Enum Constants
10 |
11 | * `TaggedNumber `
12 | FromCBORObject accepts objects with tag 0 (date/time strings) and tag 1
13 | (number of seconds since the start of 1970), and ToCBORObject converts
14 | date/time objects to CBOR objects of tag 1.
15 |
16 | * `TaggedString `
17 | FromCBORObject accepts CBOR objects with tag 0 (date/time strings) and tag 1
18 | (number of seconds since the start of 1970), and ToCBORObject converts
19 | date/time objects to CBOR objects of tag 0.
20 |
21 | * `UntaggedNumber `
22 | FromCBORObject accepts untagged CBOR integer or CBOR floating-point objects
23 | that give the number of seconds since the start of 1970, and ToCBORObject
24 | converts date/time objects (java.util.Date in DotNet, and Date in Java) to such
25 | untagged CBOR objects.
26 |
27 | ## Methods
28 |
29 | * `static CBORDateConverter.ConversionType valueOf(String name)`
30 | Returns the enum constant of this class with the specified name.
31 |
32 | * `static CBORDateConverter.ConversionType[] values()`
33 | Returns an array containing the constants of this enum class, in
34 | the order they are declared.
35 |
36 | ## Method Details
37 |
38 | ### values
39 |
40 | public static CBORDateConverter.ConversionType[] values()
41 |
42 | ### valueOf
43 |
44 | public static CBORDateConverter.ConversionType valueOf(String name)
45 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.CBORException.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.CBORException
2 |
3 | public final class CBORException extends RuntimeException
4 |
5 |
Exception thrown for errors involving CBOR data.
This library may
6 | throw exceptions of this type in certain cases, notably when errors occur,
7 | and may supply messages to those exceptions (the message can be accessed
8 | through the Message property in.NET or the getMessage()
9 | method in Java). These messages are intended to be read by humans to help
10 | diagnose the error (or other cause of the exception); they are not intended
11 | to be parsed by computer programs, and the exact text of the messages may
12 | change at any time between versions of this library.
13 |
14 | ## Constructors
15 |
16 | ## Methods
17 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.CBORNumber.NumberKind.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.CBORNumber.NumberKind
2 |
3 | public static enum CBORNumber.NumberKind extends Enum
4 |
5 | Specifies the underlying form of this CBOR number object.
6 |
7 | ## Nested Classes
8 |
9 | ## Enum Constants
10 |
11 | * `Double `
12 | A 64-bit binary floating-point number.
13 |
14 | * `EDecimal `
15 | An arbitrary-precision decimal number.
16 |
17 | * `EFloat `
18 | An arbitrary-precision binary number.
19 |
20 | * `EInteger `
21 | An arbitrary-precision integer.
22 |
23 | * `ERational `
24 | An arbitrary-precision rational number.
25 |
26 | * `Integer `
27 | A 64-bit signed integer.
28 |
29 | ## Methods
30 |
31 | * `static CBORNumber.NumberKind valueOf(String name)`
32 | Returns the enum constant of this class with the specified name.
33 |
34 | * `static CBORNumber.NumberKind[] values()`
35 | Returns an array containing the constants of this enum class, in
36 | the order they are declared.
37 |
38 | ## Method Details
39 |
40 | ### values
41 |
42 | public static CBORNumber.NumberKind[] values()
43 |
44 | ### valueOf
45 |
46 | public static CBORNumber.NumberKind valueOf(String name)
47 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.CBORType.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.CBORType
2 |
3 | public enum CBORType extends Enum
4 |
5 | Represents a type that a CBOR object can have.
6 |
7 | ## Nested Classes
8 |
9 | ## Enum Constants
10 |
11 | * `Array `
12 | An array of CBOR objects.
13 |
14 | * `Boolean `
15 | The simple values true and false.
16 |
17 | * `ByteString `
18 | An array of bytes.
19 |
20 | * `FloatingPoint `
21 | A 16-, 32-, or 64-bit binary floating-point number.
22 |
23 | * `Integer `
24 | An integer in the interval [-(2^64), 2^64 - 1], or an integer of major type
25 | 0 and 1.
26 |
27 | * `Map `
28 | A map of CBOR objects.
29 |
30 | * `Number `
31 | Deprecated.
32 | Since version 4.0, CBORObject.Type no longer returns this value for any
33 | CBOR Object - this is a breaking change from earlier
34 | versions.
35 |
36 | * `SimpleValue `
37 | A "simple value" other than floating point values, true, and false.
38 |
39 | * `TextString `
40 | A text string.
41 |
42 | ## Methods
43 |
44 | * `static CBORType valueOf(String name)`
45 | Returns the enum constant of this class with the specified name.
46 |
47 | * `static CBORType[] values()`
48 | Returns an array containing the constants of this enum class, in
49 | the order they are declared.
50 |
51 | ## Method Details
52 |
53 | ### values
54 |
55 | public static CBORType[] values()
56 |
57 | ### valueOf
58 |
59 | public static CBORType valueOf(String name)
60 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.CBORTypeMapper.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.CBORTypeMapper
2 |
3 | public final class CBORTypeMapper extends Object
4 |
5 | Holds converters to customize the serialization and deserialization behavior
6 | of CBORObject.FromObject and CBORObject#ToObject, as well as
7 | type filters for ToObject.
8 |
9 | ## Constructors
10 |
11 | ## Methods
12 |
13 | * ` CBORTypeMapper AddConverter(Type type,
14 | ICBORConverter converter)`
15 | Registers an object that converts objects of a given type to CBOR objects
16 | (called a CBOR converter).
17 |
18 | * `CBORTypeMapper AddTypeName(String name)`
19 | Adds the fully qualified name of a Java or.NET type for use in type
20 | matching.
21 |
22 | * `CBORTypeMapper AddTypePrefix(String prefix)`
23 | Adds a prefix of a Java or.NET type for use in type matching.
24 |
25 | * `boolean FilterTypeName(String typeName)`
26 | Returns whether the specified Java or.NET type name fits the filters given
27 | in this mapper.
28 |
29 | ## Method Details
30 |
31 | ### AddConverter
32 |
33 | public CBORTypeMapper AddConverter(Type type, ICBORConverter converter)
34 |
35 | Registers an object that converts objects of a given type to CBOR objects
36 | (called a CBOR converter). If the CBOR converter converts to and from CBOR
37 | objects, it should implement the ICBORToFromConverter interface and provide
38 | ToCBORObject and FromCBORObject methods. If the CBOR converter only supports
39 | converting to (not from) CBOR objects, it should implement the
40 | ICBORConverter interface and provide a ToCBORObject method.
41 |
42 | **Type Parameters:**
43 |
44 | * T - Must be the same as the "type" parameter.
45 |
46 | **Parameters:**
47 |
48 | * type - A Type object specifying the type that the converter converts to
49 | CBOR objects.
50 |
51 | * converter - The parameter converter is an ICBORConverter
52 | object.
53 |
54 | **Returns:**
55 |
56 | * This object.
57 |
58 | **Throws:**
59 |
60 | * NullPointerException - The parameter type or
61 | converter is null.
62 |
63 | * IllegalArgumentException - Converter doesn't contain a proper ToCBORObject
64 | method".
65 |
66 | ### FilterTypeName
67 |
68 | public boolean FilterTypeName(String typeName)
69 |
70 | Returns whether the specified Java or.NET type name fits the filters given
71 | in this mapper.
72 |
73 | **Parameters:**
74 |
75 | * typeName - The fully qualified name of a Java or.NET class (for
76 | example, java.math.BigInteger or
77 | System.Globalization.CultureInfo).
78 |
79 | **Returns:**
80 |
81 | * Either true if the specified Java or.NET type name fits the
82 | filters given in this mapper, or false otherwise.
83 |
84 | ### AddTypePrefix
85 |
86 | public CBORTypeMapper AddTypePrefix(String prefix)
87 |
88 | Adds a prefix of a Java or.NET type for use in type matching. A type matches
89 | a prefix if its fully qualified name is or begins with that prefix, using
90 | codepoint-by-codepoint (case-sensitive) matching.
91 |
92 | **Parameters:**
93 |
94 | * prefix - The prefix of a Java or.NET type (for example, `java.math.` or
95 | `System.Globalization`).
96 |
97 | **Returns:**
98 |
99 | * This object.
100 |
101 | **Throws:**
102 |
103 | * NullPointerException - The parameter prefix is null.
104 |
105 | * IllegalArgumentException - The parameter prefix is empty.
106 |
107 | ### AddTypeName
108 |
109 | public CBORTypeMapper AddTypeName(String name)
110 |
111 | Adds the fully qualified name of a Java or.NET type for use in type
112 | matching.
113 |
114 | **Parameters:**
115 |
116 | * name - The fully qualified name of a Java or.NET class (for example,
117 | java.math.BigInteger or System.Globalization.CultureInfo).
118 |
119 | **Returns:**
120 |
121 | * This object.
122 |
123 | **Throws:**
124 |
125 | * NullPointerException - The parameter name is null.
126 |
127 | * IllegalArgumentException - The parameter name is empty.
128 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.ICBORConverter.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.ICBORConverter
2 |
3 | public interface ICBORConverter
4 |
5 | Interface implemented by classes that convert objects of arbitrary types to
6 | CBOR objects.
7 |
8 | ## Methods
9 |
10 | * `CBORObject ToCBORObject(T obj)`
11 | Converts an object to a CBOR object.
12 |
13 | ## Method Details
14 |
15 | ### ToCBORObject
16 |
17 | CBORObject ToCBORObject(T obj)
18 |
19 | Converts an object to a CBOR object.
20 |
21 | **Parameters:**
22 |
23 | * obj - An object to convert to a CBOR object.
24 |
25 | **Returns:**
26 |
27 | * A CBOR object.
28 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.ICBORToFromConverter.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.ICBORToFromConverter
2 |
3 | public interface ICBORToFromConverter extends ICBORConverter
4 |
5 | Classes that implement this interface can support conversions from CBOR
6 | objects to a custom type and back.
7 |
8 | ## Methods
9 |
10 | * `T FromCBORObject(CBORObject obj)`
11 | Converts a CBOR object to a custom type.
12 |
13 | ## Method Details
14 |
15 | ### FromCBORObject
16 |
17 | T FromCBORObject(CBORObject obj)
18 |
19 | Converts a CBOR object to a custom type.
20 |
21 | **Parameters:**
22 |
23 | * obj - A CBOR object to convert to the custom type.
24 |
25 | **Returns:**
26 |
27 | * An object of the custom type after conversion.
28 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.JSONOptions.ConversionMode.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.JSONOptions.ConversionMode
2 |
3 | public static enum JSONOptions.ConversionMode extends Enum
4 |
5 | Specifies how JSON numbers are converted to CBOR objects when decoding JSON
6 | (such as via FromJSONString or ReadJSON). None of these
7 | conversion modes affects how CBOR objects are later encoded (such as via
8 | EncodeToBytes).
9 |
10 | ## Nested Classes
11 |
12 | ## Enum Constants
13 |
14 | * `Decimal128 `
15 | JSON numbers are decoded to CBOR as their closest-rounded approximation to
16 | an IEEE 854 decimal128 value, using the round-to-nearest/ties-to-even
17 | rounding mode and the rules for the EDecimal form of that approximation as
18 | given in the CBORObject.FromObject(EDecimal) method.
19 |
20 | * `Double `
21 | JSON numbers are decoded to CBOR as their closest-rounded approximation
22 | as 64-bit binary floating-point numbers (using the
23 | round-to-nearest/ties-to-even rounding mode).
24 |
25 | * `Full `
26 | JSON numbers are decoded to CBOR using the full precision given in the JSON
27 | text.
28 |
29 | * `IntOrFloat `
30 | A JSON number is decoded to CBOR objects either as a CBOR integer (major
31 | type 0 or 1) if the JSON number represents an integer at least -(2^53)+1 and
32 | less than 2^53, or as their closest-rounded approximation as 64-bit binary
33 | floating-point numbers (using the round-to-nearest/ties-to-even rounding
34 | mode) otherwise.
35 |
36 | * `IntOrFloatFromDouble `
37 | A JSON number is decoded to CBOR objects either as a CBOR integer (major
38 | type 0 or 1) if the number's closest-rounded approximation as a 64-bit
39 | binary floating-point number (using the round-to-nearest/ties-to-even
40 | rounding mode) represents an integer at least -(2^53)+1 and less than 2^53,
41 | or as that approximation otherwise.
42 |
43 | ## Methods
44 |
45 | * `static JSONOptions.ConversionMode valueOf(String name)`
46 | Returns the enum constant of this class with the specified name.
47 |
48 | * `static JSONOptions.ConversionMode[] values()`
49 | Returns an array containing the constants of this enum class, in
50 | the order they are declared.
51 |
52 | ## Method Details
53 |
54 | ### values
55 |
56 | public static JSONOptions.ConversionMode[] values()
57 |
58 | ### valueOf
59 |
60 | public static JSONOptions.ConversionMode valueOf(String name)
61 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.JSONOptions.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.JSONOptions
2 |
3 | public final class JSONOptions extends Object
4 |
5 | Includes options to control how CBOR objects are converted to and from
6 | JavaScript object Notation (JSON).
7 |
8 | ## Nested Classes
9 |
10 | * `static enum JSONOptions.ConversionMode`
11 | Specifies how JSON numbers are converted to CBOR objects when decoding JSON
12 | (such as via FromJSONString or ReadJSON).
13 |
14 | ## Fields
15 |
16 | * `static final JSONOptions Default`
17 | The default options for converting CBOR objects to JSON.
18 |
19 | ## Constructors
20 |
21 | ## Methods
22 |
23 | * `final boolean getAllowDuplicateKeys()`
24 | Gets a value indicating whether to allow duplicate keys when reading JSON.
25 |
26 | * `final boolean getKeepKeyOrder()`
27 | Gets a value indicating whether to preserve the order in which a map's keys
28 | appear when decoding JSON, by using maps created as though by
29 | CBORObject.NewOrderedMap.
30 |
31 | * `final JSONOptions.ConversionMode getNumberConversion()`
32 | Gets a value indicating how JSON numbers are decoded to CBOR objects.
33 |
34 | * `final boolean getPreserveNegativeZero()`
35 | Gets a value indicating whether the JSON decoder should preserve the
36 | distinction between positive zero and negative zero when the decoder decodes
37 | JSON to a floating-point number format that makes this distinction.
38 |
39 | * `final boolean getReplaceSurrogates()`
40 | Gets a value indicating whether surrogate code points not part of a
41 | surrogate pair (which consists of two consecutive char s forming one
42 | Unicode code point) are each replaced with a replacement character (U+FFFD).
43 |
44 | * `final boolean getWriteBasic()`
45 | Gets a value indicating whether JSON is written using only code points from
46 | the Basic Latin block (U+0000 to U+007F), also known as ASCII.
47 |
48 | * `String toString()`
49 | Gets the values of this options object's properties in text form.
50 |
51 | ## Field Details
52 |
53 | ### Default
54 |
55 | public static final JSONOptions Default
56 |
57 | The default options for converting CBOR objects to JSON.
58 |
59 | ## Method Details
60 |
61 | ### toString
62 |
63 | public String toString()
64 |
65 | Gets the values of this options object's properties in text form.
66 |
67 | **Overrides:**
68 |
69 | * toString in class Object
70 |
71 | **Returns:**
72 |
73 | * A text string containing the values of this options object's
74 | properties. The format of the string is the same as the one described in the
75 | string constructor for this class.
76 |
77 | ### getPreserveNegativeZero
78 |
79 | public final boolean getPreserveNegativeZero()
80 |
81 | Gets a value indicating whether the JSON decoder should preserve the
82 | distinction between positive zero and negative zero when the decoder decodes
83 | JSON to a floating-point number format that makes this distinction. For a
84 | value of false, if the result of parsing a JSON string would be a
85 | floating-point negative zero, that result is a positive zero instead. (Note
86 | that this property has no effect for conversion kind
87 | IntOrFloatFromDouble, where floating-point zeros are not possible.).
88 |
89 | **Returns:**
90 |
91 | * A value indicating whether to preserve the distinction between
92 | positive zero and negative zero when decoding JSON. The default is true.
93 |
94 | ### getNumberConversion
95 |
96 | public final JSONOptions.ConversionMode getNumberConversion()
97 |
98 | Gets a value indicating how JSON numbers are decoded to CBOR objects. None
99 | of the conversion modes affects how CBOR objects are later encoded (such as
100 | via EncodeToBytes).
101 |
102 | **Returns:**
103 |
104 | * A value indicating how JSON numbers are decoded to CBOR. The default
105 | is ConversionMode.Full.
106 |
107 | ### getWriteBasic
108 |
109 | public final boolean getWriteBasic()
110 |
111 | Gets a value indicating whether JSON is written using only code points from
112 | the Basic Latin block (U+0000 to U+007F), also known as ASCII.
113 |
114 | **Returns:**
115 |
116 | * A value indicating whether JSON is written using only code points
117 | from the Basic Latin block (U+0000 to U+007F), also known as ASCII. Default
118 | is false.
119 |
120 | ### getKeepKeyOrder
121 |
122 | public final boolean getKeepKeyOrder()
123 |
124 | Gets a value indicating whether to preserve the order in which a map's keys
125 | appear when decoding JSON, by using maps created as though by
126 | CBORObject.NewOrderedMap. If false, key order is not guaranteed to be
127 | preserved when decoding JSON.
128 |
129 | **Returns:**
130 |
131 | * A value indicating whether to preserve the order in which a CBOR
132 | map's keys appear when decoding JSON. The default is false.
133 |
134 | ### getAllowDuplicateKeys
135 |
136 | public final boolean getAllowDuplicateKeys()
137 |
138 | Gets a value indicating whether to allow duplicate keys when reading JSON.
139 | Used only when decoding JSON. If this property is true and a JSON
140 | object has two or more values with the same key, the last value of that key
141 | set forth in the JSON object is taken.
142 |
143 | **Returns:**
144 |
145 | * A value indicating whether to allow duplicate keys when reading
146 | JSON. The default is false.
147 |
148 | ### getReplaceSurrogates
149 |
150 | public final boolean getReplaceSurrogates()
151 |
152 | Gets a value indicating whether surrogate code points not part of a
153 | surrogate pair (which consists of two consecutive char s forming one
154 | Unicode code point) are each replaced with a replacement character (U+FFFD).
155 | If false, an exception is thrown when such code points are encountered.
156 |
157 | **Returns:**
158 |
159 | * True, if surrogate code points not part of a surrogate pair are each
160 | replaced with a replacement character, or false if an exception is thrown
161 | when such code points are encountered. The default is false.
162 |
--------------------------------------------------------------------------------
/api/com.upokecenter.cbor.PODOptions.md:
--------------------------------------------------------------------------------
1 | # com.upokecenter.cbor.PODOptions
2 |
3 | public class PODOptions extends Object
4 |
5 | Options for controlling how certain DotNET or Java objects, such as
6 | so-called "plain old data" objects (better known as POCOs in DotNET or POJOs
7 | in Java), are converted to CBOR objects.
8 |
9 | ## Fields
10 |
11 | * `static final PODOptions Default`
12 | The default settings for "plain old data" options.
13 |
14 | ## Constructors
15 |
16 | ## Methods
17 |
18 | * `final boolean getUseCamelCase()`
19 | Gets a value indicating whether property, field, and method names are
20 | converted to camel case before they are used as keys.
21 |
22 | * `String toString()`
23 | Gets the values of this options object's properties in text form.
24 |
25 | ## Field Details
26 |
27 | ### Default
28 |
29 | public static final PODOptions Default
30 |
31 | The default settings for "plain old data" options.
32 |
33 | ## Method Details
34 |
35 | ### toString
36 |
37 | public String toString()
38 |
39 | Gets the values of this options object's properties in text form.
40 |
41 | **Overrides:**
42 |
43 | * toString in class Object
44 |
45 | **Returns:**
46 |
47 | * A text string containing the values of this options object's
48 | properties. The format of the string is the same as the one described in the
49 | string constructor for this class.
50 |
51 | ### getUseCamelCase
52 |
53 | public final boolean getUseCamelCase()
54 |
55 |
Gets a value indicating whether property, field, and method names are
56 | converted to camel case before they are used as keys. This option changes
57 | the behavior of key name serialization as follows. If "useCamelCase" is
58 | false :
In the .NET version, all key names are
59 | capitalized, meaning the first letter in the name is converted to a basic
60 | uppercase letter if it's a basic lowercase letter ("a" to "z"). (For
61 | example, "Name" and "IsName" both remain unchanged.)
In the Java
62 | version, all field names are capitalized, and for each eligible method name,
63 | the word "get" or "set" is removed from the name if the name starts with
64 | that word, then the name is capitalized. (For example, "getName" and
65 | "setName" both become "Name", and "isName" becomes "IsName".)
66 |
If "useCamelCase" is true :
In the .NET version, for
67 | each eligible property or field name, the word "Is" is removed from the name
68 | if the name starts with that word, then the name is converted to camel case,
69 | meaning the first letter in the name is converted to a basic lowercase
70 | letter if it's a basic uppercase letter ("A" to "Z"). (For example, "Name"
71 | and "IsName" both become "name", and "IsIsName" becomes
72 | "isName".)
In the Java version: For each eligible method name, the
73 | word "get", "set", or "is" is removed from the name if the name starts with
74 | that word, then the name is converted to camel case. (For example,
75 | "getName", "setName", and "isName" all become "name".) For each eligible
76 | field name, the word "is" is removed from the name if the name starts with
77 | that word, then the name is converted to camel case. (For example, "name"
78 | and "isName" both become "name".)
In the description above, a
79 | name "starts with" a word if that word begins the name and is followed by a
80 | character other than a basic digit or basic lowercase letter, that is, other
81 | than "a" to "z" or "0" to "9".
82 |
83 | **Returns:**
84 |
85 | * true If the names are converted to camel case; otherwise,
86 | false. This property is true by default.
87 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.upokecenter
5 | cbor
6 | jar
7 | 5.0.0-alpha2
8 | CBOR (Concise Binary Object Representation)
9 | A Java implementation of Concise Binary Object Representation (CBOR), a general-purpose binary data format defined in RFC 8949.
10 | https://github.com/peteroupc/CBOR-Java
11 |
12 |
13 | release
14 |
15 |
16 |
17 | org.apache.maven.plugins
18 | maven-gpg-plugin
19 | 1.5
20 |
21 |
22 | sign-artifacts
23 | verify
24 |
25 | sign
26 |
27 |
28 |
29 |
30 |
31 | org.apache.maven.plugins
32 | maven-javadoc-plugin
33 | 3.0.1
34 |
35 | CBOR for Java documentation, generated in {currentYear}.
36 |
37 | -html5
38 |
39 |
40 |
41 |
42 |
43 | attach-javadocs
44 |
45 | jar
46 |
47 |
48 |
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-source-plugin
53 | 2.2.1
54 |
55 |
56 | attach-sources
57 |
58 | jar-no-fork
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | scm:git:https://github.com/peteroupc/CBOR-Java
69 | scm:git:https://github.com/peteroupc/CBOR-Java.git
70 | https://github.com/peteroupc/CBOR-Java
71 |
72 |
73 |
74 | Anders Gustaffson
75 |
76 |
77 |
78 |
79 | Peter Occil
80 | poccil14@gmail.com
81 |
82 |
83 |
84 | UTF-8
85 | 8
86 | 1.8
87 |
88 |
89 |
90 | Unlicense
91 | repo
92 | http://www.creativecommons.org/publicdomain/zero/1.0/
93 |
94 |
95 |
96 |
97 |
98 | org.apache.maven.plugins
99 | maven-compiler-plugin
100 | 3.7.0
101 |
102 |
103 | -Xlint:all
104 |
105 |
106 |
107 |
108 | org.sonatype.plugins
109 | nexus-staging-maven-plugin
110 | true
111 | 1.6.13
112 |
113 | ossrh
114 | true
115 | https://oss.sonatype.org/
116 |
117 |
118 |
119 |
120 |
121 |
122 | ossrh
123 | https://oss.sonatype.org/content/repositories/snapshots
124 |
125 |
126 | ossrh
127 | https://oss.sonatype.org/service/local/staging/deploy/maven2/
128 |
129 |
130 |
131 |
132 | junit
133 | junit
134 | 4.13.1
135 | test
136 |
137 |
138 | com.github.peteroupc
139 | numbers
140 | 1.8.2
141 |
142 |
143 | com.github.peteroupc
144 | uriutility
145 | 1.0.1
146 |
147 |
148 | com.github.peteroupc
149 | datautilities
150 | 1.1.0
151 |
152 |
153 |
154 |
155 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/Base64.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | final class Base64 {
11 | private Base64() {
12 | }
13 | private static final String Base64URL =
14 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
15 |
16 | private static final String Base64Classic =
17 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
18 |
19 | public static void WriteBase64(
20 | StringOutput writer,
21 | byte[] data,
22 | int offset,
23 | int count,
24 | boolean padding) throws java.io.IOException {
25 | WriteBase64(writer, data, offset, count, true, padding);
26 | }
27 |
28 | public static void WriteBase64URL(
29 | StringOutput writer,
30 | byte[] data,
31 | int offset,
32 | int count,
33 | boolean padding) throws java.io.IOException {
34 | WriteBase64(writer, data, offset, count, false, padding);
35 | }
36 |
37 | private static void WriteBase64(
38 | StringOutput writer,
39 | byte[] data,
40 | int offset,
41 | int count,
42 | boolean classic,
43 | boolean padding) throws java.io.IOException {
44 | if (writer == null) {
45 | throw new NullPointerException("writer");
46 | }
47 | if (offset < 0) {
48 | throw new IllegalArgumentException("offset(" + offset + ") is less than " +
49 | "0 ");
50 | }
51 | if (offset > data.length) {
52 | throw new IllegalArgumentException("offset(" + offset + ") is more than " +
53 | data.length);
54 | }
55 | if (count < 0) {
56 | throw new IllegalArgumentException("count(" + count + ") is less than " +
57 | "0 ");
58 | }
59 | if (count > data.length) {
60 | throw new IllegalArgumentException("count(" + count + ") is more than " +
61 | data.length);
62 | }
63 | if (data.length - offset < count) {
64 | throw new IllegalArgumentException("data's length minus " + offset + "(" +
65 | (data.length - offset) + ") is less than " + count);
66 | }
67 | String alphabet = classic ? Base64Classic : Base64URL;
68 | int length = offset + count;
69 | byte[] buffer = new byte[32];
70 | int bufferOffset = 0;
71 | int i;
72 | for (i = offset; i < (length - 2); i += 3) {
73 | if (bufferOffset >= buffer.length) {
74 | writer.WriteAscii(buffer, 0, bufferOffset);
75 | bufferOffset = 0;
76 | }
77 | buffer[bufferOffset++] = (byte)alphabet.charAt((data[i] >> 2) & 63);
78 | buffer[bufferOffset++] = (byte)alphabet.charAt(((data[i] & 3) << 4) +
79 | ((data[i + 1] >> 4) & 15));
80 | buffer[bufferOffset++] = (byte)alphabet.charAt(((data[i + 1] & 15) << 2) +
81 | ((data[i + 2] >> 6) & 3));
82 | buffer[bufferOffset++] = (byte)alphabet.charAt(data[i + 2] & 63);
83 | }
84 | int lenmod3 = count % 3;
85 | if (lenmod3 != 0) {
86 | if (bufferOffset >= buffer.length) {
87 | writer.WriteAscii(buffer, 0, bufferOffset);
88 | bufferOffset = 0;
89 | }
90 | i = length - lenmod3;
91 | buffer[bufferOffset++] = (byte)alphabet.charAt((data[i] >> 2) & 63);
92 | if (lenmod3 == 2) {
93 | buffer[bufferOffset++] = (byte)alphabet.charAt(((data[i] & 3) << 4) +
94 | ((data[i + 1] >> 4) & 15));
95 | buffer[bufferOffset++] = (byte)alphabet.charAt((data[i + 1] & 15) << 2);
96 | if (padding) {
97 | buffer[bufferOffset++] = (byte)'=';
98 | }
99 | } else {
100 | buffer[bufferOffset++] = (byte)alphabet.charAt((data[i] & 3) << 4);
101 | if (padding) {
102 | buffer[bufferOffset++] = (byte)'=';
103 | buffer[bufferOffset++] = (byte)'=';
104 | }
105 | }
106 | }
107 | if (bufferOffset >= 0) {
108 | writer.WriteAscii(buffer, 0, bufferOffset);
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORCanonical.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 |
3 | import java.util.*;
4 | import java.io.*;
5 |
6 | final class CBORCanonical {
7 | private CBORCanonical() {
8 | }
9 | static final Comparator Comparer =
10 | new CtapComparer();
11 |
12 | private static final Comparator>
13 | ByteComparer = new CtapByteComparer();
14 |
15 | private static final class CtapByteComparer implements Comparator>
17 | {
18 | public int compare(
19 | Map.Entry kva,
20 | Map.Entry kvb) {
21 | byte[] bytesA = kva.getKey();
22 | byte[] bytesB = kvb.getKey();
23 | if (bytesA == null) {
24 | return bytesB == null ? 0 : -1;
25 | }
26 | if (bytesB == null) {
27 | return 1;
28 | }
29 | if (bytesA.length == 0) {
30 | return bytesB.length == 0 ? 0 : -1;
31 | }
32 | if (bytesB.length == 0) {
33 | return 1;
34 | }
35 | if (bytesA == bytesB) {
36 | // NOTE: Assumes reference equality of CBORObjects
37 | return 0;
38 | }
39 | // check major types
40 | if ((bytesA[0] & 0xe0) != (bytesB[0] & 0xe0)) {
41 | return (bytesA[0] & 0xe0) < (bytesB[0] & 0xe0) ? -1 : 1;
42 | }
43 | // check lengths
44 | if (bytesA.length != bytesB.length) {
45 | return bytesA.length < bytesB.length ? -1 : 1;
46 | }
47 | // check bytes
48 | for (int i = 0; i < bytesA.length; ++i) {
49 | if (bytesA[i] != bytesB[i]) {
50 | int ai = bytesA[i] & 0xff;
51 | int bi = bytesB[i] & 0xff;
52 | return (ai < bi) ? -1 : 1;
53 | }
54 | }
55 | return 0;
56 | }
57 | }
58 |
59 | private static final class CtapComparer implements Comparator
60 | {
61 | private static int MajorType(CBORObject a) {
62 | if (a.isTagged()) {
63 | return 6;
64 | }
65 | switch (a.getType()) {
66 | case Integer:
67 | return a.AsNumber().IsNegative() ? 1 : 0;
68 | case SimpleValue:
69 | case Boolean:
70 | case FloatingPoint:
71 | return 7;
72 | case ByteString:
73 | return 2;
74 | case TextString:
75 | return 3;
76 | case Array:
77 | return 4;
78 | case Map:
79 | return 5;
80 | default: throw new IllegalStateException();
81 | }
82 | }
83 |
84 | public int compare(CBORObject a, CBORObject b) {
85 | if (a == null) {
86 | return b == null ? 0 : -1;
87 | }
88 | if (b == null) {
89 | return 1;
90 | }
91 | if (a == b) {
92 | // NOTE: Assumes reference equality of CBORObjects
93 | return 0;
94 | }
95 | a = a.Untag();
96 | b = b.Untag();
97 | byte[] abs;
98 | byte[] bbs;
99 | int amt = MajorType(a);
100 | int bmt = MajorType(b);
101 | if (amt != bmt) {
102 | return amt < bmt ? -1 : 1;
103 | }
104 | // System.out.println("a="+a);
105 | // System.out.println("b="+b);
106 | if (amt == 2) {
107 | // Both objects are byte strings
108 | abs = a.GetByteString();
109 | bbs = b.GetByteString();
110 | } else {
111 | // Might store arrays or maps, where
112 | // canonical encoding can fail due to too-deep
113 | // nesting
114 | abs = CtapCanonicalEncode(a);
115 | bbs = CtapCanonicalEncode(b);
116 | }
117 | if (abs.length != bbs.length) {
118 | // different lengths
119 | return abs.length < bbs.length ? -1 : 1;
120 | }
121 | for (int i = 0; i < abs.length; ++i) {
122 | if (abs[i] != bbs[i]) {
123 | int ai = abs[i] & 0xff;
124 | int bi = bbs[i] & 0xff;
125 | return (ai < bi) ? -1 : 1;
126 | }
127 | }
128 | return 0;
129 | }
130 | }
131 |
132 | private static boolean IsArrayOrMap(CBORObject a) {
133 | return a.getType() == CBORType.Array || a.getType() == CBORType.Map;
134 | }
135 |
136 | public static byte[] CtapCanonicalEncode(CBORObject a) {
137 | return CtapCanonicalEncode(a, 0);
138 | }
139 |
140 | private static boolean ByteArraysEqual(byte[] bytesA, byte[] bytesB) {
141 | if (bytesA == bytesB) {
142 | return true;
143 | }
144 | if (bytesA == null || bytesB == null) {
145 | return false;
146 | }
147 | if (bytesA.length == bytesB.length) {
148 | for (int j = 0; j < bytesA.length; ++j) {
149 | if (bytesA[j] != bytesB[j]) {
150 | return false;
151 | }
152 | }
153 | return true;
154 | }
155 | return false;
156 | }
157 |
158 | private static void CheckDepth(CBORObject cbor, int depth) {
159 | if (cbor.getType() == CBORType.Array) {
160 | for (int i = 0; i < cbor.size(); ++i) {
161 | if (depth >= 3 && IsArrayOrMap(cbor.get(i))) {
162 | throw new CBORException("Nesting level too deep");
163 | }
164 | CheckDepth(cbor.get(i), depth + 1);
165 | }
166 | } else if (cbor.getType() == CBORType.Map) {
167 | for (CBORObject key : cbor.getKeys()) {
168 | if (depth >= 3 && (IsArrayOrMap(key) || IsArrayOrMap(cbor.get(key)))) {
169 | throw new CBORException("Nesting level too deep");
170 | }
171 | CheckDepth(key, depth + 1);
172 | CheckDepth(cbor.get(key), depth + 1);
173 | }
174 | }
175 | }
176 |
177 | private static byte[] CtapCanonicalEncode(CBORObject a, int depth) {
178 | CBORObject cbor = a.Untag();
179 | CBORType valueAType = cbor.getType();
180 | try {
181 | if (valueAType == CBORType.Array) {
182 | {
183 | java.io.ByteArrayOutputStream ms = null;
184 | try {
185 | ms = new java.io.ByteArrayOutputStream();
186 |
187 | CBORObject.WriteValue(ms, 4, cbor.size());
188 | for (int i = 0; i < cbor.size(); ++i) {
189 | if (depth >= 3 && IsArrayOrMap(cbor.get(i))) {
190 | throw new CBORException("Nesting level too deep");
191 | }
192 | byte[] bytes = CtapCanonicalEncode(cbor.get(i), depth + 1);
193 | ms.write(bytes, 0, bytes.length);
194 | }
195 | return ms.toByteArray();
196 | }
197 | finally {
198 | try { if (ms != null) { ms.close(); } } catch (java.io.IOException ex) {}
199 | }
200 | }
201 | } else if (valueAType == CBORType.Map) {
202 | Map.Entry kv1;
203 | ArrayList> sortedKeys;
204 | sortedKeys = new ArrayList>();
205 | for (CBORObject key : cbor.getKeys()) {
206 | if (depth >= 3 && (IsArrayOrMap(key) || IsArrayOrMap(cbor.get(key)))) {
207 | throw new CBORException("Nesting level too deep");
208 | }
209 | CheckDepth(key, depth + 1);
210 | CheckDepth(cbor.get(key), depth + 1);
211 | // Check if key and value can be canonically encoded
212 | // (will throw an exception if they cannot)
213 | kv1 = new AbstractMap.SimpleImmutableEntry(
214 | CtapCanonicalEncode(key, depth + 1),
215 | CtapCanonicalEncode(cbor.get(key), depth + 1));
216 | sortedKeys.add(kv1);
217 | }
218 | java.util.Collections.sort(sortedKeys, ByteComparer);
219 | {
220 | java.io.ByteArrayOutputStream ms = null;
221 | try {
222 | ms = new java.io.ByteArrayOutputStream();
223 |
224 | CBORObject.WriteValue(ms, 5, cbor.size());
225 | byte[] lastKey = null;
226 | for (int i = 0; i < sortedKeys.size(); ++i) {
227 | kv1 = sortedKeys.get(i);
228 | byte[] bytes = kv1.getKey();
229 | if (lastKey != null && ByteArraysEqual(bytes, lastKey)) {
230 | throw new CBORException("duplicate canonical CBOR key");
231 | }
232 | lastKey = bytes;
233 | ms.write(bytes, 0, bytes.length);
234 | bytes = kv1.getValue();
235 | ms.write(bytes, 0, bytes.length);
236 | }
237 | return ms.toByteArray();
238 | }
239 | finally {
240 | try { if (ms != null) { ms.close(); } } catch (java.io.IOException ex) {}
241 | }
242 | }
243 | }
244 | } catch (IOException ex) {
245 | throw new IllegalStateException(ex.toString(), ex);
246 | }
247 | if (valueAType == CBORType.SimpleValue ||
248 | valueAType == CBORType.Boolean || valueAType == CBORType.ByteString ||
249 | valueAType == CBORType.TextString) {
250 | return cbor.EncodeToBytes(CBOREncodeOptions.Default);
251 | } else if (valueAType == CBORType.FloatingPoint) {
252 | long bits = cbor.AsDoubleBits();
253 | return new byte[] {
254 | (byte)0xfb,
255 | (byte)((bits >> 56) & 0xffL),
256 | (byte)((bits >> 48) & 0xffL),
257 | (byte)((bits >> 40) & 0xffL),
258 | (byte)((bits >> 32) & 0xffL),
259 | (byte)((bits >> 24) & 0xffL),
260 | (byte)((bits >> 16) & 0xffL),
261 | (byte)((bits >> 8) & 0xffL),
262 | (byte)(bits & 0xffL),
263 | };
264 | } else {
265 | if (!(valueAType == CBORType.Integer)) {
266 | throw new IllegalArgumentException("Invalid CBOR type.");
267 | }
268 | return cbor.EncodeToBytes(CBOREncodeOptions.Default);
269 | }
270 | }
271 | }
272 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORDoubleBits.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | import com.upokecenter.numbers.*;
11 |
12 | class CBORDoubleBits implements ICBORNumber {
13 | public boolean IsPositiveInfinity(Object obj) {
14 | return ((((Long)obj).longValue())) == (0x7ffL << 52);
15 | }
16 |
17 | public boolean IsInfinity(Object obj) {
18 | return (((((Long)obj).longValue())) & ~(1L << 63)) == (0x7ffL << 52);
19 | }
20 |
21 | public boolean IsNegativeInfinity(Object obj) {
22 | return ((((Long)obj).longValue())) == (0xfffL << 52);
23 | }
24 |
25 | public boolean IsNaN(Object obj) {
26 | return CBORUtilities.DoubleBitsNaN((((Long)obj).longValue()));
27 | }
28 |
29 | public double AsDouble(Object obj) {
30 | return CBORUtilities.Int64BitsToDouble((((Long)obj).longValue()));
31 | }
32 |
33 | public EDecimal AsEDecimal(Object obj) {
34 | return EDecimal.FromDoubleBits((((Long)obj).longValue()));
35 | }
36 |
37 | public EFloat AsEFloat(Object obj) {
38 | return EFloat.FromDoubleBits((((Long)obj).longValue()));
39 | }
40 |
41 | public float AsSingle(Object obj) {
42 | return CBORUtilities.Int32BitsToSingle(
43 | CBORUtilities.DoubleToRoundedSinglePrecision((((Long)obj).longValue())));
44 | }
45 |
46 | public EInteger AsEInteger(Object obj) {
47 | return CBORUtilities.EIntegerFromDoubleBits((((Long)obj).longValue()));
48 | }
49 |
50 | public long AsInt64(Object obj) {
51 | if (this.IsNaN(obj) || this.IsInfinity(obj)) {
52 | throw new ArithmeticException("This Object's value is out of range");
53 | }
54 | long b = DoubleBitsRoundDown((((Long)obj).longValue()));
55 | boolean neg = (b >> 63) != 0;
56 | b &= ~(1L << 63);
57 | if (b == 0) {
58 | return 0;
59 | }
60 | if (neg && b == (0x43eL << 52)) {
61 | return Long.MIN_VALUE;
62 | }
63 | if ((b >> 52) >= 0x43e) {
64 | throw new ArithmeticException("This Object's value is out of range");
65 | }
66 | int exp = (int)(b >> 52);
67 | long mant = b & ((1L << 52) - 1);
68 | mant |= 1L << 52;
69 | int shift = 52 - (exp - 0x3ff);
70 | if (shift < 0) {
71 | mant <<= -shift;
72 | } else {
73 | mant >>= shift;
74 | }
75 | if (neg) {
76 | mant = -mant;
77 | }
78 | return mant;
79 | }
80 |
81 | public boolean CanFitInSingle(Object obj) {
82 | return this.IsNaN(obj) ||
83 | CBORUtilities.DoubleRetainsSameValueInSingle((((Long)obj).longValue()));
84 | }
85 |
86 | public boolean CanFitInDouble(Object obj) {
87 | return true;
88 | }
89 |
90 | public boolean CanFitInInt32(Object obj) {
91 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt32(obj);
92 | }
93 |
94 | public boolean CanFitInInt64(Object obj) {
95 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt64(obj);
96 | }
97 |
98 | public boolean CanFitInUInt64(Object obj) {
99 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInUInt64(obj);
100 | }
101 |
102 | private static long DoubleBitsRoundDown(long bits) {
103 | long origbits = bits;
104 | bits &= ~(1L << 63);
105 | if (bits == 0) {
106 | return origbits;
107 | }
108 | // Infinity and NaN
109 | if (bits >= (0x7ffL << 52)) {
110 | return origbits;
111 | }
112 | // Beyond noninteger range
113 | if ((bits >> 52) >= 0x433) {
114 | return origbits;
115 | }
116 | // Less than 1
117 | if ((bits >> 52) <= 0x3fe) {
118 | return (origbits >> 63) != 0 ? (1L << 63) : 0;
119 | }
120 | int exp = (int)(bits >> 52);
121 | long mant = bits & ((1L << 52) - 1);
122 | int shift = 52 - (exp - 0x3ff);
123 | return ((mant >> shift) << shift) | (origbits & (0xfffL << 52));
124 | }
125 |
126 | public boolean CanTruncatedIntFitInInt64(Object obj) {
127 | if (this.IsNaN(obj) || this.IsInfinity(obj)) {
128 | return false;
129 | }
130 | long b = DoubleBitsRoundDown((((Long)obj).longValue()));
131 | boolean neg = (b >> 63) != 0;
132 | b &= ~(1L << 63);
133 | return (neg && b == (0x43eL << 52)) || ((b >> 52) < 0x43e);
134 | }
135 |
136 | public boolean CanTruncatedIntFitInUInt64(Object obj) {
137 | if (this.IsNaN(obj) || this.IsInfinity(obj)) {
138 | return false;
139 | }
140 | long b = DoubleBitsRoundDown((((Long)obj).longValue()));
141 | boolean neg = (b >> 63) != 0;
142 | b &= ~(1L << 63);
143 | return (neg && b == 0) || (!neg && (b >> 52) < 0x43f);
144 | }
145 |
146 | public boolean CanTruncatedIntFitInInt32(Object obj) {
147 | if (this.IsNaN(obj) || this.IsInfinity(obj)) {
148 | return false;
149 | }
150 | long b = DoubleBitsRoundDown((((Long)obj).longValue()));
151 | boolean neg = (b >> 63) != 0;
152 | b &= ~(1L << 63);
153 | return (neg && b == (0x41eL << 52)) || ((b >> 52) < 0x41e);
154 | }
155 |
156 | public int AsInt32(Object obj, int minValue, int maxValue) {
157 | if (this.IsNaN(obj) || this.IsInfinity(obj)) {
158 | throw new ArithmeticException("This Object's value is out of range");
159 | }
160 | long b = DoubleBitsRoundDown((((Long)obj).longValue()));
161 | boolean neg = (b >> 63) != 0;
162 | b &= ~(1L << 63);
163 | if (b == 0) {
164 | return 0;
165 | }
166 | // Beyond noninteger range (thus beyond int32 range)
167 | if ((b >> 52) >= 0x433) {
168 | throw new ArithmeticException("This Object's value is out of range");
169 | }
170 | int exp = (int)(b >> 52);
171 | long mant = b & ((1L << 52) - 1);
172 | mant |= 1L << 52;
173 | int shift = 52 - (exp - 0x3ff);
174 | mant >>= shift;
175 | if (neg) {
176 | mant = -mant;
177 | }
178 | if (mant < minValue || mant > maxValue) {
179 | throw new ArithmeticException("This Object's value is out of range");
180 | }
181 | return (int)mant;
182 | }
183 |
184 | public boolean IsNumberZero(Object obj) {
185 | return (((((Long)obj).longValue())) & ~(1L << 63)) == 0;
186 | }
187 |
188 | public int Sign(Object obj) {
189 | return this.IsNaN(obj) ? (-2) : ((((((Long)obj).longValue())) >> 63) != 0 ? -1 : 1);
190 | }
191 |
192 | public boolean IsIntegral(Object obj) {
193 | return CBORUtilities.IsIntegerValue((((Long)obj).longValue()));
194 | }
195 |
196 | public Object Negate(Object obj) {
197 | return ((((Long)obj).longValue())) ^ (1L << 63);
198 | }
199 |
200 | public Object Abs(Object obj) {
201 | return ((((Long)obj).longValue())) & ~(1L << 63);
202 | }
203 |
204 | public ERational AsERational(Object obj) {
205 | return ERational.FromDoubleBits((((Long)obj).longValue()));
206 | }
207 |
208 | public boolean IsNegative(Object obj) {
209 | return (((((Long)obj).longValue())) >> 63) != 0;
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBOREInteger.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | import com.upokecenter.numbers.*;
11 |
12 | class CBOREInteger implements ICBORNumber {
13 | public boolean IsPositiveInfinity(Object obj) {
14 | return false;
15 | }
16 |
17 | public boolean IsInfinity(Object obj) {
18 | return false;
19 | }
20 |
21 | public boolean IsNegativeInfinity(Object obj) {
22 | return false;
23 | }
24 |
25 | public boolean IsNaN(Object obj) {
26 | return false;
27 | }
28 |
29 | public double AsDouble(Object obj) {
30 | return EFloat.FromEInteger((EInteger)obj).ToDouble();
31 | }
32 |
33 | public EDecimal AsEDecimal(Object obj) {
34 | return EDecimal.FromEInteger((EInteger)obj);
35 | }
36 |
37 | public EFloat AsEFloat(Object obj) {
38 | return EFloat.FromEInteger((EInteger)obj);
39 | }
40 |
41 | public float AsSingle(Object obj) {
42 | return EFloat.FromEInteger((EInteger)obj).ToSingle();
43 | }
44 |
45 | public EInteger AsEInteger(Object obj) {
46 | return (EInteger)obj;
47 | }
48 |
49 | public long AsInt64(Object obj) {
50 | EInteger bi = (EInteger)obj;
51 | if (!bi.CanFitInInt64()) {
52 | throw new ArithmeticException("This" +
53 | "\u0020object's value is out of range");
54 | }
55 | return bi.ToInt64Checked();
56 | }
57 |
58 | public boolean CanFitInSingle(Object obj) {
59 | EInteger bigintItem = (EInteger)obj;
60 | EFloat ef = EFloat.FromEInteger(bigintItem);
61 | EFloat ef2 = EFloat.FromSingle(ef.ToSingle());
62 | return ef.compareTo(ef2) == 0;
63 | }
64 |
65 | public boolean CanFitInDouble(Object obj) {
66 | EInteger bigintItem = (EInteger)obj;
67 | EFloat ef = EFloat.FromEInteger(bigintItem);
68 | EFloat ef2 = EFloat.FromDouble(ef.ToDouble());
69 | return ef.compareTo(ef2) == 0;
70 | }
71 |
72 | public boolean CanFitInInt32(Object obj) {
73 | EInteger bi = (EInteger)obj;
74 | return bi.CanFitInInt32();
75 | }
76 |
77 | public boolean CanFitInInt64(Object obj) {
78 | EInteger bi = (EInteger)obj;
79 | return bi.CanFitInInt64();
80 | }
81 |
82 | public boolean CanFitInUInt64(Object obj) {
83 | EInteger bi = (EInteger)obj;
84 | return bi.signum() >= 0 && bi.GetUnsignedBitLengthAsInt64() <= 64;
85 | }
86 |
87 | public boolean CanTruncatedIntFitInInt64(Object obj) {
88 | return this.CanFitInInt64(obj);
89 | }
90 |
91 | public boolean CanTruncatedIntFitInUInt64(Object obj) {
92 | return this.CanFitInUInt64(obj);
93 | }
94 |
95 | public boolean CanTruncatedIntFitInInt32(Object obj) {
96 | return this.CanFitInInt32(obj);
97 | }
98 |
99 | public boolean IsNumberZero(Object obj) {
100 | return ((EInteger)obj).isZero();
101 | }
102 |
103 | public int Sign(Object obj) {
104 | return ((EInteger)obj).signum();
105 | }
106 |
107 | public boolean IsIntegral(Object obj) {
108 | return true;
109 | }
110 |
111 | public int AsInt32(Object obj, int minValue, int maxValue) {
112 | EInteger bi = (EInteger)obj;
113 | if (bi.CanFitInInt32()) {
114 | int ret = bi.ToInt32Checked();
115 | if (ret >= minValue && ret <= maxValue) {
116 | return ret;
117 | }
118 | }
119 | throw new ArithmeticException("This Object's value is out of range");
120 | }
121 |
122 | public Object Negate(Object obj) {
123 | EInteger bigobj = (EInteger)obj;
124 | bigobj = bigobj.Negate();
125 | return bigobj;
126 | }
127 |
128 | public Object Abs(Object obj) {
129 | return ((EInteger)obj).Abs();
130 | }
131 |
132 | public ERational AsERational(Object obj) {
133 | return ERational.FromEInteger((EInteger)obj);
134 | }
135 |
136 | public boolean IsNegative(Object obj) {
137 | return ((EInteger)obj).signum() < 0;
138 | }
139 | }
140 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORException.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Any copyright to this work is released to the Public Domain.
4 | In case this is not possible, this work is also
5 | licensed under the Unlicense: https://unlicense.org/
6 |
7 | */
8 |
9 | /**
10 | *
Exception thrown for errors involving CBOR data.
This library may
11 | * throw exceptions of this type in certain cases, notably when errors occur,
12 | * and may supply messages to those exceptions (the message can be accessed
13 | * through the {@code Message} property in.NET or the {@code getMessage()}
14 | * method in Java). These messages are intended to be read by humans to help
15 | * diagnose the error (or other cause of the exception); they are not intended
16 | * to be parsed by computer programs, and the exact text of the messages may
17 | * change at any time between versions of this library.
18 | */
19 |
20 | public final class CBORException extends RuntimeException {
21 | private static final long serialVersionUID = 1L;
22 | /**
23 | * Initializes a new instance of the {@link com.upokecenter.cbor.CBORException}
24 | * class.
25 | */
26 | public CBORException() {
27 | }
28 |
29 | /**
30 | * Initializes a new instance of the {@link com.upokecenter.cbor.CBORException}
31 | * class.
32 | * @param message The parameter {@code message} is a text string.
33 | */
34 | public CBORException(String message) {
35 | super(message);
36 | }
37 |
38 | /**
39 | * Initializes a new instance of the {@link com.upokecenter.cbor.CBORException}
40 | * class. Uses the specified message and inner exception.
41 | * @param message The parameter {@code message} is a text string.
42 | * @param innerException The parameter {@code innerException} is an Exception
43 | * object.
44 | */
45 | public CBORException(String message, Throwable innerException) {
46 | super(message);
47 | initCause(innerException);;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORExtendedDecimal.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | import com.upokecenter.numbers.*;
11 |
12 | class CBORExtendedDecimal implements ICBORNumber {
13 | public boolean IsPositiveInfinity(Object obj) {
14 | EDecimal ed = (EDecimal)obj;
15 | return ed.IsPositiveInfinity();
16 | }
17 |
18 | public boolean IsInfinity(Object obj) {
19 | EDecimal ed = (EDecimal)obj;
20 | return ed.IsInfinity();
21 | }
22 |
23 | public boolean IsNegativeInfinity(Object obj) {
24 | EDecimal ed = (EDecimal)obj;
25 | return ed.IsNegativeInfinity();
26 | }
27 |
28 | public boolean IsNaN(Object obj) {
29 | EDecimal ed = (EDecimal)obj;
30 | return ed.IsNaN();
31 | }
32 |
33 | public double AsDouble(Object obj) {
34 | EDecimal ed = (EDecimal)obj;
35 | return ed.ToDouble();
36 | }
37 |
38 | public EDecimal AsEDecimal(Object obj) {
39 | EDecimal ed = (EDecimal)obj;
40 | return ed;
41 | }
42 |
43 | public EFloat AsEFloat(Object obj) {
44 | EDecimal ed = (EDecimal)obj;
45 | return ed.ToEFloat();
46 | }
47 |
48 | public float AsSingle(Object obj) {
49 | EDecimal ed = (EDecimal)obj;
50 | return ed.ToSingle();
51 | }
52 |
53 | public EInteger AsEInteger(Object obj) {
54 | EDecimal ed = (EDecimal)obj;
55 | return ed.ToEInteger();
56 | }
57 |
58 | public long AsInt64(Object obj) {
59 | EDecimal ef = (EDecimal)obj;
60 | if (this.CanTruncatedIntFitInInt64(obj)) {
61 | EInteger bi = ef.ToEInteger();
62 | return bi.ToInt64Checked();
63 | }
64 | throw new ArithmeticException("This Object's value is out of range");
65 | }
66 |
67 | public boolean CanFitInSingle(Object obj) {
68 | EDecimal ef = (EDecimal)obj;
69 | return (!ef.isFinite()) || (ef.compareTo(EDecimal.FromSingle(
70 | ef.ToSingle())) == 0);
71 | }
72 |
73 | public boolean CanFitInDouble(Object obj) {
74 | EDecimal ef = (EDecimal)obj;
75 | return (!ef.isFinite()) || (ef.compareTo(EDecimal.FromDouble(
76 | ef.ToDouble())) == 0);
77 | }
78 |
79 | public boolean CanFitInInt32(Object obj) {
80 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt32(obj);
81 | }
82 |
83 | public boolean CanFitInInt64(Object obj) {
84 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt64(obj);
85 | }
86 |
87 | public boolean CanFitInUInt64(Object obj) {
88 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInUInt64(obj);
89 | }
90 |
91 | public boolean CanTruncatedIntFitInInt64(Object obj) {
92 | EDecimal ef = (EDecimal)obj;
93 | if (!ef.isFinite()) {
94 | return false;
95 | }
96 | if (ef.isZero()) {
97 | return true;
98 | }
99 | if (ef.getExponent().compareTo(EInteger.FromInt64(21)) >= 0) {
100 | return false;
101 | }
102 | EInteger bi = ef.ToEInteger();
103 | return bi.CanFitInInt64();
104 | }
105 |
106 | public boolean CanTruncatedIntFitInUInt64(Object obj) {
107 | EDecimal ef = (EDecimal)obj;
108 | if (!ef.isFinite()) {
109 | return false;
110 | }
111 | if (ef.isZero()) {
112 | return true;
113 | }
114 | if (ef.getExponent().compareTo(EInteger.FromInt64(21)) >= 0) {
115 | return false;
116 | }
117 | EInteger bi = ef.ToEInteger();
118 | return bi.signum() >= 0 && bi.GetUnsignedBitLengthAsInt64() <= 64;
119 | }
120 |
121 | public boolean CanTruncatedIntFitInInt32(Object obj) {
122 | EDecimal ef = (EDecimal)obj;
123 | if (!ef.isFinite()) {
124 | return false;
125 | }
126 | if (ef.isZero()) {
127 | return true;
128 | }
129 | if (ef.getExponent().compareTo(EInteger.FromInt64(11)) >= 0) {
130 | return false;
131 | }
132 | EInteger bi = ef.ToEInteger();
133 | return bi.CanFitInInt32();
134 | }
135 |
136 | public boolean IsNumberZero(Object obj) {
137 | EDecimal ed = (EDecimal)obj;
138 | return ed.isZero();
139 | }
140 |
141 | public int Sign(Object obj) {
142 | EDecimal ed = (EDecimal)obj;
143 | return ed.IsNaN() ? 2 : ed.signum();
144 | }
145 |
146 | public boolean IsIntegral(Object obj) {
147 | EDecimal ed = (EDecimal)obj;
148 | return ed.isFinite() && ((ed.getExponent().signum() >= 0) ||
149 | (ed.compareTo(EDecimal.FromEInteger(ed.ToEInteger())) ==
150 |
151 | 0));
152 | }
153 |
154 | public int AsInt32(Object obj, int minValue, int maxValue) {
155 | EDecimal ef = (EDecimal)obj;
156 | if (this.CanTruncatedIntFitInInt32(obj)) {
157 | EInteger bi = ef.ToEInteger();
158 | int ret = bi.ToInt32Checked();
159 | if (ret >= minValue && ret <= maxValue) {
160 | return ret;
161 | }
162 | }
163 | throw new ArithmeticException("This Object's value is out of range");
164 | }
165 |
166 | public Object Negate(Object obj) {
167 | EDecimal ed = (EDecimal)obj;
168 | return ed.Negate();
169 | }
170 |
171 | public Object Abs(Object obj) {
172 | EDecimal ed = (EDecimal)obj;
173 | return ed.Abs();
174 | }
175 |
176 | public ERational AsERational(Object obj) {
177 | return ERational.FromEDecimal((EDecimal)obj);
178 | }
179 |
180 | public boolean IsNegative(Object obj) {
181 | return ((EDecimal)obj).isNegative();
182 | }
183 | }
184 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORExtendedFloat.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | import com.upokecenter.numbers.*;
11 |
12 | class CBORExtendedFloat implements ICBORNumber {
13 | public boolean IsPositiveInfinity(Object obj) {
14 | EFloat ef = (EFloat)obj;
15 | return ef.IsPositiveInfinity();
16 | }
17 |
18 | public boolean IsInfinity(Object obj) {
19 | EFloat ef = (EFloat)obj;
20 | return ef.IsInfinity();
21 | }
22 |
23 | public boolean IsNegativeInfinity(Object obj) {
24 | EFloat ef = (EFloat)obj;
25 | return ef.IsNegativeInfinity();
26 | }
27 |
28 | public boolean IsNaN(Object obj) {
29 | EFloat ef = (EFloat)obj;
30 | return ef.IsNaN();
31 | }
32 |
33 | public double AsDouble(Object obj) {
34 | EFloat ef = (EFloat)obj;
35 | return ef.ToDouble();
36 | }
37 |
38 | public EDecimal AsEDecimal(Object obj) {
39 | EFloat ef = (EFloat)obj;
40 | return ef.ToEDecimal();
41 | }
42 |
43 | public EFloat AsEFloat(Object obj) {
44 | EFloat ef = (EFloat)obj;
45 | return ef;
46 | }
47 |
48 | public float AsSingle(Object obj) {
49 | EFloat ef = (EFloat)obj;
50 | return ef.ToSingle();
51 | }
52 |
53 | public EInteger AsEInteger(Object obj) {
54 | EFloat ef = (EFloat)obj;
55 | return ef.ToEInteger();
56 | }
57 |
58 | public long AsInt64(Object obj) {
59 | EFloat ef = (EFloat)obj;
60 | if (this.CanTruncatedIntFitInInt64(obj)) {
61 | EInteger bi = ef.ToEInteger();
62 | return bi.ToInt64Checked();
63 | }
64 | throw new ArithmeticException("This Object's value is out of range");
65 | }
66 |
67 | public boolean CanFitInSingle(Object obj) {
68 | EFloat ef = (EFloat)obj;
69 | return (!ef.isFinite()) || (ef.compareTo(EFloat.FromSingle(
70 | ef.ToSingle())) == 0);
71 | }
72 |
73 | public boolean CanFitInDouble(Object obj) {
74 | EFloat ef = (EFloat)obj;
75 | return (!ef.isFinite()) || (ef.compareTo(EFloat.FromDouble(
76 | ef.ToDouble())) == 0);
77 | }
78 |
79 | public boolean CanFitInInt32(Object obj) {
80 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt32(obj);
81 | }
82 |
83 | public boolean CanFitInInt64(Object obj) {
84 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt64(obj);
85 | }
86 |
87 | public boolean CanFitInUInt64(Object obj) {
88 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInUInt64(obj);
89 | }
90 |
91 | public boolean CanTruncatedIntFitInInt64(Object obj) {
92 | EFloat ef = (EFloat)obj;
93 | if (!ef.isFinite()) {
94 | return false;
95 | }
96 | if (ef.isZero()) {
97 | return true;
98 | }
99 | if (ef.getExponent().compareTo(EInteger.FromInt64(65)) >= 0) {
100 | return false;
101 | }
102 | EInteger bi = ef.ToEInteger();
103 | return bi.CanFitInInt64();
104 | }
105 |
106 | public boolean CanTruncatedIntFitInUInt64(Object obj) {
107 | EFloat ef = (EFloat)obj;
108 | if (!ef.isFinite()) {
109 | return false;
110 | }
111 | if (ef.isZero()) {
112 | return true;
113 | }
114 | if (ef.getExponent().compareTo(EInteger.FromInt64(65)) >= 0) {
115 | return false;
116 | }
117 | EInteger bi = ef.ToEInteger();
118 | return bi.signum() >= 0 && bi.GetUnsignedBitLengthAsInt64() <= 64;
119 | }
120 |
121 | public boolean CanTruncatedIntFitInInt32(Object obj) {
122 | EFloat ef = (EFloat)obj;
123 | if (!ef.isFinite()) {
124 | return false;
125 | }
126 | if (ef.isZero()) {
127 | return true;
128 | }
129 | if (ef.getExponent().compareTo(EInteger.FromInt64(33)) >= 0) {
130 | return false;
131 | }
132 | EInteger bi = ef.ToEInteger();
133 | return bi.CanFitInInt32();
134 | }
135 |
136 | public boolean IsNumberZero(Object obj) {
137 | EFloat ef = (EFloat)obj;
138 | return ef.isZero();
139 | }
140 |
141 | public int Sign(Object obj) {
142 | EFloat ef = (EFloat)obj;
143 | return ef.IsNaN() ? 2 : ef.signum();
144 | }
145 |
146 | public boolean IsIntegral(Object obj) {
147 | EFloat ef = (EFloat)obj;
148 | if (!ef.isFinite()) {
149 | return false;
150 | }
151 | if (ef.getExponent().signum() >= 0) {
152 | return true;
153 | }
154 | EFloat ef2 = EFloat.FromEInteger(ef.ToEInteger());
155 | return ef2.compareTo(ef) == 0;
156 | }
157 |
158 | public int AsInt32(Object obj, int minValue, int maxValue) {
159 | EFloat ef = (EFloat)obj;
160 | if (this.CanTruncatedIntFitInInt32(obj)) {
161 | EInteger bi = ef.ToEInteger();
162 | int ret = bi.ToInt32Checked();
163 | if (ret >= minValue && ret <= maxValue) {
164 | return ret;
165 | }
166 | }
167 | throw new ArithmeticException("This Object's value is out of range");
168 | }
169 |
170 | public Object Negate(Object obj) {
171 | EFloat ed = (EFloat)obj;
172 | return ed.Negate();
173 | }
174 |
175 | public Object Abs(Object obj) {
176 | EFloat ed = (EFloat)obj;
177 | return ed.Abs();
178 | }
179 |
180 | public ERational AsERational(Object obj) {
181 | return ERational.FromEFloat((EFloat)obj);
182 | }
183 |
184 | public boolean IsNegative(Object obj) {
185 | return ((EFloat)obj).isNegative();
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORExtendedRational.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | import com.upokecenter.numbers.*;
11 |
12 | class CBORExtendedRational implements ICBORNumber {
13 | public boolean IsPositiveInfinity(Object obj) {
14 | return ((ERational)obj).IsPositiveInfinity();
15 | }
16 |
17 | public boolean IsInfinity(Object obj) {
18 | return ((ERational)obj).IsInfinity();
19 | }
20 |
21 | public boolean IsNegativeInfinity(Object obj) {
22 | return ((ERational)obj).IsNegativeInfinity();
23 | }
24 |
25 | public boolean IsNaN(Object obj) {
26 | return ((ERational)obj).IsNaN();
27 | }
28 |
29 | public double AsDouble(Object obj) {
30 | ERational er = (ERational)obj;
31 | return er.ToDouble();
32 | }
33 |
34 | public EDecimal AsEDecimal(Object obj) {
35 | ERational er = (ERational)obj;
36 | return
37 |
38 | er.ToEDecimalExactIfPossible(
39 | EContext.Decimal128.WithUnlimitedExponents());
40 | }
41 |
42 | public EFloat AsEFloat(Object obj) {
43 | ERational er = (ERational)obj;
44 | return
45 |
46 | er.ToEFloatExactIfPossible(
47 | EContext.Binary128.WithUnlimitedExponents());
48 | }
49 |
50 | public float AsSingle(Object obj) {
51 | ERational er = (ERational)obj;
52 | return er.ToSingle();
53 | }
54 |
55 | public EInteger AsEInteger(Object obj) {
56 | ERational er = (ERational)obj;
57 | return er.ToEInteger();
58 | }
59 |
60 | public long AsInt64(Object obj) {
61 | ERational ef = (ERational)obj;
62 | if (ef.isFinite()) {
63 | EInteger bi = ef.ToEInteger();
64 | if (bi.CanFitInInt64()) {
65 | return bi.ToInt64Checked();
66 | }
67 | }
68 | throw new ArithmeticException("This Object's value is out of range");
69 | }
70 |
71 | public boolean CanFitInSingle(Object obj) {
72 | ERational ef = (ERational)obj;
73 | return (!ef.isFinite()) || (ef.compareTo(ERational.FromSingle(
74 | ef.ToSingle())) == 0);
75 | }
76 |
77 | public boolean CanFitInDouble(Object obj) {
78 | ERational ef = (ERational)obj;
79 | return (!ef.isFinite()) || (ef.compareTo(ERational.FromDouble(
80 | ef.ToDouble())) == 0);
81 | }
82 |
83 | public boolean CanFitInInt32(Object obj) {
84 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt32(obj);
85 | }
86 |
87 | public boolean CanFitInInt64(Object obj) {
88 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInInt64(obj);
89 | }
90 |
91 | public boolean CanFitInUInt64(Object obj) {
92 | return this.IsIntegral(obj) && this.CanTruncatedIntFitInUInt64(obj);
93 | }
94 |
95 | public boolean CanTruncatedIntFitInInt64(Object obj) {
96 | ERational ef = (ERational)obj;
97 | if (!ef.isFinite()) {
98 | return false;
99 | }
100 | EInteger bi = ef.ToEInteger();
101 | return bi.CanFitInInt64();
102 | }
103 |
104 | public boolean CanTruncatedIntFitInInt32(Object obj) {
105 | ERational ef = (ERational)obj;
106 | if (!ef.isFinite()) {
107 | return false;
108 | }
109 | EInteger bi = ef.ToEInteger();
110 | return bi.CanFitInInt32();
111 | }
112 |
113 | public boolean CanTruncatedIntFitInUInt64(Object obj) {
114 | ERational ef = (ERational)obj;
115 | if (!ef.isFinite()) {
116 | return false;
117 | }
118 | EInteger bi = ef.ToEInteger();
119 | return bi.signum() >= 0 && bi.GetUnsignedBitLengthAsInt64() <= 64;
120 | }
121 |
122 | public boolean IsNumberZero(Object obj) {
123 | ERational ef = (ERational)obj;
124 | return ef.isZero();
125 | }
126 |
127 | public int Sign(Object obj) {
128 | ERational ef = (ERational)obj;
129 | return ef.signum();
130 | }
131 |
132 | public boolean IsIntegral(Object obj) {
133 | ERational ef = (ERational)obj;
134 | if (!ef.isFinite()) {
135 | return false;
136 | }
137 | if (ef.getDenominator().equals(EInteger.FromInt32(1))) {
138 | return true;
139 | }
140 | // A rational number is integral if the remainder
141 | // of the numerator divided by the denominator is 0
142 | EInteger denom = ef.getDenominator();
143 | EInteger rem = ef.getNumerator().Remainder(denom);
144 | return rem.isZero();
145 | }
146 |
147 | public int AsInt32(Object obj, int minValue, int maxValue) {
148 | ERational ef = (ERational)obj;
149 | if (ef.isFinite()) {
150 | EInteger bi = ef.ToEInteger();
151 | if (bi.CanFitInInt32()) {
152 | int ret = bi.ToInt32Checked();
153 | if (ret >= minValue && ret <= maxValue) {
154 | return ret;
155 | }
156 | }
157 | }
158 | throw new ArithmeticException("This Object's value is out of range");
159 | }
160 |
161 | public Object Negate(Object obj) {
162 | ERational ed = (ERational)obj;
163 | return ed.Negate();
164 | }
165 |
166 | public Object Abs(Object obj) {
167 | ERational ed = (ERational)obj;
168 | return ed.Abs();
169 | }
170 |
171 | public ERational AsERational(Object obj) {
172 | return (ERational)obj;
173 | }
174 |
175 | public boolean IsNegative(Object obj) {
176 | return ((ERational)obj).isNegative();
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORInteger.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | import com.upokecenter.numbers.*;
11 |
12 | class CBORInteger implements ICBORNumber {
13 | public Object Abs(Object obj) {
14 | long val = (((Long)obj).longValue());
15 | return (val == Integer.MIN_VALUE) ? (EInteger.FromInt32(1).ShiftLeft(63)) : ((val < 0) ?
16 | -val : obj);
17 | }
18 |
19 | public EInteger AsEInteger(Object obj) {
20 | return EInteger.FromInt64((((Long)obj).longValue()));
21 | }
22 |
23 | public double AsDouble(Object obj) {
24 | return ((Long)obj).longValue();
25 | }
26 |
27 | public EDecimal AsEDecimal(Object obj) {
28 | return EDecimal.FromInt64((((Long)obj).longValue()));
29 | }
30 |
31 | public EFloat AsEFloat(Object obj) {
32 | return EFloat.FromInt64((((Long)obj).longValue()));
33 | }
34 |
35 | public ERational AsERational(Object obj) {
36 | return ERational.FromInt64((((Long)obj).longValue()));
37 | }
38 |
39 | public int AsInt32(Object obj, int minValue, int maxValue) {
40 | long val = (((Long)obj).longValue());
41 | if (!(val >= minValue && val <= maxValue)) {
42 | throw new ArithmeticException("This Object's value is out of range");
43 | }
44 | return (int)val;
45 | }
46 |
47 | public long AsInt64(Object obj) {
48 | return ((Long)obj).longValue();
49 | }
50 |
51 | public float AsSingle(Object obj) {
52 | return ((Long)obj).longValue();
53 | }
54 |
55 | public boolean CanFitInDouble(Object obj) {
56 | long intItem = (((Long)obj).longValue());
57 | if (intItem == Long.MIN_VALUE) {
58 | return true;
59 | }
60 | intItem = (intItem < 0) ? -intItem : intItem;
61 | while (intItem >= (1L << 53) && (intItem & 1) == 0) {
62 | intItem >>= 1;
63 | }
64 | return intItem < (1L << 53);
65 | }
66 |
67 | public boolean CanFitInInt32(Object obj) {
68 | long val = (((Long)obj).longValue());
69 | return val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE;
70 | }
71 |
72 | public boolean CanFitInInt64(Object obj) {
73 | return true;
74 | }
75 |
76 | public boolean CanFitInSingle(Object obj) {
77 | long intItem = (((Long)obj).longValue());
78 | if (intItem == Long.MIN_VALUE) {
79 | return true;
80 | }
81 | intItem = (intItem < 0) ? -intItem : intItem;
82 | while (intItem >= (1L << 24) && (intItem & 1) == 0) {
83 | intItem >>= 1;
84 | }
85 | return intItem < (1L << 24);
86 | }
87 |
88 | public boolean CanTruncatedIntFitInInt32(Object obj) {
89 | long val = (((Long)obj).longValue());
90 | return val >= Integer.MIN_VALUE && val <= Integer.MAX_VALUE;
91 | }
92 |
93 | public boolean CanTruncatedIntFitInUInt64(Object obj) {
94 | long val = (((Long)obj).longValue());
95 | return val >= 0;
96 | }
97 |
98 | public boolean CanFitInUInt64(Object obj) {
99 | long val = (((Long)obj).longValue());
100 | return val >= 0;
101 | }
102 |
103 | public boolean CanTruncatedIntFitInInt64(Object obj) {
104 | return true;
105 | }
106 |
107 | public boolean IsInfinity(Object obj) {
108 | return false;
109 | }
110 |
111 | public boolean IsIntegral(Object obj) {
112 | return true;
113 | }
114 |
115 | public boolean IsNaN(Object obj) {
116 | return false;
117 | }
118 |
119 | public boolean IsNegative(Object obj) {
120 | return ((((Long)obj).longValue())) < 0;
121 | }
122 |
123 | public boolean IsNegativeInfinity(Object obj) {
124 | return false;
125 | }
126 |
127 | public boolean IsPositiveInfinity(Object obj) {
128 | return false;
129 | }
130 |
131 | public boolean IsNumberZero(Object obj) {
132 | return ((((Long)obj).longValue())) == 0;
133 | }
134 |
135 | public Object Negate(Object obj) {
136 | return (((((Long)obj).longValue())) == Long.MIN_VALUE) ? (EInteger.FromInt32(1).ShiftLeft(63)) :
137 | (-(((Long)obj).longValue()));
138 | }
139 |
140 | public int Sign(Object obj) {
141 | long val = (((Long)obj).longValue());
142 | return (val == 0) ? 0 : ((val < 0) ? -1 : 1);
143 | }
144 | }
145 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORType.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 | /*
3 | Written by Peter O.
4 | Any copyright to this work is released to the Public Domain.
5 | In case this is not possible, this work is also
6 | licensed under the Unlicense: https://unlicense.org/
7 |
8 | */
9 |
10 | /**
11 | * Represents a type that a CBOR object can have.
12 | */
13 | public enum CBORType
14 | {
15 | /**
16 | * This property is no longer used.
17 | * @deprecated Since version 4.0, CBORObject.Type no longer returns this\u0020value for any
18 | * CBOR Object - this is a breaking change from earlier
19 | * versions.\u0020Instead, use the IsNumber property of CBORObject to
20 | * determine whether a CBOR Object represents a number, or use the two new
21 | * CBORType values instead. CBORType.Integer covers CBOR objects
22 | * representing\u0020integers of\u0020major type 0 and 1.
23 | * CBORType.FloatingPoint covers CBOR objects representing 16-, 32-, and
24 | * 64-bit floating-point numbers. CBORType.Number may be removed in version
25 | * 5.0 or later.
26 | */
27 | @Deprecated
28 | Number,
29 |
30 | /**
31 | * The simple values true and false.
32 | */
33 | Boolean,
34 |
35 | /**
36 | * A "simple value" other than floating point values, true, and false.
37 | */
38 | SimpleValue,
39 |
40 | /**
41 | * An array of bytes.
42 | */
43 | ByteString,
44 |
45 | /**
46 | * A text string.
47 | */
48 | TextString,
49 |
50 | /**
51 | * An array of CBOR objects.
52 | */
53 | Array,
54 |
55 | /**
56 | * A map of CBOR objects.
57 | */
58 | Map,
59 |
60 | /**
61 | * An integer in the interval [-(2^64), 2^64 - 1], or an integer of major type
62 | * 0 and 1.
63 | */
64 | Integer,
65 |
66 | /**
67 | * A 16-, 32-, or 64-bit binary floating-point number.
68 | */
69 | FloatingPoint,
70 | }
71 |
--------------------------------------------------------------------------------
/src/main/java/com/upokecenter/cbor/CBORTypeMapper.java:
--------------------------------------------------------------------------------
1 | package com.upokecenter.cbor;
2 |
3 | import java.util.*;
4 |
5 | /**
6 | * Holds converters to customize the serialization and deserialization behavior
7 | * of {@code CBORObject.FromObject} and {@code CBORObject#ToObject}, as well as
8 | * type filters for {@code ToObject}.
9 | */
10 | public final class CBORTypeMapper {
11 | private final List typePrefixes;
12 | private final List typeNames;
13 | private final Map