Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hashmap Marshal has some bug #312

Open
duruo850 opened this issue Oct 19, 2024 · 0 comments
Open

Hashmap Marshal has some bug #312

duruo850 opened this issue Oct 19, 2024 · 0 comments

Comments

@duruo850
Copy link

These codes run normally at times, but sometimes they throw errors: "not enough bits" ? why?

`package tonapiservice

import (
"fmt"
"testing"

"github.com/tonkeeper/tongo/boc"
"github.com/tonkeeper/tongo/tlb"

)

func TestHashmapE(t *testing.T) {
// Hashmap的序列化有bug,数据一样的情况下,有时候会提示not enouth bits.

c := boc.NewCell()
//write function id to cell
if err := c.WriteUint(uint64(0), 32); err != nil {
	panic(err)
}

type BuyInfo struct {
	StartLuckNum uint16 // 开始的彩票号码,从1开始
	Amount       uint16 // 购买的nifi数量
}

// go map
orders := map[uint32]BuyInfo{
	1: {StartLuckNum: 1, Amount: 2},
	2: {StartLuckNum: 3, Amount: 4},
	3: {StartLuckNum: 5, Amount: 6},
	4: {StartLuckNum: 7, Amount: 8},
	5: {StartLuckNum: 9, Amount: 10},
	6: {StartLuckNum: 11, Amount: 12},
}

type Msg struct {
	RoundId uint32
	Orders  tlb.Hashmap[tlb.Uint32, BuyInfo] // 订单号码:购买信息
}

// elb map
msg := Msg{
	RoundId: 10000,
}
var keys []tlb.Uint32
var values []BuyInfo
for key, value := range orders {
	keys = append(keys, tlb.Uint32(key))
	values = append(values, value)
}
msg.Orders = tlb.NewHashmap(keys, values)

// 序列化
if err := tlb.Marshal(c, msg); err != nil {
	panic(err)
}

b, _ := c.ToBoc()
fmt.Println(b)

}`

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

No branches or pull requests

1 participant