本文整理汇总了Golang中github.com/andres-erbsen/protobuf/jsonpb.Marshaler类的典型用法代码示例。如果您正苦于以下问题:Golang Marshaler类的具体用法?Golang Marshaler怎么用?Golang Marshaler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Marshaler类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestFooJSON
func TestFooJSON(t *testing.T) {
seed := time.Now().UnixNano()
popr := math_rand.New(math_rand.NewSource(seed))
p := NewPopulatedFoo(popr, true)
marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
jsondata, err := marshaler.MarshalToString(p)
if err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
msg := &Foo{}
err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
if err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
if !p.Equal(msg) {
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
}
}
开发者ID:andres-erbsen,项目名称:protobuf,代码行数:18,代码来源:protopb_test.go
示例2: TestEncodedAuthorizationPolicyJSON
func TestEncodedAuthorizationPolicyJSON(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedEncodedAuthorizationPolicy(popr, true)
marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
jsondata, err := marshaler.MarshalToString(p)
if err != nil {
t.Fatal(err)
}
msg := &EncodedAuthorizationPolicy{}
err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
if err != nil {
t.Fatal(err)
}
if err := p.VerboseEqual(msg); err != nil {
t.Fatalf("%#v !VerboseProto %#v, since %v", msg, p, err)
}
if !p.Equal(msg) {
t.Fatalf("%#v !Json Equal %#v", msg, p)
}
}
开发者ID:Liamsi,项目名称:coname,代码行数:20,代码来源:AuthorizationPolicypr_test.go
示例3: TestMessageWithMapJSON
func TestMessageWithMapJSON(t *testing.T) {
seed := time.Now().UnixNano()
popr := math_rand.New(math_rand.NewSource(seed))
p := NewPopulatedMessageWithMap(popr, true)
marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{}
jsondata, err := marshaler.MarshalToString(p)
if err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
msg := &MessageWithMap{}
err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg)
if err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
if err := p.VerboseEqual(msg); err != nil {
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
}
if !p.Equal(msg) {
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
}
}
开发者ID:andres-erbsen,项目名称:protobuf,代码行数:21,代码来源:theproto3pb_test.go
示例4: TestEmailProofByClientCertJSON
func TestEmailProofByClientCertJSON(t *testing.T) {
seed := time.Now().UnixNano()
popr := math_rand.New(math_rand.NewSource(seed))
p := NewPopulatedEmailProofByClientCert(popr, true)
marshaler := github_com_andres_erbsen_protobuf_jsonpb.Marshaler{}
jsondata, err := marshaler.MarshalToString(p)
if err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
msg := &EmailProofByClientCert{}
err = github_com_andres_erbsen_protobuf_jsonpb.UnmarshalString(jsondata, msg)
if err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
if err := p.VerboseEqual(msg); err != nil {
t.Fatalf("seed = %d, %#v !VerboseProto %#v, since %v", seed, msg, p, err)
}
if !p.Equal(msg) {
t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p)
}
}
开发者ID:andres-erbsen,项目名称:coname-mit,代码行数:21,代码来源:keyserverconfigpb_test.go
示例5: ServeHTTP
func (h *HTTPFront) ServeHTTP(w http.ResponseWriter, r *http.Request) {
path := r.URL.Path
userid, err := auth(r)
if err != nil {
http.Error(w, err.Error(), http.StatusUnauthorized)
return
}
if r.Method != "POST" || (path != "/lookup" && path != "/update") {
http.Error(w, `this server only supports queries of the POST /lookup or POST /update`, http.StatusNotFound)
return
}
pf := &proto.LookupProof{}
ctx := context.Background()
if path == "/lookup" {
pf, err = h.doLookup(r.Body, ctx)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
} else if path == "/update" {
pf, err = h.doUpdate(r.Body, ctx, userid)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
}
marshaler := jsonpb.Marshaler{}
err = marshaler.Marshal(w, pf)
if err != nil {
http.Error(w, `Internal server error`, http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
return
}
开发者ID:Liamsi,项目名称:coname,代码行数:38,代码来源:httpfront.go
注:本文中的github.com/andres-erbsen/protobuf/jsonpb.Marshaler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论