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

Unified Diff: lib/protobuf/runtime/ByteListUtils.dart

Issue 10595002: Protocol Buffer runtime library and 'protoc' plugin (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Work around http://code.google.com/p/dart/issues/detail?id=3806 Created 8 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 | « lib/protobuf/runtime/ByteArrayProvider.dart ('k') | lib/protobuf/runtime/ChangeListener.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/protobuf/runtime/ByteListUtils.dart
diff --git a/lib/protobuf/runtime/ByteListUtils.dart b/lib/protobuf/runtime/ByteListUtils.dart
new file mode 100755
index 0000000000000000000000000000000000000000..260d39666f5d850e731f0c342f3feecf875f7d9b
--- /dev/null
+++ b/lib/protobuf/runtime/ByteListUtils.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+class ByteListUtils {
+ static String toRawBytesAsString(List<int> bytes) {
+ List<String> _bytes = [];
+ for(int b in bytes) {
+ _bytes.add(toHex(b));
+ }
+ return Strings.join(_bytes, " ");
+ }
+
+ static final String HEX_CHARS = "0123456789abcdef";
+ static String toHex(int dec, [int minLength = 2]) {
+ List<int> hexCodes = [];
+ int len = 0;
+ while (len < minLength || dec > 0) {
+ hexCodes.add(HEX_CHARS.charCodeAt(dec & 0xf));
+ dec >>= 4;
+ len ++;
+ }
+ List<int> strSrc = [];
+ for (int i = hexCodes.length - 1; i >= 0; i--) {
+ strSrc.add(hexCodes[i]);
+ }
+ return new String.fromCharCodes(strSrc);
+ }
+
+ static String toBits(int dec, [int minLength = 8]) {
+ Queue<String> q = new Queue();
+ int len = 0;
+ while (len < minLength || dec > 0) {
+ if(len > 0 && len % 4 == 0) q.addFirst(" ");
+ q.addFirst("${dec & 0x1}");
+ dec >>= 1;
+ len ++;
+ }
+ StringBuffer sb = new StringBuffer();
+ for(String i in q) {
+ sb.add(i);
+ }
+ return sb.toString();
+ }
+}
« no previous file with comments | « lib/protobuf/runtime/ByteArrayProvider.dart ('k') | lib/protobuf/runtime/ChangeListener.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698