From 4d5f6e794d02b9a6f265d174b477067583eedb4c Mon Sep 17 00:00:00 2001 From: Fabio Rossetto Date: Tue, 2 Dec 2025 12:20:41 -0300 Subject: [PATCH 1/3] feature: Add annotation support for enum configuration - Add new EnumConfig struct with annotation parsing capabilities - Implement annotation processing for per-enum configuration overrides - Support annotations like @marshal, @sql, @prefix, @nocase, @noprefix - Add example annotation enum with comprehensive test coverage - Update generator to respect annotation-based configuration - Maintain backward compatibility with existing enum definitions --- README.md | 75 +++++++++-- example/annotation.go | 15 +++ example/annotation_enum.go | 266 +++++++++++++++++++++++++++++++++++++ example/annotation_test.go | 218 ++++++++++++++++++++++++++++++ generator/enum_config.go | 188 ++++++++++++++++++++++++++ generator/generator.go | 121 +++++++++++++---- 6 files changed, 849 insertions(+), 34 deletions(-) create mode 100644 example/annotation.go create mode 100644 example/annotation_enum.go create mode 100644 example/annotation_test.go create mode 100644 generator/enum_config.go diff --git a/README.md b/README.md index ca5e5ac..9bbbb57 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ An enum generator for Go that creates type-safe enumerations with useful methods ```go package main - + // ENUM(red, green, blue) type Color int ``` @@ -67,7 +67,7 @@ An enum generator for Go that creates type-safe enumerations with useful methods ```shell # Go 1.24+ (recommended) go tool go-enum -f your_file.go - + # Or for older Go versions go-enum -f your_file.go ``` @@ -77,7 +77,7 @@ An enum generator for Go that creates type-safe enumerations with useful methods ```go color := ColorRed fmt.Println(color.String()) // prints "red" - + parsed, err := ParseColor("green") if err == nil { fmt.Println(parsed) // prints "green" @@ -147,7 +147,7 @@ const ( ``` If you would like to get integer values in sql, but strings elsewhere, you can assign an int value in the declaration -like always, and specify the `--sqlint` flag. Those values will be then used to convey the int value to sql, while allowing you to use only strings elsewhere. +like always, and specify the `--sqlint` flag. Those values will be then used to convey the int value to sql, while allowing you to use only strings elsewhere. This might be helpful for things like swagger docs where you want the same type being used on the api layer, as you do in the sql layer, and not have swagger assume that your enumerations are integers, but are in fact strings! @@ -183,6 +183,62 @@ Change the default `_enum.go` suffix to something else: go-enum --output-suffix="_generated" -f your_file.go # Creates your_file_generated.go ``` +### Inline Annotations (v0.10.0+) + +You can now specify configuration options directly in the enum declaration using inline annotations. This allows you to override global command-line options on a per-enum basis. + +Annotations are specified as comments starting with `@` before the `ENUM` declaration: + +```go +// @marshal:true @sql:false @prefix:"My" +// ENUM(pending, running, completed, failed) +type AnnotationStatus string + +// @noprefix @nocase +// ENUM(annotation_red, annotation_green, annotation_blue) +type AnnotationColor string + +// @marshal @sql +// ENUM(one, two, three) +type AnnotationNumber int +``` + +**Available annotations:** + +| Annotation | Values | Description | +| ------------- | -------------- | -------------------------------------------------- | +| `@prefix` | `"string"` | Custom prefix for constants (e.g., `@prefix:"My"`) | +| `@marshal` | `true`/`false` | Enables/disables JSON/text marshaling methods | +| `@sql` | `true`/`false` | Enables/disables SQL Scan/Value methods | +| `@sqlint` | `true`/`false` | Stores string enums as integers in SQL | +| `@noprefix` | `true`/`false` | Disables prefixing constants with enum name | +| `@nocase` | `true`/`false` | Enables case-insensitive parsing | +| `@noparse` | `true`/`false` | Disables Parse method generation | +| `@mustparse` | `true`/`false` | Adds MustParse method that panics on failure | +| `@flag` | `true`/`false` | Adds flag.Value interface methods | +| `@ptr` | `true`/`false` | Adds Ptr() method | +| `@names` | `true`/`false` | Adds Names() []string method | +| `@values` | `true`/`false` | Adds Values() []Enum method | +| `@nocomments` | `true`/`false` | Disables auto-generated comments | +| `@noiota` | `true`/`false` | Disables iota usage | +| `@forcelower` | `true`/`false` | Forces lowercase constant names | +| `@forceupper` | `true`/`false` | Forces uppercase constant names | + +**Syntax notes:** + +- Boolean annotations can be specified as `@annotation` (defaults to `true`) or `@annotation:true`/`@annotation:false` +- String annotations use quotes: `@prefix:"My"` +- Multiple annotations can be specified on the same line or across multiple lines +- Inline annotations override global command-line options + +**Example with mixed annotations:** + +```go +// @marshal @sql:false @nocase @prefix:"App" +// ENUM(draft, review, published, archived) +type DocumentStatus string +``` + ## Goal The goal of go-enum is to create an easy to use enum generator that will take a decorated type declaration like `type EnumName int` and create the associated constant values and funcs that will make life a little easier for adding new values. @@ -302,7 +358,7 @@ For older Go versions: ## Command options -``` shell +```shell go-enum --help NAME: @@ -343,12 +399,13 @@ GLOBAL OPTIONS: --help, -h show help --version, -v print the version ``` +**Note:** Many command-line options can also be specified as inline annotations directly in your enum declarations. See the [Inline Annotations](#inline-annotations-v0100) section for details. ### Syntax The parser looks for comments on your type defs and parse the enum declarations from it. -The parser will look for `ENUM(` and continue to look for comma separated values until it finds a `)`. You can put values on the same line, or on multiple lines.\ -If you need to have a specific value jump in the enum, you can now specify that by adding `=numericValue` to the enum declaration. Keep in mind, this resets the data for all following values. So if you specify `50` in the middle of an enum, each value after that will be `51, 52, 53...` +The parser will look for `ENUM(` and continue to look for comma separated values until it finds a `)`. You can put values on the same line, or on multiple lines.\ +If you need to have a specific value jump in the enum, you can now specify that by adding `=numericValue` to the enum declaration. Keep in mind, this resets the data for all following values. So if you specify `50` in the middle of an enum, each value after that will be `51, 52, 53...` [Examples can be found in the example folder](./example/) @@ -391,7 +448,7 @@ const ( There are a few examples in the `example` [directory](./example/). I've included one here for easy access, but can't guarantee it's up to date. -``` go +```go // Color is an enumeration of colors that are allowed. /* ENUM( Black, White, Red @@ -410,7 +467,7 @@ type Color int32 The generated code will look something like: -``` go +```go // Code generated by go-enum DO NOT EDIT. // Version: example // Revision: example diff --git a/example/annotation.go b/example/annotation.go new file mode 100644 index 0000000..75b9e77 --- /dev/null +++ b/example/annotation.go @@ -0,0 +1,15 @@ +//go:generate ../bin/go-enum -b example + +package example + +// @marshal:true @sql:false @prefix:"My" +// ENUM(pending, running, completed, failed) +type AnnotationStatus string + +// @noprefix @nocase +// ENUM(annotation_red, annotation_green, annotation_blue) +type AnnotationColor string + +// @marshal @sql @marshal +// ENUM(one, two, three) +type AnnotationNumber int diff --git a/example/annotation_enum.go b/example/annotation_enum.go new file mode 100644 index 0000000..3291dfd --- /dev/null +++ b/example/annotation_enum.go @@ -0,0 +1,266 @@ +// Code generated by go-enum DO NOT EDIT. +// Version: example +// Revision: example +// Build Date: example +// Built By: example + +//go:build example +// +build example + +package example + +import ( + "database/sql/driver" + "errors" + "fmt" + "strings" +) + +const ( + // AnnotationRed is a AnnotationColor of type annotation_red. + AnnotationRed AnnotationColor = "annotation_red" + // AnnotationGreen is a AnnotationColor of type annotation_green. + AnnotationGreen AnnotationColor = "annotation_green" + // AnnotationBlue is a AnnotationColor of type annotation_blue. + AnnotationBlue AnnotationColor = "annotation_blue" +) + +var ErrInvalidAnnotationColor = errors.New("not a valid AnnotationColor") + +// String implements the Stringer interface. +func (x AnnotationColor) String() string { + return string(x) +} + +// IsValid provides a quick way to determine if the typed value is +// part of the allowed enumerated values +func (x AnnotationColor) IsValid() bool { + _, err := ParseAnnotationColor(string(x)) + return err == nil +} + +var _AnnotationColorValue = map[string]AnnotationColor{ + "annotation_red": AnnotationRed, + "annotation_green": AnnotationGreen, + "annotation_blue": AnnotationBlue, +} + +// ParseAnnotationColor attempts to convert a string to a AnnotationColor. +func ParseAnnotationColor(name string) (AnnotationColor, error) { + if x, ok := _AnnotationColorValue[name]; ok { + return x, nil + } + // Case insensitive parse, do a separate lookup to prevent unnecessary cost of lowercasing a string if we don't need to. + if x, ok := _AnnotationColorValue[strings.ToLower(name)]; ok { + return x, nil + } + return AnnotationColor(""), fmt.Errorf("%s is %w", name, ErrInvalidAnnotationColor) +} + +const ( + // AnnotationNumberOne is a AnnotationNumber of type One. + AnnotationNumberOne AnnotationNumber = iota + // AnnotationNumberTwo is a AnnotationNumber of type Two. + AnnotationNumberTwo + // AnnotationNumberThree is a AnnotationNumber of type Three. + AnnotationNumberThree +) + +var ErrInvalidAnnotationNumber = errors.New("not a valid AnnotationNumber") + +const _AnnotationNumberName = "onetwothree" + +var _AnnotationNumberMap = map[AnnotationNumber]string{ + AnnotationNumberOne: _AnnotationNumberName[0:3], + AnnotationNumberTwo: _AnnotationNumberName[3:6], + AnnotationNumberThree: _AnnotationNumberName[6:11], +} + +// String implements the Stringer interface. +func (x AnnotationNumber) String() string { + if str, ok := _AnnotationNumberMap[x]; ok { + return str + } + return fmt.Sprintf("AnnotationNumber(%d)", x) +} + +// IsValid provides a quick way to determine if the typed value is +// part of the allowed enumerated values +func (x AnnotationNumber) IsValid() bool { + _, ok := _AnnotationNumberMap[x] + return ok +} + +var _AnnotationNumberValue = map[string]AnnotationNumber{ + _AnnotationNumberName[0:3]: AnnotationNumberOne, + _AnnotationNumberName[3:6]: AnnotationNumberTwo, + _AnnotationNumberName[6:11]: AnnotationNumberThree, +} + +// ParseAnnotationNumber attempts to convert a string to a AnnotationNumber. +func ParseAnnotationNumber(name string) (AnnotationNumber, error) { + if x, ok := _AnnotationNumberValue[name]; ok { + return x, nil + } + return AnnotationNumber(0), fmt.Errorf("%s is %w", name, ErrInvalidAnnotationNumber) +} + +// MarshalText implements the text marshaller method. +func (x AnnotationNumber) MarshalText() ([]byte, error) { + return []byte(x.String()), nil +} + +// UnmarshalText implements the text unmarshaller method. +func (x *AnnotationNumber) UnmarshalText(text []byte) error { + name := string(text) + tmp, err := ParseAnnotationNumber(name) + if err != nil { + return err + } + *x = tmp + return nil +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (x *AnnotationNumber) AppendText(b []byte) ([]byte, error) { + return append(b, x.String()...), nil +} + +var errAnnotationNumberNilPtr = errors.New("value pointer is nil") // one per type for package clashes + +// Scan implements the Scanner interface. +func (x *AnnotationNumber) Scan(value interface{}) (err error) { + if value == nil { + *x = AnnotationNumber(0) + return + } + + // A wider range of scannable types. + // driver.Value values at the top of the list for expediency + switch v := value.(type) { + case int64: + *x = AnnotationNumber(v) + case string: + *x, err = ParseAnnotationNumber(v) + case []byte: + *x, err = ParseAnnotationNumber(string(v)) + case AnnotationNumber: + *x = v + case int: + *x = AnnotationNumber(v) + case *AnnotationNumber: + if v == nil { + return errAnnotationNumberNilPtr + } + *x = *v + case uint: + *x = AnnotationNumber(v) + case uint64: + *x = AnnotationNumber(v) + case *int: + if v == nil { + return errAnnotationNumberNilPtr + } + *x = AnnotationNumber(*v) + case *int64: + if v == nil { + return errAnnotationNumberNilPtr + } + *x = AnnotationNumber(*v) + case float64: // json marshals everything as a float64 if it's a number + *x = AnnotationNumber(v) + case *float64: // json marshals everything as a float64 if it's a number + if v == nil { + return errAnnotationNumberNilPtr + } + *x = AnnotationNumber(*v) + case *uint: + if v == nil { + return errAnnotationNumberNilPtr + } + *x = AnnotationNumber(*v) + case *uint64: + if v == nil { + return errAnnotationNumberNilPtr + } + *x = AnnotationNumber(*v) + case *string: + if v == nil { + return errAnnotationNumberNilPtr + } + *x, err = ParseAnnotationNumber(*v) + } + + return +} + +// Value implements the driver Valuer interface. +func (x AnnotationNumber) Value() (driver.Value, error) { + return x.String(), nil +} + +const ( + // MyAnnotationStatusPending is a AnnotationStatus of type pending. + MyAnnotationStatusPending AnnotationStatus = "pending" + // MyAnnotationStatusRunning is a AnnotationStatus of type running. + MyAnnotationStatusRunning AnnotationStatus = "running" + // MyAnnotationStatusCompleted is a AnnotationStatus of type completed. + MyAnnotationStatusCompleted AnnotationStatus = "completed" + // MyAnnotationStatusFailed is a AnnotationStatus of type failed. + MyAnnotationStatusFailed AnnotationStatus = "failed" +) + +var ErrInvalidAnnotationStatus = errors.New("not a valid AnnotationStatus") + +// String implements the Stringer interface. +func (x AnnotationStatus) String() string { + return string(x) +} + +// IsValid provides a quick way to determine if the typed value is +// part of the allowed enumerated values +func (x AnnotationStatus) IsValid() bool { + _, err := ParseAnnotationStatus(string(x)) + return err == nil +} + +var _AnnotationStatusValue = map[string]AnnotationStatus{ + "pending": MyAnnotationStatusPending, + "running": MyAnnotationStatusRunning, + "completed": MyAnnotationStatusCompleted, + "failed": MyAnnotationStatusFailed, +} + +// ParseAnnotationStatus attempts to convert a string to a AnnotationStatus. +func ParseAnnotationStatus(name string) (AnnotationStatus, error) { + if x, ok := _AnnotationStatusValue[name]; ok { + return x, nil + } + return AnnotationStatus(""), fmt.Errorf("%s is %w", name, ErrInvalidAnnotationStatus) +} + +// MarshalText implements the text marshaller method. +func (x AnnotationStatus) MarshalText() ([]byte, error) { + return []byte(string(x)), nil +} + +// UnmarshalText implements the text unmarshaller method. +func (x *AnnotationStatus) UnmarshalText(text []byte) error { + tmp, err := ParseAnnotationStatus(string(text)) + if err != nil { + return err + } + *x = tmp + return nil +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (x *AnnotationStatus) AppendText(b []byte) ([]byte, error) { + return append(b, x.String()...), nil +} diff --git a/example/annotation_test.go b/example/annotation_test.go new file mode 100644 index 0000000..2a48716 --- /dev/null +++ b/example/annotation_test.go @@ -0,0 +1,218 @@ +//go:build example +// +build example + +package example + +import ( + "encoding/json" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +type annotationTestData struct { + Status AnnotationStatus `json:"status"` + Color AnnotationColor `json:"color"` + Number AnnotationNumber `json:"number"` +} + +func TestAnnotationStatus(t *testing.T) { + // Test prefix "My" was applied + assert.Equal(t, MyAnnotationStatusPending, AnnotationStatus("pending")) + assert.Equal(t, MyAnnotationStatusRunning, AnnotationStatus("running")) + assert.Equal(t, MyAnnotationStatusCompleted, AnnotationStatus("completed")) + assert.Equal(t, MyAnnotationStatusFailed, AnnotationStatus("failed")) + + // Test String() + assert.Equal(t, "pending", MyAnnotationStatusPending.String()) + assert.Equal(t, "running", MyAnnotationStatusRunning.String()) + + // Test IsValid() + assert.True(t, MyAnnotationStatusPending.IsValid()) + assert.True(t, MyAnnotationStatusRunning.IsValid()) + assert.False(t, AnnotationStatus("invalid").IsValid()) + + // Test Parse + parsed, err := ParseAnnotationStatus("pending") + assert.NoError(t, err) + assert.Equal(t, MyAnnotationStatusPending, parsed) + + _, err = ParseAnnotationStatus("invalid") + assert.Error(t, err) + assert.Equal(t, "invalid is not a valid AnnotationStatus", err.Error()) + + // Test Marshal/Unmarshal + jsonData := `{"status":"pending"}` + var data struct { + Status AnnotationStatus `json:"status"` + } + err = json.Unmarshal([]byte(jsonData), &data) + assert.NoError(t, err) + assert.Equal(t, MyAnnotationStatusPending, data.Status) + + marshaled, err := json.Marshal(data) + assert.NoError(t, err) + assert.JSONEq(t, jsonData, string(marshaled)) + + // Test AppendText (method has pointer receiver) + status := MyAnnotationStatusPending + text, err := status.AppendText(nil) + assert.NoError(t, err) + assert.Equal(t, "pending", string(text)) +} + +func TestAnnotationColor(t *testing.T) { + // Test noprefix - no "AnnotationColor" prefix + assert.Equal(t, AnnotationRed, AnnotationColor("annotation_red")) + assert.Equal(t, AnnotationGreen, AnnotationColor("annotation_green")) + assert.Equal(t, AnnotationBlue, AnnotationColor("annotation_blue")) + + // Test nocase - case insensitive parsing + parsed, err := ParseAnnotationColor("ANNOTATION_RED") + assert.NoError(t, err) + assert.Equal(t, AnnotationRed, parsed) + + parsed, err = ParseAnnotationColor("annotation_red") + assert.NoError(t, err) + assert.Equal(t, AnnotationRed, parsed) + + parsed, err = ParseAnnotationColor("AnNoTaTiOn_ReD") + assert.NoError(t, err) + assert.Equal(t, AnnotationRed, parsed) + + // Test invalid + _, err = ParseAnnotationColor("invalid") + assert.Error(t, err) + assert.Equal(t, "invalid is not a valid AnnotationColor", err.Error()) + + // Test String() + assert.Equal(t, "annotation_red", AnnotationRed.String()) + + // Test IsValid() + assert.True(t, AnnotationRed.IsValid()) + assert.False(t, AnnotationColor("invalid").IsValid()) + + // Note: No marshal methods for AnnotationColor (not specified) +} + +func TestAnnotationNumber(t *testing.T) { + // Test constants + assert.Equal(t, AnnotationNumberOne, AnnotationNumber(0)) + assert.Equal(t, AnnotationNumberTwo, AnnotationNumber(1)) + assert.Equal(t, AnnotationNumberThree, AnnotationNumber(2)) + + // Test String() + assert.Equal(t, "one", AnnotationNumberOne.String()) + assert.Equal(t, "two", AnnotationNumberTwo.String()) + assert.Equal(t, "three", AnnotationNumberThree.String()) + + // Test IsValid() + assert.True(t, AnnotationNumberOne.IsValid()) + assert.False(t, AnnotationNumber(999).IsValid()) + + // Test Parse + parsed, err := ParseAnnotationNumber("one") + assert.NoError(t, err) + assert.Equal(t, AnnotationNumberOne, parsed) + + _, err = ParseAnnotationNumber("invalid") + assert.Error(t, err) + assert.Equal(t, "invalid is not a valid AnnotationNumber", err.Error()) + + // Test Marshal/Unmarshal + jsonData := `{"number":"one"}` + var data struct { + Number AnnotationNumber `json:"number"` + } + err = json.Unmarshal([]byte(jsonData), &data) + assert.NoError(t, err) + assert.Equal(t, AnnotationNumberOne, data.Number) + + marshaled, err := json.Marshal(data) + assert.NoError(t, err) + assert.JSONEq(t, jsonData, string(marshaled)) + + // Test SQL Scan/Value (basic test) + var numScan AnnotationNumber + err = numScan.Scan("one") + assert.NoError(t, err) + assert.Equal(t, AnnotationNumberOne, numScan) + + val, err := AnnotationNumberOne.Value() + assert.NoError(t, err) + assert.Equal(t, "one", val) + + // Test AppendText (method has pointer receiver) + numAppend := AnnotationNumberOne + text, err := numAppend.AppendText(nil) + assert.NoError(t, err) + assert.Equal(t, "one", string(text)) +} + +func TestAnnotationSQL(t *testing.T) { + // Test AnnotationNumber SQL (enabled) + var num AnnotationNumber + + // Scan from string + err := num.Scan("two") + assert.NoError(t, err) + assert.Equal(t, AnnotationNumberTwo, num) + + // Scan from int + err = num.Scan(1) + assert.NoError(t, err) + assert.Equal(t, AnnotationNumberTwo, num) + + // Value returns string + val, err := num.Value() + assert.NoError(t, err) + assert.Equal(t, "two", val) + + // Test AnnotationStatus SQL (disabled - should not have Scan/Value methods) + // We can't test absence directly, but we can verify that the type doesn't implement + // driver.Valuer and sql.Scanner for AnnotationStatus (they're not generated) +} + +func TestAnnotationMarshalCombined(t *testing.T) { + // Test all three together + jsonData := `{"status":"completed","color":"annotation_green","number":"three"}` + var data annotationTestData + err := json.Unmarshal([]byte(jsonData), &data) + assert.NoError(t, err) + assert.Equal(t, MyAnnotationStatusCompleted, data.Status) + assert.Equal(t, AnnotationGreen, data.Color) + assert.Equal(t, AnnotationNumberThree, data.Number) + + marshaled, err := json.Marshal(data) + assert.NoError(t, err) + assert.JSONEq(t, jsonData, string(marshaled)) +} + +func BenchmarkAnnotationParse(b *testing.B) { + knownItems := []string{ + "pending", + "annotation_red", + "one", + } + + var err error + for _, item := range knownItems { + b.Run(item, func(b *testing.B) { + b.ReportAllocs() + b.ResetTimer() + for i := 0; i < b.N; i++ { + // Try to parse with appropriate parser + switch { + case strings.Contains(item, "annotation_"): + _, err = ParseAnnotationColor(item) + case item == "one" || item == "two" || item == "three": + _, err = ParseAnnotationNumber(item) + default: + _, err = ParseAnnotationStatus(item) + } + assert.NoError(b, err) + } + }) + } +} diff --git a/generator/enum_config.go b/generator/enum_config.go new file mode 100644 index 0000000..dc2d288 --- /dev/null +++ b/generator/enum_config.go @@ -0,0 +1,188 @@ +package generator + +import ( + "fmt" + "strconv" + "strings" +) + +// EnumConfigValue holds a configuration value with its validity flag. +type EnumConfigValue struct { + Value interface{} + Valid bool +} + +// GetBool returns the boolean value if valid, otherwise returns the default value. +func (v *EnumConfigValue) GetBool(defaultValue bool) bool { + if v.Valid { + if b, ok := v.Value.(bool); ok { + return b + } + } + return defaultValue +} + +// GetString returns the string value if valid, otherwise returns the default value. +func (v *EnumConfigValue) GetString(defaultValue string) string { + if v.Valid { + if s, ok := v.Value.(string); ok { + return s + } + } + return defaultValue +} + + +// EnumConfig holds configuration options specific to a single enum. +// These options can be specified inline via annotations and override global GeneratorConfig. +type EnumConfig struct { + // Bool options + NoPrefix EnumConfigValue `json:"no_prefix"` + NoIota EnumConfigValue `json:"no_iota"` + LowercaseLookup EnumConfigValue `json:"lowercase_lookup"` + CaseInsensitive EnumConfigValue `json:"case_insensitive"` + Marshal EnumConfigValue `json:"marshal"` + SQL EnumConfigValue `json:"sql"` + SQLInt EnumConfigValue `json:"sql_int"` + Flag EnumConfigValue `json:"flag"` + Names EnumConfigValue `json:"names"` + Values EnumConfigValue `json:"values"` + LeaveSnakeCase EnumConfigValue `json:"leave_snake_case"` + Ptr EnumConfigValue `json:"ptr"` + SQLNullInt EnumConfigValue `json:"sql_null_int"` + SQLNullStr EnumConfigValue `json:"sql_null_str"` + MustParse EnumConfigValue `json:"must_parse"` + ForceLower EnumConfigValue `json:"force_lower"` + ForceUpper EnumConfigValue `json:"force_upper"` + NoComments EnumConfigValue `json:"no_comments"` + NoParse EnumConfigValue `json:"no_parse"` + + // String options + Prefix EnumConfigValue `json:"prefix"` + + // Slice/map options (not supported inline for simplicity) + // BuildTags []string + // ReplacementNames map[string]string + // TemplateFileNames []string +} + +// NewEnumConfig creates a new EnumConfig with default values. +func NewEnumConfig() *EnumConfig { + return &EnumConfig{} +} + +// ParseAnnotation parses a single annotation string (e.g., "@marshal", "@marshal:true", "@prefix=\"My\"") +// and updates the EnumConfig accordingly. +func (ec *EnumConfig) ParseAnnotation(annotation string) error { + annotation = strings.TrimSpace(annotation) + if annotation == "" { + return nil + } + + // Remove @ prefix + if !strings.HasPrefix(annotation, "@") { + return fmt.Errorf("annotation must start with @: %s", annotation) + } + annotation = annotation[1:] + + // Check for key:value format (e.g., @marshal:true, @marshal:false) + if strings.Contains(annotation, ":") { + parts := strings.SplitN(annotation, ":", 2) + key := strings.TrimSpace(parts[0]) + value := strings.TrimSpace(parts[1]) + + // Parse boolean value + if value == "true" || value == "false" { + boolValue, _ := strconv.ParseBool(value) + return ec.setBoolOption(key, boolValue) + } + + // String value (could be quoted) + if len(value) >= 2 && ((value[0] == '"' && value[len(value)-1] == '"') || + (value[0] == '\'' && value[len(value)-1] == '\'')) { + value = value[1 : len(value)-1] + } + + return ec.setStringOption(key, value) + } + + // Check for key=value format (legacy style, e.g., @prefix="My") + if strings.Contains(annotation, "=") { + parts := strings.SplitN(annotation, "=", 2) + key := strings.TrimSpace(parts[0]) + value := strings.TrimSpace(parts[1]) + + // Remove quotes if present + if len(value) >= 2 && ((value[0] == '"' && value[len(value)-1] == '"') || + (value[0] == '\'' && value[len(value)-1] == '\'')) { + value = value[1 : len(value)-1] + } + + return ec.setStringOption(key, value) + } + + // Boolean flag without explicit value (defaults to true) + return ec.setBoolOption(annotation, true) +} + +// setBoolOption sets a boolean option in the EnumConfig. +func (ec *EnumConfig) setBoolOption(key string, value bool) error { + switch key { + case "noprefix": + ec.NoPrefix = EnumConfigValue{Value: value, Valid: true} + case "noiota": + ec.NoIota = EnumConfigValue{Value: value, Valid: true} + case "lower": + ec.LowercaseLookup = EnumConfigValue{Value: value, Valid: true} + case "nocase": + ec.CaseInsensitive = EnumConfigValue{Value: value, Valid: true} + if value { + ec.LowercaseLookup = EnumConfigValue{Value: true, Valid: true} // nocase forces lower + } + case "marshal": + ec.Marshal = EnumConfigValue{Value: value, Valid: true} + case "sql": + ec.SQL = EnumConfigValue{Value: value, Valid: true} + case "sqlint": + ec.SQLInt = EnumConfigValue{Value: value, Valid: true} + case "flag": + ec.Flag = EnumConfigValue{Value: value, Valid: true} + case "names": + ec.Names = EnumConfigValue{Value: value, Valid: true} + case "values": + ec.Values = EnumConfigValue{Value: value, Valid: true} + case "nocamel": + ec.LeaveSnakeCase = EnumConfigValue{Value: value, Valid: true} + case "ptr": + ec.Ptr = EnumConfigValue{Value: value, Valid: true} + case "sqlnullint": + ec.SQLNullInt = EnumConfigValue{Value: value, Valid: true} + case "sqlnullstr": + ec.SQLNullStr = EnumConfigValue{Value: value, Valid: true} + case "mustparse": + ec.MustParse = EnumConfigValue{Value: value, Valid: true} + case "forcelower": + ec.ForceLower = EnumConfigValue{Value: value, Valid: true} + case "forceupper": + ec.ForceUpper = EnumConfigValue{Value: value, Valid: true} + case "nocomments": + ec.NoComments = EnumConfigValue{Value: value, Valid: true} + case "noparse": + ec.NoParse = EnumConfigValue{Value: value, Valid: true} + default: + return fmt.Errorf("unknown annotation: @%s", key) + } + + return nil +} + +// setStringOption sets a string option in the EnumConfig. +func (ec *EnumConfig) setStringOption(key, value string) error { + switch key { + case "prefix": + ec.Prefix = EnumConfigValue{Value: value, Valid: true} + default: + return fmt.Errorf("unknown annotation with value: @%s=%s", key, value) + } + return nil +} diff --git a/generator/generator.go b/generator/generator.go index cac315a..7999591 100644 --- a/generator/generator.go +++ b/generator/generator.go @@ -45,6 +45,7 @@ type Enum struct { Type string Values []EnumValue Comment string + Config *EnumConfig } // EnumValue holds the individual data for each enum value within the found enum. @@ -194,39 +195,45 @@ func (g *Generator) Generate(f *ast.File) ([]byte, error) { created++ + // Use enum-specific config if available, otherwise fall back to global config + config := enum.Config + // Determine parse method generation logic - parseNeeded := g.MustParse || g.Marshal || g.anySQLEnabled() || g.Flag - generateParse := !g.NoParse || parseNeeded - parseIsPublic := !g.NoParse + parseNeeded := config.MustParse.GetBool(g.MustParse) || config.Marshal.GetBool(g.Marshal) || + (config.SQL.GetBool(g.SQL) || config.SQLInt.GetBool(g.SQLInt) || + config.SQLNullStr.GetBool(g.SQLNullStr) || config.SQLNullInt.GetBool(g.SQLNullInt)) || + config.Flag.GetBool(g.Flag) + generateParse := !config.NoParse.GetBool(g.NoParse) || parseNeeded + parseIsPublic := !config.NoParse.GetBool(g.NoParse) parseName := "Parse" if !parseIsPublic && generateParse { parseName = "parse" } // Determine if error variable is needed - generateError := generateParse || (enum.Type == "string" && g.SQLInt) + generateError := generateParse || (enum.Type == "string" && config.SQLInt.GetBool(g.SQLInt)) data := map[string]any{ "enum": enum, "name": name, - "lowercase": g.LowercaseLookup, - "nocase": g.CaseInsensitive, - "nocomments": g.NoComments, - "noIota": g.NoIota, - "marshal": g.Marshal, - "sql": g.SQL, - "sqlint": g.SQLInt, - "flag": g.Flag, - "names": g.Names, - "ptr": g.Ptr, - "values": g.Values, - "anySQLEnabled": g.anySQLEnabled(), - "sqlnullint": g.SQLNullInt, - "sqlnullstr": g.SQLNullStr, - "mustparse": g.MustParse, - "forcelower": g.ForceLower, - "forceupper": g.ForceUpper, - "noparse": g.NoParse, + "lowercase": config.LowercaseLookup.GetBool(g.LowercaseLookup), + "nocase": config.CaseInsensitive.GetBool(g.CaseInsensitive), + "nocomments": config.NoComments.GetBool(g.NoComments), + "noIota": config.NoIota.GetBool(g.NoIota), + "marshal": config.Marshal.GetBool(g.Marshal), + "sql": config.SQL.GetBool(g.SQL), + "sqlint": config.SQLInt.GetBool(g.SQLInt), + "flag": config.Flag.GetBool(g.Flag), + "names": config.Names.GetBool(g.Names), + "ptr": config.Ptr.GetBool(g.Ptr), + "values": config.Values.GetBool(g.Values), + "anySQLEnabled": config.SQL.GetBool(g.SQL) || config.SQLInt.GetBool(g.SQLInt) || config.SQLNullStr.GetBool(g.SQLNullStr) || config.SQLNullInt.GetBool(g.SQLNullInt), + "sqlnullint": config.SQLNullInt.GetBool(g.SQLNullInt), + "sqlnullstr": config.SQLNullStr.GetBool(g.SQLNullStr), + "mustparse": config.MustParse.GetBool(g.MustParse), + "forcelower": config.ForceLower.GetBool(g.ForceLower), + "forceupper": config.ForceUpper.GetBool(g.ForceUpper), + "noparse": config.NoParse.GetBool(g.NoParse), // Computed values for cleaner templates "generateParse": generateParse, "parseIsPublic": parseIsPublic, @@ -284,21 +291,42 @@ func (g *Generator) parseEnum(ts *ast.TypeSpec) (*Enum, error) { return nil, errors.New("no doc on enum") } - enum := &Enum{} + enum := &Enum{ + Config: NewEnumConfig(), + } enum.Name = ts.Name.Name enum.Type = fmt.Sprintf("%s", ts.Type) - if !g.NoPrefix { + + // Extract annotations and enum declaration + annotations, enumDecl := extractAnnotationsAndEnumDecl(ts.Doc.List) + + // Parse annotations + for _, annotation := range annotations { + if err := enum.Config.ParseAnnotation(annotation); err != nil { + fmt.Printf("Warning: failed to parse annotation %q: %v\n", annotation, err) + } + } + + // Determine prefix based on config (local overrides global) + noPrefix := enum.Config.NoPrefix.GetBool(g.NoPrefix) + if !noPrefix { enum.Prefix = ts.Name.Name } + + // Apply global prefix if set if g.Prefix != "" { enum.Prefix = g.Prefix + enum.Prefix } + + // Apply annotation prefix if set (overrides everything) + if prefix := enum.Config.Prefix.GetString(""); prefix != "" { + enum.Prefix = prefix + ts.Name.Name + } commentPreEnumDecl, _, _ := strings.Cut(ts.Doc.Text(), `ENUM(`) enum.Comment = strings.TrimSpace(commentPreEnumDecl) - enumDecl := getEnumDeclFromComments(ts.Doc.List) if enumDecl == "" { return nil, errors.New("failed parsing enum") } @@ -657,3 +685,46 @@ func isTypeSpecEnum(ts *ast.TypeSpec) bool { return isEnum } + +// extractAnnotationsAndEnumDecl extracts annotations (lines starting with @) and the ENUM declaration +// from the comment list. Returns the annotations and the enum declaration string. +func extractAnnotationsAndEnumDecl(comments []*ast.Comment) ([]string, string) { + var annotations []string + var enumDecl string + + for _, comment := range comments { + lines := breakCommentIntoLines(comment) + for _, line := range lines { + trimmedLine := strings.TrimSpace(line) + + // Skip empty lines + if trimmedLine == "" { + continue + } + + // Check if this line contains ENUM( + if strings.Contains(trimmedLine, "ENUM(") { + // Use the existing getEnumDeclFromComments function to get the full declaration + enumDecl = getEnumDeclFromComments(comments) + break + } + + // Check if this line contains annotations + if strings.Contains(trimmedLine, "@") { + // Split by whitespace to get individual annotations + // This handles cases like "@para1 @param2 @para3" + parts := strings.Fields(trimmedLine) + for _, part := range parts { + if strings.HasPrefix(part, "@") { + annotations = append(annotations, part) + } + } + } + } + if enumDecl != "" { + break + } + } + + return annotations, enumDecl +} From 96d81cee932ea034967a4a0354c227f10c4dec14 Mon Sep 17 00:00:00 2001 From: Fabio Rossetto Date: Fri, 26 Dec 2025 22:05:07 -0300 Subject: [PATCH 2/3] feat(generator): refactor EnumConfigValue to use generics for type safety - Convert EnumConfigValue to generic struct with string or bool type constraint - Update GetBool and GetString methods to use typed receivers, removing type assertions - Modify EnumConfig fields to use typed EnumConfigValue instances - Improves type safety and eliminates runtime type checking overhead --- generator/enum_config.go | 129 +++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 67 deletions(-) diff --git a/generator/enum_config.go b/generator/enum_config.go index dc2d288..5467a56 100644 --- a/generator/enum_config.go +++ b/generator/enum_config.go @@ -7,59 +7,54 @@ import ( ) // EnumConfigValue holds a configuration value with its validity flag. -type EnumConfigValue struct { - Value interface{} +type EnumConfigValue[T ~string | ~bool] struct { + Value T Valid bool } // GetBool returns the boolean value if valid, otherwise returns the default value. -func (v *EnumConfigValue) GetBool(defaultValue bool) bool { +func (v *EnumConfigValue[bool]) GetBool(def bool) bool { if v.Valid { - if b, ok := v.Value.(bool); ok { - return b - } + return v.Value } - return defaultValue + return def } // GetString returns the string value if valid, otherwise returns the default value. -func (v *EnumConfigValue) GetString(defaultValue string) string { +func (v *EnumConfigValue[string]) GetString(def string) string { if v.Valid { - if s, ok := v.Value.(string); ok { - return s - } + return v.Value } - return defaultValue + return def } - // EnumConfig holds configuration options specific to a single enum. // These options can be specified inline via annotations and override global GeneratorConfig. type EnumConfig struct { // Bool options - NoPrefix EnumConfigValue `json:"no_prefix"` - NoIota EnumConfigValue `json:"no_iota"` - LowercaseLookup EnumConfigValue `json:"lowercase_lookup"` - CaseInsensitive EnumConfigValue `json:"case_insensitive"` - Marshal EnumConfigValue `json:"marshal"` - SQL EnumConfigValue `json:"sql"` - SQLInt EnumConfigValue `json:"sql_int"` - Flag EnumConfigValue `json:"flag"` - Names EnumConfigValue `json:"names"` - Values EnumConfigValue `json:"values"` - LeaveSnakeCase EnumConfigValue `json:"leave_snake_case"` - Ptr EnumConfigValue `json:"ptr"` - SQLNullInt EnumConfigValue `json:"sql_null_int"` - SQLNullStr EnumConfigValue `json:"sql_null_str"` - MustParse EnumConfigValue `json:"must_parse"` - ForceLower EnumConfigValue `json:"force_lower"` - ForceUpper EnumConfigValue `json:"force_upper"` - NoComments EnumConfigValue `json:"no_comments"` - NoParse EnumConfigValue `json:"no_parse"` + NoPrefix EnumConfigValue[bool] `json:"no_prefix"` + NoIota EnumConfigValue[bool] `json:"no_iota"` + LowercaseLookup EnumConfigValue[bool] `json:"lowercase_lookup"` + CaseInsensitive EnumConfigValue[bool] `json:"case_insensitive"` + Marshal EnumConfigValue[bool] `json:"marshal"` + SQL EnumConfigValue[bool] `json:"sql"` + SQLInt EnumConfigValue[bool] `json:"sql_int"` + Flag EnumConfigValue[bool] `json:"flag"` + Names EnumConfigValue[bool] `json:"names"` + Values EnumConfigValue[bool] `json:"values"` + LeaveSnakeCase EnumConfigValue[bool] `json:"leave_snake_case"` + Ptr EnumConfigValue[bool] `json:"ptr"` + SQLNullInt EnumConfigValue[bool] `json:"sql_null_int"` + SQLNullStr EnumConfigValue[bool] `json:"sql_null_str"` + MustParse EnumConfigValue[bool] `json:"must_parse"` + ForceLower EnumConfigValue[bool] `json:"force_lower"` + ForceUpper EnumConfigValue[bool] `json:"force_upper"` + NoComments EnumConfigValue[bool] `json:"no_comments"` + NoParse EnumConfigValue[bool] `json:"no_parse"` // String options - Prefix EnumConfigValue `json:"prefix"` - + Prefix EnumConfigValue[string] `json:"prefix"` + // Slice/map options (not supported inline for simplicity) // BuildTags []string // ReplacementNames map[string]string @@ -78,49 +73,49 @@ func (ec *EnumConfig) ParseAnnotation(annotation string) error { if annotation == "" { return nil } - + // Remove @ prefix if !strings.HasPrefix(annotation, "@") { return fmt.Errorf("annotation must start with @: %s", annotation) } annotation = annotation[1:] - + // Check for key:value format (e.g., @marshal:true, @marshal:false) if strings.Contains(annotation, ":") { parts := strings.SplitN(annotation, ":", 2) key := strings.TrimSpace(parts[0]) value := strings.TrimSpace(parts[1]) - + // Parse boolean value if value == "true" || value == "false" { boolValue, _ := strconv.ParseBool(value) return ec.setBoolOption(key, boolValue) } - + // String value (could be quoted) - if len(value) >= 2 && ((value[0] == '"' && value[len(value)-1] == '"') || + if len(value) >= 2 && ((value[0] == '"' && value[len(value)-1] == '"') || (value[0] == '\'' && value[len(value)-1] == '\'')) { value = value[1 : len(value)-1] } - + return ec.setStringOption(key, value) } - + // Check for key=value format (legacy style, e.g., @prefix="My") if strings.Contains(annotation, "=") { parts := strings.SplitN(annotation, "=", 2) key := strings.TrimSpace(parts[0]) value := strings.TrimSpace(parts[1]) - + // Remove quotes if present - if len(value) >= 2 && ((value[0] == '"' && value[len(value)-1] == '"') || + if len(value) >= 2 && ((value[0] == '"' && value[len(value)-1] == '"') || (value[0] == '\'' && value[len(value)-1] == '\'')) { value = value[1 : len(value)-1] } - + return ec.setStringOption(key, value) } - + // Boolean flag without explicit value (defaults to true) return ec.setBoolOption(annotation, true) } @@ -129,50 +124,50 @@ func (ec *EnumConfig) ParseAnnotation(annotation string) error { func (ec *EnumConfig) setBoolOption(key string, value bool) error { switch key { case "noprefix": - ec.NoPrefix = EnumConfigValue{Value: value, Valid: true} + ec.NoPrefix = EnumConfigValue[bool]{Value: value, Valid: true} case "noiota": - ec.NoIota = EnumConfigValue{Value: value, Valid: true} + ec.NoIota = EnumConfigValue[bool]{Value: value, Valid: true} case "lower": - ec.LowercaseLookup = EnumConfigValue{Value: value, Valid: true} + ec.LowercaseLookup = EnumConfigValue[bool]{Value: value, Valid: true} case "nocase": - ec.CaseInsensitive = EnumConfigValue{Value: value, Valid: true} + ec.CaseInsensitive = EnumConfigValue[bool]{Value: value, Valid: true} if value { - ec.LowercaseLookup = EnumConfigValue{Value: true, Valid: true} // nocase forces lower + ec.LowercaseLookup = EnumConfigValue[bool]{Value: true, Valid: true} // nocase forces lower } case "marshal": - ec.Marshal = EnumConfigValue{Value: value, Valid: true} + ec.Marshal = EnumConfigValue[bool]{Value: value, Valid: true} case "sql": - ec.SQL = EnumConfigValue{Value: value, Valid: true} + ec.SQL = EnumConfigValue[bool]{Value: value, Valid: true} case "sqlint": - ec.SQLInt = EnumConfigValue{Value: value, Valid: true} + ec.SQLInt = EnumConfigValue[bool]{Value: value, Valid: true} case "flag": - ec.Flag = EnumConfigValue{Value: value, Valid: true} + ec.Flag = EnumConfigValue[bool]{Value: value, Valid: true} case "names": - ec.Names = EnumConfigValue{Value: value, Valid: true} + ec.Names = EnumConfigValue[bool]{Value: value, Valid: true} case "values": - ec.Values = EnumConfigValue{Value: value, Valid: true} + ec.Values = EnumConfigValue[bool]{Value: value, Valid: true} case "nocamel": - ec.LeaveSnakeCase = EnumConfigValue{Value: value, Valid: true} + ec.LeaveSnakeCase = EnumConfigValue[bool]{Value: value, Valid: true} case "ptr": - ec.Ptr = EnumConfigValue{Value: value, Valid: true} + ec.Ptr = EnumConfigValue[bool]{Value: value, Valid: true} case "sqlnullint": - ec.SQLNullInt = EnumConfigValue{Value: value, Valid: true} + ec.SQLNullInt = EnumConfigValue[bool]{Value: value, Valid: true} case "sqlnullstr": - ec.SQLNullStr = EnumConfigValue{Value: value, Valid: true} + ec.SQLNullStr = EnumConfigValue[bool]{Value: value, Valid: true} case "mustparse": - ec.MustParse = EnumConfigValue{Value: value, Valid: true} + ec.MustParse = EnumConfigValue[bool]{Value: value, Valid: true} case "forcelower": - ec.ForceLower = EnumConfigValue{Value: value, Valid: true} + ec.ForceLower = EnumConfigValue[bool]{Value: value, Valid: true} case "forceupper": - ec.ForceUpper = EnumConfigValue{Value: value, Valid: true} + ec.ForceUpper = EnumConfigValue[bool]{Value: value, Valid: true} case "nocomments": - ec.NoComments = EnumConfigValue{Value: value, Valid: true} + ec.NoComments = EnumConfigValue[bool]{Value: value, Valid: true} case "noparse": - ec.NoParse = EnumConfigValue{Value: value, Valid: true} + ec.NoParse = EnumConfigValue[bool]{Value: value, Valid: true} default: return fmt.Errorf("unknown annotation: @%s", key) } - + return nil } @@ -180,7 +175,7 @@ func (ec *EnumConfig) setBoolOption(key string, value bool) error { func (ec *EnumConfig) setStringOption(key, value string) error { switch key { case "prefix": - ec.Prefix = EnumConfigValue{Value: value, Valid: true} + ec.Prefix = EnumConfigValue[string]{Value: value, Valid: true} default: return fmt.Errorf("unknown annotation with value: @%s=%s", key, value) } From eea13530c2ef31d2a5b34019bbbffa174cc97c30 Mon Sep 17 00:00:00 2001 From: Fabio Rossetto Date: Tue, 10 Feb 2026 15:09:00 -0300 Subject: [PATCH 3/3] feat(generator): add MarshalText, UnmarshalText and AppendText methods to Null types - Add MarshalText, UnmarshalText and AppendText methods to Null{{.enum.Name}} type - Add MarshalText, UnmarshalText and AppendText methods to Null{{.enum.Name}}Str type - These methods allow Null types to properly implement text marshalling interfaces - Methods are only generated when .marshal flag is enabled - Maintains backward compatibility with existing code --- example/sql_enum.go | 62 ++ example/strings_only_enum.go | 31 + .../Test118CustomPrefixExampleFile-1.18 | 64 +- .../Test118CustomPrefixExampleFile-og | 888 +++++++++++++++++- .../.snapshots/TestCustomPrefixExampleFile | 888 +++++++++++++++++- generator/enum.tmpl | 62 ++ generator/enum_string.tmpl | 62 ++ 7 files changed, 2036 insertions(+), 21 deletions(-) diff --git a/example/sql_enum.go b/example/sql_enum.go index 736a0a1..5c96584 100644 --- a/example/sql_enum.go +++ b/example/sql_enum.go @@ -238,6 +238,37 @@ func (n *NullProjectStatus) UnmarshalJSON(b []byte) error { return err } +// MarshalText implements the text marshaller method. +func (n NullProjectStatus) MarshalText() ([]byte, error) { + if n.Valid { + return n.ProjectStatus.MarshalText() + } + return []byte{}, nil +} + +// UnmarshalText implements the text unmarshaller method. +func (n *NullProjectStatus) UnmarshalText(text []byte) error { + n.Set = true + if len(text) == 0 { + n.Valid = false + return nil + } + err := n.ProjectStatus.UnmarshalText(text) + n.Valid = (err == nil) + return err +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (n *NullProjectStatus) AppendText(b []byte) ([]byte, error) { + if n.Valid { + return n.ProjectStatus.AppendText(b) + } + return b, nil +} + type NullProjectStatusStr struct { NullProjectStatus } @@ -275,3 +306,34 @@ func (n *NullProjectStatusStr) UnmarshalJSON(b []byte) error { err = n.Scan(x) return err } + +// MarshalText implements the text marshaller method. +func (n NullProjectStatusStr) MarshalText() ([]byte, error) { + if n.Valid { + return n.ProjectStatus.MarshalText() + } + return []byte{}, nil +} + +// UnmarshalText implements the text unmarshaller method. +func (n *NullProjectStatusStr) UnmarshalText(text []byte) error { + n.Set = true + if len(text) == 0 { + n.Valid = false + return nil + } + err := n.ProjectStatus.UnmarshalText(text) + n.Valid = (err == nil) + return err +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (n *NullProjectStatusStr) AppendText(b []byte) ([]byte, error) { + if n.Valid { + return n.ProjectStatus.AppendText(b) + } + return b, nil +} diff --git a/example/strings_only_enum.go b/example/strings_only_enum.go index 9aeab16..baa5e30 100644 --- a/example/strings_only_enum.go +++ b/example/strings_only_enum.go @@ -226,3 +226,34 @@ func (n *NullStrState) UnmarshalJSON(b []byte) error { err = n.Scan(x) return err } + +// MarshalText implements the text marshaller method. +func (n NullStrState) MarshalText() ([]byte, error) { + if n.Valid { + return n.StrState.MarshalText() + } + return []byte{}, nil +} + +// UnmarshalText implements the text unmarshaller method. +func (n *NullStrState) UnmarshalText(text []byte) error { + n.Set = true + if len(text) == 0 { + n.Valid = false + return nil + } + err := n.StrState.UnmarshalText(text) + n.Valid = (err == nil) + return err +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (n *NullStrState) AppendText(b []byte) ([]byte, error) { + if n.Valid { + return n.StrState.AppendText(b) + } + return b, nil +} diff --git a/generator/.snapshots/Test118CustomPrefixExampleFile-1.18 b/generator/.snapshots/Test118CustomPrefixExampleFile-1.18 index a75eafc..8294316 100644 --- a/generator/.snapshots/Test118CustomPrefixExampleFile-1.18 +++ b/generator/.snapshots/Test118CustomPrefixExampleFile-1.18 @@ -1,4 +1,4 @@ -([]string) (len=296) { +([]string) (len=358) { (string) (len=41) "// Code generated by go-enum DO NOT EDIT.", (string) (len=13) "// Version: -", (string) (len=14) "// Revision: -", @@ -257,6 +257,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=55) "func (n NullChangeType) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.ChangeType.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=59) "func (n *NullChangeType) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.ChangeType.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=63) "func (n *NullChangeType) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.ChangeType.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=31) "type NullChangeTypeStr struct {", (string) (len=15) "\tNullChangeType", (string) (len=1) "}", @@ -294,5 +325,36 @@ (string) (len=16) "\terr = n.Scan(x)", (string) (len=11) "\treturn err", (string) (len=1) "}", + (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=58) "func (n NullChangeTypeStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.ChangeType.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=62) "func (n *NullChangeTypeStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.ChangeType.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=66) "func (n *NullChangeTypeStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.ChangeType.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", (string) "" } diff --git a/generator/.snapshots/Test118CustomPrefixExampleFile-og b/generator/.snapshots/Test118CustomPrefixExampleFile-og index 271b324..a74d2c7 100644 --- a/generator/.snapshots/Test118CustomPrefixExampleFile-og +++ b/generator/.snapshots/Test118CustomPrefixExampleFile-og @@ -1,4 +1,4 @@ -([]string) (len=4174) { +([]string) (len=5042) { (string) (len=41) "// Code generated by go-enum DO NOT EDIT.", (string) (len=13) "// Version: -", (string) (len=14) "// Revision: -", @@ -257,6 +257,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=51) "func (n NullAnimal) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=55) "func (n *NullAnimal) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=36) "\terr := n.Animal.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=59) "func (n *NullAnimal) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=27) "type NullAnimalStr struct {", (string) (len=11) "\tNullAnimal", (string) (len=1) "}", @@ -295,6 +326,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=54) "func (n NullAnimalStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=58) "func (n *NullAnimalStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=36) "\terr := n.Animal.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=62) "func (n *NullAnimalStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=59) "\t// Custom_prefix_Test_lower is a Cases of type Test_lower.", (string) (len=38) "\tCustom_prefix_Test_lower Cases = iota", @@ -536,6 +598,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=50) "func (n NullCases) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=54) "func (n *NullCases) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Cases.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=58) "func (n *NullCases) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=26) "type NullCasesStr struct {", (string) (len=10) "\tNullCases", (string) (len=1) "}", @@ -574,6 +667,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullCasesStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullCasesStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Cases.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullCasesStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=49) "\t// Custom_prefix_Black is a Color of type Black.", (string) (len=33) "\tCustom_prefix_Black Color = iota", @@ -835,6 +959,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=50) "func (n NullColor) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=54) "func (n *NullColor) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Color.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=58) "func (n *NullColor) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=26) "type NullColorStr struct {", (string) (len=10) "\tNullColor", (string) (len=1) "}", @@ -873,6 +1028,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullColorStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullColorStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Color.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullColorStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=60) "\t// Custom_prefix_Black is a ColorWithComment of type Black.", (string) (len=44) "\tCustom_prefix_Black ColorWithComment = iota", @@ -1135,6 +1321,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=61) "func (n NullColorWithComment) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=65) "func (n *NullColorWithComment) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=46) "\terr := n.ColorWithComment.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=69) "func (n *NullColorWithComment) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=37) "type NullColorWithCommentStr struct {", (string) (len=21) "\tNullColorWithComment", (string) (len=1) "}", @@ -1173,6 +1390,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=64) "func (n NullColorWithCommentStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=68) "func (n *NullColorWithCommentStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=46) "\terr := n.ColorWithComment.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=72) "func (n *NullColorWithCommentStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=61) "\t// Custom_prefix_Black is a ColorWithComment2 of type Black.", (string) (len=45) "\tCustom_prefix_Black ColorWithComment2 = iota", @@ -1435,6 +1683,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=62) "func (n NullColorWithComment2) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=66) "func (n *NullColorWithComment2) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment2.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=70) "func (n *NullColorWithComment2) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=38) "type NullColorWithComment2Str struct {", (string) (len=22) "\tNullColorWithComment2", (string) (len=1) "}", @@ -1473,6 +1752,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=65) "func (n NullColorWithComment2Str) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=69) "func (n *NullColorWithComment2Str) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment2.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=73) "func (n *NullColorWithComment2Str) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=61) "\t// Custom_prefix_Black is a ColorWithComment3 of type Black.", (string) (len=45) "\tCustom_prefix_Black ColorWithComment3 = iota", @@ -1751,6 +2061,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=62) "func (n NullColorWithComment3) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=66) "func (n *NullColorWithComment3) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment3.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=70) "func (n *NullColorWithComment3) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=38) "type NullColorWithComment3Str struct {", (string) (len=22) "\tNullColorWithComment3", (string) (len=1) "}", @@ -1789,6 +2130,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=65) "func (n NullColorWithComment3Str) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=69) "func (n *NullColorWithComment3Str) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment3.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=73) "func (n *NullColorWithComment3Str) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=18) "\t// Skipped value.", (string) (len=15) "\t// Placeholder", @@ -2067,6 +2439,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=62) "func (n NullColorWithComment4) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=66) "func (n *NullColorWithComment4) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment4.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=70) "func (n *NullColorWithComment4) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=38) "type NullColorWithComment4Str struct {", (string) (len=22) "\tNullColorWithComment4", (string) (len=1) "}", @@ -2105,15 +2508,46 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", - (string) (len=7) "const (", - (string) (len=57) "\t// Custom_prefix_Unknown is a Enum64bit of type Unknown.", - (string) (len=39) "\tCustom_prefix_Unknown Enum64bit = iota", - (string) (len=53) "\t// Custom_prefix_E2P15 is a Enum64bit of type E2P15.", - (string) (len=45) "\tCustom_prefix_E2P15 Enum64bit = iota + 32767", - (string) (len=53) "\t// Custom_prefix_E2P16 is a Enum64bit of type E2P16.", - (string) (len=45) "\tCustom_prefix_E2P16 Enum64bit = iota + 65534", - (string) (len=53) "\t// Custom_prefix_E2P17 is a Enum64bit of type E2P17.", - (string) (len=46) "\tCustom_prefix_E2P17 Enum64bit = iota + 131069", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=65) "func (n NullColorWithComment4Str) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=69) "func (n *NullColorWithComment4Str) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment4.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=73) "func (n *NullColorWithComment4Str) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", + (string) (len=7) "const (", + (string) (len=57) "\t// Custom_prefix_Unknown is a Enum64bit of type Unknown.", + (string) (len=39) "\tCustom_prefix_Unknown Enum64bit = iota", + (string) (len=53) "\t// Custom_prefix_E2P15 is a Enum64bit of type E2P15.", + (string) (len=45) "\tCustom_prefix_E2P15 Enum64bit = iota + 32767", + (string) (len=53) "\t// Custom_prefix_E2P16 is a Enum64bit of type E2P16.", + (string) (len=45) "\tCustom_prefix_E2P16 Enum64bit = iota + 65534", + (string) (len=53) "\t// Custom_prefix_E2P17 is a Enum64bit of type E2P17.", + (string) (len=46) "\tCustom_prefix_E2P17 Enum64bit = iota + 131069", (string) (len=53) "\t// Custom_prefix_E2P18 is a Enum64bit of type E2P18.", (string) (len=46) "\tCustom_prefix_E2P18 Enum64bit = iota + 262140", (string) (len=53) "\t// Custom_prefix_E2P19 is a Enum64bit of type E2P19.", @@ -2406,6 +2840,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=54) "func (n NullEnum64bit) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=58) "func (n *NullEnum64bit) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=39) "\terr := n.Enum64bit.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=62) "func (n *NullEnum64bit) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=30) "type NullEnum64bitStr struct {", (string) (len=14) "\tNullEnum64bit", (string) (len=1) "}", @@ -2444,6 +2909,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=57) "func (n NullEnum64bitStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=61) "func (n *NullEnum64bitStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=39) "\terr := n.Enum64bit.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=65) "func (n *NullEnum64bitStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=51) "\t// Custom_prefix_Toyota is a Model of type Toyota.", (string) (len=34) "\tCustom_prefix_Toyota Model = iota", @@ -2689,6 +3185,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=50) "func (n NullModel) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=54) "func (n *NullModel) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Model.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=58) "func (n *NullModel) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=26) "type NullModelStr struct {", (string) (len=10) "\tNullModel", (string) (len=1) "}", @@ -2727,6 +3254,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullModelStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullModelStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Model.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullModelStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=66) "\t// Custom_prefix_Продам is a NonASCII of type Продам.", (string) (len=50) "\tCustom_prefix_Продам NonASCII = iota + 1114", @@ -2968,6 +3526,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullNonASCII) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullNonASCII) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=38) "\terr := n.NonASCII.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullNonASCII) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=29) "type NullNonASCIIStr struct {", (string) (len=13) "\tNullNonASCII", (string) (len=1) "}", @@ -3006,6 +3595,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=56) "func (n NullNonASCIIStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=60) "func (n *NullNonASCIIStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=38) "\terr := n.NonASCII.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=64) "func (n *NullNonASCIIStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=65) "\t// Custom_prefix_TestHyphen is a Sanitizing of type Test-Hyphen.", (string) (len=43) "\tCustom_prefix_TestHyphen Sanitizing = iota", @@ -3267,6 +3887,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=55) "func (n NullSanitizing) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=59) "func (n *NullSanitizing) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.Sanitizing.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=63) "func (n *NullSanitizing) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=31) "type NullSanitizingStr struct {", (string) (len=15) "\tNullSanitizing", (string) (len=1) "}", @@ -3305,6 +3956,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=58) "func (n NullSanitizingStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=62) "func (n *NullSanitizingStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.Sanitizing.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=66) "func (n *NullSanitizingStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=46) "\t// Custom_prefix_Coke is a Soda of type Coke.", (string) (len=31) "\tCustom_prefix_Coke Soda = iota", @@ -3546,6 +4228,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=49) "func (n NullSoda) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=53) "func (n *NullSoda) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=34) "\terr := n.Soda.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=57) "func (n *NullSoda) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=25) "type NullSodaStr struct {", (string) (len=9) "\tNullSoda", (string) (len=1) "}", @@ -3584,6 +4297,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=52) "func (n NullSodaStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=56) "func (n *NullSodaStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=34) "\terr := n.Soda.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=60) "func (n *NullSodaStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=70) "\t// Custom_prefix_StartWithNum is a StartNotZero of type StartWithNum.", (string) (len=52) "\tCustom_prefix_StartWithNum StartNotZero = iota + 23", @@ -3820,6 +4564,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=57) "func (n NullStartNotZero) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=61) "func (n *NullStartNotZero) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=42) "\terr := n.StartNotZero.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=65) "func (n *NullStartNotZero) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=33) "type NullStartNotZeroStr struct {", (string) (len=17) "\tNullStartNotZero", (string) (len=1) "}", @@ -3858,6 +4633,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=60) "func (n NullStartNotZeroStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=64) "func (n *NullStartNotZeroStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=42) "\terr := n.StartNotZero.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=68) "func (n *NullStartNotZeroStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=56) "\t// Custom_prefix_Random is a StringEnum of type random.", (string) (len=43) "\tCustom_prefix_Random StringEnum = \"random\"", @@ -4135,6 +4941,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=55) "func (n NullStringEnum) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=59) "func (n *NullStringEnum) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.StringEnum.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=63) "func (n *NullStringEnum) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=31) "type NullStringEnumStr struct {", (string) (len=15) "\tNullStringEnum", (string) (len=1) "}", @@ -4172,5 +5009,36 @@ (string) (len=16) "\terr = n.Scan(x)", (string) (len=11) "\treturn err", (string) (len=1) "}", + (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=58) "func (n NullStringEnumStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=62) "func (n *NullStringEnumStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.StringEnum.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=66) "func (n *NullStringEnumStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", (string) "" } diff --git a/generator/.snapshots/TestCustomPrefixExampleFile b/generator/.snapshots/TestCustomPrefixExampleFile index 271b324..a74d2c7 100644 --- a/generator/.snapshots/TestCustomPrefixExampleFile +++ b/generator/.snapshots/TestCustomPrefixExampleFile @@ -1,4 +1,4 @@ -([]string) (len=4174) { +([]string) (len=5042) { (string) (len=41) "// Code generated by go-enum DO NOT EDIT.", (string) (len=13) "// Version: -", (string) (len=14) "// Revision: -", @@ -257,6 +257,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=51) "func (n NullAnimal) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=55) "func (n *NullAnimal) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=36) "\terr := n.Animal.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=59) "func (n *NullAnimal) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=27) "type NullAnimalStr struct {", (string) (len=11) "\tNullAnimal", (string) (len=1) "}", @@ -295,6 +326,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=54) "func (n NullAnimalStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=58) "func (n *NullAnimalStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=36) "\terr := n.Animal.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=62) "func (n *NullAnimalStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=31) "\t\treturn n.Animal.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=59) "\t// Custom_prefix_Test_lower is a Cases of type Test_lower.", (string) (len=38) "\tCustom_prefix_Test_lower Cases = iota", @@ -536,6 +598,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=50) "func (n NullCases) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=54) "func (n *NullCases) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Cases.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=58) "func (n *NullCases) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=26) "type NullCasesStr struct {", (string) (len=10) "\tNullCases", (string) (len=1) "}", @@ -574,6 +667,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullCasesStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullCasesStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Cases.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullCasesStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Cases.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=49) "\t// Custom_prefix_Black is a Color of type Black.", (string) (len=33) "\tCustom_prefix_Black Color = iota", @@ -835,6 +959,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=50) "func (n NullColor) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=54) "func (n *NullColor) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Color.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=58) "func (n *NullColor) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=26) "type NullColorStr struct {", (string) (len=10) "\tNullColor", (string) (len=1) "}", @@ -873,6 +1028,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullColorStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullColorStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Color.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullColorStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Color.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=60) "\t// Custom_prefix_Black is a ColorWithComment of type Black.", (string) (len=44) "\tCustom_prefix_Black ColorWithComment = iota", @@ -1135,6 +1321,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=61) "func (n NullColorWithComment) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=65) "func (n *NullColorWithComment) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=46) "\terr := n.ColorWithComment.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=69) "func (n *NullColorWithComment) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=37) "type NullColorWithCommentStr struct {", (string) (len=21) "\tNullColorWithComment", (string) (len=1) "}", @@ -1173,6 +1390,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=64) "func (n NullColorWithCommentStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=68) "func (n *NullColorWithCommentStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=46) "\terr := n.ColorWithComment.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=72) "func (n *NullColorWithCommentStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=41) "\t\treturn n.ColorWithComment.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=61) "\t// Custom_prefix_Black is a ColorWithComment2 of type Black.", (string) (len=45) "\tCustom_prefix_Black ColorWithComment2 = iota", @@ -1435,6 +1683,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=62) "func (n NullColorWithComment2) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=66) "func (n *NullColorWithComment2) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment2.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=70) "func (n *NullColorWithComment2) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=38) "type NullColorWithComment2Str struct {", (string) (len=22) "\tNullColorWithComment2", (string) (len=1) "}", @@ -1473,6 +1752,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=65) "func (n NullColorWithComment2Str) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=69) "func (n *NullColorWithComment2Str) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment2.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=73) "func (n *NullColorWithComment2Str) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment2.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=61) "\t// Custom_prefix_Black is a ColorWithComment3 of type Black.", (string) (len=45) "\tCustom_prefix_Black ColorWithComment3 = iota", @@ -1751,6 +2061,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=62) "func (n NullColorWithComment3) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=66) "func (n *NullColorWithComment3) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment3.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=70) "func (n *NullColorWithComment3) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=38) "type NullColorWithComment3Str struct {", (string) (len=22) "\tNullColorWithComment3", (string) (len=1) "}", @@ -1789,6 +2130,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=65) "func (n NullColorWithComment3Str) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=69) "func (n *NullColorWithComment3Str) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment3.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=73) "func (n *NullColorWithComment3Str) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment3.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=18) "\t// Skipped value.", (string) (len=15) "\t// Placeholder", @@ -2067,6 +2439,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=62) "func (n NullColorWithComment4) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=66) "func (n *NullColorWithComment4) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment4.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=70) "func (n *NullColorWithComment4) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=38) "type NullColorWithComment4Str struct {", (string) (len=22) "\tNullColorWithComment4", (string) (len=1) "}", @@ -2105,15 +2508,46 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", - (string) (len=7) "const (", - (string) (len=57) "\t// Custom_prefix_Unknown is a Enum64bit of type Unknown.", - (string) (len=39) "\tCustom_prefix_Unknown Enum64bit = iota", - (string) (len=53) "\t// Custom_prefix_E2P15 is a Enum64bit of type E2P15.", - (string) (len=45) "\tCustom_prefix_E2P15 Enum64bit = iota + 32767", - (string) (len=53) "\t// Custom_prefix_E2P16 is a Enum64bit of type E2P16.", - (string) (len=45) "\tCustom_prefix_E2P16 Enum64bit = iota + 65534", - (string) (len=53) "\t// Custom_prefix_E2P17 is a Enum64bit of type E2P17.", - (string) (len=46) "\tCustom_prefix_E2P17 Enum64bit = iota + 131069", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=65) "func (n NullColorWithComment4Str) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=69) "func (n *NullColorWithComment4Str) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=47) "\terr := n.ColorWithComment4.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=73) "func (n *NullColorWithComment4Str) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=42) "\t\treturn n.ColorWithComment4.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", + (string) (len=7) "const (", + (string) (len=57) "\t// Custom_prefix_Unknown is a Enum64bit of type Unknown.", + (string) (len=39) "\tCustom_prefix_Unknown Enum64bit = iota", + (string) (len=53) "\t// Custom_prefix_E2P15 is a Enum64bit of type E2P15.", + (string) (len=45) "\tCustom_prefix_E2P15 Enum64bit = iota + 32767", + (string) (len=53) "\t// Custom_prefix_E2P16 is a Enum64bit of type E2P16.", + (string) (len=45) "\tCustom_prefix_E2P16 Enum64bit = iota + 65534", + (string) (len=53) "\t// Custom_prefix_E2P17 is a Enum64bit of type E2P17.", + (string) (len=46) "\tCustom_prefix_E2P17 Enum64bit = iota + 131069", (string) (len=53) "\t// Custom_prefix_E2P18 is a Enum64bit of type E2P18.", (string) (len=46) "\tCustom_prefix_E2P18 Enum64bit = iota + 262140", (string) (len=53) "\t// Custom_prefix_E2P19 is a Enum64bit of type E2P19.", @@ -2406,6 +2840,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=54) "func (n NullEnum64bit) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=58) "func (n *NullEnum64bit) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=39) "\terr := n.Enum64bit.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=62) "func (n *NullEnum64bit) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=30) "type NullEnum64bitStr struct {", (string) (len=14) "\tNullEnum64bit", (string) (len=1) "}", @@ -2444,6 +2909,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=57) "func (n NullEnum64bitStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=61) "func (n *NullEnum64bitStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=39) "\terr := n.Enum64bit.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=65) "func (n *NullEnum64bitStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=34) "\t\treturn n.Enum64bit.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=51) "\t// Custom_prefix_Toyota is a Model of type Toyota.", (string) (len=34) "\tCustom_prefix_Toyota Model = iota", @@ -2689,6 +3185,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=50) "func (n NullModel) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=54) "func (n *NullModel) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Model.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=58) "func (n *NullModel) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=26) "type NullModelStr struct {", (string) (len=10) "\tNullModel", (string) (len=1) "}", @@ -2727,6 +3254,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullModelStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullModelStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=35) "\terr := n.Model.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullModelStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=30) "\t\treturn n.Model.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=66) "\t// Custom_prefix_Продам is a NonASCII of type Продам.", (string) (len=50) "\tCustom_prefix_Продам NonASCII = iota + 1114", @@ -2968,6 +3526,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=53) "func (n NullNonASCII) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=57) "func (n *NullNonASCII) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=38) "\terr := n.NonASCII.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=61) "func (n *NullNonASCII) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=29) "type NullNonASCIIStr struct {", (string) (len=13) "\tNullNonASCII", (string) (len=1) "}", @@ -3006,6 +3595,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=56) "func (n NullNonASCIIStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=60) "func (n *NullNonASCIIStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=38) "\terr := n.NonASCII.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=64) "func (n *NullNonASCIIStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=33) "\t\treturn n.NonASCII.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=65) "\t// Custom_prefix_TestHyphen is a Sanitizing of type Test-Hyphen.", (string) (len=43) "\tCustom_prefix_TestHyphen Sanitizing = iota", @@ -3267,6 +3887,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=55) "func (n NullSanitizing) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=59) "func (n *NullSanitizing) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.Sanitizing.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=63) "func (n *NullSanitizing) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=31) "type NullSanitizingStr struct {", (string) (len=15) "\tNullSanitizing", (string) (len=1) "}", @@ -3305,6 +3956,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=58) "func (n NullSanitizingStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=62) "func (n *NullSanitizingStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.Sanitizing.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=66) "func (n *NullSanitizingStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.Sanitizing.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=46) "\t// Custom_prefix_Coke is a Soda of type Coke.", (string) (len=31) "\tCustom_prefix_Coke Soda = iota", @@ -3546,6 +4228,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=49) "func (n NullSoda) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=53) "func (n *NullSoda) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=34) "\terr := n.Soda.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=57) "func (n *NullSoda) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=25) "type NullSodaStr struct {", (string) (len=9) "\tNullSoda", (string) (len=1) "}", @@ -3584,6 +4297,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=52) "func (n NullSodaStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=56) "func (n *NullSodaStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=34) "\terr := n.Soda.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=60) "func (n *NullSodaStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=29) "\t\treturn n.Soda.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=70) "\t// Custom_prefix_StartWithNum is a StartNotZero of type StartWithNum.", (string) (len=52) "\tCustom_prefix_StartWithNum StartNotZero = iota + 23", @@ -3820,6 +4564,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=57) "func (n NullStartNotZero) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=61) "func (n *NullStartNotZero) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=42) "\terr := n.StartNotZero.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=65) "func (n *NullStartNotZero) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=33) "type NullStartNotZeroStr struct {", (string) (len=17) "\tNullStartNotZero", (string) (len=1) "}", @@ -3858,6 +4633,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=60) "func (n NullStartNotZeroStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=64) "func (n *NullStartNotZeroStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=42) "\terr := n.StartNotZero.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=68) "func (n *NullStartNotZeroStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=37) "\t\treturn n.StartNotZero.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=7) "const (", (string) (len=56) "\t// Custom_prefix_Random is a StringEnum of type random.", (string) (len=43) "\tCustom_prefix_Random StringEnum = \"random\"", @@ -4135,6 +4941,37 @@ (string) (len=11) "\treturn err", (string) (len=1) "}", (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=55) "func (n NullStringEnum) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=59) "func (n *NullStringEnum) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.StringEnum.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=63) "func (n *NullStringEnum) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", + (string) "", (string) (len=31) "type NullStringEnumStr struct {", (string) (len=15) "\tNullStringEnum", (string) (len=1) "}", @@ -4172,5 +5009,36 @@ (string) (len=16) "\terr = n.Scan(x)", (string) (len=11) "\treturn err", (string) (len=1) "}", + (string) "", + (string) (len=53) "// MarshalText implements the text marshaller method.", + (string) (len=58) "func (n NullStringEnumStr) MarshalText() ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.MarshalText()", + (string) (len=2) "\t}", + (string) (len=21) "\treturn []byte{}, nil", + (string) (len=1) "}", + (string) "", + (string) (len=57) "// UnmarshalText implements the text unmarshaller method.", + (string) (len=62) "func (n *NullStringEnumStr) UnmarshalText(text []byte) error {", + (string) (len=13) "\tn.Set = true", + (string) (len=20) "\tif len(text) == 0 {", + (string) (len=17) "\t\tn.Valid = false", + (string) (len=12) "\t\treturn nil", + (string) (len=2) "\t}", + (string) (len=40) "\terr := n.StringEnum.UnmarshalText(text)", + (string) (len=23) "\tn.Valid = (err == nil)", + (string) (len=11) "\treturn err", + (string) (len=1) "}", + (string) "", + (string) (len=74) "// AppendText appends the textual representation of itself to the end of b", + (string) (len=74) "// (allocating a larger slice if necessary) and returns the updated slice.", + (string) (len=2) "//", + (string) (len=77) "// Implementations must not retain b, nor mutate any bytes within b[:len(b)].", + (string) (len=66) "func (n *NullStringEnumStr) AppendText(b []byte) ([]byte, error) {", + (string) (len=13) "\tif n.Valid {", + (string) (len=35) "\t\treturn n.StringEnum.AppendText(b)", + (string) (len=2) "\t}", + (string) (len=14) "\treturn b, nil", + (string) (len=1) "}", (string) "" } diff --git a/generator/enum.tmpl b/generator/enum.tmpl index 8d214a5..5103cf5 100644 --- a/generator/enum.tmpl +++ b/generator/enum.tmpl @@ -308,6 +308,37 @@ func (n *Null{{.enum.Name}}) UnmarshalJSON(b []byte) error { err = n.Scan(x) return err } + +// MarshalText implements the text marshaller method. +func (n Null{{.enum.Name}}) MarshalText() ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.MarshalText() + } + return []byte{}, nil +} + +// UnmarshalText implements the text unmarshaller method. +func (n *Null{{.enum.Name}}) UnmarshalText(text []byte) error { + n.Set = true + if len(text) == 0 { + n.Valid = false + return nil + } + err := n.{{.enum.Name}}.UnmarshalText(text) + n.Valid = (err == nil) + return err +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (n *Null{{.enum.Name}}) AppendText(b []byte) ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.AppendText(b) + } + return b, nil +} {{ end }} {{ end }} @@ -350,6 +381,37 @@ func (n *Null{{.enum.Name}}Str) UnmarshalJSON(b []byte) error { err = n.Scan(x) return err } + +// MarshalText implements the text marshaller method. +func (n Null{{.enum.Name}}Str) MarshalText() ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.MarshalText() + } + return []byte{}, nil +} + +// UnmarshalText implements the text unmarshaller method. +func (n *Null{{.enum.Name}}Str) UnmarshalText(text []byte) error { + n.Set = true + if len(text) == 0 { + n.Valid = false + return nil + } + err := n.{{.enum.Name}}.UnmarshalText(text) + n.Valid = (err == nil) + return err +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (n *Null{{.enum.Name}}Str) AppendText(b []byte) ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.AppendText(b) + } + return b, nil +} {{ end }} {{ end }} diff --git a/generator/enum_string.tmpl b/generator/enum_string.tmpl index ee929d3..4965b05 100644 --- a/generator/enum_string.tmpl +++ b/generator/enum_string.tmpl @@ -353,6 +353,37 @@ func (n *Null{{.enum.Name}}) UnmarshalJSON(b []byte) error { err = n.Scan(x) return err } + +// MarshalText implements the text marshaller method. +func (n Null{{.enum.Name}}) MarshalText() ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.MarshalText() + } + return []byte{}, nil +} + +// UnmarshalText implements the text unmarshaller method. +func (n *Null{{.enum.Name}}) UnmarshalText(text []byte) error { + n.Set = true + if len(text) == 0 { + n.Valid = false + return nil + } + err := n.{{.enum.Name}}.UnmarshalText(text) + n.Valid = (err == nil) + return err +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (n *Null{{.enum.Name}}) AppendText(b []byte) ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.AppendText(b) + } + return b, nil +} {{ end }} {{ end }} @@ -395,6 +426,37 @@ func (n *Null{{.enum.Name}}Str) UnmarshalJSON(b []byte) error { err = n.Scan(x) return err } + +// MarshalText implements the text marshaller method. +func (n Null{{.enum.Name}}Str) MarshalText() ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.MarshalText() + } + return []byte{}, nil +} + +// UnmarshalText implements the text unmarshaller method. +func (n *Null{{.enum.Name}}Str) UnmarshalText(text []byte) error { + n.Set = true + if len(text) == 0 { + n.Valid = false + return nil + } + err := n.{{.enum.Name}}.UnmarshalText(text) + n.Valid = (err == nil) + return err +} + +// AppendText appends the textual representation of itself to the end of b +// (allocating a larger slice if necessary) and returns the updated slice. +// +// Implementations must not retain b, nor mutate any bytes within b[:len(b)]. +func (n *Null{{.enum.Name}}Str) AppendText(b []byte) ([]byte, error) { + if n.Valid { + return n.{{.enum.Name}}.AppendText(b) + } + return b, nil +} {{ end }} {{ end }}