(cctx *Context, typ super.Type)
| 35 | } |
| 36 | |
| 37 | func NewEncoder(cctx *Context, typ super.Type) Encoder { |
| 38 | switch typ := typ.(type) { |
| 39 | case *super.TypeNamed: |
| 40 | return &NamedEncoder{NewEncoder(cctx, typ.Type), typ.Name} |
| 41 | case *super.TypeError: |
| 42 | return &ErrorEncoder{NewEncoder(cctx, typ.Type)} |
| 43 | case *super.TypeRecord: |
| 44 | return NewRecordEncoder(cctx, typ) |
| 45 | case *super.TypeArray: |
| 46 | return NewArrayEncoder(cctx, typ) |
| 47 | case *super.TypeSet: |
| 48 | // Sets encode the same way as arrays but behave |
| 49 | // differently semantically, and we don't care here. |
| 50 | return NewSetEncoder(cctx, typ) |
| 51 | case *super.TypeMap: |
| 52 | return NewMapEncoder(cctx, typ) |
| 53 | case *super.TypeUnion: |
| 54 | return NewUnionEncoder(cctx, typ) |
| 55 | case *super.TypeFusion: |
| 56 | return NewFusionEncoder(cctx, typ) |
| 57 | case *super.TypeEnum: |
| 58 | return NewPrimitiveEncoder(typ) |
| 59 | default: |
| 60 | if !super.IsPrimitiveType(typ) { |
| 61 | panic(fmt.Sprintf("unsupported type in CSUP file: %T", typ)) |
| 62 | } |
| 63 | return NewDictEncoder(typ, NewPrimitiveEncoder(typ)) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | func NewPrimitiveEncoder(typ super.Type) PrimitiveEncoder { |
| 68 | switch id := typ.ID(); { |
no test coverage detected