jameshartig commented on code in PR #1855: URL: https://github.com/apache/cassandra-gocql-driver/pull/1855#discussion_r2128990729
########## marshal.go: ########## @@ -2623,251 +2990,23 @@ func unmarshalUDT(info TypeInfo, data []byte, value interface{}) error { return nil } -// TypeInfo describes a Cassandra specific data type. -type TypeInfo interface { - Type() Type - Version() byte - Custom() string - - // NewWithError creates a pointer to an empty version of whatever type - // is referenced by the TypeInfo receiver. - // - // If there is no corresponding Go type for the CQL type, NewWithError returns an error. - NewWithError() (interface{}, error) -} - -type NativeType struct { - proto byte - typ Type - custom string // only used for TypeCustom -} - -func NewNativeType(proto byte, typ Type) NativeType { - return NativeType{proto, typ, ""} -} - -func NewCustomType(proto byte, typ Type, custom string) NativeType { - return NativeType{proto, typ, custom} -} - -func (t NativeType) NewWithError() (interface{}, error) { - typ, err := goType(t) - if err != nil { - return nil, err - } - return reflect.New(typ).Interface(), nil -} - -func (s NativeType) Type() Type { - return s.typ -} - -func (s NativeType) Version() byte { - return s.proto -} - -func (s NativeType) Custom() string { - return s.custom -} - -func (s NativeType) String() string { - switch s.typ { - case TypeCustom: - return fmt.Sprintf("%s(%s)", s.typ, s.custom) - default: - return s.typ.String() - } -} - -type CollectionType struct { - NativeType - Key TypeInfo // only used for TypeMap - Elem TypeInfo // only used for TypeMap, TypeList and TypeSet -} - -type VectorType struct { - NativeType - SubType TypeInfo - Dimensions int -} - -func (t CollectionType) NewWithError() (interface{}, error) { - typ, err := goType(t) - if err != nil { - return nil, err - } - return reflect.New(typ).Interface(), nil -} - -func (c CollectionType) String() string { - switch c.typ { - case TypeMap: - return fmt.Sprintf("%s(%s, %s)", c.typ, c.Key, c.Elem) - case TypeList, TypeSet: - return fmt.Sprintf("%s(%s)", c.typ, c.Elem) - case TypeCustom: - return fmt.Sprintf("%s(%s)", c.typ, c.custom) - default: - return c.typ.String() - } -} - -type TupleTypeInfo struct { - NativeType - Elems []TypeInfo -} - -func (t TupleTypeInfo) String() string { - var buf bytes.Buffer - buf.WriteString(fmt.Sprintf("%s(", t.typ)) - for _, elem := range t.Elems { - buf.WriteString(fmt.Sprintf("%s, ", elem)) - } - buf.Truncate(buf.Len() - 2) - buf.WriteByte(')') - return buf.String() -} - -func (t TupleTypeInfo) NewWithError() (interface{}, error) { - typ, err := goType(t) - if err != nil { - return nil, err - } - return reflect.New(typ).Interface(), nil -} - -type UDTField struct { - Name string - Type TypeInfo -} - -type UDTTypeInfo struct { - NativeType - KeySpace string - Name string - Elements []UDTField -} - -func (u UDTTypeInfo) NewWithError() (interface{}, error) { - typ, err := goType(u) - if err != nil { - return nil, err - } - return reflect.New(typ).Interface(), nil -} - -func (u UDTTypeInfo) String() string { - buf := &bytes.Buffer{} - - fmt.Fprintf(buf, "%s.%s{", u.KeySpace, u.Name) - first := true - for _, e := range u.Elements { - if !first { - fmt.Fprint(buf, ",") - } else { - first = false +// NewNativeType returns a TypeInfo from the global registered types. +// Deprecated. +// TODO: make sure this works with known public usages +func NewNativeType(proto byte, typ Type, custom string) TypeInfo { + if typ == TypeCustom { + // TODO: do we need to parse custom? what if its a composite type? + rt := GlobalTypes.custom[custom] Review Comment: okay for now we can just avoid composite types and get back to this later if we need to -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org For additional commands, e-mail: pr-h...@cassandra.apache.org