@JRubyMethod(meta = true) public static IRubyObject decode(ThreadContext context, IRubyObject recv, IRubyObject data) { byte[] bin = data.convertToString().getBytes(); RubyMessage ret = (RubyMessage) ((RubyClass) recv).newInstance(context, Block.NULL_BLOCK); try { ret.builder.mergeFrom(bin); } catch (InvalidProtocolBufferException e) { throw context.runtime.newRuntimeError(e.getMessage()); } return ret; }
case BYTES: Utils.validateStringEncoding(context, fieldDescriptor.getType(), value); val = ByteString.copyFrom(((RubyString) value).getBytes()); break; case STRING:
private byte[] convertToBytes(IRubyObject arg) { if (arg instanceof RubyString) { return ((RubyString) arg).getBytes(); } else if (arg instanceof RubyNumeric) { return arg.asString().getBytes(); } else { throw new IllegalArgumentException("Don't know how to write a " + arg + " " + arg.getClass()); } }
private byte[] convertToBytes(IRubyObject arg) { if (arg instanceof RubyString) { return ((RubyString) arg).getBytes(); } else if (arg instanceof RubyNumeric) { return arg.asString().getBytes(); } else { throw new IllegalArgumentException("Don't know how to write a " + arg + " " + arg.getClass()); } }
public static Encoding encArg(ThreadContext context, IRubyObject encval, byte[][] name_p, Encoding[] enc_p) { Encoding enc; if ((enc = toEncodingIndex(context, encval)) == null) { name_p[0] = encval.convertToString().getBytes(); } else { name_p[0] = enc.getName(); } return enc_p[0] = enc; }
public static Encoding encArg(ThreadContext context, IRubyObject encval, byte[][] name_p, Encoding[] enc_p) { if ((enc_p[0] = toEncodingIndex(context, encval)) == null) { name_p[0] = ((RubyString)encval.anyToString()).getBytes(); } else { name_p[0] = enc_p[0].getName(); } return enc_p[0]; }
private void joinMulticastGroup(IRubyObject val) throws IOException, BadDescriptorException { Channel socketChannel = getOpenChannel(); if(socketChannel instanceof DatagramChannel) { if (multicastStateManager == null) { multicastStateManager = new MulticastStateManager(); } if (val instanceof RubyString) { byte [] ipaddr_buf = val.convertToString().getBytes(); multicastStateManager.addMembership(ipaddr_buf); } } }
@JRubyMethod(name = "hexdigest", required = 1, optional = 1, meta = true) public static IRubyObject s_hexdigest(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { Ruby runtime = recv.getRuntime(); byte[] digest = recv.callMethod(context, "digest", args, Block.NULL_BLOCK).convertToString().getBytes(); return RubyDigest.toHexString(runtime, digest); }
@JRubyMethod(name = "hexdigest", required = 1, optional = 1, meta = true) public static IRubyObject s_hexdigest(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { Ruby runtime = recv.getRuntime(); byte[] digest = recv.callMethod(context, "digest", args, Block.NULL_BLOCK).convertToString().getBytes(); return RubyDigest.toHexString(runtime, digest); }
@JRubyMethod(name = "hexdigest", required = 1, optional = 1, meta = true) public static IRubyObject s_hexdigest(ThreadContext ctx, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { Ruby runtime = recv.getRuntime(); byte[] digest = recv.callMethod(ctx, "digest", args, Block.NULL_BLOCK).convertToString().getBytes(); return RubyDigest.toHexString(runtime, digest); } }
@JRubyMethod(name = "hexdigest", required = 1, optional = 1, meta = true) public static IRubyObject s_hexdigest(ThreadContext ctx, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { Ruby runtime = recv.getRuntime(); byte[] digest = recv.callMethod(ctx, "digest", args, Block.NULL_BLOCK).convertToString().getBytes(); return RubyDigest.toHexString(runtime, digest); } }
@Override protected byte[] computeNext() { try { return enumerator.callMethod(threadContext, "next").convertToString().getBytes(); } catch (RaiseException e) { close(); return endOfData(); } }
@JRubyMethod(name = "replicate") public IRubyObject replicate(ThreadContext context, IRubyObject arg) { return new RubyEncoding(context.runtime, arg.convertToString().getBytes(), getEncoding(), isDummy); }
@JRubyMethod(module = true, visibility = Visibility.PRIVATE) public static IRubyObject ruby_string_to_bytes(IRubyObject recv, IRubyObject string) { Ruby runtime = recv.getRuntime(); if (!(string instanceof RubyString)) { throw runtime.newTypeError(string, runtime.getString()); } return JavaUtil.convertJavaToUsableRubyObject(runtime, ((RubyString)string).getBytes()); }
@JRubyMethod(module = true, visibility = Visibility.PRIVATE) public static IRubyObject ruby_string_to_bytes(IRubyObject recv, IRubyObject string) { Ruby runtime = recv.getRuntime(); if (!(string instanceof RubyString)) { throw runtime.newTypeError(string, runtime.getString()); } return JavaUtil.convertJavaToUsableRubyObject(runtime, ((RubyString)string).getBytes()); }
@JRubyMethod(module = true, visibility = Visibility.PRIVATE) public static IRubyObject ruby_string_to_bytes(IRubyObject recv, IRubyObject string) { Ruby runtime = recv.getRuntime(); if (!(string instanceof RubyString)) { throw runtime.newTypeError(string, runtime.getString()); } return JavaUtil.convertJavaToUsableRubyObject(runtime, ((RubyString)string).getBytes()); }
@JRubyMethod(name = "bubblebabble", required = 1, optional = 1, meta = true) public static IRubyObject bubblebabble(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { byte[] digest = recv.callMethod(context, "digest", args, Block.NULL_BLOCK).convertToString().getBytes(); return RubyString.newString(recv.getRuntime(), BubbleBabble.bubblebabble(digest, 0, digest.length)); }
@JRubyMethod(name = "bubblebabble", required = 1, optional = 1, meta = true) public static IRubyObject bubblebabble(ThreadContext context, IRubyObject recv, IRubyObject[] args, Block unusedBlock) { byte[] digest = recv.callMethod(context, "digest", args, Block.NULL_BLOCK).convertToString().getBytes(); return RubyString.newString(recv.getRuntime(), BubbleBabble.bubblebabble(digest, 0, digest.length)); }
@JRubyMethod(name = "bubblebabble", required = 1, meta = true) public static RubyString bubblebabble(IRubyObject recv, IRubyObject arg) { byte[] digest = recv.callMethod(recv.getRuntime().getCurrentContext(), "digest", arg).convertToString().getBytes(); return RubyString.newString(recv.getRuntime(), BubbleBabble.bubblebabble(digest, 0, digest.length)); } }
@JRubyMethod(name = "bubblebabble", required = 1, meta = true) public static RubyString bubblebabble(IRubyObject recv, IRubyObject arg) { byte[] digest = recv.callMethod(recv.getRuntime().getCurrentContext(), "digest", arg).convertToString().getBytes(); return RubyString.newString(recv.getRuntime(), BubbleBabble.bubblebabble(digest, 0, digest.length)); } }