blob: 505df403b8d2770381b51ecd5b425e21254b7af6 [file] [log] [blame]
Ethan Nicholas0df1b042017-03-31 13:56:23 -04001/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKSL_OUTPUTSTREAM
9#define SKSL_OUTPUTSTREAM
10
Ethan Nicholasdaed2592021-03-04 14:30:25 -050011#include "include/private/SkSLDefines.h"
12#include "include/private/SkSLString.h"
Ethan Nicholas0df1b042017-03-31 13:56:23 -040013
14namespace SkSL {
15
16class OutputStream {
17public:
18 virtual bool isValid() const {
19 return true;
20 }
21
22 virtual void write8(uint8_t b) = 0;
23
Ethan Nicholasc18bb512020-07-28 14:46:53 -040024 void write16(uint16_t i) {
25 this->write8((uint8_t) i);
26 this->write8((uint8_t) (i >> 8));
27 }
28
29 void write32(uint32_t i) {
30 this->write8((uint8_t) i);
31 this->write8((uint8_t) (i >> 8));
32 this->write8((uint8_t) (i >> 16));
33 this->write8((uint8_t) (i >> 24));
34 }
35
Ethan Nicholas0df1b042017-03-31 13:56:23 -040036 virtual void writeText(const char* s) = 0;
37
38 virtual void write(const void* s, size_t size) = 0;
39
John Stilese1589a12020-10-08 13:56:46 -040040 void writeString(const String& s);
Ethan Nicholas842d31b2019-01-22 10:59:11 -050041
John Stiles1dd2b4b2021-02-02 16:05:57 -050042 void printf(const char format[], ...) SK_PRINTF_LIKE(2, 3);
Ethan Nicholas842d31b2019-01-22 10:59:11 -050043
44 void appendVAList(const char format[], va_list args);
Ethan Nicholas0df1b042017-03-31 13:56:23 -040045
46 virtual ~OutputStream() {}
Ethan Nicholas842d31b2019-01-22 10:59:11 -050047
48private:
49 static const int kBufferSize = 1024;
Ethan Nicholas0df1b042017-03-31 13:56:23 -040050};
51
John Stilesa6841be2020-08-06 14:11:56 -040052} // namespace SkSL
Ethan Nicholas0df1b042017-03-31 13:56:23 -040053
54#endif