Decode wraps Codec.Decode and ensure PartitionRingDesc maps are not nil.
(in []byte)
| 19 | |
| 20 | // Decode wraps Codec.Decode and ensure PartitionRingDesc maps are not nil. |
| 21 | func (c *partitionRingCodec) Decode(in []byte) (interface{}, error) { |
| 22 | out, err := c.Codec.Decode(in) |
| 23 | if err != nil { |
| 24 | return out, err |
| 25 | } |
| 26 | |
| 27 | // Ensure maps are initialised. This makes working with PartitionRingDesc more convenient. |
| 28 | if actual, ok := out.(*PartitionRingDesc); ok { |
| 29 | if actual.Partitions == nil { |
| 30 | actual.Partitions = map[int32]PartitionDesc{} |
| 31 | } |
| 32 | if actual.Owners == nil { |
| 33 | actual.Owners = map[string]OwnerDesc{} |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | return out, nil |
| 38 | } |
| 39 | |
| 40 | func GetPartitionRingCodec() codec.Codec { |
| 41 | return &partitionRingCodec{ |