Skip to content

Commit

Permalink
Merge pull request #29 from Cirru/bincode
Browse files Browse the repository at this point in the history
add bincode support
  • Loading branch information
NoEgAm authored Jan 17, 2024
2 parents 2ef8938 + cd57329 commit eb59cce
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Deploy to server
id: deploy
uses: Pendect/action-rsyncer@v1.1.0
uses: Pendect/action-rsyncer@v2.0.0
env:
DEPLOY_KEY: ${{secrets.rsync_private_key}}
with:
Expand Down
28 changes: 27 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cirru_parser"
version = "0.1.25"
version = "0.1.26"
authors = ["jiyinyiyong <[email protected]>"]
edition = "2021"
license = "MIT"
Expand Down Expand Up @@ -30,6 +30,7 @@ use-serde = ["serde", "serde_json"]
[dependencies]
serde = { version = "1.0.147", optional = true }
serde_json = { version = "1.0.87", optional = true }
bincode = "2.0.0-rc.3"

[dev-dependencies]
criterion = "0.4.0"
Expand Down
24 changes: 24 additions & 0 deletions examples/bincode.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use cirru_parser::{format, parse, Cirru, CirruWriterOptions};
use std::fs;

fn main() -> Result<(), String> {
let large_demo = "/Users/chenyong/repo/calcit-lang/editor/compact.cirru";
let content = fs::read_to_string(large_demo).unwrap();

let v = parse(&content)?;

let buf = bincode::encode_to_vec(&v, bincode::config::standard()).map_err(|e| e.to_string())?;

let bin_out = "target/bincode/calcit-info.bin";

fs::write(bin_out, &buf).map_err(|e| e.to_string())?;

let (decoded, _length): (Vec<Cirru>, usize) = bincode::decode_from_slice(&buf[..], bincode::config::standard()).unwrap();

let writer_options = CirruWriterOptions { use_inline: true };
println!("wrote to {}", bin_out);

println!("{}", format(&decoded, writer_options).unwrap());

Ok(())
}
3 changes: 2 additions & 1 deletion src/primes.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bincode::{Decode, Encode};
use std::clone::Clone;
use std::fmt;
use std::hash::Hash;
Expand All @@ -14,7 +15,7 @@ use serde::{
use crate::s_expr;

/// Cirru uses nested Vecters and Strings as data structure
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Decode, Encode)]
pub enum Cirru {
Leaf(Box<str>),
List(Vec<Cirru>),
Expand Down

0 comments on commit eb59cce

Please sign in to comment.