| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 library rect_mojom; | 5 library media_metadata_mojom; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:mojo/bindings.dart' as bindings; | 9 import 'package:mojo/bindings.dart' as bindings; |
| 10 import 'package:mojo/core.dart' as core; | 10 import 'package:mojo/core.dart' as core; |
| 11 | 11 |
| 12 | 12 |
| 13 | 13 |
| 14 class Rect extends bindings.Struct { | 14 class MediaMetadata extends bindings.Struct { |
| 15 static const List<bindings.StructDataHeader> kVersions = const [ | 15 static const List<bindings.StructDataHeader> kVersions = const [ |
| 16 const bindings.StructDataHeader(24, 0) | 16 const bindings.StructDataHeader(64, 0) |
| 17 ]; | 17 ]; |
| 18 int x = 0; | 18 int duration = 0; |
| 19 int y = 0; | 19 String title = null; |
| 20 int width = 0; | 20 String artist = null; |
| 21 int height = 0; | 21 String album = null; |
| 22 String publisher = null; |
| 23 String genre = null; |
| 24 String composer = null; |
| 22 | 25 |
| 23 Rect() : super(kVersions.last.size); | 26 MediaMetadata() : super(kVersions.last.size); |
| 24 | 27 |
| 25 static Rect deserialize(bindings.Message message) { | 28 static MediaMetadata deserialize(bindings.Message message) { |
| 26 var decoder = new bindings.Decoder(message); | 29 var decoder = new bindings.Decoder(message); |
| 27 var result = decode(decoder); | 30 var result = decode(decoder); |
| 28 if (decoder.excessHandles != null) { | 31 if (decoder.excessHandles != null) { |
| 29 decoder.excessHandles.forEach((h) => h.close()); | 32 decoder.excessHandles.forEach((h) => h.close()); |
| 30 } | 33 } |
| 31 return result; | 34 return result; |
| 32 } | 35 } |
| 33 | 36 |
| 34 static Rect decode(bindings.Decoder decoder0) { | 37 static MediaMetadata decode(bindings.Decoder decoder0) { |
| 35 if (decoder0 == null) { | 38 if (decoder0 == null) { |
| 36 return null; | 39 return null; |
| 37 } | 40 } |
| 38 Rect result = new Rect(); | 41 MediaMetadata result = new MediaMetadata(); |
| 39 | 42 |
| 40 var mainDataHeader = decoder0.decodeStructDataHeader(); | 43 var mainDataHeader = decoder0.decodeStructDataHeader(); |
| 41 if (mainDataHeader.version <= kVersions.last.version) { | 44 if (mainDataHeader.version <= kVersions.last.version) { |
| 42 // Scan in reverse order to optimize for more recent versions. | 45 // Scan in reverse order to optimize for more recent versions. |
| 43 for (int i = kVersions.length - 1; i >= 0; --i) { | 46 for (int i = kVersions.length - 1; i >= 0; --i) { |
| 44 if (mainDataHeader.version >= kVersions[i].version) { | 47 if (mainDataHeader.version >= kVersions[i].version) { |
| 45 if (mainDataHeader.size == kVersions[i].size) { | 48 if (mainDataHeader.size == kVersions[i].size) { |
| 46 // Found a match. | 49 // Found a match. |
| 47 break; | 50 break; |
| 48 } | 51 } |
| 49 throw new bindings.MojoCodecError( | 52 throw new bindings.MojoCodecError( |
| 50 'Header size doesn\'t correspond to known version size.'); | 53 'Header size doesn\'t correspond to known version size.'); |
| 51 } | 54 } |
| 52 } | 55 } |
| 53 } else if (mainDataHeader.size < kVersions.last.size) { | 56 } else if (mainDataHeader.size < kVersions.last.size) { |
| 54 throw new bindings.MojoCodecError( | 57 throw new bindings.MojoCodecError( |
| 55 'Message newer than the last known version cannot be shorter than ' | 58 'Message newer than the last known version cannot be shorter than ' |
| 56 'required by the last known version.'); | 59 'required by the last known version.'); |
| 57 } | 60 } |
| 58 if (mainDataHeader.version >= 0) { | 61 if (mainDataHeader.version >= 0) { |
| 59 | 62 |
| 60 result.x = decoder0.decodeInt32(8); | 63 result.duration = decoder0.decodeUint64(8); |
| 61 } | 64 } |
| 62 if (mainDataHeader.version >= 0) { | 65 if (mainDataHeader.version >= 0) { |
| 63 | 66 |
| 64 result.y = decoder0.decodeInt32(12); | 67 result.title = decoder0.decodeString(16, true); |
| 65 } | 68 } |
| 66 if (mainDataHeader.version >= 0) { | 69 if (mainDataHeader.version >= 0) { |
| 67 | 70 |
| 68 result.width = decoder0.decodeInt32(16); | 71 result.artist = decoder0.decodeString(24, true); |
| 69 } | 72 } |
| 70 if (mainDataHeader.version >= 0) { | 73 if (mainDataHeader.version >= 0) { |
| 71 | 74 |
| 72 result.height = decoder0.decodeInt32(20); | 75 result.album = decoder0.decodeString(32, true); |
| 76 } |
| 77 if (mainDataHeader.version >= 0) { |
| 78 |
| 79 result.publisher = decoder0.decodeString(40, true); |
| 80 } |
| 81 if (mainDataHeader.version >= 0) { |
| 82 |
| 83 result.genre = decoder0.decodeString(48, true); |
| 84 } |
| 85 if (mainDataHeader.version >= 0) { |
| 86 |
| 87 result.composer = decoder0.decodeString(56, true); |
| 73 } | 88 } |
| 74 return result; | 89 return result; |
| 75 } | 90 } |
| 76 | 91 |
| 77 void encode(bindings.Encoder encoder) { | 92 void encode(bindings.Encoder encoder) { |
| 78 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); | 93 var encoder0 = encoder.getStructEncoderAtOffset(kVersions.last); |
| 79 | 94 |
| 80 encoder0.encodeInt32(x, 8); | 95 encoder0.encodeUint64(duration, 8); |
| 81 | 96 |
| 82 encoder0.encodeInt32(y, 12); | 97 encoder0.encodeString(title, 16, true); |
| 83 | 98 |
| 84 encoder0.encodeInt32(width, 16); | 99 encoder0.encodeString(artist, 24, true); |
| 85 | 100 |
| 86 encoder0.encodeInt32(height, 20); | 101 encoder0.encodeString(album, 32, true); |
| 102 |
| 103 encoder0.encodeString(publisher, 40, true); |
| 104 |
| 105 encoder0.encodeString(genre, 48, true); |
| 106 |
| 107 encoder0.encodeString(composer, 56, true); |
| 87 } | 108 } |
| 88 | 109 |
| 89 String toString() { | 110 String toString() { |
| 90 return "Rect(" | 111 return "MediaMetadata(" |
| 91 "x: $x" ", " | 112 "duration: $duration" ", " |
| 92 "y: $y" ", " | 113 "title: $title" ", " |
| 93 "width: $width" ", " | 114 "artist: $artist" ", " |
| 94 "height: $height" ")"; | 115 "album: $album" ", " |
| 116 "publisher: $publisher" ", " |
| 117 "genre: $genre" ", " |
| 118 "composer: $composer" ")"; |
| 95 } | 119 } |
| 96 | 120 |
| 97 Map toJson() { | 121 Map toJson() { |
| 98 Map map = new Map(); | 122 Map map = new Map(); |
| 99 map["x"] = x; | 123 map["duration"] = duration; |
| 100 map["y"] = y; | 124 map["title"] = title; |
| 101 map["width"] = width; | 125 map["artist"] = artist; |
| 102 map["height"] = height; | 126 map["album"] = album; |
| 127 map["publisher"] = publisher; |
| 128 map["genre"] = genre; |
| 129 map["composer"] = composer; |
| 103 return map; | 130 return map; |
| 104 } | 131 } |
| 105 } | 132 } |
| 106 | 133 |
| 107 | 134 |
| OLD | NEW |