Files
at-container-registry/pkg/atproto/generate.go
T

49 lines
1.3 KiB
Go

//go:build ignore
package main
// CBOR Code Generator
//
// This generates optimized CBOR marshaling code for ATProto records.
//
// Usage:
// go generate ./pkg/atproto/...
//
// This creates pkg/atproto/cbor_gen.go which should be committed to git.
// Only re-run when you modify types in pkg/atproto/types.go
//
// The //go:generate directive is in lexicon.go
import (
"fmt"
"os"
cbg "github.com/whyrusleeping/cbor-gen"
"atcr.io/pkg/atproto"
)
func main() {
// MaxStringLength bumps the package-wide string read limit. cbor-gen v0.3.1
// honors per-field `cborgen:"...,maxlen=N"` tags only on the write side; the
// unmarshal template hard-codes the package default. ImageConfigRecord's
// configJson holds raw OCI image configs that routinely exceed the stock
// 8KB default (deep build histories, verbose created_by lines), so we lift
// the ceiling for everyone. Per-field write caps still apply.
gen := cbg.Gen{MaxStringLength: 1_000_000}
if err := gen.WriteMapEncodersToFile("cbor_gen.go", "atproto",
atproto.CrewRecord{},
atproto.CaptainRecord{},
atproto.LayerRecord{},
atproto.TangledProfileRecord{},
atproto.StatsRecord{},
atproto.DailyStatsRecord{},
atproto.ScanRecord{},
atproto.ImageConfigRecord{},
); err != nil {
fmt.Printf("Failed to generate CBOR encoders: %v\n", err)
os.Exit(1)
}
}