Repository navigation
Add a CBOR module that reads and writes TLA+ values #136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| -------------------------------- MODULE CBOR -------------------------------- | ||
| (***************************************************************************) | ||
|
younes-io marked this conversation as resolved.
|
||
| (* Encodes TLA+ values as CBOR (RFC 8949) and decodes them back. *) | ||
| (* CBORSerialize and CBORDeserialize exchange values through files. *) | ||
| (* Public ToCBOR and FromCBOR work in memory, without file I/O. *) | ||
| (* ToCBOR returns a sequence of integers in 0..255, one per encoded byte. *) | ||
| (* Use its length to check message sizes, or FromCBOR to interpret bytes. *) | ||
| (* *) | ||
| (* In a module that uses CBOR: *) | ||
| (* EXTENDS Naturals, Sequences, CBOR *) | ||
| (* Message == [id |-> 1, payload |-> <<TRUE, FALSE>>] *) | ||
| (* Fits == Len(ToCBOR(Message)) <= 1024 *) | ||
| (* Decoded == FromCBOR(<<130, 1, 245>>) \* equals <<1, TRUE>> *) | ||
| (* *) | ||
| (* For files, using the same imports and Message definition: *) | ||
| (* WriteMessage == CBORSerialize("/tmp/message.cbor", Message) *) | ||
| (* ReadMessage == CBORDeserialize("/tmp/message.cbor") *) | ||
| (* *) | ||
| (* Requires CommunityModules.jar or CommunityModules-deps.jar on TLC's *) | ||
| (* classpath. See README.md for setup. *) | ||
| (* Values must be finite and encodable: integers within TLC's range and *) | ||
| (* strings of valid Unicode. Set elements and function arguments must be *) | ||
| (* comparable by TLC for FromCBOR(ToCBOR(v)) = v to hold. Deep nesting *) | ||
| (* can exhaust the JVM stack, which a larger -Xss setting can relieve. *) | ||
| (***************************************************************************) | ||
|
|
||
| LOCAL INSTANCE TLC | ||
|
|
||
| (***************************************************************************) | ||
| (* The CBOR encoding of value as a sequence of integers in 0..255, one *) | ||
| (* per byte. Sets use tag 258, model values tag 39, and functions that *) | ||
| (* are neither sequences nor records tag 33000 (registered with IANA). *) | ||
|
younes-io marked this conversation as resolved.
|
||
| (* Equal values give identical bytes. TLC reports an error if value *) | ||
| (* cannot be encoded. *) | ||
| (***************************************************************************) | ||
| ToCBOR(value) == | ||
|
lemmy marked this conversation as resolved.
|
||
| Assert(FALSE, "ToCBOR needs CommunityModules.jar on TLC's classpath.") | ||
|
|
||
| (***************************************************************************) | ||
| (* The TLA+ value of the CBOR data item in bytes, a sequence of integers *) | ||
| (* in 0..255. TLC reports an error for malformed input and for anything *) | ||
| (* it cannot represent, such as floats or a model value it does not know. *) | ||
| (***************************************************************************) | ||
| FromCBOR(bytes) == | ||
| Assert(FALSE, "FromCBOR needs CommunityModules.jar on TLC's classpath.") | ||
|
|
||
| (***************************************************************************) | ||
| (* Writes the bytes of ToCBOR(value) to the file absoluteFilename and *) | ||
| (* equals TRUE. Creates missing parent directories and replaces an *) | ||
| (* existing file. If value cannot be encoded, TLC reports an error and *) | ||
| (* leaves the file untouched. *) | ||
| (***************************************************************************) | ||
| CBORSerialize(absoluteFilename, value) == | ||
| Assert(FALSE, "CBORSerialize needs CommunityModules.jar on TLC's classpath.") | ||
|
|
||
| (***************************************************************************) | ||
| (* FromCBOR applied to the bytes of the file absoluteFilename. A *) | ||
| (* definition without parameters is constant-level, so TLC reuses its *) | ||
| (* value instead of reading the file again in each state. *) | ||
| (***************************************************************************) | ||
| CBORDeserialize(absoluteFilename) == | ||
| Assert(FALSE, "CBORDeserialize needs CommunityModules.jar on TLC's classpath.") | ||
|
|
||
| ============================================================================= | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.