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