ObjFW  Diff

Differences From Artifact [2f37969ef7]:

To Artifact [a93512463b]:


213
214
215
216
217
218
219


220
221
222
223
224
225
226
@property (readonly, nonatomic) bool hasDataInReadBuffer;

/**
 * @brief Whether the stream can block.
 *
 * By default, a stream can block.
 * On Win32, setting this currently only works for sockets!


 */
@property (nonatomic) bool canBlock;

/**
 * @brief The delegate for asynchronous operations on the stream.
 *
 * @note The delegate is retained for as long as asynchronous operations are







>
>







213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
@property (readonly, nonatomic) bool hasDataInReadBuffer;

/**
 * @brief Whether the stream can block.
 *
 * By default, a stream can block.
 * On Win32, setting this currently only works for sockets!
 *
 * @throw OFSetOptionFailedException The option could not be set
 */
@property (nonatomic) bool canBlock;

/**
 * @brief The delegate for asynchronous operations on the stream.
 *
 * @note The delegate is retained for as long as asynchronous operations are
260
261
262
263
264
265
266


267
268
269
270
271
272
273
 * @warning Only call this when you know that specified amount of data is
 *	    available! Otherwise you will get an exception!
 *
 * @param buffer The buffer into which the data is read
 * @param length The length of the data that should be read.
 *		 The buffer *must* be *at least* this big!
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
 - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length;

#ifdef OF_HAVE_SOCKETS
/**
 * @brief Asynchronously reads *at most* `length` bytes from the stream into a







>
>







262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
 * @warning Only call this when you know that specified amount of data is
 *	    available! Otherwise you will get an exception!
 *
 * @param buffer The buffer into which the data is read
 * @param length The length of the data that should be read.
 *		 The buffer *must* be *at least* this big!
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading the specified amount
 * @throw OFNotOpenException The stream is not open
 */
 - (void)readIntoBuffer: (void *)buffer exactLength: (size_t)length;

#ifdef OF_HAVE_SOCKETS
/**
 * @brief Asynchronously reads *at most* `length` bytes from the stream into a
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
 * @brief Reads a uint8_t from the stream.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint8_t from the stream
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (uint8_t)readInt8;

/**
 * @brief Reads a uint16_t from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint16_t from the stream in native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (uint16_t)readBigEndianInt16;

/**
 * @brief Reads a uint32_t from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint32_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (uint32_t)readBigEndianInt32;

/**
 * @brief Reads a uint64_t from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint64_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (uint64_t)readBigEndianInt64;

/**
 * @brief Reads a float from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A float from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (float)readBigEndianFloat;

/**
 * @brief Reads a double from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A double from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (double)readBigEndianDouble;

/**
 * @brief Reads a uint16_t from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint16_t from the stream in native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (uint16_t)readLittleEndianInt16;

/**
 * @brief Reads a uint32_t from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint32_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (uint32_t)readLittleEndianInt32;

/**
 * @brief Reads a uint64_t from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint64_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (uint64_t)readLittleEndianInt64;

/**
 * @brief Reads a float from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A float from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (float)readLittleEndianFloat;

/**
 * @brief Reads a double from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A double from the stream in the native endianess
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (double)readLittleEndianDouble;

/**
 * @brief Reads the specified number of items with an item size of 1 from the
 *	  stream and returns them as OFData.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @param count The number of items to read
 * @return OFData with count items.
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (OFData *)readDataWithCount: (size_t)count;

/**
 * @brief Reads the specified number of items with the specified item size from
 *	  the stream and returns them as OFData.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @param itemSize The size of each item
 * @param count The number of items to read
 * @return OFData with count items.
 * @throw OFReadFailedException Reading failed


 * @throw OFNotOpenException The stream is not open
 */
