src/main/java/org/semgus/java/object/SmtTerm.java
private static SmtTerm deserializeBitVector(JSONObject termDto) throws DeserializationException {
        // deserialize size
        int size = JsonUtils.getInt(termDto, "size");
        if (size < 0) {
            throw new DeserializationException("Bit vector size must be non-negative!", "size");
        }

        // deserialize the bit field string
        String bitVecStr = JsonUtils.getString(termDto, "value");
        if (!bitVecStr.startsWith("0x")) {
            throw new DeserializationException("Bit vector value must start with \"0x\"!", "value");
        }
        int bitVecStrLen = bitVecStr.length();
        int unpaddedByteCount = bitVecStrLen / 2 - 1; // minus one to account for the "0x"

        // parse out the bit field
        byte[] bitField;
        try {
            if ((bitVecStrLen % 2) == 1) { // hex string is of odd length; need to pad the most significant byte
                bitField = new byte[unpaddedByteCount + 1];
                bitField[unpaddedByteCount] = (byte)readHexChar(bitVecStr.charAt(2));
            } else { // hex string is of even length; no bytes need to be padded
                bitField = new byte[unpaddedByteCount];
            }
            for (int i = 0; i < unpaddedByteCount; i++) {
                bitField[i] = (byte)(readHexChar(bitVecStr.charAt(bitVecStrLen - i * 2 - 1))
                        | (readHexChar(bitVecStr.charAt(bitVecStrLen - i * 2 - 2)) << 4));
            }
        } catch (DeserializationException e) {
            throw e.prepend("value");
        }
        BitSet bitVecValue = BitSet.valueOf(bitField);
        if (bitVecValue.nextSetBit(size) != -1) { // ensure there are no set bits beyond the vector size
            throw new DeserializationException("Bit vector value is wider than bit vector size!");
        }

        return new CBitVector(size, bitVecValue);
    }
/**
     * Deserializes a bit vector constant.
     *
     * @param termDto The JSON representation of the bit vector constant.
     * @return The deserialized bit vector constant.
     * @throws DeserializationException If {@code termDto} is not a valid representation of a bit vector constant.
     */
Deserializes a bit vector constant.
@param termDto The JSON representation of the bit vector constant.
@return The deserialized bit vector constant.
@throws DeserializationException If  termDto is not a valid representation of a bit vector constant.
Deserializes a bit vector constant . @param termDto The JSON representation of the bit vector constant . @return The deserialized bit vector constant . @throws DeserializationException If termDto is not a valid representation of a bit vector constant .
private static SmtTerm deserializeBitVector(JSONObject termDto) throws DeserializationException {
        int size = JsonUtils.getInt(termDto, "size");
        if (size < 0) {
            throw new DeserializationException("Bit vector size must be non-negative!", "size");
        }
        String bitVecStr = JsonUtils.getString(termDto, "value");
        if (!bitVecStr.startsWith("0x")) {
            throw new DeserializationException("Bit vector value must start with \"0x\"!", "value");
        }
        int bitVecStrLen = bitVecStr.length();
        int unpaddedByteCount = bitVecStrLen / 2 - 1; 
        byte[] bitField;
        try {
            if ((bitVecStrLen % 2) == 1) { 
                bitField = new byte[unpaddedByteCount + 1];
                bitField[unpaddedByteCount] = (byte)readHexChar(bitVecStr.charAt(2));
            } else { 
                bitField = new byte[unpaddedByteCount];
            }
            for (int i = 0; i < unpaddedByteCount; i++) {
                bitField[i] = (byte)(readHexChar(bitVecStr.charAt(bitVecStrLen - i * 2 - 1))
                        | (readHexChar(bitVecStr.charAt(bitVecStrLen - i * 2 - 2)) << 4));
            }
        } catch (DeserializationException e) {
            throw e.prepend("value");
        }
        BitSet bitVecValue = BitSet.valueOf(bitField);
        if (bitVecValue.nextSetBit(size) != -1) { 
            throw new DeserializationException("Bit vector value is wider than bit vector size!");
        }
        return new CBitVector(size, bitVecValue);
    }
private static SmtTerm deserializeBitVector ( JSONObject termDto ) throws DeserializationException { int size = JsonUtils . getInt ( termDto , "size" ) ; if ( size < 0 ) { throw new DeserializationException ( "Bit vector size must be non-negative!" , "size" ) ; } String bitVecStr = JsonUtils . getString ( termDto , "value" ) ; if ( ! bitVecStr . startsWith ( "0x" ) ) { throw new DeserializationException ( "Bit vector value must start with \"0x\"!" , "value" ) ; } int bitVecStrLen = bitVecStr . length ( ) ; int unpaddedByteCount = bitVecStrLen / 2 - 1 ; byte [ ] bitField ; try { if ( ( bitVecStrLen % 2 ) == 1 ) { bitField = new byte [ unpaddedByteCount + 1 ] ; bitField [ unpaddedByteCount ] = ( byte ) readHexChar ( bitVecStr . charAt ( 2 ) ) ; } else { bitField = new byte [ unpaddedByteCount ] ; } for ( int i = 0 ; i < unpaddedByteCount ; i ++ ) { bitField [ i ] = ( byte ) ( readHexChar ( bitVecStr . charAt ( bitVecStrLen - i * 2 - 1 ) ) | ( readHexChar ( bitVecStr . charAt ( bitVecStrLen - i * 2 - 2 ) ) << 4 ) ) ; } } catch ( DeserializationException e ) { throw e . prepend ( "value" ) ; } BitSet bitVecValue = BitSet . valueOf ( bitField ) ; if ( bitVecValue . nextSetBit ( size ) != - 1 ) { throw new DeserializationException ( "Bit vector value is wider than bit vector size!" ) ; } return new CBitVector ( size , bitVecValue ) ; }
Deserializes a bit vector constant.
Deserializes a bit vector constant .
// deserialize size // deserialize the bit field string // minus one to account for the "0x" // parse out the bit field // hex string is of odd length; need to pad the most significant byte // hex string is of even length; no bytes need to be padded // ensure there are no set bits beyond the vector size