Packing.sol 63 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v5.1.0) (utils/Packing.sol)
  3. // This file was procedurally generated from scripts/generate/templates/Packing.js.
  4. pragma solidity ^0.8.20;
  5. /**
  6. * @dev Helper library packing and unpacking multiple values into bytesXX.
  7. *
  8. * Example usage:
  9. *
  10. * ```solidity
  11. * library MyPacker {
  12. * type MyType is bytes32;
  13. *
  14. * function _pack(address account, bytes4 selector, uint64 period) external pure returns (MyType) {
  15. * bytes12 subpack = Packing.pack_4_8(selector, bytes8(period));
  16. * bytes32 pack = Packing.pack_20_12(bytes20(account), subpack);
  17. * return MyType.wrap(pack);
  18. * }
  19. *
  20. * function _unpack(MyType self) external pure returns (address, bytes4, uint64) {
  21. * bytes32 pack = MyType.unwrap(self);
  22. * return (
  23. * address(Packing.extract_32_20(pack, 0)),
  24. * Packing.extract_32_4(pack, 20),
  25. * uint64(Packing.extract_32_8(pack, 24))
  26. * );
  27. * }
  28. * }
  29. * ```
  30. *
  31. * _Available since v5.1._
  32. */
  33. // solhint-disable func-name-mixedcase
  34. library Packing {
  35. error OutOfRangeAccess();
  36. function pack_1_1(bytes1 left, bytes1 right) internal pure returns (bytes2 result) {
  37. assembly ("memory-safe") {
  38. left := and(left, shl(248, not(0)))
  39. right := and(right, shl(248, not(0)))
  40. result := or(left, shr(8, right))
  41. }
  42. }
  43. function pack_2_2(bytes2 left, bytes2 right) internal pure returns (bytes4 result) {
  44. assembly ("memory-safe") {
  45. left := and(left, shl(240, not(0)))
  46. right := and(right, shl(240, not(0)))
  47. result := or(left, shr(16, right))
  48. }
  49. }
  50. function pack_2_4(bytes2 left, bytes4 right) internal pure returns (bytes6 result) {
  51. assembly ("memory-safe") {
  52. left := and(left, shl(240, not(0)))
  53. right := and(right, shl(224, not(0)))
  54. result := or(left, shr(16, right))
  55. }
  56. }
  57. function pack_2_6(bytes2 left, bytes6 right) internal pure returns (bytes8 result) {
  58. assembly ("memory-safe") {
  59. left := and(left, shl(240, not(0)))
  60. right := and(right, shl(208, not(0)))
  61. result := or(left, shr(16, right))
  62. }
  63. }
  64. function pack_2_8(bytes2 left, bytes8 right) internal pure returns (bytes10 result) {
  65. assembly ("memory-safe") {
  66. left := and(left, shl(240, not(0)))
  67. right := and(right, shl(192, not(0)))
  68. result := or(left, shr(16, right))
  69. }
  70. }
  71. function pack_2_10(bytes2 left, bytes10 right) internal pure returns (bytes12 result) {
  72. assembly ("memory-safe") {
  73. left := and(left, shl(240, not(0)))
  74. right := and(right, shl(176, not(0)))
  75. result := or(left, shr(16, right))
  76. }
  77. }
  78. function pack_2_20(bytes2 left, bytes20 right) internal pure returns (bytes22 result) {
  79. assembly ("memory-safe") {
  80. left := and(left, shl(240, not(0)))
  81. right := and(right, shl(96, not(0)))
  82. result := or(left, shr(16, right))
  83. }
  84. }
  85. function pack_2_22(bytes2 left, bytes22 right) internal pure returns (bytes24 result) {
  86. assembly ("memory-safe") {
  87. left := and(left, shl(240, not(0)))
  88. right := and(right, shl(80, not(0)))
  89. result := or(left, shr(16, right))
  90. }
  91. }
  92. function pack_4_2(bytes4 left, bytes2 right) internal pure returns (bytes6 result) {
  93. assembly ("memory-safe") {
  94. left := and(left, shl(224, not(0)))
  95. right := and(right, shl(240, not(0)))
  96. result := or(left, shr(32, right))
  97. }
  98. }
  99. function pack_4_4(bytes4 left, bytes4 right) internal pure returns (bytes8 result) {
  100. assembly ("memory-safe") {
  101. left := and(left, shl(224, not(0)))
  102. right := and(right, shl(224, not(0)))
  103. result := or(left, shr(32, right))
  104. }
  105. }
  106. function pack_4_6(bytes4 left, bytes6 right) internal pure returns (bytes10 result) {
  107. assembly ("memory-safe") {
  108. left := and(left, shl(224, not(0)))
  109. right := and(right, shl(208, not(0)))
  110. result := or(left, shr(32, right))
  111. }
  112. }
  113. function pack_4_8(bytes4 left, bytes8 right) internal pure returns (bytes12 result) {
  114. assembly ("memory-safe") {
  115. left := and(left, shl(224, not(0)))
  116. right := and(right, shl(192, not(0)))
  117. result := or(left, shr(32, right))
  118. }
  119. }
  120. function pack_4_12(bytes4 left, bytes12 right) internal pure returns (bytes16 result) {
  121. assembly ("memory-safe") {
  122. left := and(left, shl(224, not(0)))
  123. right := and(right, shl(160, not(0)))
  124. result := or(left, shr(32, right))
  125. }
  126. }
  127. function pack_4_16(bytes4 left, bytes16 right) internal pure returns (bytes20 result) {
  128. assembly ("memory-safe") {
  129. left := and(left, shl(224, not(0)))
  130. right := and(right, shl(128, not(0)))
  131. result := or(left, shr(32, right))
  132. }
  133. }
  134. function pack_4_20(bytes4 left, bytes20 right) internal pure returns (bytes24 result) {
  135. assembly ("memory-safe") {
  136. left := and(left, shl(224, not(0)))
  137. right := and(right, shl(96, not(0)))
  138. result := or(left, shr(32, right))
  139. }
  140. }
  141. function pack_4_24(bytes4 left, bytes24 right) internal pure returns (bytes28 result) {
  142. assembly ("memory-safe") {
  143. left := and(left, shl(224, not(0)))
  144. right := and(right, shl(64, not(0)))
  145. result := or(left, shr(32, right))
  146. }
  147. }
  148. function pack_4_28(bytes4 left, bytes28 right) internal pure returns (bytes32 result) {
  149. assembly ("memory-safe") {
  150. left := and(left, shl(224, not(0)))
  151. right := and(right, shl(32, not(0)))
  152. result := or(left, shr(32, right))
  153. }
  154. }
  155. function pack_6_2(bytes6 left, bytes2 right) internal pure returns (bytes8 result) {
  156. assembly ("memory-safe") {
  157. left := and(left, shl(208, not(0)))
  158. right := and(right, shl(240, not(0)))
  159. result := or(left, shr(48, right))
  160. }
  161. }
  162. function pack_6_4(bytes6 left, bytes4 right) internal pure returns (bytes10 result) {
  163. assembly ("memory-safe") {
  164. left := and(left, shl(208, not(0)))
  165. right := and(right, shl(224, not(0)))
  166. result := or(left, shr(48, right))
  167. }
  168. }
  169. function pack_6_6(bytes6 left, bytes6 right) internal pure returns (bytes12 result) {
  170. assembly ("memory-safe") {
  171. left := and(left, shl(208, not(0)))
  172. right := and(right, shl(208, not(0)))
  173. result := or(left, shr(48, right))
  174. }
  175. }
  176. function pack_6_10(bytes6 left, bytes10 right) internal pure returns (bytes16 result) {
  177. assembly ("memory-safe") {
  178. left := and(left, shl(208, not(0)))
  179. right := and(right, shl(176, not(0)))
  180. result := or(left, shr(48, right))
  181. }
  182. }
  183. function pack_6_16(bytes6 left, bytes16 right) internal pure returns (bytes22 result) {
  184. assembly ("memory-safe") {
  185. left := and(left, shl(208, not(0)))
  186. right := and(right, shl(128, not(0)))
  187. result := or(left, shr(48, right))
  188. }
  189. }
  190. function pack_6_22(bytes6 left, bytes22 right) internal pure returns (bytes28 result) {
  191. assembly ("memory-safe") {
  192. left := and(left, shl(208, not(0)))
  193. right := and(right, shl(80, not(0)))
  194. result := or(left, shr(48, right))
  195. }
  196. }
  197. function pack_8_2(bytes8 left, bytes2 right) internal pure returns (bytes10 result) {
  198. assembly ("memory-safe") {
  199. left := and(left, shl(192, not(0)))
  200. right := and(right, shl(240, not(0)))
  201. result := or(left, shr(64, right))
  202. }
  203. }
  204. function pack_8_4(bytes8 left, bytes4 right) internal pure returns (bytes12 result) {
  205. assembly ("memory-safe") {
  206. left := and(left, shl(192, not(0)))
  207. right := and(right, shl(224, not(0)))
  208. result := or(left, shr(64, right))
  209. }
  210. }
  211. function pack_8_8(bytes8 left, bytes8 right) internal pure returns (bytes16 result) {
  212. assembly ("memory-safe") {
  213. left := and(left, shl(192, not(0)))
  214. right := and(right, shl(192, not(0)))
  215. result := or(left, shr(64, right))
  216. }
  217. }
  218. function pack_8_12(bytes8 left, bytes12 right) internal pure returns (bytes20 result) {
  219. assembly ("memory-safe") {
  220. left := and(left, shl(192, not(0)))
  221. right := and(right, shl(160, not(0)))
  222. result := or(left, shr(64, right))
  223. }
  224. }
  225. function pack_8_16(bytes8 left, bytes16 right) internal pure returns (bytes24 result) {
  226. assembly ("memory-safe") {
  227. left := and(left, shl(192, not(0)))
  228. right := and(right, shl(128, not(0)))
  229. result := or(left, shr(64, right))
  230. }
  231. }
  232. function pack_8_20(bytes8 left, bytes20 right) internal pure returns (bytes28 result) {
  233. assembly ("memory-safe") {
  234. left := and(left, shl(192, not(0)))
  235. right := and(right, shl(96, not(0)))
  236. result := or(left, shr(64, right))
  237. }
  238. }
  239. function pack_8_24(bytes8 left, bytes24 right) internal pure returns (bytes32 result) {
  240. assembly ("memory-safe") {
  241. left := and(left, shl(192, not(0)))
  242. right := and(right, shl(64, not(0)))
  243. result := or(left, shr(64, right))
  244. }
  245. }
  246. function pack_10_2(bytes10 left, bytes2 right) internal pure returns (bytes12 result) {
  247. assembly ("memory-safe") {
  248. left := and(left, shl(176, not(0)))
  249. right := and(right, shl(240, not(0)))
  250. result := or(left, shr(80, right))
  251. }
  252. }
  253. function pack_10_6(bytes10 left, bytes6 right) internal pure returns (bytes16 result) {
  254. assembly ("memory-safe") {
  255. left := and(left, shl(176, not(0)))
  256. right := and(right, shl(208, not(0)))
  257. result := or(left, shr(80, right))
  258. }
  259. }
  260. function pack_10_10(bytes10 left, bytes10 right) internal pure returns (bytes20 result) {
  261. assembly ("memory-safe") {
  262. left := and(left, shl(176, not(0)))
  263. right := and(right, shl(176, not(0)))
  264. result := or(left, shr(80, right))
  265. }
  266. }
  267. function pack_10_12(bytes10 left, bytes12 right) internal pure returns (bytes22 result) {
  268. assembly ("memory-safe") {
  269. left := and(left, shl(176, not(0)))
  270. right := and(right, shl(160, not(0)))
  271. result := or(left, shr(80, right))
  272. }
  273. }
  274. function pack_10_22(bytes10 left, bytes22 right) internal pure returns (bytes32 result) {
  275. assembly ("memory-safe") {
  276. left := and(left, shl(176, not(0)))
  277. right := and(right, shl(80, not(0)))
  278. result := or(left, shr(80, right))
  279. }
  280. }
  281. function pack_12_4(bytes12 left, bytes4 right) internal pure returns (bytes16 result) {
  282. assembly ("memory-safe") {
  283. left := and(left, shl(160, not(0)))
  284. right := and(right, shl(224, not(0)))
  285. result := or(left, shr(96, right))
  286. }
  287. }
  288. function pack_12_8(bytes12 left, bytes8 right) internal pure returns (bytes20 result) {
  289. assembly ("memory-safe") {
  290. left := and(left, shl(160, not(0)))
  291. right := and(right, shl(192, not(0)))
  292. result := or(left, shr(96, right))
  293. }
  294. }
  295. function pack_12_10(bytes12 left, bytes10 right) internal pure returns (bytes22 result) {
  296. assembly ("memory-safe") {
  297. left := and(left, shl(160, not(0)))
  298. right := and(right, shl(176, not(0)))
  299. result := or(left, shr(96, right))
  300. }
  301. }
  302. function pack_12_12(bytes12 left, bytes12 right) internal pure returns (bytes24 result) {
  303. assembly ("memory-safe") {
  304. left := and(left, shl(160, not(0)))
  305. right := and(right, shl(160, not(0)))
  306. result := or(left, shr(96, right))
  307. }
  308. }
  309. function pack_12_16(bytes12 left, bytes16 right) internal pure returns (bytes28 result) {
  310. assembly ("memory-safe") {
  311. left := and(left, shl(160, not(0)))
  312. right := and(right, shl(128, not(0)))
  313. result := or(left, shr(96, right))
  314. }
  315. }
  316. function pack_12_20(bytes12 left, bytes20 right) internal pure returns (bytes32 result) {
  317. assembly ("memory-safe") {
  318. left := and(left, shl(160, not(0)))
  319. right := and(right, shl(96, not(0)))
  320. result := or(left, shr(96, right))
  321. }
  322. }
  323. function pack_16_4(bytes16 left, bytes4 right) internal pure returns (bytes20 result) {
  324. assembly ("memory-safe") {
  325. left := and(left, shl(128, not(0)))
  326. right := and(right, shl(224, not(0)))
  327. result := or(left, shr(128, right))
  328. }
  329. }
  330. function pack_16_6(bytes16 left, bytes6 right) internal pure returns (bytes22 result) {
  331. assembly ("memory-safe") {
  332. left := and(left, shl(128, not(0)))
  333. right := and(right, shl(208, not(0)))
  334. result := or(left, shr(128, right))
  335. }
  336. }
  337. function pack_16_8(bytes16 left, bytes8 right) internal pure returns (bytes24 result) {
  338. assembly ("memory-safe") {
  339. left := and(left, shl(128, not(0)))
  340. right := and(right, shl(192, not(0)))
  341. result := or(left, shr(128, right))
  342. }
  343. }
  344. function pack_16_12(bytes16 left, bytes12 right) internal pure returns (bytes28 result) {
  345. assembly ("memory-safe") {
  346. left := and(left, shl(128, not(0)))
  347. right := and(right, shl(160, not(0)))
  348. result := or(left, shr(128, right))
  349. }
  350. }
  351. function pack_16_16(bytes16 left, bytes16 right) internal pure returns (bytes32 result) {
  352. assembly ("memory-safe") {
  353. left := and(left, shl(128, not(0)))
  354. right := and(right, shl(128, not(0)))
  355. result := or(left, shr(128, right))
  356. }
  357. }
  358. function pack_20_2(bytes20 left, bytes2 right) internal pure returns (bytes22 result) {
  359. assembly ("memory-safe") {
  360. left := and(left, shl(96, not(0)))
  361. right := and(right, shl(240, not(0)))
  362. result := or(left, shr(160, right))
  363. }
  364. }
  365. function pack_20_4(bytes20 left, bytes4 right) internal pure returns (bytes24 result) {
  366. assembly ("memory-safe") {
  367. left := and(left, shl(96, not(0)))
  368. right := and(right, shl(224, not(0)))
  369. result := or(left, shr(160, right))
  370. }
  371. }
  372. function pack_20_8(bytes20 left, bytes8 right) internal pure returns (bytes28 result) {
  373. assembly ("memory-safe") {
  374. left := and(left, shl(96, not(0)))
  375. right := and(right, shl(192, not(0)))
  376. result := or(left, shr(160, right))
  377. }
  378. }
  379. function pack_20_12(bytes20 left, bytes12 right) internal pure returns (bytes32 result) {
  380. assembly ("memory-safe") {
  381. left := and(left, shl(96, not(0)))
  382. right := and(right, shl(160, not(0)))
  383. result := or(left, shr(160, right))
  384. }
  385. }
  386. function pack_22_2(bytes22 left, bytes2 right) internal pure returns (bytes24 result) {
  387. assembly ("memory-safe") {
  388. left := and(left, shl(80, not(0)))
  389. right := and(right, shl(240, not(0)))
  390. result := or(left, shr(176, right))
  391. }
  392. }
  393. function pack_22_6(bytes22 left, bytes6 right) internal pure returns (bytes28 result) {
  394. assembly ("memory-safe") {
  395. left := and(left, shl(80, not(0)))
  396. right := and(right, shl(208, not(0)))
  397. result := or(left, shr(176, right))
  398. }
  399. }
  400. function pack_22_10(bytes22 left, bytes10 right) internal pure returns (bytes32 result) {
  401. assembly ("memory-safe") {
  402. left := and(left, shl(80, not(0)))
  403. right := and(right, shl(176, not(0)))
  404. result := or(left, shr(176, right))
  405. }
  406. }
  407. function pack_24_4(bytes24 left, bytes4 right) internal pure returns (bytes28 result) {
  408. assembly ("memory-safe") {
  409. left := and(left, shl(64, not(0)))
  410. right := and(right, shl(224, not(0)))
  411. result := or(left, shr(192, right))
  412. }
  413. }
  414. function pack_24_8(bytes24 left, bytes8 right) internal pure returns (bytes32 result) {
  415. assembly ("memory-safe") {
  416. left := and(left, shl(64, not(0)))
  417. right := and(right, shl(192, not(0)))
  418. result := or(left, shr(192, right))
  419. }
  420. }
  421. function pack_28_4(bytes28 left, bytes4 right) internal pure returns (bytes32 result) {
  422. assembly ("memory-safe") {
  423. left := and(left, shl(32, not(0)))
  424. right := and(right, shl(224, not(0)))
  425. result := or(left, shr(224, right))
  426. }
  427. }
  428. function extract_2_1(bytes2 self, uint8 offset) internal pure returns (bytes1 result) {
  429. if (offset > 1) revert OutOfRangeAccess();
  430. assembly ("memory-safe") {
  431. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  432. }
  433. }
  434. function replace_2_1(bytes2 self, bytes1 value, uint8 offset) internal pure returns (bytes2 result) {
  435. bytes1 oldValue = extract_2_1(self, offset);
  436. assembly ("memory-safe") {
  437. value := and(value, shl(248, not(0)))
  438. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  439. }
  440. }
  441. function extract_4_1(bytes4 self, uint8 offset) internal pure returns (bytes1 result) {
  442. if (offset > 3) revert OutOfRangeAccess();
  443. assembly ("memory-safe") {
  444. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  445. }
  446. }
  447. function replace_4_1(bytes4 self, bytes1 value, uint8 offset) internal pure returns (bytes4 result) {
  448. bytes1 oldValue = extract_4_1(self, offset);
  449. assembly ("memory-safe") {
  450. value := and(value, shl(248, not(0)))
  451. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  452. }
  453. }
  454. function extract_4_2(bytes4 self, uint8 offset) internal pure returns (bytes2 result) {
  455. if (offset > 2) revert OutOfRangeAccess();
  456. assembly ("memory-safe") {
  457. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  458. }
  459. }
  460. function replace_4_2(bytes4 self, bytes2 value, uint8 offset) internal pure returns (bytes4 result) {
  461. bytes2 oldValue = extract_4_2(self, offset);
  462. assembly ("memory-safe") {
  463. value := and(value, shl(240, not(0)))
  464. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  465. }
  466. }
  467. function extract_6_1(bytes6 self, uint8 offset) internal pure returns (bytes1 result) {
  468. if (offset > 5) revert OutOfRangeAccess();
  469. assembly ("memory-safe") {
  470. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  471. }
  472. }
  473. function replace_6_1(bytes6 self, bytes1 value, uint8 offset) internal pure returns (bytes6 result) {
  474. bytes1 oldValue = extract_6_1(self, offset);
  475. assembly ("memory-safe") {
  476. value := and(value, shl(248, not(0)))
  477. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  478. }
  479. }
  480. function extract_6_2(bytes6 self, uint8 offset) internal pure returns (bytes2 result) {
  481. if (offset > 4) revert OutOfRangeAccess();
  482. assembly ("memory-safe") {
  483. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  484. }
  485. }
  486. function replace_6_2(bytes6 self, bytes2 value, uint8 offset) internal pure returns (bytes6 result) {
  487. bytes2 oldValue = extract_6_2(self, offset);
  488. assembly ("memory-safe") {
  489. value := and(value, shl(240, not(0)))
  490. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  491. }
  492. }
  493. function extract_6_4(bytes6 self, uint8 offset) internal pure returns (bytes4 result) {
  494. if (offset > 2) revert OutOfRangeAccess();
  495. assembly ("memory-safe") {
  496. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  497. }
  498. }
  499. function replace_6_4(bytes6 self, bytes4 value, uint8 offset) internal pure returns (bytes6 result) {
  500. bytes4 oldValue = extract_6_4(self, offset);
  501. assembly ("memory-safe") {
  502. value := and(value, shl(224, not(0)))
  503. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  504. }
  505. }
  506. function extract_8_1(bytes8 self, uint8 offset) internal pure returns (bytes1 result) {
  507. if (offset > 7) revert OutOfRangeAccess();
  508. assembly ("memory-safe") {
  509. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  510. }
  511. }
  512. function replace_8_1(bytes8 self, bytes1 value, uint8 offset) internal pure returns (bytes8 result) {
  513. bytes1 oldValue = extract_8_1(self, offset);
  514. assembly ("memory-safe") {
  515. value := and(value, shl(248, not(0)))
  516. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  517. }
  518. }
  519. function extract_8_2(bytes8 self, uint8 offset) internal pure returns (bytes2 result) {
  520. if (offset > 6) revert OutOfRangeAccess();
  521. assembly ("memory-safe") {
  522. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  523. }
  524. }
  525. function replace_8_2(bytes8 self, bytes2 value, uint8 offset) internal pure returns (bytes8 result) {
  526. bytes2 oldValue = extract_8_2(self, offset);
  527. assembly ("memory-safe") {
  528. value := and(value, shl(240, not(0)))
  529. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  530. }
  531. }
  532. function extract_8_4(bytes8 self, uint8 offset) internal pure returns (bytes4 result) {
  533. if (offset > 4) revert OutOfRangeAccess();
  534. assembly ("memory-safe") {
  535. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  536. }
  537. }
  538. function replace_8_4(bytes8 self, bytes4 value, uint8 offset) internal pure returns (bytes8 result) {
  539. bytes4 oldValue = extract_8_4(self, offset);
  540. assembly ("memory-safe") {
  541. value := and(value, shl(224, not(0)))
  542. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  543. }
  544. }
  545. function extract_8_6(bytes8 self, uint8 offset) internal pure returns (bytes6 result) {
  546. if (offset > 2) revert OutOfRangeAccess();
  547. assembly ("memory-safe") {
  548. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  549. }
  550. }
  551. function replace_8_6(bytes8 self, bytes6 value, uint8 offset) internal pure returns (bytes8 result) {
  552. bytes6 oldValue = extract_8_6(self, offset);
  553. assembly ("memory-safe") {
  554. value := and(value, shl(208, not(0)))
  555. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  556. }
  557. }
  558. function extract_10_1(bytes10 self, uint8 offset) internal pure returns (bytes1 result) {
  559. if (offset > 9) revert OutOfRangeAccess();
  560. assembly ("memory-safe") {
  561. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  562. }
  563. }
  564. function replace_10_1(bytes10 self, bytes1 value, uint8 offset) internal pure returns (bytes10 result) {
  565. bytes1 oldValue = extract_10_1(self, offset);
  566. assembly ("memory-safe") {
  567. value := and(value, shl(248, not(0)))
  568. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  569. }
  570. }
  571. function extract_10_2(bytes10 self, uint8 offset) internal pure returns (bytes2 result) {
  572. if (offset > 8) revert OutOfRangeAccess();
  573. assembly ("memory-safe") {
  574. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  575. }
  576. }
  577. function replace_10_2(bytes10 self, bytes2 value, uint8 offset) internal pure returns (bytes10 result) {
  578. bytes2 oldValue = extract_10_2(self, offset);
  579. assembly ("memory-safe") {
  580. value := and(value, shl(240, not(0)))
  581. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  582. }
  583. }
  584. function extract_10_4(bytes10 self, uint8 offset) internal pure returns (bytes4 result) {
  585. if (offset > 6) revert OutOfRangeAccess();
  586. assembly ("memory-safe") {
  587. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  588. }
  589. }
  590. function replace_10_4(bytes10 self, bytes4 value, uint8 offset) internal pure returns (bytes10 result) {
  591. bytes4 oldValue = extract_10_4(self, offset);
  592. assembly ("memory-safe") {
  593. value := and(value, shl(224, not(0)))
  594. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  595. }
  596. }
  597. function extract_10_6(bytes10 self, uint8 offset) internal pure returns (bytes6 result) {
  598. if (offset > 4) revert OutOfRangeAccess();
  599. assembly ("memory-safe") {
  600. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  601. }
  602. }
  603. function replace_10_6(bytes10 self, bytes6 value, uint8 offset) internal pure returns (bytes10 result) {
  604. bytes6 oldValue = extract_10_6(self, offset);
  605. assembly ("memory-safe") {
  606. value := and(value, shl(208, not(0)))
  607. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  608. }
  609. }
  610. function extract_10_8(bytes10 self, uint8 offset) internal pure returns (bytes8 result) {
  611. if (offset > 2) revert OutOfRangeAccess();
  612. assembly ("memory-safe") {
  613. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  614. }
  615. }
  616. function replace_10_8(bytes10 self, bytes8 value, uint8 offset) internal pure returns (bytes10 result) {
  617. bytes8 oldValue = extract_10_8(self, offset);
  618. assembly ("memory-safe") {
  619. value := and(value, shl(192, not(0)))
  620. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  621. }
  622. }
  623. function extract_12_1(bytes12 self, uint8 offset) internal pure returns (bytes1 result) {
  624. if (offset > 11) revert OutOfRangeAccess();
  625. assembly ("memory-safe") {
  626. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  627. }
  628. }
  629. function replace_12_1(bytes12 self, bytes1 value, uint8 offset) internal pure returns (bytes12 result) {
  630. bytes1 oldValue = extract_12_1(self, offset);
  631. assembly ("memory-safe") {
  632. value := and(value, shl(248, not(0)))
  633. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  634. }
  635. }
  636. function extract_12_2(bytes12 self, uint8 offset) internal pure returns (bytes2 result) {
  637. if (offset > 10) revert OutOfRangeAccess();
  638. assembly ("memory-safe") {
  639. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  640. }
  641. }
  642. function replace_12_2(bytes12 self, bytes2 value, uint8 offset) internal pure returns (bytes12 result) {
  643. bytes2 oldValue = extract_12_2(self, offset);
  644. assembly ("memory-safe") {
  645. value := and(value, shl(240, not(0)))
  646. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  647. }
  648. }
  649. function extract_12_4(bytes12 self, uint8 offset) internal pure returns (bytes4 result) {
  650. if (offset > 8) revert OutOfRangeAccess();
  651. assembly ("memory-safe") {
  652. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  653. }
  654. }
  655. function replace_12_4(bytes12 self, bytes4 value, uint8 offset) internal pure returns (bytes12 result) {
  656. bytes4 oldValue = extract_12_4(self, offset);
  657. assembly ("memory-safe") {
  658. value := and(value, shl(224, not(0)))
  659. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  660. }
  661. }
  662. function extract_12_6(bytes12 self, uint8 offset) internal pure returns (bytes6 result) {
  663. if (offset > 6) revert OutOfRangeAccess();
  664. assembly ("memory-safe") {
  665. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  666. }
  667. }
  668. function replace_12_6(bytes12 self, bytes6 value, uint8 offset) internal pure returns (bytes12 result) {
  669. bytes6 oldValue = extract_12_6(self, offset);
  670. assembly ("memory-safe") {
  671. value := and(value, shl(208, not(0)))
  672. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  673. }
  674. }
  675. function extract_12_8(bytes12 self, uint8 offset) internal pure returns (bytes8 result) {
  676. if (offset > 4) revert OutOfRangeAccess();
  677. assembly ("memory-safe") {
  678. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  679. }
  680. }
  681. function replace_12_8(bytes12 self, bytes8 value, uint8 offset) internal pure returns (bytes12 result) {
  682. bytes8 oldValue = extract_12_8(self, offset);
  683. assembly ("memory-safe") {
  684. value := and(value, shl(192, not(0)))
  685. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  686. }
  687. }
  688. function extract_12_10(bytes12 self, uint8 offset) internal pure returns (bytes10 result) {
  689. if (offset > 2) revert OutOfRangeAccess();
  690. assembly ("memory-safe") {
  691. result := and(shl(mul(8, offset), self), shl(176, not(0)))
  692. }
  693. }
  694. function replace_12_10(bytes12 self, bytes10 value, uint8 offset) internal pure returns (bytes12 result) {
  695. bytes10 oldValue = extract_12_10(self, offset);
  696. assembly ("memory-safe") {
  697. value := and(value, shl(176, not(0)))
  698. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  699. }
  700. }
  701. function extract_16_1(bytes16 self, uint8 offset) internal pure returns (bytes1 result) {
  702. if (offset > 15) revert OutOfRangeAccess();
  703. assembly ("memory-safe") {
  704. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  705. }
  706. }
  707. function replace_16_1(bytes16 self, bytes1 value, uint8 offset) internal pure returns (bytes16 result) {
  708. bytes1 oldValue = extract_16_1(self, offset);
  709. assembly ("memory-safe") {
  710. value := and(value, shl(248, not(0)))
  711. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  712. }
  713. }
  714. function extract_16_2(bytes16 self, uint8 offset) internal pure returns (bytes2 result) {
  715. if (offset > 14) revert OutOfRangeAccess();
  716. assembly ("memory-safe") {
  717. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  718. }
  719. }
  720. function replace_16_2(bytes16 self, bytes2 value, uint8 offset) internal pure returns (bytes16 result) {
  721. bytes2 oldValue = extract_16_2(self, offset);
  722. assembly ("memory-safe") {
  723. value := and(value, shl(240, not(0)))
  724. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  725. }
  726. }
  727. function extract_16_4(bytes16 self, uint8 offset) internal pure returns (bytes4 result) {
  728. if (offset > 12) revert OutOfRangeAccess();
  729. assembly ("memory-safe") {
  730. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  731. }
  732. }
  733. function replace_16_4(bytes16 self, bytes4 value, uint8 offset) internal pure returns (bytes16 result) {
  734. bytes4 oldValue = extract_16_4(self, offset);
  735. assembly ("memory-safe") {
  736. value := and(value, shl(224, not(0)))
  737. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  738. }
  739. }
  740. function extract_16_6(bytes16 self, uint8 offset) internal pure returns (bytes6 result) {
  741. if (offset > 10) revert OutOfRangeAccess();
  742. assembly ("memory-safe") {
  743. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  744. }
  745. }
  746. function replace_16_6(bytes16 self, bytes6 value, uint8 offset) internal pure returns (bytes16 result) {
  747. bytes6 oldValue = extract_16_6(self, offset);
  748. assembly ("memory-safe") {
  749. value := and(value, shl(208, not(0)))
  750. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  751. }
  752. }
  753. function extract_16_8(bytes16 self, uint8 offset) internal pure returns (bytes8 result) {
  754. if (offset > 8) revert OutOfRangeAccess();
  755. assembly ("memory-safe") {
  756. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  757. }
  758. }
  759. function replace_16_8(bytes16 self, bytes8 value, uint8 offset) internal pure returns (bytes16 result) {
  760. bytes8 oldValue = extract_16_8(self, offset);
  761. assembly ("memory-safe") {
  762. value := and(value, shl(192, not(0)))
  763. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  764. }
  765. }
  766. function extract_16_10(bytes16 self, uint8 offset) internal pure returns (bytes10 result) {
  767. if (offset > 6) revert OutOfRangeAccess();
  768. assembly ("memory-safe") {
  769. result := and(shl(mul(8, offset), self), shl(176, not(0)))
  770. }
  771. }
  772. function replace_16_10(bytes16 self, bytes10 value, uint8 offset) internal pure returns (bytes16 result) {
  773. bytes10 oldValue = extract_16_10(self, offset);
  774. assembly ("memory-safe") {
  775. value := and(value, shl(176, not(0)))
  776. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  777. }
  778. }
  779. function extract_16_12(bytes16 self, uint8 offset) internal pure returns (bytes12 result) {
  780. if (offset > 4) revert OutOfRangeAccess();
  781. assembly ("memory-safe") {
  782. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  783. }
  784. }
  785. function replace_16_12(bytes16 self, bytes12 value, uint8 offset) internal pure returns (bytes16 result) {
  786. bytes12 oldValue = extract_16_12(self, offset);
  787. assembly ("memory-safe") {
  788. value := and(value, shl(160, not(0)))
  789. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  790. }
  791. }
  792. function extract_20_1(bytes20 self, uint8 offset) internal pure returns (bytes1 result) {
  793. if (offset > 19) revert OutOfRangeAccess();
  794. assembly ("memory-safe") {
  795. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  796. }
  797. }
  798. function replace_20_1(bytes20 self, bytes1 value, uint8 offset) internal pure returns (bytes20 result) {
  799. bytes1 oldValue = extract_20_1(self, offset);
  800. assembly ("memory-safe") {
  801. value := and(value, shl(248, not(0)))
  802. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  803. }
  804. }
  805. function extract_20_2(bytes20 self, uint8 offset) internal pure returns (bytes2 result) {
  806. if (offset > 18) revert OutOfRangeAccess();
  807. assembly ("memory-safe") {
  808. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  809. }
  810. }
  811. function replace_20_2(bytes20 self, bytes2 value, uint8 offset) internal pure returns (bytes20 result) {
  812. bytes2 oldValue = extract_20_2(self, offset);
  813. assembly ("memory-safe") {
  814. value := and(value, shl(240, not(0)))
  815. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  816. }
  817. }
  818. function extract_20_4(bytes20 self, uint8 offset) internal pure returns (bytes4 result) {
  819. if (offset > 16) revert OutOfRangeAccess();
  820. assembly ("memory-safe") {
  821. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  822. }
  823. }
  824. function replace_20_4(bytes20 self, bytes4 value, uint8 offset) internal pure returns (bytes20 result) {
  825. bytes4 oldValue = extract_20_4(self, offset);
  826. assembly ("memory-safe") {
  827. value := and(value, shl(224, not(0)))
  828. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  829. }
  830. }
  831. function extract_20_6(bytes20 self, uint8 offset) internal pure returns (bytes6 result) {
  832. if (offset > 14) revert OutOfRangeAccess();
  833. assembly ("memory-safe") {
  834. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  835. }
  836. }
  837. function replace_20_6(bytes20 self, bytes6 value, uint8 offset) internal pure returns (bytes20 result) {
  838. bytes6 oldValue = extract_20_6(self, offset);
  839. assembly ("memory-safe") {
  840. value := and(value, shl(208, not(0)))
  841. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  842. }
  843. }
  844. function extract_20_8(bytes20 self, uint8 offset) internal pure returns (bytes8 result) {
  845. if (offset > 12) revert OutOfRangeAccess();
  846. assembly ("memory-safe") {
  847. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  848. }
  849. }
  850. function replace_20_8(bytes20 self, bytes8 value, uint8 offset) internal pure returns (bytes20 result) {
  851. bytes8 oldValue = extract_20_8(self, offset);
  852. assembly ("memory-safe") {
  853. value := and(value, shl(192, not(0)))
  854. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  855. }
  856. }
  857. function extract_20_10(bytes20 self, uint8 offset) internal pure returns (bytes10 result) {
  858. if (offset > 10) revert OutOfRangeAccess();
  859. assembly ("memory-safe") {
  860. result := and(shl(mul(8, offset), self), shl(176, not(0)))
  861. }
  862. }
  863. function replace_20_10(bytes20 self, bytes10 value, uint8 offset) internal pure returns (bytes20 result) {
  864. bytes10 oldValue = extract_20_10(self, offset);
  865. assembly ("memory-safe") {
  866. value := and(value, shl(176, not(0)))
  867. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  868. }
  869. }
  870. function extract_20_12(bytes20 self, uint8 offset) internal pure returns (bytes12 result) {
  871. if (offset > 8) revert OutOfRangeAccess();
  872. assembly ("memory-safe") {
  873. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  874. }
  875. }
  876. function replace_20_12(bytes20 self, bytes12 value, uint8 offset) internal pure returns (bytes20 result) {
  877. bytes12 oldValue = extract_20_12(self, offset);
  878. assembly ("memory-safe") {
  879. value := and(value, shl(160, not(0)))
  880. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  881. }
  882. }
  883. function extract_20_16(bytes20 self, uint8 offset) internal pure returns (bytes16 result) {
  884. if (offset > 4) revert OutOfRangeAccess();
  885. assembly ("memory-safe") {
  886. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  887. }
  888. }
  889. function replace_20_16(bytes20 self, bytes16 value, uint8 offset) internal pure returns (bytes20 result) {
  890. bytes16 oldValue = extract_20_16(self, offset);
  891. assembly ("memory-safe") {
  892. value := and(value, shl(128, not(0)))
  893. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  894. }
  895. }
  896. function extract_22_1(bytes22 self, uint8 offset) internal pure returns (bytes1 result) {
  897. if (offset > 21) revert OutOfRangeAccess();
  898. assembly ("memory-safe") {
  899. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  900. }
  901. }
  902. function replace_22_1(bytes22 self, bytes1 value, uint8 offset) internal pure returns (bytes22 result) {
  903. bytes1 oldValue = extract_22_1(self, offset);
  904. assembly ("memory-safe") {
  905. value := and(value, shl(248, not(0)))
  906. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  907. }
  908. }
  909. function extract_22_2(bytes22 self, uint8 offset) internal pure returns (bytes2 result) {
  910. if (offset > 20) revert OutOfRangeAccess();
  911. assembly ("memory-safe") {
  912. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  913. }
  914. }
  915. function replace_22_2(bytes22 self, bytes2 value, uint8 offset) internal pure returns (bytes22 result) {
  916. bytes2 oldValue = extract_22_2(self, offset);
  917. assembly ("memory-safe") {
  918. value := and(value, shl(240, not(0)))
  919. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  920. }
  921. }
  922. function extract_22_4(bytes22 self, uint8 offset) internal pure returns (bytes4 result) {
  923. if (offset > 18) revert OutOfRangeAccess();
  924. assembly ("memory-safe") {
  925. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  926. }
  927. }
  928. function replace_22_4(bytes22 self, bytes4 value, uint8 offset) internal pure returns (bytes22 result) {
  929. bytes4 oldValue = extract_22_4(self, offset);
  930. assembly ("memory-safe") {
  931. value := and(value, shl(224, not(0)))
  932. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  933. }
  934. }
  935. function extract_22_6(bytes22 self, uint8 offset) internal pure returns (bytes6 result) {
  936. if (offset > 16) revert OutOfRangeAccess();
  937. assembly ("memory-safe") {
  938. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  939. }
  940. }
  941. function replace_22_6(bytes22 self, bytes6 value, uint8 offset) internal pure returns (bytes22 result) {
  942. bytes6 oldValue = extract_22_6(self, offset);
  943. assembly ("memory-safe") {
  944. value := and(value, shl(208, not(0)))
  945. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  946. }
  947. }
  948. function extract_22_8(bytes22 self, uint8 offset) internal pure returns (bytes8 result) {
  949. if (offset > 14) revert OutOfRangeAccess();
  950. assembly ("memory-safe") {
  951. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  952. }
  953. }
  954. function replace_22_8(bytes22 self, bytes8 value, uint8 offset) internal pure returns (bytes22 result) {
  955. bytes8 oldValue = extract_22_8(self, offset);
  956. assembly ("memory-safe") {
  957. value := and(value, shl(192, not(0)))
  958. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  959. }
  960. }
  961. function extract_22_10(bytes22 self, uint8 offset) internal pure returns (bytes10 result) {
  962. if (offset > 12) revert OutOfRangeAccess();
  963. assembly ("memory-safe") {
  964. result := and(shl(mul(8, offset), self), shl(176, not(0)))
  965. }
  966. }
  967. function replace_22_10(bytes22 self, bytes10 value, uint8 offset) internal pure returns (bytes22 result) {
  968. bytes10 oldValue = extract_22_10(self, offset);
  969. assembly ("memory-safe") {
  970. value := and(value, shl(176, not(0)))
  971. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  972. }
  973. }
  974. function extract_22_12(bytes22 self, uint8 offset) internal pure returns (bytes12 result) {
  975. if (offset > 10) revert OutOfRangeAccess();
  976. assembly ("memory-safe") {
  977. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  978. }
  979. }
  980. function replace_22_12(bytes22 self, bytes12 value, uint8 offset) internal pure returns (bytes22 result) {
  981. bytes12 oldValue = extract_22_12(self, offset);
  982. assembly ("memory-safe") {
  983. value := and(value, shl(160, not(0)))
  984. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  985. }
  986. }
  987. function extract_22_16(bytes22 self, uint8 offset) internal pure returns (bytes16 result) {
  988. if (offset > 6) revert OutOfRangeAccess();
  989. assembly ("memory-safe") {
  990. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  991. }
  992. }
  993. function replace_22_16(bytes22 self, bytes16 value, uint8 offset) internal pure returns (bytes22 result) {
  994. bytes16 oldValue = extract_22_16(self, offset);
  995. assembly ("memory-safe") {
  996. value := and(value, shl(128, not(0)))
  997. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  998. }
  999. }
  1000. function extract_22_20(bytes22 self, uint8 offset) internal pure returns (bytes20 result) {
  1001. if (offset > 2) revert OutOfRangeAccess();
  1002. assembly ("memory-safe") {
  1003. result := and(shl(mul(8, offset), self), shl(96, not(0)))
  1004. }
  1005. }
  1006. function replace_22_20(bytes22 self, bytes20 value, uint8 offset) internal pure returns (bytes22 result) {
  1007. bytes20 oldValue = extract_22_20(self, offset);
  1008. assembly ("memory-safe") {
  1009. value := and(value, shl(96, not(0)))
  1010. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1011. }
  1012. }
  1013. function extract_24_1(bytes24 self, uint8 offset) internal pure returns (bytes1 result) {
  1014. if (offset > 23) revert OutOfRangeAccess();
  1015. assembly ("memory-safe") {
  1016. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  1017. }
  1018. }
  1019. function replace_24_1(bytes24 self, bytes1 value, uint8 offset) internal pure returns (bytes24 result) {
  1020. bytes1 oldValue = extract_24_1(self, offset);
  1021. assembly ("memory-safe") {
  1022. value := and(value, shl(248, not(0)))
  1023. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1024. }
  1025. }
  1026. function extract_24_2(bytes24 self, uint8 offset) internal pure returns (bytes2 result) {
  1027. if (offset > 22) revert OutOfRangeAccess();
  1028. assembly ("memory-safe") {
  1029. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  1030. }
  1031. }
  1032. function replace_24_2(bytes24 self, bytes2 value, uint8 offset) internal pure returns (bytes24 result) {
  1033. bytes2 oldValue = extract_24_2(self, offset);
  1034. assembly ("memory-safe") {
  1035. value := and(value, shl(240, not(0)))
  1036. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1037. }
  1038. }
  1039. function extract_24_4(bytes24 self, uint8 offset) internal pure returns (bytes4 result) {
  1040. if (offset > 20) revert OutOfRangeAccess();
  1041. assembly ("memory-safe") {
  1042. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  1043. }
  1044. }
  1045. function replace_24_4(bytes24 self, bytes4 value, uint8 offset) internal pure returns (bytes24 result) {
  1046. bytes4 oldValue = extract_24_4(self, offset);
  1047. assembly ("memory-safe") {
  1048. value := and(value, shl(224, not(0)))
  1049. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1050. }
  1051. }
  1052. function extract_24_6(bytes24 self, uint8 offset) internal pure returns (bytes6 result) {
  1053. if (offset > 18) revert OutOfRangeAccess();
  1054. assembly ("memory-safe") {
  1055. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  1056. }
  1057. }
  1058. function replace_24_6(bytes24 self, bytes6 value, uint8 offset) internal pure returns (bytes24 result) {
  1059. bytes6 oldValue = extract_24_6(self, offset);
  1060. assembly ("memory-safe") {
  1061. value := and(value, shl(208, not(0)))
  1062. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1063. }
  1064. }
  1065. function extract_24_8(bytes24 self, uint8 offset) internal pure returns (bytes8 result) {
  1066. if (offset > 16) revert OutOfRangeAccess();
  1067. assembly ("memory-safe") {
  1068. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  1069. }
  1070. }
  1071. function replace_24_8(bytes24 self, bytes8 value, uint8 offset) internal pure returns (bytes24 result) {
  1072. bytes8 oldValue = extract_24_8(self, offset);
  1073. assembly ("memory-safe") {
  1074. value := and(value, shl(192, not(0)))
  1075. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1076. }
  1077. }
  1078. function extract_24_10(bytes24 self, uint8 offset) internal pure returns (bytes10 result) {
  1079. if (offset > 14) revert OutOfRangeAccess();
  1080. assembly ("memory-safe") {
  1081. result := and(shl(mul(8, offset), self), shl(176, not(0)))
  1082. }
  1083. }
  1084. function replace_24_10(bytes24 self, bytes10 value, uint8 offset) internal pure returns (bytes24 result) {
  1085. bytes10 oldValue = extract_24_10(self, offset);
  1086. assembly ("memory-safe") {
  1087. value := and(value, shl(176, not(0)))
  1088. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1089. }
  1090. }
  1091. function extract_24_12(bytes24 self, uint8 offset) internal pure returns (bytes12 result) {
  1092. if (offset > 12) revert OutOfRangeAccess();
  1093. assembly ("memory-safe") {
  1094. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  1095. }
  1096. }
  1097. function replace_24_12(bytes24 self, bytes12 value, uint8 offset) internal pure returns (bytes24 result) {
  1098. bytes12 oldValue = extract_24_12(self, offset);
  1099. assembly ("memory-safe") {
  1100. value := and(value, shl(160, not(0)))
  1101. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1102. }
  1103. }
  1104. function extract_24_16(bytes24 self, uint8 offset) internal pure returns (bytes16 result) {
  1105. if (offset > 8) revert OutOfRangeAccess();
  1106. assembly ("memory-safe") {
  1107. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  1108. }
  1109. }
  1110. function replace_24_16(bytes24 self, bytes16 value, uint8 offset) internal pure returns (bytes24 result) {
  1111. bytes16 oldValue = extract_24_16(self, offset);
  1112. assembly ("memory-safe") {
  1113. value := and(value, shl(128, not(0)))
  1114. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1115. }
  1116. }
  1117. function extract_24_20(bytes24 self, uint8 offset) internal pure returns (bytes20 result) {
  1118. if (offset > 4) revert OutOfRangeAccess();
  1119. assembly ("memory-safe") {
  1120. result := and(shl(mul(8, offset), self), shl(96, not(0)))
  1121. }
  1122. }
  1123. function replace_24_20(bytes24 self, bytes20 value, uint8 offset) internal pure returns (bytes24 result) {
  1124. bytes20 oldValue = extract_24_20(self, offset);
  1125. assembly ("memory-safe") {
  1126. value := and(value, shl(96, not(0)))
  1127. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1128. }
  1129. }
  1130. function extract_24_22(bytes24 self, uint8 offset) internal pure returns (bytes22 result) {
  1131. if (offset > 2) revert OutOfRangeAccess();
  1132. assembly ("memory-safe") {
  1133. result := and(shl(mul(8, offset), self), shl(80, not(0)))
  1134. }
  1135. }
  1136. function replace_24_22(bytes24 self, bytes22 value, uint8 offset) internal pure returns (bytes24 result) {
  1137. bytes22 oldValue = extract_24_22(self, offset);
  1138. assembly ("memory-safe") {
  1139. value := and(value, shl(80, not(0)))
  1140. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1141. }
  1142. }
  1143. function extract_28_1(bytes28 self, uint8 offset) internal pure returns (bytes1 result) {
  1144. if (offset > 27) revert OutOfRangeAccess();
  1145. assembly ("memory-safe") {
  1146. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  1147. }
  1148. }
  1149. function replace_28_1(bytes28 self, bytes1 value, uint8 offset) internal pure returns (bytes28 result) {
  1150. bytes1 oldValue = extract_28_1(self, offset);
  1151. assembly ("memory-safe") {
  1152. value := and(value, shl(248, not(0)))
  1153. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1154. }
  1155. }
  1156. function extract_28_2(bytes28 self, uint8 offset) internal pure returns (bytes2 result) {
  1157. if (offset > 26) revert OutOfRangeAccess();
  1158. assembly ("memory-safe") {
  1159. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  1160. }
  1161. }
  1162. function replace_28_2(bytes28 self, bytes2 value, uint8 offset) internal pure returns (bytes28 result) {
  1163. bytes2 oldValue = extract_28_2(self, offset);
  1164. assembly ("memory-safe") {
  1165. value := and(value, shl(240, not(0)))
  1166. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1167. }
  1168. }
  1169. function extract_28_4(bytes28 self, uint8 offset) internal pure returns (bytes4 result) {
  1170. if (offset > 24) revert OutOfRangeAccess();
  1171. assembly ("memory-safe") {
  1172. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  1173. }
  1174. }
  1175. function replace_28_4(bytes28 self, bytes4 value, uint8 offset) internal pure returns (bytes28 result) {
  1176. bytes4 oldValue = extract_28_4(self, offset);
  1177. assembly ("memory-safe") {
  1178. value := and(value, shl(224, not(0)))
  1179. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1180. }
  1181. }
  1182. function extract_28_6(bytes28 self, uint8 offset) internal pure returns (bytes6 result) {
  1183. if (offset > 22) revert OutOfRangeAccess();
  1184. assembly ("memory-safe") {
  1185. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  1186. }
  1187. }
  1188. function replace_28_6(bytes28 self, bytes6 value, uint8 offset) internal pure returns (bytes28 result) {
  1189. bytes6 oldValue = extract_28_6(self, offset);
  1190. assembly ("memory-safe") {
  1191. value := and(value, shl(208, not(0)))
  1192. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1193. }
  1194. }
  1195. function extract_28_8(bytes28 self, uint8 offset) internal pure returns (bytes8 result) {
  1196. if (offset > 20) revert OutOfRangeAccess();
  1197. assembly ("memory-safe") {
  1198. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  1199. }
  1200. }
  1201. function replace_28_8(bytes28 self, bytes8 value, uint8 offset) internal pure returns (bytes28 result) {
  1202. bytes8 oldValue = extract_28_8(self, offset);
  1203. assembly ("memory-safe") {
  1204. value := and(value, shl(192, not(0)))
  1205. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1206. }
  1207. }
  1208. function extract_28_10(bytes28 self, uint8 offset) internal pure returns (bytes10 result) {
  1209. if (offset > 18) revert OutOfRangeAccess();
  1210. assembly ("memory-safe") {
  1211. result := and(shl(mul(8, offset), self), shl(176, not(0)))
  1212. }
  1213. }
  1214. function replace_28_10(bytes28 self, bytes10 value, uint8 offset) internal pure returns (bytes28 result) {
  1215. bytes10 oldValue = extract_28_10(self, offset);
  1216. assembly ("memory-safe") {
  1217. value := and(value, shl(176, not(0)))
  1218. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1219. }
  1220. }
  1221. function extract_28_12(bytes28 self, uint8 offset) internal pure returns (bytes12 result) {
  1222. if (offset > 16) revert OutOfRangeAccess();
  1223. assembly ("memory-safe") {
  1224. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  1225. }
  1226. }
  1227. function replace_28_12(bytes28 self, bytes12 value, uint8 offset) internal pure returns (bytes28 result) {
  1228. bytes12 oldValue = extract_28_12(self, offset);
  1229. assembly ("memory-safe") {
  1230. value := and(value, shl(160, not(0)))
  1231. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1232. }
  1233. }
  1234. function extract_28_16(bytes28 self, uint8 offset) internal pure returns (bytes16 result) {
  1235. if (offset > 12) revert OutOfRangeAccess();
  1236. assembly ("memory-safe") {
  1237. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  1238. }
  1239. }
  1240. function replace_28_16(bytes28 self, bytes16 value, uint8 offset) internal pure returns (bytes28 result) {
  1241. bytes16 oldValue = extract_28_16(self, offset);
  1242. assembly ("memory-safe") {
  1243. value := and(value, shl(128, not(0)))
  1244. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1245. }
  1246. }
  1247. function extract_28_20(bytes28 self, uint8 offset) internal pure returns (bytes20 result) {
  1248. if (offset > 8) revert OutOfRangeAccess();
  1249. assembly ("memory-safe") {
  1250. result := and(shl(mul(8, offset), self), shl(96, not(0)))
  1251. }
  1252. }
  1253. function replace_28_20(bytes28 self, bytes20 value, uint8 offset) internal pure returns (bytes28 result) {
  1254. bytes20 oldValue = extract_28_20(self, offset);
  1255. assembly ("memory-safe") {
  1256. value := and(value, shl(96, not(0)))
  1257. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1258. }
  1259. }
  1260. function extract_28_22(bytes28 self, uint8 offset) internal pure returns (bytes22 result) {
  1261. if (offset > 6) revert OutOfRangeAccess();
  1262. assembly ("memory-safe") {
  1263. result := and(shl(mul(8, offset), self), shl(80, not(0)))
  1264. }
  1265. }
  1266. function replace_28_22(bytes28 self, bytes22 value, uint8 offset) internal pure returns (bytes28 result) {
  1267. bytes22 oldValue = extract_28_22(self, offset);
  1268. assembly ("memory-safe") {
  1269. value := and(value, shl(80, not(0)))
  1270. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1271. }
  1272. }
  1273. function extract_28_24(bytes28 self, uint8 offset) internal pure returns (bytes24 result) {
  1274. if (offset > 4) revert OutOfRangeAccess();
  1275. assembly ("memory-safe") {
  1276. result := and(shl(mul(8, offset), self), shl(64, not(0)))
  1277. }
  1278. }
  1279. function replace_28_24(bytes28 self, bytes24 value, uint8 offset) internal pure returns (bytes28 result) {
  1280. bytes24 oldValue = extract_28_24(self, offset);
  1281. assembly ("memory-safe") {
  1282. value := and(value, shl(64, not(0)))
  1283. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1284. }
  1285. }
  1286. function extract_32_1(bytes32 self, uint8 offset) internal pure returns (bytes1 result) {
  1287. if (offset > 31) revert OutOfRangeAccess();
  1288. assembly ("memory-safe") {
  1289. result := and(shl(mul(8, offset), self), shl(248, not(0)))
  1290. }
  1291. }
  1292. function replace_32_1(bytes32 self, bytes1 value, uint8 offset) internal pure returns (bytes32 result) {
  1293. bytes1 oldValue = extract_32_1(self, offset);
  1294. assembly ("memory-safe") {
  1295. value := and(value, shl(248, not(0)))
  1296. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1297. }
  1298. }
  1299. function extract_32_2(bytes32 self, uint8 offset) internal pure returns (bytes2 result) {
  1300. if (offset > 30) revert OutOfRangeAccess();
  1301. assembly ("memory-safe") {
  1302. result := and(shl(mul(8, offset), self), shl(240, not(0)))
  1303. }
  1304. }
  1305. function replace_32_2(bytes32 self, bytes2 value, uint8 offset) internal pure returns (bytes32 result) {
  1306. bytes2 oldValue = extract_32_2(self, offset);
  1307. assembly ("memory-safe") {
  1308. value := and(value, shl(240, not(0)))
  1309. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1310. }
  1311. }
  1312. function extract_32_4(bytes32 self, uint8 offset) internal pure returns (bytes4 result) {
  1313. if (offset > 28) revert OutOfRangeAccess();
  1314. assembly ("memory-safe") {
  1315. result := and(shl(mul(8, offset), self), shl(224, not(0)))
  1316. }
  1317. }
  1318. function replace_32_4(bytes32 self, bytes4 value, uint8 offset) internal pure returns (bytes32 result) {
  1319. bytes4 oldValue = extract_32_4(self, offset);
  1320. assembly ("memory-safe") {
  1321. value := and(value, shl(224, not(0)))
  1322. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1323. }
  1324. }
  1325. function extract_32_6(bytes32 self, uint8 offset) internal pure returns (bytes6 result) {
  1326. if (offset > 26) revert OutOfRangeAccess();
  1327. assembly ("memory-safe") {
  1328. result := and(shl(mul(8, offset), self), shl(208, not(0)))
  1329. }
  1330. }
  1331. function replace_32_6(bytes32 self, bytes6 value, uint8 offset) internal pure returns (bytes32 result) {
  1332. bytes6 oldValue = extract_32_6(self, offset);
  1333. assembly ("memory-safe") {
  1334. value := and(value, shl(208, not(0)))
  1335. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1336. }
  1337. }
  1338. function extract_32_8(bytes32 self, uint8 offset) internal pure returns (bytes8 result) {
  1339. if (offset > 24) revert OutOfRangeAccess();
  1340. assembly ("memory-safe") {
  1341. result := and(shl(mul(8, offset), self), shl(192, not(0)))
  1342. }
  1343. }
  1344. function replace_32_8(bytes32 self, bytes8 value, uint8 offset) internal pure returns (bytes32 result) {
  1345. bytes8 oldValue = extract_32_8(self, offset);
  1346. assembly ("memory-safe") {
  1347. value := and(value, shl(192, not(0)))
  1348. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1349. }
  1350. }
  1351. function extract_32_10(bytes32 self, uint8 offset) internal pure returns (bytes10 result) {
  1352. if (offset > 22) revert OutOfRangeAccess();
  1353. assembly ("memory-safe") {
  1354. result := and(shl(mul(8, offset), self), shl(176, not(0)))
  1355. }
  1356. }
  1357. function replace_32_10(bytes32 self, bytes10 value, uint8 offset) internal pure returns (bytes32 result) {
  1358. bytes10 oldValue = extract_32_10(self, offset);
  1359. assembly ("memory-safe") {
  1360. value := and(value, shl(176, not(0)))
  1361. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1362. }
  1363. }
  1364. function extract_32_12(bytes32 self, uint8 offset) internal pure returns (bytes12 result) {
  1365. if (offset > 20) revert OutOfRangeAccess();
  1366. assembly ("memory-safe") {
  1367. result := and(shl(mul(8, offset), self), shl(160, not(0)))
  1368. }
  1369. }
  1370. function replace_32_12(bytes32 self, bytes12 value, uint8 offset) internal pure returns (bytes32 result) {
  1371. bytes12 oldValue = extract_32_12(self, offset);
  1372. assembly ("memory-safe") {
  1373. value := and(value, shl(160, not(0)))
  1374. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1375. }
  1376. }
  1377. function extract_32_16(bytes32 self, uint8 offset) internal pure returns (bytes16 result) {
  1378. if (offset > 16) revert OutOfRangeAccess();
  1379. assembly ("memory-safe") {
  1380. result := and(shl(mul(8, offset), self), shl(128, not(0)))
  1381. }
  1382. }
  1383. function replace_32_16(bytes32 self, bytes16 value, uint8 offset) internal pure returns (bytes32 result) {
  1384. bytes16 oldValue = extract_32_16(self, offset);
  1385. assembly ("memory-safe") {
  1386. value := and(value, shl(128, not(0)))
  1387. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1388. }
  1389. }
  1390. function extract_32_20(bytes32 self, uint8 offset) internal pure returns (bytes20 result) {
  1391. if (offset > 12) revert OutOfRangeAccess();
  1392. assembly ("memory-safe") {
  1393. result := and(shl(mul(8, offset), self), shl(96, not(0)))
  1394. }
  1395. }
  1396. function replace_32_20(bytes32 self, bytes20 value, uint8 offset) internal pure returns (bytes32 result) {
  1397. bytes20 oldValue = extract_32_20(self, offset);
  1398. assembly ("memory-safe") {
  1399. value := and(value, shl(96, not(0)))
  1400. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1401. }
  1402. }
  1403. function extract_32_22(bytes32 self, uint8 offset) internal pure returns (bytes22 result) {
  1404. if (offset > 10) revert OutOfRangeAccess();
  1405. assembly ("memory-safe") {
  1406. result := and(shl(mul(8, offset), self), shl(80, not(0)))
  1407. }
  1408. }
  1409. function replace_32_22(bytes32 self, bytes22 value, uint8 offset) internal pure returns (bytes32 result) {
  1410. bytes22 oldValue = extract_32_22(self, offset);
  1411. assembly ("memory-safe") {
  1412. value := and(value, shl(80, not(0)))
  1413. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1414. }
  1415. }
  1416. function extract_32_24(bytes32 self, uint8 offset) internal pure returns (bytes24 result) {
  1417. if (offset > 8) revert OutOfRangeAccess();
  1418. assembly ("memory-safe") {
  1419. result := and(shl(mul(8, offset), self), shl(64, not(0)))
  1420. }
  1421. }
  1422. function replace_32_24(bytes32 self, bytes24 value, uint8 offset) internal pure returns (bytes32 result) {
  1423. bytes24 oldValue = extract_32_24(self, offset);
  1424. assembly ("memory-safe") {
  1425. value := and(value, shl(64, not(0)))
  1426. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1427. }
  1428. }
  1429. function extract_32_28(bytes32 self, uint8 offset) internal pure returns (bytes28 result) {
  1430. if (offset > 4) revert OutOfRangeAccess();
  1431. assembly ("memory-safe") {
  1432. result := and(shl(mul(8, offset), self), shl(32, not(0)))
  1433. }
  1434. }
  1435. function replace_32_28(bytes32 self, bytes28 value, uint8 offset) internal pure returns (bytes32 result) {
  1436. bytes28 oldValue = extract_32_28(self, offset);
  1437. assembly ("memory-safe") {
  1438. value := and(value, shl(32, not(0)))
  1439. result := xor(self, shr(mul(8, offset), xor(oldValue, value)))
  1440. }
  1441. }
  1442. }