Experimental: Mutation functions. These allow scalars in an already created buffer to be updated in-place. Since by default scalars are stored in the smallest possible space, the new value may not fit, in which case these functions return false. To avoid this, you can construct the values you intend to mutate using Builder::ForceMinimumBitWidth.
| 659 | // To avoid this, you can construct the values you intend to mutate using |
| 660 | // Builder::ForceMinimumBitWidth. |
| 661 | bool MutateInt(int64_t i) { |
| 662 | if (type_ == FBT_INT) { |
| 663 | return Mutate(data_, i, parent_width_, WidthI(i)); |
| 664 | } else if (type_ == FBT_INDIRECT_INT) { |
| 665 | return Mutate(Indirect(), i, byte_width_, WidthI(i)); |
| 666 | } else if (type_ == FBT_UINT) { |
| 667 | auto u = static_cast<uint64_t>(i); |
| 668 | return Mutate(data_, u, parent_width_, WidthU(u)); |
| 669 | } else if (type_ == FBT_INDIRECT_UINT) { |
| 670 | auto u = static_cast<uint64_t>(i); |
| 671 | return Mutate(Indirect(), u, byte_width_, WidthU(u)); |
| 672 | } else { |
| 673 | return false; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | bool MutateBool(bool b) { |
| 678 | return type_ == FBT_BOOL && Mutate(data_, b, parent_width_, BIT_WIDTH_8); |