|
10 | 10 | using System.IO; |
11 | 11 | using System.Text; // For StringBuilder. |
12 | 12 | using System.Buffers.Binary; |
13 | | -using System.Runtime.InteropServices; |
14 | 13 | // see #Introduction and #SerializerIntroduction |
15 | 14 | namespace FastSerialization |
16 | 15 | { |
@@ -185,6 +184,10 @@ interface IStreamWriter : IDisposable |
185 | 184 | /// </summary> |
186 | 185 | void Write(int value); |
187 | 186 | /// <summary> |
| 187 | + /// Write an blob to a stream |
| 188 | + /// </summary> |
| 189 | + void WriteBlobAsInt(int value); |
| 190 | + /// <summary> |
188 | 191 | /// Write a long to a stream |
189 | 192 | /// </summary> |
190 | 193 | void Write(long value); |
@@ -605,7 +608,7 @@ public Serializer(IStreamWriter writer, IFastSerializable entryObject) |
605 | 608 | Log("<ForwardRefTable StreamLabel=\"0x" + forwardRefsLabel.ToString("x") + "\">"); |
606 | 609 | if (forwardReferenceDefinitions != null) |
607 | 610 | { |
608 | | - Write(BinaryPrimitives.ReadInt32LittleEndian(BitConverter.GetBytes(forwardReferenceDefinitions.Count))); |
| 611 | + Write(forwardReferenceDefinitions.Count); |
609 | 612 | for (int i = 0; i < forwardReferenceDefinitions.Count; i++) |
610 | 613 | { |
611 | 614 | Debug.Assert(forwardReferenceDefinitions[i] != StreamLabel.Invalid); |
@@ -675,6 +678,14 @@ public void Write(int value) |
675 | 678 | writer.Write(value); |
676 | 679 | } |
677 | 680 | /// <summary> |
| 681 | + /// Write an blob to a stream |
| 682 | + /// </summary> |
| 683 | + public void WriteBlobAsInt(int value) |
| 684 | + { |
| 685 | + Log("<Write Type=\"int\" Value=\"" + value + "\" StreamLabel=\"0x" + writer.GetLabel().ToString("x") + "\"/>"); |
| 686 | + writer.WriteBlobAsInt(value); |
| 687 | + } |
| 688 | + /// <summary> |
678 | 689 | /// Write a long to a stream |
679 | 690 | /// </summary> |
680 | 691 | public void Write(long value) |
@@ -823,15 +834,15 @@ public void DefineForwardReference(ForwardReference forwardReference) |
823 | 834 | /// <summary> |
824 | 835 | /// Write a byte preceded by a tag that indicates its a short. These should be read with the corresponding TryReadTagged operation |
825 | 836 | /// </summary> |
826 | | - public void WriteTagged(short value) { WriteTag(Tags.Int16); Write(BinaryPrimitives.ReadInt16LittleEndian(BitConverter.GetBytes(value))); } |
| 837 | + public void WriteTagged(short value) { WriteTag(Tags.Int16); Write(value); } |
827 | 838 | /// <summary> |
828 | 839 | /// Write a byte preceded by a tag that indicates its a int. These should be read with the corresponding TryReadTagged operation |
829 | 840 | /// </summary> |
830 | | - public void WriteTagged(int value) { WriteTag(Tags.Int32); Write(BinaryPrimitives.ReadInt32LittleEndian(BitConverter.GetBytes(value))); } |
| 841 | + public void WriteTagged(int value) { WriteTag(Tags.Int32); Write(value); } |
831 | 842 | /// <summary> |
832 | 843 | /// Write a byte preceded by a tag that indicates its a long. These should be read with the corresponding TryReadTagged operation |
833 | 844 | /// </summary> |
834 | | - public void WriteTagged(long value) { WriteTag(Tags.Int64); Write(BinaryPrimitives.ReadInt64LittleEndian(BitConverter.GetBytes(value))); } |
| 845 | + public void WriteTagged(long value) { WriteTag(Tags.Int64); Write(value); } |
835 | 846 | /// <summary> |
836 | 847 | /// Write a byte preceded by a tag that indicates its a string. These should be read with the corresponding TryReadTagged operation |
837 | 848 | /// </summary> |
@@ -1599,6 +1610,7 @@ public StreamLabel ResolveForwardReference(ForwardReference reference, bool pres |
1599 | 1610 | reader.GotoSuffixLabel(); |
1600 | 1611 | Log("<Trailer StreamLabel=\"0x" + reader.Current.ToString("x") + "\"/>"); |
1601 | 1612 | StreamLabel forwardRefsLabel = reader.ReadLabel(); |
| 1613 | + |
1602 | 1614 | Goto(forwardRefsLabel); |
1603 | 1615 | int fowardRefCount = reader.ReadInt32(); |
1604 | 1616 | Log("<ForwardReferenceDefinitons StreamLabel=\"0x" + forwardRefsLabel.ToString("x") + |
@@ -2233,7 +2245,7 @@ public void Write(Serializer serializer, Action toStream) |
2233 | 2245 | serializer.Log("<DeferedRegion>\r\n"); |
2234 | 2246 | // We actually don't use the this pointer! We did this for symmetry with Read |
2235 | 2247 | ForwardReference endRegion = serializer.GetForwardReference(); |
2236 | | - serializer.Write(BinaryPrimitives.ReadInt32LittleEndian(BitConverter.GetBytes((int)endRegion))); // Allow the reader to skip this. |
| 2248 | + serializer.Write(endRegion); // Allow the reader to skip this. |
2237 | 2249 | toStream(); // Write the deferred data. |
2238 | 2250 | serializer.DefineForwardReference(endRegion); |
2239 | 2251 | serializer.Log("</DeferedRegion>\r\n"); |
@@ -2510,8 +2522,8 @@ internal SerializationType(string fullName, Deserializer deserializer) |
2510 | 2522 | } |
2511 | 2523 | void IFastSerializable.ToStream(Serializer serializer) |
2512 | 2524 | { |
2513 | | - serializer.Write(BinaryPrimitives.ReadInt32LittleEndian(BitConverter.GetBytes(version))); |
2514 | | - serializer.Write(BinaryPrimitives.ReadInt32LittleEndian(BitConverter.GetBytes(minimumReaderVersion))); |
| 2525 | + serializer.Write(version); |
| 2526 | + serializer.Write(minimumReaderVersion); |
2515 | 2527 | serializer.Write(fullName); |
2516 | 2528 | } |
2517 | 2529 | void IFastSerializable.FromStream(Deserializer deserializer) |
|
0 commit comments