2 * Copyright 2016 Xamarin Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "sk_stream.h"
12 #include "sk_types_priv.h"
14 void sk_stream_asset_destroy(sk_stream_asset_t* cstream)
16 delete AsStreamAsset(cstream);
19 void sk_filestream_destroy(sk_stream_filestream_t* cstream)
21 delete AsFileStream(cstream);
24 void sk_memorystream_destroy(sk_stream_memorystream_t* cstream)
26 delete AsMemoryStream(cstream);
29 sk_stream_filestream_t* sk_filestream_new (const char* path)
31 return ToFileStream(new SkFILEStream(path));
34 sk_stream_memorystream_t* sk_memorystream_new ()
36 return ToMemoryStream(new SkMemoryStream());
38 sk_stream_memorystream_t* sk_memorystream_new_with_length (size_t length)
40 return ToMemoryStream(new SkMemoryStream(length));
42 sk_stream_memorystream_t* sk_memorystream_new_with_data (const void* data, size_t length, bool copyData)
44 return ToMemoryStream(new SkMemoryStream(data, length, copyData));
46 sk_stream_memorystream_t* sk_memorystream_new_with_skdata (sk_data_t* data)
48 return ToMemoryStream(new SkMemoryStream(AsData(data)));
50 void sk_memorystream_set_memory (sk_stream_memorystream_t* cmemorystream, const void* data, size_t length, bool copyData)
52 AsMemoryStream(cmemorystream)->setMemory(data, length, copyData);
55 size_t sk_stream_read (sk_stream_t* cstream, void* buffer, size_t size)
57 return AsStream(cstream)->read(buffer, size);
60 size_t sk_stream_skip (sk_stream_t* cstream, size_t size)
62 return AsStream(cstream)->skip(size);
65 bool sk_stream_is_at_end (sk_stream_t* cstream)
67 return AsStream(cstream)->isAtEnd();
69 int8_t sk_stream_read_s8 (sk_stream_t* cstream)
71 return AsStream(cstream)->readS8();
73 int16_t sk_stream_read_s16 (sk_stream_t* cstream)
75 return AsStream(cstream)->readS16();
77 int32_t sk_stream_read_s32 (sk_stream_t* cstream)
79 return AsStream(cstream)->readS32();
81 uint8_t sk_stream_read_u8 (sk_stream_t* cstream)
83 return AsStream(cstream)->readU8();
85 uint16_t sk_stream_read_u16 (sk_stream_t* cstream)
87 return AsStream(cstream)->readU16();
89 uint32_t sk_stream_read_u32 (sk_stream_t* cstream)
91 return AsStream(cstream)->readU32();
93 bool sk_stream_read_bool (sk_stream_t* cstream)
95 return AsStream(cstream)->readBool();
98 bool sk_stream_rewind (sk_stream_t* cstream)
100 return AsStream(cstream)->rewind();
103 bool sk_stream_has_position (sk_stream_t* cstream)
105 return AsStream(cstream)->hasPosition();
108 size_t sk_stream_get_position (sk_stream_t* cstream)
110 return AsStream(cstream)->getPosition();
113 bool sk_stream_seek (sk_stream_t* cstream, size_t position)
115 return AsStream(cstream)->seek(position);
118 bool sk_stream_move (sk_stream_t* cstream, long offset)
120 return AsStream(cstream)->move(offset);
123 bool sk_stream_has_length (sk_stream_t* cstream)
125 return AsStream(cstream)->hasLength();
128 size_t sk_stream_get_length (sk_stream_t* cstream)
130 return AsStream(cstream)->getLength();
133 void sk_filewstream_destroy(sk_wstream_filestream_t* cstream)
135 delete AsFileWStream(cstream);
138 void sk_dynamicmemorywstream_destroy(sk_wstream_dynamicmemorystream_t* cstream)
140 delete AsDynamicMemoryWStream(cstream);
143 sk_wstream_filestream_t* sk_filewstream_new(const char* path)
145 return ToFileWStream(new SkFILEWStream(path));
148 sk_wstream_dynamicmemorystream_t* sk_dynamicmemorywstream_new()
150 return ToDynamicMemoryWStream(new SkDynamicMemoryWStream());
153 sk_data_t* sk_dynamicmemorywstream_copy_to_data(sk_wstream_dynamicmemorystream_t* cstream)
155 return ToData(AsDynamicMemoryWStream(cstream)->copyToData());
158 sk_stream_asset_t* sk_dynamicmemorywstream_detach_as_stream(sk_wstream_dynamicmemorystream_t* cstream)
160 return ToStreamAsset(AsDynamicMemoryWStream(cstream)->detachAsStream());
163 bool sk_wstream_write(sk_wstream_t* cstream, const void* buffer, size_t size)
165 return AsWStream(cstream)->write(buffer, size);
168 void sk_wstream_newline(sk_wstream_t* cstream)
170 return AsWStream(cstream)->newline();
173 void sk_wstream_flush(sk_wstream_t* cstream)
175 return AsWStream(cstream)->flush();
178 size_t sk_wstream_bytes_written(sk_wstream_t* cstream)
180 return AsWStream(cstream)->bytesWritten();
183 bool sk_wstream_write_8(sk_wstream_t* cstream, uint8_t value)
185 return AsWStream(cstream)->write8(value);
188 bool sk_wstream_write_16(sk_wstream_t* cstream, uint16_t value)
190 return AsWStream(cstream)->write16(value);
193 bool sk_wstream_write_32(sk_wstream_t* cstream, uint32_t value)
195 return AsWStream(cstream)->write32(value);
198 bool sk_wstream_write_text(sk_wstream_t* cstream, const char* value)
200 return AsWStream(cstream)->writeText(value);
203 bool sk_wstream_write_dec_as_text(sk_wstream_t* cstream, int32_t value)
205 return AsWStream(cstream)->writeDecAsText(value);
208 bool sk_wstream_write_bigdec_as_text(sk_wstream_t* cstream, int64_t value, int minDigits)
210 return AsWStream(cstream)->writeBigDecAsText(value, minDigits);
213 bool sk_wstream_write_hex_as_text(sk_wstream_t* cstream, uint32_t value, int minDigits)
215 return AsWStream(cstream)->writeHexAsText(value, minDigits);
218 bool sk_wstream_write_scalar_as_text(sk_wstream_t* cstream, float value)
220 return AsWStream(cstream)->writeScalarAsText(value);
223 bool sk_wstream_write_bool(sk_wstream_t* cstream, bool value)
225 return AsWStream(cstream)->writeBool(value);
228 bool sk_wstream_write_scalar(sk_wstream_t* cstream, float value)
230 return AsWStream(cstream)->writeScalar(value);
233 bool sk_wstream_write_packed_uint(sk_wstream_t* cstream, size_t value)
235 return AsWStream(cstream)->writePackedUInt(value);
238 bool sk_wstream_write_stream(sk_wstream_t* cstream, sk_stream_t* input, size_t length)
240 return AsWStream(cstream)->writeStream(AsStream(input), length);
243 int sk_wstream_get_size_of_packed_uint(size_t value)
245 return SkWStream::SizeOfPackedUInt(value);