当在AS3的ByteArray中使用writeUTF()和writeUTFBytes() [英] when to use writeUTF() and writeUTFBytes() in ByteArray of AS3

查看:1497
本文介绍了当在AS3的ByteArray中使用writeUTF()和writeUTFBytes()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个文件格式为我自己,所以我形成了我的文件头。要编写一个已知长度的字符串转换为字节数组,我应该使用哪种方法,writeUTF()或writeUTFBytes()可。

I am trying to create a file format for myself, so i was forming the header for my file. To write a known length string into a ByteArray, which method should i use, writeUTF() or writeUTFBytes().

从Flex 3语言参考,它告诉我,writeUTF(),prepends字符串的长度和引发RangeError而writeUTFBytes()可没有。

From the Flex 3 language ref, it tells me that writeUTF() prepends the length of the string and throws a RangeError whereas writeUTFBytes() does not.

任何suggessions将AP preciated。

Any suggessions would be appreciated.

推荐答案

这两者之间的唯一区别是, writeUTFBytes()可没有prePEND消息用字符串的长度(的RangeError是因为65535是最高的数字,你可以在16位存储)

The only difference between the two is that writeUTFBytes() doesn't prepend the message with the length of the string (The RangeError is because 65535 is the highest number you can store in 16 bits)

如果你使用一个比其他取决于你在做什么。比如,我使用 writeUTFBytes()可复制一个XML对象了是COM pressed时。在这种情况下,我不关心字符串的长度,它会引入一些额外的code。

Where you'd use one over the other depends on what you're doing. For example, I use writeUTFBytes() when copying a XML object over to be compressed. In this case, I don't care about the length of the string, and it'd introduce something extra to the code.

writeUTF()如果你正在写一个流媒体/网络服务器,在那里你preFIX消息长度的消息时,你知道如何可能是有用的许多字节流的消息结束之前的另一端。例如,我有200个字节的价值信息。我读的长度(16位整数),它告诉我的信息是100个字节。我读的100个字节,我知道这是一个完整的消息。一切后,是另一条消息。如果消息长度表示该消息为300字节,那么我知道我不得不等待了一下之前,我有充分的信息。

writeUTF() can be useful if you're writing a streaming/network server, where as you prefix the message length to the message, you know how many bytes to stream on the other end before the end of the message. e.g., I have 200 bytes worth of message. I read the length (16-bit integer), which tells me the message is 100 bytes. I read in 100 bytes and I know it's a complete message. Everything after is another message. If the message length said the message was 300 bytes, then I'd know I'd have to wait a bit before I have the full message.

这篇关于当在AS3的ByteArray中使用writeUTF()和writeUTFBytes()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