11import 'dart:typed_data' ;
22
3- enum Flag {
4- none,
5- requireMinimalEncoding,
6- }
3+ enum Flag { none, requireMinimalEncoding }
74
85class CBORTag {
96 static const int majorUnsignedInteger = 0 ;
@@ -75,23 +72,27 @@ class CBOREncoder {
7572 if (length >= 5 && length <= 8 ) {
7673 encodeTagAndAdditional (tag, CBORTag .minorLength8);
7774 _buffer.add (
78- Uint8List (8 )..buffer.asByteData ().setUint64 (0 , value, Endian .big));
75+ Uint8List (8 )..buffer.asByteData ().setUint64 (0 , value, Endian .big),
76+ );
7977 } else if (length == 3 || length == 4 ) {
8078 encodeTagAndAdditional (tag, CBORTag .minorLength4);
8179 _buffer.add (
82- Uint8List (4 )..buffer.asByteData ().setUint32 (0 , value, Endian .big));
80+ Uint8List (4 )..buffer.asByteData ().setUint32 (0 , value, Endian .big),
81+ );
8382 } else if (length == 2 ) {
8483 encodeTagAndAdditional (tag, CBORTag .minorLength2);
8584 _buffer.add (
86- Uint8List (2 )..buffer.asByteData ().setUint16 (0 , value, Endian .big));
85+ Uint8List (2 )..buffer.asByteData ().setUint16 (0 , value, Endian .big),
86+ );
8787 } else if (length == 1 ) {
8888 encodeTagAndAdditional (tag, CBORTag .minorLength1);
8989 _buffer.addByte (value);
9090 } else if (length == 0 ) {
9191 encodeTagAndAdditional (tag, value);
9292 } else {
9393 throw Exception (
94- "Unsupported byte length of $length for value in encodeTagAndValue()" );
94+ "Unsupported byte length of $length for value in encodeTagAndValue()" ,
95+ );
9596 }
9697
9798 return 1 + length;
@@ -111,7 +112,9 @@ class CBOREncoder {
111112
112113 int encodeBool (bool value) {
113114 return encodeTagAndValue (
114- CBORTag .majorSimple, value ? CBORTag .minorTrue : CBORTag .minorFalse);
115+ CBORTag .majorSimple,
116+ value ? CBORTag .minorTrue : CBORTag .minorFalse,
117+ );
115118 }
116119
117120 int encodeBytes (Uint8List value) {
@@ -122,12 +125,16 @@ class CBOREncoder {
122125
123126 int encodeEncodedBytesPrefix (int value) {
124127 return encodeTagAndValue (
125- CBORTag .majorSemantic, CBORTag .minorCborEncodedData);
128+ CBORTag .majorSemantic,
129+ CBORTag .minorCborEncodedData,
130+ );
126131 }
127132
128133 int encodeEncodedBytes (Uint8List value) {
129- int length =
130- encodeTagAndValue (CBORTag .majorSemantic, CBORTag .minorCborEncodedData);
134+ int length = encodeTagAndValue (
135+ CBORTag .majorSemantic,
136+ CBORTag .minorCborEncodedData,
137+ );
131138 return length + encodeBytes (value);
132139 }
133140
@@ -197,8 +204,11 @@ class CBORDecoder {
197204 throw Exception ("Not enough input" );
198205 }
199206
200- ByteData byteData =
201- ByteData .sublistView (_buffer, _position, _position + bytesToRead);
207+ ByteData byteData = ByteData .sublistView (
208+ _buffer,
209+ _position,
210+ _position + bytesToRead,
211+ );
202212 _position += bytesToRead;
203213
204214 switch (bytesToRead) {
@@ -271,8 +281,11 @@ class CBORDecoder {
271281 throw Exception ("Not enough input" );
272282 }
273283
274- Uint8List value =
275- Uint8List .sublistView (_buffer, _position, _position + byteLength);
284+ Uint8List value = Uint8List .sublistView (
285+ _buffer,
286+ _position,
287+ _position + byteLength,
288+ );
276289 _position += byteLength;
277290 return (value, sizeLength + byteLength);
278291 }
@@ -312,8 +325,11 @@ class CBORDecoder {
312325 throw Exception ("Not enough input" );
313326 }
314327
315- Uint8List utf8Bytes =
316- Uint8List .sublistView (_buffer, _position, _position + byteLength);
328+ Uint8List utf8Bytes = Uint8List .sublistView (
329+ _buffer,
330+ _position,
331+ _position + byteLength,
332+ );
317333 _position += byteLength;
318334 String value = String .fromCharCodes (utf8Bytes);
319335 return (value, sizeLength + byteLength);
0 commit comments