Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Wrong mantis for bitwise/flaggable enums in G #4131

Merged
merged 5 commits into from
Feb 5, 2024
Merged

Conversation

rkodev
Copy link
Contributor

@rkodev rkodev commented Feb 5, 2024

Fixes #3936
Fixes microsoftgraph/msgraph-beta-sdk-go#366

Resolves issue with left shift algorithm used in String() operation to assign a value to a multi value enum

Example output

// Supported platform types.
type DeviceManagementConfigurationPlatforms int

// enum values for multi values are base 2
const (
	// Default. No platform type specified.
	NONE_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 1
	// Settings for Android platform.
	ANDROID_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 2
	// Settings for iOS platform.
	IOS_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 4
	// Settings for MacOS platform.
	MACOS_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 8
	// Windows 10 X.
	WINDOWS10X_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 16
	// Settings for Windows 10 platform.
	WINDOWS10_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 32
	// Settings for Linux platform.
	LINUX_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 64
	// Evolvable enumeration sentinel value. Do not use.
	UNKNOWNFUTUREVALUE_DEVICEMANAGEMENTCONFIGURATIONPLATFORMS = 128
)


func (i DeviceManagementConfigurationPlatforms) String() string {
	var values []string
	options := []string{"none", "android", "iOS", "macOS", "windows10X", "windows10", "linux", "unknownFutureValue"}
	for p := 0; p < 8; p++ {
		mantis := DeviceManagementConfigurationPlatforms(int(math.Pow(2, float64(p))))
		if i&mantis == mantis {
			values = append(values, options[p])
		}
	}
	return strings.Join(values, ",")
}

@rkodev rkodev requested a review from a team as a code owner February 5, 2024 15:17
Copy link

sonarqubecloud bot commented Feb 5, 2024

@rkodev rkodev merged commit 6077e9f into main Feb 5, 2024
185 of 186 checks passed
@rkodev rkodev deleted the fix/go-bitwise-enums branch February 5, 2024 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong mantis for bitwise/flaggable enums in Go Serialization of platforms not returning expected value.
2 participants