mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-08 05:47:07 +09:00
51 lines
1,012 B
Go
51 lines
1,012 B
Go
//go:build !nogrpcserver && !_test
|
|
// +build !nogrpcserver,!_test
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
"os"
|
|
|
|
"github.com/gogo/protobuf/jsonpb"
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
"github.com/anyproto/anytype-heart/pb"
|
|
|
|
_ "net/http/pprof"
|
|
)
|
|
|
|
func main() {
|
|
if len(os.Args) > 1 {
|
|
for _, path := range os.Args[1:] {
|
|
s, err := decodeFile(path)
|
|
if err != nil {
|
|
fmt.Printf("failed to decode %s: %s\n", path, err)
|
|
continue
|
|
}
|
|
fmt.Println(path + ":")
|
|
fmt.Println(s)
|
|
fmt.Print("\n\n")
|
|
}
|
|
}
|
|
}
|
|
|
|
func decodeFile(path string) (string, error) {
|
|
b, err := ioutil.ReadFile(path)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to read file: %w", err)
|
|
}
|
|
var snapshot pb.ChangeSnapshot
|
|
err = proto.Unmarshal(b, &snapshot)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to unmarshal pb: %w", err)
|
|
}
|
|
marsh := &jsonpb.Marshaler{Indent: " "}
|
|
s, err := marsh.MarshalToString(&snapshot)
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to marshal to json: %w", err)
|
|
}
|
|
|
|
return s, nil
|
|
}
|