本文整理汇总了Golang中go/uber/org/thriftrw/wire.NewValueString函数的典型用法代码示例。如果您正苦于以下问题:Golang NewValueString函数的具体用法?Golang NewValueString怎么用?Golang NewValueString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewValueString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestUnionFromWireInconsistencies
func TestUnionFromWireInconsistencies(t *testing.T) {
tests := []struct {
desc string
input wire.Value
success *tu.Document
failure string
}{
{
desc: "multiple recognized fields",
input: wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 1, Value: wire.NewValueBinary([]byte{1, 2, 3})},
{ID: 2, Value: wire.NewValueString("hello")},
}}),
failure: "should have exactly one field: got 2 fields",
},
{
desc: "recognized and unrecognized fields",
input: wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 1, Value: wire.NewValueBinary([]byte{1, 2, 3})},
{ID: 3, Value: wire.NewValueString("hello")},
}}),
success: &tu.Document{Pdf: []byte{1, 2, 3}},
},
{
desc: "recognized field duplicates",
input: wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 1, Value: wire.NewValueBinary([]byte{1, 2, 3})},
{ID: 1, Value: wire.NewValueBinary([]byte{4, 5, 6})},
}}),
success: &tu.Document{Pdf: []byte{4, 5, 6}},
},
{
desc: "only unrecognized fields",
input: wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 2, Value: wire.NewValueI32(42)}, // also a type mismatch
{ID: 3, Value: wire.NewValueString("hello")},
}}),
failure: "should have exactly one field: got 0 fields",
},
{
desc: "no fields",
input: wire.NewValueStruct(wire.Struct{}),
failure: "should have exactly one field: got 0 fields",
},
}
for _, tt := range tests {
var o tu.Document
err := o.FromWire(tt.input)
if tt.success != nil {
if assert.NoError(t, err, tt.desc) {
assert.Equal(t, tt.success, &o, tt.desc)
}
} else {
if assert.Error(t, err, tt.desc) {
assert.Contains(t, err.Error(), tt.failure, tt.desc)
}
}
}
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:60,代码来源:struct_test.go
示例2: ToWire
func (v *KeyValue_SetValue_Args) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
if v.Key != nil {
w, err = wire.NewValueString(*(v.Key)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
if v.Value != nil {
w, err = wire.NewValueString(*(v.Value)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 2, Value: w}
i++
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:25,代码来源:keyvalue_setvalue.go
示例3: ToWire
func (v *ThriftTest_TestMultiException_Args) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
if v.Arg0 != nil {
w, err = wire.NewValueString(*(v.Arg0)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
if v.Arg1 != nil {
w, err = wire.NewValueString(*(v.Arg1)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 2, Value: w}
i++
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:25,代码来源:thrifttest_testmultiexception.go
示例4: ToWire
func (v *Function) ToWire() (wire.Value, error) {
var (
fields [6]wire.Field
i int = 0
w wire.Value
err error
)
w, err = wire.NewValueString(v.Name), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
w, err = wire.NewValueString(v.ThriftName), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 2, Value: w}
i++
if v.Arguments == nil {
return w, errors.New("field Arguments of Function is required")
}
w, err = wire.NewValueList(_List_Argument_ValueList(v.Arguments)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 3, Value: w}
i++
if v.ReturnType != nil {
w, err = v.ReturnType.ToWire()
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 4, Value: w}
i++
}
if v.Exceptions != nil {
w, err = wire.NewValueList(_List_Argument_ValueList(v.Exceptions)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 5, Value: w}
i++
}
if v.OneWay != nil {
w, err = wire.NewValueBool(*(v.OneWay)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 6, Value: w}
i++
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:54,代码来源:types.go
示例5: ToWire
func (v *PrimitiveRequiredStruct) ToWire() (wire.Value, error) {
var (
fields [8]wire.Field
i int = 0
w wire.Value
err error
)
w, err = wire.NewValueBool(v.BoolField), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
w, err = wire.NewValueI8(v.ByteField), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 2, Value: w}
i++
w, err = wire.NewValueI16(v.Int16Field), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 3, Value: w}
i++
w, err = wire.NewValueI32(v.Int32Field), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 4, Value: w}
i++
w, err = wire.NewValueI64(v.Int64Field), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 5, Value: w}
i++
w, err = wire.NewValueDouble(v.DoubleField), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 6, Value: w}
i++
w, err = wire.NewValueString(v.StringField), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 7, Value: w}
i++
if v.BinaryField == nil {
return w, errors.New("field BinaryField of PrimitiveRequiredStruct is required")
}
w, err = wire.NewValueBinary(v.BinaryField), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 8, Value: w}
i++
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:60,代码来源:types.go
示例6: ToWire
func (v *KeyValue_GetValue_Result) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
if v.Success != nil {
w, err = wire.NewValueString(*(v.Success)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 0, Value: w}
i++
}
if v.DoesNotExist != nil {
w, err = v.DoesNotExist.ToWire()
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
if i != 1 {
return wire.Value{}, fmt.Errorf("KeyValue_GetValue_Result should have exactly one field: got %v fields", i)
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:28,代码来源:keyvalue_getvalue.go
示例7: ToWire
func (v *TApplicationException) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
if v.Message != nil {
w, err = wire.NewValueString(*(v.Message)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
if v.Type != nil {
w, err = v.Type.ToWire()
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 2, Value: w}
i++
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:25,代码来源:types.go
示例8: TestStructFromWireUnrecognizedField
func TestStructFromWireUnrecognizedField(t *testing.T) {
tests := []struct {
desc string
give wire.Value
want ts.ContactInfo
wantError string
}{
{
desc: "unknown field",
give: wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 1, Value: wire.NewValueString("foo")},
{ID: 2, Value: wire.NewValueI32(42)},
}}),
want: ts.ContactInfo{EmailAddress: "foo"},
},
{
desc: "only unknown field",
give: wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 2, Value: wire.NewValueString("bar")},
}}),
wantError: "field EmailAddress of ContactInfo is required",
},
{
desc: "wrong type for recognized field",
give: wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 1, Value: wire.NewValueI32(42)},
{ID: 1, Value: wire.NewValueString("foo")},
}}),
want: ts.ContactInfo{EmailAddress: "foo"},
},
}
for _, tt := range tests {
var o ts.ContactInfo
err := o.FromWire(tt.give)
if tt.wantError != "" {
if assert.Error(t, err, tt.desc) {
assert.Contains(t, err.Error(), tt.wantError)
}
} else {
if assert.NoError(t, err, tt.desc) {
assert.Equal(t, tt.want, o)
}
}
}
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:47,代码来源:struct_test.go
示例9: ForEach
func (m _Map_String_String_MapItemList) ForEach(f func(wire.MapItem) error) error {
for k, v := range m {
kw, err := wire.NewValueString(k), error(nil)
if err != nil {
return err
}
vw, err := wire.NewValueString(v), error(nil)
if err != nil {
return err
}
err = f(wire.MapItem{Key: kw, Value: vw})
if err != nil {
return err
}
}
return nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:17,代码来源:types.go
示例10: TestTypedefString
func TestTypedefString(t *testing.T) {
tests := []struct {
x td.State
v wire.Value
}{
{
td.State("hello"),
wire.NewValueString("hello"),
},
{
td.State("world"),
wire.NewValueString("world"),
},
}
for _, tt := range tests {
assertRoundTrip(t, &tt.x, tt.v, "State")
}
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:19,代码来源:typedef_test.go
示例11: ToWire
func (v *Pong) ToWire() (wire.Value, error) {
var (
fields [1]wire.Field
i int = 0
w wire.Value
err error
)
w, err = wire.NewValueString(v.Boop), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:15,代码来源:types.go
示例12: ToWire
func (v *ThriftTest_TestString_Args) ToWire() (wire.Value, error) {
var (
fields [1]wire.Field
i int = 0
w wire.Value
err error
)
if v.Thing != nil {
w, err = wire.NewValueString(*(v.Thing)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:17,代码来源:thrifttest_teststring.go
示例13: ToWire
func (v *Oneway_Echo_Args) ToWire() (wire.Value, error) {
var (
fields [1]wire.Field
i int = 0
w wire.Value
err error
)
if v.Token != nil {
w, err = wire.NewValueString(*(v.Token)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:17,代码来源:oneway_echo.go
示例14: TestBasicException
func TestBasicException(t *testing.T) {
tests := []struct {
s tx.DoesNotExistException
v wire.Value
}{
{
tx.DoesNotExistException{Key: "foo"},
wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 1, Value: wire.NewValueString("foo")},
}}),
},
}
for _, tt := range tests {
assertRoundTrip(t, &tt.s, tt.v, "DoesNotExistException")
err := error(&tt.s) // should implement the error interface
assert.Equal(t, "DoesNotExistException{Key: foo}", err.Error())
}
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:20,代码来源:struct_test.go
示例15: ToWire
func (v *EchoResponse) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
w, err = wire.NewValueString(v.Message), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
w, err = wire.NewValueI16(v.Count), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 2, Value: w}
i++
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:21,代码来源:types.go
注:本文中的go/uber/org/thriftrw/wire.NewValueString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论