nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
app.nit: id the platform at runtime
[nit.git]
/
lib
/
binary
/
binary.nit
diff --git
a/lib/binary/binary.nit
b/lib/binary/binary.nit
index
263ad95
..
dbe07be
100644
(file)
--- a/
lib/binary/binary.nit
+++ b/
lib/binary/binary.nit
@@
-12,7
+12,7
@@
# See the License for the specific language governing permissions and
# limitations under the License.
# See the License for the specific language governing permissions and
# limitations under the License.
-# Add reading and writing binary services
+# Read and write binary data with any `Reader` and `Writer`
#
# ~~~
# var w = new FileWriter.open("/tmp/data.bin")
#
# ~~~
# var w = new FileWriter.open("/tmp/data.bin")
@@
-107,7
+107,7
@@
redef abstract class Writer
# Compared to `write_string`, this method supports null bytes in `text`.
fun write_block(text: Text)
do
# Compared to `write_string`, this method supports null bytes in `text`.
fun write_block(text: Text)
do
- write_int64 text.length
+ write_int64 text.byte_length
write text
end
write text
end
@@
-178,11
+178,13
@@
redef abstract class Reader
# Returns a truncated string when an error is pending (`last_error != null`).
fun read_string: String
do
# Returns a truncated string when an error is pending (`last_error != null`).
fun read_string: String
do
- var buf = new FlatBuffer
+ var buf = new Bytes.empty
loop
var byte = read_byte
loop
var byte = read_byte
- if byte == null or byte == 0x00u8 then return buf.to_s
- buf.bytes.add byte
+ if byte == null or byte == 0u8 then
+ return buf.to_s
+ end
+ buf.add byte
end
end
end
end
@@
-195,7
+197,7
@@
redef abstract class Reader
do
var length = read_int64
if length == 0 then return ""
do
var length = read_int64
if length == 0 then return ""
- return read(length)
+ return read_bytes(length).to_s
end
# Read a floating point on 32 bits and return it as a `Float`
end
# Read a floating point on 32 bits and return it as a `Float`