/** Returns the function call to pack a given type. */ private String getPackFuncJava(Type t, Object off, Object len) { String prefix = (record != packetType) ? "pack" : "packPayload"; if (t == BOOLEAN) return prefix + "Boolean(" + off + ", val)"; if (t == BOOLNULL) return prefix + "Boolean(" + off + ", val)"; if (t == INETADDR) return prefix + "InetAddr(" + off + ", val)"; if (t == UUID) return prefix + "UUID(" + off + ", val)"; if (t == BYTE) return prefix + "Byte(" + off + ", val)"; if (t == SHORT) return prefix + "Short(" + off + ", val)"; if (t == INT) return prefix + "Int(" + off + ", val)"; if (t == LONG) return prefix + "Long(" + off + ", val)"; if (t == FLOAT) return prefix + "Float(" + off + ", val)"; if (t == DOUBLE) return prefix + "Double(" + off + ", val)"; if (t == UTCTIME) return prefix + "TimeStamp(" + off + ", val, nxm.vrt.lib.TimeStamp.IntegerMode.UTC)"; if (t == GPSTIME) return prefix + "TimeStamp(" + off + ", val, nxm.vrt.lib.TimeStamp.IntegerMode.GPS)"; if (t.isAsciiType()) return prefix + "Ascii(" + off + ", val, " + len + ")"; if (t.isUTF8Type()) return prefix + "UTF8(" + off + ", val, " + len + ")"; if (t.isAsciiTypeStr()) return prefix + "Ascii(" + off + ", val, " + len + ")"; if (t.isUTF8TypeStr()) return prefix + "UTF8(" + off + ", val, " + len + ")"; if (t.isMetadataType()) return prefix + "Metadata(" + off + ", val, " + len + ")"; if (t instanceof Record) return prefix + "Record(" + off + ", val)"; if (t instanceof Enumeration) return prefix + "Byte(" + off + ", " + t.getTypeJavaGet() + ".getValue(val))"; throw new RuntimeException("Unsupported type " + t.getTypeName()); }
/** Gets the <tt>HasFields</tt> type for C++. */ public CharSequence getCPPFieldType() { Type t = getType(); String prefix = ""; if (t.isArrayType()) { prefix = "(ValueType)-"; t = t.getArrayType(); } if (t == BOOLEAN) return prefix + "ValueType_Bool"; if (t == BOOLNULL) return prefix + "ValueType_BoolNull"; if (t == INETADDR) return prefix + "ValueType_VRTObject"; if (t == UUID) return prefix + "ValueType_VRTObject"; if (t == BYTE) return prefix + "ValueType_Int8"; if (t == SHORT) return prefix + "ValueType_Int16"; if (t == INT) return prefix + "ValueType_Int32"; if (t == LONG) return prefix + "ValueType_Int64"; if (t == FLOAT) return prefix + "ValueType_Float"; if (t == DOUBLE) return prefix + "ValueType_Double"; if (t == UTCTIME) return prefix + "ValueType_VRTObject"; if (t == GPSTIME) return prefix + "ValueType_VRTObject"; if (t.isAsciiType()) return prefix + "ValueType_String"; if (t.isUTF8Type()) return prefix + "ValueType_WString"; if (t.isAsciiTypeStr()) return prefix + "ValueType_String"; if (t.isUTF8TypeStr()) return prefix + "ValueType_WString"; if (t.isMetadataType()) return prefix + "ValueType_VRTObject"; if (t instanceof Record) return prefix + "ValueType_VRTObject"; if (t instanceof Enumeration) return prefix + "ValueType_Int8"; throw new RuntimeException("Unsupported type " + t.getTypeName()); }
/** Returns the function call to unpack a given type. */ private String getUnpackFuncCPP(Type t, Object off, Object len) { String prefix = (record != packetType) ? "unpack" : "unpackPayload"; if (t == BOOLEAN) return prefix + "Boolean(" + off + ")"; if (t == BOOLNULL) return prefix + "Boolean(" + off + ")"; if (t == INETADDR) return prefix + "InetAddr(" + off + ")"; if (t == UUID) return prefix + "UUID(" + off + ")"; if (t == BYTE) return prefix + "Byte(" + off + ")"; if (t == SHORT) return prefix + "Short(" + off + ")"; if (t == INT) return prefix + "Int(" + off + ")"; if (t == LONG) return prefix + "Long(" + off + ")"; if (t == FLOAT) return prefix + "Float(" + off + ")"; if (t == DOUBLE) return prefix + "Double(" + off + ")"; if (t == UTCTIME) return prefix + "TimeStamp(" + off + ", IntegerMode_UTC)"; if (t == GPSTIME) return prefix + "TimeStamp(" + off + ", IntegerMode_GPS)"; if (t.isAsciiType()) return prefix + "Ascii(" + off + ", " + len + ")"; if (t.isUTF8Type()) return prefix + "UTF8(" + off + ", " + len + ")"; if (t.isAsciiTypeStr()) return prefix + "Ascii(" + off + ", " + len + ")"; if (t.isUTF8TypeStr()) return prefix + "UTF8(" + off + ", " + len + ")"; if (t.isMetadataType()) return prefix + "Metadata(" + off + ", " + len + ")"; if (t instanceof Record) return prefix + "Record(" + off + ", r)"; // <-- special handling if (t instanceof Enumeration) return "(" + t.getTypeJavaGet() + ")" + prefix + "Byte(" + off + ")"; throw new RuntimeException("Unsupported type " + t.getTypeName()); }
/** Is the given type a native type in C++ (or an array of native types)? */ private boolean isCPPNativeType(Type t) { if (t.isArrayType()) return isCPPNativeType(t.getArrayType()); if (t == BOOLEAN) return true; if (t == BOOLNULL) return true; if (t == BYTE) return true; if (t == SHORT) return true; if (t == INT) return true; if (t == LONG) return true; if (t == FLOAT) return true; if (t == DOUBLE) return true; if (t.isAsciiType()) return true; // string if (t.isUTF8Type()) return true; // wstring if (t.isAsciiTypeStr()) return true; // string if (t.isUTF8TypeStr()) return true; // wstring if (t instanceof Enumeration) return true; // int8_t return false; }
private CodeParams getCodeParams(boolean isJava) { // ignore the pad bytes Type t = getType(); int b = getType().getTypeBytes(); String lenGet; String lenSet; String limit; String size; if (b >= 0) { lenGet = Integer.toString(b); lenSet = Integer.toString(b); limit = null; size = Integer.toString(b); } else if (b != Type.STAR_LENGTH) { if (t.isStringType()) { lenGet = "getPayloadLength()-" + offset; lenSet = Integer.toString(b); limit = null; size = "0 to " + (-b - 1) + " octets"; } else { throw new RuntimeException( "The array syntax [0" + b + "] is only applicable to ascii and utf8 fields."); } } else if (t.isAsciiType() || t.isAsciiTypeStr()) { lenGet = "getPayloadLength()-" + offset; lenSet = "val.length()"; limit = "MAX_PAYLOAD_LENGTH-" + offset; size = "variable"; } else if (t.isStringType()) { lenGet = "getPayloadLength()-" + offset; lenSet = (isJava) ? "nxm.vrt.lib.VRTMath.lengthUTF8(val)" : "vrt::VRTMath::lengthUTF8(val)"; limit = "MAX_PAYLOAD_LENGTH-" + offset; size = "variable"; } else if (t.isMetadataType()) { lenGet = "getPayloadLength()-" + offset; lenSet = "val.getLengthInBytes()"; limit = null; size = "variable"; } else if (t.isArrayType()) { int bytes = t.getArrayType().getTypeBytes(); if (bytes == 0) { lenGet = "getPayloadLength()-" + offset; lenSet = "val.length"; limit = null; size = "variable"; } else if (bytes > 0) { lenGet = "(getPayloadLength()-" + offset + ")/" + bytes; lenSet = "val.length"; limit = null; size = "variable"; } else { throw new RuntimeException( "Could not determine length of " + t.getTypeName() + " for " + this); } } else { throw new RuntimeException( "Could not determine length of " + t.getTypeName() + " for " + this); } String html = toHtmlDoc(descr, "").trim(); if (html.length() == 0) { html = methodName; } if (!html.endsWith(".")) { html += "."; } if (Character.isUpperCase(html.charAt(0)) && Character.isLowerCase(html.charAt(1))) { html = html.substring(0, 1).toLowerCase() + html.substring(1); } return new CodeParams(html, size, limit, lenGet, lenSet); }