Skip to content

Commit

Permalink
Merge pull request #29 from loopholelabs/staging
Browse files Browse the repository at this point in the history
Release v1.1.3
  • Loading branch information
ShivanshVij authored Sep 1, 2023
2 parents f96ef00 + 9fdfb19 commit ed3407b
Show file tree
Hide file tree
Showing 18 changed files with 1,534 additions and 1,042 deletions.
8 changes: 8 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
dist
target
.github
**/*.go
**/*.rs
go.mod
go.sum
53 changes: 53 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Lint

on: [pull_request]

jobs:
typescript:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Cache the dependency directories
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('*.json') }}
- name: Install dependencies with npm
run: npm install --save-dev
- name: Lint with npm
run: npm run lint
rust:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Rust
run: |
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
rustup component add clippy
shell: bash
- name: Cargo lint
run: cargo fmt --all -- --check
- name: Cargo clippy
run: cargo clippy --all -- -D warnings
golang:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Golang
uses: actions/setup-go@v4
with:
go-version: '1.21'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
17 changes: 8 additions & 9 deletions .github/workflows/releases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ on:
workflow_dispatch:

jobs:
Rust:
cargo:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: Set up Rust
run: |
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
shell: bash
- name: Cargo build
run: cargo build --release
- name: Publish to crates.io
run: cargo publish
run: cargo publish --token $CARGO_REGISTRY_TOKEN
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
Typescript:
Expand All @@ -31,7 +30,7 @@ jobs:
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Cache the Node Modules Directory
uses: actions/cache@v3
Expand Down
28 changes: 13 additions & 15 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
uses: actions/setup-go@v4
with:
go-version: "1.20"
go-version: "1.21"
check-latest: true
cache: true
- name: Run Tests
Expand All @@ -21,37 +21,35 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- name: Set up Rust
run: |
rustup toolchain install stable --profile minimal --no-self-update
rustup default stable
rustup target add wasm32-wasi
shell: bash
- name: Cargo fmt
run: cargo fmt --all -- --check
- name: Cargo check
run: cargo check
- name: Add wasm32-unknown-unknown target
run: rustup target add wasm32-unknown-unknown
- name: Cargo check wasm32-unknown-unknown
run: cargo check --target wasm32-unknown-unknown
- name: Cargo check wasm32-wasi
run: cargo check --target wasm32-wasi
- name: Run Tests
run: cargo test
Typescript:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: "16"
node-version: "20"
registry-url: "https://registry.npmjs.org"
- name: Cache the Node Modules Directory
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-${{ hashFiles('package.json') }}
key: ${{ runner.os }}-${{ hashFiles('*.json') }}
- name: Install Node Dependencies with NPM
run: npm install
- name: Run Tests
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [v1.1.3] - 2023-09-01

### Features

