本文整理汇总了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))
}
示例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))
}
}
示例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))
}
}
示例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)
}
示例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)
}
}
}
示例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))
}
示例7: String
func (this *CreateLogoutURLResponse) String() string { return proto.CompactTextString(this) }
示例8: String
func (this *Response) String() string { return proto.CompactTextString(this) }
示例9: String
func (this *ReadKeyValueResponse_KeyValue) String() string { return proto.CompactTextString(this) }