-
Notifications
You must be signed in to change notification settings - Fork 35
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
tlb support Unmarshal a cell to a message struct and opCode #279
Comments
For example, Old codetype TokenExcesses struct {
QueryId uint64
}
type TokenExcessesWithOpCode struct {
OpCode uint32
QueryId uint64
}
func parseTokenExcesses(rawBody string) (*TokenExcesses, error) {
cells, err := boc.DeserializeBocHex(rawBody)
if err != nil {
return nil, err
}
//define new struct with opCode
ex := TokenExcessesWithOpCode{}
err = Unmarshal(cells[0], &ex)
if err != nil {
return nil, err
}
//return struct without opCode
return &TokenExcesses{QueryId: ex.QueryId}, nil
}
func Test_Unmarshal(t *testing.T) {
rawBody := "b5ee9c7201010101000e000018d53276db546de4efe9d175f0"
ex, err := parseTokenExcesses(rawBody)
assert.NoError(t, err)
t.Logf("%+v", ex)
} New codetype TokenExcesses struct {
QueryId uint64
}
func newParseTokenExcesses(rawBody string) (*TokenExcesses, error) {
cells, err := boc.DeserializeBocHex(rawBody)
if err != nil {
return nil, err
}
ex := TokenExcesses{}
opCode, err := UnmarshalMessage(cells[0], &ex)
if err != nil {
return nil, err
}
if opCode != uint32(0xd53276db) {
return nil, fmt.Errorf("unexpected opCode: %x", opCode)
}
//return struct without opCode
return &ex, nil
} |
studyzy
added a commit
to studyzy/tongo
that referenced
this issue
Jul 26, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently, tlb only have:
func Unmarshal(c *boc.Cell, o any) error
but when the Cell is a message with OpCode, I must define a struct with
OpCode uint32
.What I want?
I want to have a new function:
So I don't need define new message struct with OpCode.
The text was updated successfully, but these errors were encountered: