Skip to content
Merged
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
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,13 @@ var database = new TonObject { ClassName = "database" };
database.SetProperty("host", TonValue.From("localhost"));
newDoc.RootObject.AddChild(database);

// Serialize and save
// Serialize - using ToString() for quick serialization with default options
string tonContent = newDoc.ToString();
Console.WriteLine(tonContent);

// Or use TonSerializer for more control
var serializer = new TonSerializer();
string tonContent = serializer.SerializeDocument(newDoc, TonSerializeOptions.Pretty);
string prettyTon = serializer.SerializeDocument(newDoc, TonSerializeOptions.Pretty);
await serializer.SerializeToFileAsync(newDoc, "config.ton", TonSerializeOptions.Pretty);
```
</details>
Expand Down Expand Up @@ -134,9 +138,13 @@ const database = new TonObject('database');
database.setProperty('host', TonValue.from('localhost'));
newDoc.rootObject.addChild(database);

// Serialize and save
// Serialize - using toString() for quick serialization with default options
const tonContent = newDoc.toString();
console.log(tonContent);

// Or use TonSerializer for more control
const serializer = new TonSerializer();
const tonContent = serializer.serializeDocument(newDoc, TonSerializeOptions.Pretty);
const prettyTon = serializer.serializeDocument(newDoc, TonSerializeOptions.Pretty);
await serializer.serializeToFile(newDoc, 'config.ton', TonSerializeOptions.Pretty);
```
</details>
Expand Down Expand Up @@ -165,9 +173,13 @@ database = TonObject(class_name='database')
database.set_property('host', TonValue.from_value('localhost'))
new_doc.root_object.add_child(database)

# Serialize and save
# Serialize - using str() for quick serialization with default options
ton_content = str(new_doc)
print(ton_content)

# Or use TonSerializer for more control
serializer = TonSerializer()
ton_content = serializer.serialize_document(new_doc, TonSerializeOptions.Pretty)
pretty_ton = serializer.serialize_document(new_doc, TonSerializeOptions.Pretty)
await serializer.serialize_to_file(new_doc, 'config.ton', TonSerializeOptions.Pretty)
```
</details>
Expand Down
5 changes: 3 additions & 2 deletions src/CSharp/DevPossible.Ton/DevPossible.Ton.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>DevPossible.Ton</PackageId>
<Version>0.1.6</Version>
<Version>0.1.7</Version>
<Authors>DevPossible, LLC</Authors>
<Company>DevPossible, LLC</Company>
<Product>DevPossible.Ton</Product>
Expand All @@ -27,7 +27,7 @@
<AssemblyCopyright>Copyright © 2024 DevPossible, LLC</AssemblyCopyright>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<PackageVersion>0.1.6</PackageVersion>
<PackageVersion>0.1.7</PackageVersion>

<!-- Contact Information -->
<PackageOwners>DevPossible, LLC</PackageOwners>
Expand All @@ -40,3 +40,4 @@

</Project>


3 changes: 2 additions & 1 deletion src/CSharp/DevPossible.Ton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Install-Package DevPossible.Ton
### Via PackageReference

```xml
<PackageReference Include="DevPossible.Ton" Version="0.1.6" />
<PackageReference Include="DevPossible.Ton" Version="0.1.7" />
```

## Quick Start
Expand Down Expand Up @@ -235,3 +235,4 @@ TON Specification: [tonspec.com](https://tonspec.com)

**© 2024 DevPossible, LLC. All rights reserved.**


12 changes: 11 additions & 1 deletion src/CSharp/DevPossible.Ton/src/Models/TonDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ public static TonDocument FromObject(object obj)
var rootObject = TonObject.FromObject(obj);
return new TonDocument(rootObject);
}

/// <summary>
/// Serializes the document to a TON string using default options
/// </summary>
/// <returns>The serialized TON document</returns>
public override string ToString()
{
var serializer = new TonSerializer();
return serializer.Serialize(this);
}
}

/// <summary>
Expand Down Expand Up @@ -142,4 +152,4 @@ public object? this[string key]
set => Attributes[key] = value;
}
}
}
}
2 changes: 1 addition & 1 deletion src/JavaScript/devpossible-ton/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@devpossible/ton",
"version": "0.1.6",
"version": "0.1.7",
"description": "JavaScript library for parsing, validating, and serializing TON (Text Object Notation) files. Full specification at https://tonspec.com. ALPHA RELEASE: Core functionality is complete but API may change before stable 1.0 release.",
"type": "module",
"main": "dist/index.js",
Expand Down
7 changes: 5 additions & 2 deletions src/JavaScript/devpossible-ton/src/models/TonDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export class TonDocument {
}

public toString(): string {
return JSON.stringify(this.toJSON(), null, 2);
// Import is handled at the top of the file if needed
const { TonSerializer } = require('../serializer/TonSerializer');
const serializer = new TonSerializer();
return serializer.serialize(this);
}

/**
Expand All @@ -160,4 +163,4 @@ export class TonDocument {
}
return new TonDocument(new TonValue(obj));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ def to_json(self) -> Any:
return self.root

def __str__(self) -> str:
"""String representation."""
return json.dumps(self.to_json(), indent=2)
"""String representation - serializes to TON format using default options."""
from ..serializer.ton_serializer import TonSerializer
serializer = TonSerializer()
return serializer.serialize(self)


# Monkey-patch json.dumps to use our encoder by default for TonDocument types
Expand Down
3 changes: 2 additions & 1 deletion src/Python/devpossible_ton/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

setup(
name="devpossible-ton",
version="0.1.6",
version="0.1.7",
author="DevPossible, LLC",
author_email="support@devpossible.com",
description="Python library for parsing, validating, and serializing TON (Text Object Notation) files. Full specification at https://tonspec.com. ALPHA RELEASE: Core functionality is complete but API may change before stable 1.0 release.",
Expand Down Expand Up @@ -66,3 +66,4 @@




2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"library_version": "0.1.6",
"library_version": "0.1.7",
"ton_spec_version": "1.0",
"description": "Centralized version file for all DevPossible.Ton packages. library_version is for the package, ton_spec_version is for the TON file format specification."
}