Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
byte_buffer_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_BYTE_BUFFER_STREAMS_H_
6#define FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BYTE_BUFFER_STREAMS_H_
7
8#include <cassert>
9#include <cstdint>
10#include <cstring>
11#include <iostream>
12#include <vector>
13
15
16namespace flutter {
17
18// Implementation of ByteStreamReader base on a byte array.
20 public:
21 // Createa a reader reading from |bytes|, which must have a length of |size|.
22 // |bytes| must remain valid for the lifetime of this object.
23 explicit ByteBufferStreamReader(const uint8_t* bytes, size_t size)
24 : bytes_(bytes), size_(size) {}
25
26 virtual ~ByteBufferStreamReader() = default;
27
28 // |ByteStreamReader|
29 uint8_t ReadByte() override {
30 if (location_ >= size_) {
31 std::cerr << "Invalid read in StandardCodecByteStreamReader" << std::endl;
32 return 0;
33 }
34 return bytes_[location_++];
35 }
36
37 // |ByteStreamReader|
38 void ReadBytes(uint8_t* buffer, size_t length) override {
39 if (location_ + length > size_) {
40 std::cerr << "Invalid read in StandardCodecByteStreamReader" << std::endl;
41 return;
42 }
43 std::memcpy(buffer, &bytes_[location_], length);
44 location_ += length;
45 }
46
47 // |ByteStreamReader|
48 void ReadAlignment(uint8_t alignment) override {
49 uint8_t mod = location_ % alignment;
50 if (mod) {
51 location_ += alignment - mod;
52 }
53 }
54
55 private:
56 // The buffer to read from.
57 const uint8_t* bytes_;
58 // The total size of the buffer.
59 size_t size_;
60 // The current read location.
61 size_t location_ = 0;
62};
63
64// Implementation of ByteStreamWriter based on a byte array.
66 public:
67 // Creates a writer that writes into |buffer|.
68 // |buffer| must remain valid for the lifetime of this object.
69 explicit ByteBufferStreamWriter(std::vector<uint8_t>* buffer)
70 : bytes_(buffer) {
71 assert(buffer);
72 }
73
74 virtual ~ByteBufferStreamWriter() = default;
75
76 // |ByteStreamWriter|
77 void WriteByte(uint8_t byte) { bytes_->push_back(byte); }
78
79 // |ByteStreamWriter|
80 void WriteBytes(const uint8_t* bytes, size_t length) {
81 assert(length > 0);
82 bytes_->insert(bytes_->end(), bytes, bytes + length);
83 }
84
85 // |ByteStreamWriter|
86 void WriteAlignment(uint8_t alignment) {
87 uint8_t mod = bytes_->size() % alignment;
88 if (mod) {
89 for (int i = 0; i < alignment - mod; ++i) {
90 WriteByte(0);
91 }
92 }
93 }
94
95 private:
96 // The buffer to write to.
97 std::vector<uint8_t>* bytes_;
98};
99
100} // namespace flutter
101
102#endif // FLUTTER_SHELL_PLATFORM_COMMON_CLIENT_WRAPPER_BYTE_BUFFER_STREAMS_H_
ByteBufferStreamReader(const uint8_t *bytes, size_t size)
void ReadBytes(uint8_t *buffer, size_t length) override
void ReadAlignment(uint8_t alignment) override
virtual ~ByteBufferStreamReader()=default
void WriteBytes(const uint8_t *bytes, size_t length)
void WriteAlignment(uint8_t alignment)
ByteBufferStreamWriter(std::vector< uint8_t > *buffer)
virtual ~ByteBufferStreamWriter()=default
size_t length
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition switches.h:126
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition switches.h:259