diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-12 16:17:34 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-12 16:17:34 -0700 |
commit | c55326b0cb6994bb802cf6aac4a296acfb0e41ff (patch) | |
tree | 020cb033adb3809bcc8ffed5f56ba8d167b32dd1 /lib/btrfs/btrfsitem/item_fileextent.go | |
parent | cfcc753dc8906817e15b1b7c36b4dc12462d12e4 (diff) | |
parent | acbbfafa07922b458506b91a58f3a082da453fd1 (diff) |
Merge branch 'lukeshu/enums'
Diffstat (limited to 'lib/btrfs/btrfsitem/item_fileextent.go')
-rw-r--r-- | lib/btrfs/btrfsitem/item_fileextent.go | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/lib/btrfs/btrfsitem/item_fileextent.go b/lib/btrfs/btrfsitem/item_fileextent.go index 30a14ef..6b08897 100644 --- a/lib/btrfs/btrfsitem/item_fileextent.go +++ b/lib/btrfs/btrfsitem/item_fileextent.go @@ -101,11 +101,17 @@ func (o FileExtent) MarshalBinary() ([]byte, error) { type FileExtentType uint8 const ( - FILE_EXTENT_INLINE = FileExtentType(iota) + FILE_EXTENT_INLINE FileExtentType = iota FILE_EXTENT_REG FILE_EXTENT_PREALLOC ) +var fileExtentTypeNames = []string{ + "inline", + "regular", + "prealloc", +} + func (o FileExtent) Size() (int64, error) { switch o.Type { case FILE_EXTENT_INLINE: @@ -118,14 +124,9 @@ func (o FileExtent) Size() (int64, error) { } func (fet FileExtentType) String() string { - names := map[FileExtentType]string{ - FILE_EXTENT_INLINE: "inline", - FILE_EXTENT_REG: "regular", - FILE_EXTENT_PREALLOC: "prealloc", - } - name, ok := names[fet] - if !ok { - name = "unknown" + name := "unknown" + if int(fet) < len(fileExtentTypeNames) { + name = fileExtentTypeNames[fet] } return fmt.Sprintf("%d (%s)", fet, name) } @@ -133,22 +134,23 @@ func (fet FileExtentType) String() string { type CompressionType uint8 const ( - COMPRESS_NONE = CompressionType(iota) + COMPRESS_NONE CompressionType = iota COMPRESS_ZLIB COMPRESS_LZO COMPRESS_ZSTD ) +var compressionTypeNames = []string{ + "none", + "zlib", + "lzo", + "zstd", +} + func (ct CompressionType) String() string { - names := map[CompressionType]string{ - COMPRESS_NONE: "none", - COMPRESS_ZLIB: "zlib", - COMPRESS_LZO: "lzo", - COMPRESS_ZSTD: "zstd", - } - name, ok := names[ct] - if !ok { - name = "unknown" + name := "unknown" + if int(ct) < len(compressionTypeNames) { + name = compressionTypeNames[ct] } return fmt.Sprintf("%d (%s)", ct, name) } |