Skip to content

Commit

Permalink
make the vendored name shorter
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsamson committed Oct 5, 2024
1 parent 198fc86 commit f1c10fa
Show file tree
Hide file tree
Showing 24 changed files with 165 additions and 165 deletions.
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# JasonVendored
# JasonV

A blazing fast JSON parser and generator in pure Elixir.

The parser and generator are at least twice as fast as other Elixir/Erlang libraries
(most notably `Poison`).
The performance is comparable to `jiffy`, which is implemented in C as a NIF.
JasonVendored is usually only twice as slow.
JasonV is usually only twice as slow.

Both parser and generator fully conform to
[RFC 8259](https://tools.ietf.org/html/rfc8259) and
Expand All @@ -26,10 +26,10 @@ end
## Basic Usage

``` elixir
iex(1)> JasonVendored.encode!(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"})
iex(1)> JasonV.encode!(%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"})
"{\"age\":44,\"name\":\"Steve Irwin\",\"nationality\":\"Australian\"}"

iex(2)> JasonVendored.decode!(~s({"age":44,"name":"Steve Irwin","nationality":"Australian"}))
iex(2)> JasonV.decode!(~s({"age":44,"name":"Steve Irwin","nationality":"Australian"}))
%{"age" => 44, "name" => "Steve Irwin", "nationality" => "Australian"}
```

Expand All @@ -39,17 +39,17 @@ Full documentation can be found at [https://hexdocs.pm/jason](https://hexdocs.pm

### Postgrex

Versions starting at 0.14.0 use `JasonVendored` by default. For earlier versions, please refer to
Versions starting at 0.14.0 use `JasonV` by default. For earlier versions, please refer to
[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#postgrex).

### Ecto

Versions starting at 3.0.0 use `JasonVendored` by default. For earlier versions, please refer to
Versions starting at 3.0.0 use `JasonV` by default. For earlier versions, please refer to
[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#ecto).

### Plug (and Phoenix)

Phoenix starting at 1.4.0 uses `JasonVendored` by default. For earlier versions, please refer to
Phoenix starting at 1.4.0 uses `JasonV` by default. For earlier versions, please refer to
[previous versions of this document](https://github.com/michalmuskala/jason/tree/v1.1.2#plug-and-phoenix).

### Absinthe
Expand All @@ -60,12 +60,12 @@ You need to pass the `:json_codec` option to `Absinthe.Plug`
# When called directly:
plug Absinthe.Plug,
schema: MyApp.Schema,
json_codec: JasonVendored
json_codec: JasonV

# When used in phoenix router:
forward "/api",
to: Absinthe.Plug,
init_opts: [schema: MyApp.Schema, json_codec: JasonVendored]
init_opts: [schema: MyApp.Schema, json_codec: JasonV]
```

## Benchmarks
Expand All @@ -85,15 +85,15 @@ A HTML report of the benchmarks (after their execution) can be found in

## Differences to Poison

JasonVendored has a couple feature differences compared to Poison.
JasonV has a couple feature differences compared to Poison.

* JasonVendored follows the JSON spec more strictly, for example it does not allow
* JasonV follows the JSON spec more strictly, for example it does not allow
unescaped newline characters in JSON strings - e.g. `"\"\n\""` will
produce a decoding error.
* no support for decoding into data structures (the `as:` option).
* no built-in encoders for `MapSet`, `Range` and `Stream`.
* no support for encoding arbitrary structs - explicit implementation
of the `JasonVendored.Encoder` protocol is always required.
of the `JasonV.Encoder` protocol is always required.
* different pretty-printing customisation options (default `pretty: true` works the same)

### Encoders
Expand All @@ -102,9 +102,9 @@ If you require encoders for any of the unsupported collection types, I suggest
adding the needed implementations directly to your project:

```elixir
defimpl JasonVendored.Encoder, for: [MapSet, Range, Stream] do
defimpl JasonV.Encoder, for: [MapSet, Range, Stream] do
def encode(struct, opts) do
JasonVendored.Encode.list(Enum.to_list(struct), opts)
JasonV.Encode.list(Enum.to_list(struct), opts)
end
end
```
Expand All @@ -114,7 +114,7 @@ if you own the struct, you can derive the implementation specifying
which fields should be encoded to JSON:

```elixir
@derive {JasonVendored.Encoder, only: [....]}
@derive {JasonV.Encoder, only: [....]}
defstruct # ...
```

Expand All @@ -123,16 +123,16 @@ used carefully to avoid accidentally leaking private information
when new fields are added:

```elixir
@derive JasonVendored.Encoder
@derive JasonV.Encoder
defstruct # ...
```

Finally, if you don't own the struct you want to encode to JSON,
you may use `Protocol.derive/3` placed outside of any module:

```elixir
Protocol.derive(JasonVendored.Encoder, NameOfTheStruct, only: [...])
Protocol.derive(JasonVendored.Encoder, NameOfTheStruct)
Protocol.derive(JasonV.Encoder, NameOfTheStruct, only: [...])
Protocol.derive(JasonV.Encoder, NameOfTheStruct)
```

## Injecting an already encoded JSON inside a to-be-encoded structure
Expand All @@ -151,7 +151,7 @@ or if it is already provided by another system (e.g. `jsonb_agg` with Postgres).

## License

JasonVendored is released under the Apache License 2.0 - see the [LICENSE](LICENSE) file.
JasonV is released under the Apache License 2.0 - see the [LICENSE](LICENSE) file.

Some elements of tests and benchmarks have their origins in the
[Poison library](https://github.com/devinus/poison) and were initially licensed under [CC0-1.0](https://creativecommons.org/publicdomain/zero/1.0/).
4 changes: 2 additions & 2 deletions bench/decode.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
decode_jobs = %{
"JasonVendored" => fn {json, _} -> JasonVendored.decode!(json) end,
"JasonV" => fn {json, _} -> JasonV.decode!(json) end,
"Poison" => fn {json, _} -> Poison.decode!(json) end,
"JSX" => fn {json, _} -> JSX.decode!(json, [:strict]) end,
"Tiny" => fn {json, _} -> Tiny.decode!(json) end,
Expand Down Expand Up @@ -30,7 +30,7 @@ read_data = fn name ->
|> String.trim("-")

json = File.read!(Path.expand("data/#{file}.json", __DIR__))
etf = :erlang.term_to_binary(JasonVendored.decode!(json))
etf = :erlang.term_to_binary(JasonV.decode!(json))

{json, etf}
end
Expand Down
6 changes: 3 additions & 3 deletions bench/encode.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
encode_jobs = %{
"JasonVendored" => &JasonVendored.encode_to_iodata!/1,
"JasonVendored strict" => &JasonVendored.encode_to_iodata!(&1, maps: :strict),
"JasonV" => &JasonV.encode_to_iodata!/1,
"JasonV strict" => &JasonV.encode_to_iodata!(&1, maps: :strict),
"Poison" => &Poison.encode_to_iodata!/1,
"JSX" => &JSX.encode!/1,
"Tiny" => &Tiny.encode!/1,
Expand Down Expand Up @@ -41,7 +41,7 @@ Benchee.run(encode_jobs,
for name <- encode_inputs, into: %{} do
name
|> read_data.()
|> JasonVendored.decode!()
|> JasonV.decode!()
|> (&{name, &1}).()
end,
formatters: [
Expand Down
2 changes: 1 addition & 1 deletion bench/mix.exs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule JasonVendoredBench.MixProject do
defmodule JasonVBench.MixProject do
use Mix.Project

def project do
Expand Down
4 changes: 2 additions & 2 deletions lib/codegen.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule JasonVendored.Codegen do
defmodule JasonV.Codegen do
@moduledoc false

alias JasonVendored.{Encode, EncodeError}
alias JasonV.{Encode, EncodeError}

def jump_table(ranges, default) do
ranges
Expand Down
8 changes: 4 additions & 4 deletions lib/decoder.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule JasonVendored.DecodeError do
defmodule JasonV.DecodeError do
@type t :: %__MODULE__{position: integer, data: String.t()}

defexception [:position, :token, :data]
Expand All @@ -25,12 +25,12 @@ defmodule JasonVendored.DecodeError do
end
end

defmodule JasonVendored.Decoder do
defmodule JasonV.Decoder do
@moduledoc false

import Bitwise

alias JasonVendored.{DecodeError, Codegen}
alias JasonV.{DecodeError, Codegen}

import Codegen, only: [bytecase: 2, bytecase: 3]
import Record
Expand Down Expand Up @@ -77,7 +77,7 @@ defmodule JasonVendored.Decoder do
defp string_decode_function(%{strings: :reference}), do: & &1

defp object_decode_function(%{objects: :maps}), do: &:maps.from_list/1
defp object_decode_function(%{objects: :ordered_objects}), do: &JasonVendored.OrderedObject.new(:lists.reverse(&1))
defp object_decode_function(%{objects: :ordered_objects}), do: &JasonV.OrderedObject.new(:lists.reverse(&1))

defp float_decode_function(%{floats: :native}) do
fn string, token, skip ->
Expand Down
10 changes: 5 additions & 5 deletions lib/encode.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule JasonVendored.EncodeError do
defmodule JasonV.EncodeError do
defexception [:message]

@type t :: %__MODULE__{message: String.t()}
Expand All @@ -12,14 +12,14 @@ defmodule JasonVendored.EncodeError do
end
end

defmodule JasonVendored.Encode do
defmodule JasonV.Encode do
@moduledoc """
Utilities for encoding elixir values to JSON.
"""

import Bitwise

alias JasonVendored.{Codegen, EncodeError, Encoder, Fragment, OrderedObject}
alias JasonV.{Codegen, EncodeError, Encoder, Fragment, OrderedObject}

@typep escape :: (String.t(), String.t(), integer -> iodata)
@typep encode_map :: (map, escape, encode_map -> iodata)
Expand All @@ -41,7 +41,7 @@ defmodule JasonVendored.Encode do
:throw, %EncodeError{} = e ->
{:error, e}

:error, %Protocol.UndefinedError{protocol: JasonVendored.Encoder} = e ->
:error, %Protocol.UndefinedError{protocol: JasonV.Encoder} = e ->
{:error, e}
end
end
Expand All @@ -66,7 +66,7 @@ defmodule JasonVendored.Encode do
end

@doc """
Equivalent to calling the `JasonVendored.Encoder.encode/2` protocol function.
Equivalent to calling the `JasonV.Encoder.encode/2` protocol function.
Slightly more efficient for built-in types because of the internal dispatching.
"""
Expand Down
Loading

0 comments on commit f1c10fa

Please sign in to comment.