Package org.jruby.util

Examples of org.jruby.util.ByteList.begin()


                }
            }

            ByteList result = new ByteList((int) left);
            ByteBuffer buf = ByteBuffer.wrap(result.getUnsafeBytes(),
                    result.begin(), (int) left);

            //
            // Copy any buffered data (including ungetc byte)
            //
            copyBufferedBytes(buf);
View Full Code Here


        if (length < 0 || length > bytes.length() - start) {
            length = bytes.length() - start;
        }
       
        ByteBuffer buf = ByteBuffer.wrap(bytes.getUnsafeBytes(), bytes.begin() + start, length);
       
        try {
            CharBuffer cbuf = fromEncoding.decode(buf);
            buf = toEncoding.encode(cbuf);
        } catch (MalformedInputException e) {
View Full Code Here

            } else if (parameter.isNil()) {
                buffer.putAddress(0L);

            } else if (parameter instanceof RubyString) {
                ByteList bl = ((RubyString) parameter).getByteList();
                buffer.putArray(bl.getUnsafeBytes(), bl.begin(), bl.length(), flags | ArrayFlags.NULTERMINATE);

            } else if (parameter.respondsTo("to_ptr")) {
                final int MAXRECURSE = 4;
                for (int depth = 0; depth < MAXRECURSE; ++depth) {
                    IRubyObject ptr = parameter.callMethod(context, "to_ptr");
View Full Code Here

       
        public final void marshal(ThreadContext context, InvocationBuffer buffer, IRubyObject parameter) {
            if (parameter instanceof RubyString) {
                StringSupport.checkStringSafety(context.getRuntime(), parameter);
                ByteList bl = ((RubyString) parameter).getByteList();
                buffer.putArray(bl.getUnsafeBytes(), bl.begin(), bl.length(),
                        ArrayFlags.IN | ArrayFlags.NULTERMINATE);
            } else if (parameter.isNil()) {
                buffer.putAddress(0);
            } else {
                throw context.getRuntime().newArgumentError("Invalid string parameter");
View Full Code Here

    @JRubyMethod(name = "put_string")
    public IRubyObject put_string(ThreadContext context, IRubyObject offArg, IRubyObject strArg) {
        long off = getOffset(offArg);
        ByteList bl = strArg.convertToString().getByteList();
        getMemoryIO().putZeroTerminatedByteArray(off, bl.getUnsafeBytes(), bl.begin(), bl.length());
        return this;
    }

    @JRubyMethod(name = "get_bytes")
    public IRubyObject get_bytes(ThreadContext context, IRubyObject offArg, IRubyObject lenArg) {
View Full Code Here

        }
        int len = args.length > 3 ? Util.int32Value(args[3]) : (bl.length() - idx);
        if (len < 0 || len > (bl.length() - idx)) {
            throw context.getRuntime().newRangeError("Invalid length");
        }
        getMemoryIO().put(off, bl.getUnsafeBytes(), bl.begin() + idx, len);
        return this;
    }


    @JRubyMethod(name = { "read_pointer" })
View Full Code Here

            // not get freed by the GC until the struct is freed
            //
            cache.putReference(m, mem);

            MemoryIO io = mem.getMemoryIO();
            io.put(0, bl.getUnsafeBytes(), bl.begin(), bl.length());
            io.putByte(bl.length(), (byte) 0);

            ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), io);
        }
View Full Code Here

        public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) {
           
            if (isCharArray() && value instanceof RubyString) {
                ByteList bl = value.convertToString().getByteList();
                ptr.getMemoryIO().putZeroTerminatedByteArray(m.offset, bl.getUnsafeBytes(), bl.begin(),
                    Math.min(bl.length(), arrayType.length() - 1));

            } else if (false) {
                RubyArray ary = value.convertToArray();
                int count = ary.size();
View Full Code Here

            // not get freed by the GC until the struct is freed
            //
            cache.putReference(m, mem);

            MemoryIO io = mem.getMemoryIO();
            io.put(0, bl.getUnsafeBytes(), bl.begin(), bl.length());
            io.putByte(bl.length(), (byte) 0);

            ptr.getMemoryIO().putMemoryIO(m.getOffset(ptr), io);
        }
View Full Code Here

        @Override
        void put(ThreadContext context, MemoryIO io, long offset, IRubyObject value) {
            if (isCharArray() && value instanceof RubyString) {
                ByteList bl = value.convertToString().getByteList();
                io.putZeroTerminatedByteArray(offset, bl.getUnsafeBytes(), bl.begin(),
                    Math.min(bl.length(), arrayType.length() - 1));
            } else {
                throw context.runtime.newNotImplementedError("cannot set multi deminesional array field");
            }
        }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.