Examples of EBitString


Examples of erjang.EBitString

    /** Emulate io_lib:write_binary_body(), but without using deep stack. */
    @BIF
    static public EObject write_binary_body(EObject arg1, EObject arg2)
    {
        EBitString bin = arg1.testBitString();
        EInteger d = arg2.testInteger();
       
        if (bin == null || d == null)
            throw ERT.badarg(arg1, arg2);
       
        int depth = d.intValue();
        if (depth < 0) depth=Integer.MAX_VALUE;
       
        ESeq builder = ERT.NIL;
        long bitCount = bin.bitSize();
        if (bitCount > 8*(depth-1)) {
            // Replace tail with ellipsis:
            builder = builder.cons(EString.fromString("..."));
        } else if (bitCount % 8 > 0) {
            // Handle tail bits
            int tailBitCount = (int)(bitCount & 7);
            int tailBits = bin.intBitsAt(bitCount & (~7), tailBitCount);
            builder = builder.cons(EString.fromString(String.valueOf(tailBitCount)));
            builder = builder.cons(ESmall.make(':'));
            builder = builder.cons(EString.fromString(String.valueOf(tailBits)));
        }
        // Handle whole bytes:
        for (long bitPos=8*(Math.min(bitCount/8, depth-1)-1);
             bitPos>=0;
             bitPos-=8)
        {
            if (bitPos < bitCount-8) {
                builder = builder.cons(ESmall.make(','));
            }
            String byteAsIntString = String.valueOf(bin.intBitsAt(bitPos, 8));
            builder = builder.cons(EString.fromString(byteAsIntString));
        }
        return builder;
    }
View Full Code Here

Examples of erjang.EBitString

    EBinary bin = term_to_binary(obj);
    return ERT.box(bin.byteSize());
  }

  @BIF static ETuple2 split_binary(EObject bin, EObject idx) {
    EBitString b;
    ESmall i;
    if ((b=bin.testBitString()) == null
      || ((i=idx.testSmall()) == null)
      || i.value < 0
      || i.value > b.byteSize()) {
      throw ERT.badarg(bin, idx);
    }

    long split = i.value*8;
    return new ETuple2(b.substring(0, split),
               b.substring(split));

    /* more efficient, but works only for EBinary */

    // return new ETuple2(b.sub_binary(0, i.value),
    //    b.sub_binary(i.value, b.byteSize()-i.value));   
View Full Code Here

Examples of erjang.EBitString

    return EString.make(bin);
  }

  @BIF
  public static EObject bitstring_to_list(EObject obj) {
    EBitString bin = obj.testBitString();
    if (bin == null)
      throw ERT.badarg(obj);
    return bin.toList();
  }
View Full Code Here

Examples of erjang.EBitString

    }
  }

  @BIF
  public static EBitString iolist_to_binary(EObject list) {
    EBitString bin = list.testBitString();
    if (bin != null)
      return bin;

    ECons iol = list.testCons();
    if (iol == null)
View Full Code Here

Examples of erjang.EBitString

  }


  @BIF(type=Type.GUARD, name="bit_size")
  public static EInteger bit_size_guard(EObject o) {
    EBitString bin = o.testBitString();
    if (bin == null)
      return null;
    return ERT.box(bin.bitSize());
  }
View Full Code Here

Examples of erjang.EBitString

    return ERT.box(t.arity());
  }

  @BIF
  public static ESmall byte_size(EObject o) {
    EBitString bin = o.testBitString();
    if (bin == null)
      throw ERT.badarg(o);
    return ERT.box(bin.totalByteSize());
  }
View Full Code Here

Examples of erjang.EBitString

  }

 
  @BIF(type=Type.GUARD, name="byte_size")
  public static ESmall byte_size_guard(EObject o) {
    EBitString bin = o.testBitString();
    if (bin == null)
      return null;
    return ERT.box(bin.totalByteSize());
  }
View Full Code Here

Examples of erjang.EBitString

    return ERT.box(bin.totalByteSize());
  }

  @BIF
  public static EInteger bit_size(EObject o) {
    EBitString bin = o.testBitString();
    if (bin == null)
      throw ERT.badarg(o);
    return ERT.box(bin.bitSize());
  }
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.