Skip to content

Commit 0cac7dd

Browse files
committed
Roll back to 0.9.60 and scaffold monorepo
1 parent 813d0f0 commit 0cac7dd

19 files changed

Lines changed: 470 additions & 636 deletions

File tree

.gitignore

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
1-
no_proto_rs/target
1+
.DS_Store
2+
**/.DS_Store
23
**/*.rs.bk
3-
no_proto_rs/Cargo.lock
44
test.json
55

6-
bench/target/**/*
7-
no_proto_js/target/**/*
8-
target/**/*
6+
# Rust
7+
target/
8+
**/target/
9+
no_proto_rs/Cargo.lock
10+
11+
# JavaScript / TypeScript
12+
node_modules/
13+
dist/
14+
coverage/
15+
16+
# PHP
17+
vendor/
18+
composer.lock
19+
20+
# Go
21+
bin/

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[workspace]
2+
members = [
3+
"bench",
4+
"no_proto_js",
5+
"no_proto_rs",
6+
]
7+
resolver = "1"

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
[![crates.io](https://img.shields.io/crates/v/no_proto.svg)](https://crates.io/crates/no_proto)
99
[![docs.rs](https://docs.rs/no_proto/badge.svg)](https://docs.rs/no_proto/latest/no_proto/)
1010
[![GitHub stars](https://img.shields.io/github/stars/only-cliches/NoProto.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/only-cliches/NoProto/stargazers/)
11+
12+
### Monorepo Status
13+
14+
The stable Rust implementation is pinned to `no_proto` `0.9.60`. The experimental `0.10.0` refactor has been abandoned so future work can focus on a language-neutral NoProto specification and compatible implementations.
15+
16+
Repository layout:
17+
18+
- `no_proto_rs/` - stable Rust crate and current reference implementation.
19+
- `no_proto_js/` - existing Rust/WASM JavaScript package.
20+
- `packages/` - home for native language implementations such as JavaScript, PHP, and Go.
21+
- `spec/` - shared NoProto format and schema specification.
22+
- `conformance/` - cross-language compatibility test plan and fixtures.
23+
- `bench/` - Rust benchmark suite.
24+
1125
### Features
1226

1327
**Lightweight**<br/>
@@ -315,4 +329,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
315329
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
316330
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
317331
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
318-
SOFTWARE.
332+
SOFTWARE.

bench/src/run_bench_no_proto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl NoProtoBench {
7575
}
7676

7777
#[inline(always)]
78-
fn get_factory() -> Result<NP_Factory, NP_Error> {
78+
fn get_factory<'get>() -> Result<NP_Factory<'get>, NP_Error> {
7979

8080
// NP_Factory::new_bytes(&SCHEMA)
8181
NP_Factory::new(r#"

conformance/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# NoProto Conformance
2+
3+
This directory is for shared compatibility fixtures used by every language implementation.
4+
5+
The conformance suite should prove that each implementation can parse the same schemas, encode the same values, decode the same buffers, and export the same JSON-compatible data as `no_proto_rs` `0.9.60`.
6+
7+
## Fixture Shape
8+
9+
Use one directory per case:
10+
11+
```text
12+
conformance/cases/<case-name>/
13+
schema.json
14+
schema.idl
15+
input.json
16+
buffer.hex
17+
output.json
18+
```
19+
20+
- `schema.json` is the canonical schema when JSON schema syntax is available.
21+
- `schema.idl` is the IDL form when the case covers IDL parsing.
22+
- `input.json` is the value to encode.
23+
- `buffer.hex` is the canonical encoded buffer as lowercase hexadecimal.
24+
- `output.json` is the expected exported value after decoding.
25+
26+
Language packages should load these fixtures directly instead of duplicating them.

docs/monorepo.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# NoProto Monorepo
2+
3+
NoProto is moving from a single Rust crate repository toward a language implementation monorepo. The Rust crate remains the reference implementation at version `0.9.60` while the shared specification and conformance suite are extracted.
4+
5+
## Layout
6+
7+
- `no_proto_rs/` contains the Rust crate published as `no_proto`.
8+
- `no_proto_js/` contains the existing Rust/WASM JavaScript package.
9+
- `packages/javascript/` is reserved for a native JavaScript or TypeScript implementation.
10+
- `packages/php/` is reserved for a native PHP implementation.
11+
- `packages/go/` is reserved for a native Go implementation.
12+
- `spec/` contains the language-neutral format and schema specification.
13+
- `conformance/` contains shared test vectors and compatibility requirements.
14+
- `bench/` contains the existing Rust benchmark suite.
15+
16+
## Implementation Rules
17+
18+
Every language package should implement the behavior described by `spec/` and validate against `conformance/` before release.
19+
20+
The Rust crate is the compatibility anchor until the specification is complete. If a behavior is not yet documented in `spec/`, match `no_proto_rs` version `0.9.60`.
21+
22+
Language packages should not introduce incompatible buffer, schema, or JSON conversion behavior without first updating the specification and adding conformance coverage.
23+
24+
## Versioning
25+
26+
Package versions should track the NoProto compatibility level they implement. A package that targets the stable Rust crate behavior should start from the `0.9.60` compatibility line, even if its own package ecosystem requires a different release format.

idl.graphql

Lines changed: 0 additions & 118 deletions
This file was deleted.

idl.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// WIP IDL ideas...
2+
3+
// this is a comment
4+
struct({fiels: {
5+
name: string({default: "default value here", size: 20}),
6+
tags: list({of: string()}),
7+
tuple: tuple({sorted: true, values: [string(), string(), string()]}),
8+
map: map({values: string()}),
9+
// another comment
10+
enum: option({default: "red", choices: ["red", "blue", "orange"]}),
11+
p: portal({to: "map"}),
12+
nested: struct({fiels: {
13+
name: string(),
14+
value: u32({default: 20}),
15+
geo: geo({size: 4, default: {lat: 20, lng: 20.28}}),
16+
}})
17+
}});
18+
19+
20+
21+
rpc_spec({
22+
name: "Test API",
23+
author: "hello",
24+
version: "1.0.0",
25+
spec: (self, mod) => {
26+
msg("send_name", struct());
27+
rpc("your_face", fn(self.send_name), option(self.send_name));
28+
rpc("your_face", fn(self.argument), result(self.send_name, self.error));
29+
rpc("your_face", fn(self.argument), empty());
30+
mod("mod_name", (self) => {
31+
32+
});
33+
}
34+
});
35+
36+
struct({
37+
name: string(),
38+
age: u16({default: 0}),
39+
tags: list({of: string()})
40+
});
41+
42+
//! let user_factory = NP_Factory::new(r#"{
43+
//! "type": "struct",
44+
//! "fields": [
45+
//! ["name", {"type": "string"}],
46+
//! ["age", {"type": "u16", "default": 0}],
47+
//! ["tags", {"type": "list", "of": {
48+
//! "type": "string"
49+
//! }}]
50+
//! ]
51+
//! }"#)?;

no_proto_rs/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ keywords = ["protocol-buffers", "grpc", "avro", "database", "json"]
1616
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1717

1818
[features]
19+
np_rpc = []
20+
default = ["np_rpc"]
1921

no_proto_rs/src/hashmap.rs

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,47 +5,47 @@ use crate::error::NP_Error;
55

66
pub static SEED: u32 = 2181155409;
77

8-
#[derive(Debug, Clone)]
9-
pub struct NP_HashMap<V> {
10-
data: Vec<Vec<(u32, V)>>
8+
#[derive(Debug)]
9+
pub struct NP_HashMap {
10+
data: Vec<Vec<(String, usize)>>
1111
}
1212

13-
const HASH_SIZE: usize = 4096;
13+
const HASH_SIZE: usize = 2048;
1414

15-
impl<V> NP_HashMap<V> {
15+
impl NP_HashMap {
1616

1717
pub fn empty() -> Self {
1818
Self { data: Vec::with_capacity(1) }
1919
}
2020

2121
pub fn new() -> Self {
2222
let mut vector = Vec::with_capacity(HASH_SIZE);
23-
vector.extend((0..HASH_SIZE).map(|_| Vec::with_capacity(4)));
23+
vector.extend((0..HASH_SIZE).map(|_| Vec::new()));
2424
Self { data: vector }
2525
}
2626

27-
pub fn insert(&mut self, key: &str, value: V) -> Result<(), NP_Error> {
27+
pub fn insert(&mut self, key: &str, value: usize) -> Result<(), NP_Error> {
2828

2929
let hash = murmurhash3_x86_32(key.as_bytes(), SEED);
3030

3131
let bucket = hash as usize % HASH_SIZE;
3232

3333
if self.data[bucket].len() == 0 {
34-
self.data[bucket].push((hash, value));
34+
self.data[bucket].push((String::from(key), value));
3535
} else {
3636
for (k, v) in self.data[bucket].iter_mut() {
37-
if *k == hash {
37+
if k == key {
3838
*v = value;
3939
return Ok(())
4040
}
4141
}
42-
self.data[bucket].push((hash, value));
42+
self.data[bucket].push((String::from(key), value));
4343
}
4444

4545
Ok(())
4646
}
4747

48-
pub fn get(&self, key: &str) -> Option<&V> {
48+
pub fn get(&self, key: &str) -> Option<&usize> {
4949
let hash = murmurhash3_x86_32(key.as_bytes(), SEED);
5050
let bucket = hash as usize % HASH_SIZE;
5151

@@ -56,14 +56,10 @@ impl<V> NP_HashMap<V> {
5656
return None;
5757
}
5858
if len == 1 {
59-
if x[0].0 == hash {
60-
return Some(&x[0].1);
61-
} else {
62-
return None;
63-
}
59+
return Some(&x[0].1);
6460
}
6561
for (k, v) in x.iter() {
66-
if *k == hash {
62+
if k == key {
6763
return Some(v)
6864
}
6965
}
@@ -78,7 +74,7 @@ impl<V> NP_HashMap<V> {
7874
let bucket = hash as usize % HASH_SIZE;
7975
match self.data.get_mut(bucket) {
8076
Some(bucket) => {
81-
bucket.retain(|(k, _v)| *k != hash);
77+
bucket.retain(|(k, _v)| *k != key);
8278
},
8379
_ => { }
8480
}

0 commit comments

Comments
 (0)