File tree Expand file tree Collapse file tree
src/EcoFlow.Proto.Decoder Expand file tree Collapse file tree Original file line number Diff line number Diff line change 66 <Project Path =" src/EcoFlow.Mqtt.Api/EcoFlow.Mqtt.Api.csproj" />
77 <Project Path =" src/EcoFlow.Proto.Exporter/EcoFlow.Proto.Exporter.csproj" />
88 </Folder >
9+ <Folder Name =" /src/EcoFlow.Proto.Decoder/" />
910</Solution >
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "os"
5+ "path/filepath"
6+
7+ "google.golang.org/protobuf/proto"
8+ "google.golang.org/protobuf/types/descriptorpb"
9+
10+ "github.com/jhump/protoreflect/desc"
11+ "github.com/jhump/protoreflect/desc/protoprint"
12+ )
13+
14+ func main () {
15+ if len (os .Args ) != 3 {
16+ os .Stderr .WriteString ("usage: decoder <file_descriptor_set.pb> <out_directory>\n " )
17+ os .Exit (2 )
18+ }
19+
20+ descriptorSetPath := os .Args [1 ]
21+ outputDirectoryPath := os .Args [2 ]
22+
23+ descriptorSetBytes , readError := os .ReadFile (descriptorSetPath )
24+ if readError != nil {
25+ panic (readError )
26+ }
27+
28+ var fileDescriptorSet descriptorpb.FileDescriptorSet
29+ if unmarshalError := proto .Unmarshal (descriptorSetBytes , & fileDescriptorSet ); unmarshalError != nil {
30+ panic (unmarshalError )
31+ }
32+
33+ fileDescriptors , buildError := desc .CreateFileDescriptorsFromSet (& fileDescriptorSet )
34+ if buildError != nil {
35+ panic (buildError )
36+ }
37+
38+ protoPrinter := protoprint.Printer {}
39+
40+ for _ , fileDescriptor := range fileDescriptors {
41+ outputFilePath := filepath .Join (outputDirectoryPath , fileDescriptor .GetName ())
42+ if mkdirError := os .MkdirAll (filepath .Dir (outputFilePath ), 0o755 ); mkdirError != nil {
43+ panic (mkdirError )
44+ }
45+
46+ outputFile , createError := os .Create (outputFilePath )
47+ if createError != nil {
48+ panic (createError )
49+ }
50+
51+ printError := protoPrinter .PrintProtoFile (fileDescriptor , outputFile )
52+ closeError := outputFile .Close ()
53+ if printError != nil {
54+ panic (printError )
55+ }
56+ if closeError != nil {
57+ panic (closeError )
58+ }
59+ }
60+ }
Original file line number Diff line number Diff line change 1+ module decoder
2+
3+ go 1.25.6
4+
5+ require (
6+ github.com/golang/protobuf v1.5.4 // indirect
7+ github.com/jhump/protoreflect v1.18.0 // indirect
8+ github.com/jhump/protoreflect/v2 v2.0.0-beta.1 // indirect
9+ google.golang.org/protobuf v1.36.11 // indirect
10+ )
Original file line number Diff line number Diff line change 1+ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek =
2+ github.com/golang/protobuf v1.5.4 /go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps =
3+ github.com/jhump/protoreflect v1.18.0 h1:TOz0MSR/0JOZ5kECB/0ufGnC2jdsgZ123Rd/k4Z5/2w =
4+ github.com/jhump/protoreflect v1.18.0 /go.mod h1:ezWcltJIVF4zYdIFM+D/sHV4Oh5LNU08ORzCGfwvTz8 =
5+ github.com/jhump/protoreflect/v2 v2.0.0-beta.1 h1:Dw1rslK/VotaUGYsv53XVWITr+5RCPXfvvlGrM/+B6w =
6+ github.com/jhump/protoreflect/v2 v2.0.0-beta.1 /go.mod h1:D9LBEowZyv8/iSu97FU2zmXG3JxVTmNw21mu63niFzU =
7+ google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE =
8+ google.golang.org/protobuf v1.36.11 /go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco =
You can’t perform that action at this time.
0 commit comments