Commit 22e6503
Well known mime types and Composite metadata extension (rsocket#635)
* Add encodeUnsignedMedium to NumberUtils
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Add WellKnownMimeType enum with String/ID conversions
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Add a flyweight capable of encoding Composite Metadata
The flyweight also exposes a method to decode Composite Metadata to a
Map.
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Move flyweight into metadata package, change decodeToMap to decodeNext
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Add CompositeMetadata interface with factory methods to decode/encode
The API is intended as a readonly way of listing the composite metadata
mime-buffer pairs, as well as accessing metadata pairs by mime type or
index, including the case where a mime type is associated with several
metadata entries (`List<Entry> getAll(String)`)...
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Add first test for CompositeMetadata (decode smoke test)
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Expose incremental decode method that decodes a single metadata entry
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* WellKnownMimeType parsing now avoids exceptions (except null arguments)
Instead has 2 special enums. int parsing allows detection of potentially
legit type that is still unknown to the current implementation, which
could help making it more future-proof.
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* rework encoding / decoding API around Entry, accommodate 3 mime case
Encoding becomes a mirror of decoding, purely based on Entry.
Accommodate 3 flavors of mime type decoding:
- compressed well known with id matching an enum
- uncompressed custom string
- compressed but known as reserved for future use (future proofness)
The later can be decoded into a special Entry that will allow re
encoding it and transmitting it to other nodes as it was.
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* No need for a CompositeMetadata interface, single concrete implem
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Expose the CompositeMetadataFlyweight for low-level, simplify API
- the flyweight deals with low-level encoding/decoding with
minimal garbage and only uses exceptions in the encoding path
-- encoding a non-ASCII custom mime type OR
-- encoding an out of range byte
- the CompositeMetadata is an _option_ for a higher level
Iterable-based API, but which instantiates new types
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Remove CompositeMetadata, make Entry child of flyweight
Entry is now the only high-level abstraction, will need a way to
decode into a List<Entry>.
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Add javadoc for CompositeMetadataFlyweight methods
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Switch to a single Entry implementation, remove isPassthrough
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Rename Entry#decodeEntry to #decode, add #decodeAll
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* apply Google-style formatting
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Use precomputed array for WellKnownMimeType.fromId
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Use precomputed Map<String,WellKnownMimeType> for fromMimeType + jmh benchmark to validate perf increase
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Several custom mime metadata header encoding improvements:
- avoid the use of a CompositeByteBuf
- length can be safely predicted due to requirement that custom mime
type be ASCII only
- still using UTF8 writing and ByteBufUtil.isText(ASCII) to detect
non-ascii text as:
- writeAscii would not reject non-ascii chars but replace with `?`
- ISO-8859 chars (eg. Latin-1) could be considered valid when only
checking the number of written bytes
- use of ByteBufUtil.writeUtf8 to simplify encoding the mime into the
preallocated buffer
- release the buffer if there is an encoding exception
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Use Unpooled buffers in tests
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Remove Entry, replace with CompositeMetadata Iterator-like abstraction
The CompositeMetadata wraps a ByteBuf and exposes a hasNext/decodeNext
API (reminiscent of the Iterator API) as a facade over the flyweight's
methods.
Each round decodeNext() is correctly invoked, the CompositeMetadata
state is updated and the getters can be used to retrieve decoded entry
components.
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Add an encode flyweight method that attempts compressing String
This is a qol method that will first check if the String passed can be
mapped to a WellKnownMimeType (and thus compressed to a 1 byte
representation).
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* Avoid moving full buffer's readerIndex when slicing entries
This implies that the index from which to decode and slice the next
entry MUST be provided by the user. To that end, we provide a method
to compute the next entry's index, given the pair of ByteBuf slices
returned by decodeMimeAndContentBuffers.
Also renamed that method to decodeMimeAndContentBufferSlices, to make
it more obvious that it produces slices (readerIndex impact and slices
nature are mentioned in the javadoc).
CompositeMetadata now keeps the nextEntryIndex as state and uses that
for hasNext / decodeNext.
Signed-off-by: Simon Baslé <sbasle@pivotal.io>
* CompositeMetadata as Iterable
Previously, the implementation of CompositeMetadata resulted in a
mutable type that didn't fit in with either imperative (for) or reactive
(fromIterable) iteration strategies. This change updates the type to
implement Iterable, and return an Iterator that lazily traverses the
ByteBuf.
There are also some improvements to the Flyweight in order to support
this iteration style.
Signed-off-by: Ben Hale <bhale@pivotal.io>
* Apply googleFormat
Signed-off-by: Simon Baslé <sbasle@pivotal.io>1 parent 8b8dba1 commit 22e6503
9 files changed
Lines changed: 1663 additions & 0 deletions
File tree
- rsocket-core/src
- jmh/java/io/rsocket/metadata
- main/java/io/rsocket
- metadata
- util
- test/java/io/rsocket
- metadata
- util
Lines changed: 96 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
Lines changed: 220 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
0 commit comments