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

Side by Side 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, 5 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « lib/protobuf/runtime/ByteArrayProvider.dart ('k') | lib/protobuf/runtime/ChangeListener.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011, 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 class ByteListUtils {
6 static String toRawBytesAsString(List<int> bytes) {
7 List<String> _bytes = [];
8 for(int b in bytes) {
9 _bytes.add(toHex(b));
10 }
11 return Strings.join(_bytes, " ");
12 }
13
14 static final String HEX_CHARS = "0123456789abcdef";
15 static String toHex(int dec, [int minLength = 2]) {
16 List<int> hexCodes = [];
17 int len = 0;
18 while (len < minLength || dec > 0) {
19 hexCodes.add(HEX_CHARS.charCodeAt(dec & 0xf));
20 dec >>= 4;
21 len ++;
22 }
23 List<int> strSrc = [];
24 for (int i = hexCodes.length - 1; i >= 0; i--) {
25 strSrc.add(hexCodes[i]);
26 }
27 return new String.fromCharCodes(strSrc);
28 }
29
30 static String toBits(int dec, [int minLength = 8]) {
31 Queue<String> q = new Queue();
32 int len = 0;
33 while (len < minLength || dec > 0) {
34 if(len > 0 && len % 4 == 0) q.addFirst(" ");
35 q.addFirst("${dec & 0x1}");
36 dec >>= 1;
37 len ++;
38 }
39 StringBuffer sb = new StringBuffer();
40 for(String i in q) {
41 sb.add(i);
42 }
43 return sb.toString();
44 }
45 }
OLDNEW
« 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