Created
August 7, 2021 13:09
-
-
Save pandulaDW/0797500e2b845128527321e5a05b0bc5 to your computer and use it in GitHub Desktop.
the main function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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