fork of indigo with slightly nicer lexgen
1package main
2
3import (
4 "reflect"
5
6 atproto "github.com/bluesky-social/indigo/api/atproto"
7 bsky "github.com/bluesky-social/indigo/api/bsky"
8 chat "github.com/bluesky-social/indigo/api/chat"
9 "github.com/bluesky-social/indigo/atproto/data"
10 "github.com/bluesky-social/indigo/atproto/label"
11 atrepo "github.com/bluesky-social/indigo/atproto/repo"
12 atmst "github.com/bluesky-social/indigo/atproto/repo/mst"
13 "github.com/bluesky-social/indigo/events"
14 lexutil "github.com/bluesky-social/indigo/lex/util"
15 "github.com/bluesky-social/indigo/mst"
16 "github.com/bluesky-social/indigo/plc"
17 "github.com/bluesky-social/indigo/repo"
18 "github.com/bluesky-social/indigo/util/labels"
19
20 cbg "github.com/whyrusleeping/cbor-gen"
21)
22
23func main() {
24 var typVals []any
25 for _, typ := range mst.CBORTypes() {
26 typVals = append(typVals, reflect.New(typ).Elem().Interface())
27 }
28
29 genCfg := cbg.Gen{
30 MaxStringLength: 1_000_000,
31 }
32
33 if err := genCfg.WriteMapEncodersToFile("mst/cbor_gen.go", "mst", typVals...); err != nil {
34 panic(err)
35 }
36
37 if err := genCfg.WriteMapEncodersToFile("repo/cbor_gen.go", "repo", repo.SignedCommit{}, repo.UnsignedCommit{}); err != nil {
38 panic(err)
39 }
40
41 if err := genCfg.WriteMapEncodersToFile("plc/cbor_gen.go", "plc", plc.CreateOp{}); err != nil {
42 panic(err)
43 }
44
45 if err := genCfg.WriteMapEncodersToFile("util/labels/cbor_gen.go", "labels", labels.UnsignedLabel{}); err != nil {
46 panic(err)
47 }
48
49 if err := genCfg.WriteMapEncodersToFile("api/bsky/cbor_gen.go", "bsky",
50 bsky.FeedPost{}, bsky.FeedRepost{}, bsky.FeedPost_Entity{},
51 bsky.FeedPost_ReplyRef{}, bsky.FeedPost_TextSlice{}, bsky.EmbedImages{},
52 bsky.EmbedExternal{}, bsky.EmbedExternal_External{},
53 bsky.EmbedImages_Image{}, bsky.GraphFollow{}, bsky.ActorProfile{},
54 bsky.EmbedRecord{}, bsky.FeedLike{}, bsky.RichtextFacet{},
55 bsky.RichtextFacet_ByteSlice{},
56 bsky.RichtextFacet_Link{}, bsky.RichtextFacet_Mention{}, bsky.RichtextFacet_Tag{},
57 bsky.EmbedRecordWithMedia{},
58 bsky.FeedDefs_NotFoundPost{},
59 bsky.GraphBlock{},
60 bsky.GraphList{},
61 bsky.GraphListitem{},
62 bsky.FeedGenerator{},
63 bsky.GraphListblock{},
64 bsky.EmbedDefs_AspectRatio{},
65 bsky.FeedThreadgate{},
66 bsky.FeedThreadgate_ListRule{},
67 bsky.FeedThreadgate_MentionRule{},
68 bsky.FeedThreadgate_FollowerRule{},
69 bsky.FeedThreadgate_FollowingRule{},
70 bsky.GraphStarterpack_FeedItem{},
71 bsky.GraphStarterpack{},
72 bsky.LabelerService{},
73 bsky.LabelerDefs_LabelerPolicies{},
74 bsky.EmbedVideo{}, bsky.EmbedVideo_Caption{},
75 bsky.FeedPostgate{},
76 bsky.FeedPostgate_DisableRule{},
77 bsky.GraphVerification{},
78 bsky.ActorStatus{},
79 bsky.NotificationDeclaration{},
80 /*bsky.EmbedImages_View{},
81 bsky.EmbedRecord_View{}, bsky.EmbedRecordWithMedia_View{},
82 bsky.EmbedExternal_View{}, bsky.EmbedImages_ViewImage{},
83 bsky.EmbedExternal_ViewExternal{}, bsky.EmbedRecord_ViewNotFound{},
84 bsky.FeedDefs_ThreadViewPost{}, bsky.EmbedRecord_ViewRecord{},
85 bsky.FeedDefs_PostView{}, bsky.ActorDefs_ProfileViewBasic{},
86 */
87 ); err != nil {
88 panic(err)
89 }
90
91 if err := genCfg.WriteMapEncodersToFile("api/chat/cbor_gen.go", "chat",
92 chat.ActorDeclaration{},
93 ); err != nil {
94 panic(err)
95 }
96
97 if err := genCfg.WriteMapEncodersToFile("api/atproto/cbor_gen.go", "atproto",
98 atproto.LexiconSchema{},
99 atproto.RepoStrongRef{},
100 atproto.SyncSubscribeRepos_Commit{},
101 atproto.SyncSubscribeRepos_Sync{},
102 atproto.SyncSubscribeRepos_Identity{},
103 atproto.SyncSubscribeRepos_Account{},
104 atproto.SyncSubscribeRepos_Info{},
105 atproto.SyncSubscribeRepos_RepoOp{},
106 atproto.LabelDefs_SelfLabels{},
107 atproto.LabelDefs_SelfLabel{},
108 atproto.LabelDefs_Label{},
109 atproto.LabelSubscribeLabels_Labels{},
110 atproto.LabelSubscribeLabels_Info{},
111 atproto.LabelDefs_LabelValueDefinition{},
112 atproto.LabelDefs_LabelValueDefinitionStrings{},
113 ); err != nil {
114 panic(err)
115 }
116
117 if err := genCfg.WriteMapEncodersToFile("lex/util/cbor_gen.go", "util", lexutil.CborChecker{}, lexutil.LegacyBlob{}, lexutil.BlobSchema{}); err != nil {
118 panic(err)
119 }
120
121 if err := genCfg.WriteMapEncodersToFile("events/cbor_gen.go", "events", events.EventHeader{}, events.ErrorFrame{}); err != nil {
122 panic(err)
123 }
124
125 if err := genCfg.WriteMapEncodersToFile("atproto/data/cbor_gen.go", "data", data.GenericRecord{}, data.LegacyBlobSchema{}, data.BlobSchema{}); err != nil {
126 panic(err)
127 }
128
129 if err := genCfg.WriteMapEncodersToFile("atproto/repo/cbor_gen.go", "repo", atrepo.Commit{}); err != nil {
130 panic(err)
131 }
132
133 if err := genCfg.WriteMapEncodersToFile("atproto/repo/mst/cbor_gen.go", "mst", atmst.NodeData{}, atmst.EntryData{}); err != nil {
134 panic(err)
135 }
136
137 if err := genCfg.WriteMapEncodersToFile("atproto/label/cbor_gen.go", "label", label.Label{}); err != nil {
138 panic(err)
139 }
140}