private getBuiltInType()

in packages/typespec-go/src/tcgcadapter/types.ts [297:436]


  private getBuiltInType(type: tcgc.SdkBuiltInType): go.PossibleType {
    switch (type.kind) {
      case 'unknown': {
        if (this.codeModel.options.rawJSONAsBytes) {
          const anyRawJSONKey = 'any-raw-json';
          let anyRawJSON = this.types.get(anyRawJSONKey);
          if (anyRawJSON) {
            return anyRawJSON;
          }
          anyRawJSON = new go.SliceType(new go.PrimitiveType('byte'), true);
          anyRawJSON.rawJSONAsBytes = true;
          this.types.set(anyRawJSONKey, anyRawJSON);
          return anyRawJSON;
        }
        let anyType = this.types.get('any');
        if (anyType) {
          return anyType;
        }
        anyType = new go.PrimitiveType('any');
        this.types.set('any', anyType);
        return anyType;
      }
      case 'boolean': {
        const boolKey = 'boolean';
        let primitiveBool = this.types.get(boolKey);
        if (primitiveBool) {
          return primitiveBool;
        }
        primitiveBool = new go.PrimitiveType('bool');
        this.types.set(boolKey, primitiveBool);
        return primitiveBool;
      }
      case 'bytes':
        return this.adaptBytesType(type);
      case 'plainDate': {
        const dateKey = 'dateType';
        let date = this.types.get(dateKey);
        if (date) {
          return date;
        }
        date = new go.TimeType('dateType', false);
        this.types.set(dateKey, date);
        return date;
      }
      case 'decimal':
      case 'decimal128': {
        const decimalKey = 'float64';
        let decimalType = this.types.get(decimalKey);
        if (decimalType) {
          return decimalType;
        }
        decimalType = new go.PrimitiveType(decimalKey);
        this.types.set(decimalKey, decimalType);
        return decimalType;
      }
      case 'float': // C# and Java define float as 32 bits so we're following suit
      case 'float32': {
        const float32Key = 'float32';
        let float32 = this.types.get(float32Key);
        if (float32) {
          return float32;
        }
        float32 = new go.PrimitiveType(float32Key);
        this.types.set(float32Key, float32);
        return float32;
      }
      case 'float64': {
        const float64Key = 'float64';
        let float64 = this.types.get(float64Key);
        if (float64) {
          return float64;
        }
        float64 = new go.PrimitiveType(float64Key);
        this.types.set(float64Key, float64);
        return float64;
      }
      case 'int8':
      case 'int16':
      case 'int32':
      case 'int64':
      case 'uint8':
      case 'uint16':
      case 'uint32':
      case 'uint64': {
        const keyName = type.encode === 'string' ? `${type.kind}-string` : type.kind;
        let intType = this.types.get(keyName);
        if (intType) {
          return intType;
        }
        intType = new go.PrimitiveType(type.kind, type.encode === 'string');
        this.types.set(keyName, intType);
        return intType;
      }
      case 'safeint': {
        const safeintkey = type.encode === 'string' ? 'int64-string' : 'int64';
        let int64 = this.types.get(safeintkey);
        if (int64) {
          return int64;
        }
        int64 = new go.PrimitiveType('int64', type.encode === 'string');
        this.types.set(safeintkey, int64);
        return int64;
      }
      case 'string':
      case 'url': {
        if (type.crossLanguageDefinitionId === 'Azure.Core.eTag') {
          const etagKey = 'etag';
          let etag = this.types.get(etagKey);
          if (etag) {
            return etag;
          }
          etag = new go.QualifiedType('ETag', 'github.com/Azure/azure-sdk-for-go/sdk/azcore');
          this.types.set(etagKey, etag);
          return etag;
        }

        const stringKey = 'string';
        let stringType = this.types.get(stringKey);
        if (stringType) {
          return stringType;
        }
        stringType = new go.PrimitiveType('string');
        this.types.set(stringKey, stringType);
        return stringType;
      }
      case 'plainTime': {
        const encoding = 'timeRFC3339';
        let time = this.types.get(encoding);
        if (time) {
          return time;
        }
        time = new go.TimeType(encoding, false);
        this.types.set(encoding, time);
        return time;
      
      }
      default:
        throw new AdapterError('UnsupportedTsp', `unsupported type kind ${type.kind}`, type.__raw?.node ?? tsp.NoTarget);
    }
  }