Flutter Engine
The Flutter Engine
json_writer.h
Go to the documentation of this file.
1// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#ifndef RUNTIME_VM_JSON_WRITER_H_
6#define RUNTIME_VM_JSON_WRITER_H_
7
10
11namespace dart {
12
13class String;
14
16 public:
17 explicit JSONWriter(intptr_t buf_size = 256);
18
19 TextBuffer* buffer() { return &buffer_; }
20 const char* ToCString() { return buffer_.buffer(); }
21
22 void Steal(char** buffer, intptr_t* buffer_length);
23
24 void PrintCommaIfNeeded();
25
26 // Append |buffer| to the stream.
27 void AppendBytes(const uint8_t* buffer, intptr_t buffer_length);
28
29 // Append the Base64 encoding of |bytes| to the stream.
30 //
31 // Beware that padding characters are added when |length| is not a multiple of
32 // three. Padding is only valid at the end of Base64 strings, so you must be
33 // careful when trying to populate a single Base64 string with multiple calls
34 // to this method. |JSONBase64String| should be used for that use-case,
35 // because it handles padding management.
36 void AppendBytesInBase64(const uint8_t* bytes, intptr_t length);
37
38 // Append |serialized_object| to the stream.
39 void AppendSerializedObject(const char* serialized_object);
40
41 // Append |serialized_object| to the stream with |property_name|.
42 void AppendSerializedObject(const char* property_name,
43 const char* serialized_object);
44
45 void OpenObject(const char* property_name = nullptr);
46 void CloseObject();
47 void UncloseObject();
48
49 void OpenArray(const char* property_name = nullptr);
50 void CloseArray();
51
52 void Clear();
53
54 void PrintValueNull();
55 void PrintValueBool(bool b);
56 void PrintValue(intptr_t i);
57 void PrintValue64(int64_t i);
58 void PrintValue(double d);
59 void PrintValueBase64(const uint8_t* bytes, intptr_t length);
60 void PrintValue(const char* s);
61 void PrintValue(const char* s, intptr_t len);
62 void PrintValueNoEscape(const char* s);
63 void PrintfValue(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
64 void VPrintfValue(const char* format, va_list args);
65 bool PrintValueStr(const String& s, intptr_t offset, intptr_t count);
66
67 void PrintPropertyBool(const char* name, bool b);
68 void PrintProperty(const char* name, intptr_t i);
69 void PrintProperty64(const char* name, int64_t i);
70 void PrintProperty(const char* name, double d);
71 void PrintPropertyBase64(const char* name,
72 const uint8_t* bytes,
73 intptr_t length);
74 void PrintProperty(const char* name, const char* s);
75 bool PrintPropertyStr(const char* name,
76 const String& s,
77 intptr_t offset = 0,
78 intptr_t count = -1);
79 void PrintPropertyNoEscape(const char* name, const char* s);
80 void PrintfProperty(const char* name, const char* format, ...)
81 PRINTF_ATTRIBUTE(3, 4);
82 void VPrintfProperty(const char* name, const char* format, va_list args);
83
84 void PrintPropertyName(const char* name);
85
86 void PrintNewline();
87
88 void AddEscapedUTF8String(const char* s);
89 void AddEscapedUTF8String(const char* s, intptr_t len);
90
91 private:
92 bool NeedComma();
93 bool AddDartString(const String& s, intptr_t offset, intptr_t count);
94
95 // Debug only fatal assertion.
96 static void EnsureIntegerIsRepresentableInJavaScript(int64_t i);
97
98 intptr_t open_objects_;
99 TextBuffer buffer_;
100};
101
102} // namespace dart
103
104#endif // RUNTIME_VM_JSON_WRITER_H_
int count
Definition: FontMgrTest.cpp:50
char * buffer() const
Definition: text_buffer.h:35
void AppendBytesInBase64(const uint8_t *bytes, intptr_t length)
Definition: json_writer.cc:46
bool PrintPropertyStr(const char *name, const String &s, intptr_t offset=0, intptr_t count=-1)
Definition: json_writer.cc:256
JSONWriter(intptr_t buf_size=256)
Definition: json_writer.cc:35
void PrintPropertyBool(const char *name, bool b)
Definition: json_writer.cc:224
void PrintProperty64(const char *name, int64_t i)
Definition: json_writer.cc:234
void UncloseObject()
Definition: json_writer.cc:98
void PrintPropertyBase64(const char *name, const uint8_t *bytes, intptr_t length)
Definition: json_writer.cc:249
void PrintCommaIfNeeded()
Definition: json_writer.cc:320
void Steal(char **buffer, intptr_t *buffer_length)
Definition: json_writer.cc:300
void PrintValue(intptr_t i)
Definition: json_writer.cc:137
void PrintValueBase64(const uint8_t *bytes, intptr_t length)
Definition: json_writer.cc:159
void PrintValueBool(bool b)
Definition: json_writer.cc:132
const char * ToCString()
Definition: json_writer.h:20
void PrintProperty(const char *name, intptr_t i)
Definition: json_writer.cc:229
void PrintPropertyName(const char *name)
Definition: json_writer.cc:307
void void VPrintfValue(const char *format, va_list args)
Definition: json_writer.cc:202
void PrintfValue(const char *format,...) PRINTF_ATTRIBUTE(2
Definition: json_writer.cc:195
void OpenArray(const char *property_name=nullptr)
Definition: json_writer.cc:112
void AppendBytes(const uint8_t *buffer, intptr_t buffer_length)
Definition: json_writer.cc:38
TextBuffer * buffer()
Definition: json_writer.h:19
bool PrintValueStr(const String &s, intptr_t offset, intptr_t count)
Definition: json_writer.cc:180
void AppendSerializedObject(const char *serialized_object)
Definition: json_writer.cc:72
void void VPrintfProperty(const char *name, const char *format, va_list args)
Definition: json_writer.cc:276
void PrintfProperty(const char *name, const char *format,...) PRINTF_ATTRIBUTE(3
Definition: json_writer.cc:269
void AddEscapedUTF8String(const char *s)
Definition: json_writer.cc:348
void PrintValueNoEscape(const char *s)
Definition: json_writer.cc:190
void OpenObject(const char *property_name=nullptr)
Definition: json_writer.cc:89
void PrintValue64(int64_t i)
Definition: json_writer.cc:143
void PrintPropertyNoEscape(const char *name, const char *s)
Definition: json_writer.cc:264
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
static bool b
struct MyStruct s
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
size_t length
Definition: dart_vm.cc:33
const char *const name
#define PRINTF_ATTRIBUTE(string_index, first_to_check)
Definition: globals.h:697
SeparatedVector2 offset