Example #1
0
func main() {
	flag.Parse()

	f, err := vfs.Open(context.Background(), flag.Arg(0))
	if err != nil {
		log.Fatal(err)
	}

	data, err := ioutil.ReadAll(f)
	f.Close()
	if err != nil {
		log.Fatal(err)
	}

	var xa xapb.ExtraActionInfo
	if err := proto.Unmarshal(data, &xa); err != nil {
		log.Fatal(err)
	}

	obj := make(map[string]interface{})
	obj["extra_action_info"] = &xa

	xs, err := proto.GetExtensions(&xa, knownExtensions)
	if err != nil {
		log.Fatal(err)
	}

	var extensions []interface{}
	for _, e := range xs {
		if e != nil {
			extensions = append(extensions, e)
		}
	}

	if len(extensions) > 0 {
		obj["extensions"] = extensions
	}

	if err := json.NewEncoder(os.Stdout).Encode(obj); err != nil {
		log.Fatal(err)
	}

}
Example #2
0
func TestGetExtensionsWithMissingExtensions(t *testing.T) {
	msg := &pb.MyMessage{}
	ext1 := &pb.Ext{}
	if err := proto.SetExtension(msg, pb.E_Ext_More, ext1); err != nil {
		t.Fatalf("Could not set ext1: %s", ext1)
	}
	exts, err := proto.GetExtensions(msg, []*proto.ExtensionDesc{
		pb.E_Ext_More,
		pb.E_Ext_Text,
	})
	if err != nil {
		t.Fatalf("GetExtensions() failed: %s", err)
	}
	if exts[0] != ext1 {
		t.Errorf("ext1 not in returned extensions: %T %v", exts[0], exts[0])
	}
	if exts[1] != nil {
		t.Errorf("ext2 in returned extensions: %T %v", exts[1], exts[1])
	}
}