Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
4e6d649f
Commit
4e6d649f
authored
Jan 08, 2020
by
Sunbreak
Committed by
Flutter GitHub Bot
Jan 08, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add optional `endian` argument for WriteBuffer/ReadBuffer (#46661)
parent
945f206b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
20 deletions
+44
-20
serialization.dart
packages/flutter/lib/src/foundation/serialization.dart
+20
-20
serialization_test.dart
packages/flutter/test/foundation/serialization_test.dart
+24
-0
No files found.
packages/flutter/lib/src/foundation/serialization.dart
View file @
4e6d649f
...
...
@@ -30,33 +30,33 @@ class WriteBuffer {
}
/// Write a Uint16 into the buffer.
void
putUint16
(
int
value
)
{
_eightBytes
.
setUint16
(
0
,
value
,
Endian
.
host
);
void
putUint16
(
int
value
,
{
Endian
endian
}
)
{
_eightBytes
.
setUint16
(
0
,
value
,
endian
??
Endian
.
host
);
_buffer
.
addAll
(
_eightBytesAsList
,
0
,
2
);
}
/// Write a Uint32 into the buffer.
void
putUint32
(
int
value
)
{
_eightBytes
.
setUint32
(
0
,
value
,
Endian
.
host
);
void
putUint32
(
int
value
,
{
Endian
endian
}
)
{
_eightBytes
.
setUint32
(
0
,
value
,
endian
??
Endian
.
host
);
_buffer
.
addAll
(
_eightBytesAsList
,
0
,
4
);
}
/// Write an Int32 into the buffer.
void
putInt32
(
int
value
)
{
_eightBytes
.
setInt32
(
0
,
value
,
Endian
.
host
);
void
putInt32
(
int
value
,
{
Endian
endian
}
)
{
_eightBytes
.
setInt32
(
0
,
value
,
endian
??
Endian
.
host
);
_buffer
.
addAll
(
_eightBytesAsList
,
0
,
4
);
}
/// Write an Int64 into the buffer.
void
putInt64
(
int
value
)
{
_eightBytes
.
setInt64
(
0
,
value
,
Endian
.
host
);
void
putInt64
(
int
value
,
{
Endian
endian
}
)
{
_eightBytes
.
setInt64
(
0
,
value
,
endian
??
Endian
.
host
);
_buffer
.
addAll
(
_eightBytesAsList
,
0
,
8
);
}
/// Write an Float64 into the buffer.
void
putFloat64
(
double
value
)
{
void
putFloat64
(
double
value
,
{
Endian
endian
}
)
{
_alignTo
(
8
);
_eightBytes
.
setFloat64
(
0
,
value
,
Endian
.
host
);
_eightBytes
.
setFloat64
(
0
,
value
,
endian
??
Endian
.
host
);
_buffer
.
addAll
(
_eightBytesAsList
);
}
...
...
@@ -122,37 +122,37 @@ class ReadBuffer {
}
/// Reads a Uint16 from the buffer.
int
getUint16
()
{
final
int
value
=
data
.
getUint16
(
_position
,
Endian
.
host
);
int
getUint16
(
{
Endian
endian
}
)
{
final
int
value
=
data
.
getUint16
(
_position
,
endian
??
Endian
.
host
);
_position
+=
2
;
return
value
;
}
/// Reads a Uint32 from the buffer.
int
getUint32
()
{
final
int
value
=
data
.
getUint32
(
_position
,
Endian
.
host
);
int
getUint32
(
{
Endian
endian
}
)
{
final
int
value
=
data
.
getUint32
(
_position
,
endian
??
Endian
.
host
);
_position
+=
4
;
return
value
;
}
/// Reads an Int32 from the buffer.
int
getInt32
()
{
final
int
value
=
data
.
getInt32
(
_position
,
Endian
.
host
);
int
getInt32
(
{
Endian
endian
}
)
{
final
int
value
=
data
.
getInt32
(
_position
,
endian
??
Endian
.
host
);
_position
+=
4
;
return
value
;
}
/// Reads an Int64 from the buffer.
int
getInt64
()
{
final
int
value
=
data
.
getInt64
(
_position
,
Endian
.
host
);
int
getInt64
(
{
Endian
endian
}
)
{
final
int
value
=
data
.
getInt64
(
_position
,
endian
??
Endian
.
host
);
_position
+=
8
;
return
value
;
}
/// Reads a Float64 from the buffer.
double
getFloat64
()
{
double
getFloat64
(
{
Endian
endian
}
)
{
_alignTo
(
8
);
final
double
value
=
data
.
getFloat64
(
_position
,
Endian
.
host
);
final
double
value
=
data
.
getFloat64
(
_position
,
endian
??
Endian
.
host
);
_position
+=
8
;
return
value
;
}
...
...
packages/flutter/test/foundation/serialization_test.dart
View file @
4e6d649f
...
...
@@ -27,6 +27,14 @@ void main() {
final
ReadBuffer
read
=
ReadBuffer
(
written
);
expect
(
read
.
getInt32
(),
equals
(-
9
));
});
test
(
'of 32-bit integer in big endian'
,
()
{
final
WriteBuffer
write
=
WriteBuffer
();
write
.
putInt32
(-
9
,
endian:
Endian
.
big
);
final
ByteData
written
=
write
.
done
();
expect
(
written
.
lengthInBytes
,
equals
(
4
));
final
ReadBuffer
read
=
ReadBuffer
(
written
);
expect
(
read
.
getInt32
(
endian:
Endian
.
big
),
equals
(-
9
));
});
test
(
'of 64-bit integer'
,
()
{
final
WriteBuffer
write
=
WriteBuffer
();
write
.
putInt64
(-
9000000000000
);
...
...
@@ -35,6 +43,14 @@ void main() {
final
ReadBuffer
read
=
ReadBuffer
(
written
);
expect
(
read
.
getInt64
(),
equals
(-
9000000000000
));
});
test
(
'of 64-bit integer in big endian'
,
()
{
final
WriteBuffer
write
=
WriteBuffer
();
write
.
putInt64
(-
9000000000000
,
endian:
Endian
.
big
);
final
ByteData
written
=
write
.
done
();
expect
(
written
.
lengthInBytes
,
equals
(
8
));
final
ReadBuffer
read
=
ReadBuffer
(
written
);
expect
(
read
.
getInt64
(
endian:
Endian
.
big
),
equals
(-
9000000000000
));
});
test
(
'of double'
,
()
{
final
WriteBuffer
write
=
WriteBuffer
();
write
.
putFloat64
(
3.14
);
...
...
@@ -43,6 +59,14 @@ void main() {
final
ReadBuffer
read
=
ReadBuffer
(
written
);
expect
(
read
.
getFloat64
(),
equals
(
3.14
));
});
test
(
'of double in big endian'
,
()
{
final
WriteBuffer
write
=
WriteBuffer
();
write
.
putFloat64
(
3.14
,
endian:
Endian
.
big
);
final
ByteData
written
=
write
.
done
();
expect
(
written
.
lengthInBytes
,
equals
(
8
));
final
ReadBuffer
read
=
ReadBuffer
(
written
);
expect
(
read
.
getFloat64
(
endian:
Endian
.
big
),
equals
(
3.14
));
});
test
(
'of 32-bit int list when unaligned'
,
()
{
final
Int32List
integers
=
Int32List
.
fromList
(<
int
>[-
99
,
2
,
99
]);
final
WriteBuffer
write
=
WriteBuffer
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment