當前位置: 首頁>>代碼示例>>Golang>>正文


Golang proto.CompactTextString函數代碼示例

本文整理匯總了Golang中goprotobuf/googlecode/com/hg/proto.CompactTextString函數的典型用法代碼示例。如果您正苦於以下問題:Golang CompactTextString函數的具體用法?Golang CompactTextString怎麽用?Golang CompactTextString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了CompactTextString函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestMarshalUnmarshalBase64

func TestMarshalUnmarshalBase64(t *testing.T) {
	var encbuf []byte
	var decbuf []byte
	t.Logf("start with buf %s\n", proto.CompactTextString(&cr))
	t.Log("marshalling protobuf")
	buf, err := proto.Marshal(&cr)
	if err != nil {
		t.Error("marshal error: ", err)
	}
	t.Log("marshalled")
	t.Log("urlencoding")
	t.Logf("need %d size buffer\n", base64.URLEncoding.EncodedLen(len(buf)-1))
	t.Log(buf)
	t.Logf("%v %s\n", buf, buf)
	encbuf = make([]byte, base64.URLEncoding.EncodedLen(len(buf)), base64.URLEncoding.EncodedLen(len(buf)))
	base64.URLEncoding.Encode(encbuf, buf)
	t.Log("urlencoded")
	t.Log("urldecoding")
	t.Logf("need %d size buffer\n", base64.URLEncoding.DecodedLen(len(encbuf)))
	t.Logf("%v %s\n", encbuf, encbuf)
	decbuf = make([]byte, base64.URLEncoding.DecodedLen(len(encbuf)), base64.URLEncoding.DecodedLen(len(encbuf)))
	n, err := base64.URLEncoding.Decode(decbuf, encbuf)
	t.Logf("wrote %d bytes from encbuf to decbuf. len(encbuf)=%d, len(buf)=%d\n", n, len(encbuf), len(buf))
	if err != nil {
		t.Error("urldecode error: ", err)
	}
	t.Log("urldecoded")

	t.Log(buf, decbuf)
	rcr := &CheckResult{}
	t.Log("unmarshalling")
	err = proto.Unmarshal(decbuf, rcr)
	t.Logf("%s\n", proto.CompactTextString(rcr))
}
開發者ID:pjjw,項目名稱:ncd,代碼行數:34,代碼來源:send_check_test.go

示例2: TestJsonToProto

func TestJsonToProto(t *testing.T) {
	for i, v := range jsonTests {
		ncr := &CheckResult{}
		jsonBytes := []byte(v.json)
		t.Logf("test %d: unmarshalling json to protobuf struct", i)
		err := json.Unmarshal(jsonBytes, ncr)
		if err != nil {
			t.Errorf("test %d: %s", i, err)
		}
		if proto.CompactTextString(ncr) != proto.CompactTextString(v.cr) {
			t.Errorf("test %d: mismatch\noutput:    %s\nexpected: %s", i, ncr, v.cr)
		}
		t.Logf("%s\n", proto.CompactTextString(ncr))
	}
}
開發者ID:pjjw,項目名稱:ncd,代碼行數:15,代碼來源:send_check_test.go

示例3: tryParse

// tryParse attempts to parse the input, and verifies that it matches
// the FileDescriptorProto represented in text format.
func tryParse(t *testing.T, input, output string) {
	expected := new(FileDescriptorProto)
	if err := proto.UnmarshalText(output, expected); err != nil {
		t.Fatalf("Test failure parsing an expected proto: %v", err)
	}

	actual := new(FileDescriptorProto)
	p := newParser(input)
	if pe := p.readFile(actual); pe != nil {
		t.Errorf("Failed parsing input: %v", pe)
		return
	}

	if !reflect.DeepEqual(expected, actual) {
		t.Errorf("Mismatch! Expected:\n%v\nActual\n%v",
			proto.CompactTextString(expected), proto.CompactTextString(actual))
	}
}
開發者ID:welterde,項目名稱:gotoc,代碼行數:20,代碼來源:parser_test.go

示例4: root

