Examples: query, "exact match", wildcard*, wild?ard, wild*rd
Fuzzy search: cake~ (finds cakes, bake)
Term boost: "red velvet"^4, chocolate^2
Field grouping: tags:(+work -"fun-stuff")
Escape special characters +-&|!(){}[]^"~*?:\ - e.g. \+ \* \!
Range search: properties.timestamp:[1587729413488 TO *] (inclusive), properties.title:{A TO Z}(excluding A and Z)
Combinations: chocolate AND vanilla, chocolate OR vanilla, (chocolate OR vanilla) NOT "vanilla pudding"
Field search: properties.title:"The Title" AND text
Answered
What is this means in "builder.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)"?

I'm not sure if this is a simple question, but I'd like to know if the following two lines of code are equivalent:

builder.store_uint(0, 1 + 4 + 4 + 64 + 32 + 1 + 1)
builder.store_uint(0, 107)

I understand that the first line uses the + operator to add several values together, but I'm not sure why it was written that way. Is there any difference in the output of the two lines, or is it just a matter of clarity?"

This question was imported from Telegram Chat:
https://t.me/tondev_eng/1250

  
  
Posted one year ago
Howard Peng
10 × 1 Administrator
Votes Newest

Answers 2


Yes, the two lines of code are equivalent in terms of their output. Both lines store the value 107 as an unsigned integer with a bit size of 8.

The reason why the first line was written with the + operator is likely for clarity or readability. Breaking down the value 107 into its component parts and adding them together may have been intended to make the code more self-explanatory or easier to understand.

There may be other reasons why the first line of code was written that way, such as compatibility with other parts of the codebase or consistency with existing coding conventions, but without further context it's difficult to say for certain.

  
  
Posted one year ago

Writing 107 as a sum improves readability. Also, it reminds that sometimes value to be stored (0) must be changed -- for example, if body is stored in a reference.

https://ton.org/docs/develop/smart-contracts/messages

Indeed, in the elector code above we serialize coins' amounts via .store_coins(grams) but then just put a string of zeros with length equal to 1 + 4 + 4 + 64 + 32 + 1 + 1. What is it?

First bit stands for empty extra-currencies dictionary.
Then we have two 4-bit long fields. They encode 0 as VarUInteger 16. In fact, since ihr_fee and fwd_fee will be overwritten, we may as well put there zeroes.
Then we put zero to created_lt and created_at fields. Those fields will be overwritten as well; however, in contrast to fees, these fields have a fixed length and are thus encoded as 64- and 32-bit long strings.
(we had alredy serialized the message header and passed to init/body at that moment)
Next zero-bit means that there is no init field.
The last zero-bit means that msg_body will be serialized in-place.
After that, message body (with arbitrary layout) is encoded.
1
1
Posted one year ago
2K Views
2 Answers
one year ago
one year ago
Tags