Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 100 additions & 0 deletions .credo.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# .credo.exs
%{
configs: [
%{
name: "default",
files: %{
included: ["lib/", "test/"],
excluded: [~r"/_build/", ~r"/deps/", ~r"/node_modules/"]
},
plugins: [],
requires: [],
strict: false,
parse_timeout: 5000,
color: true,
checks: %{
enabled: [
# Design Checks
{Credo.Check.Design.AliasUsage, []},
{Credo.Check.Design.TagFIXME, []},
{Credo.Check.Design.TagTODO, exit_status: 0},

# Readability Checks
{Credo.Check.Readability.AliasOrder, []},
{Credo.Check.Readability.FunctionNames, []},
{Credo.Check.Readability.LargeNumbers, []},
{Credo.Check.Readability.MaxLineLength, [max_length: 120]},
{Credo.Check.Readability.ModuleAttributeNames, []},
{Credo.Check.Readability.ModuleDoc, []},
{Credo.Check.Readability.ModuleNames, []},
{Credo.Check.Readability.ParenthesesInCondition, []},
{Credo.Check.Readability.ParenthesesOnZeroArityDefs, []},
{Credo.Check.Readability.PipeIntoAnonymousFunctions, []},
{Credo.Check.Readability.PredicateFunctionNames, []},
{Credo.Check.Readability.PreferImplicitTry, []},
{Credo.Check.Readability.RedundantBlankLines, []},
{Credo.Check.Readability.Semicolons, []},
{Credo.Check.Readability.SpaceAfterCommas, []},
{Credo.Check.Readability.StringSigils, []},
{Credo.Check.Readability.TrailingBlankLine, []},
{Credo.Check.Readability.TrailingWhiteSpace, []},
{Credo.Check.Readability.UnnecessaryAliasExpansion, []},
{Credo.Check.Readability.VariableNames, []},
{Credo.Check.Readability.WithSingleClause, []},

# Refactoring Opportunities
{Credo.Check.Refactor.Apply, []},
{Credo.Check.Refactor.CondStatements, []},
{Credo.Check.Refactor.CyclomaticComplexity, []},
{Credo.Check.Refactor.FunctionArity, []},
{Credo.Check.Refactor.LongQuoteBlocks, []},
{Credo.Check.Refactor.MatchInCondition, []},
{Credo.Check.Refactor.MapJoin, []},
{Credo.Check.Refactor.NegatedConditionsInUnless, []},
{Credo.Check.Refactor.NegatedConditionsWithElse, []},
{Credo.Check.Refactor.Nesting, []},
{Credo.Check.Refactor.UnlessWithElse, []},
{Credo.Check.Refactor.WithClauses, []},

# Warnings
{Credo.Check.Warning.ApplicationConfigInModuleAttribute, []},
{Credo.Check.Warning.BoolOperationOnSameValues, []},
{Credo.Check.Warning.Dbg, []},
{Credo.Check.Warning.ExpensiveEmptyEnumCheck, []},
{Credo.Check.Warning.IExPry, []},
{Credo.Check.Warning.IoInspect, []},
{Credo.Check.Warning.OperationOnSameValues, []},
{Credo.Check.Warning.OperationWithConstantResult, []},
{Credo.Check.Warning.RaiseInsideRescue, []},
{Credo.Check.Warning.SpecWithStruct, []},
{Credo.Check.Warning.UnusedEnumOperation, []},
{Credo.Check.Warning.UnusedFileOperation, []},
{Credo.Check.Warning.UnusedKeywordOperation, []},
{Credo.Check.Warning.UnusedListOperation, []},
{Credo.Check.Warning.UnusedPathOperation, []},
{Credo.Check.Warning.UnusedRegexOperation, []},
{Credo.Check.Warning.UnusedStringOperation, []},
{Credo.Check.Warning.UnusedTupleOperation, []},
{Credo.Check.Warning.WrongTestFileExtension, []}
],
disabled: [
# Disabled checks
{Credo.Check.Readability.MultiAlias, []},
{Credo.Check.Readability.Specs, []},
{Credo.Check.Refactor.ABCSize, []},
{Credo.Check.Refactor.AppendSingleItem, []},
{Credo.Check.Refactor.DoubleBooleanNegation, []},
{Credo.Check.Refactor.ModuleDependencies, []},
{Credo.Check.Refactor.NegatedIsNil, []},
{Credo.Check.Refactor.PipeChainStart, []},
{Credo.Check.Refactor.VariableRebinding, []},
{Credo.Check.Warning.LazyLogging, []},
{Credo.Check.Warning.LeakyEnvironment, []},
{Credo.Check.Warning.MapGetUnsafePass, []},
{Credo.Check.Warning.MixEnv, []},
{Credo.Check.Warning.UnsafeToAtom, []}
]
}
}
]
}
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on:
push:
branches: [ master, main ]
pull_request:
branches: [ master, main ]

jobs:
test:
name: Test on Elixir ${{matrix.elixir}} / OTP ${{matrix.otp}}
runs-on: ubuntu-latest
strategy:
matrix:
elixir: ['1.14', '1.15', '1.16']
otp: ['25', '26']

steps:
- uses: actions/checkout@v3

- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{matrix.elixir}}
otp-version: ${{matrix.otp}}

- name: Restore dependencies cache
uses: actions/cache@v3
with:
path: deps
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-mix-

