📄 structconverter.java
字号:
//******************************************************************
// Released under the DevelopMentor OpenSource Software License.
// Please consult the LICENSE file in the project root directory,
// or at http://www.develop.com for details before using this
// software.
//******************************************************************
package com.develop.jawin.marshal;
import com.develop.jawin.*;
import com.develop.jawin.win32.*;
import com.develop.io.*;
import com.develop.util.*;
import java.io.*;
public class StructConverter {
/*
public static INative structToMem(IStruct s)
throws COMException
{
byte[] bytes = s.instToBytes();
System.out.println(HexFormatter.convertBytesToString(bytes, 16, true));
if (bytes == null) {
throw new Error("reflective marshalling not implemented yet");
}
MemPtr mp = new MemPtr(bytes);
return mp;
}
*/
static public long parseLong(String val) {
int length = val.length();
if (length > 16) {
throw new NumberFormatException("too many digits");
}
int shift = 0;
long res = 0;
for (int i=length-1; i>=0; i--) {
res = res + ((long)Character.digit(val.charAt(i), 16) << shift);
shift += 4;
}
return res;
}
static public int parseInt(String val) {
int length = val.length();
if (length > 8) {
throw new NumberFormatException("too many digits");
}
int shift = 0;
int res = 0;
for (int i=length-1; i>=0; i--) {
res = res + (Character.digit(val.charAt(i), 16) << shift);
shift += 4;
}
return res;
}
static public short parseShort(String val) {
int length = val.length();
if (length > 4) {
throw new NumberFormatException("too many digits");
}
int shift = 0;
int res = 0;
for (int i=length-1; i>=0; i--) {
res = res + (Character.digit(val.charAt(i), 16) << shift);
shift += 4;
}
return (short) res;
}
static public int longIntoBEBytes(long data, byte[] bytes, int start) {
bytes[start++] = (byte) (data >>> 56);
bytes[start++] = (byte) (data >>> 48);
bytes[start++] = (byte) (data >>> 40);
bytes[start++] = (byte) (data >>> 32);
bytes[start++] = (byte) (data >>> 24);
bytes[start++] = (byte) (data >>> 16);
bytes[start++] = (byte) (data >>> 8);
bytes[start++] = (byte) (data);
return start;
}
static public long bytesIntoLong(byte[] bytes, int offset) {
int nLo = bytesIntoInt(bytes, offset);
int nHi = bytesIntoInt(bytes, offset+4);
return ((long)(nHi) << 32) + (nLo & 0xFFFFFFFFL);
}
static public double bytesIntoDouble(byte[] bytes, int offset) {
double d = Double.longBitsToDouble(bytesIntoLong(bytes, offset));
return d;
}
static public boolean bytesIntoBoolean(byte[] bytes, int offset) {
return bytes[offset] != 0;
}
static public int bytesIntoInt(byte[] bytes, int offset) {
int l = (bytes[offset] & 0xff) |
((bytes[offset+1] & 0xff) << 8) |
((bytes[offset+2] & 0xff) << 16) |
((bytes[offset+3] & 0xff) << 24);
return l;
}
static public int BEBytesIntoInt(byte[] bytes, int offset) {
int l = (bytes[offset+3] & 0xff) |
((bytes[offset+2] & 0xff) << 8) |
((bytes[offset+1] & 0xff) << 16) |
((bytes[offset+0] & 0xff) << 24);
return l;
}
static public short bytesIntoShort(byte[] bytes, int offset) {
int l = (bytes[offset] & 0xff) |
((bytes[offset+1] & 0xff) << 8);
return (short) l;
}
static public int longIntoBytes(long data, byte[] bytes, int start) {
bytes[start++] = (byte) (data);
bytes[start++] = (byte) (data >>> 8);
bytes[start++] = (byte) (data >>> 16);
bytes[start++] = (byte) (data >>> 24);
bytes[start++] = (byte) (data >>> 32);
bytes[start++] = (byte) (data >>> 40);
bytes[start++] = (byte) (data >>> 48);
bytes[start++] = (byte) (data >>> 56);
return start;
}
static public int intIntoBytes(int data, byte[] bytes, int start) {
bytes[start++] = (byte) (data);
bytes[start++] = (byte) (data >>> 8);
bytes[start++] = (byte) (data >>> 16);
bytes[start++] = (byte) (data >>> 24);
return start;
}
static public int shortIntoBytes(short data, byte[] bytes, int start) {
bytes[start++] = (byte) (data);
bytes[start++] = (byte) (data >>> 8);
return start;
}
static public int byteArrayIntoBytes(byte[] src, byte[] dest, int start) {
System.arraycopy(src, 0, dest, start, src.length);
return start + src.length;
}
static public String[] readStringArray(LittleEndianInputStream leis)
throws IOException
{
byte isNull = leis.readByte();
if (isNull == 0)
return null;
int size = leis.readInt();
String[] result = new String[size];
for (int n=0; n<size; n++) {
result[n] = leis.readStringUnicode();
}
return result;
}
static public int[] readIntArray(LittleEndianInputStream leis)
throws IOException
{
byte isNull = leis.readByte();
if (isNull == 0)
return null;
int size = leis.readInt();
int[] result = new int[size];
for (int n=0; n<size; n++) {
result[n] = leis.readInt();
}
return result;
}
static public Object[] readObjectArray(LittleEndianInputStream leis, GUID iid)
throws IOException, COMException
{
//COMEBACK: could infer array type from iid
byte isNull = leis.readByte();
if (isNull == 0)
return null;
int size = leis.readInt();
Object[] result = new Object[size];
for (int n=0; n<size; n++) {
result[n] = IdentityManager.getCOMPtr(leis, iid);
}
return result;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -