Skip to content

Commit

Permalink
feat(dltl): add header to downladed schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed Dec 23, 2020
1 parent 39a5715 commit 2e34df2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions _schema/telegram.tl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Code generated by ./cmd/dltl, DO NOT EDIT.
//
// Source: https://raw.githubusercontent.com/telegramdesktop/tdesktop/dev/Telegram/Resources/tl/api.tl
// Layer: 122
// SHA256: 4b2e953d778fb0bf3f3cdd4c659396cc247df949a3d01dca916948909196a1ef

boolFalse#bc799737 = Bool;

boolTrue#997275b5 = Bool;
Expand Down
19 changes: 18 additions & 1 deletion cmd/dltl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
package main

import (
"crypto/sha256"
"flag"
"fmt"
"io"
"net/http"
"net/url"
"os"
"path"
"strings"

"github.com/gotd/tl"
)
Expand Down Expand Up @@ -40,7 +42,8 @@ func main() {
}

// Parsing in-place.
s, err := tl.Parse(res.Body)
h := sha256.New()
s, err := tl.Parse(io.TeeReader(res.Body, h))
if err != nil {
panic(err)
}
Expand All @@ -59,6 +62,20 @@ func main() {
outWriter = w
}

// Writing header to avoid manual edit.
var b strings.Builder
b.WriteString("// Code generated by ./cmd/dltl, DO NOT EDIT.\n")
b.WriteString("//\n")
b.WriteString(fmt.Sprintf("// Source: %s\n", u))
if s.Layer > 0 {
b.WriteString(fmt.Sprintf("// Layer: %d\n", s.Layer))
}
b.WriteString(fmt.Sprintf("// SHA256: %x\n", h.Sum(nil)))
b.WriteRune('\n')
if _, err := io.WriteString(outWriter, b.String()); err != nil {
panic(err)
}

if _, err := s.WriteTo(outWriter); err != nil {
panic(err)
}
Expand Down

0 comments on commit 2e34df2

Please sign in to comment.