本文整理匯總了Golang中github.com/gogo/protobuf/proto.MarshalTextString函數的典型用法代碼示例。如果您正苦於以下問題:Golang MarshalTextString函數的具體用法?Golang MarshalTextString怎麽用?Golang MarshalTextString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了MarshalTextString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestUnmarshalNext
func TestUnmarshalNext(t *testing.T) {
// We only need to check against a few, not all of them.
tests := unmarshalingTests[:5]
// Create a buffer with many concatenated JSON objects.
var b bytes.Buffer
for _, tt := range tests {
b.WriteString(tt.json)
}
dec := json.NewDecoder(&b)
for _, tt := range tests {
// Make a new instance of the type of our expected object.
p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message)
err := tt.unmarshaler.UnmarshalNext(dec, p)
if err != nil {
t.Errorf("%s: %v", tt.desc, err)
continue
}
// For easier diffs, compare text strings of the protos.
exp := proto.MarshalTextString(tt.pb)
act := proto.MarshalTextString(p)
if string(exp) != string(act) {
t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp)
}
}
p := &pb.Simple{}
err := new(Unmarshaler).UnmarshalNext(dec, p)
if err != io.EOF {
t.Errorf("eof: got %v, expected io.EOF", err)
}
}
示例2: TestToProtoMultiRoot
func TestToProtoMultiRoot(t *testing.T) {
dir, dir2, _ := populateGraph(t)
defer os.RemoveAll(dir)
defer os.RemoveAll(dir2)
query := `
{
me(anyof("name", "Michonne Rick Glenn")) {
name
}
}
`
gq, _, err := gql.Parse(query)
require.NoError(t, err)
ctx := context.Background()
sg, err := ToSubGraph(ctx, gq)
require.NoError(t, err)
ch := make(chan error)
go ProcessGraph(ctx, sg, nil, ch)
err = <-ch
require.NoError(t, err)
var l Latency
pb, err := sg.ToProtocolBuffer(&l)
require.NoError(t, err)
expectedPb := `attribute: "_root_"
children: <
attribute: "me"
properties: <
prop: "name"
value: <
str_val: "Michonne"
>
>
>
children: <
attribute: "me"
properties: <
prop: "name"
value: <
str_val: "Rick Grimes"
>
>
>
children: <
attribute: "me"
properties: <
prop: "name"
value: <
str_val: "Glenn Rhee"
>
>
>
`
require.EqualValues(t, expectedPb, proto.MarshalTextString(pb))
}
示例3: TestUnmarshaling
func TestUnmarshaling(t *testing.T) {
for _, tt := range unmarshalingTests {
// Make a new instance of the type of our expected object.
p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message)
err := tt.unmarshaler.Unmarshal(strings.NewReader(tt.json), p)
if err != nil {
t.Errorf("%s: %v", tt.desc, err)
continue
}
// For easier diffs, compare text strings of the protos.
exp := proto.MarshalTextString(tt.pb)
act := proto.MarshalTextString(p)
if string(exp) != string(act) {
t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp)
}
}
}
示例4: TestUnmarshalling
func TestUnmarshalling(t *testing.T) {
for _, tt := range unmarshallingTests {
// Make a new instance of the type of our expected object.
p := proto.Clone(tt.pb)
p.Reset()
err := UnmarshalString(tt.json, p)
if err != nil {
t.Error(err)
continue
}
// For easier diffs, compare text strings of the protos.
exp := proto.MarshalTextString(tt.pb)
act := proto.MarshalTextString(p)
if string(exp) != string(act) {
t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp)
}
}
}
示例5: TestToProtoFilterAnd
func TestToProtoFilterAnd(t *testing.T) {
dir, dir2, _ := populateGraph(t)
defer os.RemoveAll(dir)
defer os.RemoveAll(dir2)
// Alright. Now we have everything set up. Let's create the query.
query := `
{
me(_uid_:0x01) {
name
gender
friend @filter(anyof("name", "Andrea") && anyof("name", "Glenn Rhee")) {
name
}
}
}
`
gq, _, err := gql.Parse(query)
require.NoError(t, err)
ctx := context.Background()
sg, err := ToSubGraph(ctx, gq)
require.NoError(t, err)
ch := make(chan error)
go ProcessGraph(ctx, sg, nil, ch)
err = <-ch
require.NoError(t, err)
var l Latency
pb, err := sg.ToProtocolBuffer(&l)
require.NoError(t, err)
expectedPb := `attribute: "_root_"
children: <
attribute: "me"
properties: <
prop: "name"
value: <
str_val: "Michonne"
>
>
properties: <
prop: "gender"
value: <
bytes_val: "female"
>
>
>
`
require.EqualValues(t, expectedPb, proto.MarshalTextString(pb))
}
示例6: TestSizeMessageProtoText
func TestSizeMessageProtoText(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedSizeMessage(popr, true)
data := github_com_gogo_protobuf_proto.MarshalTextString(p)
msg := &SizeMessage{}
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
panic(err)
}
if !p.Equal(msg) {
t.Fatalf("%#v !Proto %#v", msg, p)
}
}
示例7: TestBarProtoText
func TestBarProtoText(t *testing.T) {
seed := time.Now().UnixNano()
popr := math_rand.New(math_rand.NewSource(seed))
p := NewPopulatedBar(popr, true)
data := github_com_gogo_protobuf_proto.MarshalTextString(p)
msg := &Bar{}
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
if !p.Equal(msg) {
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
}
}
示例8: TestRepeatedNonNullableExternalStructProtoText
func TestRepeatedNonNullableExternalStructProtoText(t *testing.T) {
seed := time.Now().UnixNano()
popr := math_rand.New(math_rand.NewSource(seed))
p := NewPopulatedRepeatedNonNullableExternalStruct(popr, true)
dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
msg := &RepeatedNonNullableExternalStruct{}
if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil {
t.Fatalf("seed = %d, err = %v", seed, err)
}
if !p.Equal(msg) {
t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p)
}
}
示例9: TestFloatingPointProtoText
func TestFloatingPointProtoText(t *testing.T) {
popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano()))
p := NewPopulatedFloatingPoint(popr, true)
data := github_com_gogo_protobuf_proto.MarshalTextString(p)
msg := &FloatingPoint{}
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); err != nil {
panic(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 !Proto %#v", msg, p)
}
}
示例10: TestOperation_ExpungeProtoText
func TestOperation_ExpungeProtoText(t *testing16.T) {
popr := math_rand16.New(math_rand16.NewSource(time16.Now().UnixNano()))
p := NewPopulatedOperation_Expunge(popr, true)
data := github_com_gogo_protobuf_proto9.MarshalTextString(p)
msg := &Operation_Expunge{}
if err := github_com_gogo_protobuf_proto9.UnmarshalText(data, msg); err != nil {
panic(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 !Proto %#v", msg, p)
}
}
示例11: TestClearAllExtensions
func TestClearAllExtensions(t *testing.T) {
// unregistered extension
desc := &proto.ExtensionDesc{
ExtendedType: (*pb.MyMessage)(nil),
ExtensionType: (*bool)(nil),
Field: 101010100,
Name: "emptyextension",
Tag: "varint,0,opt",
}
m := &pb.MyMessage{}
if proto.HasExtension(m, desc) {
t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m))
}
if err := proto.SetExtension(m, desc, proto.Bool(true)); err != nil {
t.Errorf("proto.SetExtension(m, desc, true): got error %q, want nil", err)
}
if !proto.HasExtension(m, desc) {
t.Errorf("proto.HasExtension(%s): got false, want true", proto.MarshalTextString(m))
}
proto.ClearAllExtensions(m)
if proto.HasExtension(m, desc) {
t.Errorf("proto.HasExtension(%s): got true, want false", proto.MarshalTextString(m))
}
}
示例12: TestRebalanceCheckResponseProtoText
func TestRebalanceCheckResponseProtoText(t *testing.T) {
seed := time.Now().UnixNano()
popr := math_rand.New(math_rand.NewSource(seed))
p := NewPopulatedRebalanceCheckResponse(popr, true)
data := github_com_gogo_protobuf_proto.MarshalTextString(p)
msg := &RebalanceCheckResponse{}
if err := github_com_gogo_protobuf_proto.UnmarshalText(data, msg); 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 !Proto %#v", seed, msg, p)
}
}
示例13: TestAllMapsOrderedProtoText
func TestAllMapsOrderedProtoText(t *testing.T) {
seed := time.Now().UnixNano()
popr := math_rand.New(math_rand.NewSource(seed))
p := NewPopulatedAllMapsOrdered(popr, true)
dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p)
msg := &AllMapsOrdered{}
if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); 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 !Proto %#v", seed, msg, p)
}
}
示例14: TestRepeatedNilText
func TestRepeatedNilText(t *testing.T) {
m := &pb.MessageList{
Message: []*pb.MessageList_Message{
nil,
{
Name: proto.String("Horse"),
},
nil,
},
}
want := `Message <nil>
Message {
name: "Horse"
}
Message <nil>
`
if s := proto.MarshalTextString(m); s != want {
t.Errorf(" got: %s\nwant: %s", s, want)
}
}
示例15: TestToProtoOrderOffsetCount
// Test sorting / ordering by dob.
func TestToProtoOrderOffsetCount(t *testing.T) {
dir, dir2, _ := populateGraph(t)
defer os.RemoveAll(dir)
defer os.RemoveAll(dir2)
query := `
{
me(_uid_:0x01) {
name
gender
friend(order: dob, first: 2, offset: 1) {
name
}
}
}
`
gq, _, err := gql.Parse(query)
require.NoError(t, err)
ctx := context.Background()
sg, err := ToSubGraph(ctx, gq)
require.NoError(t, err)
ch := make(chan error)
go ProcessGraph(ctx, sg, nil, ch)
err = <-ch
require.NoError(t, err)
var l Latency
pb, err := sg.ToProtocolBuffer(&l)
require.NoError(t, err)
expectedPb := `attribute: "_root_"
children: <
attribute: "me"
properties: <
prop: "name"
value: <
str_val: "Michonne"
>
>
properties: <
prop: "gender"
value: <
bytes_val: "female"
>
>
children: <
attribute: "friend"
properties: <
prop: "name"
value: <
str_val: "Daryl Dixon"
>
>
>
children: <
attribute: "friend"
properties: <
prop: "name"
value: <
str_val: "Glenn Rhee"
>
>
>
>
`
require.EqualValues(t, expectedPb, proto.MarshalTextString(pb))
}