WritingPrimitives.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. #region Copyright notice and license
  2. // Protocol Buffers - Google's data interchange format
  3. // Copyright 2008 Google Inc. All rights reserved.
  4. // https://developers.google.com/protocol-buffers/
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are
  8. // met:
  9. //
  10. // * Redistributions of source code must retain the above copyright
  11. // notice, this list of conditions and the following disclaimer.
  12. // * Redistributions in binary form must reproduce the above
  13. // copyright notice, this list of conditions and the following disclaimer
  14. // in the documentation and/or other materials provided with the
  15. // distribution.
  16. // * Neither the name of Google Inc. nor the names of its
  17. // contributors may be used to endorse or promote products derived from
  18. // this software without specific prior written permission.
  19. //
  20. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. #endregion
  32. using System;
  33. using System.Buffers.Binary;
  34. using System.Runtime.CompilerServices;
  35. using System.Runtime.InteropServices;
  36. using System.Security;
  37. using System.Text;
  38. namespace Google.Protobuf
  39. {
  40. /// <summary>
  41. /// Primitives for encoding protobuf wire format.
  42. /// </summary>
  43. [SecuritySafeCritical]
  44. internal static class WritingPrimitives
  45. {
  46. // "Local" copy of Encoding.UTF8, for efficiency. (Yes, it makes a difference.)
  47. internal static readonly Encoding Utf8Encoding = Encoding.UTF8;
  48. #region Writing of values (not including tags)
  49. /// <summary>
  50. /// Writes a double field value, without a tag, to the stream.
  51. /// </summary>
  52. public static void WriteDouble(ref Span<byte> buffer, ref WriterInternalState state, double value)
  53. {
  54. WriteRawLittleEndian64(ref buffer, ref state, (ulong)BitConverter.DoubleToInt64Bits(value));
  55. }
  56. /// <summary>
  57. /// Writes a float field value, without a tag, to the stream.
  58. /// </summary>
  59. public static unsafe void WriteFloat(ref Span<byte> buffer, ref WriterInternalState state, float value)
  60. {
  61. const int length = sizeof(float);
  62. if (buffer.Length - state.position >= length)
  63. {
  64. // if there's enough space in the buffer, write the float directly into the buffer
  65. var floatSpan = buffer.Slice(state.position, length);
  66. Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(floatSpan), value);
  67. if (!BitConverter.IsLittleEndian)
  68. {
  69. floatSpan.Reverse();
  70. }
  71. state.position += length;
  72. }
  73. else
  74. {
  75. WriteFloatSlowPath(ref buffer, ref state, value);
  76. }
  77. }
  78. [MethodImpl(MethodImplOptions.NoInlining)]
  79. private static unsafe void WriteFloatSlowPath(ref Span<byte> buffer, ref WriterInternalState state, float value)
  80. {
  81. const int length = sizeof(float);
  82. // TODO(jtattermusch): deduplicate the code. Populating the span is the same as for the fastpath.
  83. Span<byte> floatSpan = stackalloc byte[length];
  84. Unsafe.WriteUnaligned(ref MemoryMarshal.GetReference(floatSpan), value);
  85. if (!BitConverter.IsLittleEndian)
  86. {
  87. floatSpan.Reverse();
  88. }
  89. WriteRawByte(ref buffer, ref state, floatSpan[0]);
  90. WriteRawByte(ref buffer, ref state, floatSpan[1]);
  91. WriteRawByte(ref buffer, ref state, floatSpan[2]);
  92. WriteRawByte(ref buffer, ref state, floatSpan[3]);
  93. }
  94. /// <summary>
  95. /// Writes a uint64 field value, without a tag, to the stream.
  96. /// </summary>
  97. public static void WriteUInt64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
  98. {
  99. WriteRawVarint64(ref buffer, ref state, value);
  100. }
  101. /// <summary>
  102. /// Writes an int64 field value, without a tag, to the stream.
  103. /// </summary>
  104. public static void WriteInt64(ref Span<byte> buffer, ref WriterInternalState state, long value)
  105. {
  106. WriteRawVarint64(ref buffer, ref state, (ulong)value);
  107. }
  108. /// <summary>
  109. /// Writes an int32 field value, without a tag, to the stream.
  110. /// </summary>
  111. public static void WriteInt32(ref Span<byte> buffer, ref WriterInternalState state, int value)
  112. {
  113. if (value >= 0)
  114. {
  115. WriteRawVarint32(ref buffer, ref state, (uint)value);
  116. }
  117. else
  118. {
  119. // Must sign-extend.
  120. WriteRawVarint64(ref buffer, ref state, (ulong)value);
  121. }
  122. }
  123. /// <summary>
  124. /// Writes a fixed64 field value, without a tag, to the stream.
  125. /// </summary>
  126. public static void WriteFixed64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
  127. {
  128. WriteRawLittleEndian64(ref buffer, ref state, value);
  129. }
  130. /// <summary>
  131. /// Writes a fixed32 field value, without a tag, to the stream.
  132. /// </summary>
  133. public static void WriteFixed32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
  134. {
  135. WriteRawLittleEndian32(ref buffer, ref state, value);
  136. }
  137. /// <summary>
  138. /// Writes a bool field value, without a tag, to the stream.
  139. /// </summary>
  140. public static void WriteBool(ref Span<byte> buffer, ref WriterInternalState state, bool value)
  141. {
  142. WriteRawByte(ref buffer, ref state, value ? (byte)1 : (byte)0);
  143. }
  144. /// <summary>
  145. /// Writes a string field value, without a tag, to the stream.
  146. /// The data is length-prefixed.
  147. /// </summary>
  148. public static void WriteString(ref Span<byte> buffer, ref WriterInternalState state, string value)
  149. {
  150. // Optimise the case where we have enough space to write
  151. // the string directly to the buffer, which should be common.
  152. int length = Utf8Encoding.GetByteCount(value);
  153. WriteLength(ref buffer, ref state, length);
  154. if (buffer.Length - state.position >= length)
  155. {
  156. if (length == value.Length) // Must be all ASCII...
  157. {
  158. for (int i = 0; i < length; i++)
  159. {
  160. buffer[state.position + i] = (byte)value[i];
  161. }
  162. state.position += length;
  163. }
  164. else
  165. {
  166. #if NETSTANDARD1_1
  167. // slowpath when Encoding.GetBytes(Char*, Int32, Byte*, Int32) is not available
  168. byte[] bytes = Utf8Encoding.GetBytes(value);
  169. WriteRawBytes(ref buffer, ref state, bytes);
  170. #else
  171. ReadOnlySpan<char> source = value.AsSpan();
  172. int bytesUsed;
  173. unsafe
  174. {
  175. fixed (char* sourceChars = &MemoryMarshal.GetReference(source))
  176. fixed (byte* destinationBytes = &MemoryMarshal.GetReference(buffer.Slice(state.position)))
  177. {
  178. bytesUsed = Utf8Encoding.GetBytes(sourceChars, source.Length, destinationBytes, buffer.Length);
  179. }
  180. }
  181. state.position += bytesUsed;
  182. #endif
  183. }
  184. }
  185. else
  186. {
  187. // Opportunity for future optimization:
  188. // Large strings that don't fit into the current buffer segment
  189. // can probably be optimized by using Utf8Encoding.GetEncoder()
  190. // but more benchmarks would need to be added as evidence.
  191. byte[] bytes = Utf8Encoding.GetBytes(value);
  192. WriteRawBytes(ref buffer, ref state, bytes);
  193. }
  194. }
  195. /// <summary>
  196. /// Write a byte string, without a tag, to the stream.
  197. /// The data is length-prefixed.
  198. /// </summary>
  199. public static void WriteBytes(ref Span<byte> buffer, ref WriterInternalState state, ByteString value)
  200. {
  201. WriteLength(ref buffer, ref state, value.Length);
  202. WriteRawBytes(ref buffer, ref state, value.Span);
  203. }
  204. /// <summary>
  205. /// Writes a uint32 value, without a tag, to the stream.
  206. /// </summary>
  207. public static void WriteUInt32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
  208. {
  209. WriteRawVarint32(ref buffer, ref state, value);
  210. }
  211. /// <summary>
  212. /// Writes an enum value, without a tag, to the stream.
  213. /// </summary>
  214. public static void WriteEnum(ref Span<byte> buffer, ref WriterInternalState state, int value)
  215. {
  216. WriteInt32(ref buffer, ref state, value);
  217. }
  218. /// <summary>
  219. /// Writes an sfixed32 value, without a tag, to the stream.
  220. /// </summary>
  221. public static void WriteSFixed32(ref Span<byte> buffer, ref WriterInternalState state, int value)
  222. {
  223. WriteRawLittleEndian32(ref buffer, ref state, (uint)value);
  224. }
  225. /// <summary>
  226. /// Writes an sfixed64 value, without a tag, to the stream.
  227. /// </summary>
  228. public static void WriteSFixed64(ref Span<byte> buffer, ref WriterInternalState state, long value)
  229. {
  230. WriteRawLittleEndian64(ref buffer, ref state, (ulong)value);
  231. }
  232. /// <summary>
  233. /// Writes an sint32 value, without a tag, to the stream.
  234. /// </summary>
  235. public static void WriteSInt32(ref Span<byte> buffer, ref WriterInternalState state, int value)
  236. {
  237. WriteRawVarint32(ref buffer, ref state, EncodeZigZag32(value));
  238. }
  239. /// <summary>
  240. /// Writes an sint64 value, without a tag, to the stream.
  241. /// </summary>
  242. public static void WriteSInt64(ref Span<byte> buffer, ref WriterInternalState state, long value)
  243. {
  244. WriteRawVarint64(ref buffer, ref state, EncodeZigZag64(value));
  245. }
  246. /// <summary>
  247. /// Writes a length (in bytes) for length-delimited data.
  248. /// </summary>
  249. /// <remarks>
  250. /// This method simply writes a rawint, but exists for clarity in calling code.
  251. /// </remarks>
  252. public static void WriteLength(ref Span<byte> buffer, ref WriterInternalState state, int length)
  253. {
  254. WriteRawVarint32(ref buffer, ref state, (uint)length);
  255. }
  256. #endregion
  257. #region Writing primitives
  258. /// <summary>
  259. /// Writes a 32 bit value as a varint. The fast route is taken when
  260. /// there's enough buffer space left to whizz through without checking
  261. /// for each byte; otherwise, we resort to calling WriteRawByte each time.
  262. /// </summary>
  263. public static void WriteRawVarint32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
  264. {
  265. // Optimize for the common case of a single byte value
  266. if (value < 128 && state.position < buffer.Length)
  267. {
  268. buffer[state.position++] = (byte)value;
  269. return;
  270. }
  271. // Fast path when capacity is available
  272. while (state.position < buffer.Length)
  273. {
  274. if (value > 127)
  275. {
  276. buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
  277. value >>= 7;
  278. }
  279. else
  280. {
  281. buffer[state.position++] = (byte)value;
  282. return;
  283. }
  284. }
  285. while (value > 127)
  286. {
  287. WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
  288. value >>= 7;
  289. }
  290. WriteRawByte(ref buffer, ref state, (byte)value);
  291. }
  292. public static void WriteRawVarint64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
  293. {
  294. // Optimize for the common case of a single byte value
  295. if (value < 128 && state.position < buffer.Length)
  296. {
  297. buffer[state.position++] = (byte)value;
  298. return;
  299. }
  300. // Fast path when capacity is available
  301. while (state.position < buffer.Length)
  302. {
  303. if (value > 127)
  304. {
  305. buffer[state.position++] = (byte)((value & 0x7F) | 0x80);
  306. value >>= 7;
  307. }
  308. else
  309. {
  310. buffer[state.position++] = (byte)value;
  311. return;
  312. }
  313. }
  314. while (value > 127)
  315. {
  316. WriteRawByte(ref buffer, ref state, (byte)((value & 0x7F) | 0x80));
  317. value >>= 7;
  318. }
  319. WriteRawByte(ref buffer, ref state, (byte)value);
  320. }
  321. public static void WriteRawLittleEndian32(ref Span<byte> buffer, ref WriterInternalState state, uint value)
  322. {
  323. const int length = sizeof(uint);
  324. if (state.position + length > buffer.Length)
  325. {
  326. WriteRawLittleEndian32SlowPath(ref buffer, ref state, value);
  327. }
  328. else
  329. {
  330. BinaryPrimitives.WriteUInt32LittleEndian(buffer.Slice(state.position), value);
  331. state.position += length;
  332. }
  333. }
  334. [MethodImpl(MethodImplOptions.NoInlining)]
  335. private static void WriteRawLittleEndian32SlowPath(ref Span<byte> buffer, ref WriterInternalState state, uint value)
  336. {
  337. WriteRawByte(ref buffer, ref state, (byte)value);
  338. WriteRawByte(ref buffer, ref state, (byte)(value >> 8));
  339. WriteRawByte(ref buffer, ref state, (byte)(value >> 16));
  340. WriteRawByte(ref buffer, ref state, (byte)(value >> 24));
  341. }
  342. public static void WriteRawLittleEndian64(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
  343. {
  344. const int length = sizeof(ulong);
  345. if (state.position + length > buffer.Length)
  346. {
  347. WriteRawLittleEndian64SlowPath(ref buffer, ref state, value);
  348. }
  349. else
  350. {
  351. // TODO(jtattermusch): According to the benchmarks, writing byte-by-byte is actually faster
  352. // than using BinaryPrimitives.WriteUInt64LittleEndian.
  353. // This is strange especially because WriteUInt32LittleEndian seems to be much faster
  354. // in terms of throughput.
  355. buffer[state.position++] = ((byte)value);
  356. buffer[state.position++] = ((byte)(value >> 8));
  357. buffer[state.position++] = ((byte)(value >> 16));
  358. buffer[state.position++] = ((byte)(value >> 24));
  359. buffer[state.position++] = ((byte)(value >> 32));
  360. buffer[state.position++] = ((byte)(value >> 40));
  361. buffer[state.position++] = ((byte)(value >> 48));
  362. buffer[state.position++] = ((byte)(value >> 56));
  363. }
  364. }
  365. [MethodImpl(MethodImplOptions.NoInlining)]
  366. public static void WriteRawLittleEndian64SlowPath(ref Span<byte> buffer, ref WriterInternalState state, ulong value)
  367. {
  368. WriteRawByte(ref buffer, ref state, (byte)value);
  369. WriteRawByte(ref buffer, ref state, (byte)(value >> 8));
  370. WriteRawByte(ref buffer, ref state, (byte)(value >> 16));
  371. WriteRawByte(ref buffer, ref state, (byte)(value >> 24));
  372. WriteRawByte(ref buffer, ref state, (byte)(value >> 32));
  373. WriteRawByte(ref buffer, ref state, (byte)(value >> 40));
  374. WriteRawByte(ref buffer, ref state, (byte)(value >> 48));
  375. WriteRawByte(ref buffer, ref state, (byte)(value >> 56));
  376. }
  377. private static void WriteRawByte(ref Span<byte> buffer, ref WriterInternalState state, byte value)
  378. {
  379. if (state.position == buffer.Length)
  380. {
  381. WriteBufferHelper.RefreshBuffer(ref buffer, ref state);
  382. }
  383. buffer[state.position++] = value;
  384. }
  385. /// <summary>
  386. /// Writes out an array of bytes.
  387. /// </summary>
  388. public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, byte[] value)
  389. {
  390. WriteRawBytes(ref buffer, ref state, new ReadOnlySpan<byte>(value));
  391. }
  392. /// <summary>
  393. /// Writes out part of an array of bytes.
  394. /// </summary>
  395. public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, byte[] value, int offset, int length)
  396. {
  397. WriteRawBytes(ref buffer, ref state, new ReadOnlySpan<byte>(value, offset, length));
  398. }
  399. /// <summary>
  400. /// Writes out part of an array of bytes.
  401. /// </summary>
  402. public static void WriteRawBytes(ref Span<byte> buffer, ref WriterInternalState state, ReadOnlySpan<byte> value)
  403. {
  404. if (buffer.Length - state.position >= value.Length)
  405. {
  406. // We have room in the current buffer.
  407. value.CopyTo(buffer.Slice(state.position, value.Length));
  408. state.position += value.Length;
  409. }
  410. else
  411. {
  412. // When writing to a CodedOutputStream backed by a Stream, we could avoid
  413. // copying the data twice (first copying to the current buffer and
  414. // and later writing from the current buffer to the underlying Stream)
  415. // in some circumstances by writing the data directly to the underlying Stream.
  416. // Current this is not being done to avoid specialcasing the code for
  417. // CodedOutputStream vs IBufferWriter<byte>.
  418. int bytesWritten = 0;
  419. while (buffer.Length - state.position < value.Length - bytesWritten)
  420. {
  421. int length = buffer.Length - state.position;
  422. value.Slice(bytesWritten, length).CopyTo(buffer.Slice(state.position, length));
  423. bytesWritten += length;
  424. state.position += length;
  425. WriteBufferHelper.RefreshBuffer(ref buffer, ref state);
  426. }
  427. // copy the remaining data
  428. int remainderLength = value.Length - bytesWritten;
  429. value.Slice(bytesWritten, remainderLength).CopyTo(buffer.Slice(state.position, remainderLength));
  430. state.position += remainderLength;
  431. }
  432. }
  433. #endregion
  434. #region Raw tag writing
  435. /// <summary>
  436. /// Encodes and writes a tag.
  437. /// </summary>
  438. public static void WriteTag(ref Span<byte> buffer, ref WriterInternalState state, int fieldNumber, WireFormat.WireType type)
  439. {
  440. WriteRawVarint32(ref buffer, ref state, WireFormat.MakeTag(fieldNumber, type));
  441. }
  442. /// <summary>
  443. /// Writes an already-encoded tag.
  444. /// </summary>
  445. public static void WriteTag(ref Span<byte> buffer, ref WriterInternalState state, uint tag)
  446. {
  447. WriteRawVarint32(ref buffer, ref state, tag);
  448. }
  449. /// <summary>
  450. /// Writes the given single-byte tag directly to the stream.
  451. /// </summary>
  452. public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1)
  453. {
  454. WriteRawByte(ref buffer, ref state, b1);
  455. }
  456. /// <summary>
  457. /// Writes the given two-byte tag directly to the stream.
  458. /// </summary>
  459. public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2)
  460. {
  461. WriteRawByte(ref buffer, ref state, b1);
  462. WriteRawByte(ref buffer, ref state, b2);
  463. }
  464. /// <summary>
  465. /// Writes the given three-byte tag directly to the stream.
  466. /// </summary>
  467. public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3)
  468. {
  469. WriteRawByte(ref buffer, ref state, b1);
  470. WriteRawByte(ref buffer, ref state, b2);
  471. WriteRawByte(ref buffer, ref state, b3);
  472. }
  473. /// <summary>
  474. /// Writes the given four-byte tag directly to the stream.
  475. /// </summary>
  476. public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4)
  477. {
  478. WriteRawByte(ref buffer, ref state, b1);
  479. WriteRawByte(ref buffer, ref state, b2);
  480. WriteRawByte(ref buffer, ref state, b3);
  481. WriteRawByte(ref buffer, ref state, b4);
  482. }
  483. /// <summary>
  484. /// Writes the given five-byte tag directly to the stream.
  485. /// </summary>
  486. public static void WriteRawTag(ref Span<byte> buffer, ref WriterInternalState state, byte b1, byte b2, byte b3, byte b4, byte b5)
  487. {
  488. WriteRawByte(ref buffer, ref state, b1);
  489. WriteRawByte(ref buffer, ref state, b2);
  490. WriteRawByte(ref buffer, ref state, b3);
  491. WriteRawByte(ref buffer, ref state, b4);
  492. WriteRawByte(ref buffer, ref state, b5);
  493. }
  494. #endregion
  495. /// <summary>
  496. /// Encode a 32-bit value with ZigZag encoding.
  497. /// </summary>
  498. /// <remarks>
  499. /// ZigZag encodes signed integers into values that can be efficiently
  500. /// encoded with varint. (Otherwise, negative values must be
  501. /// sign-extended to 64 bits to be varint encoded, thus always taking
  502. /// 10 bytes on the wire.)
  503. /// </remarks>
  504. public static uint EncodeZigZag32(int n)
  505. {
  506. // Note: the right-shift must be arithmetic
  507. return (uint)((n << 1) ^ (n >> 31));
  508. }
  509. /// <summary>
  510. /// Encode a 64-bit value with ZigZag encoding.
  511. /// </summary>
  512. /// <remarks>
  513. /// ZigZag encodes signed integers into values that can be efficiently
  514. /// encoded with varint. (Otherwise, negative values must be
  515. /// sign-extended to 64 bits to be varint encoded, thus always taking
  516. /// 10 bytes on the wire.)
  517. /// </remarks>
  518. public static ulong EncodeZigZag64(long n)
  519. {
  520. return (ulong)((n << 1) ^ (n >> 63));
  521. }
  522. }
  523. }