First thanks for you reply.
Because in fact, I have about more than 10 different struct types (maybe
more and more), your suggest is good, this is better
type Info struct{
typeStr string // store the type info to decode IData
IData interface{}
}
But I don't like to send the typeInfo through rpc call(I'm using gob to do
rpc call),maybe there's a better way to do it, just I haven't found it。
在 2017年1月18日星期三 UTC+8上午11:12:05,Felipe Spinolo写道:
>
> Why not just create a wrapper struct? Something like:
>
> type Mixed struct{
> A *A
> B *B
> }
>
> And then just encode/decode that?
>
> On Tuesday, January 17, 2017 at 1:16:37 PM UTC-8, [email protected] wrote:
>>
>> I got two struct types encoded into bytes by gob, I want to decode the
>> bytes into a specific struct, is it possible without try all struct
>> types(maybe 3 or more struct types)?
>>
>> I want to decode bytes without specify which elem in mixedBytes is
>> struct A, and which is struct B.
>> This is the playground url: https://play.golang.org/p/F0Wp5eWdGu
>>
>> Is is possible to implement it by a map or something like this?
>>
>> var typesMap = map[string]reflect.Value{
>> "A": reflect.ValueOf(A{}),
>> "B": reflect.ValueOf(B{}),
>> }
>>
>>
>>
>>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.