Flutter Linux Embedder
byte_streams.h
Go to the documentation of this file.
1
// Copyright 2013 The Flutter Authors. All rights reserved.
2
// Use of this source code is governed by a BSD-style license that can be
3
// found in the LICENSE file.
4
5
#ifndef FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BYTE_STREAMS_H_
6
#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BYTE_STREAMS_H_
7
8
// Interfaces for interacting with a stream of bytes, for use in codecs.
9
10
namespace
flutter
{
11
12
// An interface for a class that reads from a byte stream.
13
class
ByteStreamReader
{
14
public
:
15
explicit
ByteStreamReader
() =
default
;
16
virtual
~ByteStreamReader
() =
default
;
17
18
// Reads and returns the next byte from the stream.
19
virtual
uint8_t
ReadByte
() = 0;
20
21
// Reads the next |length| bytes from the stream into |buffer|. The caller
22
// is responsible for ensuring that |buffer| is large enough.
23
virtual
void
ReadBytes
(uint8_t*
buffer
,
size_t
length
) = 0;
24
25
// Advances the read cursor to the next multiple of |alignment| relative to
26
// the start of the stream, unless it is already aligned.
27
virtual
void
ReadAlignment
(uint8_t alignment) = 0;
28
29
// Reads and returns the next 32-bit integer from the stream.
30
int32_t
ReadInt32
() {
31
int32_t
value
= 0;
32
ReadBytes
(
reinterpret_cast<
uint8_t*
>
(&
value
), 4);
33
return
value
;
34
}
35
36
// Reads and returns the next 64-bit integer from the stream.
37
int64_t
ReadInt64
() {
38
int64_t
value
= 0;
39
ReadBytes
(
reinterpret_cast<
uint8_t*
>
(&
value
), 8);
40
return
value
;
41
}
42
43
// Reads and returns the next 64-bit floating point number from the stream.
44
double
ReadDouble
() {
45
double
value
= 0;
46
ReadBytes
(
reinterpret_cast<
uint8_t*
>
(&
value
), 8);
47
return
value
;
48
}
49
};
50
51
// An interface for a class that writes to a byte stream.
52
class
ByteStreamWriter
{
53
public
:
54
explicit
ByteStreamWriter
() =
default
;
55
virtual
~ByteStreamWriter
() =
default
;
56
57
// Writes |byte| to the stream.
58
virtual
void
WriteByte
(uint8_t
byte
) = 0;
59
60
// Writes the next |length| bytes from |bytes| to the stream
61
virtual
void
WriteBytes
(
const
uint8_t* bytes,
size_t
length
) = 0;
62
63
// Writes 0s until the next multiple of |alignment| relative to the start
64
// of the stream, unless the write positition is already aligned.
65
virtual
void
WriteAlignment
(uint8_t alignment) = 0;
66
67
// Writes the given 32-bit int to the stream.
68
void
WriteInt32
(int32_t
value
) {
69
WriteBytes
(
reinterpret_cast<
const
uint8_t*
>
(&
value
), 4);
70
}
71
72
// Writes the given 64-bit int to the stream.
73
void
WriteInt64
(int64_t
value
) {
74
WriteBytes
(
reinterpret_cast<
const
uint8_t*
>
(&
value
), 8);
75
}
76
77
// Writes the given 36-bit double to the stream.
78
void
WriteDouble
(
double
value
) {
79
WriteBytes
(
reinterpret_cast<
const
uint8_t*
>
(&
value
), 8);
80
}
81
};
82
83
}
// namespace flutter
84
85
#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_INCLUDE_FLUTTER_BYTE_STREAMS_H_
flutter::ByteStreamReader::ReadByte
virtual uint8_t ReadByte()=0
flutter::ByteStreamReader::ReadDouble
double ReadDouble()
Definition:
byte_streams.h:44
flutter::ByteStreamReader::ReadBytes
virtual void ReadBytes(uint8_t *buffer, size_t length)=0
flutter::ByteStreamReader::~ByteStreamReader
virtual ~ByteStreamReader()=default
flutter::ByteStreamWriter::ByteStreamWriter
ByteStreamWriter()=default
flutter::ByteStreamWriter::WriteInt32
void WriteInt32(int32_t value)
Definition:
byte_streams.h:68
flutter::ByteStreamReader::ReadInt64
int64_t ReadInt64()
Definition:
byte_streams.h:37
flutter::ByteStreamReader
Definition:
byte_streams.h:13
flutter::ByteStreamWriter::~ByteStreamWriter
virtual ~ByteStreamWriter()=default
flutter
Definition:
accessibility_bridge.cc:14
flutter::ByteStreamWriter::WriteDouble
void WriteDouble(double value)
Definition:
byte_streams.h:78
flutter::ByteStreamWriter::WriteBytes
virtual void WriteBytes(const uint8_t *bytes, size_t length)=0
flutter::ByteStreamWriter::WriteAlignment
virtual void WriteAlignment(uint8_t alignment)=0
buffer
static const uint8_t buffer[]
Definition:
fl_pixel_buffer_texture_test.cc:44
flutter::ByteStreamReader::ReadInt32
int32_t ReadInt32()
Definition:
byte_streams.h:30
flutter::ByteStreamWriter::WriteByte
virtual void WriteByte(uint8_t byte)=0
value
uint8_t value
Definition:
fl_standard_message_codec.cc:36
length
size_t length
Definition:
fl_standard_message_codec_test.cc:1113
flutter::ByteStreamWriter
Definition:
byte_streams.h:52
flutter::ByteStreamReader::ByteStreamReader
ByteStreamReader()=default
flutter::ByteStreamReader::ReadAlignment
virtual void ReadAlignment(uint8_t alignment)=0
flutter::ByteStreamWriter::WriteInt64
void WriteInt64(int64_t value)
Definition:
byte_streams.h:73
shell
platform
common
client_wrapper
include
flutter
byte_streams.h
Generated by
1.8.17