mirror of
https://github.com/borgesdan/xn65
synced 2024-12-29 21:54:47 +01:00
Implementa NullStream
This commit is contained in:
parent
5e4bab9b06
commit
3bc10d36d2
@ -11,9 +11,12 @@ namespace csharp {
|
||||
* The BinaryReader class uses byte encodings, by default UTF8.
|
||||
* This was not implemented, but we tried to follow the same standard.
|
||||
* Also the reading of primitives was modified.
|
||||
*
|
||||
*/
|
||||
|
||||
//TODO: ReadString and ReadChar as it only reads ASCII characters
|
||||
//https://learn.microsoft.com/pt-br/dotnet/csharp/language-reference/builtin-types/char
|
||||
//char - 16 bits
|
||||
|
||||
//The BinaryReader class uses byte encodings, by default UTF8
|
||||
class BinaryReader {
|
||||
@ -136,6 +139,27 @@ namespace csharp {
|
||||
|
||||
std::vector<uint8_t> _auxBuffer;
|
||||
};
|
||||
|
||||
class BinaryWriter {
|
||||
public:
|
||||
BinaryWriter(std::shared_ptr<Stream> const& output) {
|
||||
OutStream = Stream::Null;
|
||||
}
|
||||
|
||||
BinaryWriter(std::shared_ptr<Stream> const& output, bool leaveOpen);
|
||||
|
||||
protected:
|
||||
BinaryWriter();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<Stream> OutStream;
|
||||
|
||||
private:
|
||||
static constexpr int MaxArrayPoolRentalSize = 64 * 1024;
|
||||
static std::shared_ptr<BinaryWriter> Null;
|
||||
bool _leaveOpen{ false };
|
||||
bool _useFastUtf8{ true };
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
@ -76,6 +76,9 @@ namespace csharp {
|
||||
virtual void Write(uint8_t const* buffer, int32_t bufferLength);
|
||||
virtual void WriteByte(uint8_t value) = 0;
|
||||
|
||||
public:
|
||||
static const std::shared_ptr<Stream> Null;
|
||||
|
||||
protected:
|
||||
void ValidateBuffer(uint8_t const* buffer, int32_t bufferLength);
|
||||
|
||||
@ -86,6 +89,37 @@ namespace csharp {
|
||||
int32_t GetCopybufferLength() const;
|
||||
};
|
||||
|
||||
class NullStream : Stream {
|
||||
public:
|
||||
NullStream(){}
|
||||
|
||||
constexpr bool CanRead() const override { return true; }
|
||||
constexpr bool CanWrite() const override { return true; }
|
||||
constexpr bool CanSeek() const override { return true; }
|
||||
constexpr int64_t Length() const override { return 0; };
|
||||
constexpr int64_t Position() const override { return 0; };
|
||||
constexpr void Position(int64_t value) override { };
|
||||
constexpr void CopyTo(Stream& destination, int32_t bufferLength) override {};
|
||||
constexpr void SetLength(int64_t value) override {};
|
||||
|
||||
constexpr void Flush() override {};
|
||||
constexpr int64_t Seek(int64_t offset, SeekOrigin origin) override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t Read(uint8_t* buffer, int32_t bufferLength, int32_t offset, int32_t count) override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
constexpr int32_t ReadByte() override { return -1; }
|
||||
|
||||
constexpr void Write(uint8_t const* buffer, int32_t bufferLength, int32_t offset, int32_t count) override
|
||||
{}
|
||||
|
||||
constexpr void WriteByte(uint8_t value) override
|
||||
{}
|
||||
};
|
||||
|
||||
class MemoryStream : public Stream {
|
||||
public:
|
||||
MemoryStream() : MemoryStream(0) {}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user