Skip to content

Commit 20f0a63

Browse files
committed
Merge branch 'hopsoft/from_payload'
2 parents 3df32ec + 006f21d commit 20f0a63

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

README.md

+37-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
Universal ID leverages both [MessagePack](https://msgpack.org/) and [Brotli](https://github.com/google/brotli) _(a combo built for speed and best-in-class data compression)_.
3939
When combined, these libraries are up to 30% faster and within 2-5% compression rates compared to Protobuf. <a title="Source" href="https://g.co/bard/share/e5bdb17aee91">↗</a>
4040

41-
Universal ID opens the flood gates with a deluge of powerful yet easily implemented [**solutions**](docs/use_cases.md) across a variety of problem domains.
41+
Universal ID introduces a paradigm shift and enables straightforward simple [**solutions**](docs/use_cases.md) for a variety of complex problem domains.
4242

4343
> [!TIP]
4444
> All the code examples below can be tested on your local machine. Just clone the repo _(↑or use Gitpod above↑)_ and run `bin/console` to begin exploring.
@@ -64,6 +64,42 @@ Universal ID opens the flood gates with a deluge of powerful yet easily implemen
6464

6565
<!-- Tocer[finish]: Auto-generated, don't remove. -->
6666

67+
## URI::UID
68+
69+
Universal ID introduces a new URI defintion that can represent any Ruby object, yet its API is simple.
70+
UID strings are URL-safe and can be reliably transported over the wire using HTTP.
71+
The payload is optimized to be as small as possible... _especially notable with large objects._
72+
73+
```ruby
74+
data = { name: "Universal ID Demo", data: { message: "This is cool." } }
75+
76+
uid = URI::UID.build(data)
77+
#<URI::UID payload=ixuAgtYAbmFtZbFVbml2ZXJzYWwgSUQgRGVtb..., fingerprint=CwSAkccFf6RIYXNoAw>
78+
79+
uid.payload
80+
"ixuAgtYAbmFtZbFVbml2ZXJzYWwgSUQgRGVtb9YAZGF0YYHHBwBtZXNzYWdlrVRoaXMgaXMgY29vbC4D"
81+
82+
uid.fingerprint
83+
"CwSAkccFf6RIYXNoAw"
84+
85+
uri = uid.to_s
86+
"uid://universalid/ixuAgtYAbmFtZbFVbml2ZXJzYWwgSUQgRGVtb9YAZGF0YYHHBwBtZXNzYWdlrVRoaXMgaXMgY29vbC4D#CwSAkccFf6RIYXNoAw"
87+
88+
parsed = URI::UID.parse(uri)
89+
#<URI::UID payload=ixuAgtYAbmFtZbFVbml2ZXJzYWwgSUQgRGVtb..., fingerprint=CwSAkccFf6RIYXNoAw>
90+
91+
parsed.decode
92+
{:name=>"Universal ID Demo", :data=>{:message=>"This is cool."}}
93+
94+
# it's also possible to parse the payload by itself
95+
96+
parsed = URI::UID.from_payload(uid.payload)
97+
#<URI::UID payload=ixuAgtYAbmFtZbFVbml2ZXJzYWwgSUQgRGVtb..., fingerprint=CwSAkccFf6RIYXNoAw>
98+
99+
parsed.decode
100+
{:name=>"Universal ID Demo", :data=>{:message=>"This is cool."}}
101+
```
102+
67103
## Supported Data Types
68104

69105
### Primitive Types

lib/universalid/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module UniversalID
4-
VERSION = "0.1.5"
4+
VERSION = "0.1.6"
55
end

0 commit comments

Comments
 (0)