writer.go 528 B

1234567891011121314151617181920212223242526272829303132
  1. package main
  2. import (
  3. "github.com/golang/protobuf/proto"
  4. "io/ioutil"
  5. pb "maps"
  6. )
  7. func main() {
  8. message := pb.MapTest{}
  9. message.Name = "hello"
  10. message.Properties = map[string]string{
  11. "A": "AAAAAAAAAAAAAAAA",
  12. "B": "BBBBBBBBBBBBBBBB",
  13. "C": "CCCCCCCCCCCCCCCC",
  14. }
  15. message.IntegerProperties = map[int32]int32 {
  16. 1 : 100,
  17. 2 : 200,
  18. 3 : 300,
  19. 4 : 400,
  20. }
  21. data, err := proto.Marshal(&message)
  22. if err != nil {
  23. panic(err)
  24. }
  25. err = ioutil.WriteFile("maptest.bin", data, 0644)
  26. if err != nil {
  27. panic(err)
  28. }
  29. }