dagost/aton-format
Composer 安装命令:
composer require dagost/aton-format
包简介
ATON - Adaptive Token-Oriented Notation. A token-efficient data serialization format for LLM applications.
README 文档
README
ATON is a token-efficient data serialization format designed specifically for LLM applications. It reduces token usage by up to 55% compared to JSON while maintaining perfect data fidelity.
V2 Features
- Compression Modes: FAST, BALANCED, ULTRA, ADAPTIVE
- Query Language: SQL-like syntax with full AST parser
- Streaming Encoder: Process large datasets in chunks
- Dictionary Compression: Automatic string deduplication
- Full PHP 8 Support: Enums, named arguments, typed properties
- Zero Dependencies: Lightweight and fast
Installation
composer require dagost/aton-format
Quick Start
<?php use Aton\ATON; use Aton\Enums\CompressionMode; // Simple encode/decode $data = [ 'employees' => [ ['id' => 1, 'name' => 'Alice', 'role' => 'Engineer', 'active' => true], ['id' => 2, 'name' => 'Bob', 'role' => 'Designer', 'active' => true], ['id' => 3, 'name' => 'Carol', 'role' => 'Manager', 'active' => true], ] ]; $atonText = ATON::encode($data); echo $atonText; // Output: // @schema[id:int, name:str, role:str, active:bool] // @defaults[active:true] // // employees(3): // 1, "Alice", "Engineer" // 2, "Bob", "Designer" // 3, "Carol", "Manager" // Decode back $original = ATON::decode($atonText);
Compression Modes
use Aton\Encoder; use Aton\Enums\CompressionMode; // Fast: No dictionary compression, fastest encoding $fast = new Encoder(compression: CompressionMode::FAST); // Balanced: Good compression with reasonable speed (default) $balanced = new Encoder(compression: CompressionMode::BALANCED); // Ultra: Maximum compression, best for large datasets $ultra = new Encoder(compression: CompressionMode::ULTRA); // Adaptive: Automatically selects mode based on data size $adaptive = new Encoder(compression: CompressionMode::ADAPTIVE);
Query Language
ATON supports SQL-like queries for filtering data:
use Aton\ATON; use Aton\QueryEngine; $data = [ 'products' => [ ['id' => 1, 'name' => 'Laptop', 'price' => 999, 'category' => 'Electronics'], ['id' => 2, 'name' => 'Mouse', 'price' => 29, 'category' => 'Electronics'], ['id' => 3, 'name' => 'Desk', 'price' => 299, 'category' => 'Furniture'], ] ]; // Parse and execute query $queryEngine = ATON::createQueryEngine(); $query = $queryEngine->parse("products WHERE price > 100 ORDER BY price DESC LIMIT 10"); $results = $queryEngine->execute($data, $query); // Or encode with query directly $filteredAton = ATON::encodeWithQuery($data, "products WHERE category = 'Electronics'");
Query Syntax
-- Basic filtering products WHERE price > 100 -- Multiple conditions products WHERE price > 100 AND category = 'Electronics' -- OR conditions products WHERE category = 'Electronics' OR category = 'Furniture' -- IN operator products WHERE category IN ('Electronics', 'Furniture') -- LIKE operator (pattern matching) products WHERE name LIKE '%Laptop%' -- BETWEEN products WHERE price BETWEEN 100 AND 500 -- Sorting and pagination products WHERE active = true ORDER BY price DESC LIMIT 10 OFFSET 5 -- Select specific fields products SELECT id, name WHERE price > 100
Streaming Encoder
For large datasets, use the streaming encoder:
use Aton\StreamEncoder; use Aton\Enums\CompressionMode; $streamEncoder = new StreamEncoder( chunkSize: 100, compression: CompressionMode::BALANCED ); $largeData = [ 'records' => array_map( fn($i) => ['id' => $i, 'name' => "Record $i", 'value' => rand()], range(1, 10000) ) ]; // Process in chunks foreach ($streamEncoder->streamEncode($largeData) as $chunk) { echo "Chunk {$chunk['chunkId']}/{$chunk['totalChunks']}\n"; echo "Progress: " . ($chunk['metadata']['progress'] * 100) . "%\n"; // Process chunk data sendToAPI($chunk['data']); }
Compression Statistics
use Aton\ATON; $stats = ATON::getCompressionStats($data); echo "Original tokens: {$stats['originalTokens']}\n"; echo "Compressed tokens: {$stats['compressedTokens']}\n"; echo "Savings: {$stats['savingsPercent']}%\n"; echo "Compression ratio: {$stats['compressionRatio']}\n";
API Reference
ATON Facade
ATON::encode(array $data, bool $compress = true, CompressionMode $compression = CompressionMode::BALANCED): string ATON::decode(string $atonString): array ATON::encodeWithQuery(array $data, string $queryString): string ATON::getCompressionStats(array $data, CompressionMode $compression = CompressionMode::BALANCED): array ATON::createEncoder(...): Encoder ATON::createDecoder(...): Decoder ATON::createStreamEncoder(...): StreamEncoder ATON::createQueryEngine(): QueryEngine
Encoder Class
$encoder = new Encoder( optimize: true, // Enable schema and defaults optimization compression: CompressionMode::BALANCED, // Compression mode queryable: false, // Add queryable markers validate: true // Validate input data ); $encoder->encode($data, $compress); // Encode to ATON $encoder->encodeWithQuery($data, $query); // Encode with query filter $encoder->estimateTokens($text); // Estimate token count $encoder->getCompressionStats($data); // Get compression stats
Decoder Class
$decoder = new Decoder(validate: true); $decoder->decode($atonString); // Decode ATON to array
QueryEngine Class
$queryEngine = new QueryEngine(); $query = $queryEngine->parse($queryString); // Parse query to AST $results = $queryEngine->execute($data, $query); // Execute query
StreamEncoder Class
$streamEncoder = new StreamEncoder( chunkSize: 100, compression: CompressionMode::BALANCED ); foreach ($streamEncoder->streamEncode($data, $tableName) as $chunk) { // Process chunk }
Exceptions
use Aton\Exceptions\ATONException; use Aton\Exceptions\ATONEncodingException; use Aton\Exceptions\ATONDecodingException; use Aton\Exceptions\ATONQueryException; try { $aton = ATON::encode($data); } catch (ATONEncodingException $e) { echo "Encoding error: " . $e->getMessage(); }
ATON Format Specification
Basic Structure
@dict[#0:"repeated string", #1:"another string"]
@schema[field1:type1, field2:type2, ...]
@defaults[field1:value1, field2:value2, ...]
entityName(count):
value1, value2, ...
value1, value2, ...
Supported Types
| Type | Description | Example |
|---|---|---|
int |
Integer | 42 |
float |
Floating point | 3.14 |
str |
String | "hello" |
bool |
Boolean | true, false |
null |
Null value | null |
array |
Array | [1,2,3] |
object |
Object | {key:value} |
Performance
| Dataset | JSON Tokens | ATON Tokens | Reduction |
|---|---|---|---|
| Employee Records (1K) | 12,450 | 5,280 | 57.6% |
| Product Catalog (10K) | 145,200 | 64,800 | 55.4% |
| Transaction Log (100K) | 1,856,000 | 815,000 | 56.1% |
Requirements
- PHP 8.0 or higher
Links
License
MIT License - see LICENSE for details.
Author
Stefano D'Agostino
- GitHub: @dagoSte
- Email: dago.stefano@gmail.com
dagost/aton-format 适用场景与选型建议
dagost/aton-format 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 11 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「json」 「compression」 「serialization」 「token」 「ai」 「gpt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dagost/aton-format 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dagost/aton-format 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dagost/aton-format 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fork of jms/serializer 1.14.1 with support for modern PHP versions.
Asset Management for PHP
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Kinikit - PHP Application development framework MVC component
De/normalize business objects without tightly coupling them to your normalization format
ext-json wrapper with sane defaults
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 30
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-24