public ReceivePayload(ArrayBuffer arrayBuffer, WebSocketMessageType messageType = WebSocketMessageType.Binary) { using (var bin = new Uint8Array(arrayBuffer)) { dataMessageReceived = bin.ToArray(); this.messageType = messageType; } }
public static void UploadSZS(Uint8Array arr) //called from js { DoActionWithloading(() => { byte[] sarc = ManagedYaz0.Decompress(arr.ToArray()); CommonSzs = SARCExt.SARC.UnpackRamN(sarc); sarc = null; while (LayoutsComboBox.LastChild.TextContent != "Don't patch") { LayoutsComboBox.RemoveChild(LayoutsComboBox.LastChild); } targetPatch = SwitchThemesCommon.DetectSarc(CommonSzs, DefaultTemplates.templates); if (targetPatch == null) { Window.Alert("This is not a valid theme file, if it's from a newer firmware it's not compatible with this tool yet"); CommonSzs = null; targetPatch = null; lblDetected.TextContent = ""; return; } lblDetected.TextContent = "Detected " + targetPatch.TemplateName + " " + targetPatch.FirmName; for (int i = 0; i < layoutPatches.Length; i++) { if (layoutPatches[i] != null && layoutPatches[i].IsCompatible(CommonSzs)) { LayoutsComboBox.Add(new HTMLOptionElement() { TextContent = layoutPatches[i].ToString(), Value = i.ToString() }); } } }); }
public static void AutoThemeFileUploaded(Uint8Array arr) { if (!ValidAutoThemeParts.ContainsStr(AutoThemePartName)) { Window.Alert("An invalid part name has been selected"); return; } DoActionWithloading(() => { byte[] szs = arr.ToArray(); byte[] sarc = ManagedYaz0.Decompress(szs); var szsData = SARCExt.SARC.UnpackRamN(sarc); sarc = null; var detected = SwitchThemesCommon.DetectSarc(szsData, DefaultTemplates.templates); if (detected == null) { Window.Alert("This is not a valid theme file, if it's from a newer firmware it's not compatible with this tool yet"); return; } if (!detected.TemplateName.Contains(AutoThemePartName)) { Window.Alert("This szs is valid but it doesn't look like the right one, you can keep it but it might generate themes that affect the wrong parts of the menu"); } Window.LocalStorage.SetItem(AutoThemePartName, Convert.ToBase64String(szs)); Window.LocalStorage.SetItem(AutoThemePartName + "Name", detected.TemplateName + " " + detected.FirmName); LoadAutoThemeState(); }); }
public static void UploadDDS(Uint8Array arr, string fileName) //called from file uploader { DoActionWithloading(() => { lblDDSPath.TextContent = fileName; LoadedDDS = DDSEncoder.LoadDDS(arr.ToArray()); }); }
public ReceivePayload(ArrayBuffer arrayBuffer, WebSocketMessageType messageType) { using (var bin = new Uint8Array(arrayBuffer)) { _dataMessageReceived = bin.ToArray(); _messageType = messageType; } }
public static void MarshalByteBufferToInts(ArrayBuffer buffer) { using (var bytes = new Uint8Array(buffer)) { var byteBuffer = bytes.ToArray(); intBuffer = new int[bytes.Length / sizeof(int)]; for (int i = 0; i < bytes.Length; i += sizeof(int)) { intBuffer[i / sizeof(int)] = BitConverter.ToInt32(byteBuffer, i); } } }
private async Task <byte []> GetResponseData() { if (_data != null) { return(_data); } using (ArrayBuffer dataBuffer = (ArrayBuffer)await _status.ArrayBuffer()) { using (Uint8Array dataBinView = new Uint8Array(dataBuffer)) { _data = dataBinView.ToArray(); _status.Dispose(); _status = null; } } return(_data); }
static void LoadFile(Uint8Array arr) //entrypoint, called from JsFileRead { LoadThemeFromByteArr(arr.ToArray()); }
private static void MarshalByteBuffer(Uint8Array buffer) { _byteBuffer = buffer.ToArray(); }
private static void MarshalArrayBuffer(ArrayBuffer buffer) { using (var bytes = new Uint8Array(buffer)) _byteBuffer = bytes.ToArray(); }
public override async Task <int> ReadAsync(byte [] buffer, int offset, int count, CancellationToken cancellationToken) { if (buffer == null) { throw new ArgumentNullException(nameof(buffer)); } if (offset < 0) { throw new ArgumentOutOfRangeException(nameof(offset)); } if (count < 0 || buffer.Length - offset < count) { throw new ArgumentOutOfRangeException(nameof(count)); } if (_reader == null) { // If we've read everything, then _reader and _status will be null if (_status == null) { return(0); } using (var body = _status.Body) { _reader = (JSObject)body.Invoke("getReader"); } } if (_bufferedBytes != null && _position < _bufferedBytes.Length) { return(ReadBuffered()); } var t = (Task <object>)_reader.Invoke("read"); using (var read = (JSObject)await t) { if ((bool)read.GetObjectProperty("done")) { _reader.Dispose(); _reader = null; _status.Dispose(); _status = null; return(0); } _position = 0; // value for fetch streams is a Uint8Array using (Uint8Array binValue = (Uint8Array)read.GetObjectProperty("value")) _bufferedBytes = binValue.ToArray(); } return(ReadBuffered()); int ReadBuffered() { int n = _bufferedBytes.Length - _position; if (n > count) { n = count; } if (n <= 0) { return(0); } Buffer.BlockCopy(_bufferedBytes, _position, buffer, offset, n); _position += n; return(n); } }
public RTCDataChannel(JSObject ho) { cts = new CancellationTokenSource(); this.hostObject = ho; onMessage = new Action <JSObject>((messageEvent) => { ThrowIfNotConnected(); // get the events "data" var eventData = messageEvent.GetObjectProperty("data"); // If the messageEvent's data property is marshalled as a JSObject then we are dealing with // binary data if (eventData is ArrayBuffer ab) { using (var arrayBuffer = ab) { using (var bin = new Uint8Array(arrayBuffer)) { OnDataMessage?.Invoke(this, bin.ToArray()); } } } else if (eventData is JSObject evt) { // TODO: Handle ArrayBuffer binary type but have only seen 'blob' so far without // changing the default websocket binary type manually. var dataType = hostObject.GetObjectProperty("binaryType").ToString(); if (dataType == "blob") { Action <JSObject> loadend = null; // Create a new "FileReader" object using (var reader = new HostObject("FileReader")) { loadend = new Action <JSObject>((loadEvent) => { using (var target = (JSObject)loadEvent.GetObjectProperty("target")) { if ((int)target.GetObjectProperty("readyState") == 2) { using (var binResult = (ArrayBuffer)target.GetObjectProperty("result")) { //var mess = new ReceivePayload(binResult, WebSocketMessageType.Binary); //receiveMessageQueue.BufferPayload(mess); //Runtime.FreeObject(loadend); } } } loadEvent.Dispose(); }); reader.Invoke("addEventListener", "loadend", loadend); using (var blobData = (JSObject)messageEvent.GetObjectProperty("data")) reader.Invoke("readAsArrayBuffer", blobData); } } else { throw new NotImplementedException($"WebSocket bynary type '{hostObject.GetObjectProperty("binaryType").ToString()}' not supported."); } } else if (eventData is string) { OnMessage?.Invoke(this, eventData as string); } messageEvent.Dispose(); }); // Attach the onMessage callaback hostObject.Invoke("addEventListener", "message", onMessage); onBuffer = new Action <JSObject>((e) => { this.OnBuffer?.Invoke(this, EventArgs.Empty); e.Dispose(); }); hostObject.SetObjectProperty("onbufferedamountlow", onBuffer); onOpen = new Action <JSObject>((messageEvent) => { this.OnOpen?.Invoke(this, EventArgs.Empty); messageEvent.Dispose(); }); // Attach the onMessage callaback hostObject.SetObjectProperty("onopen", onOpen); onClose = new Action <JSObject>((messageEvent) => { this.OnClose?.Invoke(this, EventArgs.Empty); messageEvent.Dispose(); }); // Attach the onMessage callaback hostObject.SetObjectProperty("onclose", onClose); }
public static void MarshalByteBuffer(Uint8Array buffer) { byteBuffer = buffer.ToArray(); }