Skip to content

Hashmap Marshal has some bug #312

@duruo850

Description

@duruo850

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)

}`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions