Packing.sol 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140
  1. // SPDX-License-Identifier: MIT
  2. // This file was procedurally generated from scripts/generate/templates/Packing.js.
  3. pragma solidity ^0.8.20;
  4. /**
  5. * @dev Helper library packing and unpacking multiple values into bytesXX.
  6. *
  7. * Example usage:
  8. *
  9. * ```solidity
  10. * library MyPacker {
  11. * type MyType is bytes32;
  12. *
  13. * function _pack(address account, bytes4 selector, uint64 period) external pure returns (MyType) {
  14. * bytes12 subpack = Packing.pack_4_8(selector, bytes8(period));
  15. * bytes32 pack = Packing.pack_20_12(bytes20(account), subpack);
  16. * return MyType.wrap(pack);
  17. * }
  18. *
  19. * function _unpack(MyType self) external pure returns (address, bytes4, uint64) {
  20. * bytes32 pack = MyType.unwrap(self);
  21. * return (
  22. * address(Packing.extract_32_20(pack, 0)),
  23. * Packing.extract_32_4(pack, 20),
  24. * uint64(Packing.extract_32_8(pack, 24))
  25. * );
  26. * }
  27. * }
  28. * ```
  29. */
  30. // solhint-disable func-name-mixedcase
  31. library Packing {
  32. error OutOfRangeAccess();
  33. function pack_1_1(bytes1 left, bytes1 right) internal pure returns (bytes2 result) {
  34. assembly ("memory-safe") {
  35. left := and(left, shl(248, not(0)))
  36. right := and(right, shl(248, not(0)))
  37. result := or(left, shr(8, right))
  38. }
  39. }
  40. function pack_2_2(bytes2 left, bytes2 right) internal pure returns (bytes4 result) {
  41. assembly ("memory-safe") {
  42. left := and(left, shl(240, not(0)))
  43. right := and(right, shl(240, not(0)))
  44. result := or(left, shr(16, right))
  45. }
  46. }
  47. function pack_2_4(bytes2 left, bytes4 right) internal pure returns (bytes6 result) {
  48. assembly ("memory-safe") {
  49. left := and(left, shl(240, not(0)))
  50. right := and(right, shl(224, not(0)))
  51. result := or(left, shr(16, right))
  52. }
  53. }
  54. function pack_2_6(bytes2 left, bytes6 right) internal pure returns (bytes8 result) {
  55. assembly ("memory-safe") {
  56. left := and(left, shl(240, not(0)))
  57. right := and(right, shl(208, not(0)))
  58. result := or(left, shr(16, right))
  59. }
  60. }
  61. function pack_4_2(bytes4 left, bytes2 right) internal pure returns (bytes6 result) {
  62. assembly ("memory-safe") {
  63. left := and(left, shl(224, not(0)))
  64. right := and(right, shl(240, not(0)))
  65. result := or(left, shr(32, right))
  66. }
  67. }
  68. function pack_4_4(bytes4 left, bytes4 right) internal pure returns (bytes8 result) {
  69. assembly ("memory-safe") {
  70. left := and(left, shl(224, not(0)))
  71. right := and(right, shl(224, not(0)))
  72. result := or(left, shr(32, right))
  73. }
  74. }
  75. function pack_4_8(bytes4 left, bytes8 right) internal pure returns (bytes12 result) {
  76. assembly ("memory-safe") {
  77. left := and(left, shl(224, not(0)))
  78. right := and(right, shl(192, not(0)))
  79. result := or(left, shr(32, right))
  80. }
  81. }
  82. function pack_4_12(bytes4 left, bytes12 right) internal pure returns (bytes16 result) {
  83. assembly ("memory-safe") {
  84. left := and(left, shl(224, not(0)))
  85. right := and(right, shl(160, not(0)))
  86. result := or(left, shr(32, right))
  87. }
  88. }
  89. function pack_4_16(bytes4 left, bytes16 right) internal pure returns (bytes20 result) {
  90. assembly ("memory-safe") {
  91. left := and(left, shl(224, not(0)))
  92. right := and(right, shl(128, not(0)))
  93. result := or(left, shr(32, right))
  94. }
  95. }
  96. function pack_4_20(bytes4 left, bytes20 right) internal pure returns (bytes24 result) {
  97. assembly ("memory-safe") {
  98. left := and(left, shl(224, not(0)))
  99. right := and(right, shl(96, not(0)))
  100. result := or(left, shr(32, right))
  101. }
  102. }
  103. function pack_4_24(bytes4 left, bytes24 right) internal pure returns (bytes28 result) {
  104. assembly ("memory-safe") {
  105. left := and(left, shl(224, not(0)))
  106. right := and(right, shl(64, not(0)))
  107. result := or(left, shr(32, right))
  108. }
  109. }
  110. function pack_4_28(bytes4 left, bytes28 right) internal pure returns (bytes32 result) {
  111. assembly ("memory-safe") {
  112. left := and(left, shl(224, not(0)))
  113. right := and(right, shl(32, not(0)))
  114. result := or(left, shr(32, right))
  115. }
  116. }
  117. function pack_6_2(bytes6 left, bytes2 right) internal pure returns (bytes8 result) {
  118. assembly ("memory-safe") {
  119. left := and(left, shl(208, not(0)))
  120. right := and(right, shl(240, not(0)))
  121. result := or(left, shr(48, right))
  122. }
  123. }
  124. function pack_6_6(bytes6 left, bytes6 right) internal pure returns (bytes12 result) {
  125. assembly ("memory-safe") {
  126. left := and(left, shl(208, not(0)))
  127. right := and(right, shl(208, not(0)))
  128. result := or(left, shr(48, right))
  129. }
  130. }
  131. function pack_8_4(bytes8 left, bytes4 right) internal pure returns (bytes12 result) {
  132. assembly ("memory-safe") {
  133. left := and(left, shl(192, not(0)))
  134. right := and(right, shl(224, not(0)))
  135. result := or(left, shr(64, right))
  136. }
  137. }
  138. function pack_8_8(bytes8 left, bytes8 right) internal pure returns (bytes16 result) {
  139. assembly ("memory-safe") {
  140. left := and(left, shl(192, not(0)))
  141. right := and(right, shl(192, not(0)))
  142. result := or(left, shr(64, right))
  143. }
  144. }
  145. function pack_8_12(bytes8 left, bytes12 right) internal pure returns (bytes20 result) {
  146. assembly ("memory-safe") {
  147. left := and(left, shl(192, not(0)))
  148. right := and(right, shl(160, not(0)))
  149. result := or(left, shr(64, right))
  150. }
  151. }
  152. function pack_8_16(bytes8 left, bytes16 right) internal pure returns (bytes24 result) {
  153. assembly ("memory-safe") {
  154. left := and(left, shl(192, not(0)))
  155. right := and(right, shl(128, not(0)))
  156. result := or(left, shr(64, right))
  157. }
  158. }
  159. function pack_8_20(bytes8 left, bytes20 right) internal pure returns (bytes28 result) {
  160. assembly ("memory-safe") {
  161. left := and(left, shl(192, not(0)))
  162. right := and(right, shl(96, not(0)))
  163. result := or(left, shr(64, right))
  164. }
  165. }
  166. function pack_8_24(bytes8 left, bytes24 right) internal pure returns (bytes32 result) {
  167. assembly ("memory-safe") {
  168. left := and(left, shl(192, not(0)))
  169. right := and(right, shl(64, not(0)))
  170. result := or(left, shr(64, right))
  171. }
  172. }
  173. function pack_12_4(bytes12 left, bytes4 right) internal pure returns (bytes16 result) {
  174. assembly ("memory-safe") {
  175. left := and(left, shl(160, not(0)))
  176. right := and(right, shl(224, not(0)))
  177. result := or(left, shr(96, right))
  178. }
  179. }
  180. function pack_12_8(bytes12 left, bytes8 right) internal pure returns (bytes20 result) {
  181. assembly ("memory-safe") {
  182. left := and(left, shl(160, not(0)))
  183. right := and(right, shl(192, not(0)))
  184. result := or(left, shr(96, right))
  185. }
  186. }
  187. function pack_12_12(bytes12 left, bytes12 right) internal pure returns (bytes24 result) {
  188. assembly ("memory-safe") {
  189. left := and(left, shl(160, not(0)))
  190. right := and(right, shl(160, not(0)))
  191. result := or(left, shr(96, right))
  192. }
  193. }
  194. function pack_12_16(bytes12 left, bytes16 right) internal pure returns (bytes28 result) {
  195. assembly ("memory-safe") {
  196. left := and(left, shl(160, not(0)))
  197. right := and(right, shl(128, not(0)))
  198. result := or(left, shr(96, right))
  199. }
  200. }
  201. function pack_12_20(bytes12 left, bytes20 right) internal pure returns (bytes32 result) {
  202. assembly ("memory-safe") {
  203. left := and(left, shl(160, not(0)))
  204. right := and(right, shl(96, not(0)))
  205. result := or(left, shr(96, right))
  206. }
  207. }
  208. function pack_16_4(bytes16 left, bytes4 right) internal pure returns (bytes20 result) {
  209. assembly ("memory-safe") {
  210. left := and(left, shl(128, not(0)))
  211. right := and(right, shl(224, not(0)))
  212. result := or(left, shr(128, right))
  213. }
  214. }
  215. function pack_16_8(bytes16 left, bytes8 right) internal pure returns (bytes24 result) {
  216. assembly ("memory-safe") {
  217. left := and(left, shl(128, not(0)))
  218. right := and(right, shl(192, not(0)))
  219. result := or(left, shr(128, right))
  220. }
  221. }
  222. function pack_16_12(bytes16 left, bytes12 right) internal pure returns (bytes28 result) {
  223. assembly ("memory-safe") {
  224. left := and(left, shl(128, not(0)))
  225. right := and(right, shl(160, not(0)))
  226. result := or(left, shr(128, right))
  227. }
  228. }
  229. function pack_16_16(bytes16 left, bytes16 right) internal pure returns (bytes32 result) {
  230. assembly ("memory-safe") {
  231. left := and(left, shl(128, not(0)))
  232. right := and(right, shl(128, not(0)))
  233. result := or(left, shr(128, right))
  234. }
  235. }
  236. function pack_20_4(bytes20 left, bytes4 right) internal pure returns (bytes24 result) {
  237. assembly ("memory-safe") {
  238. left := and(left, shl(96, not(0)))
  239. right := and(right, shl(224, not(0)))
  240. result := or(left, shr(160, right))
  241. }
  242. }
  243. function pack_20_8(bytes20 left, bytes8 right) internal pure returns (bytes28 result) {
  244. assembly ("memory-safe") {
  245. left := and(left, shl(96, not(0)))
  246. right := and(right, shl(192, not(0)))
  247. result := or(left, shr(160, right))
  248. }
  249. }
  250. function pack_20_12(bytes20 left, bytes12 right) internal pure returns (bytes32 result) {
  251. assembly ("memory-safe") {
  252. left := and(left, shl(96, not(0)))
  253. right := and(right, shl(160, not(0)))
  254. result := or(left, shr(160, right))
  255. }
  256. }
  257. function pack_24_4(bytes24 left, bytes4 right) internal pure returns (bytes28 result) {
  258. assembly ("memory-safe") {
  259. left := and(left, shl(64, not(0)))
  260. right := and(right, shl(224, not(0)))
  261. result := or(left, shr(192, right))
  262. }
  263. }
  264. function pack_24_8(bytes24 left, bytes8 right) internal pure returns (bytes32 result) {
  265. assembly ("memory-safe") {
  266. left := and(left, shl(64, not(0)))
  267. right := and(right, shl(192, not(0)))
  268. result := or(left, shr(192, right))
  269. }
  270. }
  271. function pack_28_4(bytes28 left, bytes4 right) internal pure returns (bytes32 result) {
  272. assembly ("memory-safe") {
  273. left := and(left, shl(32, not(0)))
  274. right := and(right, shl(224, not(0)))
  275. result := or(left, shr(224, right))
  276. }
  277. }
  278. function extract_2_1(bytes2 self, uint8 offset) internal pure returns (bytes1 result) {
  279. if (offset > 1) revert OutOfRangeAccess();
  280. assembly ("memory-safe") {
  281. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  282. }
  283. }
  284. function replace_2_1(bytes2 self, bytes1 value, uint8 offset) internal pure returns (bytes2 result) {
  285. bytes1 oldValue = extract_2_1(self, offset);
  286. assembly ("memory-safe") {
  287. value := and(value, shl(248, not(0)))
  288. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  289. }
  290. }
  291. function extract_4_1(bytes4 self, uint8 offset) internal pure returns (bytes1 result) {
  292. if (offset > 3) revert OutOfRangeAccess();
  293. assembly ("memory-safe") {
  294. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  295. }
  296. }
  297. function replace_4_1(bytes4 self, bytes1 value, uint8 offset) internal pure returns (bytes4 result) {
  298. bytes1 oldValue = extract_4_1(self, offset);
  299. assembly ("memory-safe") {
  300. value := and(value, shl(248, not(0)))
  301. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  302. }
  303. }
  304. function extract_4_2(bytes4 self, uint8 offset) internal pure returns (bytes2 result) {
  305. if (offset > 2) revert OutOfRangeAccess();
  306. assembly ("memory-safe") {
  307. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  308. }
  309. }
  310. function replace_4_2(bytes4 self, bytes2 value, uint8 offset) internal pure returns (bytes4 result) {
  311. bytes2 oldValue = extract_4_2(self, offset);
  312. assembly ("memory-safe") {
  313. value := and(value, shl(240, not(0)))
  314. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  315. }
  316. }
  317. function extract_6_1(bytes6 self, uint8 offset) internal pure returns (bytes1 result) {
  318. if (offset > 5) revert OutOfRangeAccess();
  319. assembly ("memory-safe") {
  320. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  321. }
  322. }
  323. function replace_6_1(bytes6 self, bytes1 value, uint8 offset) internal pure returns (bytes6 result) {
  324. bytes1 oldValue = extract_6_1(self, offset);
  325. assembly ("memory-safe") {
  326. value := and(value, shl(248, not(0)))
  327. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  328. }
  329. }
  330. function extract_6_2(bytes6 self, uint8 offset) internal pure returns (bytes2 result) {
  331. if (offset > 4) revert OutOfRangeAccess();
  332. assembly ("memory-safe") {
  333. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  334. }
  335. }
  336. function replace_6_2(bytes6 self, bytes2 value, uint8 offset) internal pure returns (bytes6 result) {
  337. bytes2 oldValue = extract_6_2(self, offset);
  338. assembly ("memory-safe") {
  339. value := and(value, shl(240, not(0)))
  340. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  341. }
  342. }
  343. function extract_6_4(bytes6 self, uint8 offset) internal pure returns (bytes4 result) {
  344. if (offset > 2) revert OutOfRangeAccess();
  345. assembly ("memory-safe") {
  346. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  347. }
  348. }
  349. function replace_6_4(bytes6 self, bytes4 value, uint8 offset) internal pure returns (bytes6 result) {
  350. bytes4 oldValue = extract_6_4(self, offset);
  351. assembly ("memory-safe") {
  352. value := and(value, shl(224, not(0)))
  353. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  354. }
  355. }
  356. function extract_8_1(bytes8 self, uint8 offset) internal pure returns (bytes1 result) {
  357. if (offset > 7) revert OutOfRangeAccess();
  358. assembly ("memory-safe") {
  359. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  360. }
  361. }
  362. function replace_8_1(bytes8 self, bytes1 value, uint8 offset) internal pure returns (bytes8 result) {
  363. bytes1 oldValue = extract_8_1(self, offset);
  364. assembly ("memory-safe") {
  365. value := and(value, shl(248, not(0)))
  366. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  367. }
  368. }
  369. function extract_8_2(bytes8 self, uint8 offset) internal pure returns (bytes2 result) {
  370. if (offset > 6) revert OutOfRangeAccess();
  371. assembly ("memory-safe") {
  372. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  373. }
  374. }
  375. function replace_8_2(bytes8 self, bytes2 value, uint8 offset) internal pure returns (bytes8 result) {
  376. bytes2 oldValue = extract_8_2(self, offset);
  377. assembly ("memory-safe") {
  378. value := and(value, shl(240, not(0)))
  379. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  380. }
  381. }
  382. function extract_8_4(bytes8 self, uint8 offset) internal pure returns (bytes4 result) {
  383. if (offset > 4) revert OutOfRangeAccess();
  384. assembly ("memory-safe") {
  385. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  386. }
  387. }
  388. function replace_8_4(bytes8 self, bytes4 value, uint8 offset) internal pure returns (bytes8 result) {
  389. bytes4 oldValue = extract_8_4(self, offset);
  390. assembly ("memory-safe") {
  391. value := and(value, shl(224, not(0)))
  392. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  393. }
  394. }
  395. function extract_8_6(bytes8 self, uint8 offset) internal pure returns (bytes6 result) {
  396. if (offset > 2) revert OutOfRangeAccess();
  397. assembly ("memory-safe") {
  398. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  399. }
  400. }
  401. function replace_8_6(bytes8 self, bytes6 value, uint8 offset) internal pure returns (bytes8 result) {
  402. bytes6 oldValue = extract_8_6(self, offset);
  403. assembly ("memory-safe") {
  404. value := and(value, shl(208, not(0)))
  405. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  406. }
  407. }
  408. function extract_12_1(bytes12 self, uint8 offset) internal pure returns (bytes1 result) {
  409. if (offset > 11) revert OutOfRangeAccess();
  410. assembly ("memory-safe") {
  411. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  412. }
  413. }
  414. function replace_12_1(bytes12 self, bytes1 value, uint8 offset) internal pure returns (bytes12 result) {
  415. bytes1 oldValue = extract_12_1(self, offset);
  416. assembly ("memory-safe") {
  417. value := and(value, shl(248, not(0)))
  418. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  419. }
  420. }
  421. function extract_12_2(bytes12 self, uint8 offset) internal pure returns (bytes2 result) {
  422. if (offset > 10) revert OutOfRangeAccess();
  423. assembly ("memory-safe") {
  424. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  425. }
  426. }
  427. function replace_12_2(bytes12 self, bytes2 value, uint8 offset) internal pure returns (bytes12 result) {
  428. bytes2 oldValue = extract_12_2(self, offset);
  429. assembly ("memory-safe") {
  430. value := and(value, shl(240, not(0)))
  431. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  432. }
  433. }
  434. function extract_12_4(bytes12 self, uint8 offset) internal pure returns (bytes4 result) {
  435. if (offset > 8) revert OutOfRangeAccess();
  436. assembly ("memory-safe") {
  437. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  438. }
  439. }
  440. function replace_12_4(bytes12 self, bytes4 value, uint8 offset) internal pure returns (bytes12 result) {
  441. bytes4 oldValue = extract_12_4(self, offset);
  442. assembly ("memory-safe") {
  443. value := and(value, shl(224, not(0)))
  444. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  445. }
  446. }
  447. function extract_12_6(bytes12 self, uint8 offset) internal pure returns (bytes6 result) {
  448. if (offset > 6) revert OutOfRangeAccess();
  449. assembly ("memory-safe") {
  450. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  451. }
  452. }
  453. function replace_12_6(bytes12 self, bytes6 value, uint8 offset) internal pure returns (bytes12 result) {
  454. bytes6 oldValue = extract_12_6(self, offset);
  455. assembly ("memory-safe") {
  456. value := and(value, shl(208, not(0)))
  457. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  458. }
  459. }
  460. function extract_12_8(bytes12 self, uint8 offset) internal pure returns (bytes8 result) {
  461. if (offset > 4) revert OutOfRangeAccess();
  462. assembly ("memory-safe") {
  463. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  464. }
  465. }
  466. function replace_12_8(bytes12 self, bytes8 value, uint8 offset) internal pure returns (bytes12 result) {
  467. bytes8 oldValue = extract_12_8(self, offset);
  468. assembly ("memory-safe") {
  469. value := and(value, shl(192, not(0)))
  470. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  471. }
  472. }
  473. function extract_16_1(bytes16 self, uint8 offset) internal pure returns (bytes1 result) {
  474. if (offset > 15) revert OutOfRangeAccess();
  475. assembly ("memory-safe") {
  476. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  477. }
  478. }
  479. function replace_16_1(bytes16 self, bytes1 value, uint8 offset) internal pure returns (bytes16 result) {
  480. bytes1 oldValue = extract_16_1(self, offset);
  481. assembly ("memory-safe") {
  482. value := and(value, shl(248, not(0)))
  483. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  484. }
  485. }
  486. function extract_16_2(bytes16 self, uint8 offset) internal pure returns (bytes2 result) {
  487. if (offset > 14) revert OutOfRangeAccess();
  488. assembly ("memory-safe") {
  489. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  490. }
  491. }
  492. function replace_16_2(bytes16 self, bytes2 value, uint8 offset) internal pure returns (bytes16 result) {
  493. bytes2 oldValue = extract_16_2(self, offset);
  494. assembly ("memory-safe") {
  495. value := and(value, shl(240, not(0)))
  496. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  497. }
  498. }
  499. function extract_16_4(bytes16 self, uint8 offset) internal pure returns (bytes4 result) {
  500. if (offset > 12) revert OutOfRangeAccess();
  501. assembly ("memory-safe") {
  502. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  503. }
  504. }
  505. function replace_16_4(bytes16 self, bytes4 value, uint8 offset) internal pure returns (bytes16 result) {
  506. bytes4 oldValue = extract_16_4(self, offset);
  507. assembly ("memory-safe") {
  508. value := and(value, shl(224, not(0)))
  509. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  510. }
  511. }
  512. function extract_16_6(bytes16 self, uint8 offset) internal pure returns (bytes6 result) {
  513. if (offset > 10) revert OutOfRangeAccess();
  514. assembly ("memory-safe") {
  515. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  516. }
  517. }
  518. function replace_16_6(bytes16 self, bytes6 value, uint8 offset) internal pure returns (bytes16 result) {
  519. bytes6 oldValue = extract_16_6(self, offset);
  520. assembly ("memory-safe") {
  521. value := and(value, shl(208, not(0)))
  522. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  523. }
  524. }
  525. function extract_16_8(bytes16 self, uint8 offset) internal pure returns (bytes8 result) {
  526. if (offset > 8) revert OutOfRangeAccess();
  527. assembly ("memory-safe") {
  528. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  529. }
  530. }
  531. function replace_16_8(bytes16 self, bytes8 value, uint8 offset) internal pure returns (bytes16 result) {
  532. bytes8 oldValue = extract_16_8(self, offset);
  533. assembly ("memory-safe") {
  534. value := and(value, shl(192, not(0)))
  535. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  536. }
  537. }
  538. function extract_16_12(bytes16 self, uint8 offset) internal pure returns (bytes12 result) {
  539. if (offset > 4) revert OutOfRangeAccess();
  540. assembly ("memory-safe") {
  541. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  542. }
  543. }
  544. function replace_16_12(bytes16 self, bytes12 value, uint8 offset) internal pure returns (bytes16 result) {
  545. bytes12 oldValue = extract_16_12(self, offset);
  546. assembly ("memory-safe") {
  547. value := and(value, shl(160, not(0)))
  548. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  549. }
  550. }
  551. function extract_20_1(bytes20 self, uint8 offset) internal pure returns (bytes1 result) {
  552. if (offset > 19) revert OutOfRangeAccess();
  553. assembly ("memory-safe") {
  554. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  555. }
  556. }
  557. function replace_20_1(bytes20 self, bytes1 value, uint8 offset) internal pure returns (bytes20 result) {
  558. bytes1 oldValue = extract_20_1(self, offset);
  559. assembly ("memory-safe") {
  560. value := and(value, shl(248, not(0)))
  561. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  562. }
  563. }
  564. function extract_20_2(bytes20 self, uint8 offset) internal pure returns (bytes2 result) {
  565. if (offset > 18) revert OutOfRangeAccess();
  566. assembly ("memory-safe") {
  567. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  568. }
  569. }
  570. function replace_20_2(bytes20 self, bytes2 value, uint8 offset) internal pure returns (bytes20 result) {
  571. bytes2 oldValue = extract_20_2(self, offset);
  572. assembly ("memory-safe") {
  573. value := and(value, shl(240, not(0)))
  574. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  575. }
  576. }
  577. function extract_20_4(bytes20 self, uint8 offset) internal pure returns (bytes4 result) {
  578. if (offset > 16) revert OutOfRangeAccess();
  579. assembly ("memory-safe") {
  580. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  581. }
  582. }
  583. function replace_20_4(bytes20 self, bytes4 value, uint8 offset) internal pure returns (bytes20 result) {
  584. bytes4 oldValue = extract_20_4(self, offset);
  585. assembly ("memory-safe") {
  586. value := and(value, shl(224, not(0)))
  587. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  588. }
  589. }
  590. function extract_20_6(bytes20 self, uint8 offset) internal pure returns (bytes6 result) {
  591. if (offset > 14) revert OutOfRangeAccess();
  592. assembly ("memory-safe") {
  593. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  594. }
  595. }
  596. function replace_20_6(bytes20 self, bytes6 value, uint8 offset) internal pure returns (bytes20 result) {
  597. bytes6 oldValue = extract_20_6(self, offset);
  598. assembly ("memory-safe") {
  599. value := and(value, shl(208, not(0)))
  600. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  601. }
  602. }
  603. function extract_20_8(bytes20 self, uint8 offset) internal pure returns (bytes8 result) {
  604. if (offset > 12) revert OutOfRangeAccess();
  605. assembly ("memory-safe") {
  606. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  607. }
  608. }
  609. function replace_20_8(bytes20 self, bytes8 value, uint8 offset) internal pure returns (bytes20 result) {
  610. bytes8 oldValue = extract_20_8(self, offset);
  611. assembly ("memory-safe") {
  612. value := and(value, shl(192, not(0)))
  613. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  614. }
  615. }
  616. function extract_20_12(bytes20 self, uint8 offset) internal pure returns (bytes12 result) {
  617. if (offset > 8) revert OutOfRangeAccess();
  618. assembly ("memory-safe") {
  619. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  620. }
  621. }
  622. function replace_20_12(bytes20 self, bytes12 value, uint8 offset) internal pure returns (bytes20 result) {
  623. bytes12 oldValue = extract_20_12(self, offset);
  624. assembly ("memory-safe") {
  625. value := and(value, shl(160, not(0)))
  626. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  627. }
  628. }
  629. function extract_20_16(bytes20 self, uint8 offset) internal pure returns (bytes16 result) {
  630. if (offset > 4) revert OutOfRangeAccess();
  631. assembly ("memory-safe") {
  632. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  633. }
  634. }
  635. function replace_20_16(bytes20 self, bytes16 value, uint8 offset) internal pure returns (bytes20 result) {
  636. bytes16 oldValue = extract_20_16(self, offset);
  637. assembly ("memory-safe") {
  638. value := and(value, shl(128, not(0)))
  639. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  640. }
  641. }
  642. function extract_24_1(bytes24 self, uint8 offset) internal pure returns (bytes1 result) {
  643. if (offset > 23) revert OutOfRangeAccess();
  644. assembly ("memory-safe") {
  645. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  646. }
  647. }
  648. function replace_24_1(bytes24 self, bytes1 value, uint8 offset) internal pure returns (bytes24 result) {
  649. bytes1 oldValue = extract_24_1(self, offset);
  650. assembly ("memory-safe") {
  651. value := and(value, shl(248, not(0)))
  652. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  653. }
  654. }
  655. function extract_24_2(bytes24 self, uint8 offset) internal pure returns (bytes2 result) {
  656. if (offset > 22) revert OutOfRangeAccess();
  657. assembly ("memory-safe") {
  658. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  659. }
  660. }
  661. function replace_24_2(bytes24 self, bytes2 value, uint8 offset) internal pure returns (bytes24 result) {
  662. bytes2 oldValue = extract_24_2(self, offset);
  663. assembly ("memory-safe") {
  664. value := and(value, shl(240, not(0)))
  665. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  666. }
  667. }
  668. function extract_24_4(bytes24 self, uint8 offset) internal pure returns (bytes4 result) {
  669. if (offset > 20) revert OutOfRangeAccess();
  670. assembly ("memory-safe") {
  671. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  672. }
  673. }
  674. function replace_24_4(bytes24 self, bytes4 value, uint8 offset) internal pure returns (bytes24 result) {
  675. bytes4 oldValue = extract_24_4(self, offset);
  676. assembly ("memory-safe") {
  677. value := and(value, shl(224, not(0)))
  678. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  679. }
  680. }
  681. function extract_24_6(bytes24 self, uint8 offset) internal pure returns (bytes6 result) {
  682. if (offset > 18) revert OutOfRangeAccess();
  683. assembly ("memory-safe") {
  684. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  685. }
  686. }
  687. function replace_24_6(bytes24 self, bytes6 value, uint8 offset) internal pure returns (bytes24 result) {
  688. bytes6 oldValue = extract_24_6(self, offset);
  689. assembly ("memory-safe") {
  690. value := and(value, shl(208, not(0)))
  691. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  692. }
  693. }
  694. function extract_24_8(bytes24 self, uint8 offset) internal pure returns (bytes8 result) {
  695. if (offset > 16) revert OutOfRangeAccess();
  696. assembly ("memory-safe") {
  697. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  698. }
  699. }
  700. function replace_24_8(bytes24 self, bytes8 value, uint8 offset) internal pure returns (bytes24 result) {
  701. bytes8 oldValue = extract_24_8(self, offset);
  702. assembly ("memory-safe") {
  703. value := and(value, shl(192, not(0)))
  704. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  705. }
  706. }
  707. function extract_24_12(bytes24 self, uint8 offset) internal pure returns (bytes12 result) {
  708. if (offset > 12) revert OutOfRangeAccess();
  709. assembly ("memory-safe") {
  710. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  711. }
  712. }
  713. function replace_24_12(bytes24 self, bytes12 value, uint8 offset) internal pure returns (bytes24 result) {
  714. bytes12 oldValue = extract_24_12(self, offset);
  715. assembly ("memory-safe") {
  716. value := and(value, shl(160, not(0)))
  717. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  718. }
  719. }
  720. function extract_24_16(bytes24 self, uint8 offset) internal pure returns (bytes16 result) {
  721. if (offset > 8) revert OutOfRangeAccess();
  722. assembly ("memory-safe") {
  723. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  724. }
  725. }
  726. function replace_24_16(bytes24 self, bytes16 value, uint8 offset) internal pure returns (bytes24 result) {
  727. bytes16 oldValue = extract_24_16(self, offset);
  728. assembly ("memory-safe") {
  729. value := and(value, shl(128, not(0)))
  730. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  731. }
  732. }
  733. function extract_24_20(bytes24 self, uint8 offset) internal pure returns (bytes20 result) {
  734. if (offset > 4) revert OutOfRangeAccess();
  735. assembly ("memory-safe") {
  736. result := and(shl(mul(8, offset), self), shl(96, not(0)))
  737. }
  738. }
  739. function replace_24_20(bytes24 self, bytes20 value, uint8 offset) internal pure returns (bytes24 result) {
  740. bytes20 oldValue = extract_24_20(self, offset);
  741. assembly ("memory-safe") {
  742. value := and(value, shl(96, not(0)))
  743. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  744. }
  745. }
  746. function extract_28_1(bytes28 self, uint8 offset) internal pure returns (bytes1 result) {
  747. if (offset > 27) revert OutOfRangeAccess();
  748. assembly ("memory-safe") {
  749. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  750. }
  751. }
  752. function replace_28_1(bytes28 self, bytes1 value, uint8 offset) internal pure returns (bytes28 result) {
  753. bytes1 oldValue = extract_28_1(self, offset);
  754. assembly ("memory-safe") {
  755. value := and(value, shl(248, not(0)))
  756. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  757. }
  758. }
  759. function extract_28_2(bytes28 self, uint8 offset) internal pure returns (bytes2 result) {
  760. if (offset > 26) revert OutOfRangeAccess();
  761. assembly ("memory-safe") {
  762. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  763. }
  764. }
  765. function replace_28_2(bytes28 self, bytes2 value, uint8 offset) internal pure returns (bytes28 result) {
  766. bytes2 oldValue = extract_28_2(self, offset);
  767. assembly ("memory-safe") {
  768. value := and(value, shl(240, not(0)))
  769. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  770. }
  771. }
  772. function extract_28_4(bytes28 self, uint8 offset) internal pure returns (bytes4 result) {
  773. if (offset > 24) revert OutOfRangeAccess();
  774. assembly ("memory-safe") {
  775. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  776. }
  777. }
  778. function replace_28_4(bytes28 self, bytes4 value, uint8 offset) internal pure returns (bytes28 result) {
  779. bytes4 oldValue = extract_28_4(self, offset);
  780. assembly ("memory-safe") {
  781. value := and(value, shl(224, not(0)))
  782. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  783. }
  784. }
  785. function extract_28_6(bytes28 self, uint8 offset) internal pure returns (bytes6 result) {
  786. if (offset > 22) revert OutOfRangeAccess();
  787. assembly ("memory-safe") {
  788. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  789. }
  790. }
  791. function replace_28_6(bytes28 self, bytes6 value, uint8 offset) internal pure returns (bytes28 result) {
  792. bytes6 oldValue = extract_28_6(self, offset);
  793. assembly ("memory-safe") {
  794. value := and(value, shl(208, not(0)))
  795. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  796. }
  797. }
  798. function extract_28_8(bytes28 self, uint8 offset) internal pure returns (bytes8 result) {
  799. if (offset > 20) revert OutOfRangeAccess();
  800. assembly ("memory-safe") {
  801. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  802. }
  803. }
  804. function replace_28_8(bytes28 self, bytes8 value, uint8 offset) internal pure returns (bytes28 result) {
  805. bytes8 oldValue = extract_28_8(self, offset);
  806. assembly ("memory-safe") {
  807. value := and(value, shl(192, not(0)))
  808. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  809. }
  810. }
  811. function extract_28_12(bytes28 self, uint8 offset) internal pure returns (bytes12 result) {
  812. if (offset > 16) revert OutOfRangeAccess();
  813. assembly ("memory-safe") {
  814. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  815. }
  816. }
  817. function replace_28_12(bytes28 self, bytes12 value, uint8 offset) internal pure returns (bytes28 result) {
  818. bytes12 oldValue = extract_28_12(self, offset);
  819. assembly ("memory-safe") {
  820. value := and(value, shl(160, not(0)))
  821. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  822. }
  823. }
  824. function extract_28_16(bytes28 self, uint8 offset) internal pure returns (bytes16 result) {
  825. if (offset > 12) revert OutOfRangeAccess();
  826. assembly ("memory-safe") {
  827. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  828. }
  829. }
  830. function replace_28_16(bytes28 self, bytes16 value, uint8 offset) internal pure returns (bytes28 result) {
  831. bytes16 oldValue = extract_28_16(self, offset);
  832. assembly ("memory-safe") {
  833. value := and(value, shl(128, not(0)))
  834. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  835. }
  836. }
  837. function extract_28_20(bytes28 self, uint8 offset) internal pure returns (bytes20 result) {
  838. if (offset > 8) revert OutOfRangeAccess();
  839. assembly ("memory-safe") {
  840. result := and(shl(mul(8, offset), self), shl(96, not(0)))
  841. }
  842. }
  843. function replace_28_20(bytes28 self, bytes20 value, uint8 offset) internal pure returns (bytes28 result) {
  844. bytes20 oldValue = extract_28_20(self, offset);
  845. assembly ("memory-safe") {
  846. value := and(value, shl(96, not(0)))
  847. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  848. }
  849. }
  850. function extract_28_24(bytes28 self, uint8 offset) internal pure returns (bytes24 result) {
  851. if (offset > 4) revert OutOfRangeAccess();
  852. assembly ("memory-safe") {
  853. result := and(shl(mul(8, offset), self), shl(64, not(0)))
  854. }
  855. }
  856. function replace_28_24(bytes28 self, bytes24 value, uint8 offset) internal pure returns (bytes28 result) {
  857. bytes24 oldValue = extract_28_24(self, offset);
  858. assembly ("memory-safe") {
  859. value := and(value, shl(64, not(0)))
  860. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  861. }
  862. }
  863. function extract_32_1(bytes32 self, uint8 offset) internal pure returns (bytes1 result) {
  864. if (offset > 31) revert OutOfRangeAccess();
  865. assembly ("memory-safe") {
  866. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  867. }
  868. }
  869. function replace_32_1(bytes32 self, bytes1 value, uint8 offset) internal pure returns (bytes32 result) {
  870. bytes1 oldValue = extract_32_1(self, offset);
  871. assembly ("memory-safe") {
  872. value := and(value, shl(248, not(0)))
  873. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  874. }
  875. }
  876. function extract_32_2(bytes32 self, uint8 offset) internal pure returns (bytes2 result) {
  877. if (offset > 30) revert OutOfRangeAccess();
  878. assembly ("memory-safe") {
  879. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  880. }
  881. }
  882. function replace_32_2(bytes32 self, bytes2 value, uint8 offset) internal pure returns (bytes32 result) {
  883. bytes2 oldValue = extract_32_2(self, offset);
  884. assembly ("memory-safe") {
  885. value := and(value, shl(240, not(0)))
  886. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  887. }
  888. }
  889. function extract_32_4(bytes32 self, uint8 offset) internal pure returns (bytes4 result) {
  890. if (offset > 28) revert OutOfRangeAccess();
  891. assembly ("memory-safe") {
  892. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  893. }
  894. }
  895. function replace_32_4(bytes32 self, bytes4 value, uint8 offset) internal pure returns (bytes32 result) {
  896. bytes4 oldValue = extract_32_4(self, offset);
  897. assembly ("memory-safe") {
  898. value := and(value, shl(224, not(0)))
  899. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  900. }
  901. }
  902. function extract_32_6(bytes32 self, uint8 offset) internal pure returns (bytes6 result) {
  903. if (offset > 26) revert OutOfRangeAccess();
  904. assembly ("memory-safe") {
  905. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  906. }
  907. }
  908. function replace_32_6(bytes32 self, bytes6 value, uint8 offset) internal pure returns (bytes32 result) {
  909. bytes6 oldValue = extract_32_6(self, offset);
  910. assembly ("memory-safe") {
  911. value := and(value, shl(208, not(0)))
  912. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  913. }
  914. }
  915. function extract_32_8(bytes32 self, uint8 offset) internal pure returns (bytes8 result) {
  916. if (offset > 24) revert OutOfRangeAccess();
  917. assembly ("memory-safe") {
  918. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  919. }
  920. }
  921. function replace_32_8(bytes32 self, bytes8 value, uint8 offset) internal pure returns (bytes32 result) {
  922. bytes8 oldValue = extract_32_8(self, offset);
  923. assembly ("memory-safe") {
  924. value := and(value, shl(192, not(0)))
  925. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  926. }
  927. }
  928. function extract_32_12(bytes32 self, uint8 offset) internal pure returns (bytes12 result) {
  929. if (offset > 20) revert OutOfRangeAccess();
  930. assembly ("memory-safe") {
  931. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  932. }
  933. }
  934. function replace_32_12(bytes32 self, bytes12 value, uint8 offset) internal pure returns (bytes32 result) {
  935. bytes12 oldValue = extract_32_12(self, offset);
  936. assembly ("memory-safe") {
  937. value := and(value, shl(160, not(0)))
  938. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  939. }
  940. }
  941. function extract_32_16(bytes32 self, uint8 offset) internal pure returns (bytes16 result) {
  942. if (offset > 16) revert OutOfRangeAccess();
  943. assembly ("memory-safe") {
  944. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  945. }
  946. }
  947. function replace_32_16(bytes32 self, bytes16 value, uint8 offset) internal pure returns (bytes32 result) {
  948. bytes16 oldValue = extract_32_16(self, offset);
  949. assembly ("memory-safe") {
  950. value := and(value, shl(128, not(0)))
  951. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  952. }
  953. }
  954. function extract_32_20(bytes32 self, uint8 offset) internal pure returns (bytes20 result) {
  955. if (offset > 12) revert OutOfRangeAccess();
  956. assembly ("memory-safe") {
  957. result := and(shl(mul(8, offset), self), shl(96, not(0)))
  958. }
  959. }
  960. function replace_32_20(bytes32 self, bytes20 value, uint8 offset) internal pure returns (bytes32 result) {
  961. bytes20 oldValue = extract_32_20(self, offset);
  962. assembly ("memory-safe") {
  963. value := and(value, shl(96, not(0)))
  964. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  965. }
  966. }
  967. function extract_32_24(bytes32 self, uint8 offset) internal pure returns (bytes24 result) {
  968. if (offset > 8) revert OutOfRangeAccess();
  969. assembly ("memory-safe") {
  970. result := and(shl(mul(8, offset), self), shl(64, not(0)))
  971. }
  972. }
  973. function replace_32_24(bytes32 self, bytes24 value, uint8 offset) internal pure returns (bytes32 result) {
  974. bytes24 oldValue = extract_32_24(self, offset);
  975. assembly ("memory-safe") {
  976. value := and(value, shl(64, not(0)))
  977. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  978. }
  979. }
  980. function extract_32_28(bytes32 self, uint8 offset) internal pure returns (bytes28 result) {
  981. if (offset > 4) revert OutOfRangeAccess();
  982. assembly ("memory-safe") {
  983. result := and(shl(mul(8, offset), self), shl(32, not(0)))
  984. }
  985. }
  986. function replace_32_28(bytes32 self, bytes28 value, uint8 offset) internal pure returns (bytes32 result) {
  987. bytes28 oldValue = extract_32_28(self, offset);
  988. assembly ("memory-safe") {
  989. value := and(value, shl(32, not(0)))
  990. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  991. }
  992. }
  993. }