chore: add protobuf
This commit is contained in:
parent
7ff278e0cf
commit
41aa46ce83
17
Makefile
17
Makefile
@ -1,10 +1,21 @@
|
||||
all: avro flatbuffers protobuf
|
||||
|
||||
avro: twt-avro/gen.go
|
||||
twt-avro/gen.go: lextwt.avro
|
||||
go tool avro gen -pkg twt_avro -encoders lextwt.avro > twt-avro/gen.go
|
||||
|
||||
|
||||
flatbuffers: twt-fbs/gen.go
|
||||
twt-fbs/gen.go: lextwt.fbs
|
||||
flatbuffers: twt-fbs/lextwt
|
||||
twt-fbs/lextwt: lextwt.fbs
|
||||
flatc -o twt-fbs --go lextwt.fbs
|
||||
|
||||
.ALL: avro flatbuffers
|
||||
protobuf: twt-pb/lextwt.pb.go
|
||||
twt-pb/lextwt.pb.go: lextwt.proto
|
||||
protoc --proto_path=. \
|
||||
--plugin=bin/protoc-gen-go \
|
||||
--go_opt=paths=source_relative \
|
||||
--go_opt="Mlextwt.proto=go.sour.is/lextwt-encoding/twt-pb;twt_pb" \
|
||||
--go_out=twt-pb \
|
||||
lextwt.proto
|
||||
|
||||
.PHONY: avro protobuf flatbuffers
|
2
bin/protoc-gen-go
Executable file
2
bin/protoc-gen-go
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
go tool protoc-gen-go $@
|
4
go.mod
4
go.mod
@ -3,6 +3,7 @@ module go.sour.is/lextwt-encoding
|
||||
go 1.24.0
|
||||
|
||||
tool (
|
||||
github.com/SpirentOrion/go-avrogrpc/go-avrogrpc
|
||||
github.com/Zxilly/go-size-analyzer/cmd/gsa
|
||||
github.com/hamba/avro/v2/cmd/avrogen
|
||||
github.com/hamba/avro/v2/cmd/avrosv
|
||||
@ -12,11 +13,14 @@ tool (
|
||||
require github.com/hamba/avro/v2 v2.28.0
|
||||
|
||||
require (
|
||||
github.com/SpirentOrion/go-avrogrpc v0.0.0-20201103153720-fba312c1a9f5 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/ettle/strcase v0.2.0 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/flatbuffers v25.2.10+incompatible // indirect
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/linkedin/goavro/v2 v2.9.8 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/sirupsen/logrus v1.9.3 // indirect
|
||||
github.com/writeas/go-strip-markdown/v2 v2.1.1 // indirect
|
||||
|
55
go.sum
55
go.sum
@ -1,3 +1,7 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/SpirentOrion/go-avrogrpc v0.0.0-20201103153720-fba312c1a9f5 h1:PsBRyCMJTgg3sbFY45O8IpUxnau4s6FMLraOuyeWJNw=
|
||||
github.com/SpirentOrion/go-avrogrpc v0.0.0-20201103153720-fba312c1a9f5/go.mod h1:kIndDKhG+QcIc1PU9oaT7S6BqIRNyMzvQskKj66EpKQ=
|
||||
github.com/Zxilly/go-size-analyzer v1.7.7 h1:z+OwZgSENyR5EYh2Oce3qvDgC/ghEIwL2cf86ilKkJA=
|
||||
github.com/Zxilly/go-size-analyzer v1.7.7/go.mod h1:zanxPHgC5cVqi9D2l3X6Up9cfSePAVFUn8Bnoixf05Y=
|
||||
github.com/ZxillyFork/gore v0.0.0-20250212071411-56f1a74740b2 h1:2H4tzbdntoU7JdP096mOIIk/nLoDF+V1xOCvI5JmBic=
|
||||
@ -14,6 +18,7 @@ github.com/blacktop/go-dwarf v1.0.10 h1:i9zYgcIROETsNZ6V+zZn3uDH21FCG5BLLZ837Git
|
||||
github.com/blacktop/go-dwarf v1.0.10/go.mod h1:4W2FKgSFYcZLDwnR7k+apv5i3nrau4NGl9N6VQ9DSTo=
|
||||
github.com/blacktop/go-macho v1.1.238 h1:OFfT6NB/SWxkoky7L/ytuY8QekgFpa9pmz/GHUQLsmM=
|
||||
github.com/blacktop/go-macho v1.1.238/go.mod h1:dtlW2AJKQpFzImBVPWiUKZ6OxrQ2MLfWi/BPPe0EONE=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
|
||||
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
||||
github.com/charmbracelet/bubbletea v1.3.3 h1:WpU6fCY0J2vDWM3zfS3vIDi/ULq3SYphZhkAGGvmEUY=
|
||||
@ -24,11 +29,16 @@ github.com/charmbracelet/x/ansi v0.8.0 h1:9GTq3xq9caJW8ZrBTe0LIe2fvfLR/bYXKTx2ll
|
||||
github.com/charmbracelet/x/ansi v0.8.0/go.mod h1:wdYl/ONOLHLIVmQaxbIYEC/cRKOQyjTkowiI4blgS9Q=
|
||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
|
||||
github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q=
|
||||
@ -37,12 +47,23 @@ github.com/go-delve/delve v1.24.0 h1:M1auuI7kyfXZm5LMDQEqhqr4koKWOzGKhCgwMxsLQfo
|
||||
github.com/go-delve/delve v1.24.0/go.mod h1:yNWXOuo4yslMOOj7O8gIRrf/trDBrFy5ZXwJL4ZzOos=
|
||||
github.com/go-json-experiment/json v0.0.0-20250213060926-925ba3f173fa h1:Rpu6sKAzIeSWBkrFHD52g8yipagcPbY2Lmm70NL1Gzc=
|
||||
github.com/go-json-experiment/json v0.0.0-20250213060926-925ba3f173fa/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
|
||||
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/flatbuffers v25.2.10+incompatible h1:F3vclr7C3HpB1k9mxCGRMXq6FdUalZ6H/pNX4FP1v0Q=
|
||||
github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hamba/avro v1.8.0 h1:eCVrLX7UYThA3R3yBZ+rpmafA5qTc3ZjpTz6gYJoVGU=
|
||||
github.com/hamba/avro v1.8.0/go.mod h1:NiGUcrLLT+CKfGu5REWQtD9OVPPYUGMVFiC+DE0lQfY=
|
||||
github.com/hamba/avro/v2 v2.28.0 h1:E8J5D27biyAulWKNiEBhV85QPc9xRMCUCGJewS0KYCE=
|
||||
@ -58,6 +79,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/knadh/profiler v0.2.0 h1:jaY0xlQs8iaWxKdvGHOftaZnX7d8l7yrCGQPSecwnng=
|
||||
github.com/knadh/profiler v0.2.0/go.mod h1:LqNkAu++MfFkbEDA63AmRaIf6UkGrLXyZ5VQQdekZiI=
|
||||
github.com/linkedin/goavro/v2 v2.9.8 h1:jN50elxBsGBDGVDEKqUlDuU1cFwJ11K/yrJCBMe/7Wg=
|
||||
github.com/linkedin/goavro/v2 v2.9.8/go.mod h1:UgQUb2N/pmueQYH9bfqFioWxzYCZXSfF8Jw03O5sjqA=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
@ -90,6 +113,7 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmd
|
||||
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
@ -100,6 +124,7 @@ github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
|
||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
||||
@ -116,31 +141,61 @@ go.yarn.social/types v0.0.0-20250108134258-ed75fa653ede h1:XV9tuDQ605xxH4qIQPRHM
|
||||
go.yarn.social/types v0.0.0-20250108134258-ed75fa653ede/go.mod h1:+xnDkQ0T0S8emxWIsvxlCAoyF8gBaj0q81hr/VrKc0c=
|
||||
golang.org/x/arch v0.14.0 h1:z9JUEZWr8x4rR0OU6c4/4t6E6jOZ8/QBS2bBYBm4tx4=
|
||||
golang.org/x/arch v0.14.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
|
||||
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac h1:l5+whBCLH3iH2ZNHYLbAe58bo7yrN4mVcnkHDYz5vvs=
|
||||
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac/go.mod h1:hH+7mtFmImwwcMvScyxUhjuVHR3HGaDPMn9rMSUUbxo=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM=
|
||||
golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
|
||||
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
|
||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
|
||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
|
||||
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
||||
google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM=
|
||||
google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
|
BIN
lextwt-encoding
Executable file
BIN
lextwt-encoding
Executable file
Binary file not shown.
103
lextwt.proto
103
lextwt.proto
@ -1 +1,104 @@
|
||||
syntax = "proto3";
|
||||
option go_package = "go.sour.is/lextwt-proto/pb";
|
||||
|
||||
|
||||
service TwtRegistryService {
|
||||
rpc latestTwts (LatestTwts) returns (TwtRegistry);
|
||||
}
|
||||
|
||||
message LatestTwts {}
|
||||
|
||||
message TwtRegistry {
|
||||
repeated Comment preamble = 1;
|
||||
repeated Twter twters = 2;
|
||||
repeated Twt twts = 3;
|
||||
}
|
||||
|
||||
message BangMention {
|
||||
string name = 1;
|
||||
string target = 2;
|
||||
}
|
||||
|
||||
message Code {
|
||||
enum Type {
|
||||
CODE_UNSPECIFIED = 0;
|
||||
CODE_INLINE = 1;
|
||||
CODE_BLOCK = 2;
|
||||
}
|
||||
|
||||
Type type = 1;
|
||||
string code = 2;
|
||||
}
|
||||
|
||||
message Comment {
|
||||
string comment = 1;
|
||||
string key = 2;
|
||||
string value = 3;
|
||||
}
|
||||
|
||||
message DateTime {
|
||||
int64 timestamp = 1;
|
||||
int32 offset = 2;
|
||||
string zone = 3;
|
||||
}
|
||||
|
||||
message LineSeparator {}
|
||||
|
||||
message Link {
|
||||
enum Type {
|
||||
LINK_UNSPECIFIED = 0;
|
||||
LINK_STANDARD = 1;
|
||||
LINK_MEDIA = 2;
|
||||
LINK_PLAIN = 3;
|
||||
LINK_NAKED = 4;
|
||||
}
|
||||
|
||||
Type type = 1;
|
||||
string alt = 2;
|
||||
string target = 3;
|
||||
string title = 4;
|
||||
}
|
||||
|
||||
message Mention {
|
||||
string name = 1;
|
||||
string target = 2;
|
||||
}
|
||||
|
||||
message Subject {
|
||||
string subject = 1;
|
||||
Tag tag = 2;
|
||||
}
|
||||
|
||||
message Tag {
|
||||
string tag = 1;
|
||||
string target = 2;
|
||||
}
|
||||
|
||||
message Text {
|
||||
string text = 1;
|
||||
}
|
||||
|
||||
message Twter {
|
||||
string nick = 1;
|
||||
string uri = 2;
|
||||
}
|
||||
|
||||
message Elem {
|
||||
oneof elem {
|
||||
BangMention bangmention = 1;
|
||||
Code code = 2;
|
||||
Comment comment = 3;
|
||||
LineSeparator lineseparator = 4;
|
||||
Link link = 5;
|
||||
Mention mention = 6;
|
||||
Subject subject = 7;
|
||||
Tag tag = 8;
|
||||
Text text = 9;
|
||||
};
|
||||
}
|
||||
|
||||
message Twt {
|
||||
Twter twter = 1;
|
||||
DateTime created = 2;
|
||||
repeated Elem msg = 3;
|
||||
}
|
||||
|
16
main.go
16
main.go
@ -11,6 +11,7 @@ import (
|
||||
|
||||
twt_avro "go.sour.is/lextwt-encoding/twt-avro"
|
||||
twt_fbs "go.sour.is/lextwt-encoding/twt-fbs"
|
||||
twt_pb "go.sour.is/lextwt-encoding/twt-pb"
|
||||
)
|
||||
|
||||
type TwtRegistry interface {
|
||||
@ -54,6 +55,12 @@ func main() {
|
||||
if err == nil {
|
||||
registry, err = twt_avro.DecodeRegistry(b)
|
||||
}
|
||||
case "pb":
|
||||
var b []byte
|
||||
b, err = io.ReadAll(in)
|
||||
if err == nil {
|
||||
registry, err = twt_pb.DecodeRegistry(b)
|
||||
}
|
||||
default:
|
||||
log(fmt.Errorf("unknown input format: %q", inputType))
|
||||
return
|
||||
@ -84,6 +91,15 @@ func main() {
|
||||
if err != nil {
|
||||
log(err)
|
||||
}
|
||||
case "pb":
|
||||
b, err := twt_pb.EncodeRegistry(registry)
|
||||
if err != nil {
|
||||
log(err)
|
||||
}
|
||||
_, err = out.Write(b)
|
||||
if err != nil {
|
||||
log(err)
|
||||
}
|
||||
|
||||
default:
|
||||
log(fmt.Errorf("unknown output format: %q", outputType))
|
||||
|
310
twt-pb/helper.go
Normal file
310
twt-pb/helper.go
Normal file
@ -0,0 +1,310 @@
|
||||
package twt_pb
|
||||
|
||||
import (
|
||||
"io"
|
||||
"iter"
|
||||
"slices"
|
||||
"time"
|
||||
|
||||
"go.yarn.social/lextwt"
|
||||
"go.yarn.social/types"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
type twtRegistry interface {
|
||||
Twters() []*types.Twter
|
||||
Preamble() lextwt.Comments
|
||||
Twts() types.Twts
|
||||
WriteTo(w io.Writer) (int64, error)
|
||||
}
|
||||
|
||||
func EncodeRegistry(r twtRegistry) ([]byte, error) {
|
||||
o := &TwtRegistry{}
|
||||
o.FromLextwt(r)
|
||||
|
||||
return proto.Marshal(o)
|
||||
}
|
||||
func DecodeRegistry(b []byte) (twtRegistry, error) {
|
||||
o := &TwtRegistry{}
|
||||
err := proto.Unmarshal(b, o)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return o.ToLextwt(), nil
|
||||
}
|
||||
|
||||
func (r *TwtRegistry) FromLextwt(twt twtRegistry) error {
|
||||
twters := twt.Twters()
|
||||
r.Twters = apply(
|
||||
slices.All(twters),
|
||||
make([]*Twter, len(twters)),
|
||||
fromTwter)
|
||||
|
||||
preamble := twt.Preamble()
|
||||
r.Preamble = apply(
|
||||
slices.All(preamble),
|
||||
make([]*Comment, len(preamble)),
|
||||
fromComment)
|
||||
|
||||
twts := twt.Twts()
|
||||
r.Twts = apply(
|
||||
slices.All(twts),
|
||||
make([]*Twt, len(twts)),
|
||||
fromTwt)
|
||||
|
||||
return nil
|
||||
}
|
||||
func (r *TwtRegistry) ToLextwt() twtRegistry {
|
||||
return lextwt.NewTwtRegistry(
|
||||
apply(slices.All(r.Twters), make([]*types.Twter, len(r.Twters)), func(c *Twter) *types.Twter {
|
||||
return c.ToLextwt()
|
||||
}),
|
||||
apply(slices.All(r.Preamble), make(lextwt.Comments, len(r.Preamble)), func(c *Comment) *lextwt.Comment {
|
||||
return c.ToLextwt()
|
||||
}),
|
||||
apply(slices.All(r.Twts), make(types.Twts, len(r.Twts)), func(c *Twt) types.Twt {
|
||||
return c.ToLextwt()
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
func apply[U, V any](u iter.Seq2[int, U], v []V, fn func(U) V) []V {
|
||||
for i, u := range u {
|
||||
v[i] = fn(u)
|
||||
}
|
||||
return v
|
||||
|
||||
}
|
||||
|
||||
func (e *Twter) FromLextwt(twt *types.Twter) {
|
||||
e.Nick = twt.Nick
|
||||
e.Uri = twt.URI
|
||||
}
|
||||
func fromTwter(twt *types.Twter) *Twter {
|
||||
return &Twter{
|
||||
Nick: twt.Nick,
|
||||
Uri: twt.URI,
|
||||
}
|
||||
}
|
||||
func (e *Twter) ToLextwt() *types.Twter {
|
||||
return &types.Twter{
|
||||
Nick: e.Nick,
|
||||
URI: e.Uri,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Twt) FromLextwt(twt *lextwt.Twt) {
|
||||
twter := twt.Twter()
|
||||
|
||||
e.Twter.FromLextwt(&twter)
|
||||
e.Created = fromDateTime(twt.Created())
|
||||
e.Msg = apply(
|
||||
slices.All(twt.Elems()),
|
||||
make([]*Elem, len(twt.Elems())),
|
||||
fromElem,
|
||||
)
|
||||
}
|
||||
func fromTwt(twt types.Twt) *Twt {
|
||||
twter := twt.Twter()
|
||||
lx, ok := twt.(*lextwt.Twt)
|
||||
if !ok {
|
||||
return &Twt{}
|
||||
}
|
||||
|
||||
msg := lx.Elems()
|
||||
return &Twt{
|
||||
Twter: fromTwter(&twter),
|
||||
Created: fromDateTime(twt.Created()),
|
||||
Msg: apply(
|
||||
slices.All(msg),
|
||||
make([]*Elem, len(msg)),
|
||||
fromElem,
|
||||
),
|
||||
}
|
||||
}
|
||||
func (e *Twt) ToLextwt() *lextwt.Twt {
|
||||
return lextwt.NewTwt(
|
||||
*e.Twter.ToLextwt(),
|
||||
e.Created.ToLextwt(),
|
||||
apply(
|
||||
slices.All(e.Msg),
|
||||
make([]lextwt.Elem, len(e.Msg)),
|
||||
func(e *Elem) lextwt.Elem {
|
||||
return e.ToLextwt()
|
||||
},
|
||||
)...,
|
||||
)
|
||||
}
|
||||
|
||||
func fromDateTime(t time.Time) *DateTime {
|
||||
zone, offset := t.Zone()
|
||||
return &DateTime{
|
||||
Timestamp: t.UnixMicro(),
|
||||
Offset: int32(offset),
|
||||
Zone: zone,
|
||||
}
|
||||
}
|
||||
func (c *DateTime) ToLextwt() *lextwt.DateTime {
|
||||
dt := time.UnixMicro(c.Timestamp)
|
||||
dt = dt.In(time.FixedZone(c.Zone, int(c.Offset)))
|
||||
return lextwt.NewDateTime(dt, dt.Format(time.RFC3339))
|
||||
}
|
||||
|
||||
func fromElem(e lextwt.Elem) *Elem {
|
||||
if e == lextwt.LineSeparator {
|
||||
return &Elem{Elem: &Elem_Lineseparator{fromLineSeparator()}}
|
||||
}
|
||||
|
||||
switch e := e.(type) {
|
||||
case *lextwt.BangMention:
|
||||
return &Elem{Elem: &Elem_Bangmention{fromBangMention(e)}}
|
||||
|
||||
case *lextwt.Code:
|
||||
return &Elem{Elem: &Elem_Code{fromCode(e)}}
|
||||
|
||||
case *lextwt.Comment:
|
||||
return &Elem{Elem: &Elem_Comment{fromComment(e)}}
|
||||
|
||||
case *lextwt.Mention:
|
||||
return &Elem{Elem: &Elem_Mention{fromMention(e)}}
|
||||
|
||||
case *lextwt.Subject:
|
||||
return &Elem{Elem: &Elem_Subject{fromSubject(e)}}
|
||||
|
||||
case *lextwt.Tag:
|
||||
return &Elem{Elem: &Elem_Tag{fromTag(e)}}
|
||||
|
||||
case *lextwt.Link:
|
||||
return &Elem{Elem: &Elem_Link{fromLink(e)}}
|
||||
|
||||
case *lextwt.Text:
|
||||
return &Elem{Elem: &Elem_Text{fromText(e)}}
|
||||
}
|
||||
|
||||
return &Elem{}
|
||||
}
|
||||
func (c *Elem) ToLextwt() lextwt.Elem {
|
||||
switch e := c.Elem.(type) {
|
||||
case *Elem_Bangmention:
|
||||
return e.Bangmention.ToLextwt()
|
||||
case *Elem_Code:
|
||||
return e.Code.ToLextwt()
|
||||
case *Elem_Comment:
|
||||
return e.Comment.ToLextwt()
|
||||
case *Elem_Lineseparator:
|
||||
return e.Lineseparator.ToLextwt()
|
||||
case *Elem_Link:
|
||||
return e.Link.ToLextwt()
|
||||
case *Elem_Mention:
|
||||
return e.Mention.ToLextwt()
|
||||
case *Elem_Subject:
|
||||
return e.Subject.ToLextwt()
|
||||
case *Elem_Tag:
|
||||
return e.Tag.ToLextwt()
|
||||
case *Elem_Text:
|
||||
return e.Text.ToLextwt()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func fromCode(c *lextwt.Code) *Code {
|
||||
return &Code{
|
||||
Type: Code_Type(c.CodeType()),
|
||||
Code: c.Text(),
|
||||
}
|
||||
}
|
||||
func (c *Code) ToLextwt() *lextwt.Code {
|
||||
return lextwt.NewCode(c.Code, lextwt.CodeType(c.Type))
|
||||
}
|
||||
|
||||
func fromComment(c *lextwt.Comment) *Comment {
|
||||
return &Comment{
|
||||
Comment: c.Text(),
|
||||
Key: c.Key(),
|
||||
Value: c.Value(),
|
||||
}
|
||||
}
|
||||
func (c *Comment) ToLextwt() *lextwt.Comment {
|
||||
if c.Key != "" {
|
||||
return lextwt.NewCommentValue(c.Comment, c.Key, c.Value)
|
||||
}
|
||||
return lextwt.NewComment(c.Comment)
|
||||
}
|
||||
|
||||
func fromBangMention(c *lextwt.BangMention) *BangMention {
|
||||
return &BangMention{
|
||||
Name: c.Name(),
|
||||
Target: c.Target(),
|
||||
}
|
||||
}
|
||||
func (c *BangMention) ToLextwt() *lextwt.BangMention {
|
||||
return lextwt.NewBangMention(c.Name, c.Target)
|
||||
}
|
||||
|
||||
func fromMention(c *lextwt.Mention) *Mention {
|
||||
return &Mention{
|
||||
Name: c.Name(),
|
||||
Target: c.Target(),
|
||||
}
|
||||
}
|
||||
func (c *Mention) ToLextwt() *lextwt.Mention {
|
||||
return lextwt.NewMention(c.Name, c.Target)
|
||||
}
|
||||
|
||||
func fromTag(c *lextwt.Tag) *Tag {
|
||||
return &Tag{
|
||||
Tag: c.Text(),
|
||||
Target: c.Target(),
|
||||
}
|
||||
}
|
||||
func (c *Tag) ToLextwt() *lextwt.Tag {
|
||||
return lextwt.NewTag(c.Tag, c.Target)
|
||||
}
|
||||
|
||||
func fromLineSeparator() *LineSeparator {
|
||||
return &LineSeparator{}
|
||||
}
|
||||
func (c *LineSeparator) ToLextwt() lextwt.Elem {
|
||||
return lextwt.LineSeparator
|
||||
}
|
||||
|
||||
func fromLink(c *lextwt.Link) *Link {
|
||||
return &Link{
|
||||
Type: Link_Type(c.LinkType()),
|
||||
Alt: c.Text(),
|
||||
Target: c.Target(),
|
||||
Title: c.Title(),
|
||||
}
|
||||
}
|
||||
func (c *Link) ToLextwt() *lextwt.Link {
|
||||
if c.Type == Link_Type(lextwt.LinkMedia) {
|
||||
return lextwt.NewMedia(c.Alt, c.Target, c.Title)
|
||||
}
|
||||
return lextwt.NewLink(c.Alt, c.Target, lextwt.LinkType(c.Type))
|
||||
}
|
||||
|
||||
func fromSubject(c *lextwt.Subject) *Subject {
|
||||
if tag, ok := c.Tag().(*lextwt.Tag); ok {
|
||||
return &Subject{
|
||||
Tag: fromTag(tag),
|
||||
}
|
||||
}
|
||||
return &Subject{
|
||||
Subject: c.Text(),
|
||||
}
|
||||
}
|
||||
func (c *Subject) ToLextwt() *lextwt.Subject {
|
||||
if c.Tag != nil {
|
||||
return lextwt.NewSubjectTag(c.Tag.Tag, c.Tag.Target)
|
||||
}
|
||||
return lextwt.NewSubject(c.Subject)
|
||||
}
|
||||
|
||||
func fromText(c *lextwt.Text) *Text {
|
||||
return &Text{
|
||||
Text: c.Literal(),
|
||||
}
|
||||
}
|
||||
func (c *Text) ToLextwt() *lextwt.Text {
|
||||
return lextwt.NewText(c.Text)
|
||||
}
|
2
twt-pb/helper_test.go
Normal file
2
twt-pb/helper_test.go
Normal file
@ -0,0 +1,2 @@
|
||||
package twt_pb_test
|
||||
|
1252
twt-pb/lextwt.pb.go
Normal file
1252
twt-pb/lextwt.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user