dependabot-hex 0.119.0.beta1 → 0.119.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- metadata +8 -29
- data/helpers/install-dir/hex/deps/jason/.fetch +0 -0
- data/helpers/install-dir/hex/deps/jason/.hex +0 -0
- data/helpers/install-dir/hex/deps/jason/CHANGELOG.md +0 -88
- data/helpers/install-dir/hex/deps/jason/LICENSE +0 -13
- data/helpers/install-dir/hex/deps/jason/README.md +0 -141
- data/helpers/install-dir/hex/deps/jason/hex_metadata.config +0 -20
- data/helpers/install-dir/hex/deps/jason/lib/codegen.ex +0 -138
- data/helpers/install-dir/hex/deps/jason/lib/decoder.ex +0 -657
- data/helpers/install-dir/hex/deps/jason/lib/encode.ex +0 -634
- data/helpers/install-dir/hex/deps/jason/lib/encoder.ex +0 -216
- data/helpers/install-dir/hex/deps/jason/lib/formatter.ex +0 -253
- data/helpers/install-dir/hex/deps/jason/lib/fragment.ex +0 -11
- data/helpers/install-dir/hex/deps/jason/lib/helpers.ex +0 -98
- data/helpers/install-dir/hex/deps/jason/lib/jason.ex +0 -228
- data/helpers/install-dir/hex/deps/jason/mix.exs +0 -76
- data/helpers/install-dir/hex/lib/check_update.exs +0 -92
- data/helpers/install-dir/hex/lib/do_update.exs +0 -39
- data/helpers/install-dir/hex/lib/parse_deps.exs +0 -104
- data/helpers/install-dir/hex/lib/run.exs +0 -76
- data/helpers/install-dir/hex/mix.exs +0 -21
- data/helpers/install-dir/hex/mix.lock +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1d308ed672417c66ce2cfce3bfb05da4241eddda0eeef98c90749522a09adf40
|
|
4
|
+
data.tar.gz: 696a2bb1f90d5796a28aad7101539f86cc18bfbcf0ad8ed86a7156c921d7c300
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 51b75b9694592adae0dc4465b7d96f6232af89a0f352c3795664726b246e2587d968f28c5168e9ede74fd8e2e7e1d0138c7cd35f1f116a2cd94db58206b40335
|
|
7
|
+
data.tar.gz: b544043310882ebd964830d70f408ff4b0eb2cd9e43c878ae30d2b3a7a7a3067fd12f0cc4de8cb43453fbf7a95d9754ee62af0a6effac1150bd50d556ce11e3c
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dependabot-hex
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.119.0
|
|
4
|
+
version: 0.119.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dependabot
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-08-
|
|
11
|
+
date: 2020-08-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: dependabot-common
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - '='
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.119.0
|
|
19
|
+
version: 0.119.0
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - '='
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.119.0
|
|
26
|
+
version: 0.119.0
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: byebug
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -144,27 +144,6 @@ extensions: []
|
|
|
144
144
|
extra_rdoc_files: []
|
|
145
145
|
files:
|
|
146
146
|
- helpers/build
|
|
147
|
-
- helpers/install-dir/hex/deps/jason/.fetch
|
|
148
|
-
- helpers/install-dir/hex/deps/jason/.hex
|
|
149
|
-
- helpers/install-dir/hex/deps/jason/CHANGELOG.md
|
|
150
|
-
- helpers/install-dir/hex/deps/jason/LICENSE
|
|
151
|
-
- helpers/install-dir/hex/deps/jason/README.md
|
|
152
|
-
- helpers/install-dir/hex/deps/jason/hex_metadata.config
|
|
153
|
-
- helpers/install-dir/hex/deps/jason/lib/codegen.ex
|
|
154
|
-
- helpers/install-dir/hex/deps/jason/lib/decoder.ex
|
|
155
|
-
- helpers/install-dir/hex/deps/jason/lib/encode.ex
|
|
156
|
-
- helpers/install-dir/hex/deps/jason/lib/encoder.ex
|
|
157
|
-
- helpers/install-dir/hex/deps/jason/lib/formatter.ex
|
|
158
|
-
- helpers/install-dir/hex/deps/jason/lib/fragment.ex
|
|
159
|
-
- helpers/install-dir/hex/deps/jason/lib/helpers.ex
|
|
160
|
-
- helpers/install-dir/hex/deps/jason/lib/jason.ex
|
|
161
|
-
- helpers/install-dir/hex/deps/jason/mix.exs
|
|
162
|
-
- helpers/install-dir/hex/lib/check_update.exs
|
|
163
|
-
- helpers/install-dir/hex/lib/do_update.exs
|
|
164
|
-
- helpers/install-dir/hex/lib/parse_deps.exs
|
|
165
|
-
- helpers/install-dir/hex/lib/run.exs
|
|
166
|
-
- helpers/install-dir/hex/mix.exs
|
|
167
|
-
- helpers/install-dir/hex/mix.lock
|
|
168
147
|
- helpers/lib/check_update.exs
|
|
169
148
|
- helpers/lib/do_update.exs
|
|
170
149
|
- helpers/lib/parse_deps.exs
|
|
@@ -192,7 +171,7 @@ homepage: https://github.com/dependabot/dependabot-core
|
|
|
192
171
|
licenses:
|
|
193
172
|
- Nonstandard
|
|
194
173
|
metadata: {}
|
|
195
|
-
post_install_message:
|
|
174
|
+
post_install_message:
|
|
196
175
|
rdoc_options: []
|
|
197
176
|
require_paths:
|
|
198
177
|
- lib
|
|
@@ -207,8 +186,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
207
186
|
- !ruby/object:Gem::Version
|
|
208
187
|
version: 2.5.0
|
|
209
188
|
requirements: []
|
|
210
|
-
rubygems_version: 3.1.
|
|
211
|
-
signing_key:
|
|
189
|
+
rubygems_version: 3.1.2
|
|
190
|
+
signing_key:
|
|
212
191
|
specification_version: 4
|
|
213
192
|
summary: Elixir (Hex) support for dependabot
|
|
214
193
|
test_files: []
|
|
File without changes
|
|
Binary file
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 1.2.1 (04.05.2020)
|
|
4
|
-
|
|
5
|
-
### Security
|
|
6
|
-
|
|
7
|
-
* Fix `html_safe` escaping in `Jason.encode`
|
|
8
|
-
|
|
9
|
-
The `<!--` sequence of characters would not be escaped in `Jason.encode`
|
|
10
|
-
with`html_escape` mode, which could lead to DoS attacks when used for
|
|
11
|
-
embedding of arbitrary, user controlled strings into HTML through JSON
|
|
12
|
-
(e.g. inside of `<script>` tags).
|
|
13
|
-
|
|
14
|
-
If you were not using the `html_safe` option, you are not affected.
|
|
15
|
-
|
|
16
|
-
Affected versions: < 1.2.1
|
|
17
|
-
Patched versions: >= 1.2.1
|
|
18
|
-
|
|
19
|
-
## 1.2.0 (17.03.2020)
|
|
20
|
-
|
|
21
|
-
### Enhancements
|
|
22
|
-
|
|
23
|
-
* Add `Jason.Encode.keyword/2`
|
|
24
|
-
([cb1f26a](https://github.com/michalmuskala/jason/commit/cb1f26a)).
|
|
25
|
-
|
|
26
|
-
### Bug fixes
|
|
27
|
-
|
|
28
|
-
* Fix `Jason.Helpers.json_map/1` value expansion
|
|
29
|
-
([70b046a](https://github.com/michalmuskala/jason/commit/70b046a)).
|
|
30
|
-
|
|
31
|
-
## 1.1.2 (19.10.2018)
|
|
32
|
-
|
|
33
|
-
### Bug fixes
|
|
34
|
-
|
|
35
|
-
* correctly handle the `pretty: false` option
|
|
36
|
-
([ba318c8](https://github.com/michalmuskala/jason/commit/ba318c8)).
|
|
37
|
-
|
|
38
|
-
## 1.1.1 (10.07.2018)
|
|
39
|
-
|
|
40
|
-
### Bug fixes
|
|
41
|
-
|
|
42
|
-
* correctly handle escape sequences in strings when pretty printing
|
|
43
|
-
([794bbe4](https://github.com/michalmuskala/jason/commit/794bbe4)).
|
|
44
|
-
|
|
45
|
-
## 1.1.0 (02.07.2018)
|
|
46
|
-
|
|
47
|
-
### Enhancements
|
|
48
|
-
|
|
49
|
-
* pretty-printing support through `Jason.Formatter` and `pretty: true` option
|
|
50
|
-
in `Jason.encode/2` ([d758e36](https://github.com/michalmuskala/jason/commit/d758e36)).
|
|
51
|
-
|
|
52
|
-
### Bug fixes
|
|
53
|
-
|
|
54
|
-
* silence variable warnings for fields with underscores used during deriving
|
|
55
|
-
([88dd85c](https://github.com/michalmuskala/jason/commit/88dd85c)).
|
|
56
|
-
* **potential incompatibility** don't raise `Protocol.UndefinedError` in non-bang functions
|
|
57
|
-
([ad0f57b](https://github.com/michalmuskala/jason/commit/ad0f57b)).
|
|
58
|
-
|
|
59
|
-
## 1.0.1 (02.07.2018)
|
|
60
|
-
|
|
61
|
-
### Bug fixes
|
|
62
|
-
|
|
63
|
-
* fix `Jason.Encode.escape` type ([a57b430](https://github.com/michalmuskala/jason/commit/a57b430))
|
|
64
|
-
* multiple documentation improvements
|
|
65
|
-
|
|
66
|
-
## 1.0.0 (26.01.2018)
|
|
67
|
-
|
|
68
|
-
No changes
|
|
69
|
-
|
|
70
|
-
## 1.0.0-rc.3 (26.01.2018)
|
|
71
|
-
|
|
72
|
-
### Changes
|
|
73
|
-
|
|
74
|
-
* update `escape` option of `Jason.encode/2` to take values:
|
|
75
|
-
`:json | :unicode_safe | :html_safe | :javascript_safe` for consistency. Old values of
|
|
76
|
-
`:unicode` and `:javascript` are still supported for compatibility with Poison.
|
|
77
|
-
([f42dcbd](https://github.com/michalmuskala/jason/commit/f42dcbd))
|
|
78
|
-
|
|
79
|
-
## 1.0.0-rc.2 (07.01.2018)
|
|
80
|
-
|
|
81
|
-
### Bug fixes
|
|
82
|
-
|
|
83
|
-
* add type for `strings` option ([b459ee4](https://github.com/michalmuskala/jason/commit/b459ee4))
|
|
84
|
-
* support iodata in `decode!` ([a1f3456](https://github.com/michalmuskala/jason/commit/a1f3456))
|
|
85
|
-
|
|
86
|
-
## 1.0.0-rc.1 (22.12.2017)
|
|
87
|
-
|
|
88
|
-
Initial release
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
Copyright 2017 Michał Muskała
|
|
2
|
-
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
|
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
|
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
See the License for the specific language governing permissions and
|
|
13
|
-
limitations under the License.
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
# Jason
|
|
2
|
-
|
|
3
|
-
A blazing fast JSON parser and generator in pure Elixir.
|
|
4
|
-
|
|
5
|
-
The parser and generator are at least twice as fast as other Elixir/Erlang libraries
|
|
6
|
-
(most notably `Poison`).
|
|
7
|
-
The performance is comparable to `jiffy`, which is implemented in C as a NIF.
|
|
8
|
-
Jason is usually only twice as slow.
|
|
9
|
-
|
|
10
|
-
Both parser and generator fully conform to
|
|
11
|
-
[RFC 8259](https://tools.ietf.org/html/rfc8259) and
|
|
12
|
-
[ECMA 404](http://www.ecma-international.org/publications/standards/Ecma-404.htm)
|
|
13
|
-
standards. The parser is tested using [JSONTestSuite](https://github.com/nst/JSONTestSuite).
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
The package can be installed by adding `jason` to your list of dependencies
|
|
18
|
-
in `mix.exs`:
|
|
19
|
-
|
|
20
|
-
```elixir
|
|
21
|
-
def deps do
|
|
22
|
-
[{:jason, "~> 1.2"}]
|
|
23
|
-
end
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
## Basic Usage
|
|
27
|
-
|
|
28
|
-
``` elixir
|
|
29
|
-
iex(1)> Jason.encode!(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"})
|
|
30
|
-
"{\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}"
|
|
31
|
-
|
|
32
|
-
iex(2)> Jason.decode!(~s({"age":44,"name":"Steve Irwin","nationality":"Australian"}))
|
|
33
|
-
%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"}
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
Full documentation can be found at [https://hexdocs.pm/jason](https://hexdocs.pm/jason).
|
|
37
|
-
|
|
38
|
-
## Use with other libraries
|
|
39
|
-
|
|
40
|
-
### Postgrex
|
|
41
|
-
|
|
42
|
-
Versions starting at 0.14.0 use `Jason` by default. For earlier versions, please refer to
|
|
43
|
-
[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#postgrex).
|
|
44
|
-
|
|
45
|
-
### Ecto
|
|
46
|
-
|
|
47
|
-
Versions starting at 3.0.0 use `Jason` by default. For earlier versions, please refer to
|
|
48
|
-
[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#ecto).
|
|
49
|
-
|
|
50
|
-
### Plug (and Phoenix)
|
|
51
|
-
|
|
52
|
-
Phoenix starting at 1.4.0 uses `Jason` by default. For earlier versions, please refer to
|
|
53
|
-
[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#plug-and-phoenix).
|
|
54
|
-
|
|
55
|
-
### Absinthe
|
|
56
|
-
|
|
57
|
-
You need to pass the `:json_codec` option to `Absinthe.Plug`
|
|
58
|
-
|
|
59
|
-
```elixir
|
|
60
|
-
# When called directly:
|
|
61
|
-
plug Absinthe.Plug,
|
|
62
|
-
schema: MyApp.Schema,
|
|
63
|
-
json_codec: Jason
|
|
64
|
-
|
|
65
|
-
# When used in phoenix router:
|
|
66
|
-
forward "/api",
|
|
67
|
-
to: Absinthe.Plug,
|
|
68
|
-
init_opts: [schema: MyApp.Schema, json_codec: Jason]
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Benchmarks
|
|
72
|
-
|
|
73
|
-
Detailed benchmarks (including memory measurements):
|
|
74
|
-
https://gist.github.com/michalmuskala/4d64a5a7696ca84ac7c169a0206640d5
|
|
75
|
-
|
|
76
|
-
HTML reports for the benchmark (only performance measurements):
|
|
77
|
-
http://michal.muskala.eu/jason/decode.html and http://michal.muskala.eu/jason/encode.html
|
|
78
|
-
|
|
79
|
-
### Running
|
|
80
|
-
|
|
81
|
-
Benchmarks against most popular Elixir & Erlang json libraries can be executed after
|
|
82
|
-
going into the `bench/` folder and then executing `mix bench.encode` and `mix bench.decode`.
|
|
83
|
-
A HTML report of the benchmarks (after their execution) can be found in
|
|
84
|
-
`bench/output/encode.html` and `bench/output/decode.html` respectively.
|
|
85
|
-
|
|
86
|
-
## Differences to Poison
|
|
87
|
-
|
|
88
|
-
Jason has a couple feature differences compared to Poison.
|
|
89
|
-
|
|
90
|
-
* Jason follows the JSON spec more strictly, for example it does not allow
|
|
91
|
-
unescaped newline characters in JSON strings - e.g. `"\"\n\""` will
|
|
92
|
-
produce a decoding error.
|
|
93
|
-
* no support for decoding into data structures (the `as:` option).
|
|
94
|
-
* no built-in encoders for `MapSet`, `Range` and `Stream`.
|
|
95
|
-
* no support for encoding arbitrary structs - explicit implementation
|
|
96
|
-
of the `Jason.Encoder` protocol is always required.
|
|
97
|
-
* different pretty-printing customisation options (default `pretty: true` works the same)
|
|
98
|
-
|
|
99
|
-
If you require encoders for any of the unsupported collection types, I suggest
|
|
100
|
-
adding the needed implementations directly to your project:
|
|
101
|
-
|
|
102
|
-
```elixir
|
|
103
|
-
defimpl Jason.Encoder, for: [MapSet, Range, Stream] do
|
|
104
|
-
def encode(struct, opts) do
|
|
105
|
-
Jason.Encode.list(Enum.to_list(struct), opts)
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
If you need to encode some struct that does not implement the protocol,
|
|
111
|
-
if you own the struct, you can derive the implementation specifying
|
|
112
|
-
which fields should be encoded to JSON:
|
|
113
|
-
|
|
114
|
-
```elixir
|
|
115
|
-
@derive {Jason.Encoder, only: [....]}
|
|
116
|
-
defstruct # ...
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
It is also possible to encode all fields, although this should be
|
|
120
|
-
used carefully to avoid accidentally leaking private information
|
|
121
|
-
when new fields are added:
|
|
122
|
-
|
|
123
|
-
```elixir
|
|
124
|
-
@derive Jason.Encoder
|
|
125
|
-
defstruct # ...
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
Finally, if you don't own the struct you want to encode to JSON,
|
|
129
|
-
you may use `Protocol.derive/3` placed outside of any module:
|
|
130
|
-
|
|
131
|
-
```elixir
|
|
132
|
-
Protocol.derive(Jason.Encoder, NameOfTheStruct, only: [...])
|
|
133
|
-
Protocol.derive(Jason.Encoder, NameOfTheStruct)
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
## License
|
|
137
|
-
|
|
138
|
-
Jason is released under the Apache License 2.0 - see the [LICENSE](LICENSE) file.
|
|
139
|
-
|
|
140
|
-
Some elements of tests and benchmarks have their origins in the
|
|
141
|
-
[Poison library](https://github.com/devinus/poison) and were initially licensed under [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{<<"app">>,<<"jason">>}.
|
|
2
|
-
{<<"build_tools">>,[<<"mix">>]}.
|
|
3
|
-
{<<"description">>,
|
|
4
|
-
<<"A blazing fast JSON parser and generator in pure Elixir.">>}.
|
|
5
|
-
{<<"elixir">>,<<"~> 1.4">>}.
|
|
6
|
-
{<<"files">>,
|
|
7
|
-
[<<"lib">>,<<"lib/jason.ex">>,<<"lib/encoder.ex">>,<<"lib/decoder.ex">>,
|
|
8
|
-
<<"lib/formatter.ex">>,<<"lib/encode.ex">>,<<"lib/codegen.ex">>,
|
|
9
|
-
<<"lib/helpers.ex">>,<<"lib/fragment.ex">>,<<"mix.exs">>,<<"README.md">>,
|
|
10
|
-
<<"LICENSE">>,<<"CHANGELOG.md">>]}.
|
|
11
|
-
{<<"licenses">>,[<<"Apache-2.0">>]}.
|
|
12
|
-
{<<"links">>,[{<<"GitHub">>,<<"https://github.com/michalmuskala/jason">>}]}.
|
|
13
|
-
{<<"name">>,<<"jason">>}.
|
|
14
|
-
{<<"requirements">>,
|
|
15
|
-
[[{<<"app">>,<<"decimal">>},
|
|
16
|
-
{<<"name">>,<<"decimal">>},
|
|
17
|
-
{<<"optional">>,true},
|
|
18
|
-
{<<"repository">>,<<"hexpm">>},
|
|
19
|
-
{<<"requirement">>,<<"~> 1.0">>}]]}.
|
|
20
|
-
{<<"version">>,<<"1.2.1">>}.
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
defmodule Jason.Codegen do
|
|
2
|
-
@moduledoc false
|
|
3
|
-
|
|
4
|
-
alias Jason.{Encode, EncodeError}
|
|
5
|
-
|
|
6
|
-
def jump_table(ranges, default) do
|
|
7
|
-
ranges
|
|
8
|
-
|> ranges_to_orddict()
|
|
9
|
-
|> :array.from_orddict(default)
|
|
10
|
-
|> :array.to_orddict()
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def jump_table(ranges, default, max) do
|
|
14
|
-
ranges
|
|
15
|
-
|> ranges_to_orddict()
|
|
16
|
-
|> :array.from_orddict(default)
|
|
17
|
-
|> resize(max)
|
|
18
|
-
|> :array.to_orddict()
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
defmacro bytecase(var, do: clauses) do
|
|
22
|
-
{ranges, default, literals} = clauses_to_ranges(clauses, [])
|
|
23
|
-
|
|
24
|
-
jump_table = jump_table(ranges, default)
|
|
25
|
-
|
|
26
|
-
quote do
|
|
27
|
-
case unquote(var) do
|
|
28
|
-
unquote(jump_table_to_clauses(jump_table, literals))
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
defmacro bytecase(var, max, do: clauses) do
|
|
34
|
-
{ranges, default, empty} = clauses_to_ranges(clauses, [])
|
|
35
|
-
|
|
36
|
-
jump_table = jump_table(ranges, default, max)
|
|
37
|
-
|
|
38
|
-
quote do
|
|
39
|
-
case unquote(var) do
|
|
40
|
-
unquote(jump_table_to_clauses(jump_table, empty))
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def build_kv_iodata(kv, encode_args) do
|
|
46
|
-
elements =
|
|
47
|
-
kv
|
|
48
|
-
|> Enum.map(&encode_pair(&1, encode_args))
|
|
49
|
-
|> Enum.intersperse(",")
|
|
50
|
-
|
|
51
|
-
collapse_static(List.flatten(["{", elements] ++ '}'))
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
defp clauses_to_ranges([{:->, _, [[{:in, _, [byte, range]}, rest], action]} | tail], acc) do
|
|
55
|
-
clauses_to_ranges(tail, [{range, {byte, rest, action}} | acc])
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
defp clauses_to_ranges([{:->, _, [[default, rest], action]} | tail], acc) do
|
|
59
|
-
{Enum.reverse(acc), {default, rest, action}, literal_clauses(tail)}
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
defp literal_clauses(clauses) do
|
|
63
|
-
Enum.map(clauses, fn {:->, _, [[literal], action]} ->
|
|
64
|
-
{literal, action}
|
|
65
|
-
end)
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
defp jump_table_to_clauses([{val, {{:_, _, _}, rest, action}} | tail], empty) do
|
|
69
|
-
quote do
|
|
70
|
-
<<unquote(val), unquote(rest)::bits>> ->
|
|
71
|
-
unquote(action)
|
|
72
|
-
end ++ jump_table_to_clauses(tail, empty)
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
defp jump_table_to_clauses([{val, {byte, rest, action}} | tail], empty) do
|
|
76
|
-
quote do
|
|
77
|
-
<<unquote(byte), unquote(rest)::bits>> when unquote(byte) === unquote(val) ->
|
|
78
|
-
unquote(action)
|
|
79
|
-
end ++ jump_table_to_clauses(tail, empty)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
defp jump_table_to_clauses([], literals) do
|
|
83
|
-
Enum.flat_map(literals, fn {pattern, action} ->
|
|
84
|
-
quote do
|
|
85
|
-
unquote(pattern) ->
|
|
86
|
-
unquote(action)
|
|
87
|
-
end
|
|
88
|
-
end)
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
defp resize(array, size), do: :array.resize(size, array)
|
|
92
|
-
|
|
93
|
-
defp ranges_to_orddict(ranges) do
|
|
94
|
-
ranges
|
|
95
|
-
|> Enum.flat_map(fn
|
|
96
|
-
{int, value} when is_integer(int) ->
|
|
97
|
-
[{int, value}]
|
|
98
|
-
|
|
99
|
-
{enum, value} ->
|
|
100
|
-
Enum.map(enum, &{&1, value})
|
|
101
|
-
end)
|
|
102
|
-
|> :orddict.from_list()
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
defp encode_pair({key, value}, encode_args) do
|
|
106
|
-
key = IO.iodata_to_binary(Encode.key(key, &escape_key/3))
|
|
107
|
-
key = "\"" <> key <> "\":"
|
|
108
|
-
[key, quote(do: Encode.value(unquote(value), unquote_splicing(encode_args)))]
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
defp escape_key(binary, _original, _skip) do
|
|
112
|
-
check_safe_key!(binary)
|
|
113
|
-
binary
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
defp check_safe_key!(binary) do
|
|
117
|
-
for <<(<<byte>> <- binary)>> do
|
|
118
|
-
if byte > 0x7F or byte < 0x1F or byte in '"\\/' do
|
|
119
|
-
raise EncodeError,
|
|
120
|
-
"invalid byte #{inspect(byte, base: :hex)} in literal key: #{inspect(binary)}"
|
|
121
|
-
end
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
:ok
|
|
125
|
-
end
|
|
126
|
-
|
|
127
|
-
defp collapse_static([bin1, bin2 | rest]) when is_binary(bin1) and is_binary(bin2) do
|
|
128
|
-
collapse_static([bin1 <> bin2 | rest])
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
defp collapse_static([other | rest]) do
|
|
132
|
-
[other | collapse_static(rest)]
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
defp collapse_static([]) do
|
|
136
|
-
[]
|
|
137
|
-
end
|
|
138
|
-
end
|