Skip to content

API-15 implement runtime serialization and deserialization for new tolk ABI#451

Open
domikedos wants to merge 7 commits intotolk/new-abifrom
tolk/runtime
Open

API-15 implement runtime serialization and deserialization for new tolk ABI#451
domikedos wants to merge 7 commits intotolk/new-abifrom
tolk/runtime

Conversation

@domikedos
Copy link
Collaborator

No description provided.

@domikedos domikedos changed the title Tolk/runtime implement runtime serialization and deserialization for new tolk ABI Feb 12, 2026
@domikedos domikedos changed the title implement runtime serialization and deserialization for new tolk ABI API-15 implement runtime serialization and deserialization for new tolk ABI Feb 12, 2026
Comment on lines +72 to +73
if u.Prefix.Len > 64 {
return fmt.Errorf("union prefix length must be less than 64")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут ошибка не сходится с условием
либо 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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return fmt.Errorf("union prefix length must be less than 64")
return fmt.Errorf("union prefix length must be less or equal than 64")

Comment on lines +41 to +43
if val != -35132 {
t.Errorf("val != -35132, got %v", val)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
вообще много где удобнее было бы assert.Equal(t, val, -35132) https://pkg.go.dev/github.com/stretchr/testify/assert

Comment on lines +221 to +236
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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вынести бы этот повторяющийся кусок

Comment on lines +3 to +13
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
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На всякий prefix бы тоже проверил

Suggested change
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это как будто потом нигде не учитывается, зато может повлиять на сравнение и маршалинг, почему не отфильтровать?

Comment on lines +283 to +284
s.fieldNames = append(s.fieldNames, stringKey)
s.fieldValues = append(s.fieldValues, val)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Порядок полей в json не гарантируется, если вдруг мы планируем читать json откуда-нибудь еще

return nil
}
}
// todo: maybe return err?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думаю, было бы отлично)
Unknown может быть вполне себе существующим членом енума


if alias.CustomUnpackFromSlice {
// todo: maybe simply return error?
fmt.Println("WARNING! alias has custom unpack method. Default unpacking can be incorrect!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, лучше ошибку вернуть, если мы не уверены как распаковывать

Comment on lines +453 to +454
// todo: maybe simply return error?
fmt.Println("WARNING! alias has custom pack method. Default packing can be incorrect!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше ошибку)

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.

2 participants