Skip to content

Instantly share code, notes, and snippets.

@pandulaDW
Created August 7, 2021 13:09
Show Gist options
  • Save pandulaDW/0797500e2b845128527321e5a05b0bc5 to your computer and use it in GitHub Desktop.
Save pandulaDW/0797500e2b845128527321e5a05b0bc5 to your computer and use it in GitHub Desktop.
the main function
package main
import (
"fmt"
"github.com/pandulaDW/go-json-to-proto/transactions"
"google.golang.org/protobuf/proto"
"log"
"os"
"time"
)
func main() {
start := time.Now()
binFile := "data/encoded.bin"
_ = os.Remove(binFile)
allTransactions := transactions.ReadJsonLines()
err := transactions.WriteProtoToFile(binFile, allTransactions)
if err != nil {
log.Fatal(err)
}
content, err := transactions.ReadProtoFromFile(binFile)
if err != nil {
log.Fatal(err)
}
for _, item := range content {
t := new(transactions.Transaction)
err = proto.Unmarshal(item, t)
if err != nil {
log.Fatal(err)
}
fmt.Printf("t: %s with account id: %d and t_count: %d, with first transaction: %v\n",
t.Id, t.AccountId, t.TransactionCount, t.Transactions[0])
}
fmt.Println("took", time.Since(start))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment