Sha256: eefc9586b0dd02caf0262a909e78a6297db7dcf640cbac1d96b41127140306a8
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
#include <ruby.h> VALUE WebSocket = Qnil; VALUE WebSocketNative = Qnil; VALUE WebSocketNativeData = Qnil; void Init_websocket_native_ext(); VALUE method_websocket_native_data_mask(VALUE self, VALUE payload, VALUE mask); void Init_websocket_native_ext() { WebSocket = rb_define_module("WebSocket"); WebSocketNative = rb_define_module_under(WebSocket, "Native"); WebSocketNativeData = rb_define_class_under(WebSocketNative, "Data", rb_cObject); rb_define_method(WebSocketNativeData, "mask", method_websocket_native_data_mask, 2); } VALUE method_websocket_native_data_mask(VALUE self, VALUE payload, VALUE mask) { int n = RARRAY_LEN(payload), i, p, m; VALUE unmasked = rb_ary_new2(n); int mask_array[] = { NUM2INT(rb_ary_entry(mask, 0)), NUM2INT(rb_ary_entry(mask, 1)), NUM2INT(rb_ary_entry(mask, 2)), NUM2INT(rb_ary_entry(mask, 3)) }; for (i = 0; i < n; i++) { p = NUM2INT(rb_ary_entry(payload, i)); m = mask_array[i % 4]; rb_ary_store(unmasked, i, INT2NUM(p ^ m)); } return unmasked; }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
websocket-native-1.0.0-java | ext/websocket_native_ext/websocket_native_ext.c |
websocket-native-1.0.0 | ext/websocket_native_ext/websocket_native_ext.c |