-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
BinaryStreamingLite.pas
4312 lines (3333 loc) · 144 KB
/
BinaryStreamingLite.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-------------------------------------------------------------------------------
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
-------------------------------------------------------------------------------}
{===============================================================================
Binary streaming lite
This unit provides lightened version of BinaryStreaming library (which can
be found here: github.com/TheLazyTomcat/Lib.BinaryStreaming).
Over time, BinaryStreaming (further referred to only as BS) became bloated
with features that were only seldomly needed. This library was created for
situations, where core functionality was sufficient and/or using full BS
was undesirable (eg. because of long(er) compile times).
It provides functions for streaming of almost all basic types to memory
(Ptr_* functions) and to TStream descendants (Stream_* functions), with
exception being variants - they are not supported.
In provided functions, selection of endianness was removed - everything is
done in little endian.
And lastly, streamer objects were also completely removed.
For further details (eg. about how the primitives are streamed), please
refer to descriptions in the original BS.
NOTE - this entire unit was build from the original BS using a
specialized program, it was not manually written. The code was
copied, so if BS contains some error, it might appear here too.
Build from BinaryStreaming of version 2.0.3 (2024-04-14)
Version 1.0.1 (2024-04-14)
Last change 2024-04-14
©2024 František Milt
Contacts:
František Milt: [email protected]
Support:
If you find this code useful, please consider supporting its author(s) by
making a small donation using the following link(s):
https://www.paypal.me/FMilt
Changelog:
For detailed changelog and history please refer to this git repository:
github.com/TheLazyTomcat/Lib.BinaryStreamingLite
Dependencies:
* AuxExceptions - github.com/TheLazyTomcat/Lib.AuxExceptions
AuxTypes - github.com/TheLazyTomcat/Lib.AuxTypes
StrRect - github.com/TheLazyTomcat/Lib.StrRect
Library AuxExceptions is required only when rebasing local exception classes
(see symbol BinaryStreamingLite_UseAuxExceptions for details).
Indirect dependencies:
SimpleCPUID - github.com/TheLazyTomcat/Lib.SimpleCPUID
UInt64Utils - github.com/TheLazyTomcat/Lib.UInt64Utils
WinFileInfo - github.com/TheLazyTomcat/Lib.WinFileInfo
===============================================================================}
unit BinaryStreamingLite;
{
BinaryStreamingLite_UseAuxExceptions
If you want library-specific exceptions to be based on more advanced classes
provided by AuxExceptions library instead of basic Exception class, and don't
want to or cannot change code in this unit, you can define global symbol
BinaryStreamingLite_UseAuxExceptions to achieve this.
}
{$IF Defined(BinaryStreamingLite_UseAuxExceptions)}
{$DEFINE UseAuxExceptions}
{$IFEND}
//------------------------------------------------------------------------------
{$IFDEF FPC}
{$MODE ObjFPC}
{$INLINE ON}
{$DEFINE CanInline}
{$DEFINE FPC_DisableWarns}
{$MACRO ON}
{$ELSE}
{$IF CompilerVersion >= 17} // Delphi 2005+
{$DEFINE CanInline}
{$IFEND}
{$ENDIF}
{$H+}
interface
uses
SysUtils, Classes,
AuxTypes, StrRect {$IFDEF UseAuxExceptions}, AuxExceptions{$ENDIF};
{===============================================================================
Library-specific exceptions
===============================================================================}
type
EBSLException = class({$IFDEF UseAuxExceptions}EAEGeneralException{$ELSE}Exception{$ENDIF});
{===============================================================================
--------------------------------------------------------------------------------
Allocation helpers
--------------------------------------------------------------------------------
===============================================================================}
{
Following functions are returning number of bytes that are required to store
a given object. They are here mainly to ease allocation when streaming into
memory.
Basic types have static size (for completeness sake they are nevertheless
included), but strings and variants are a little trickier and must be scanned
to obtain the true size.
}
Function StreamedSize_Bool: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Boolean: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function StreamedSize_Int8: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UInt8: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Int16: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UInt16: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Int32: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UInt32: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Int64: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UInt64: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function StreamedSize_Float32: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Float64: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Float80: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_DateTime: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Currency: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function StreamedSize_AnsiChar: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UTF8Char: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_WideChar: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UnicodeChar: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UCS4Char: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Char: TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function StreamedSize_ShortString(const Value: ShortString): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_AnsiString(const Value: AnsiString): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UTF8String(const Value: UTF8String): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_WideString(const Value: WideString): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UnicodeString(const Value: UnicodeString): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_UCS4String(const Value: UCS4String): TMemSize;
Function StreamedSize_String(const Value: String): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function StreamedSize_Buffer(Size: TMemSize): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function StreamedSize_Bytes(Count: TMemSize): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Memory writing
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
Booleans
-------------------------------------------------------------------------------}
Function Ptr_WriteBool(var Dest: Pointer; Value: ByteBool; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteBool(Dest: Pointer; Value: ByteBool): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteBoolean(var Dest: Pointer; Value: Boolean; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_WriteBoolean(Dest: Pointer; Value: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Integers
-------------------------------------------------------------------------------}
Function Ptr_WriteInt8(var Dest: Pointer; Value: Int8; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteInt8(Dest: Pointer; Value: Int8): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUInt8(var Dest: Pointer; Value: UInt8; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUInt8(Dest: Pointer; Value: UInt8): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteInt16(var Dest: Pointer; Value: Int16; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteInt16(Dest: Pointer; Value: Int16): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUInt16(var Dest: Pointer; Value: UInt16; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUInt16(Dest: Pointer; Value: UInt16): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteInt32(var Dest: Pointer; Value: Int32; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteInt32(Dest: Pointer; Value: Int32): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUInt32(var Dest: Pointer; Value: UInt32; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUInt32(Dest: Pointer; Value: UInt32): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteInt64(var Dest: Pointer; Value: Int64; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteInt64(Dest: Pointer; Value: Int64): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUInt64(var Dest: Pointer; Value: UInt64; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUInt64(Dest: Pointer; Value: UInt64): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Floating point numbers
-------------------------------------------------------------------------------}
Function Ptr_WriteFloat32(var Dest: Pointer; Value: Float32; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteFloat32(Dest: Pointer; Value: Float32): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteFloat64(var Dest: Pointer; Value: Float64; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteFloat64(Dest: Pointer; Value: Float64): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteFloat80(var Dest: Pointer; Value: Float80; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteFloat80(Dest: Pointer; Value: Float80): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteDateTime(var Dest: Pointer; Value: TDateTime; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_WriteDateTime(Dest: Pointer; Value: TDateTime): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteCurrency(var Dest: Pointer; Value: Currency; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteCurrency(Dest: Pointer; Value: Currency): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Characters
-------------------------------------------------------------------------------}
Function Ptr_WriteAnsiChar(var Dest: Pointer; Value: AnsiChar; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteAnsiChar(Dest: Pointer; Value: AnsiChar): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUTF8Char(var Dest: Pointer; Value: UTF8Char; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUTF8Char(Dest: Pointer; Value: UTF8Char): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteWideChar(var Dest: Pointer; Value: WideChar; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteWideChar(Dest: Pointer; Value: WideChar): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUnicodeChar(var Dest: Pointer; Value: UnicodeChar; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUnicodeChar(Dest: Pointer; Value: UnicodeChar): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUCS4Char(var Dest: Pointer; Value: UCS4Char; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUCS4Char(Dest: Pointer; Value: UCS4Char): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteChar(var Dest: Pointer; Value: Char; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_WriteChar(Dest: Pointer; Value: Char): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Strings
-------------------------------------------------------------------------------}
Function Ptr_WriteShortString(var Dest: Pointer; const Value: ShortString; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteShortString(Dest: Pointer; const Value: ShortString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteAnsiString(var Dest: Pointer; const Value: AnsiString; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteAnsiString(Dest: Pointer; const Value: AnsiString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUTF8String(var Dest: Pointer; const Value: UTF8String; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUTF8String(Dest: Pointer; const Value: UTF8String): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteWideString(var Dest: Pointer; const Value: WideString; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteWideString(Dest: Pointer; const Value: WideString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUnicodeString(var Dest: Pointer; const Value: UnicodeString; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUnicodeString(Dest: Pointer; const Value: UnicodeString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteUCS4String(var Dest: Pointer; const Value: UCS4String; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteUCS4String(Dest: Pointer; const Value: UCS4String): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_WriteString(var Dest: Pointer; const Value: String; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_WriteString(Dest: Pointer; const Value: String): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
General data buffers
-------------------------------------------------------------------------------}
Function Ptr_WriteBuffer(var Dest: Pointer; const Buffer; Size: TMemSize; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteBuffer(Dest: Pointer; const Buffer; Size: TMemSize): TMemSize; overload;
//------------------------------------------------------------------------------
// note - calls with open array cannot be inlined both in Delphi and FPC
Function Ptr_WriteBytes(var Dest: Pointer; const Value: array of UInt8; Advance: Boolean): TMemSize; overload;
Function Ptr_WriteBytes(Dest: Pointer; const Value: array of UInt8): TMemSize; overload;
//------------------------------------------------------------------------------
Function Ptr_FillBytes(var Dest: Pointer; Count: TMemSize; Value: UInt8; Advance: Boolean): TMemSize; overload;
Function Ptr_FillBytes(Dest: Pointer; Count: TMemSize; Value: UInt8): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
{===============================================================================
--------------------------------------------------------------------------------
Memory reading
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
Booleans
-------------------------------------------------------------------------------}
Function Ptr_ReadBool(var Src: Pointer; out Value: ByteBool; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadBool(Src: Pointer; out Value: ByteBool): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetBool(var Src: Pointer; Advance: Boolean): ByteBool; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetBool(Src: Pointer): ByteBool; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadBoolean(var Src: Pointer; out Value: Boolean; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_ReadBoolean(Src: Pointer; out Value: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetBoolean(var Src: Pointer; Advance: Boolean): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetBoolean(Src: Pointer): Boolean; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Integers
-------------------------------------------------------------------------------}
Function Ptr_ReadInt8(var Src: Pointer; out Value: Int8; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadInt8(Src: Pointer; out Value: Int8): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt8(var Src: Pointer; Advance: Boolean): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt8(Src: Pointer): Int8; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUInt8(var Src: Pointer; out Value: UInt8; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUInt8(Src: Pointer; out Value: UInt8): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt8(var Src: Pointer; Advance: Boolean): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt8(Src: Pointer): UInt8; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadInt16(var Src: Pointer; out Value: Int16; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadInt16(Src: Pointer; out Value: Int16): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt16(var Src: Pointer; Advance: Boolean): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt16(Src: Pointer): Int16; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUInt16(var Src: Pointer; out Value: UInt16; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUInt16(Src: Pointer; out Value: UInt16): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt16(var Src: Pointer; Advance: Boolean): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt16(Src: Pointer): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadInt32(var Src: Pointer; out Value: Int32; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadInt32(Src: Pointer; out Value: Int32): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt32(var Src: Pointer; Advance: Boolean): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt32(Src: Pointer): Int32; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUInt32(var Src: Pointer; out Value: UInt32; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUInt32(Src: Pointer; out Value: UInt32): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt32(var Src: Pointer; Advance: Boolean): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt32(Src: Pointer): UInt32; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadInt64(var Src: Pointer; out Value: Int64; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadInt64(Src: Pointer; out Value: Int64): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt64(var Src: Pointer; Advance: Boolean): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetInt64(Src: Pointer): Int64; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUInt64(var Src: Pointer; out Value: UInt64; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUInt64(Src: Pointer; out Value: UInt64): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt64(var Src: Pointer; Advance: Boolean): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUInt64(Src: Pointer): UInt64; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Floating point numbers
-------------------------------------------------------------------------------}
Function Ptr_ReadFloat32(var Src: Pointer; out Value: Float32; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadFloat32(Src: Pointer; out Value: Float32): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetFloat32(var Src: Pointer; Advance: Boolean): Float32; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetFloat32(Src: Pointer): Float32; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadFloat64(var Src: Pointer; out Value: Float64; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadFloat64(Src: Pointer; out Value: Float64): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetFloat64(var Src: Pointer; Advance: Boolean): Float64; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetFloat64(Src: Pointer): Float64; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadFloat80(var Src: Pointer; out Value: Float80; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadFloat80(Src: Pointer; out Value: Float80): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetFloat80(var Src: Pointer; Advance: Boolean): Float80; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetFloat80(Src: Pointer): Float80; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadDateTime(var Src: Pointer; out Value: TDateTime; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_ReadDateTime(Src: Pointer; out Value: TDateTime): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetDateTime(var Src: Pointer; Advance: Boolean): TDateTime; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetDateTime(Src: Pointer): TDateTime; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadCurrency(var Src: Pointer; out Value: Currency; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadCurrency(Src: Pointer; out Value: Currency): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetCurrency(var Src: Pointer; Advance: Boolean): Currency; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetCurrency(Src: Pointer): Currency; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Characters
-------------------------------------------------------------------------------}
Function Ptr_ReadAnsiChar(var Src: Pointer; out Value: AnsiChar; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadAnsiChar(Src: Pointer; out Value: AnsiChar): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetAnsiChar(var Src: Pointer; Advance: Boolean): AnsiChar; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetAnsiChar(Src: Pointer): AnsiChar; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUTF8Char(var Src: Pointer; out Value: UTF8Char; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUTF8Char(Src: Pointer; out Value: UTF8Char): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUTF8Char(var Src: Pointer; Advance: Boolean): UTF8Char; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUTF8Char(Src: Pointer): UTF8Char; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadWideChar(var Src: Pointer; out Value: WideChar; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadWideChar(Src: Pointer; out Value: WideChar): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetWideChar(var Src: Pointer; Advance: Boolean): WideChar; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetWideChar(Src: Pointer): WideChar; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUnicodeChar(var Src: Pointer; out Value: UnicodeChar; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUnicodeChar(Src: Pointer; out Value: UnicodeChar): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUnicodeChar(var Src: Pointer; Advance: Boolean): UnicodeChar; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUnicodeChar(Src: Pointer): UnicodeChar; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUCS4Char(var Src: Pointer; out Value: UCS4Char; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUCS4Char(Src: Pointer; out Value: UCS4Char): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUCS4Char(var Src: Pointer; Advance: Boolean): UCS4Char; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUCS4Char(Src: Pointer): UCS4Char; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadChar(var Src: Pointer; out Value: Char; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_ReadChar(Src: Pointer; out Value: Char): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetChar(var Src: Pointer; Advance: Boolean): Char; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetChar(Src: Pointer): Char; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Strings
-------------------------------------------------------------------------------}
Function Ptr_ReadShortString(var Src: Pointer; out Value: ShortString; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadShortString(Src: Pointer; out Value: ShortString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetShortString(var Src: Pointer; Advance: Boolean): ShortString; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetShortString(Src: Pointer): ShortString; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadAnsiString(var Src: Pointer; out Value: AnsiString; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadAnsiString(Src: Pointer; out Value: AnsiString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetAnsiString(var Src: Pointer; Advance: Boolean): AnsiString; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetAnsiString(Src: Pointer): AnsiString; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUTF8String(var Src: Pointer; out Value: UTF8String; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUTF8String(Src: Pointer; out Value: UTF8String): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUTF8String(var Src: Pointer; Advance: Boolean): UTF8String; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUTF8String(Src: Pointer): UTF8String; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadWideString(var Src: Pointer; out Value: WideString; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadWideString(Src: Pointer; out Value: WideString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetWideString(var Src: Pointer; Advance: Boolean): WideString; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetWideString(Src: Pointer): WideString; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUnicodeString(var Src: Pointer; out Value: UnicodeString; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUnicodeString(Src: Pointer; out Value: UnicodeString): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUnicodeString(var Src: Pointer; Advance: Boolean): UnicodeString; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUnicodeString(Src: Pointer): UnicodeString; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadUCS4String(var Src: Pointer; out Value: UCS4String; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadUCS4String(Src: Pointer; out Value: UCS4String): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUCS4String(var Src: Pointer; Advance: Boolean): UCS4String; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetUCS4String(Src: Pointer): UCS4String; overload;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Ptr_ReadString(var Src: Pointer; out Value: String; Advance: Boolean): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_ReadString(Src: Pointer; out Value: String): TMemSize; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetString(var Src: Pointer; Advance: Boolean): String; overload;{$IFDEF CanInline} inline;{$ENDIF}
Function Ptr_GetString(Src: Pointer): String; overload;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
General data buffers
-------------------------------------------------------------------------------}
Function Ptr_ReadBuffer(var Src: Pointer; out Buffer; Size: TMemSize; Advance: Boolean): TMemSize; overload;
Function Ptr_ReadBuffer(Src: Pointer; out Buffer; Size: TMemSize): TMemSize; overload;
{===============================================================================
--------------------------------------------------------------------------------
Stream writing
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
Booleans
-------------------------------------------------------------------------------}
Function Stream_WriteBool(Stream: TStream; Value: ByteBool; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteBoolean(Stream: TStream; Value: Boolean; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Integers
-------------------------------------------------------------------------------}
Function Stream_WriteInt8(Stream: TStream; Value: Int8; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUInt8(Stream: TStream; Value: UInt8; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteInt16(Stream: TStream; Value: Int16; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUInt16(Stream: TStream; Value: UInt16; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteInt32(Stream: TStream; Value: Int32; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUInt32(Stream: TStream; Value: UInt32; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteInt64(Stream: TStream; Value: Int64; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUInt64(Stream: TStream; Value: UInt64; Advance: Boolean = True): TMemSize;
{-------------------------------------------------------------------------------
Floating point numbers
-------------------------------------------------------------------------------}
Function Stream_WriteFloat32(Stream: TStream; Value: Float32; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteFloat64(Stream: TStream; Value: Float64; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteFloat80(Stream: TStream; Value: Float80; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteDateTime(Stream: TStream; Value: TDateTime; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_WriteCurrency(Stream: TStream; Value: Currency; Advance: Boolean = True): TMemSize;
{-------------------------------------------------------------------------------
Characters
-------------------------------------------------------------------------------}
Function Stream_WriteAnsiChar(Stream: TStream; Value: AnsiChar; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUTF8Char(Stream: TStream; Value: UTF8Char; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteWideChar(Stream: TStream; Value: WideChar; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUnicodeChar(Stream: TStream; Value: UnicodeChar; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUCS4Char(Stream: TStream; Value: UCS4Char; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteChar(Stream: TStream; Value: Char; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Strings
-------------------------------------------------------------------------------}
Function Stream_WriteShortString(Stream: TStream; const Value: ShortString; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteAnsiString(Stream: TStream; const Value: AnsiString; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUTF8String(Stream: TStream; const Value: UTF8String; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteWideString(Stream: TStream; const Value: WideString; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUnicodeString(Stream: TStream; const Value: UnicodeString; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteUCS4String(Stream: TStream; const Value: UCS4String; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteString(Stream: TStream; const Value: String; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
General data buffers
-------------------------------------------------------------------------------}
Function Stream_WriteBuffer(Stream: TStream; const Buffer; Size: TMemSize; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_WriteBytes(Stream: TStream; const Value: array of UInt8; Advance: Boolean = True): TMemSize;
//------------------------------------------------------------------------------
Function Stream_FillBytes(Stream: TStream; Count: TMemSize; Value: UInt8; Advance: Boolean = True): TMemSize;
{===============================================================================
--------------------------------------------------------------------------------
Stream reading
--------------------------------------------------------------------------------
===============================================================================}
{-------------------------------------------------------------------------------
Booleans
-------------------------------------------------------------------------------}
Function Stream_ReadBool(Stream: TStream; out Value: ByteBool; Advance: Boolean = True): TMemSize;
Function Stream_GetBool(Stream: TStream; Advance: Boolean = True): ByteBool;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadBoolean(Stream: TStream; out Value: Boolean; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function Stream_GetBoolean(Stream: TStream; Advance: Boolean = True): Boolean;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Integers
-------------------------------------------------------------------------------}
Function Stream_ReadInt8(Stream: TStream; out Value: Int8; Advance: Boolean = True): TMemSize;
Function Stream_GetInt8(Stream: TStream; Advance: Boolean = True): Int8;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUInt8(Stream: TStream; out Value: UInt8; Advance: Boolean = True): TMemSize;
Function Stream_GetUInt8(Stream: TStream; Advance: Boolean = True): UInt8;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadInt16(Stream: TStream; out Value: Int16; Advance: Boolean = True): TMemSize;
Function Stream_GetInt16(Stream: TStream; Advance: Boolean = True): Int16;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUInt16(Stream: TStream; out Value: UInt16; Advance: Boolean = True): TMemSize;
Function Stream_GetUInt16(Stream: TStream; Advance: Boolean = True): UInt16;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadInt32(Stream: TStream; out Value: Int32; Advance: Boolean = True): TMemSize;
Function Stream_GetInt32(Stream: TStream; Advance: Boolean = True): Int32;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUInt32(Stream: TStream; out Value: UInt32; Advance: Boolean = True): TMemSize;
Function Stream_GetUInt32(Stream: TStream; Advance: Boolean = True): UInt32;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadInt64(Stream: TStream; out Value: Int64; Advance: Boolean = True): TMemSize;
Function Stream_GetInt64(Stream: TStream; Advance: Boolean = True): Int64;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUInt64(Stream: TStream; out Value: UInt64; Advance: Boolean = True): TMemSize;
Function Stream_GetUInt64(Stream: TStream; Advance: Boolean = True): UInt64;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Floating point numbers
-------------------------------------------------------------------------------}
Function Stream_ReadFloat32(Stream: TStream; out Value: Float32; Advance: Boolean = True): TMemSize;
Function Stream_GetFloat32(Stream: TStream; Advance: Boolean = True): Float32;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadFloat64(Stream: TStream; out Value: Float64; Advance: Boolean = True): TMemSize;
Function Stream_GetFloat64(Stream: TStream; Advance: Boolean = True): Float64;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadFloat80(Stream: TStream; out Value: Float80; Advance: Boolean = True): TMemSize;
Function Stream_GetFloat80(Stream: TStream; Advance: Boolean = True): Float80;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadDateTime(Stream: TStream; out Value: TDateTime; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function Stream_GetDateTime(Stream: TStream; Advance: Boolean = True): TDateTime;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadCurrency(Stream: TStream; out Value: Currency; Advance: Boolean = True): TMemSize;
Function Stream_GetCurrency(Stream: TStream; Advance: Boolean = True): Currency;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Characters
-------------------------------------------------------------------------------}
Function Stream_ReadAnsiChar(Stream: TStream; out Value: AnsiChar; Advance: Boolean = True): TMemSize;
Function Stream_GetAnsiChar(Stream: TStream; Advance: Boolean = True): AnsiChar;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUTF8Char(Stream: TStream; out Value: UTF8Char; Advance: Boolean = True): TMemSize;
Function Stream_GetUTF8Char(Stream: TStream; Advance: Boolean = True): UTF8Char;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadWideChar(Stream: TStream; out Value: WideChar; Advance: Boolean = True): TMemSize;
Function Stream_GetWideChar(Stream: TStream; Advance: Boolean = True): WideChar;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUnicodeChar(Stream: TStream; out Value: UnicodeChar; Advance: Boolean = True): TMemSize;
Function Stream_GetUnicodeChar(Stream: TStream; Advance: Boolean = True): UnicodeChar;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUCS4Char(Stream: TStream; out Value: UCS4Char; Advance: Boolean = True): TMemSize;
Function Stream_GetUCS4Char(Stream: TStream; Advance: Boolean = True): UCS4Char;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadChar(Stream: TStream; out Value: Char; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function Stream_GetChar(Stream: TStream; Advance: Boolean = True): Char;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
Strings
-------------------------------------------------------------------------------}
Function Stream_ReadShortString(Stream: TStream; out Value: ShortString; Advance: Boolean = True): TMemSize;
Function Stream_GetShortString(Stream: TStream; Advance: Boolean = True): ShortString;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadAnsiString(Stream: TStream; out Value: AnsiString; Advance: Boolean = True): TMemSize;
Function Stream_GetAnsiString(Stream: TStream; Advance: Boolean = True): AnsiString;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUTF8String(Stream: TStream; out Value: UTF8String; Advance: Boolean = True): TMemSize;
Function Stream_GetUTF8String(Stream: TStream; Advance: Boolean = True): UTF8String;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadWideString(Stream: TStream; out Value: WideString; Advance: Boolean = True): TMemSize;
Function Stream_GetWideString(Stream: TStream; Advance: Boolean = True): WideString;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUnicodeString(Stream: TStream; out Value: UnicodeString; Advance: Boolean = True): TMemSize;
Function Stream_GetUnicodeString(Stream: TStream; Advance: Boolean = True): UnicodeString;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadUCS4String(Stream: TStream; out Value: UCS4String; Advance: Boolean = True): TMemSize;
Function Stream_GetUCS4String(Stream: TStream; Advance: Boolean = True): UCS4String;{$IFDEF CanInline} inline;{$ENDIF}
//------------------------------------------------------------------------------
Function Stream_ReadString(Stream: TStream; out Value: String; Advance: Boolean = True): TMemSize;{$IFDEF CanInline} inline;{$ENDIF}
Function Stream_GetString(Stream: TStream; Advance: Boolean = True): String;{$IFDEF CanInline} inline;{$ENDIF}
{-------------------------------------------------------------------------------
General data buffers
-------------------------------------------------------------------------------}
Function Stream_ReadBuffer(Stream: TStream; out Buffer; Size: TMemSize; Advance: Boolean = True): TMemSize;
implementation
uses
Math;
{$IFDEF FPC_DisableWarns}
{$DEFINE FPCDWM}
{$DEFINE W4055:={$WARN 4055 OFF}} // Conversion between ordinals and pointers is not portable
{$ENDIF}
{$IF SizeOf(UInt32) <> SizeOf(UCS4Char)} // just to be sure
{$MESSAGE ERROR 'Type size mismatch (UInt32 - UCS4Char).'}
{$IFEND}
{===============================================================================
Internal variables
===============================================================================}
var
ByteOpenArrayIsPacked: Boolean = False;
{===============================================================================
--------------------------------------------------------------------------------
Auxiliary routines
--------------------------------------------------------------------------------
===============================================================================}
procedure AdvancePointer(Advance: Boolean; var Ptr: Pointer; Offset: TMemSize);{$IFDEF CanInline} inline;{$ENDIF}
begin
{$IFDEF FPCDWM}{$PUSH}W4055{$ENDIF}
If Advance then
Ptr := Pointer(TMemSize(PtrUInt(Ptr)) + Offset);
{$IFDEF FPCDWM}{$POP}{$ENDIF}
end;
//------------------------------------------------------------------------------
procedure AdvanceStream(Advance: Boolean; Stream: TStream; Offset: TMemSize);{$IFDEF CanInline} inline;{$ENDIF}
begin
If not Advance then
Stream.Seek(-Int64(Offset),soCurrent);
end;
//==============================================================================
Function BoolToNum(Val: Boolean): UInt8;{$IFDEF CanInline} inline;{$ENDIF}
begin
If Val then Result := $FF
else Result := 0;
end;
//------------------------------------------------------------------------------
Function NumToBool(Val: UInt8): Boolean;{$IFDEF CanInline} inline;{$ENDIF}
begin
Result := Val <> 0;
end;
//------------------------------------------------------------------------------
procedure ClampStringLength(var StrLength: Int32);{$IFDEF CanInline} inline;{$ENDIF}
begin
If StrLength < 0 then
StrLength := 0;
end;
//------------------------------------------------------------------------------
type
TFloat80Overlay = packed array[0..9] of Byte;
{$IFDEF ENDIAN_BIG}
//==============================================================================
Function SwapEndian(Value: UInt16): UInt16; overload;{$IFDEF CanInline} inline;{$ENDIF}
begin
Result := UInt16(Value shl 8) or UInt16(Value shr 8);
end;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Function SwapEndian(Value: UInt32): UInt32; overload;
type
Int32Rec = packed record