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

Rust TL-B serialization #874

Closed
DevNebulaX opened this issue Nov 18, 2024 · 2 comments
Closed

Rust TL-B serialization #874

DevNebulaX opened this issue Nov 18, 2024 · 2 comments
Labels
Developer Tool Related to tools or utilities used by developers

Comments

@DevNebulaX
Copy link

Summary

TL-B serialization is a fundamental component of the TON blockchain, enabling the encoding and decoding of data structures in a compact, efficient, and schema-based binary format. To provide Rust developers with seamless support for this critical feature, we propose developing a TL-B serialization library in Rust. This library will allow developers to work with TL-B schemas directly in their Rust applications, enhancing the capabilities of TON-based tools and services.

Context

The TL-B (Type Language - Binary) format is widely used within the TON blockchain for serializing and deserializing data structures, such as messages, cells, and state data. While other programming languages have partial implementations or utilities for TL-B serialization, Rust lacks a comprehensive and developer-friendly library tailored for this purpose. By creating a dedicated TL-B serialization library in Rust, we can empower developers to build efficient and reliable applications in the TON ecosystem. Key features of the proposed library include:
• Support for defining and parsing TL-B schemas directly in Rust.
• Serialization and deserialization of TL-B data structures into binary format.
• Bit-level data manipulation for precise TL-B compliance.
• Recursive structure handling for complex TL-B schemas.
• Error handling to ensure data integrity and conformity with TL-B specifications.
• Integration with existing TON blockchain tools, such as tonlibjson, for seamless workflows.

Suppose we have a simple TL-B schema:
use std::io::{self, Read, Write};

// Example struct matching the TL-B schema
struct User {
text: String,
age: i32,
}

// Serialization
impl User {
fn serialize(&self, writer: &mut impl Write) -> io::Result<()> {
// Serialize the text as a string (length-prefixed, for example)
let text_bytes = self.text.as_bytes();
let length = text_bytes.len() as u32;
writer.write_all(&length.to_be_bytes())?;
writer.write_all(text_bytes)?;

    // Serialize the age as a 32-bit integer
    writer.write_all(&self.age.to_be_bytes())?;
    Ok(())
}

// Deserialization
fn deserialize(reader: &mut impl Read) -> io::Result<Self> {
    // Read the text length
    let mut length_bytes = [0u8; 4];
    reader.read_exact(&mut length_bytes)?;
    let length = u32::from_be_bytes(length_bytes);

    // Read the text
    let mut text_bytes = vec![0u8; length as usize];
    reader.read_exact(&mut text_bytes)?;

    // Read the age
    let mut age_bytes = [0u8; 4];
    reader.read_exact(&mut age_bytes)?;
    let age = i32::from_be_bytes(age_bytes);

    Ok(Self {
        text: String::from_utf8(text_bytes).unwrap(),
        age,
    })
}

}

References

Develop a Rust library that implements TL-B serialization, enabling developers to encode, decode, and manipulate TL-B data structures effortlessly within Rust applications.

Estimate suggested reward

$5,000 USD in TON equivalent

@DevNebulaX DevNebulaX added the Developer Tool Related to tools or utilities used by developers label Nov 18, 2024
@ProgramCrafter
Copy link
Contributor

Please visit #444 also.

Speaking of improvements, I'd like infallible (and preferably non-panicking) store functions; they seem more optimal. They could be implemented as in https://gist.github.com/ProgramCrafter/c79293307b7df0740b87ae244072a4d3.

@delovoyhomie
Copy link
Collaborator

Thank you for your submission. After careful review, we regret to inform you that we cannot proceed with your application at this time, as a Rust SDK has already been implemented as part of the Bounty program (see bounty #182).

@delovoyhomie delovoyhomie closed this as not planned Won't fix, can't repro, duplicate, stale Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Developer Tool Related to tools or utilities used by developers
Projects
None yet
Development

No branches or pull requests

3 participants