Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(603)

Unified Diff: runtime/vm/json_stream.cc

Issue 1157003003: Add TypedData instance kinds. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/json_stream.cc
diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc
index 71d30a9b0168b73de9912b7c24e81e3a65d27c6c..729330f9998ff673d518beb77347eae402af9ed7 100644
--- a/runtime/vm/json_stream.cc
+++ b/runtime/vm/json_stream.cc
@@ -277,6 +277,42 @@ void JSONStream::PrintValue(double d) {
}
+static const char base64_digits[65] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char base64_pad = '=';
+
+
+void JSONStream::PrintValueBase64(const uint8_t* bytes, intptr_t length) {
+ PrintCommaIfNeeded();
+ buffer_.AddChar('"');
+
+ intptr_t odd_bits = length % 3;
+ intptr_t even_bits = length - odd_bits;
+ for (intptr_t i = 0; i < even_bits; i += 3) {
+ intptr_t triplet = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2];
+ buffer_.AddChar(base64_digits[triplet >> 18]);
+ buffer_.AddChar(base64_digits[(triplet >> 12) & 63]);
+ buffer_.AddChar(base64_digits[(triplet >> 6) & 63]);
+ buffer_.AddChar(base64_digits[triplet & 63]);
+ }
+ if (odd_bits == 1) {
+ intptr_t triplet = bytes[even_bits] << 16;
+ buffer_.AddChar(base64_digits[triplet >> 18]);
+ buffer_.AddChar(base64_digits[(triplet >> 12) & 63]);
+ buffer_.AddChar(base64_pad);
+ buffer_.AddChar(base64_pad);
+ } else if (odd_bits == 2) {
+ intptr_t triplet = (bytes[even_bits] << 16) | (bytes[even_bits + 1] << 8);
+ buffer_.AddChar(base64_digits[triplet >> 18]);
+ buffer_.AddChar(base64_digits[(triplet >> 12) & 63]);
+ buffer_.AddChar(base64_digits[(triplet >> 6) & 63]);
+ buffer_.AddChar(base64_pad);
+ }
+
+ buffer_.AddChar('"');
+}
+
+
void JSONStream::PrintValue(const char* s) {
PrintCommaIfNeeded();
buffer_.AddChar('"');
@@ -393,6 +429,14 @@ void JSONStream::PrintProperty(const char* name, const char* s) {
}
+void JSONStream::PrintPropertyBase64(const char* name,
+ const uint8_t* b,
+ intptr_t len) {
+ PrintPropertyName(name);
+ PrintValueBase64(b, len);
+}
+
+
bool JSONStream::PrintPropertyStr(const char* name,
const String& s,
intptr_t limit) {
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698