Skip to content

Commit ed3407b

Browse files
authored
Merge pull request #29 from loopholelabs/staging
Release v1.1.3
2 parents f96ef00 + 9fdfb19 commit ed3407b

18 files changed

+1534
-1042
lines changed

.eslintignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
node_modules
2+
dist
3+
target
4+
.github
5+
**/*.go
6+
**/*.rs
7+
go.mod
8+
go.sum

.github/workflows/lint.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Lint
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
typescript:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v3
11+
- name: Setup node
12+
uses: actions/setup-node@v3
13+
with:
14+
node-version: "20"
15+
registry-url: "https://registry.npmjs.org"
16+
- name: Cache the dependency directories
17+
uses: actions/cache@v3
18+
with:
19+
path: node_modules
20+
key: ${{ runner.os }}-${{ hashFiles('*.json') }}
21+
- name: Install dependencies with npm
22+
run: npm install --save-dev
23+
- name: Lint with npm
24+
run: npm run lint
25+
rust:
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v3
30+
- name: Set up Rust
31+
run: |
32+
rustup toolchain install stable --profile minimal --no-self-update
33+
rustup default stable
34+
rustup component add clippy
35+
shell: bash
36+
- name: Cargo lint
37+
run: cargo fmt --all -- --check
38+
- name: Cargo clippy
39+
run: cargo clippy --all -- -D warnings
40+
golang:
41+
runs-on: ubuntu-latest
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v3
45+
- name: Set up Golang
46+
uses: actions/setup-go@v4
47+
with:
48+
go-version: '1.21'
49+
cache: false
50+
- name: golangci-lint
51+
uses: golangci/golangci-lint-action@v3
52+
with:
53+
version: latest

.github/workflows/releases.yaml

+8-9
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,20 @@ on:
66
workflow_dispatch:
77

88
jobs:
9-
Rust:
9+
cargo:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- name: Checkout
1313
uses: actions/checkout@v3
14-
- name: Install Rust
15-
uses: actions-rs/toolchain@v1
16-
with:
17-
toolchain: stable
18-
override: true
19-
components: rustfmt, clippy
14+
- name: Set up Rust
15+
run: |
16+
rustup toolchain install stable --profile minimal --no-self-update
17+
rustup default stable
18+
shell: bash
2019
- name: Cargo build
2120
run: cargo build --release
2221
- name: Publish to crates.io
23-
run: cargo publish
22+
run: cargo publish --token $CARGO_REGISTRY_TOKEN
2423
env:
2524
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
2625
Typescript:
@@ -31,7 +30,7 @@ jobs:
3130
- name: Install Node
3231
uses: actions/setup-node@v3
3332
with:
34-
node-version: "16"
33+
node-version: "20"
3534
registry-url: "https://registry.npmjs.org"
3635
- name: Cache the Node Modules Directory
3736
uses: actions/cache@v3

.github/workflows/tests.yaml

+13-15
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
- name: Checkout
1010
uses: actions/checkout@v3
1111
- name: Install Go
12-
uses: actions/setup-go@v3
12+
uses: actions/setup-go@v4
1313
with:
14-
go-version: "1.20"
14+
go-version: "1.21"
1515
check-latest: true
1616
cache: true
1717
- name: Run Tests
@@ -21,37 +21,35 @@ jobs:
2121
steps:
2222
- name: Checkout
2323
uses: actions/checkout@v3
24-
- name: Install Rust
25-
uses: actions-rs/toolchain@v1
26-
with:
27-
toolchain: stable
28-
override: true
29-
components: rustfmt, clippy
24+
- name: Set up Rust
25+
run: |
26+
rustup toolchain install stable --profile minimal --no-self-update
27+
rustup default stable
28+
rustup target add wasm32-wasi
29+
shell: bash
3030
- name: Cargo fmt
3131
run: cargo fmt --all -- --check
3232
- name: Cargo check
3333
run: cargo check
34-
- name: Add wasm32-unknown-unknown target
35-
run: rustup target add wasm32-unknown-unknown
36-
- name: Cargo check wasm32-unknown-unknown
37-
run: cargo check --target wasm32-unknown-unknown
34+
- name: Cargo check wasm32-wasi
35+
run: cargo check --target wasm32-wasi
3836
- name: Run Tests
3937
run: cargo test
4038
Typescript:
4139
runs-on: ubuntu-latest
4240
steps:
4341
- name: Checkout
44-
uses: actions/checkout@v2
42+
uses: actions/checkout@v3
4543
- name: Install Node
4644
uses: actions/setup-node@v3
4745
with:
48-
node-version: "16"
46+
node-version: "20"
4947
registry-url: "https://registry.npmjs.org"
5048
- name: Cache the Node Modules Directory
5149
uses: actions/cache@v3
5250
with:
5351
path: node_modules
54-
key: ${{ runner.os }}-${{ hashFiles('package.json') }}
52+
key: ${{ runner.os }}-${{ hashFiles('*.json') }}
5553
- name: Install Node Dependencies with NPM
5654
run: npm install
5755
- name: Run Tests

