avm2: Implement read/writeBoolean()
This commit is contained in:
parent
437187a7bd
commit
4c540c9f17
|
@ -60,11 +60,7 @@ package flash.net {
|
|||
|
||||
public native function flush():void;
|
||||
|
||||
public function readBoolean():Boolean {
|
||||
stub_method("flash.net.Socket", "readBoolean");
|
||||
return false;
|
||||
}
|
||||
|
||||
public native function readBoolean():Boolean;
|
||||
public native function readByte():int;
|
||||
|
||||
public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void {
|
||||
|
@ -100,10 +96,7 @@ package flash.net {
|
|||
return "";
|
||||
}
|
||||
|
||||
public function writeBoolean(value:Boolean):void {
|
||||
stub_method("flash.net.Socket", "writeBoolean");
|
||||
}
|
||||
|
||||
public native function writeBoolean(value:Boolean):void;
|
||||
public native function writeByte(value:int):void;
|
||||
public native function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void;
|
||||
public native function writeDouble(value:Number):void;
|
||||
|
|
|
@ -134,6 +134,21 @@ pub fn flush<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn read_boolean<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
_args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
if let Some(socket) = this.as_socket() {
|
||||
return Ok(socket
|
||||
.read_boolean()
|
||||
.map_err(|e| e.to_avm(activation))?
|
||||
.into());
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn read_byte<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
|
@ -248,6 +263,19 @@ pub fn read_unsigned_short<'gc>(
|
|||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn write_boolean<'gc>(
|
||||
_activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
args: &[Value<'gc>],
|
||||
) -> Result<Value<'gc>, Error<'gc>> {
|
||||
if let Some(socket) = this.as_socket() {
|
||||
let byte = args.get_bool(0);
|
||||
socket.write_boolean(byte);
|
||||
}
|
||||
|
||||
Ok(Value::Undefined)
|
||||
}
|
||||
|
||||
pub fn write_byte<'gc>(
|
||||
activation: &mut Activation<'_, 'gc>,
|
||||
this: Object<'gc>,
|
||||
|
|
|
@ -104,6 +104,14 @@ impl<'gc> SocketObject<'gc> {
|
|||
let len = buf.len();
|
||||
buf.drain(..len).collect::<Vec<u8>>()
|
||||
}
|
||||
|
||||
pub fn read_boolean(&self) -> Result<bool, EofError> {
|
||||
Ok(self.read_bytes(1)? != [0])
|
||||
}
|
||||
|
||||
pub fn write_boolean(&self, val: bool) {
|
||||
self.write_bytes(&[val as u8; 1])
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_write{
|
||||
|
|
Loading…
Reference in New Issue