- (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count;

/**
 * @brief Returns OFData with all the remaining data of the stream.
 *







>
>












>
>












>
>












>
>












>
>












>
>












>
>












>
>












>
>












>
>












>
>














>
>















>
>







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
 * @brief Reads a uint8_t from the stream.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint8_t from the stream
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (uint8_t)readInt8;

/**
 * @brief Reads a uint16_t from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint16_t from the stream in native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (uint16_t)readBigEndianInt16;

/**
 * @brief Reads a uint32_t from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint32_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (uint32_t)readBigEndianInt32;

/**
 * @brief Reads a uint64_t from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint64_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (uint64_t)readBigEndianInt64;

/**
 * @brief Reads a float from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A float from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (float)readBigEndianFloat;

/**
 * @brief Reads a double from the stream which is encoded in big endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A double from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (double)readBigEndianDouble;

/**
 * @brief Reads a uint16_t from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint16_t from the stream in native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (uint16_t)readLittleEndianInt16;

/**
 * @brief Reads a uint32_t from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint32_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (uint32_t)readLittleEndianInt32;

/**
 * @brief Reads a uint64_t from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A uint64_t from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (uint64_t)readLittleEndianInt64;

/**
 * @brief Reads a float from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A float from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (float)readLittleEndianFloat;

/**
 * @brief Reads a double from the stream which is encoded in little endian.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @return A double from the stream in the native endianess
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (double)readLittleEndianDouble;

/**
 * @brief Reads the specified number of items with an item size of 1 from the
 *	  stream and returns them as OFData.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @param count The number of items to read
 * @return OFData with count items.
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (OFData *)readDataWithCount: (size_t)count;

/**
 * @brief Reads the specified number of items with the specified item size from
 *	  the stream and returns them as OFData.
 *
 * @warning Only call this when you know that enough data is available!
 *	    Otherwise you will get an exception!
 *
 * @param itemSize The size of each item
 * @param count The number of items to read
 * @return OFData with count items.
 * @throw OFReadFailedException Reading failed
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (OFData *)readDataWithItemSize: (size_t)itemSize count: (size_t)count;

/**
 * @brief Returns OFData with all the remaining data of the stream.
 *
653
654
655
656
657
658
659


660
661
662
663
664
665
666
 *	    Otherwise you will get an exception!
 *
 * @param length The length (in bytes) of the string to read from the stream
 * @return A string with the specified length
 * @throw OFReadFailedException Reading failed
 * @throw OFInvalidEncodingException The string read from the stream has
 *				     invalid encoding


 * @throw OFNotOpenException The stream is not open
 */
- (OFString *)readStringWithLength: (size_t)length;

/**
 * @brief Reads a string with the specified encoding and length from the stream.
 *







>
>







683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
 *	    Otherwise you will get an exception!
 *
 * @param length The length (in bytes) of the string to read from the stream
 * @return A string with the specified length
 * @throw OFReadFailedException Reading failed
 * @throw OFInvalidEncodingException The string read from the stream has
 *				     invalid encoding
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (OFString *)readStringWithLength: (size_t)length;

/**
 * @brief Reads a string with the specified encoding and length from the stream.
 *
674
675
676
677
678
679
680


681
682
683
684
685
686
687
 *
 * @param encoding The encoding of the string to read from the stream
 * @param length The length (in bytes) of the string to read from the stream
 * @return A string with the specified length
 * @throw OFReadFailedException Reading failed
 * @throw OFInvalidEncodingException The string read from the stream has
 *				     invalid encoding


 * @throw OFNotOpenException The stream is not open
 */
- (OFString *)readStringWithLength: (size_t)length
			  encoding: (OFStringEncoding)encoding;

/**
 * @brief Reads until a newline, `\0` or end of stream occurs.







>
>







706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
 *
 * @param encoding The encoding of the string to read from the stream
 * @param length The length (in bytes) of the string to read from the stream
 * @return A string with the specified length
 * @throw OFReadFailedException Reading failed
 * @throw OFInvalidEncodingException The string read from the stream has
 *				     invalid encoding
 * @throw OFTruncatedDataException The end of the stream was reached before
 *				   reading enough bytes
 * @throw OFNotOpenException The stream is not open
 */
- (OFString *)readStringWithLength: (size_t)length
			  encoding: (OFStringEncoding)encoding;

/**
 * @brief Reads until a newline, `\0` or end of stream occurs.