chaokunyang commented on code in PR #2004:
URL: https://github.com/apache/fory/pull/2004#discussion_r2139208645


##########
csharp/Fury/Serialization/Meta/HeaderSerializer.cs:
##########
@@ -0,0 +1,163 @@
+using System;
+using System.Diagnostics.CodeAnalysis;
+using System.Threading;
+using System.Threading.Tasks;
+using Fury.Context;
+using Fury.Meta;
+
+namespace Fury.Serialization.Meta;
+
+[Flags]
+file enum HeaderFlag : byte
+{
+    NullRootObject = 1,
+    LittleEndian = 1 << 1,
+    CrossLanguage = 1 << 2,
+    OutOfBand = 1 << 3,
+}
+
+file static class HeaderHelper
+{
+    public const short MagicNumber = 0x62D4;
+}
+
+internal sealed class HeaderSerializer
+{
+    private bool _hasWrittenMagicNumber;
+    private bool _hasWrittenHeaderFlag;
+    private bool _hasWrittenLanguage;
+
+    public void Reset()
+    {
+        _hasWrittenMagicNumber = false;
+        _hasWrittenHeaderFlag = false;
+        _hasWrittenLanguage = false;
+    }
+
+    public bool Write(ref SerializationWriterRef writerRef, bool 
rootObjectIsNull)
+    {
+        if (!_hasWrittenMagicNumber)
+        {
+            _hasWrittenMagicNumber = 
writerRef.WriteInt16(HeaderHelper.MagicNumber);
+            if (!_hasWrittenMagicNumber)
+            {
+                return false;
+            }
+        }
+
+        if (!_hasWrittenHeaderFlag)
+        {
+            var flag = HeaderFlag.LittleEndian | HeaderFlag.CrossLanguage;
+            if (rootObjectIsNull)
+            {
+                flag |= HeaderFlag.NullRootObject;
+            }
+
+            _hasWrittenHeaderFlag = writerRef.WriteUInt8((byte)flag);
+            if (!_hasWrittenMagicNumber)

Review Comment:
   ```suggestion
               if (!_hasWrittenHeaderFlag)
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to