implement LongItem block

This commit is contained in:
REAndroid 2023-04-05 12:32:12 -04:00
parent 2eb4e7f96d
commit 2b6da361dc
3 changed files with 73 additions and 0 deletions

View File

@ -158,4 +158,29 @@ public abstract class BlockItem extends Block {
int value = (bytes[byteOffset] & mask) | add; int value = (bytes[byteOffset] & mask) | add;
bytes[byteOffset] = (byte) value; bytes[byteOffset] = (byte) value;
} }
protected static long getLong(byte[] bytes, int offset){
if((offset + 8)>bytes.length){
return 0;
}
long result = 0;
int index = offset + 7;
while (index>=offset){
result = result << 8;
result |= (bytes[index] & 0xff);
index --;
}
return result;
}
protected static void putLong(byte[] bytes, int offset, long value){
if((offset + 8) > bytes.length){
return;
}
int index = offset;
offset = index + 8;
while (index<offset){
bytes[index] = (byte) (value & 0xff);
value = value >>> 8;
index++;
}
}
} }

View File

@ -46,6 +46,9 @@ package com.reandroid.arsc.item;
public int get(){ public int get(){
return mCache; return mCache;
} }
public long unsignedLong(){
return get() & 0x00000000ffffffffL;
}
public String toHex(){ public String toHex(){
return String.format("0x%08x", get()); return String.format("0x%08x", get());
} }

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2022 github.com/REAndroid
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.arsc.item;
public class LongItem extends BlockItem{
private long mCache;
public LongItem() {
super(8);
}
public void set(long value){
if(value == mCache){
return;
}
mCache = value;
putLong(getBytesInternal(), 0, value);
}
public long get(){
return mCache;
}
public String toHex(){
return String.format("0x%016x", get());
}
@Override
protected void onBytesChanged() {
mCache = getLong(getBytesInternal(), 0);
}
@Override
public String toString(){
return String.valueOf(get());
}
}