Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
base64.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_COMMON_BASE64_H_
6#define FLUTTER_SHELL_COMMON_BASE64_H_
7
8#include <cstddef>
9
10namespace flutter {
11
12struct Base64 {
13 public:
14 enum class Error {
15 kNone,
18 };
19
20 /**
21 Base64 encodes src into dst.
22
23 @param dst a pointer to a buffer large enough to receive the result.
24
25 @return the required length of dst for encoding.
26 */
27 static size_t Encode(const void* src, size_t length, void* dst);
28
29 /**
30 Returns the length of the buffer that needs to be allocated to encode
31 srcDataLength bytes.
32 */
33 static size_t EncodedSize(size_t srcDataLength) {
34 // Take the floor of division by 3 to find the number of groups that need to
35 // be encoded. Each group takes 4 bytes to be represented in base64.
36 return ((srcDataLength + 2) / 3) * 4;
37 }
38
39 /**
40 Base64 decodes src into dst.
41
42 This can be called once with 'dst' nullptr to get the required size,
43 then again with an allocated 'dst' pointer to do the actual decoding.
44
45 @param dst nullptr or a pointer to a buffer large enough to receive the
46 result
47
48 @param dstLength assigned the length dst is required to be. Must not be
49 nullptr.
50 */
51 [[nodiscard]] static Error Decode(const void* src,
52 size_t srcLength,
53 void* dst,
54 size_t* dstLength);
55};
56
57} // namespace flutter
58
59#endif // FLUTTER_SHELL_COMMON_BASE64_H_
size_t length
static size_t Encode(const void *src, size_t length, void *dst)
Definition base64.cc:118
static Error Decode(const void *src, size_t srcLength, void *dst, size_t *dstLength)
Definition base64.cc:28
static size_t EncodedSize(size_t srcDataLength)
Definition base64.h:33