API-15 implement runtime serialization and deserialization for new tolk ABI#451
API-15 implement runtime serialization and deserialization for new tolk ABI#451domikedos wants to merge 7 commits intotolk/new-abifrom
Conversation
| if u.Prefix.Len > 64 { | ||
| return fmt.Errorf("union prefix length must be less than 64") |
There was a problem hiding this comment.
тут ошибка не сходится с условием
либо Len >= 64
либо "be less or equal than 64"
| eatPrefix := ty.Variants[0].PrefixEatInPlace | ||
| if prefixLen > 64 { | ||
| // todo: maybe prefix len can be bigger than 64? | ||
| return fmt.Errorf("union prefix length must be less than 64") |
There was a problem hiding this comment.
| return fmt.Errorf("union prefix length must be less than 64") | |
| return fmt.Errorf("union prefix length must be less or equal than 64") |
| if val != -35132 { | ||
| t.Errorf("val != -35132, got %v", val) | ||
| } |
There was a problem hiding this comment.
nit:
вообще много где удобнее было бы assert.Equal(t, val, -35132) https://pkg.go.dev/github.com/stretchr/testify/assert
| pathPrefix := jsonFilesPath + inputFilename | ||
| actual, err := json.MarshalIndent(v, "", " ") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| err = os.WriteFile(pathPrefix+".output.json", actual, os.ModePerm) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| expected, err := os.ReadFile(pathPrefix + ".json") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if !bytes.Equal(actual, expected) { | ||
| t.Errorf("%s got different results", pathPrefix) | ||
| } |
There was a problem hiding this comment.
вынести бы этот повторяющийся кусок
| func ConcatPrefixAndSuffixIfExists(prefix, suffix []byte) []byte { | ||
| if len(suffix) == 0 { | ||
| return prefix | ||
| } | ||
| prefix = prefix[:len(prefix)-1] // remove '}' | ||
| suffix[0] = ',' // replace '{' with ',' | ||
| result := make([]byte, 0, len(prefix)+len(suffix)) | ||
| result = append(result, prefix...) | ||
| result = append(result, suffix...) | ||
| return result | ||
| } |
There was a problem hiding this comment.
На всякий prefix бы тоже проверил
| func ConcatPrefixAndSuffixIfExists(prefix, suffix []byte) []byte { | |
| if len(suffix) == 0 { | |
| return prefix | |
| } | |
| prefix = prefix[:len(prefix)-1] // remove '}' | |
| suffix[0] = ',' // replace '{' with ',' | |
| result := make([]byte, 0, len(prefix)+len(suffix)) | |
| result = append(result, prefix...) | |
| result = append(result, suffix...) | |
| return result | |
| } | |
| func ConcatJsonObjects(prefix, suffix []byte) []byte { | |
| if len(suffix) == 0 { | |
| return prefix | |
| } | |
| if len(prefix) == 0 { | |
| return suffix | |
| } | |
| prefix = prefix[:len(prefix)-1] // remove '}' | |
| suffix[0] = ',' // replace '{' with ',' | |
| result := make([]byte, 0, len(prefix)+len(suffix)) | |
| result = append(result, prefix...) | |
| result = append(result, suffix...) | |
| return result | |
| } |
| func (s *Struct) RemoveField(field string) { | ||
| for i, name := range s.fieldNames { | ||
| if name == field { | ||
| s.fieldNames[i] = "|" // impossible symbol for field name in Tolk language |
There was a problem hiding this comment.
Это как будто потом нигде не учитывается, зато может повлиять на сравнение и маршалинг, почему не отфильтровать?
| s.fieldNames = append(s.fieldNames, stringKey) | ||
| s.fieldValues = append(s.fieldValues, val) |
There was a problem hiding this comment.
Порядок полей в json не гарантируется, если вдруг мы планируем читать json откуда-нибудь еще
| return nil | ||
| } | ||
| } | ||
| // todo: maybe return err? |
There was a problem hiding this comment.
Думаю, было бы отлично)
Unknown может быть вполне себе существующим членом енума
|
|
||
| if alias.CustomUnpackFromSlice { | ||
| // todo: maybe simply return error? | ||
| fmt.Println("WARNING! alias has custom unpack method. Default unpacking can be incorrect!") |
There was a problem hiding this comment.
Да, лучше ошибку вернуть, если мы не уверены как распаковывать
| // todo: maybe simply return error? | ||
| fmt.Println("WARNING! alias has custom pack method. Default packing can be incorrect!") |
No description provided.