func root(w http.ResponseWriter, r *http.Request) {
	// check header
	if *flagPassword != "" && *flagUsername != "" {
		auth, ok := r.Header["Authorization"]
		if ok && strings.HasPrefix(auth[0], "Basic ") {
			str := strings.TrimLeft(auth[0], "Basic ")
			decode, err := base64.StdEncoding.DecodeString(str)
			if err != nil {
				log.Print("cannot decode auth string: ", err)
				return
			}
			user, pass, err := url.UnescapeUserinfo(string(decode))
			if err != nil {
				log.Print("auth: couldn't decode user/pass: ", err)
			}
			if !(user == *flagUsername && pass == *flagPassword) {
				log.Print("auth: wrong user/pass: ", user+"/"+pass, *r)
				return
			}
			/* log.Printf("auth: %#v, user: %s, pass: %s", auth, user, pass)*/
		} else {
			log.Print("auth: no authorization")
			return
		}
	}

	checkpb := new(CheckResultSet)
	if r.Method == "POST" {
		cout := new(bytes.Buffer)
		if _, err := cout.ReadFrom(r.Body); err != nil {
			log.Print("error! ", err)
			return
		}
		switch r.Header["Content-Type"][0] {
		case "application/x-protobuf":
			err := proto.Unmarshal(cout.Bytes(), checkpb)
			if err != nil {
				log.Printf("unmarshalling error: ", err)
			}
		case "application/json", "text/plain", "application/x-www-form-urlencoded", "multipart/form-data":
			err := json.Unmarshal(cout.Bytes(), checkpb)
			if err != nil {
				log.Printf("unmarshalling error: ", err)
			}
		}
		logger.Printf("check returned! %s", proto.CompactTextString(checkpb))
		for _, v := range checkpb.Results {
			_, err := WriteCheck(v, *flagSpoolDir)
			if err != nil {
				logger.Print("writecheck failed: ", err)
			}
		}
	} else {
		/* logger.Printf("NOT POST!! %s", r.Method)*/
	}
	templ.Execute(w, nil)
}
開發者ID:pjjw,項目名稱:ncd,代碼行數:57,代碼來源:ncd.go

示例5: TestParsePerfDataElement

func TestParsePerfDataElement(t *testing.T) {
	for i, v := range petests {
		pd, err := parsePerfDataElement(v.in)
		if err != nil {
			t.Errorf("test %d: parsePerfDataElement returned error: %v", i, err)
		}
		out := proto.CompactTextString(pd)
		if v.out != out {
			t.Errorf("test %d: mismatch:\noutput:   %v\nexpected: %v", i, out, v.out)
		}
	}
}
開發者ID:pjjw,項目名稱:ncd,代碼行數:12,代碼來源:nagios_test.go

示例6: main

func main() {
	p := example.Person{
		Name: proto.String("Taro Yamada"),
		Age:  proto.Int32(8),
	}

	pet := example.Pet{Name: proto.String("Mike")}
	p.Pet = append(p.Pet, &pet)
	fmt.Println("-- p.String()  --")
	fmt.Println(p.String())
	fmt.Println("-- MarshalText --")
	fmt.Print(PrintToString(&p)) // not compact

	fmt.Println("-- Marshal --")
	m, _ := proto.Marshal(&p)
	fmt.Println(m)

	fmt.Println("-- CompactTextString --")
	fmt.Println(proto.CompactTextString(&p))
}
開發者ID:Saikees,項目名稱:practice,代碼行數:20,代碼來源:protobuf.go

示例7: String

func (this *CreateLogoutURLResponse) String() string { return proto.CompactTextString(this) }
開發者ID:sarnowski,項目名稱:google-go-lang-idea-plugin,代碼行數:1,代碼來源:user_service.pb.go

示例8: String

func (this *Response) String() string { return proto.CompactTextString(this) }
開發者ID:sarnowski,項目名稱:google-go-lang-idea-plugin,代碼行數:1,代碼來源:remote_api.pb.go

示例9: String

func (this *ReadKeyValueResponse_KeyValue) String() string { return proto.CompactTextString(this) }
開發者ID:sarnowski,項目名稱:google-go-lang-idea-plugin,代碼行數:1,代碼來源:file_service.pb.go


注:本文中的goprotobuf/googlecode/com/hg/proto.CompactTextString函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。