- name: Install dependencies
run: mix deps.get

- name: Compile with warnings as errors
run: mix compile --warnings-as-errors

- name: Run tests
run: mix test

- name: Run Credo
run: mix credo --strict

- name: Run Sobelow
run: mix sobelow --exit Low

8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ erl_crash.dump

# Ignore package tarball (built via "mix hex.build").
smile-*.tar
smile_ex-*.tar

# Temporary files, for example, from tests.
/tmp/

# Dialyzer
/priv/plts/

# Coverage reports
coveralls.html
.coveralls.yml
35 changes: 35 additions & 0 deletions .hexignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Ignore build artifacts
/_build
/cover
/doc
/deps

# Ignore test files
/test

# Ignore git files
/.git
/.github
/.gitignore

# Ignore development files
/.elixir_ls
/.vscode
/.idea

# Ignore examples
/examples

# Ignore temporary files
*.swp
*.swo
*~
.DS_Store

# Ignore CI files
/.travis.yml
/.github

# Ignore summary
/SUMMARY.md

13 changes: 13 additions & 0 deletions .sobelow-conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
verbose: false,
private: false,
skip: false,
router: "",
exit: "false",
format: "txt",
out: "",
threshold: "low",
ignore: [],
ignore_files: []
]

12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Initial release of Smile binary format encoder/decoder for Elixir
- Initial release of SmileEx binary format encoder/decoder for Elixir
- Complete implementation of Smile format specification v1.0
- Support for all JSON-compatible data types (null, boolean, integer, float, string, array, object)
- Encoding with back-references for field names and string values
Expand All @@ -30,5 +30,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Typically 20-40% size reduction compared to JSON
- Faster encoding and decoding than text-based JSON

[0.1.0]: https://github.com/thanos/smile/releases/tag/v0.1.0
[0.1.0]: https://github.com/thanos/smile_ex/releases/tag/v0.1.0

22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2025 Smile Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

47 changes: 35 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Smile
# SmileEx


[![Hex.pm](https://img.shields.io/hexpm/v/smile.svg)](https://hex.pm/packages/smile)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/smile/)
[![Hex.pm](https://img.shields.io/hexpm/dt/smile.svg)](https://hex.pm/packages/smile)
[![Hex.pm](https://img.shields.io/hexpm/v/smile_ex.svg)](https://hex.pm/packages/smile_ex)
[![Hex Docs](https://img.shields.io/badge/hex-docs-lightgreen.svg)](https://hexdocs.pm/smile_ex/)
[![Hex.pm](https://img.shields.io/hexpm/dt/smile_ex.svg)](https://hex.pm/packages/smile_ex)



Expand All @@ -21,12 +22,12 @@ Smile is a computer data interchange format based on JSON. It can be considered

## Installation

Add `smile` to your list of dependencies in `mix.exs`:
Add `smile_ex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:smile, "~> 0.1.0"}
{:smile_ex, "~> 0.1.0"}
]
end
```
Expand Down Expand Up @@ -187,18 +188,33 @@ json = Jason.encode!(data)
# Plus: faster to encode/decode
```

## Testing
## Development

Run the test suite:
### Testing

```bash
# Run tests
mix test

# Run tests with coverage
mix test --cover

# Generate HTML coverage report
mix coveralls.html
open cover/excoveralls.html
```

Run tests with coverage:
### Code Quality

```bash
mix test --cover
# Static code analysis
mix credo

# Security analysis
mix sobelow

# Type checking (first run takes a while)
mix dialyzer
```

## Specification
Expand All @@ -211,15 +227,22 @@ For more details about the format, see:

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.
Contributions are welcome! Please ensure:

1. All tests pass: `mix test`
2. Code passes static analysis: `mix credo`
3. No security issues: `mix sobelow`
4. Code is formatted: `mix format`

Then submit a Pull Request.

## License

This project is licensed under the MIT License.

## API Documentation

The complete API documentation is available on [HexDocs](https://hexdocs.pm/smile/).
The complete API documentation is available on [HexDocs](https://hexdocs.pm/smile_ex/).

You can also generate documentation locally:

Expand Down
12 changes: 12 additions & 0 deletions coveralls.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"coverage_options": {
"minimum_coverage": 70,
"treat_no_relevant_lines_as_covered": true,
"output_dir": "cover/"
},
"skip_files": [
"test/",
"deps/"
]
}

14 changes: 9 additions & 5 deletions lib/constants.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,21 @@ defmodule Smile.Constants do
def max_shared_names, do: 1024
def max_shared_string_values, do: 1024
def max_shared_string_length_bytes, do: 65
def min_buffer_for_possible_short_string, do: 1 + (3 * 65)
def min_buffer_for_possible_short_string, do: 1 + 3 * 65

# Byte markers
def byte_marker_end_of_string, do: 0xFC
def byte_marker_end_of_content, do: 0xFF

# Format header
def header_byte_1, do: 0x3A # ':'
def header_byte_2, do: 0x29 # ')'
def header_byte_3, do: 0x0A # '\n'
def header_byte_4, do: 0x00 # version 0
# ':'
def header_byte_1, do: 0x3A
# ')'
def header_byte_2, do: 0x29
# '\n'
def header_byte_3, do: 0x0A
# version 0
def header_byte_4, do: 0x00

# Header bits
def header_bit_has_shared_names, do: 0x01
Expand Down
Loading
Loading