Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: tl refac #791

Closed
wants to merge 3 commits into from
Closed
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
15 changes: 12 additions & 3 deletions 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,7 +1,8 @@
[workspace]
resolver = "2"
members = [
"tl_parser",
"tl-parser",
"tl-core",
"tonlibjson-sys",
"tonlibjson-client",
"ton-grpc",
Expand Down
4 changes: 0 additions & 4 deletions adnl-tcp/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
pub mod packet;
pub mod client;
pub mod ping;
pub mod types;
pub mod serializer;
pub mod deserializer;
pub mod boxed;
mod codec;
mod key;
12 changes: 12 additions & 0 deletions tl-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "tl-core"
version = "0.1.0"
edition = "2021"
authors = ["Andrei Kostylev <[email protected]>"]
license = "MIT"
repository = "https://github.com/getgems-io/ton-grpc"
description = "A toolset for Telegram Type Language"

[dependencies]
anyhow = { workspace = true }
bytes = "1.6.0"
File renamed without changes.
5 changes: 2 additions & 3 deletions adnl-tcp/src/deserializer.rs → tl-core/src/deserializer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::bail;
use bytes::{Buf, Bytes};
use crate::types::Int256;

pub trait Deserialize where Self: Sized {
fn deserialize(de: &mut Deserializer) -> anyhow::Result<Self>;
Expand Down Expand Up @@ -49,15 +48,15 @@ impl Deserializer {
Ok(self.input.get_i64_le())
}

pub fn parse_i256(&mut self) -> anyhow::Result<Int256> {
pub fn parse_i256(&mut self) -> anyhow::Result<[u8; 32]> {
let mut needed = self.input.split_to(32);
let mut result: [u8; 32] = [0; 32];
needed.copy_to_slice(&mut result);

Ok(result)
}

pub fn parse_bytes(&mut self) -> anyhow::Result<crate::types::Bytes> {
pub fn parse_bytes(&mut self) -> anyhow::Result<Vec<u8>> {
let len = self.input.get_u8();
if len <= 253 {
let mut needed = self.input.split_to(len as usize);
Expand Down
4 changes: 4 additions & 0 deletions tl-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod serializer;
pub mod deserializer;
pub mod types;
pub mod boxed;
3 changes: 1 addition & 2 deletions adnl-tcp/src/serializer.rs → tl-core/src/serializer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::fmt::Debug;
use bytes::BufMut;
use crate::types::{Int256};

pub trait Serialize {
fn serialize(&self, se: &mut Serializer);
Expand Down Expand Up @@ -32,7 +31,7 @@ impl Serializer {
self.output.put_i64_le(val)
}

pub fn write_i256(&mut self, val: &Int256) {
pub fn write_i256(&mut self, val: &[u8; 32]) {
self.output.put_slice(val)
}

Expand Down
2 changes: 1 addition & 1 deletion adnl-tcp/src/types.rs → tl-core/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::boxed::Boxed;
use crate::deserializer::{Deserialize, Deserializer};
use crate::serializer::{Serialize, Serializer};
use crate::boxed::Boxed;

pub trait Functional {
type Result;
Expand Down
5 changes: 4 additions & 1 deletion tl_parser/Cargo.toml → tl-parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
[package]
name = "tl_parser"
name = "tl-parser"
version = "0.1.0"
edition = "2021"
authors = ["Andrei Kostylev <[email protected]>"]
license = "MIT"
repository = "https://github.com/getgems-io/ton-grpc"
description = "A parser for Telegram Type Language"

[dependencies]
anyhow = { workspace = true }
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion ton-liteserver-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[build-dependencies]
tl_parser = { path = "../tl_parser" }
tl-parser = { path = "../tl-parser" }
anyhow = { workspace = true }
quote = "1.0"
syn = "2.0.58"
Expand All @@ -13,6 +13,7 @@ convert_case = "0.6.0"

[dependencies]
adnl-tcp = { path = "../adnl-tcp" }
tl-core = { path = "../tl-core" }
anyhow = { workspace = true }
tokio = { workspace = true }
tower = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion ton-liteserver-client/examples/playground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::net::{Ipv4Addr, SocketAddrV4};
use base64::Engine;
use tower::ServiceExt;
use adnl_tcp::client::ServerKey;
use adnl_tcp::types::BareType;
use tl_core::types::BareType;
use ton_liteserver_client::client::LiteServerClient;
use ton_liteserver_client::tl::{LiteServerGetMasterchainInfo, LiteServerListBlockTransactions, LiteServerLookupBlock, TonNodeBlockId, True};

Expand Down
2 changes: 1 addition & 1 deletion ton-liteserver-client/examples/tower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use base64::Engine;
use futures::{stream, StreamExt};
use tower::{ServiceBuilder, ServiceExt};
use adnl_tcp::client::ServerKey;
use adnl_tcp::types::BareType;
use tl_core::types::BareType;
use ton_liteserver_client::client::LiteServerClient;
use ton_liteserver_client::tl::{LiteServerGetMasterchainInfo, LiteServerLookupBlock, TonNodeBlockId};

Expand Down
8 changes: 4 additions & 4 deletions ton-liteserver-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ use thiserror::Error;
use tokio::sync::mpsc::UnboundedSender;
use tokio::sync::oneshot::Receiver;
use tokio::time::MissedTickBehavior;
use adnl_tcp::boxed::Boxed;
use adnl_tcp::types::{BareType, BoxedType};
use adnl_tcp::packet::Packet;
use adnl_tcp::ping::{is_pong_packet, ping_packet};
use adnl_tcp::deserializer::{Deserialize, from_bytes};
use adnl_tcp::serializer::to_bytes;
use tl_core::boxed::Boxed;
use tl_core::types::{BareType, BoxedType};
use tl_core::deserializer::{Deserialize, from_bytes};
use tl_core::serializer::to_bytes;
use crate::request::Requestable;
use crate::tl::{AdnlMessageAnswer, AdnlMessageQuery, Bytes, Int256, LiteServerError, LiteServerQuery};

Expand Down
6 changes: 3 additions & 3 deletions ton-liteserver-client/src/request.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use adnl_tcp::deserializer::Deserialize;
use adnl_tcp::serializer::Serialize;
use adnl_tcp::types::Functional;
use tl_core::deserializer::Deserialize;
use tl_core::serializer::Serialize;
use tl_core::types::Functional;

pub trait Requestable: Serialize + Send {
type Response: Deserialize + Send + 'static;
Expand Down
14 changes: 7 additions & 7 deletions ton-liteserver-client/src/tl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

use std::fmt::{Debug, Display, Formatter};
use anyhow::anyhow;
use adnl_tcp::deserializer::{Deserialize, Deserializer};
use adnl_tcp::serializer::{Serialize, Serializer};
use adnl_tcp::boxed::Boxed;
pub use adnl_tcp::types::*;
use tl_core::deserializer::{Deserialize, Deserializer};
use tl_core::serializer::{Serialize, Serializer};
use tl_core::boxed::Boxed;
pub use tl_core::types::*;

include!(concat!(env!("OUT_DIR"), "/generated.rs"));

Expand All @@ -23,9 +23,9 @@ impl std::error::Error for LiteServerError {
#[cfg(test)]
mod tests {
use base64::Engine;
use adnl_tcp::boxed::Boxed;
use adnl_tcp::deserializer::from_bytes;
use adnl_tcp::serializer::to_bytes;
use tl_core::boxed::Boxed;
use tl_core::deserializer::from_bytes;
use tl_core::serializer::to_bytes;
use super::*;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tonlibjson-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ tracing-test = { workspace = true }
serial_test = "3.0.0"

[build-dependencies]
tl_parser = { path = "../tl_parser" }
tl-parser = { path = "../tl-parser" }
anyhow = { workspace = true }
quote = "1.0"
syn = "2.0.60"
Expand Down
Loading