本文整理汇总了Golang中go/uber/org/thriftrw/wire.NewValueStruct函数的典型用法代码示例。如果您正苦于以下问题:Golang NewValueStruct函数的具体用法?Golang NewValueStruct怎么用?Golang NewValueStruct使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewValueStruct函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: TestClient
func TestClient(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
mockClient := envelopetest.NewMockClient(mockCtrl)
mockClient.EXPECT().Send("Foo:hello", wire.NewValueStruct(wire.Struct{})).
Return(wire.NewValueStruct(wire.Struct{}), nil)
client := NewClient("Foo", mockClient)
_, err := client.Send("hello", wire.NewValueStruct(wire.Struct{}))
assert.NoError(t, err)
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:12,代码来源:client_test.go
示例3: TestHandlerErrors
func TestHandlerErrors(t *testing.T) {
tests := []struct {
name string
expect func(meta, kv *envelopetest.MockHandler)
wantError error
}{
{
name: "Meta:health",
expect: func(meta, kv *envelopetest.MockHandler) {
meta.EXPECT().Handle("health", gomock.Any()).
Return(wire.NewValueStruct(wire.Struct{}), nil)
},
},
{
name: "KeyValue:setValue",
expect: func(meta, kv *envelopetest.MockHandler) {
kv.EXPECT().Handle("setValue", gomock.Any()).
Return(wire.NewValueStruct(wire.Struct{}), nil)
},
},
{
name: "keyValue:setValue",
wantError: envelope.ErrUnknownMethod("keyValue:setValue"),
},
{
name: "setValue",
wantError: envelope.ErrUnknownMethod("setValue"),
},
}
for _, tt := range tests {
func() {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
meta := envelopetest.NewMockHandler(mockCtrl)
kv := envelopetest.NewMockHandler(mockCtrl)
handler := NewHandler()
handler.Put("Meta", meta)
handler.Put("KeyValue", kv)
if tt.expect != nil {
tt.expect(meta, kv)
}
_, err := handler.Handle(tt.name, wire.NewValueStruct(wire.Struct{}))
assert.Equal(t, tt.wantError, err)
}()
}
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:51,代码来源:handler_test.go
示例4: ToWire
func (v *TypePair) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
if v.Left == nil {
return w, errors.New("field Left of TypePair is required")
}
w, err = v.Left.ToWire()
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
if v.Right == nil {
return w, errors.New("field Right of TypePair is required")
}
w, err = v.Right.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,代码行数:27,代码来源:types.go
示例5: ToWire
func (v *Plugin_Goodbye_Result) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:7,代码来源:plugin_goodbye.go
示例6: ToWire
func (v *SecondService_BlahBlah_Result) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:7,代码来源:secondservice_blahblah.go
示例7: 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
示例8: ToWire
func (v *ThriftTest_TestVoid_Result) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:7,代码来源:thrifttest_testvoid.go
示例9: ToWire
func (v *MapOfBinaryAndString) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
if v.BinaryToString != nil {
w, err = wire.NewValueMap(_Map_Binary_String_MapItemList(v.BinaryToString)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
if v.StringToBinary != nil {
w, err = wire.NewValueMap(_Map_String_Binary_MapItemList(v.StringToBinary)), 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:thriftrw,项目名称:thriftrw-go,代码行数:25,代码来源:types.go
示例10: ToWire
func (v *NonStandardServiceName_NonStandardFunctionName_Result) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:7,代码来源:non_standard_service_name_non_standard_function_name.go
示例11: ToWire
func (v *KeyValue_DeleteValue_Result) ToWire() (wire.Value, error) {
var (
fields [2]wire.Field
i int = 0
w wire.Value
err error
)
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 v.InternalError != nil {
w, err = v.InternalError.ToWire()
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 2, Value: w}
i++
}
if i > 1 {
return wire.Value{}, fmt.Errorf("KeyValue_DeleteValue_Result should have at most one field: got %v fields", i)
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:28,代码来源:keyvalue_deletevalue.go
示例12: 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
示例13: ToWire
func (v *Cache_Clear_Args) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
开发者ID:thriftrw,项目名称:thriftrw-go,代码行数:7,代码来源:cache_clear.go
示例14: 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 = v.Key.ToWire()
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 1, Value: w}
i++
}
if v.Value != nil {
w, err = v.Value.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,代码来源:keyvalue_setvalue.go
示例15: 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 = v.Success.ToWire()
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:thriftrw,项目名称:thriftrw-go,代码行数:28,代码来源:keyvalue_getvalue.go
示例16: 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
示例17: TestDisableEnveloperEncode
func TestDisableEnveloperEncode(t *testing.T) {
rand := rand.New(rand.NewSource(time.Now().Unix()))
tests := []struct {
value wire.Value
want []byte
}{
{
wire.NewValueStruct(wire.Struct{Fields: []wire.Field{}}),
[]byte{0x00},
},
{
wire.NewValueStruct(wire.Struct{Fields: []wire.Field{
{ID: 1, Value: wire.NewValueI32(42)},
}}),
[]byte{
0x08, 0x00, 0x01,
0x00, 0x00, 0x00, 0x2a,
0x00,
},
},
}
for _, tt := range tests {
e := wire.Envelope{Value: tt.value, Type: wire.Call}
generate(&e.Name, rand)
generate(&e.SeqID, rand)
var buffer bytes.Buffer
proto := disableEnvelopingProtocol{protocol.Binary, wire.Reply}
if !assert.NoError(t, proto.EncodeEnveloped(e, &buffer)) {
continue
}
assert.Equal(t, tt.want, buffer.Bytes())
gotE, err := proto.DecodeEnveloped(bytes.NewReader(tt.want))
if !assert.NoError(t, err) {
continue
}
assert.Equal(t, wire.Reply, gotE.Type)
assert.True(t, wire.ValuesAreEqual(tt.value, gotE.Value))
}
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:45,代码来源:envelope_test.go
注:本文中的go/uber/org/thriftrw/wire.NewValueStruct函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论