├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── rust ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── build.rs ├── examples │ ├── input.rs │ └── output.rs └── src │ ├── decode.rs │ ├── encode.rs │ ├── lib.rs │ └── tuple_encode.in.rs └── shell.nix /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [hauleth] 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.ernie 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Attribution-ShareAlike 4.0 International 2 | 3 | ======================================================================= 4 | 5 | Creative Commons Corporation ("Creative Commons") is not a law firm and 6 | does not provide legal services or legal advice. Distribution of 7 | Creative Commons public licenses does not create a lawyer-client or 8 | other relationship. Creative Commons makes its licenses and related 9 | information available on an "as-is" basis. Creative Commons gives no 10 | warranties regarding its licenses, any material licensed under their 11 | terms and conditions, or any related information. Creative Commons 12 | disclaims all liability for damages resulting from their use to the 13 | fullest extent possible. 14 | 15 | Using Creative Commons Public Licenses 16 | 17 | Creative Commons public licenses provide a standard set of terms and 18 | conditions that creators and other rights holders may use to share 19 | original works of authorship and other material subject to copyright 20 | and certain other rights specified in the public license below. The 21 | following considerations are for informational purposes only, are not 22 | exhaustive, and do not form part of our licenses. 23 | 24 | Considerations for licensors: Our public licenses are 25 | intended for use by those authorized to give the public 26 | permission to use material in ways otherwise restricted by 27 | copyright and certain other rights. Our licenses are 28 | irrevocable. Licensors should read and understand the terms 29 | and conditions of the license they choose before applying it. 30 | Licensors should also secure all rights necessary before 31 | applying our licenses so that the public can reuse the 32 | material as expected. Licensors should clearly mark any 33 | material not subject to the license. This includes other CC- 34 | licensed material, or material used under an exception or 35 | limitation to copyright. More considerations for licensors: 36 | 37 | wiki.creativecommons.org/Considerations_for_licensors 38 | 39 | Considerations for the public: By using one of our public 40 | licenses, a licensor grants the public permission to use the 41 | licensed material under specified terms and conditions. If 42 | the licensor's permission is not necessary for any reason--for 43 | example, because of any applicable exception or limitation to 44 | copyright--then that use is not regulated by the license. Our 45 | licenses grant only permissions under copyright and certain 46 | other rights that a licensor has authority to grant. Use of 47 | the licensed material may still be restricted for other 48 | reasons, including because others have copyright or other 49 | rights in the material. A licensor may make special requests, 50 | such as asking that all changes be marked or described. 51 | Although not required by our licenses, you are encouraged to 52 | respect those requests where reasonable. More_considerations 53 | for the public: 54 | 55 | wiki.creativecommons.org/Considerations_for_licensees 56 | 57 | ======================================================================= 58 | 59 | Creative Commons Attribution-ShareAlike 4.0 International Public 60 | License 61 | 62 | By exercising the Licensed Rights (defined below), You accept and agree 63 | to be bound by the terms and conditions of this Creative Commons 64 | Attribution-ShareAlike 4.0 International Public License ("Public 65 | License"). To the extent this Public License may be interpreted as a 66 | contract, You are granted the Licensed Rights in consideration of Your 67 | acceptance of these terms and conditions, and the Licensor grants You 68 | such rights in consideration of benefits the Licensor receives from 69 | making the Licensed Material available under these terms and 70 | conditions. 71 | 72 | 73 | Section 1 -- Definitions. 74 | 75 | a. Adapted Material means material subject to Copyright and Similar 76 | Rights that is derived from or based upon the Licensed Material 77 | and in which the Licensed Material is translated, altered, 78 | arranged, transformed, or otherwise modified in a manner requiring 79 | permission under the Copyright and Similar Rights held by the 80 | Licensor. For purposes of this Public License, where the Licensed 81 | Material is a musical work, performance, or sound recording, 82 | Adapted Material is always produced where the Licensed Material is 83 | synched in timed relation with a moving image. 84 | 85 | b. Adapter's License means the license You apply to Your Copyright 86 | and Similar Rights in Your contributions to Adapted Material in 87 | accordance with the terms and conditions of this Public License. 88 | 89 | c. BY-SA Compatible License means a license listed at 90 | creativecommons.org/compatiblelicenses, approved by Creative 91 | Commons as essentially the equivalent of this Public License. 92 | 93 | d. Copyright and Similar Rights means copyright and/or similar rights 94 | closely related to copyright including, without limitation, 95 | performance, broadcast, sound recording, and Sui Generis Database 96 | Rights, without regard to how the rights are labeled or 97 | categorized. For purposes of this Public License, the rights 98 | specified in Section 2(b)(1)-(2) are not Copyright and Similar 99 | Rights. 100 | 101 | e. Effective Technological Measures means those measures that, in the 102 | absence of proper authority, may not be circumvented under laws 103 | fulfilling obligations under Article 11 of the WIPO Copyright 104 | Treaty adopted on December 20, 1996, and/or similar international 105 | agreements. 106 | 107 | f. Exceptions and Limitations means fair use, fair dealing, and/or 108 | any other exception or limitation to Copyright and Similar Rights 109 | that applies to Your use of the Licensed Material. 110 | 111 | g. License Elements means the license attributes listed in the name 112 | of a Creative Commons Public License. The License Elements of this 113 | Public License are Attribution and ShareAlike. 114 | 115 | h. Licensed Material means the artistic or literary work, database, 116 | or other material to which the Licensor applied this Public 117 | License. 118 | 119 | i. Licensed Rights means the rights granted to You subject to the 120 | terms and conditions of this Public License, which are limited to 121 | all Copyright and Similar Rights that apply to Your use of the 122 | Licensed Material and that the Licensor has authority to license. 123 | 124 | j. Licensor means the individual(s) or entity(ies) granting rights 125 | under this Public License. 126 | 127 | k. Share means to provide material to the public by any means or 128 | process that requires permission under the Licensed Rights, such 129 | as reproduction, public display, public performance, distribution, 130 | dissemination, communication, or importation, and to make material 131 | available to the public including in ways that members of the 132 | public may access the material from a place and at a time 133 | individually chosen by them. 134 | 135 | l. Sui Generis Database Rights means rights other than copyright 136 | resulting from Directive 96/9/EC of the European Parliament and of 137 | the Council of 11 March 1996 on the legal protection of databases, 138 | as amended and/or succeeded, as well as other essentially 139 | equivalent rights anywhere in the world. 140 | 141 | m. You means the individual or entity exercising the Licensed Rights 142 | under this Public License. Your has a corresponding meaning. 143 | 144 | 145 | Section 2 -- Scope. 146 | 147 | a. License grant. 148 | 149 | 1. Subject to the terms and conditions of this Public License, 150 | the Licensor hereby grants You a worldwide, royalty-free, 151 | non-sublicensable, non-exclusive, irrevocable license to 152 | exercise the Licensed Rights in the Licensed Material to: 153 | 154 | a. reproduce and Share the Licensed Material, in whole or 155 | in part; and 156 | 157 | b. produce, reproduce, and Share Adapted Material. 158 | 159 | 2. Exceptions and Limitations. For the avoidance of doubt, where 160 | Exceptions and Limitations apply to Your use, this Public 161 | License does not apply, and You do not need to comply with 162 | its terms and conditions. 163 | 164 | 3. Term. The term of this Public License is specified in Section 165 | 6(a). 166 | 167 | 4. Media and formats; technical modifications allowed. The 168 | Licensor authorizes You to exercise the Licensed Rights in 169 | all media and formats whether now known or hereafter created, 170 | and to make technical modifications necessary to do so. The 171 | Licensor waives and/or agrees not to assert any right or 172 | authority to forbid You from making technical modifications 173 | necessary to exercise the Licensed Rights, including 174 | technical modifications necessary to circumvent Effective 175 | Technological Measures. For purposes of this Public License, 176 | simply making modifications authorized by this Section 2(a) 177 | (4) never produces Adapted Material. 178 | 179 | 5. Downstream recipients. 180 | 181 | a. Offer from the Licensor -- Licensed Material. Every 182 | recipient of the Licensed Material automatically 183 | receives an offer from the Licensor to exercise the 184 | Licensed Rights under the terms and conditions of this 185 | Public License. 186 | 187 | b. Additional offer from the Licensor -- Adapted Material. 188 | Every recipient of Adapted Material from You 189 | automatically receives an offer from the Licensor to 190 | exercise the Licensed Rights in the Adapted Material 191 | under the conditions of the Adapter's License You apply. 192 | 193 | c. No downstream restrictions. You may not offer or impose 194 | any additional or different terms or conditions on, or 195 | apply any Effective Technological Measures to, the 196 | Licensed Material if doing so restricts exercise of the 197 | Licensed Rights by any recipient of the Licensed 198 | Material. 199 | 200 | 6. No endorsement. Nothing in this Public License constitutes or 201 | may be construed as permission to assert or imply that You 202 | are, or that Your use of the Licensed Material is, connected 203 | with, or sponsored, endorsed, or granted official status by, 204 | the Licensor or others designated to receive attribution as 205 | provided in Section 3(a)(1)(A)(i). 206 | 207 | b. Other rights. 208 | 209 | 1. Moral rights, such as the right of integrity, are not 210 | licensed under this Public License, nor are publicity, 211 | privacy, and/or other similar personality rights; however, to 212 | the extent possible, the Licensor waives and/or agrees not to 213 | assert any such rights held by the Licensor to the limited 214 | extent necessary to allow You to exercise the Licensed 215 | Rights, but not otherwise. 216 | 217 | 2. Patent and trademark rights are not licensed under this 218 | Public License. 219 | 220 | 3. To the extent possible, the Licensor waives any right to 221 | collect royalties from You for the exercise of the Licensed 222 | Rights, whether directly or through a collecting society 223 | under any voluntary or waivable statutory or compulsory 224 | licensing scheme. In all other cases the Licensor expressly 225 | reserves any right to collect such royalties. 226 | 227 | 228 | Section 3 -- License Conditions. 229 | 230 | Your exercise of the Licensed Rights is expressly made subject to the 231 | following conditions. 232 | 233 | a. Attribution. 234 | 235 | 1. If You Share the Licensed Material (including in modified 236 | form), You must: 237 | 238 | a. retain the following if it is supplied by the Licensor 239 | with the Licensed Material: 240 | 241 | i. identification of the creator(s) of the Licensed 242 | Material and any others designated to receive 243 | attribution, in any reasonable manner requested by 244 | the Licensor (including by pseudonym if 245 | designated); 246 | 247 | ii. a copyright notice; 248 | 249 | iii. a notice that refers to this Public License; 250 | 251 | iv. a notice that refers to the disclaimer of 252 | warranties; 253 | 254 | v. a URI or hyperlink to the Licensed Material to the 255 | extent reasonably practicable; 256 | 257 | b. indicate if You modified the Licensed Material and 258 | retain an indication of any previous modifications; and 259 | 260 | c. indicate the Licensed Material is licensed under this 261 | Public License, and include the text of, or the URI or 262 | hyperlink to, this Public License. 263 | 264 | 2. You may satisfy the conditions in Section 3(a)(1) in any 265 | reasonable manner based on the medium, means, and context in 266 | which You Share the Licensed Material. For example, it may be 267 | reasonable to satisfy the conditions by providing a URI or 268 | hyperlink to a resource that includes the required 269 | information. 270 | 271 | 3. If requested by the Licensor, You must remove any of the 272 | information required by Section 3(a)(1)(A) to the extent 273 | reasonably practicable. 274 | 275 | b. ShareAlike. 276 | 277 | In addition to the conditions in Section 3(a), if You Share 278 | Adapted Material You produce, the following conditions also apply. 279 | 280 | 1. The Adapter's License You apply must be a Creative Commons 281 | license with the same License Elements, this version or 282 | later, or a BY-SA Compatible License. 283 | 284 | 2. You must include the text of, or the URI or hyperlink to, the 285 | Adapter's License You apply. You may satisfy this condition 286 | in any reasonable manner based on the medium, means, and 287 | context in which You Share Adapted Material. 288 | 289 | 3. You may not offer or impose any additional or different terms 290 | or conditions on, or apply any Effective Technological 291 | Measures to, Adapted Material that restrict exercise of the 292 | rights granted under the Adapter's License You apply. 293 | 294 | 295 | Section 4 -- Sui Generis Database Rights. 296 | 297 | Where the Licensed Rights include Sui Generis Database Rights that 298 | apply to Your use of the Licensed Material: 299 | 300 | a. for the avoidance of doubt, Section 2(a)(1) grants You the right 301 | to extract, reuse, reproduce, and Share all or a substantial 302 | portion of the contents of the database; 303 | 304 | b. if You include all or a substantial portion of the database 305 | contents in a database in which You have Sui Generis Database 306 | Rights, then the database in which You have Sui Generis Database 307 | Rights (but not its individual contents) is Adapted Material, 308 | 309 | including for purposes of Section 3(b); and 310 | c. You must comply with the conditions in Section 3(a) if You Share 311 | all or a substantial portion of the contents of the database. 312 | 313 | For the avoidance of doubt, this Section 4 supplements and does not 314 | replace Your obligations under this Public License where the Licensed 315 | Rights include other Copyright and Similar Rights. 316 | 317 | 318 | Section 5 -- Disclaimer of Warranties and Limitation of Liability. 319 | 320 | a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE 321 | EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS 322 | AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF 323 | ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS, 324 | IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION, 325 | WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR 326 | PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS, 327 | ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT 328 | KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT 329 | ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU. 330 | 331 | b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE 332 | TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION, 333 | NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT, 334 | INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES, 335 | COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR 336 | USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN 337 | ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR 338 | DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR 339 | IN PART, THIS LIMITATION MAY NOT APPLY TO YOU. 340 | 341 | c. The disclaimer of warranties and limitation of liability provided 342 | above shall be interpreted in a manner that, to the extent 343 | possible, most closely approximates an absolute disclaimer and 344 | waiver of all liability. 345 | 346 | 347 | Section 6 -- Term and Termination. 348 | 349 | a. This Public License applies for the term of the Copyright and 350 | Similar Rights licensed here. However, if You fail to comply with 351 | this Public License, then Your rights under this Public License 352 | terminate automatically. 353 | 354 | b. Where Your right to use the Licensed Material has terminated under 355 | Section 6(a), it reinstates: 356 | 357 | 1. automatically as of the date the violation is cured, provided 358 | it is cured within 30 days of Your discovery of the 359 | violation; or 360 | 361 | 2. upon express reinstatement by the Licensor. 362 | 363 | For the avoidance of doubt, this Section 6(b) does not affect any 364 | right the Licensor may have to seek remedies for Your violations 365 | of this Public License. 366 | 367 | c. For the avoidance of doubt, the Licensor may also offer the 368 | Licensed Material under separate terms or conditions or stop 369 | distributing the Licensed Material at any time; however, doing so 370 | will not terminate this Public License. 371 | 372 | d. Sections 1, 5, 6, 7, and 8 survive termination of this Public 373 | License. 374 | 375 | 376 | Section 7 -- Other Terms and Conditions. 377 | 378 | a. The Licensor shall not be bound by any additional or different 379 | terms or conditions communicated by You unless expressly agreed. 380 | 381 | b. Any arrangements, understandings, or agreements regarding the 382 | Licensed Material not stated herein are separate from and 383 | independent of the terms and conditions of this Public License. 384 | 385 | 386 | Section 8 -- Interpretation. 387 | 388 | a. For the avoidance of doubt, this Public License does not, and 389 | shall not be interpreted to, reduce, limit, restrict, or impose 390 | conditions on any use of the Licensed Material that could lawfully 391 | be made without permission under this Public License. 392 | 393 | b. To the extent possible, if any provision of this Public License is 394 | deemed unenforceable, it shall be automatically reformed to the 395 | minimum extent necessary to make it enforceable. If the provision 396 | cannot be reformed, it shall be severed from this Public License 397 | without affecting the enforceability of the remaining terms and 398 | conditions. 399 | 400 | c. No term or condition of this Public License will be waived and no 401 | failure to comply consented to unless expressly agreed to by the 402 | Licensor. 403 | 404 | d. Nothing in this Public License constitutes or may be interpreted 405 | as a limitation upon, or waiver of, any privileges and immunities 406 | that apply to the Licensor or You, including from the legal 407 | processes of any jurisdiction or authority. 408 | 409 | 410 | ======================================================================= 411 | 412 | Creative Commons is not a party to its public 413 | licenses. Notwithstanding, Creative Commons may elect to apply one of 414 | its public licenses to material it publishes and in those instances 415 | will be considered the “Licensor.” The text of the Creative Commons 416 | public licenses is dedicated to the public domain under the CC0 Public 417 | Domain Dedication. Except for the limited purpose of indicating that 418 | material is shared under a Creative Commons public license or as 419 | otherwise permitted by the Creative Commons policies published at 420 | creativecommons.org/policies, Creative Commons does not authorize the 421 | use of the trademark "Creative Commons" or any other trademark or logo 422 | of Creative Commons without its prior written consent including, 423 | without limitation, in connection with any unauthorized modifications 424 | to any of its public licenses or any other arrangements, 425 | understandings, or agreements concerning use of licensed material. For 426 | the avoidance of doubt, this paragraph does not form part of the 427 | public licenses. 428 | 429 | Creative Commons may be contacted at creativecommons.org. 430 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Ernie 2 | ====================== 3 | 4 | Simple binary data exchange format that is based on [External Term Format][ETF] 5 | in Erlang. This is update on [BERT][] which is a little bit outdated right now. 6 | 7 | ### Name 8 | 9 | Ernie is fun over the original BERT name, from the Sesame Street Bert & Ernie 10 | couple. 11 | 12 | ### RPC 13 | 14 | No, this document will not define RPC syntax because of 2 reasons: 15 | 16 | 1. This is out of scope of this document. It is meant to define only data 17 | encoding format, not services one will use it for. 18 | 2. Authors of this document believes that RPC are bad, and you should not use 19 | them. Instead use message passing between your services. 20 | 21 | ### Schema/structured data 22 | 23 | This is meant to encode free-form data, if you want to encode structured data 24 | with schema then we highly suggest you to take look into other formats like: 25 | 26 | - ASN.1 and any of it's encodings 27 | - ProtoBuffers 28 | - Apache Thrift 29 | - FlatBuffers 30 | - Cap'n'Proto 31 | 32 | Specification 33 | ------------- 34 | 35 | ### Introduction 36 | 37 | 1. The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 38 | "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 39 | document are to be interpreted as described in [BCP 14][bcp14]. 40 | 41 | ### Types 42 | 43 | 1. Integer 44 | 45 | Binary representation of integers. 46 | 47 | Implementation MUST support at least 8-bit unsigned and 32-bit signed 48 | integers with full precision. 49 | 50 | 2. 64-bit Float 51 | 52 | IEEE 754 double precision floats. 53 | 54 | Implementation MUST support all non-NaN, non-infinite, non-subnormal values 55 | described in IEEE 754 binary64 spec. Implementations SHOULD NOT encode these 56 | values. 57 | 58 | 3. Tuple 59 | 60 | Fixed length sequence of values. 61 | 62 | 4. List 63 | 64 | Dynamic length sequence of values. 65 | 66 | 5. Binary 67 | 68 | Representation of bytes with arbitrary length. If used to store 69 | human-readable strings it MUST be encoded as correct UTF-8 string. 70 | 71 | 6. Map 72 | 73 | List of key-value pairs in arbitrary order. Keys MUST NOT appear twice in 74 | the same map. 75 | 76 | ### Encoding 77 | 78 | 1. Top level 79 | 80 | Binary encoded data MUST start with magic byte of decimal value of `131` 81 | followed by single byte `Tag` value followed by arbitrary length data: 82 | 83 | 0 1 2 84 | +--------+-------+-------+------- 85 | | 131 | Tag | Data ... 86 | +--------+-------+-------+------- 87 | 88 | 2. Integer 89 | 90 | Integer can be encoded in 3 different forms: 91 | 92 | - Values in range 0..255 (aka byte) 93 | 94 | 0 1 2 95 | +-------+--------+ 96 | | 97 | Data | 97 | +-------+--------+ 98 | 99 | Where `Data` is unsigned byte representation of value. 100 | 101 | - Values in range -4 294 967 295..4 294 967 294 (signed 32-bit value) 102 | 103 | 0 1 2 3 4 5 104 | +-------+-------+------+------+------+ 105 | | 98 | Data | 106 | +-------+-------+------+------+------+ 107 | 108 | Where `Data` is signed 32-bit representation of integer in U2 big-endian 109 | encoding. 110 | 111 | - "Short" arbitrary long signed integers (up to 2040-bit) 112 | 113 | 0 1 2 3 ... N+3 114 | +-------+-------+-------+------+------+ 115 | | 110 | N | Sign | Data | 116 | +-------+-------+-------+------+------+ 117 | 118 | `N` is big-endian 16-bit unsigned integer. `Data` represents little-endian 119 | encoded `N` byte long integer. `Sign` is `0` for positive integer 120 | and `1` for negative one. 121 | 122 | - "Long" arbitrary long signed integers (from 2041 to 524 288-bit long) 123 | 124 | 0 1 2 3 4 ... N+4 125 | +-------+-------+-------+-------+------+------+ 126 | | 111 | N | Sign | Data | 127 | +-------+-------+-------+-------+------+------+ 128 | 129 | `N` is big-endian 16-bit unsigned integer. `Data` represents little-endian 130 | encoded `N` byte long integer. `Sign` is `0` for positive integer 131 | and `1` for negative one. 132 | 133 | 3. Float 134 | 135 | 0 1 2 3 4 5 6 7 8 9 136 | +-------+-------+--------+-------+-------+-------+-------+-------+-------+ 137 | | 70 | Data | 138 | +-------+-------+--------+-------+-------+-------+-------+-------+-------+ 139 | 140 | Where `Data` is IEEE 754 double precision floating-point number encoded as 141 | big-endian. 142 | 143 | 4. Tuple 144 | 145 | - Tuples up to 255 elements 146 | 147 | 0 1 2 ... N+2 148 | +-------+-------+--------+--------+ 149 | | 104 | Arity | Data ... | 150 | +-------+-------+--------+--------+ 151 | 152 | - Tuples up to 4 294 967 295 elements 153 | 154 | 0 1 2 3 4 5 ... N+5 155 | +-------+-------+--------+--------+--------+--------+--------+ 156 | | 105 | Arity | Data ... | 157 | +-------+-------+--------+--------+--------+--------+--------+ 158 | 159 | Where `Arity` is big-endian unsigned integer declaring amount of elements in 160 | `Data`. 161 | 162 | 5. List 163 | 164 | - Byte list 165 | 166 | 0 1 2 3 ... N+3 167 | +-------+-------+-------+-------+-------+ 168 | | 107 | N | Data ... | 169 | +-------+-------+-------+-------+-------+ 170 | 171 | This is optimisation for lists that contains only values in range 172 | 0..255, inclusive. 173 | 174 | - General list 175 | 176 | 0 1 2 3 4 5 ... N+5 N+6 177 | +-------+-------+-------+-------+-------+-------+-------+-------+ 178 | | 108 | Arity | Data ... | 106 | 179 | +-------+-------+-------+-------+-------+-------+-------+-------+ 180 | 181 | Where `Arity` is big-endian unsigned 32-bit integer declaring amount 182 | of elements in `Data`. 183 | 184 | - Empty list 185 | 186 | 0 1 187 | +-------+ 188 | | 106 | 189 | +-------+ 190 | 191 | 6. Binary 192 | 193 | 0 1 2 3 4 5 ... N+5 194 | +-------+-------+-------+-------+-------+-------+-------+ 195 | | 109 | N | Data ... | 196 | +-------+-------+-------+-------+-------+-------+-------+ 197 | 198 | 7. Map 199 | 200 | 0 1 2 3 4 5 ... N+5 201 | +-------+-------+-------+-------+-------+-------+-------+ 202 | | 116 | Arity | Data ... | 203 | +-------+-------+-------+-------+-------+-------+-------+ 204 | 205 | The `Arity` field is an unsigned 32-bit integer in big-endian format that 206 | determines the number of key-value pairs in the map. Key and value pairs 207 | (`Ki => Vi`) are encoded in section `Data` in the following order: 208 | `K1, V1, K2, V2,..., Kn, Vn`. 209 | 210 | Open questions 211 | -------------- 212 | 213 | 1. Should we support atoms? 214 | 2. Should we allow defining improper lists? 215 | 216 | License 217 | ------- 218 | 219 | This document is released on [Creative Commons Attribution-ShareAlike 4.0 220 | International License](http://creativecommons.org/licenses/by-sa/4.0/). 221 | 222 | [BERT]: http://bert-rpc.org 223 | [ETF]: http://erlang.org/doc/apps/erts/erl_ext_dist.html 224 | [bcp14]: https://tools.ietf.org/html/bcp14 225 | -------------------------------------------------------------------------------- /rust/.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | -------------------------------------------------------------------------------- /rust/Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | [[package]] 4 | name = "byteorder" 5 | version = "1.0.0" 6 | source = "registry+https://github.com/rust-lang/crates.io-index" 7 | 8 | [[package]] 9 | name = "ernie" 10 | version = "0.1.0" 11 | dependencies = [ 12 | "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 13 | ] 14 | 15 | [metadata] 16 | "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" 17 | -------------------------------------------------------------------------------- /rust/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ernie" 3 | version = "0.1.0" 4 | authors = ["Łukasz Niemier "] 5 | edition = "2018" 6 | build = "build.rs" 7 | 8 | [dependencies] 9 | byteorder = "~1.0" 10 | -------------------------------------------------------------------------------- /rust/build.rs: -------------------------------------------------------------------------------- 1 | use std::fs::File; 2 | use std::io::{self, Write}; 3 | 4 | fn main() -> io::Result<()> { 5 | let mut encode_file = File::create("src/tuple_encode.in.rs").unwrap(); 6 | // let mut decode_file = File::create("src/tuple_decode.in.rs").unwrap(); 7 | 8 | for i in 1..=32 { 9 | write!(&mut encode_file, "impl<")?; 10 | write_types(&mut encode_file, i, ": Encode")?; 11 | write!(&mut encode_file, "> Encode for (")?; 12 | write_types(&mut encode_file, i, "")?; 13 | writeln!(&mut encode_file, ") {{")?; 14 | writeln!(&mut encode_file, " fn encode(&self, out: &mut impl io::Write) -> Result {{")?; 15 | writeln!(&mut encode_file, " out.write_u8(104)?;")?; 16 | writeln!(&mut encode_file, " out.write_u8({})?;", i)?; 17 | 18 | for j in 0..i { 19 | writeln!(&mut encode_file, " self.{}.encode(out)?;", j)?; 20 | } 21 | 22 | writeln!(&mut encode_file, " Ok(())\n }}\n}}")?; 23 | writeln!(&mut encode_file, "")?; 24 | 25 | // write!(&mut decode_file, "impl<")?; 26 | // write_types(&mut decode_file, i, "")?; 27 | // write!(&mut decode_file, "> TryInto<(")?; 28 | // write_types(&mut decode_file, i, "")?; 29 | // write!(&mut decode_file, ")> for Type where ")?; 30 | // write_types(&mut decode_file, i, ": TryFrom")?; 31 | // writeln!(&mut decode_file, " {{")?; 32 | // writeln!(&mut decode_file, " type Error = TryFromErnieError;")?; 33 | // writeln!(&mut decode_file, "")?; 34 | // write!(&mut decode_file, " fn try_into(self) -> Result<(")?; 35 | // write_types(&mut decode_file, i, "")?; 36 | // writeln!(&mut decode_file, "), Self::Error> {{")?; 37 | // writeln!(&mut decode_file, " match self {{")?; 38 | // writeln!(&mut decode_file, " Type::Tuple(data) => {{")?; 39 | // writeln!(&mut decode_file, " if data.len() != {} {{", i)?; 40 | // writeln!(&mut decode_file, " return Err(TryFromErnieError::InvalidTupleArity(data.len()))")?; 41 | // writeln!(&mut decode_file, " }}")?; 42 | // writeln!(&mut decode_file, " let mut iter = data.into_iter();")?; 43 | // write!(&mut decode_file, " Ok((")?; 44 | // write_types(&mut decode_file, i, "::try_from(iter.next().unwrap())?")?; 45 | // writeln!(&mut decode_file, "))")?; 46 | // writeln!(&mut decode_file, " }}")?; 47 | // writeln!(&mut decode_file, " _ => Err(TryFromErnieError::InvalidType(self))")?; 48 | // writeln!(&mut decode_file, " }}")?; 49 | // writeln!(&mut decode_file, " }}")?; 50 | // writeln!(&mut decode_file, "}}")?; 51 | // writeln!(&mut decode_file, "")?; 52 | } 53 | 54 | Ok(()) 55 | } 56 | 57 | fn write_types(file: &mut impl Write, count: u32, suffix: &str) -> io::Result<()> { 58 | for i in 0..count { 59 | write!(file, "T{}{}, ", i, suffix)?; 60 | } 61 | 62 | Ok(()) 63 | } 64 | -------------------------------------------------------------------------------- /rust/examples/input.rs: -------------------------------------------------------------------------------- 1 | use std::fs; 2 | use std::collections::BTreeMap; 3 | use std::convert::TryInto; 4 | 5 | // type Output = ; 6 | 7 | fn main() -> std::io::Result<()> { 8 | let mut file = fs::File::open("file.ernie")?; 9 | let value = ernie::decode(&mut file).unwrap(); 10 | println!("{:#?}", value); 11 | 12 | // let t: (Vec, String, i32, f64, BTreeMap) = value.try_into().unwrap(); 13 | // let mut t: Vec = value.try_into().unwrap(); 14 | let s: BTreeMap = value.try_into().unwrap(); 15 | 16 | println!("{:#?}", s); 17 | 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /rust/examples/output.rs: -------------------------------------------------------------------------------- 1 | use std::collections::HashMap; 2 | use std::fs; 3 | 4 | fn main() -> std::io::Result<()> { 5 | let mut file = fs::File::create("file.ernie")?; 6 | let mut map = HashMap::new(); 7 | let _ = map.insert(1, "foo"); 8 | let _ = map.insert(2, "bar"); 9 | 10 | // let value = (vec![1,2,3,4,5], "Zażółć gęślą jaźń", 10, 3.14, map); 11 | let value = map; 12 | 13 | println!("{:#?}", value); 14 | ernie::encode(value, &mut file)?; 15 | 16 | Ok(()) 17 | } 18 | -------------------------------------------------------------------------------- /rust/src/decode.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | use std::collections::BTreeMap; 3 | use std::fmt; 4 | use std::str; 5 | 6 | use std::convert::TryInto; 7 | 8 | use core::cmp::Ordering; 9 | 10 | use byteorder::{BigEndian, ReadBytesExt}; 11 | 12 | #[doc(hidden)] 13 | // Wrapper over floats to allow them being key in the map 14 | #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] 15 | pub struct Float(f64); 16 | 17 | impl core::cmp::Ord for Float { 18 | fn cmp(&self, other: &Self) -> Ordering { 19 | if self.0 < other.0 { return Ordering::Less } 20 | if self.0 > other.0 { return Ordering::Greater } 21 | 22 | Ordering::Equal 23 | } 24 | } 25 | 26 | impl core::cmp::Eq for Float {} 27 | 28 | /// Internal representation of decoded data 29 | #[derive(PartialEq, PartialOrd, Ord, Eq)] 30 | pub enum Type { 31 | #[doc(hidden)] 32 | Byte(u8), 33 | #[doc(hidden)] 34 | Integer(i32), 35 | #[doc(hidden)] 36 | BigInt { 37 | sign: bool, 38 | repr: Vec 39 | }, 40 | #[doc(hidden)] 41 | Float(Float), 42 | #[doc(hidden)] 43 | Tuple(Vec), 44 | #[doc(hidden)] 45 | List(Vec), 46 | #[doc(hidden)] 47 | Binary(Vec), 48 | #[doc(hidden)] 49 | Map(BTreeMap) 50 | } 51 | 52 | impl fmt::Debug for Type { 53 | fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> { 54 | match *self { 55 | Type::Byte(b) => write!(fmt, "{}", b), 56 | Type::Integer(n) => write!(fmt, "{}", n), 57 | Type::Float(f) => write!(fmt, "{}", f.0), 58 | Type::Tuple(ref data) => fmt.debug_set().entries(data.into_iter()).finish(), 59 | Type::List(ref data) => fmt.debug_list().entries(data.into_iter()).finish(), 60 | Type::Binary(ref data) => { 61 | match str::from_utf8(data) { 62 | Ok(s) => write!(fmt, "<<{:?}>>", s), 63 | _ => write!(fmt, "<<{:?}>>", data) 64 | } 65 | } 66 | Type::Map(ref map) => fmt.debug_map().entries(map.into_iter()).finish(), 67 | _ => std::unimplemented!("Not yet implemented") 68 | } 69 | } 70 | } 71 | 72 | impl Type { 73 | /// Checks if current value is an integer 74 | pub fn is_integer(&self) -> bool { 75 | match *self { 76 | Type::Byte(_) => true, 77 | Type::Integer(_) => true, 78 | Type::BigInt { .. } => true, 79 | _ => false 80 | } 81 | } 82 | 83 | /// Checks if current value is a float 84 | pub fn is_float(&self) -> bool { 85 | match *self { 86 | Type::Float(_) => true, 87 | _ => false 88 | } 89 | } 90 | 91 | /// Checks if current value is a numeric value (either integer or float) 92 | pub fn is_numeric(&self) -> bool { 93 | self.is_integer() || self.is_float() 94 | } 95 | 96 | /// Checks if current value is a tuple 97 | pub fn is_tuple(&self) -> bool { 98 | match *self { 99 | Type::Tuple(_) => true, 100 | _ => false 101 | } 102 | } 103 | 104 | /// Checks if current value is a list 105 | pub fn is_list(&self) -> bool { 106 | match *self { 107 | Type::List(_) => true, 108 | _ => false 109 | } 110 | } 111 | 112 | /// Checks if current value is a binary 113 | pub fn is_binary(&self) -> bool { 114 | match *self { 115 | Type::Binary(_) => true, 116 | _ => false 117 | } 118 | } 119 | 120 | /// Checks if current value is a map 121 | pub fn is_map(&self) -> bool { 122 | match *self { 123 | Type::Map(_) => true, 124 | _ => false 125 | } 126 | } 127 | 128 | /// Checks if current value is a charlist (aka Erlang string) 129 | pub fn is_charlist(&self) -> bool { 130 | fn valid_codepoint(t: &Type) -> bool { 131 | match *t { 132 | Type::Byte(_) => true, 133 | Type::Integer(n) if n <= 0x10FFFF => true, 134 | _ => false 135 | } 136 | } 137 | 138 | match *self { 139 | Type::List(ref data) => data.into_iter().all(valid_codepoint), 140 | _ => false 141 | } 142 | } 143 | } 144 | 145 | pub fn decode_type(reader: &mut impl io::Read) -> io::Result { 146 | let mut header = [0u8; 1]; 147 | 148 | reader.read_exact(&mut header)?; 149 | 150 | match header[0] { 151 | 97 => reader.read_u8().map(Type::Byte), 152 | 98 => reader.read_i32::().map(Type::Integer), 153 | 70 => reader.read_f64::().and_then(validate_float).map(Type::Float), 154 | 104 => read_small_tuple(reader).map(Type::Tuple), 155 | 105 => read_big_tuple(reader).map(Type::Tuple), 156 | 106 => Ok(Type::List(vec![])), 157 | 107 => read_bytelist(reader).map(Type::List), 158 | 108 => read_list(reader).map(Type::List), 159 | 109 => read_binary(reader).map(Type::Binary), 160 | 110 => std::unimplemented!("Small arbitrary integer deserialization is currently unsupported"), 161 | 111 => std::unimplemented!("Big arbitrary integer deserialization is currently unsupported"), 162 | 116 => read_map(reader).map(Type::Map), 163 | sig => std::unimplemented!("{:x?} is unknown", sig) 164 | } 165 | } 166 | 167 | fn validate_float(float: f64) -> io::Result { 168 | if float.is_nan() { 169 | return Err(io::Error::new(io::ErrorKind::InvalidData, "Found NaN in float field")) 170 | } 171 | if float.is_infinite() { 172 | return Err(io::Error::new(io::ErrorKind::InvalidData, "Found Infinity in float field")) 173 | } 174 | 175 | Ok(Float(float)) 176 | } 177 | 178 | fn read_small_tuple(reader: &mut impl io::Read) -> io::Result> { 179 | let size = reader.read_u8()? as usize; 180 | 181 | read_vector(size, reader) 182 | } 183 | 184 | fn read_big_tuple(reader: &mut impl io::Read) -> io::Result> { 185 | let size = reader.read_u32::()? as usize; 186 | 187 | read_vector(size, reader) 188 | } 189 | 190 | fn read_list(reader: &mut impl io::Read) -> io::Result> { 191 | let size = reader.read_u32::()? as usize; 192 | 193 | let vec = read_vector(size, reader)?; 194 | 195 | if reader.read_u8()? == 106 { 196 | Ok(vec) 197 | } else { 198 | panic!("Improper list"); 199 | } 200 | } 201 | 202 | fn read_binary(reader: &mut impl io::Read) -> io::Result> { 203 | let size = reader.read_u32::()? as usize; 204 | let mut data = vec![0; size]; 205 | 206 | reader.read_exact(&mut data)?; 207 | 208 | Ok(data) 209 | } 210 | 211 | fn read_bytelist(reader: &mut impl io::Read) -> io::Result> { 212 | let size = reader.read_u16::()? as usize; 213 | let mut data = vec![0; size]; 214 | 215 | reader.read_exact(&mut data)?; 216 | 217 | Ok(data.into_iter().map(Type::Byte).collect()) 218 | } 219 | 220 | fn read_vector(size: usize, reader: &mut impl io::Read) -> io::Result> { 221 | let mut data = Vec::with_capacity(size); 222 | 223 | for _ in 0..size { 224 | let elem = decode_type(reader)?; 225 | data.push(elem); 226 | } 227 | 228 | Ok(data) 229 | } 230 | 231 | fn read_map(reader: &mut impl io::Read) -> io::Result> { 232 | let size = reader.read_u32::()? as usize; 233 | let mut map = BTreeMap::new(); 234 | 235 | for _ in 0..size { 236 | let key = decode_type(reader)?; 237 | let value = decode_type(reader)?; 238 | 239 | map.insert(key, value); 240 | } 241 | 242 | Ok(map) 243 | } 244 | 245 | #[derive(Debug)] 246 | pub enum TryFromErnieError { 247 | InvalidType(Type), 248 | InvalidTupleArity(usize), 249 | NotUtf8(std::string::FromUtf8Error) 250 | } 251 | 252 | 253 | impl TryInto for Type { 254 | type Error = TryFromErnieError; 255 | 256 | fn try_into(self) -> Result { 257 | match self { 258 | Type::Byte(b) => Ok(b), 259 | Type::Integer(n) if n >= core::u8::MIN as i32 && n <= core::u8::MAX as i32 => Ok(n as u8), 260 | Type::BigInt { sign, ref repr } if !sign && repr.len() == 1 => Ok(repr[0]), 261 | Type::BigInt { ref repr, .. } if repr.len() == 0 => Ok(0), 262 | _ => Err(TryFromErnieError::InvalidType(self)) 263 | } 264 | } 265 | } 266 | 267 | impl TryInto for Type { 268 | type Error = TryFromErnieError; 269 | 270 | fn try_into(self) -> Result { 271 | match self { 272 | Type::Byte(b) => Ok(b as i32), 273 | Type::Integer(n) => Ok(n), 274 | Type::BigInt { sign, ref repr } if !sign && repr.len() == 1 => Ok(repr[0] as i32), 275 | Type::BigInt { sign, ref repr } if !sign && repr.len() == 2 => Ok(i32::from_be_bytes([repr[0], repr[1], 0, 0])), 276 | Type::BigInt { sign, ref repr } if !sign && repr.len() == 3 => Ok(i32::from_be_bytes([repr[0], repr[1], repr[2], 0])), 277 | Type::BigInt { sign, ref repr } if !sign && repr.len() == 4 && repr[3] < 0x80 => Ok(i32::from_be_bytes([repr[0], repr[1], repr[2], repr[4]])), 278 | Type::BigInt { sign, ref repr } if sign && repr.len() == 1 => Ok(-(repr[0] as i32)), 279 | Type::BigInt { sign, ref repr } if sign && repr.len() == 2 => Ok(-i32::from_be_bytes([repr[0], repr[1], 0, 0])), 280 | Type::BigInt { sign, ref repr } if sign && repr.len() == 3 => Ok(-i32::from_be_bytes([repr[0], repr[1], repr[2], 0])), 281 | Type::BigInt { sign, ref repr } if sign && repr.len() == 4 && repr[3] < 0x80 => Ok(-i32::from_be_bytes([repr[0], repr[1], repr[2], repr[4]])), 282 | Type::BigInt { ref repr, .. } if repr.len() == 0 => Ok(0), 283 | _ => Err(TryFromErnieError::InvalidType(self)) 284 | } 285 | } 286 | } 287 | 288 | impl TryInto for Type { 289 | type Error = TryFromErnieError; 290 | 291 | fn try_into(self) -> Result { 292 | match self { 293 | Type::Float(f) => Ok(f.0), 294 | _ => Err(TryFromErnieError::InvalidType(self)) 295 | } 296 | } 297 | } 298 | 299 | impl TryInto> for Type { 300 | type Error = TryFromErnieError; 301 | 302 | fn try_into(self) -> Result, Self::Error> { 303 | match self { 304 | Type::Tuple(data) => Ok(data), 305 | Type::List(data) => Ok(data), 306 | _ => Err(TryFromErnieError::InvalidType(self)) 307 | } 308 | } 309 | } 310 | 311 | impl TryInto> for Type { 312 | type Error = TryFromErnieError; 313 | 314 | fn try_into(self) -> Result, Self::Error> { 315 | match self { 316 | Type::Binary(data) => Ok(data), 317 | _ => Err(TryFromErnieError::InvalidType(self)) 318 | } 319 | } 320 | } 321 | 322 | impl TryInto for Type { 323 | type Error = TryFromErnieError; 324 | 325 | fn try_into(self) -> Result { 326 | self.try_into() 327 | .and_then(|vec| String::from_utf8(vec).map_err(TryFromErnieError::NotUtf8)) 328 | } 329 | } 330 | 331 | impl TryInto> for Type { 332 | type Error = TryFromErnieError; 333 | 334 | fn try_into(self) -> Result, Self::Error> { 335 | match self { 336 | Type::Map(data) => Ok(data), 337 | _ => Err(TryFromErnieError::InvalidType(self)) 338 | } 339 | } 340 | } 341 | -------------------------------------------------------------------------------- /rust/src/encode.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | use std::collections::{HashMap, BTreeMap}; 3 | 4 | use byteorder::{BigEndian, LittleEndian, WriteBytesExt}; 5 | 6 | pub type Result = io::Result<()>; 7 | 8 | fn write_int(sign: bool, bytes: &[u8], out: &mut impl io::Write) -> io::Result<()> { 9 | let mut size = bytes.len(); 10 | 11 | while size > 1 && bytes[size - 1] == 0 { size -= 1; } 12 | 13 | let sign = if sign { 1 } else { 0 }; 14 | 15 | match size { 16 | 1 => out.write_u8(97)?, 17 | 2..=3 => { 18 | out.write_u8(98)?; 19 | size = 4; 20 | } 21 | 4..=255 => out.write_all(&[110, size as u8, sign])?, 22 | size if size <= std::u16::MAX as usize => { 23 | out.write_u8(111)?; 24 | out.write_u16::(size as u16)?; 25 | out.write_u8(sign)?; 26 | } 27 | _ => std::unimplemented!() 28 | } 29 | 30 | out.write_all(&bytes[..size]) 31 | } 32 | 33 | pub trait Encode { 34 | fn encode(&self, out: &mut impl io::Write) -> Result; 35 | } 36 | 37 | impl Encode for u8 { 38 | fn encode(&self, out: &mut impl io::Write) -> Result { out.write_all(&[97, *self]) } 39 | } 40 | 41 | impl Encode for i8 { 42 | fn encode(&self, out: &mut impl io::Write) -> Result { 43 | if *self > 0 { 44 | (*self as u8).encode(out) 45 | } else { 46 | (*self as i32).encode(out) 47 | } 48 | } 49 | } 50 | 51 | impl Encode for i32 { 52 | fn encode(&self, out: &mut impl io::Write) -> Result { 53 | if *self <= 255 { 54 | (*self as u8).encode(out) 55 | } else { 56 | out.write_u8(98)?; 57 | out.write_i32::(*self) 58 | } 59 | } 60 | } 61 | 62 | impl Encode for u32 { 63 | fn encode(&self, out: &mut impl io::Write) -> Result { 64 | if *self <= std::i32::MAX as u32 { 65 | (*self as i32).encode(out) 66 | } else { 67 | (*self as u64).encode(out) 68 | } 69 | } 70 | } 71 | 72 | impl Encode for u64 { 73 | fn encode(&self, out: &mut impl io::Write) -> Result { 74 | if *self <= std::i32::MAX as u64 { 75 | (*self as i32).encode(out) 76 | } else { 77 | let mut tmp = [0u8; 8]; 78 | let mut w = &mut tmp[..]; 79 | w.write_u64::(*self)?; 80 | write_int(false, &tmp, out) 81 | } 82 | } 83 | } 84 | 85 | impl Encode for i64 { 86 | fn encode(&self, out: &mut impl io::Write) -> Result { 87 | if *self <= std::i32::MAX as i64 && *self >= std::i32::MIN as i64 { 88 | (*self as i32).encode(out) 89 | } else { 90 | let mut tmp = [0u8; 8]; 91 | let mut w = &mut tmp[..]; 92 | w.write_i64::(self.abs())?; 93 | write_int(*self < 0, &tmp, out) 94 | } 95 | } 96 | } 97 | 98 | impl Encode for f32 { 99 | fn encode(&self, out: &mut impl io::Write) -> Result { (*self as f64).encode(out) } 100 | } 101 | 102 | impl Encode for f64 { 103 | fn encode(&self, out: &mut impl io::Write) -> Result { 104 | if self.is_nan() || self.is_infinite() { 105 | return Err(io::Error::new(io::ErrorKind::InvalidData, "Serializing NaN and infinite values is not supported")); 106 | } 107 | 108 | out.write_u8(70)?; 109 | out.write_f64::(*self) 110 | } 111 | } 112 | 113 | impl Encode for &str { 114 | fn encode(&self, out: &mut impl io::Write) -> Result { 115 | out.write_u8(109)?; 116 | out.write_u32::(self.len() as u32)?; 117 | out.write_all(self.as_bytes()) 118 | } 119 | } 120 | 121 | impl Encode for String { 122 | fn encode(&self, out: &mut impl io::Write) -> Result { 123 | out.write_u8(109)?; 124 | out.write_u32::(self.len() as u32)?; 125 | out.write_all(self.as_bytes()) 126 | } 127 | } 128 | 129 | impl Encode for &[u8] { 130 | fn encode(&self, out: &mut impl io::Write) -> Result { 131 | out.write_u8(109)?; 132 | out.write_u32::(self.len() as u32)?; 133 | out.write_all(self) 134 | } 135 | } 136 | 137 | impl Encode for BTreeMap { 138 | fn encode(&self, out: &mut impl io::Write) -> Result { 139 | out.write_u8(116)?; 140 | out.write_u32::(self.len() as u32)?; 141 | 142 | for (k, v) in self { 143 | k.encode(out)?; 144 | v.encode(out)?; 145 | } 146 | 147 | Ok(()) 148 | } 149 | } 150 | 151 | impl Encode for HashMap { 152 | fn encode(&self, out: &mut impl io::Write) -> Result { 153 | out.write_u8(116)?; 154 | out.write_u32::(self.len() as u32)?; 155 | 156 | for (k, v) in self { 157 | k.encode(out)?; 158 | v.encode(out)?; 159 | } 160 | 161 | Ok(()) 162 | } 163 | } 164 | 165 | impl Encode for Vec { 166 | fn encode(&self, out: &mut impl io::Write) -> Result { 167 | if !self.is_empty() { 168 | out.write_u8(108)?; 169 | out.write_u32::(self.len() as u32)?; 170 | 171 | for elem in self { 172 | elem.encode(out)?; 173 | } 174 | } 175 | 176 | out.write_u8(106) 177 | } 178 | } 179 | 180 | include!("tuple_encode.in.rs"); 181 | -------------------------------------------------------------------------------- /rust/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::io; 2 | 3 | mod encode; 4 | mod decode; 5 | 6 | pub use encode::Encode; 7 | pub use decode::Type; 8 | 9 | pub fn encode(data: impl Encode, out: &mut impl io::Write) -> io::Result<()> { 10 | out.write_all(&[131]).and_then(|_| data.encode(out)) 11 | } 12 | 13 | pub fn decode(reader: &mut impl io::Read) -> io::Result { 14 | let mut header = [0u8; 1]; 15 | 16 | reader.read_exact(&mut header)?; 17 | 18 | if header[0] == 131 { 19 | decode::decode_type(reader) 20 | } else { 21 | Err(io::Error::new(io::ErrorKind::InvalidData, "Invalid magic byte")) 22 | } 23 | } 24 | 25 | #[cfg(test)] 26 | mod tests { 27 | #[test] 28 | fn it_works() { 29 | assert_eq!(2 + 2, 4); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /rust/src/tuple_encode.in.rs: -------------------------------------------------------------------------------- 1 | impl Encode for (T0, ) { 2 | fn encode(&self, out: &mut impl io::Write) -> Result { 3 | out.write_u8(104)?; 4 | out.write_u8(1)?; 5 | self.0.encode(out)?; 6 | Ok(()) 7 | } 8 | } 9 | 10 | impl Encode for (T0, T1, ) { 11 | fn encode(&self, out: &mut impl io::Write) -> Result { 12 | out.write_u8(104)?; 13 | out.write_u8(2)?; 14 | self.0.encode(out)?; 15 | self.1.encode(out)?; 16 | Ok(()) 17 | } 18 | } 19 | 20 | impl Encode for (T0, T1, T2, ) { 21 | fn encode(&self, out: &mut impl io::Write) -> Result { 22 | out.write_u8(104)?; 23 | out.write_u8(3)?; 24 | self.0.encode(out)?; 25 | self.1.encode(out)?; 26 | self.2.encode(out)?; 27 | Ok(()) 28 | } 29 | } 30 | 31 | impl Encode for (T0, T1, T2, T3, ) { 32 | fn encode(&self, out: &mut impl io::Write) -> Result { 33 | out.write_u8(104)?; 34 | out.write_u8(4)?; 35 | self.0.encode(out)?; 36 | self.1.encode(out)?; 37 | self.2.encode(out)?; 38 | self.3.encode(out)?; 39 | Ok(()) 40 | } 41 | } 42 | 43 | impl Encode for (T0, T1, T2, T3, T4, ) { 44 | fn encode(&self, out: &mut impl io::Write) -> Result { 45 | out.write_u8(104)?; 46 | out.write_u8(5)?; 47 | self.0.encode(out)?; 48 | self.1.encode(out)?; 49 | self.2.encode(out)?; 50 | self.3.encode(out)?; 51 | self.4.encode(out)?; 52 | Ok(()) 53 | } 54 | } 55 | 56 | impl Encode for (T0, T1, T2, T3, T4, T5, ) { 57 | fn encode(&self, out: &mut impl io::Write) -> Result { 58 | out.write_u8(104)?; 59 | out.write_u8(6)?; 60 | self.0.encode(out)?; 61 | self.1.encode(out)?; 62 | self.2.encode(out)?; 63 | self.3.encode(out)?; 64 | self.4.encode(out)?; 65 | self.5.encode(out)?; 66 | Ok(()) 67 | } 68 | } 69 | 70 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, ) { 71 | fn encode(&self, out: &mut impl io::Write) -> Result { 72 | out.write_u8(104)?; 73 | out.write_u8(7)?; 74 | self.0.encode(out)?; 75 | self.1.encode(out)?; 76 | self.2.encode(out)?; 77 | self.3.encode(out)?; 78 | self.4.encode(out)?; 79 | self.5.encode(out)?; 80 | self.6.encode(out)?; 81 | Ok(()) 82 | } 83 | } 84 | 85 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, ) { 86 | fn encode(&self, out: &mut impl io::Write) -> Result { 87 | out.write_u8(104)?; 88 | out.write_u8(8)?; 89 | self.0.encode(out)?; 90 | self.1.encode(out)?; 91 | self.2.encode(out)?; 92 | self.3.encode(out)?; 93 | self.4.encode(out)?; 94 | self.5.encode(out)?; 95 | self.6.encode(out)?; 96 | self.7.encode(out)?; 97 | Ok(()) 98 | } 99 | } 100 | 101 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, ) { 102 | fn encode(&self, out: &mut impl io::Write) -> Result { 103 | out.write_u8(104)?; 104 | out.write_u8(9)?; 105 | self.0.encode(out)?; 106 | self.1.encode(out)?; 107 | self.2.encode(out)?; 108 | self.3.encode(out)?; 109 | self.4.encode(out)?; 110 | self.5.encode(out)?; 111 | self.6.encode(out)?; 112 | self.7.encode(out)?; 113 | self.8.encode(out)?; 114 | Ok(()) 115 | } 116 | } 117 | 118 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, ) { 119 | fn encode(&self, out: &mut impl io::Write) -> Result { 120 | out.write_u8(104)?; 121 | out.write_u8(10)?; 122 | self.0.encode(out)?; 123 | self.1.encode(out)?; 124 | self.2.encode(out)?; 125 | self.3.encode(out)?; 126 | self.4.encode(out)?; 127 | self.5.encode(out)?; 128 | self.6.encode(out)?; 129 | self.7.encode(out)?; 130 | self.8.encode(out)?; 131 | self.9.encode(out)?; 132 | Ok(()) 133 | } 134 | } 135 | 136 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, ) { 137 | fn encode(&self, out: &mut impl io::Write) -> Result { 138 | out.write_u8(104)?; 139 | out.write_u8(11)?; 140 | self.0.encode(out)?; 141 | self.1.encode(out)?; 142 | self.2.encode(out)?; 143 | self.3.encode(out)?; 144 | self.4.encode(out)?; 145 | self.5.encode(out)?; 146 | self.6.encode(out)?; 147 | self.7.encode(out)?; 148 | self.8.encode(out)?; 149 | self.9.encode(out)?; 150 | self.10.encode(out)?; 151 | Ok(()) 152 | } 153 | } 154 | 155 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, ) { 156 | fn encode(&self, out: &mut impl io::Write) -> Result { 157 | out.write_u8(104)?; 158 | out.write_u8(12)?; 159 | self.0.encode(out)?; 160 | self.1.encode(out)?; 161 | self.2.encode(out)?; 162 | self.3.encode(out)?; 163 | self.4.encode(out)?; 164 | self.5.encode(out)?; 165 | self.6.encode(out)?; 166 | self.7.encode(out)?; 167 | self.8.encode(out)?; 168 | self.9.encode(out)?; 169 | self.10.encode(out)?; 170 | self.11.encode(out)?; 171 | Ok(()) 172 | } 173 | } 174 | 175 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, ) { 176 | fn encode(&self, out: &mut impl io::Write) -> Result { 177 | out.write_u8(104)?; 178 | out.write_u8(13)?; 179 | self.0.encode(out)?; 180 | self.1.encode(out)?; 181 | self.2.encode(out)?; 182 | self.3.encode(out)?; 183 | self.4.encode(out)?; 184 | self.5.encode(out)?; 185 | self.6.encode(out)?; 186 | self.7.encode(out)?; 187 | self.8.encode(out)?; 188 | self.9.encode(out)?; 189 | self.10.encode(out)?; 190 | self.11.encode(out)?; 191 | self.12.encode(out)?; 192 | Ok(()) 193 | } 194 | } 195 | 196 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, ) { 197 | fn encode(&self, out: &mut impl io::Write) -> Result { 198 | out.write_u8(104)?; 199 | out.write_u8(14)?; 200 | self.0.encode(out)?; 201 | self.1.encode(out)?; 202 | self.2.encode(out)?; 203 | self.3.encode(out)?; 204 | self.4.encode(out)?; 205 | self.5.encode(out)?; 206 | self.6.encode(out)?; 207 | self.7.encode(out)?; 208 | self.8.encode(out)?; 209 | self.9.encode(out)?; 210 | self.10.encode(out)?; 211 | self.11.encode(out)?; 212 | self.12.encode(out)?; 213 | self.13.encode(out)?; 214 | Ok(()) 215 | } 216 | } 217 | 218 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, ) { 219 | fn encode(&self, out: &mut impl io::Write) -> Result { 220 | out.write_u8(104)?; 221 | out.write_u8(15)?; 222 | self.0.encode(out)?; 223 | self.1.encode(out)?; 224 | self.2.encode(out)?; 225 | self.3.encode(out)?; 226 | self.4.encode(out)?; 227 | self.5.encode(out)?; 228 | self.6.encode(out)?; 229 | self.7.encode(out)?; 230 | self.8.encode(out)?; 231 | self.9.encode(out)?; 232 | self.10.encode(out)?; 233 | self.11.encode(out)?; 234 | self.12.encode(out)?; 235 | self.13.encode(out)?; 236 | self.14.encode(out)?; 237 | Ok(()) 238 | } 239 | } 240 | 241 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, ) { 242 | fn encode(&self, out: &mut impl io::Write) -> Result { 243 | out.write_u8(104)?; 244 | out.write_u8(16)?; 245 | self.0.encode(out)?; 246 | self.1.encode(out)?; 247 | self.2.encode(out)?; 248 | self.3.encode(out)?; 249 | self.4.encode(out)?; 250 | self.5.encode(out)?; 251 | self.6.encode(out)?; 252 | self.7.encode(out)?; 253 | self.8.encode(out)?; 254 | self.9.encode(out)?; 255 | self.10.encode(out)?; 256 | self.11.encode(out)?; 257 | self.12.encode(out)?; 258 | self.13.encode(out)?; 259 | self.14.encode(out)?; 260 | self.15.encode(out)?; 261 | Ok(()) 262 | } 263 | } 264 | 265 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, ) { 266 | fn encode(&self, out: &mut impl io::Write) -> Result { 267 | out.write_u8(104)?; 268 | out.write_u8(17)?; 269 | self.0.encode(out)?; 270 | self.1.encode(out)?; 271 | self.2.encode(out)?; 272 | self.3.encode(out)?; 273 | self.4.encode(out)?; 274 | self.5.encode(out)?; 275 | self.6.encode(out)?; 276 | self.7.encode(out)?; 277 | self.8.encode(out)?; 278 | self.9.encode(out)?; 279 | self.10.encode(out)?; 280 | self.11.encode(out)?; 281 | self.12.encode(out)?; 282 | self.13.encode(out)?; 283 | self.14.encode(out)?; 284 | self.15.encode(out)?; 285 | self.16.encode(out)?; 286 | Ok(()) 287 | } 288 | } 289 | 290 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, ) { 291 | fn encode(&self, out: &mut impl io::Write) -> Result { 292 | out.write_u8(104)?; 293 | out.write_u8(18)?; 294 | self.0.encode(out)?; 295 | self.1.encode(out)?; 296 | self.2.encode(out)?; 297 | self.3.encode(out)?; 298 | self.4.encode(out)?; 299 | self.5.encode(out)?; 300 | self.6.encode(out)?; 301 | self.7.encode(out)?; 302 | self.8.encode(out)?; 303 | self.9.encode(out)?; 304 | self.10.encode(out)?; 305 | self.11.encode(out)?; 306 | self.12.encode(out)?; 307 | self.13.encode(out)?; 308 | self.14.encode(out)?; 309 | self.15.encode(out)?; 310 | self.16.encode(out)?; 311 | self.17.encode(out)?; 312 | Ok(()) 313 | } 314 | } 315 | 316 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, ) { 317 | fn encode(&self, out: &mut impl io::Write) -> Result { 318 | out.write_u8(104)?; 319 | out.write_u8(19)?; 320 | self.0.encode(out)?; 321 | self.1.encode(out)?; 322 | self.2.encode(out)?; 323 | self.3.encode(out)?; 324 | self.4.encode(out)?; 325 | self.5.encode(out)?; 326 | self.6.encode(out)?; 327 | self.7.encode(out)?; 328 | self.8.encode(out)?; 329 | self.9.encode(out)?; 330 | self.10.encode(out)?; 331 | self.11.encode(out)?; 332 | self.12.encode(out)?; 333 | self.13.encode(out)?; 334 | self.14.encode(out)?; 335 | self.15.encode(out)?; 336 | self.16.encode(out)?; 337 | self.17.encode(out)?; 338 | self.18.encode(out)?; 339 | Ok(()) 340 | } 341 | } 342 | 343 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, ) { 344 | fn encode(&self, out: &mut impl io::Write) -> Result { 345 | out.write_u8(104)?; 346 | out.write_u8(20)?; 347 | self.0.encode(out)?; 348 | self.1.encode(out)?; 349 | self.2.encode(out)?; 350 | self.3.encode(out)?; 351 | self.4.encode(out)?; 352 | self.5.encode(out)?; 353 | self.6.encode(out)?; 354 | self.7.encode(out)?; 355 | self.8.encode(out)?; 356 | self.9.encode(out)?; 357 | self.10.encode(out)?; 358 | self.11.encode(out)?; 359 | self.12.encode(out)?; 360 | self.13.encode(out)?; 361 | self.14.encode(out)?; 362 | self.15.encode(out)?; 363 | self.16.encode(out)?; 364 | self.17.encode(out)?; 365 | self.18.encode(out)?; 366 | self.19.encode(out)?; 367 | Ok(()) 368 | } 369 | } 370 | 371 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, ) { 372 | fn encode(&self, out: &mut impl io::Write) -> Result { 373 | out.write_u8(104)?; 374 | out.write_u8(21)?; 375 | self.0.encode(out)?; 376 | self.1.encode(out)?; 377 | self.2.encode(out)?; 378 | self.3.encode(out)?; 379 | self.4.encode(out)?; 380 | self.5.encode(out)?; 381 | self.6.encode(out)?; 382 | self.7.encode(out)?; 383 | self.8.encode(out)?; 384 | self.9.encode(out)?; 385 | self.10.encode(out)?; 386 | self.11.encode(out)?; 387 | self.12.encode(out)?; 388 | self.13.encode(out)?; 389 | self.14.encode(out)?; 390 | self.15.encode(out)?; 391 | self.16.encode(out)?; 392 | self.17.encode(out)?; 393 | self.18.encode(out)?; 394 | self.19.encode(out)?; 395 | self.20.encode(out)?; 396 | Ok(()) 397 | } 398 | } 399 | 400 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, ) { 401 | fn encode(&self, out: &mut impl io::Write) -> Result { 402 | out.write_u8(104)?; 403 | out.write_u8(22)?; 404 | self.0.encode(out)?; 405 | self.1.encode(out)?; 406 | self.2.encode(out)?; 407 | self.3.encode(out)?; 408 | self.4.encode(out)?; 409 | self.5.encode(out)?; 410 | self.6.encode(out)?; 411 | self.7.encode(out)?; 412 | self.8.encode(out)?; 413 | self.9.encode(out)?; 414 | self.10.encode(out)?; 415 | self.11.encode(out)?; 416 | self.12.encode(out)?; 417 | self.13.encode(out)?; 418 | self.14.encode(out)?; 419 | self.15.encode(out)?; 420 | self.16.encode(out)?; 421 | self.17.encode(out)?; 422 | self.18.encode(out)?; 423 | self.19.encode(out)?; 424 | self.20.encode(out)?; 425 | self.21.encode(out)?; 426 | Ok(()) 427 | } 428 | } 429 | 430 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, ) { 431 | fn encode(&self, out: &mut impl io::Write) -> Result { 432 | out.write_u8(104)?; 433 | out.write_u8(23)?; 434 | self.0.encode(out)?; 435 | self.1.encode(out)?; 436 | self.2.encode(out)?; 437 | self.3.encode(out)?; 438 | self.4.encode(out)?; 439 | self.5.encode(out)?; 440 | self.6.encode(out)?; 441 | self.7.encode(out)?; 442 | self.8.encode(out)?; 443 | self.9.encode(out)?; 444 | self.10.encode(out)?; 445 | self.11.encode(out)?; 446 | self.12.encode(out)?; 447 | self.13.encode(out)?; 448 | self.14.encode(out)?; 449 | self.15.encode(out)?; 450 | self.16.encode(out)?; 451 | self.17.encode(out)?; 452 | self.18.encode(out)?; 453 | self.19.encode(out)?; 454 | self.20.encode(out)?; 455 | self.21.encode(out)?; 456 | self.22.encode(out)?; 457 | Ok(()) 458 | } 459 | } 460 | 461 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, ) { 462 | fn encode(&self, out: &mut impl io::Write) -> Result { 463 | out.write_u8(104)?; 464 | out.write_u8(24)?; 465 | self.0.encode(out)?; 466 | self.1.encode(out)?; 467 | self.2.encode(out)?; 468 | self.3.encode(out)?; 469 | self.4.encode(out)?; 470 | self.5.encode(out)?; 471 | self.6.encode(out)?; 472 | self.7.encode(out)?; 473 | self.8.encode(out)?; 474 | self.9.encode(out)?; 475 | self.10.encode(out)?; 476 | self.11.encode(out)?; 477 | self.12.encode(out)?; 478 | self.13.encode(out)?; 479 | self.14.encode(out)?; 480 | self.15.encode(out)?; 481 | self.16.encode(out)?; 482 | self.17.encode(out)?; 483 | self.18.encode(out)?; 484 | self.19.encode(out)?; 485 | self.20.encode(out)?; 486 | self.21.encode(out)?; 487 | self.22.encode(out)?; 488 | self.23.encode(out)?; 489 | Ok(()) 490 | } 491 | } 492 | 493 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, ) { 494 | fn encode(&self, out: &mut impl io::Write) -> Result { 495 | out.write_u8(104)?; 496 | out.write_u8(25)?; 497 | self.0.encode(out)?; 498 | self.1.encode(out)?; 499 | self.2.encode(out)?; 500 | self.3.encode(out)?; 501 | self.4.encode(out)?; 502 | self.5.encode(out)?; 503 | self.6.encode(out)?; 504 | self.7.encode(out)?; 505 | self.8.encode(out)?; 506 | self.9.encode(out)?; 507 | self.10.encode(out)?; 508 | self.11.encode(out)?; 509 | self.12.encode(out)?; 510 | self.13.encode(out)?; 511 | self.14.encode(out)?; 512 | self.15.encode(out)?; 513 | self.16.encode(out)?; 514 | self.17.encode(out)?; 515 | self.18.encode(out)?; 516 | self.19.encode(out)?; 517 | self.20.encode(out)?; 518 | self.21.encode(out)?; 519 | self.22.encode(out)?; 520 | self.23.encode(out)?; 521 | self.24.encode(out)?; 522 | Ok(()) 523 | } 524 | } 525 | 526 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, ) { 527 | fn encode(&self, out: &mut impl io::Write) -> Result { 528 | out.write_u8(104)?; 529 | out.write_u8(26)?; 530 | self.0.encode(out)?; 531 | self.1.encode(out)?; 532 | self.2.encode(out)?; 533 | self.3.encode(out)?; 534 | self.4.encode(out)?; 535 | self.5.encode(out)?; 536 | self.6.encode(out)?; 537 | self.7.encode(out)?; 538 | self.8.encode(out)?; 539 | self.9.encode(out)?; 540 | self.10.encode(out)?; 541 | self.11.encode(out)?; 542 | self.12.encode(out)?; 543 | self.13.encode(out)?; 544 | self.14.encode(out)?; 545 | self.15.encode(out)?; 546 | self.16.encode(out)?; 547 | self.17.encode(out)?; 548 | self.18.encode(out)?; 549 | self.19.encode(out)?; 550 | self.20.encode(out)?; 551 | self.21.encode(out)?; 552 | self.22.encode(out)?; 553 | self.23.encode(out)?; 554 | self.24.encode(out)?; 555 | self.25.encode(out)?; 556 | Ok(()) 557 | } 558 | } 559 | 560 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, ) { 561 | fn encode(&self, out: &mut impl io::Write) -> Result { 562 | out.write_u8(104)?; 563 | out.write_u8(27)?; 564 | self.0.encode(out)?; 565 | self.1.encode(out)?; 566 | self.2.encode(out)?; 567 | self.3.encode(out)?; 568 | self.4.encode(out)?; 569 | self.5.encode(out)?; 570 | self.6.encode(out)?; 571 | self.7.encode(out)?; 572 | self.8.encode(out)?; 573 | self.9.encode(out)?; 574 | self.10.encode(out)?; 575 | self.11.encode(out)?; 576 | self.12.encode(out)?; 577 | self.13.encode(out)?; 578 | self.14.encode(out)?; 579 | self.15.encode(out)?; 580 | self.16.encode(out)?; 581 | self.17.encode(out)?; 582 | self.18.encode(out)?; 583 | self.19.encode(out)?; 584 | self.20.encode(out)?; 585 | self.21.encode(out)?; 586 | self.22.encode(out)?; 587 | self.23.encode(out)?; 588 | self.24.encode(out)?; 589 | self.25.encode(out)?; 590 | self.26.encode(out)?; 591 | Ok(()) 592 | } 593 | } 594 | 595 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, ) { 596 | fn encode(&self, out: &mut impl io::Write) -> Result { 597 | out.write_u8(104)?; 598 | out.write_u8(28)?; 599 | self.0.encode(out)?; 600 | self.1.encode(out)?; 601 | self.2.encode(out)?; 602 | self.3.encode(out)?; 603 | self.4.encode(out)?; 604 | self.5.encode(out)?; 605 | self.6.encode(out)?; 606 | self.7.encode(out)?; 607 | self.8.encode(out)?; 608 | self.9.encode(out)?; 609 | self.10.encode(out)?; 610 | self.11.encode(out)?; 611 | self.12.encode(out)?; 612 | self.13.encode(out)?; 613 | self.14.encode(out)?; 614 | self.15.encode(out)?; 615 | self.16.encode(out)?; 616 | self.17.encode(out)?; 617 | self.18.encode(out)?; 618 | self.19.encode(out)?; 619 | self.20.encode(out)?; 620 | self.21.encode(out)?; 621 | self.22.encode(out)?; 622 | self.23.encode(out)?; 623 | self.24.encode(out)?; 624 | self.25.encode(out)?; 625 | self.26.encode(out)?; 626 | self.27.encode(out)?; 627 | Ok(()) 628 | } 629 | } 630 | 631 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, ) { 632 | fn encode(&self, out: &mut impl io::Write) -> Result { 633 | out.write_u8(104)?; 634 | out.write_u8(29)?; 635 | self.0.encode(out)?; 636 | self.1.encode(out)?; 637 | self.2.encode(out)?; 638 | self.3.encode(out)?; 639 | self.4.encode(out)?; 640 | self.5.encode(out)?; 641 | self.6.encode(out)?; 642 | self.7.encode(out)?; 643 | self.8.encode(out)?; 644 | self.9.encode(out)?; 645 | self.10.encode(out)?; 646 | self.11.encode(out)?; 647 | self.12.encode(out)?; 648 | self.13.encode(out)?; 649 | self.14.encode(out)?; 650 | self.15.encode(out)?; 651 | self.16.encode(out)?; 652 | self.17.encode(out)?; 653 | self.18.encode(out)?; 654 | self.19.encode(out)?; 655 | self.20.encode(out)?; 656 | self.21.encode(out)?; 657 | self.22.encode(out)?; 658 | self.23.encode(out)?; 659 | self.24.encode(out)?; 660 | self.25.encode(out)?; 661 | self.26.encode(out)?; 662 | self.27.encode(out)?; 663 | self.28.encode(out)?; 664 | Ok(()) 665 | } 666 | } 667 | 668 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, ) { 669 | fn encode(&self, out: &mut impl io::Write) -> Result { 670 | out.write_u8(104)?; 671 | out.write_u8(30)?; 672 | self.0.encode(out)?; 673 | self.1.encode(out)?; 674 | self.2.encode(out)?; 675 | self.3.encode(out)?; 676 | self.4.encode(out)?; 677 | self.5.encode(out)?; 678 | self.6.encode(out)?; 679 | self.7.encode(out)?; 680 | self.8.encode(out)?; 681 | self.9.encode(out)?; 682 | self.10.encode(out)?; 683 | self.11.encode(out)?; 684 | self.12.encode(out)?; 685 | self.13.encode(out)?; 686 | self.14.encode(out)?; 687 | self.15.encode(out)?; 688 | self.16.encode(out)?; 689 | self.17.encode(out)?; 690 | self.18.encode(out)?; 691 | self.19.encode(out)?; 692 | self.20.encode(out)?; 693 | self.21.encode(out)?; 694 | self.22.encode(out)?; 695 | self.23.encode(out)?; 696 | self.24.encode(out)?; 697 | self.25.encode(out)?; 698 | self.26.encode(out)?; 699 | self.27.encode(out)?; 700 | self.28.encode(out)?; 701 | self.29.encode(out)?; 702 | Ok(()) 703 | } 704 | } 705 | 706 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, ) { 707 | fn encode(&self, out: &mut impl io::Write) -> Result { 708 | out.write_u8(104)?; 709 | out.write_u8(31)?; 710 | self.0.encode(out)?; 711 | self.1.encode(out)?; 712 | self.2.encode(out)?; 713 | self.3.encode(out)?; 714 | self.4.encode(out)?; 715 | self.5.encode(out)?; 716 | self.6.encode(out)?; 717 | self.7.encode(out)?; 718 | self.8.encode(out)?; 719 | self.9.encode(out)?; 720 | self.10.encode(out)?; 721 | self.11.encode(out)?; 722 | self.12.encode(out)?; 723 | self.13.encode(out)?; 724 | self.14.encode(out)?; 725 | self.15.encode(out)?; 726 | self.16.encode(out)?; 727 | self.17.encode(out)?; 728 | self.18.encode(out)?; 729 | self.19.encode(out)?; 730 | self.20.encode(out)?; 731 | self.21.encode(out)?; 732 | self.22.encode(out)?; 733 | self.23.encode(out)?; 734 | self.24.encode(out)?; 735 | self.25.encode(out)?; 736 | self.26.encode(out)?; 737 | self.27.encode(out)?; 738 | self.28.encode(out)?; 739 | self.29.encode(out)?; 740 | self.30.encode(out)?; 741 | Ok(()) 742 | } 743 | } 744 | 745 | impl Encode for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, ) { 746 | fn encode(&self, out: &mut impl io::Write) -> Result { 747 | out.write_u8(104)?; 748 | out.write_u8(32)?; 749 | self.0.encode(out)?; 750 | self.1.encode(out)?; 751 | self.2.encode(out)?; 752 | self.3.encode(out)?; 753 | self.4.encode(out)?; 754 | self.5.encode(out)?; 755 | self.6.encode(out)?; 756 | self.7.encode(out)?; 757 | self.8.encode(out)?; 758 | self.9.encode(out)?; 759 | self.10.encode(out)?; 760 | self.11.encode(out)?; 761 | self.12.encode(out)?; 762 | self.13.encode(out)?; 763 | self.14.encode(out)?; 764 | self.15.encode(out)?; 765 | self.16.encode(out)?; 766 | self.17.encode(out)?; 767 | self.18.encode(out)?; 768 | self.19.encode(out)?; 769 | self.20.encode(out)?; 770 | self.21.encode(out)?; 771 | self.22.encode(out)?; 772 | self.23.encode(out)?; 773 | self.24.encode(out)?; 774 | self.25.encode(out)?; 775 | self.26.encode(out)?; 776 | self.27.encode(out)?; 777 | self.28.encode(out)?; 778 | self.29.encode(out)?; 779 | self.30.encode(out)?; 780 | self.31.encode(out)?; 781 | Ok(()) 782 | } 783 | } 784 | 785 | -------------------------------------------------------------------------------- /shell.nix: -------------------------------------------------------------------------------- 1 | { pkgs ? import {} }: 2 | 3 | with pkgs; 4 | 5 | mkShell { 6 | buildInputs = [ 7 | cargo 8 | yarn 9 | go 10 | ruby 11 | elixir 12 | ]; 13 | } 14 | --------------------------------------------------------------------------------