chaokunyang commented on code in PR #2004:
URL: https://github.com/apache/fory/pull/2004#discussion_r2139214781
##########
csharp/Fury/Serialization/Meta/ReferenceMetaSerializer.cs:
##########
@@ -0,0 +1,242 @@
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Diagnostics.CodeAnalysis;
+using System.Threading;
+using System.Threading.Tasks;
+using Fury.Collections;
+using Fury.Context;
+using Fury.Meta;
+
+namespace Fury.Serialization.Meta;
+
+internal sealed class ReferenceMetaSerializer
+{
+ private bool _referenceTracking;
+
+ private readonly HashSet<object> _objectsBeingSerialized = [];
+ private readonly AutoIncrementIdDictionary<object> _writtenRefIds = new();
+ private bool _hasWrittenRefId;
+ private bool _hasWrittenRefFlag;
+ private RefMetadata? _cachedRefMetadata;
+
+ public void Reset()
+ {
+ ResetCurrent();
+
+ _objectsBeingSerialized.Clear();
+ _writtenRefIds.Clear();
+ }
+
+ public void Initialize(bool referenceTracking)
+ {
+ _referenceTracking = referenceTracking;
+ }
+
+ public void ResetCurrent()
+ {
+ _hasWrittenRefId = false;
+ _hasWrittenRefFlag = false;
+ _cachedRefMetadata = null;
+ }
+
+ public bool Write<TTarget>(ref SerializationWriterRef writerRef, in
TTarget? value, out RefFlag writtenFlag)
+ {
+ if (value is null)
+ {
+ writtenFlag = RefFlag.Null;
+ WriteRefFlag(ref writerRef, writtenFlag);
Review Comment:
we just write one byte for null, but write a varint for ref tracking
--
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]