github.com/mutagen-io/mutagen@v0.18.0-rc1/pkg/synchronization/scan_mode.go (about)

     1  package synchronization
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  // IsDefault indicates whether or not the scan mode is ScanMode_ScanModeDefault.
     8  func (m ScanMode) IsDefault() bool {
     9  	return m == ScanMode_ScanModeDefault
    10  }
    11  
    12  // MarshalText implements encoding.TextMarshaler.MarshalText.
    13  func (m ScanMode) MarshalText() ([]byte, error) {
    14  	var result string
    15  	switch m {
    16  	case ScanMode_ScanModeDefault:
    17  	case ScanMode_ScanModeFull:
    18  		result = "full"
    19  	case ScanMode_ScanModeAccelerated:
    20  		result = "accelerated"
    21  	default:
    22  		result = "unknown"
    23  	}
    24  	return []byte(result), nil
    25  }
    26  
    27  // UnmarshalText implements encoding.TextUnmarshaler.UnmarshalText.
    28  func (m *ScanMode) UnmarshalText(textBytes []byte) error {
    29  	// Convert the bytes to a string.
    30  	text := string(textBytes)
    31  
    32  	// Convert to a scan mode.
    33  	switch text {
    34  	case "full":
    35  		*m = ScanMode_ScanModeFull
    36  	case "accelerated":
    37  		*m = ScanMode_ScanModeAccelerated
    38  	default:
    39  		return fmt.Errorf("unknown scan mode specification: %s", text)
    40  	}
    41  
    42  	// Success.
    43  	return nil
    44  }
    45  
    46  // Supported indicates whether or not a particular scan mode is a valid,
    47  // non-default value.
    48  func (m ScanMode) Supported() bool {
    49  	switch m {
    50  	case ScanMode_ScanModeFull:
    51  		return true
    52  	case ScanMode_ScanModeAccelerated:
    53  		return true
    54  	default:
    55  		return false
    56  	}
    57  }
    58  
    59  // Description returns a human-readable description of a scan mode.
    60  func (m ScanMode) Description() string {
    61  	switch m {
    62  	case ScanMode_ScanModeDefault:
    63  		return "Default"
    64  	case ScanMode_ScanModeFull:
    65  		return "Full"
    66  	case ScanMode_ScanModeAccelerated:
    67  		return "Accelerated"
    68  	default:
    69  		return "Unknown"
    70  	}
    71  }