本文整理匯總了Golang中github.com/gogo/protobuf/test.ThetestDescription函數的典型用法代碼示例。如果您正苦於以下問題:Golang ThetestDescription函數的具體用法?Golang ThetestDescription怎麽用?Golang ThetestDescription使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了ThetestDescription函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleCompile
func ExampleCompile() {
a := &test.NinOptNative{
Field4: proto.Int64(1234),
Field7: proto.Int32(123),
}
fp1, err := fieldpath.NewInt64Path("test", "NinOptNative", test.ThetestDescription(), "Field4")
if err != nil {
panic(err)
}
fp2, err := fieldpath.NewSint32Path("test", "NinOptNative", test.ThetestDescription(), "Field7")
if err != nil {
panic(err)
}
buf, err := proto.Marshal(a)
if err != nil {
panic(err)
}
u1 := fieldpath.NewInt64Unmarshaler(fp1, &handler64{})
u2 := fieldpath.NewSint32Unmarshaler(fp2, &handler32{})
c := fieldpath.Compile(u1, u2)
err = c.Unmarshal(buf)
if err != nil {
panic(err)
}
// Output:
// 1234
// 123
}
示例2: TestNoMergeExtensionMerge
func TestNoMergeExtensionMerge(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
bigm := test.NewPopulatedMyExtendable(r, true)
m := test.NewPopulatedNinOptNative(r, true)
err := proto.SetExtension(bigm, test.E_FieldB, m)
if err != nil {
panic(err)
}
data, err := proto.Marshal(bigm)
if err != nil {
panic(err)
}
key := uint32(101)<<3 | uint32(2)
data2 := make([]byte, 10)
n := binary.PutUvarint(data2, uint64(key))
data2 = data2[:n]
data = append(data, data2...)
data4, err := proto.Marshal(test.NewPopulatedNinOptNative(r, true))
if err != nil {
panic(err)
}
data3 := make([]byte, 10)
n = binary.PutUvarint(data3, uint64(len(data4)))
data3 = data3[:n]
data = append(data, data3...)
data = append(data, data4...)
err = fieldpath.NoMerge(data, test.ThetestDescription(), "test", "MyExtendable")
if err == nil || !strings.Contains(err.Error(), "requires merging") {
t.Fatalf("should require merging")
}
}
示例3: TestExtend
func TestExtend(t *testing.T) {
fp, err := fieldpath.NewFloat64Path("test", "MyExtendable", test.ThetestDescription(), "FieldA")
if err != nil {
panic(err)
}
m := &test.MyExtendable{}
err = proto.SetExtension(m, test.E_FieldA, proto.Float64(10.0))
if err != nil {
panic(err)
}
buf, err := proto.Marshal(m)
if err != nil {
panic(err)
}
var unmarshalled float64
f := FuncHandler{
Float64Func: func(v float64) {
t.Logf("unmarshalled %v", v)
unmarshalled = v
},
}
unmarshaler := fieldpath.NewFloat64Unmarshaler(fp, f)
err = unmarshaler.Unmarshal(buf)
if err != nil {
panic(err)
}
if unmarshalled != float64(10.0) {
panic(fmt.Errorf("wtf %v", unmarshalled))
}
}
示例4: TestNewExtended
func TestNewExtended(t *testing.T) {
path := "FieldC.Field1.Field1"
rootPkg := "test"
rootMsg := "MyExtendable"
_, _, err := fieldpath.TestNew(rootPkg, rootMsg, test.ThetestDescription(), path)
if err != nil {
panic(err)
}
}
示例5: TestToMessagesMyExtendableFieldCField1
func TestToMessagesMyExtendableFieldCField1(t *testing.T) {
got, err := fieldpath.ToMessages("test.MyExtendable.FieldC.Field1", test.ThetestDescription())
if err != nil {
panic(err)
}
exp := []string{"test.MyExtendable", "test.NinEmbeddedStruct", "test.NidOptNative"}
if !reflect.DeepEqual(exp, got) {
t.Fatalf("Expected %v got %v", exp, got)
}
}
示例6: TestNoMergeNestedNoMerge
func TestNoMergeNestedNoMerge(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
bigm := test.NewPopulatedNidOptStruct(r, true)
data, err := proto.Marshal(bigm)
if err != nil {
panic(err)
}
err = fieldpath.NoMerge(data, test.ThetestDescription(), "test", "NidOptStruct")
if err != nil {
panic(err)
}
}
示例7: TestNoLatentNoMerge
func TestNoLatentNoMerge(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
m := test.NewPopulatedNinOptNative(r, true)
data, err := proto.Marshal(m)
if err != nil {
panic(err)
}
err = fieldpath.NoLatentAppendingOrMerging(data, test.ThetestDescription(), "test", "NinOptNative")
if err != nil {
panic(err)
}
}
示例8: TestExpandAndCollapseExtendedMessage
func TestExpandAndCollapseExtendedMessage(t *testing.T) {
collapsed := "FieldB.Field1"
expanded := "FieldB.Field1"
rootPkg := "test"
rootMsg := "MyExtendable"
e, err := fieldpath.Expand(rootPkg, rootMsg, collapsed, test.ThetestDescription())
if err != nil {
panic(err)
}
t.Logf("Expanded to %v", e)
if e != expanded {
t.Fatalf("Expected Expanded %v but got %v", expanded, e)
}
c, err := fieldpath.Collapse(rootPkg, rootMsg, expanded, test.ThetestDescription())
if err != nil {
panic(err)
}
t.Logf("Collapsed to %v", c)
if c != collapsed {
t.Fatalf("Expected Collapsed %v but got %v", collapsed, c)
}
}
示例9: TestExpandAndCollapseOneLevel
func TestExpandAndCollapseOneLevel(t *testing.T) {
collapsed := "Field1"
expanded := "Field1.Field1"
rootPkg := "test"
rootMsg := "NinEmbeddedStruct"
e, err := fieldpath.Expand(rootPkg, rootMsg, collapsed, test.ThetestDescription())
if err != nil {
panic(err)
}
t.Logf("Expanded to %v", e)
if e != expanded {
t.Fatalf("Expected Expanded %v but got %v", expanded, e)
}
c, err := fieldpath.Collapse(rootPkg, rootMsg, expanded, test.ThetestDescription())
if err != nil {
panic(err)
}
t.Logf("Collapsed to %v", c)
if c != collapsed {
t.Fatalf("Expected Collapsed %v but got %v", collapsed, c)
}
}
示例10: TestNoMergeMessageMerge
func TestNoMergeMessageMerge(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
bigm := test.NewPopulatedNidOptStruct(r, true)
data, err := proto.Marshal(bigm)
if err != nil {
panic(err)
}
key := byte(uint32(4)<<3 | uint32(2))
data = append(data, key, 5, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
err = fieldpath.NoMerge(data, test.ThetestDescription(), "test", "NidOptStruct")
if err == nil || !strings.Contains(err.Error(), "requires merging") {
panic(err)
}
}
示例11: TestString
func TestString(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
s := test.NewPopulatedNinOptStruct(r, false)
data, err := proto.Marshal(s)
if err != nil {
panic(err)
}
buf := bytes.NewBuffer(nil)
err = fieldpath.ToString("test", "NinOptStruct", test.ThetestDescription(), "", data, 0, os.Stdout)
if err != nil {
panic(err)
}
_ = buf
t.Logf("%v", string(buf.Bytes()))
}
示例12: TestNoMergeMerge
func TestNoMergeMerge(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
m := test.NewPopulatedNinOptNative(r, true)
if m.Field1 == nil {
m.Field1 = proto.Float64(1.1)
}
data, err := proto.Marshal(m)
if err != nil {
panic(err)
}
key := byte(uint32(1)<<3 | uint32(1))
data = append(data, key, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
err = fieldpath.NoMerge(data, test.ThetestDescription(), "test", "NinOptNative")
if err == nil || !strings.Contains(err.Error(), "NinOptNative.Field1 requires merging") {
t.Fatalf("Field1 should require merging")
}
}
示例13: TestNoMergeExtensionNoMerge
func TestNoMergeExtensionNoMerge(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
bigm := test.NewPopulatedMyExtendable(r, true)
m := test.NewPopulatedNinOptNative(r, true)
err := proto.SetExtension(bigm, test.E_FieldB, m)
if err != nil {
panic(err)
}
data, err := proto.Marshal(bigm)
if err != nil {
panic(err)
}
err = fieldpath.NoMerge(data, test.ThetestDescription(), "test", "MyExtendable")
if err != nil {
panic(err)
}
}
示例14: ExampleInt64SinglePath
func ExampleInt64SinglePath() {
a := &test.NinOptNative{
Field4: proto.Int64(1234),
}
fp, err := fieldpath.NewInt64SinglePath("test", "NinOptNative", test.ThetestDescription(), "Field4")
if err != nil {
panic(err)
}
buf, err := proto.Marshal(a)
if err != nil {
panic(err)
}
unmarshalled, err := fp.Unmarshal(buf)
if err != nil {
panic(err)
}
fmt.Printf("%v\n", *unmarshalled)
// Output:
// 1234
}
示例15: TestNoLatentLatent
func TestNoLatentLatent(t *testing.T) {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
m := test.NewPopulatedNinRepNative(r, true)
if m.Field1 == nil {
m.Field1 = []float64{1.1, 1.2}
}
if m.Field2 == nil {
m.Field2 = []float32{1.1, 1.2}
}
data, err := proto.Marshal(m)
if err != nil {
panic(err)
}
key := byte(uint32(1)<<3 | uint32(1))
data = append(data, key, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)))
err = fieldpath.NoLatentAppendingOrMerging(data, test.ThetestDescription(), "test", "NinRepNative")
if err == nil || !strings.Contains(err.Error(), "NinRepNative.Field1") {
t.Fatalf("Field1 should have latent appending")
}
}