| 1 | // Copyright 2021 The Go Authors. All rights reserved. |
|---|---|
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package pkgbits |
| 6 | |
| 7 | // A Code is an enum value that can be encoded into bitstreams. |
| 8 | // |
| 9 | // Code types are preferable for enum types, because they allow |
| 10 | // Decoder to detect desyncs. |
| 11 | type Code interface { |
| 12 | // Marker returns the SyncMarker for the Code's dynamic type. |
| 13 | Marker() SyncMarker |
| 14 | |
| 15 | // Value returns the Code's ordinal value. |
| 16 | Value() int |
| 17 | } |
| 18 | |
| 19 | // A CodeVal distinguishes among go/constant.Value encodings. |
| 20 | type CodeVal int |
| 21 | |
| 22 | func (c CodeVal) Marker() SyncMarker { return SyncVal } |
| 23 | func (c CodeVal) Value() int { return int(c) } |
| 24 | |
| 25 | // Note: These values are public and cannot be changed without |
| 26 | // updating the go/types importers. |
| 27 | |
| 28 | const ( |
| 29 | ValBool CodeVal = iota |
| 30 | ValString |
| 31 | ValInt64 |
| 32 | ValBigInt |
| 33 | ValBigRat |
| 34 | ValBigFloat |
| 35 | ) |
| 36 | |
| 37 | // A CodeType distinguishes among go/types.Type encodings. |
| 38 | type CodeType int |
| 39 | |
| 40 | func (c CodeType) Marker() SyncMarker { return SyncType } |
| 41 | func (c CodeType) Value() int { return int(c) } |
| 42 | |
| 43 | // Note: These values are public and cannot be changed without |
| 44 | // updating the go/types importers. |
| 45 | |
| 46 | const ( |
| 47 | TypeBasic CodeType = iota |
| 48 | TypeNamed |
| 49 | TypePointer |
| 50 | TypeSlice |
| 51 | TypeArray |
| 52 | TypeChan |
| 53 | TypeMap |
| 54 | TypeSignature |
| 55 | TypeStruct |
| 56 | TypeInterface |
| 57 | TypeUnion |
| 58 | TypeTypeParam |
| 59 | ) |
| 60 | |
| 61 | // A CodeObj distinguishes among go/types.Object encodings. |
| 62 | type CodeObj int |
| 63 | |
| 64 | func (c CodeObj) Marker() SyncMarker { return SyncCodeObj } |
| 65 | func (c CodeObj) Value() int { return int(c) } |
| 66 | |
| 67 | // Note: These values are public and cannot be changed without |
| 68 | // updating the go/types importers. |
| 69 | |
| 70 | const ( |
| 71 | ObjAlias CodeObj = iota |
| 72 | ObjConst |
| 73 | ObjType |
| 74 | ObjFunc |
| 75 | ObjVar |
| 76 | ObjStub |
| 77 | ) |
| 78 |
Members