/go-tl-parser

Generates JSON or Go structs/methods of a Telegram .tl file

Primary LanguageGoGNU General Public License v3.0GPL-3.0

go-tl-parser

Generates JSON or Go structs/methods of a Telegram .tl file Adds every single comment (Structs, Struct members, Methods, Method arguments)

Proof of concept

Here is class defined in Type Language:

//@description The message was originally a post in a channel @chat_id Identifier of the chat from which the message was forwarded @author_signature Post author signature
//@date Point in time (Unix timestamp) when the message was originally sent @message_id Message identifier of the original message from which the new message was forwarded; 0 if unknown
//@forwarded_from_chat_id For messages forwarded to the chat with the current user (saved messages), the identifier of the chat from which the message was forwarded; 0 if unknown
//@forwarded_from_message_id For messages forwarded to the chat with the current user (saved messages), the identifier of the original message from which the new message was forwarded; 0 if unknown
messageForwardedPost chat_id:int53 author_signature:string date:int32 message_id:int53 forwarded_from_chat_id:int53 forwarded_from_message_id:int53 = MessageForwardInfo;

Here is the autogenerated go struct:

// MessageForwardedPost The message was originally a post in a channel
type MessageForwardedPost struct {
	tdCommon
	MessageID              int64  `json:"message_id"`                // Message identifier of the original message from which the new message was forwarded; 0 if unknown
	ForwardedFromChatID    int64  `json:"forwarded_from_chat_id"`    // For messages forwarded to the chat with the current user (saved messages), the identifier of the chat from which the message was forwarded; 0 if unknown
	ForwardedFromMessageID int64  `json:"forwarded_from_message_id"` // For messages forwarded to the chat with the current user (saved messages), the identifier of the original message from which the new message was forwarded; 0 if unknown
	ChatID                 int64  `json:"chat_id"`                   // Identifier of the chat from which the message was forwarded
	AuthorSignature        string `json:"author_signature"`          // Post author signature
	Date                   int32  `json:"date"`                      // Point in time (Unix timestamp) when the message was originally sent
}

Usage

Install by running:

$ go get github.com/Arman92/go-tl-parser

Run by:

$ go-tl-parser file=./schema.tl dir=./tdlib package=tdlib structs-file=types.go methods-file=methods.go

This work is used in Telegram Tdlib go binding project, used to generate types and functions from .tl schema file, so you may want to change the code to meet your needs.

Files under tdlib folder are autogenerated (except tdjson.go which is only there for error-free compliation)

Credits for basic c-bindings goes to go-tdjson

Type Language .tl schema for tdlib can be found here