diff options
author | Mark Erickson <merickson@apache.org> | 2016-06-07 16:24:23 -0500 |
---|---|---|
committer | Mark Erickson <merickson@apache.org> | 2016-06-07 16:24:23 -0500 |
commit | e1abc8b2f3aed139f43ee0f9d1eca95b7da4f312 (patch) | |
tree | 80952fd91c7d150e7c9de11ce81616d62688e632 /lib/dart | |
parent | 7407e2e2f3547037655d5d231cbc283e2e4a8923 (diff) | |
download | thrift-e1abc8b2f3aed139f43ee0f9d1eca95b7da4f312.tar.gz |
THRIFT-3849 Port Go serializer and deserializer to Dart
Client: Dart
Patch: Keaton Carter <keaton.carter@workiva.com>
This closes #1023
Diffstat (limited to 'lib/dart')
-rw-r--r-- | lib/dart/lib/src/browser/t_web_socket.dart | 6 | ||||
-rw-r--r-- | lib/dart/lib/src/console/t_web_socket.dart | 6 | ||||
-rw-r--r-- | lib/dart/lib/src/protocol/t_json_protocol.dart | 4 | ||||
-rw-r--r-- | lib/dart/lib/src/serializer/t_deserializer.dart | 50 | ||||
-rw-r--r-- | lib/dart/lib/src/serializer/t_serializer.dart | 48 | ||||
-rw-r--r-- | lib/dart/lib/src/transport/t_buffered_transport.dart | 4 | ||||
-rw-r--r-- | lib/dart/lib/src/transport/t_framed_transport.dart | 2 | ||||
-rw-r--r-- | lib/dart/lib/src/transport/t_http_transport.dart | 4 | ||||
-rw-r--r-- | lib/dart/lib/src/transport/t_socket_transport.dart | 6 | ||||
-rw-r--r-- | lib/dart/lib/thrift.dart | 6 | ||||
-rw-r--r-- | lib/dart/pubspec.yaml | 3 | ||||
-rw-r--r-- | lib/dart/test/serializer/serializer_test.dart | 119 | ||||
-rw-r--r-- | lib/dart/test/serializer/serializer_test_data.dart | 342 | ||||
-rw-r--r-- | lib/dart/test/transport/t_http_transport_test.dart | 11 | ||||
-rw-r--r-- | lib/dart/test/transport/t_socket_transport_test.dart | 13 |
15 files changed, 591 insertions, 33 deletions
diff --git a/lib/dart/lib/src/browser/t_web_socket.dart b/lib/dart/lib/src/browser/t_web_socket.dart index dfcee8391..17693b300 100644 --- a/lib/dart/lib/src/browser/t_web_socket.dart +++ b/lib/dart/lib/src/browser/t_web_socket.dart @@ -18,13 +18,13 @@ library thrift.src.browser; import 'dart:async'; +import 'dart:convert' show BASE64; import 'dart:html' show CloseEvent; import 'dart:html' show Event; import 'dart:html' show MessageEvent; import 'dart:html' show WebSocket; import 'dart:typed_data' show Uint8List; -import 'package:crypto/crypto.dart' show CryptoUtils; import 'package:thrift/thrift.dart'; /// A [TSocket] backed by a [WebSocket] from dart:html @@ -90,7 +90,7 @@ class TWebSocket implements TSocket { void _sendRequests() { while (isOpen && _requests.isNotEmpty) { Uint8List data = _requests.removeAt(0); - _socket.sendString(CryptoUtils.bytesToBase64(data)); + _socket.sendString(BASE64.encode(data)); } } @@ -114,7 +114,7 @@ class TWebSocket implements TSocket { void _onMessage(MessageEvent message) { try { Uint8List data = - new Uint8List.fromList(CryptoUtils.base64StringToBytes(message.data)); + new Uint8List.fromList(BASE64.decode(message.data)); _onMessageController.add(data); } on FormatException catch (_) { var error = new TProtocolError(TProtocolErrorType.INVALID_DATA, diff --git a/lib/dart/lib/src/console/t_web_socket.dart b/lib/dart/lib/src/console/t_web_socket.dart index 5a549be21..4ed728444 100644 --- a/lib/dart/lib/src/console/t_web_socket.dart +++ b/lib/dart/lib/src/console/t_web_socket.dart @@ -18,10 +18,10 @@ library thrift.src.console.t_web_socket; import 'dart:async'; +import 'dart:convert' show BASE64; import 'dart:io'; import 'dart:typed_data' show Uint8List; -import 'package:crypto/crypto.dart' show CryptoUtils; import 'package:thrift/thrift.dart'; /// A [TSocket] backed by a [WebSocket] from dart:io @@ -67,13 +67,13 @@ class TWebSocket implements TSocket { } void send(Uint8List data) { - _socket.add(CryptoUtils.bytesToBase64(data)); + _socket.add(BASE64.encode(data)); } void _onMessage(String message) { try { Uint8List data = - new Uint8List.fromList(CryptoUtils.base64StringToBytes(message)); + new Uint8List.fromList(BASE64.decode(message)); _onMessageController.add(data); } on FormatException catch (_) { var error = new TProtocolError(TProtocolErrorType.INVALID_DATA, diff --git a/lib/dart/lib/src/protocol/t_json_protocol.dart b/lib/dart/lib/src/protocol/t_json_protocol.dart index ca91c8bcf..7fbb7c443 100644 --- a/lib/dart/lib/src/protocol/t_json_protocol.dart +++ b/lib/dart/lib/src/protocol/t_json_protocol.dart @@ -155,7 +155,7 @@ class TJsonProtocol extends TProtocol { _context.write(); transport.writeAll(_Constants.QUOTE_BYTES); - String base64 = CryptoUtils.bytesToBase64(bytes); + String base64 = BASE64.encode(bytes); transport.writeAll(utf8Codec.encode(base64)); transport.writeAll(_Constants.QUOTE_BYTES); @@ -423,7 +423,7 @@ class TJsonProtocol extends TProtocol { Uint8List base64Bytes = _readJsonString(); String base64 = utf8Codec.decode(base64Bytes); - return new Uint8List.fromList(CryptoUtils.base64StringToBytes(base64)); + return new Uint8List.fromList(BASE64.decode(base64)); } void _readJsonObjectStart() { diff --git a/lib/dart/lib/src/serializer/t_deserializer.dart b/lib/dart/lib/src/serializer/t_deserializer.dart new file mode 100644 index 000000000..ed1d139aa --- /dev/null +++ b/lib/dart/lib/src/serializer/t_deserializer.dart @@ -0,0 +1,50 @@ +/// Licensed to the Apache Software Foundation (ASF) under one +/// or more contributor license agreements. See the NOTICE file +/// distributed with this work for additional information +/// regarding copyright ownership. The ASF licenses this file +/// to you under the Apache License, Version 2.0 (the +/// "License"); you may not use this file except in compliance +/// with the License. You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, +/// software distributed under the License is distributed on an +/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +/// KIND, either express or implied. See the License for the +/// specific language governing permissions and limitations +/// under the License. + +part of thrift; + +class TDeserializer { + final message = new TMessage('Deserializer', TMessageType.ONEWAY, 1); + TBufferedTransport transport; + TProtocol protocol; + + TDeserializer({TProtocolFactory protocolFactory}) { + this.transport = new TBufferedTransport(); + + if (protocolFactory == null) { + protocolFactory = new TBinaryProtocolFactory(); + } + + this.protocol = protocolFactory.getProtocol(this.transport); + } + + void read(TBase base, Uint8List data) { + transport.writeAll(data); + + transport.flush(); + + base.read(protocol); + } + + void readString(TBase base, String data) { + transport.writeAll(BASE64.decode(data)); + + transport.flush(); + + base.read(protocol); + } +} diff --git a/lib/dart/lib/src/serializer/t_serializer.dart b/lib/dart/lib/src/serializer/t_serializer.dart new file mode 100644 index 000000000..20ddb6d97 --- /dev/null +++ b/lib/dart/lib/src/serializer/t_serializer.dart @@ -0,0 +1,48 @@ +/// Licensed to the Apache Software Foundation (ASF) under one +/// or more contributor license agreements. See the NOTICE file +/// distributed with this work for additional information +/// regarding copyright ownership. The ASF licenses this file +/// to you under the Apache License, Version 2.0 (the +/// "License"); you may not use this file except in compliance +/// with the License. You may obtain a copy of the License at +/// +/// http://www.apache.org/licenses/LICENSE-2.0 +/// +/// Unless required by applicable law or agreed to in writing, +/// software distributed under the License is distributed on an +/// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +/// KIND, either express or implied. See the License for the +/// specific language governing permissions and limitations +/// under the License. + +part of thrift; + +class TSerializer { + final message = new TMessage('Serializer', TMessageType.ONEWAY, 1); + TBufferedTransport transport; + TProtocol protocol; + + TSerializer({TProtocolFactory protocolFactory}) { + this.transport = new TBufferedTransport(); + + if (protocolFactory == null) { + protocolFactory = new TBinaryProtocolFactory(); + } + + this.protocol = protocolFactory.getProtocol(this.transport); + } + + Uint8List write(TBase base) { + base.write(protocol); + + return transport.consumeWriteBuffer(); + } + + String writeString(TBase base) { + base.write(protocol); + + Uint8List bytes = transport.consumeWriteBuffer(); + + return BASE64.encode(bytes); + } +} diff --git a/lib/dart/lib/src/transport/t_buffered_transport.dart b/lib/dart/lib/src/transport/t_buffered_transport.dart index 1d44c621d..b73a30c0e 100644 --- a/lib/dart/lib/src/transport/t_buffered_transport.dart +++ b/lib/dart/lib/src/transport/t_buffered_transport.dart @@ -22,7 +22,7 @@ class TBufferedTransport extends TTransport { final List<int> _writeBuffer = []; Iterator<int> _readIterator; - Uint8List _consumeWriteBuffer() { + Uint8List consumeWriteBuffer() { Uint8List buffer = new Uint8List.fromList(_writeBuffer); _writeBuffer.clear(); return buffer; @@ -91,7 +91,7 @@ class TBufferedTransport extends TTransport { } Future flush() { - _readIterator = _consumeWriteBuffer().iterator; + _readIterator = consumeWriteBuffer().iterator; return new Future.value(); } diff --git a/lib/dart/lib/src/transport/t_framed_transport.dart b/lib/dart/lib/src/transport/t_framed_transport.dart index baf8f3212..80ccf2c55 100644 --- a/lib/dart/lib/src/transport/t_framed_transport.dart +++ b/lib/dart/lib/src/transport/t_framed_transport.dart @@ -71,7 +71,7 @@ class TFramedTransport extends TBufferedTransport { } Future flush() { - Uint8List buffer = _consumeWriteBuffer(); + Uint8List buffer = consumeWriteBuffer(); int length = buffer.length; headerBytes.buffer.asByteData().setUint32(0, length); diff --git a/lib/dart/lib/src/transport/t_http_transport.dart b/lib/dart/lib/src/transport/t_http_transport.dart index 0e99a1dfe..bd821f444 100644 --- a/lib/dart/lib/src/transport/t_http_transport.dart +++ b/lib/dart/lib/src/transport/t_http_transport.dart @@ -44,7 +44,7 @@ class THttpClientTransport extends TBufferedTransport { } Future flush() { - var requestBody = CryptoUtils.bytesToBase64(_consumeWriteBuffer()); + var requestBody = BASE64.encode(consumeWriteBuffer()); // Use a sync completer to ensure that the buffer can be read immediately // after the read buffer is set, and avoid a race condition where another @@ -57,7 +57,7 @@ class THttpClientTransport extends TBufferedTransport { Uint8List data; try { data = new Uint8List.fromList( - CryptoUtils.base64StringToBytes(response.body)); + BASE64.decode(response.body)); } on FormatException catch (_) { throw new TProtocolError(TProtocolErrorType.INVALID_DATA, "Expected a Base 64 encoded string."); diff --git a/lib/dart/lib/src/transport/t_socket_transport.dart b/lib/dart/lib/src/transport/t_socket_transport.dart index d23e6ab68..824260d1e 100644 --- a/lib/dart/lib/src/transport/t_socket_transport.dart +++ b/lib/dart/lib/src/transport/t_socket_transport.dart @@ -71,7 +71,7 @@ class TClientSocketTransport extends TSocketTransport { TClientSocketTransport(TSocket socket) : super(socket); Future flush() { - Uint8List bytes = _consumeWriteBuffer(); + Uint8List bytes = consumeWriteBuffer(); // Use a sync completer to ensure that the buffer can be read immediately // after the read buffer is set, and avoid a race condition where another @@ -116,7 +116,7 @@ class TAsyncClientSocketTransport extends TSocketTransport { super(socket); Future flush() { - Uint8List bytes = _consumeWriteBuffer(); + Uint8List bytes = consumeWriteBuffer(); TMessage message = messageReader.readMessage(bytes); int seqid = message.seqid; @@ -163,7 +163,7 @@ class TServerSocketTransport extends TSocketTransport { super(socket); Future flush() async { - Uint8List message = _consumeWriteBuffer(); + Uint8List message = consumeWriteBuffer(); socket.send(message); } diff --git a/lib/dart/lib/thrift.dart b/lib/dart/lib/thrift.dart index ca23fb330..3d9bb016c 100644 --- a/lib/dart/lib/thrift.dart +++ b/lib/dart/lib/thrift.dart @@ -19,12 +19,11 @@ library thrift; import 'dart:async'; import 'dart:collection'; -import 'dart:convert' show Utf8Codec; +import 'dart:convert' show Utf8Codec, BASE64; import 'dart:typed_data' show ByteData; import 'dart:typed_data' show Endianness; import 'dart:typed_data' show Uint8List; -import 'package:crypto/crypto.dart' show CryptoUtils; import 'package:fixnum/fixnum.dart'; import 'package:http/http.dart' show Client; import 'package:logging/logging.dart'; @@ -51,6 +50,9 @@ part 'src/protocol/t_set.dart'; part 'src/protocol/t_struct.dart'; part 'src/protocol/t_type.dart'; +part 'src/serializer/t_deserializer.dart'; +part 'src/serializer/t_serializer.dart'; + part 'src/transport/t_buffered_transport.dart'; part 'src/transport/t_framed_transport.dart'; part 'src/transport/t_http_transport.dart'; diff --git a/lib/dart/pubspec.yaml b/lib/dart/pubspec.yaml index 7012f5d55..53f5450f2 100644 --- a/lib/dart/pubspec.yaml +++ b/lib/dart/pubspec.yaml @@ -23,9 +23,8 @@ author: Apache Thrift Developers <dev@thrift.apache.org> homepage: http://thrift.apache.org documentation: http://thrift.apache.org environment: - sdk: ">=1.12.0 <2.0.0" + sdk: ">=1.13.0 <2.0.0" dependencies: - crypto: "^0.9.0" fixnum: "^0.10.2" http: "^0.11.3" logging: "^0.11.0" diff --git a/lib/dart/test/serializer/serializer_test.dart b/lib/dart/test/serializer/serializer_test.dart new file mode 100644 index 000000000..2f76503c4 --- /dev/null +++ b/lib/dart/test/serializer/serializer_test.dart @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +library thrift.test.serializer.serializer_test; + +import 'package:test/test.dart'; +import 'package:thrift/thrift.dart'; +import 'serializer_test_data.dart'; + +void main() { + var serializer = () { + TDeserializer deserializer; + TSerializer serializer; + TestTObject testTObject; + + setUp(() { + serializer = new TSerializer(); + deserializer = new TDeserializer(); + + testTObject = new TestTObject(); + testTObject.b = true; + testTObject.s = "TEST"; + testTObject.d = 15.25; + testTObject.i = 10; + + var testList = new List<String>(); + testList.add("TEST 1"); + testList.add("TEST 2"); + + testTObject.l = testList; + }); + + assertNewObjectEqualsTObject(TestTObject newObject) { + expect(newObject.l, equals(testTObject.l)); + expect(newObject.b, equals(testTObject.b)); + expect(newObject.i, equals(testTObject.i)); + expect(newObject.d, equals(testTObject.d)); + expect(newObject.s, equals(testTObject.s)); + } + + runWriteStringTest() { + var s = serializer.writeString(testTObject); + + var newObject = new TestTObject(); + deserializer.readString(newObject, s); + + assertNewObjectEqualsTObject(newObject); + }; + + runWriteTest() { + var s = serializer.write(testTObject); + + var newObject = new TestTObject(); + deserializer.read(newObject, s); + + assertNewObjectEqualsTObject(newObject); + }; + + test('JSON Protocol String', () { + serializer.protocol = new TJsonProtocol(serializer.transport); + deserializer.protocol = new TJsonProtocol(deserializer.transport); + + runWriteStringTest(); + }); + + test('JSON Protocol', () { + serializer.protocol = new TJsonProtocol(serializer.transport); + deserializer.protocol = new TJsonProtocol(deserializer.transport); + + runWriteTest(); + }); + + test('Binary Protocol String', () { + serializer.protocol = new TBinaryProtocol(serializer.transport); + deserializer.protocol = new TBinaryProtocol(deserializer.transport); + + runWriteStringTest(); + }); + + test('Binary Protocol', () { + serializer.protocol = new TBinaryProtocol(serializer.transport); + deserializer.protocol = new TBinaryProtocol(deserializer.transport); + + runWriteTest(); + }); + + test('Compact Protocol String', () { + serializer.protocol = new TCompactProtocol(serializer.transport); + deserializer.protocol = new TCompactProtocol(deserializer.transport); + + runWriteStringTest(); + }); + + test('Compact Protocol', () { + serializer.protocol = new TCompactProtocol(serializer.transport); + deserializer.protocol = new TCompactProtocol(deserializer.transport); + + runWriteTest(); + }); + }; + + group('Serializer', serializer); +} diff --git a/lib/dart/test/serializer/serializer_test_data.dart b/lib/dart/test/serializer/serializer_test_data.dart new file mode 100644 index 000000000..f957e3d69 --- /dev/null +++ b/lib/dart/test/serializer/serializer_test_data.dart @@ -0,0 +1,342 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +library thrift.test.serializer.serializer_test; + +import 'package:thrift/thrift.dart'; + +/// TestTObject is a simple test struct +class TestTObject implements TBase { + static final TStruct _STRUCT_DESC = new TStruct("TestTObject"); + static final TField _I_FIELD_DESC = new TField("i", TType.I32, 1); + static final TField _D_FIELD_DESC = new TField("d", TType.DOUBLE, 2); + static final TField _S_FIELD_DESC = new TField("s", TType.STRING, 3); + static final TField _L_FIELD_DESC = new TField("l", TType.LIST, 4); + static final TField _B_FIELD_DESC = new TField("b", TType.BOOL, 5); + + int _i; + static const int I = 1; + double _d; + static const int D = 2; + String _s; + static const int S = 3; + List<String> _l; + static const int L = 4; + bool _b; + static const int B = 5; + + bool __isset_i = false; + bool __isset_d = false; + bool __isset_b = false; + + TestTObject() { + } + + // i + int get i => this._i; + + set i(int i) { + this._i = i; + this.__isset_i = true; + } + + bool isSetI() => this.__isset_i; + + unsetI() { + this.__isset_i = false; + } + + // d + double get d => this._d; + + set d(double d) { + this._d = d; + this.__isset_d = true; + } + + bool isSetD() => this.__isset_d; + + unsetD() { + this.__isset_d = false; + } + + // s + String get s => this._s; + + set s(String s) { + this._s = s; + } + + bool isSetS() => this.s != null; + + unsetS() { + this.s = null; + } + + // l + List<String> get l => this._l; + + set l(List<String> l) { + this._l = l; + } + + bool isSetL() => this.l != null; + + unsetL() { + this.l = null; + } + + // b + bool get b => this._b; + + set b(bool b) { + this._b = b; + this.__isset_b = true; + } + + bool isSetB() => this.__isset_b; + + unsetB() { + this.__isset_b = false; + } + + getFieldValue(int fieldID) { + switch (fieldID) { + case I: + return this.i; + case D: + return this.d; + case S: + return this.s; + case L: + return this.l; + case B: + return this.b; + default: + throw new ArgumentError("Field $fieldID doesn't exist!"); + } + } + + setFieldValue(int fieldID, Object value) { + switch (fieldID) { + case I: + if (value == null) { + unsetI(); + } else { + this.i = value; + } + break; + + case D: + if (value == null) { + unsetD(); + } else { + this.d = value; + } + break; + + case S: + if (value == null) { + unsetS(); + } else { + this.s = value; + } + break; + + case L: + if (value == null) { + unsetL(); + } else { + this.l = value; + } + break; + + case B: + if (value == null) { + unsetB(); + } else { + this.b = value; + } + break; + + default: + throw new ArgumentError("Field $fieldID doesn't exist!"); + } + } + + // Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise + bool isSet(int fieldID) { + switch (fieldID) { + case I: + return isSetI(); + case D: + return isSetD(); + case S: + return isSetS(); + case L: + return isSetL(); + case B: + return isSetB(); + default: + throw new ArgumentError("Field $fieldID doesn't exist!"); + } + } + + read(TProtocol iprot) { + TField field; + iprot.readStructBegin(); + while (true) { + field = iprot.readFieldBegin(); + if (field.type == TType.STOP) { + break; + } + switch (field.id) { + case I: + if (field.type == TType.I32) { + this.i = iprot.readI32(); + this.__isset_i = true; + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case D: + if (field.type == TType.DOUBLE) { + this.d = iprot.readDouble(); + this.__isset_d = true; + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case S: + if (field.type == TType.STRING) { + this.s = iprot.readString(); + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case L: + if (field.type == TType.LIST) { + { + TList _list74 = iprot.readListBegin(); + this.l = new List<String>(); + for (int _i75 = 0; _i75 < _list74.length; ++_i75) { + String _elem76; + _elem76 = iprot.readString(); + this.l.add(_elem76); + } + iprot.readListEnd(); + } + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + case B: + if (field.type == TType.BOOL) { + this.b = iprot.readBool(); + this.__isset_b = true; + } else { + TProtocolUtil.skip(iprot, field.type); + } + break; + default: + TProtocolUtil.skip(iprot, field.type); + break; + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + write(TProtocol oprot) { + validate(); + + oprot.writeStructBegin(_STRUCT_DESC); + oprot.writeFieldBegin(_I_FIELD_DESC); + oprot.writeI32(this.i); + oprot.writeFieldEnd(); + oprot.writeFieldBegin(_D_FIELD_DESC); + oprot.writeDouble(this.d); + oprot.writeFieldEnd(); + if (this.s != null) { + oprot.writeFieldBegin(_S_FIELD_DESC); + oprot.writeString(this.s); + oprot.writeFieldEnd(); + } + if (this.l != null) { + oprot.writeFieldBegin(_L_FIELD_DESC); + { + oprot.writeListBegin(new TList(TType.STRING, this.l.length)); + for (var elem77 in this.l) { + oprot.writeString(elem77); + } + oprot.writeListEnd(); + } + oprot.writeFieldEnd(); + } + oprot.writeFieldBegin(_B_FIELD_DESC); + oprot.writeBool(this.b); + oprot.writeFieldEnd(); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + String toString() { + StringBuffer ret = new StringBuffer("TestTObject("); + + ret.write("i:"); + ret.write(this.i); + + ret.write(", "); + ret.write("d:"); + ret.write(this.d); + + ret.write(", "); + ret.write("s:"); + if (this.s == null) { + ret.write("null"); + } else { + ret.write(this.s); + } + + ret.write(", "); + ret.write("l:"); + if (this.l == null) { + ret.write("null"); + } else { + ret.write(this.l); + } + + ret.write(", "); + ret.write("b:"); + ret.write(this.b); + + ret.write(")"); + + return ret.toString(); + } + + validate() { + // check for required fields + // check that fields of type enum have valid values + } + +}
\ No newline at end of file diff --git a/lib/dart/test/transport/t_http_transport_test.dart b/lib/dart/test/transport/t_http_transport_test.dart index 7fcab3eae..66f3d054b 100644 --- a/lib/dart/test/transport/t_http_transport_test.dart +++ b/lib/dart/test/transport/t_http_transport_test.dart @@ -19,10 +19,9 @@ library thrift.test.transport.t_socket_transport_test; import 'dart:async'; import 'dart:convert' show Encoding; -import 'dart:convert' show Utf8Codec; +import 'dart:convert' show Utf8Codec, BASE64; import 'dart:typed_data' show Uint8List; -import 'package:crypto/crypto.dart' show CryptoUtils; import 'package:http/http.dart' show BaseRequest; import 'package:http/http.dart' show Client; import 'package:http/http.dart' show Response; @@ -54,14 +53,14 @@ void main() { expect(client.postRequest, isNotEmpty); var requestText = - utf8Codec.decode(CryptoUtils.base64StringToBytes(client.postRequest)); + utf8Codec.decode(BASE64.decode(client.postRequest)); expect(requestText, expectedText); }); test('Test transport receives response', () async { var expectedText = 'my response'; var expectedBytes = utf8Codec.encode(expectedText); - client.postResponse = CryptoUtils.bytesToBase64(expectedBytes); + client.postResponse = BASE64.encode(expectedBytes); transport.writeAll(utf8Codec.encode('my request')); expect(transport.hasReadData, isFalse); @@ -95,7 +94,7 @@ void main() { // prepare a response transport.writeAll(utf8Codec.encode('request 1')); - client.postResponse = CryptoUtils.bytesToBase64(expectedBytes); + client.postResponse = BASE64.encode(expectedBytes); Future responseReady = transport.flush().then((_) { var buffer = new Uint8List(expectedBytes.length); @@ -106,7 +105,7 @@ void main() { // prepare a second response transport.writeAll(utf8Codec.encode('request 2')); var response2Bytes = utf8Codec.encode('response 2'); - client.postResponse = CryptoUtils.bytesToBase64(response2Bytes); + client.postResponse = BASE64.encode(response2Bytes); await transport.flush(); await responseReady; diff --git a/lib/dart/test/transport/t_socket_transport_test.dart b/lib/dart/test/transport/t_socket_transport_test.dart index 997df0db2..929ab17b1 100644 --- a/lib/dart/test/transport/t_socket_transport_test.dart +++ b/lib/dart/test/transport/t_socket_transport_test.dart @@ -18,10 +18,9 @@ library thrift.test.transport.t_socket_transport_test; import 'dart:async'; -import 'dart:convert' show Utf8Codec; +import 'dart:convert' show Utf8Codec, BASE64; import 'dart:typed_data' show Uint8List; -import 'package:crypto/crypto.dart' show CryptoUtils; import 'package:mockito/mockito.dart'; import 'package:test/test.dart'; import 'package:thrift/thrift.dart'; @@ -31,14 +30,14 @@ void main() { final requestText = 'my test request'; final requestBytes = new Uint8List.fromList(utf8Codec.encode(requestText)); - final requestBase64 = CryptoUtils.bytesToBase64(requestBytes); + final requestBase64 = BASE64.encode(requestBytes); final responseText = 'response 1'; final responseBytes = new Uint8List.fromList(utf8Codec.encode(responseText)); - final responseBase64 = CryptoUtils.bytesToBase64(responseBytes); + final responseBase64 = BASE64.encode(responseBytes); final framedResponseBase64 = - CryptoUtils.bytesToBase64(_getFramedResponse(responseBytes)); + BASE64.encode(_getFramedResponse(responseBytes)); group('TClientSocketTransport', () { FakeSocket socket; @@ -140,7 +139,7 @@ void main() { var response2Text = 'response 2'; var response2Bytes = new Uint8List.fromList(utf8Codec.encode(response2Text)); - var response2Base64 = CryptoUtils.bytesToBase64(response2Bytes); + var response2Base64 = BASE64.encode(response2Bytes); protocolFactory.message = new TMessage('foo2', TMessageType.REPLY, 124); socket.receiveFakeMessage(response2Base64); @@ -280,7 +279,7 @@ class FakeSocket extends TSocket { if (!isOpen) throw new StateError('The socket is not open'); var message = - new Uint8List.fromList(CryptoUtils.base64StringToBytes(base64)); + new Uint8List.fromList(BASE64.decode(base64)); _onMessageController.add(message); } } |