- Added Durable Errors for Decoders ([#28](https://github.com/loopholelabs/polyglot/pull/28))

## [v1.1.2] - 2023-08-26

### Fixes
Expand All @@ -33,7 +39,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

- Merging Typescript, Golang, and Rust implementations into a single repository

[unreleased]: https://github.com/loopholelabs/scale/compare/v1.1.2...HEAD
[unreleased]: https://github.com/loopholelabs/scale/compare/v1.1.3...HEAD
[v1.1.3]: https://github.com/loopholelabs/scale/compare/v1.1.3
[v1.1.2]: https://github.com/loopholelabs/scale/compare/v1.1.2
[v1.1.1]: https://github.com/loopholelabs/scale/compare/v1.1.1
[v1.1.0]: https://github.com/loopholelabs/scale/compare/v1.1.0
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "polyglot_rs"
version = "1.1.2"
version = "1.1.3"
edition = "2021"
description="A high-performance serialization framework used for encoding and decoding arbitrary datastructures across languages."
license = "Apache-2.0"
Expand Down Expand Up @@ -28,7 +28,7 @@ byteorder = "1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.105"
base64 = "0.21.3"
num_enum = "0.6.1"
num_enum = "0.7.0"

[profile.release]
opt-level = 3
Expand Down
35 changes: 16 additions & 19 deletions decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,11 @@ pub trait Decoder {

impl Decoder for Cursor<&mut Vec<u8>> {
fn decode_none(&mut self) -> bool {
match self.read_u8() {
Ok(kind) => {
if kind == Kind::None as u8 {
return true;
}
self.set_position(self.position() - 1);
if let Ok(kind) = self.read_u8() {
if kind == Kind::None as u8 {
return true;
}
Err(_) => {}
self.set_position(self.position() - 1);
}
false
}
Expand Down Expand Up @@ -331,10 +328,10 @@ mod tests {

let mut decoder = Cursor::new(encoder.get_mut());
let val = decoder.decode_none();
assert_eq!(val, true);
assert!(val);
assert_eq!(decoder.get_ref().len() - decoder.position() as usize, 0);
let next_val = decoder.decode_none();
assert_eq!(next_val, false);
assert!(!next_val);
}

#[test]
Expand All @@ -348,7 +345,7 @@ mod tests {
}

let mut decoder = Cursor::new(encoder.get_mut());
let size = decoder.decode_array(Kind::String).unwrap() as usize;
let size = decoder.decode_array(Kind::String).unwrap();
assert_eq!(size, m.len());

let mut mv: Vec<String> = Vec::with_capacity(size);
Expand Down Expand Up @@ -379,7 +376,7 @@ mod tests {
}

let mut decoder = Cursor::new(encoder.get_mut());
let size = decoder.decode_map(Kind::String, Kind::U32).unwrap() as usize;
let size = decoder.decode_map(Kind::String, Kind::U32).unwrap();
assert_eq!(size, m.len());

let mut mv = HashMap::new();
Expand Down Expand Up @@ -440,7 +437,7 @@ mod tests {

let mut decoder = Cursor::new(encoder.get_mut());
let val = decoder.decode_bool().unwrap();
assert_eq!(val, true);
assert!(val);

let error = decoder.decode_bool().unwrap_err();
assert_eq!(error, DecodingError::InvalidBool);
Expand All @@ -449,7 +446,7 @@ mod tests {
#[test]
fn test_decode_u8() {
let mut encoder = Cursor::new(Vec::with_capacity(512));
let v = 32 as u8;
let v = 32_u8;
encoder.encode_u8(v).unwrap();

let mut decoder = Cursor::new(encoder.get_mut());
Expand All @@ -463,7 +460,7 @@ mod tests {
#[test]
fn test_decode_u16() {
let mut encoder = Cursor::new(Vec::with_capacity(512));
let v = 1024 as u16;
let v = 1024_u16;
encoder.encode_u16(v).unwrap();

let mut decoder = Cursor::new(encoder.get_mut());
Expand All @@ -477,7 +474,7 @@ mod tests {
#[test]
fn test_decode_u32() {
let mut encoder = Cursor::new(Vec::with_capacity(512));
let v = 4294967290 as u32;
let v = 4294967290_u32;
encoder.encode_u32(v).unwrap();

let mut decoder = Cursor::new(encoder.get_mut());
Expand All @@ -491,7 +488,7 @@ mod tests {
#[test]
fn test_decode_u64() {
let mut encoder = Cursor::new(Vec::with_capacity(512));
let v = 18446744073709551610 as u64;
let v = 18446744073709551610_u64;
encoder.encode_u64(v).unwrap();

let mut decoder = Cursor::new(encoder.get_mut());
Expand Down Expand Up @@ -524,7 +521,7 @@ mod tests {
#[test]
fn test_decode_i64() {
let mut encoder = Cursor::new(Vec::with_capacity(512));
let v = -9223372036854775808 as i64;
let v = -9223372036854775808_i64;
encoder.encode_i64(v).unwrap();

let mut decoder = Cursor::new(encoder.get_mut());
Expand All @@ -538,7 +535,7 @@ mod tests {
#[test]
fn test_decode_f32() {
let mut encoder = Cursor::new(Vec::with_capacity(512));
let v = -2147483.648 as f32;
let v = -2_147_483.8_f32;
encoder.encode_f32(v).unwrap();

let mut decoder = Cursor::new(encoder.get_mut());
Expand All @@ -552,7 +549,7 @@ mod tests {
#[test]
fn test_decode_f64() {
let mut encoder = Cursor::new(Vec::with_capacity(512));
let v = -922337203.477580 as f64;
let v = -922337203.477580_f64;
encoder.encode_f64(v).unwrap();

let mut decoder = Cursor::new(encoder.get_mut());
Expand Down
6 changes: 3 additions & 3 deletions decoder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { Encoder } from "./encoder";
import { Kind } from "./kind";

window.TextEncoder = TextEncoder;
window.TextDecoder = TextDecoder as typeof window["TextDecoder"];
window.TextDecoder = TextDecoder as (typeof window)["TextDecoder"];

describe("Decoder", () => {
it("Can decode Null", () => {
Expand Down Expand Up @@ -262,7 +262,7 @@ describe("Decoder", () => {
expect(decoder.length).toBe(0);

expect(() => decoder.map(Kind.String, Kind.Uint32)).toThrowError(
InvalidMapError
InvalidMapError,
);
});

Expand Down Expand Up @@ -309,7 +309,7 @@ describe("Decoder", () => {
expect(() => {
const encodedWithMissingStringKind = new Encoder().error(expected).bytes;
const decoderMissingStringKind = new Decoder(
encodedWithMissingStringKind
encodedWithMissingStringKind,
);

encodedWithMissingStringKind[1] = 999999;
Expand Down
Loading

0 comments on commit ed3407b

Please sign in to comment.