Switch to crc32 as TOML cannot encode MaxUint64

This commit is contained in:
Elara 2023-01-12 18:29:31 -08:00
parent 928b5e8bab
commit 9442934541
2 changed files with 7 additions and 23 deletions

View File

@ -1,8 +1,7 @@
package main package main
import ( import (
"hash/crc64" "hash/crc32"
"io"
"os" "os"
"github.com/pelletier/go-toml/v2" "github.com/pelletier/go-toml/v2"
@ -28,17 +27,8 @@ func genIDCmd(c *cli.Context) error {
} }
fl.Close() fl.Close()
hash := crc64.New(crc64.MakeTable(crc64.ISO))
for i, item := range tr.Items { for i, item := range tr.Items {
hash.Reset() tr.Items[i].ID = crc32.ChecksumIEEE([]byte(item.Value))
_, err := io.WriteString(hash, item.Value)
if err != nil {
return err
}
tr.Items[i].ID = hash.Sum64()
} }
fl, err = os.Create(c.Args().First()) fl, err = os.Create(c.Args().First())

View File

@ -1,8 +1,7 @@
package translate package translate
import ( import (
"hash/crc64" "hash/crc32"
"io"
"io/fs" "io/fs"
"os" "os"
"path/filepath" "path/filepath"
@ -17,11 +16,11 @@ type Translations struct {
} }
type Translation struct { type Translation struct {
ID uint64 `toml:"id"` ID uint32 `toml:"id"`
Value string `toml:"value"` Value string `toml:"value"`
} }
type Dictionary map[uint64]string type Dictionary map[uint32]string
type Catalog map[language.Tag]Dictionary type Catalog map[language.Tag]Dictionary
type Translator struct { type Translator struct {
@ -107,11 +106,6 @@ func toDict(tr Translations) Dictionary {
return out return out
} }
func hashString(s string) uint64 { func hashString(s string) uint32 {
hash := crc64.New(crc64.MakeTable(crc64.ISO)) return crc32.ChecksumIEEE([]byte(s))
_, err := io.WriteString(hash, s)
if err != nil {
return 0
}
return hash.Sum64()
} }