CHANGELOG.md

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88
## [Unreleased]
99

10+
## [v1.1.3] - 2023-09-01
11+
12+
### Features
13+
14+
- Added Durable Errors for Decoders ([#28](https://github.com/loopholelabs/polyglot/pull/28))
15+
1016
## [v1.1.2] - 2023-08-26
1117

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

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

36-
[unreleased]: https://github.com/loopholelabs/scale/compare/v1.1.2...HEAD
42+
[unreleased]: https://github.com/loopholelabs/scale/compare/v1.1.3...HEAD
43+
[v1.1.3]: https://github.com/loopholelabs/scale/compare/v1.1.3
3744
[v1.1.2]: https://github.com/loopholelabs/scale/compare/v1.1.2
3845
[v1.1.1]: https://github.com/loopholelabs/scale/compare/v1.1.1
3946
[v1.1.0]: https://github.com/loopholelabs/scale/compare/v1.1.0

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "polyglot_rs"
3-
version = "1.1.2"
3+
version = "1.1.3"
44
edition = "2021"
55
description="A high-performance serialization framework used for encoding and decoding arbitrary datastructures across languages."
66
license = "Apache-2.0"
@@ -28,7 +28,7 @@ byteorder = "1"
2828
serde = { version = "1.0", features = ["derive"] }
2929
serde_json = "1.0.105"
3030
base64 = "0.21.3"
31-
num_enum = "0.6.1"
31+
num_enum = "0.7.0"
3232

3333
[profile.release]
3434
opt-level = 3

decoder.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,11 @@ pub trait Decoder {
7575

7676
impl Decoder for Cursor<&mut Vec<u8>> {
7777
fn decode_none(&mut self) -> bool {
78-
match self.read_u8() {
79-
Ok(kind) => {
80-
if kind == Kind::None as u8 {
81-
return true;
82-
}
83-
self.set_position(self.position() - 1);
78+
if let Ok(kind) = self.read_u8() {
79+
if kind == Kind::None as u8 {
80+
return true;
8481
}
85-
Err(_) => {}
82+
self.set_position(self.position() - 1);
8683
}
8784
false
8885
}
@@ -331,10 +328,10 @@ mod tests {
331328

332329
let mut decoder = Cursor::new(encoder.get_mut());
333330
let val = decoder.decode_none();
334-
assert_eq!(val, true);
331+
assert!(val);
335332
assert_eq!(decoder.get_ref().len() - decoder.position() as usize, 0);
336333
let next_val = decoder.decode_none();
337-
assert_eq!(next_val, false);
334+
assert!(!next_val);
338335
}
339336

340337
#[test]
@@ -348,7 +345,7 @@ mod tests {
348345
}
349346

350347
let mut decoder = Cursor::new(encoder.get_mut());
351-
let size = decoder.decode_array(Kind::String).unwrap() as usize;
348+
let size = decoder.decode_array(Kind::String).unwrap();
352349
assert_eq!(size, m.len());
353350

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

381378
let mut decoder = Cursor::new(encoder.get_mut());
382-
let size = decoder.decode_map(Kind::String, Kind::U32).unwrap() as usize;
379+
let size = decoder.decode_map(Kind::String, Kind::U32).unwrap();
383380
assert_eq!(size, m.len());
384381

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

441438
let mut decoder = Cursor::new(encoder.get_mut());
442439
let val = decoder.decode_bool().unwrap();
443-
assert_eq!(val, true);
440+
assert!(val);
444441

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

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

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

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

497494
let mut decoder = Cursor::new(encoder.get_mut());
@@ -524,7 +521,7 @@ mod tests {
524521
#[test]
525522
fn test_decode_i64() {
526523
let mut encoder = Cursor::new(Vec::with_capacity(512));
527-
let v = -9223372036854775808 as i64;
524+
let v = -9223372036854775808_i64;
528525
encoder.encode_i64(v).unwrap();
529526

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

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

558555
let mut decoder = Cursor::new(encoder.get_mut());

decoder.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import { Encoder } from "./encoder";
3636
import { Kind } from "./kind";
3737

3838
window.TextEncoder = TextEncoder;
39-
window.TextDecoder = TextDecoder as typeof window["TextDecoder"];
39+
window.TextDecoder = TextDecoder as (typeof window)["TextDecoder"];
4040

4141
describe("Decoder", () => {
4242
it("Can decode Null", () => {
@@ -262,7 +262,7 @@ describe("Decoder", () => {
262262
expect(decoder.length).toBe(0);
263263

264264
expect(() => decoder.map(Kind.String, Kind.Uint32)).toThrowError(
265-
InvalidMapError
265+
InvalidMapError,
266266
);
267267
});
268268

@@ -309,7 +309,7 @@ describe("Decoder", () => {
309309
expect(() => {
310310
const encodedWithMissingStringKind = new Encoder().error(expected).bytes;
311311
const decoderMissingStringKind = new Decoder(
312-
encodedWithMissingStringKind
312+
encodedWithMissingStringKind,
313313
);
314314

315315
encodedWithMissingStringKind[1] = 999999;

0 commit comments

Comments
 (0)