def setFn(field): valueString = setMath("value", field, "") lookup = "" if "Enum" in field: # find index that corresponds to string input param lookup = enumLookup(field) param = "value" loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", idx" ret = '''\ %s <MSGSHORTNAME>.prototype.Set%s = function(%s) { %sthis.m_data.set%s(%s, %s%s); };''' % (fnHdr(field), field["Name"], param, lookup, fieldType(field), loc, valueString, endian_string()) if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): ret += ''' %s <MSGSHORTNAME>.prototype.Set%sString = function(value) { for(i=0; i<%s && i<value.length; i++) { this.Set%s(value[i].charCodeAt(0), i); } };''' % (fnHdr(field), field["Name"], str(MsgParser.fieldCount(field)), field["Name"]) return ret
def setFn(field): paramType = returnType(field, None) valueString = setMath("value", field) #if "Enum" in field: # valueString = paramType + "(" + valueString + ")" # paramType = field["Enum"] param = paramType + " value" loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", int idx" ret = '''\ %s void Set%s(%s) { _data.set%s(%s, %s%s); }''' % (fnHdr(field), field["Name"], param, fieldType(field), loc, valueString, endian_string()) if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): ret += ''' %s void Set%sString(String value) { for(int i=0; i<%s && i<value.length; i++) { Set%s(value.codeUnitAt(i), i); } }''' % (fnHdr(field), field["Name"], str( MsgParser.fieldCount(field)), field["Name"]) return ret
def setFn(msg, field): valueString = setMath("value", field, fieldType(field)) loc = str(1 + MsgParser.fieldLocation(field)) end_loc = str(1 + MsgParser.fieldLocation(field) + MsgParser.fieldSize(field) * MsgParser.fieldCount(field) - 1) asInt = "" if "Enum" in field: asInt = "AsInt" ret = '''\ %s function obj = set.%s%s(obj, value) ''' % (fnHdr(field), matlabFieldName(msg, field), asInt) if MsgParser.big_endian: swap = "swapbytes" else: swap = "" ret += '''\ obj.m_data(%s:%s) = typecast(%s(%s(%s)), 'uint8'); end ''' % (loc, end_loc, swap, fieldType(field), valueString) if "Enum" in field: ret += '''\ %s function obj = set.%s(obj, value) ''' % (fnHdr(field), matlabFieldName(msg, field)) ret += " if isKey(obj.Reverse" + field["Enum"] + "Enum, value)\n" ret += " value = obj.Reverse" + field["Enum"] + "Enum(value);\n" ret += " end\n" ret += " obj." + matlabFieldName(msg, field) + "AsInt = value;\n" ret += "end\n" # Need to handle arrays of structs, where elements of array are not contiguous! if MsgParser.fieldSize(field) != MsgParser.fieldArrayElementOffset(field): ret = "ERROR! Need to handle arrays of structs, where elements of array are not contiguous!\n" + ret return ret
def setFn(msg, field): loc = msgName(msg) + ".MSG_OFFSET + " + str(MsgParser.fieldLocation(field)) count = MsgParser.fieldCount(field) type = fieldType(field) lookup = "" if "Enum" in field: # find index that corresponds to string input param lookup = enumLookup(msg, field) math = MsgParser.setMath("value", field, "int") storageType = field["Type"] if "int" in storageType: math = "min(max(%s, %s), %s)" % (math, MsgParser.fieldStorageMin(storageType), MsgParser.fieldStorageMax(storageType)) math = lookup + "tmp = " + math if count > 1: if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): type = str(count) + "s" count = 1 math = "tmp = value.encode('utf-8')" else: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) ret = '''\ %s %s struct.pack_into('%s', self.rawBuffer(), %s, tmp) ''' % (fnHdr(field,MsgParser.fieldLocation(field),count, "Set"+field["Name"]), math, type, loc) return ret
def getFn(msg, field): loc = msgName(msg) + ".MSG_OFFSET + " + str(MsgParser.fieldLocation(field)) type = "'"+fieldType(field)+"'" count = MsgParser.fieldCount(field) cleanup = "" preface = "" if "Enum" in field: # find index that corresponds to string input param cleanup = reverseEnumLookup(msg, field) if count > 1: if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): preface += "\n count = " + str(count)+"\n" preface += " if count > len(self.rawBuffer())-("+loc+"):\n" preface += " count = len(self.rawBuffer())-("+loc+")\n" type = "str(count)+'s'" count = 1 cleanup = '''ascii_len = str(value).find("\\\\x00") value = str(value)[2:ascii_len] ''' else: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) if "Offset" in field or "Scale" in field: cleanup = "value = " + MsgParser.getMath("value", field, "")+"\n " ret = '''\ %s%s value = struct.unpack_from(%s, self.rawBuffer(), %s)[0] %sreturn value ''' % (fnHdr(field,MsgParser.fieldLocation(field),count, "Get"+field["Name"]), preface, type, loc, cleanup) return ret
def arrayAccessor(field): # if we've got floating point conversion, don't do an array accessor if "Offset" in field or "Scale" in field: return "" # if we're not an array, don't do an array accessor if MsgParser.fieldCount(field) == 1: return "" # if we're not contiguous, don't do an array accessor if MsgParser.fieldSize(field) != MsgParser.fieldArrayElementOffset(field): return "" # if we don't have natural alignment, don't do an array accessor if MsgParser.fieldLocation(field) % MsgParser.fieldSize(field) != 0: return "" loc = str(MsgParser.fieldLocation(field)) access = "(%s*)&m_data[%s]" % (fieldType(field), loc) ret = '''\ %s %s* %s(%s) { return %s; }''' % (fnHdr(field), functionPrefix + fieldType(field), namespace + field["Name"], firstParamDecl, access) if MsgParser.fieldSize(field) != 1: if MsgParser.big_endian: ret = "#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \n" + ret + "\n#endif\n" else: ret = "#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ \n" + ret + "\n#endif\n" return ret
def setFn(msg, field): valueString = setMath("value", field, fieldType(field)) loc = str(1+MsgParser.fieldLocation(field)) end_loc = str(1+MsgParser.fieldLocation(field) + MsgParser.fieldSize(field)*MsgParser.fieldCount(field)-1) asInt = "" if "Enum" in field: asInt = "AsInt" ret = '''\ %s function obj = set.%s%s(obj, value) ''' % (fnHdr(field), matlabFieldName(msg,field), asInt) if MsgParser.big_endian: swap = "swapbytes" else: swap = "" ret += '''\ obj.m_data(%s:%s) = typecast(%s(%s(%s)), 'uint8'); end ''' % (loc, end_loc, swap, fieldType(field), valueString) if "Enum" in field: ret += '''\ %s function obj = set.%s(obj, value) ''' % (fnHdr(field), matlabFieldName(msg,field)) ret += " if isKey(obj.Reverse"+field["Enum"]+"Enum, value)\n" ret += " value = obj.Reverse"+field["Enum"]+"Enum(value);\n" ret += " end\n" ret += " obj."+matlabFieldName(msg,field)+"AsInt = value;\n" ret += "end\n" # Need to handle arrays of structs, where elements of array are not contiguous! if MsgParser.fieldSize(field) != MsgParser.fieldArrayElementOffset(field): ret = "ERROR! Need to handle arrays of structs, where elements of array are not contiguous!\n" + ret return ret
def setFn(msg, field): loc = msgName(msg) + ".MSG_OFFSET + " + str(MsgParser.fieldLocation(field)) count = MsgParser.fieldCount(field) type = fieldType(field) lookup = "" if "Enum" in field: # find index that corresponds to string input param lookup = enumLookup(msg, field) math = MsgParser.setMath("value", field, "int") storageType = field["Type"] if "int" in storageType: math = "min(max(%s, %s), %s)" % ( math, MsgParser.fieldStorageMin(storageType), MsgParser.fieldStorageMax(storageType)) math = lookup + "tmp = " + math if count > 1: if MsgParser.fieldUnits(field) == "ASCII" and ( field["Type"] == "uint8" or field["Type"] == "int8"): type = str(count) + "s" count = 1 math = "tmp = value.encode('utf-8')" else: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) ret = '''\ %s %s struct.pack_into('%s', self.rawBuffer(), %s, tmp) ''' % (fnHdr(field, MsgParser.fieldLocation(field), count, "Set" + field["Name"]), math, type, loc) return ret
def getFn(msg, field): loc = str(1+MsgParser.fieldLocation(field)) end_loc = str(1+MsgParser.fieldLocation(field) + MsgParser.fieldSize(field)*MsgParser.fieldCount(field)-1) param = "obj" access = "typecast(obj.m_data(%s:%s), '%s')" % (loc, end_loc, fieldType(field)) if MsgParser.big_endian: access = "swapbytes(%s)" % access access = getMath(access, field, typeForScaledInt(field)) retType = fieldType(field) if "Offset" in field or "Scale" in field: retType = typeForScaledInt(field) asInt = "" if "Enum" in field: asInt = "AsInt" ret = '''\ %s function ret = get.%s%s(%s) ret = %s; end ''' % (fnHdr(field), matlabFieldName(msg,field), asInt, param, access) if "Enum" in field: ret += '''\ %s function ret = get.%s(%s) ret = obj.%sAsInt; ''' % (fnHdr(field), matlabFieldName(msg,field), param, matlabFieldName(msg,field)) ret += " if isKey(obj."+field["Enum"]+"Enum, ret)\n" ret += " ret = obj."+field["Enum"]+"Enum(ret);\n" ret += " end\n" ret += "end\n" # Need to handle arrays of structs, where elements of array are not contiguous! if MsgParser.fieldSize(field) != MsgParser.fieldArrayElementOffset(field): ret = "ERROR! Need to handle arrays of structs, where elements of array are not contiguous!\n" + ret return ret
def getFn(msg, field): loc = msgName(msg) + ".MSG_OFFSET + " + str(MsgParser.fieldLocation(field)) type = "'" + fieldType(field) + "'" count = MsgParser.fieldCount(field) cleanup = "" preface = "" if "Enum" in field: # find index that corresponds to string input param cleanup = reverseEnumLookup(msg, field) if count > 1: if MsgParser.fieldUnits(field) == "ASCII" and ( field["Type"] == "uint8" or field["Type"] == "int8"): preface += "\n count = " + str(count) + "\n" preface += " if count > len(self.rawBuffer())-(" + loc + "):\n" preface += " count = len(self.rawBuffer())-(" + loc + ")\n" type = "str(count)+'s'" count = 1 cleanup = '''ascii_len = str(value).find("\\\\x00") value = str(value)[2:ascii_len] ''' else: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) if "Offset" in field or "Scale" in field: cleanup = "value = " + MsgParser.getMath("value", field, "") + "\n " ret = '''\ %s%s value = struct.unpack_from(%s, self.rawBuffer(), %s)[0] %sreturn value ''' % (fnHdr(field, MsgParser.fieldLocation(field), count, "Get" + field["Name"]), preface, type, loc, cleanup) return ret
def arrayAccessor(field): # if we've got floating point conversion, don't do an array accessor if "Offset" in field or "Scale" in field: return "" # if we're not an array, don't do an array accessor if MsgParser.fieldCount(field) == 1: return "" # if we're not contiguous, don't do an array accessor if MsgParser.fieldSize(field) != MsgParser.fieldArrayElementOffset(field): return "" # if we don't have natural alignment, don't do an array accessor if MsgParser.fieldLocation(field) % MsgParser.fieldSize(field) != 0: return "" loc = str(MsgParser.fieldLocation(field)) access = "(%s*)&m_data[%s]" % (fieldType(field), loc) ret = '''\ %s %s* %s(%s) { return %s; }''' % (fnHdr(field), functionPrefix+fieldType(field), namespace+field["Name"], firstParamDecl, access) if MsgParser.fieldSize(field) != 1: if MsgParser.big_endian: ret = "#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \n" + ret + "\n#endif\n" else: ret = "#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ \n" + ret + "\n#endif\n" return ret
def setFn(field): valueString = setMath("value", field, fieldType(field)) param = "_ value: " + paramType(field) loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", _ idx: Int" ret = '''\ %s public func Set%s(%s) { m_data.SetField(offset: %s, value: %s); };''' % (fnHdr(field), field["Name"], param, loc, valueString) if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): ret += ''' %s public func Set%sString(value: String) { let stringArray = Array(value.utf8); for i in 0 ..< min(%s, stringArray.count) { Set%s(stringArray[i], i); } };''' % (fnHdr(field), field["Name"], str(MsgParser.fieldCount(field)), field["Name"]) return ret
def setFn(field): paramType = fieldType(field) if "Offset" in field or "Scale" in field: paramType = typeForScaledInt(field) valueString = setMath("value", field, fieldType(field)) param = "value: " + paramType loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += " + index*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", index: Int" ret = '''\ %s fun set%s(%s) { data.put%s(%s, %s%s) }''' % (fnHdr(field), field["Name"], param, fieldType(field), loc, valueString, endian_string()) return ret
def setFn(field): paramType = fieldType(field) valueString = setMath("value", field, '('+fieldType(field)+')', 'f') if "Offset" in field or "Scale" in field: paramType = typeForScaledInt(field) #elif "Enum" in field: # valueString = valueString + ".intValue()" # paramType = field["Enum"] param = paramType + " value" loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", int idx" ret = '''\ %s public void Set%s(%s) { m_data.put%s(%s, (%s)%s); }''' % (fnHdr(field), field["Name"], param, fieldAccessorType(field), loc, fieldCastType(field).lower(), valueString) return ret
def setFn(field): paramType = fieldType(field) valueString = setMath("value", field, '(' + fieldType(field) + ')', 'f') if "Offset" in field or "Scale" in field: paramType = typeForScaledInt(field) #elif "Enum" in field: # valueString = valueString + ".intValue()" # paramType = field["Enum"] param = paramType + " value" loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", int idx" ret = '''\ %s public void Set%s(%s) { m_data.put%s(%s, (%s)%s); }''' % (fnHdr(field), field["Name"], param, fieldAccessorType(field), loc, fieldCastType(field).lower(), valueString) return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += " + index*" + str(MsgParser.fieldArrayElementOffset(field)) param += "index: Int" retType = fieldType(field) if "Offset" in field or "Scale" in field: retType = typeForScaledInt(field) ret = '''\ %s fun get%s(%s): %s { ''' % (fnHdr(field), field["Name"], param, retType) access = "data.get%s(%s%s)" % (fieldType(field), loc, endian_string()) if ("Offset" in field or "Scale" in field): ret += ' val valI : ' + fieldType(field) + ' = ' + access + '\n' access = getMath("valI", field, "Double") ret += ' val valD = ' + access + '\n' ret += ' return valD\n' else: ret += ' return %s\n' % (access) ret += '}' if MsgParser.fieldUnits(field) == "ASCII" and MsgParser.fieldCount( field) > 1 and (field["Type"] == "uint8" or field["Type"] == "int8"): ret += ''' %s fun get%sString(): String { var value = "" for (i in 0 until minOf(%s, header.getDataLength().toInt() - %s)) { val nextChar = get%s(i) if (nextChar == 0.toUByte()) { break } value += nextChar.toByte().toChar() } return value }''' % (fnHdr(field), field["Name"], str(MsgParser.fieldCount(field)), str(MsgParser.fieldLocation(field)), field["Name"]) return ret
def setFn(field): paramType = fieldType(field) valueString = setMath("value", field, "("+fieldType(field)+")", 'f') if "Offset" in field or "Scale" in field: paramType = typeForScaledInt(field) elif "Enum" in field and namespace == "": valueString = "("+paramType+")" + "(" + valueString + ")" paramType = namespace+field["Enum"] param = paramType + " value" loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", int idx" ret = '''\ %s %s %s(%s) { Set_%s(&m_data[%s], %s); }''' % (fnHdr(field), functionPrefix+"void", namespace+"Set"+field["Name"], params(firstParamDecl, param), fieldType(field), loc, valueString) if "float" in paramType or "double" in paramType: ret = "#ifndef DISABLE_FLOAT_ACCESSORS\n" + ret + "\n#endif\n" return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += "idx" if "Enum" in field: if param != "": param += ", " param += "enumAsInt=false" access = "(this.m_data.get%s(%s%s))" % (fieldType(field), loc, endian_string()) access = getMath(access, field, "") cleanup = "" if "Enum" in field: cleanup = reverseEnumLookup(field) ret = '''\ %s <MSGSHORTNAME>.prototype.Get%s = function(%s) { var value = %s; %sreturn value; };''' % (fnHdr(field), field["Name"], param, access, cleanup) if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): ret += ''' %s <MSGSHORTNAME>.prototype.Get%sString = function() { var value = ''; for(i=0; i<%s && i<this.hdr.GetDataLength()-%s; i++) { nextChar = String.fromCharCode(this.Get%s(i)); if(nextChar == '\\0') break; value += nextChar; } return value; };''' % (fnHdr(field), field["Name"], str(MsgParser.fieldCount(field)), str(MsgParser.fieldLocation(field)), field["Name"]) return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += "_ idx: Int" ret = '''\ %s public func Get%s(%s) -> %s { ''' % (fnHdr(field), field["Name"], param, paramType(field)) access = "m_data.GetField(offset: %s)" % (loc) if ("Offset" in field or "Scale" in field): ret += ' let valI : '+fieldType(field)+' = '+access+';\n' access = getMath("valI", field, "Double") ret += ' let valD = '+access+';\n' ret += ' return valD;\n' else: ret += ' return %s;\n' % (access) ret += '};' if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): ret += ''' %s public func Get%sString() -> String { var value = ""; for i in 0 ..< min(%s, hdr.GetDataLength()-%s) { let nextChar = Get%s(Int(i)); if(nextChar == 0) { break; } value += String(nextChar); } return value; };''' % (fnHdr(field), field["Name"], str(MsgParser.fieldCount(field)), str(MsgParser.fieldLocation(field)), field["Name"]) return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += "int idx" access = "Get_%s(&m_data[%s])" % (fieldType(field), loc) access = getMath(access, field, castForScaledInt(field), 'f') retType = fieldType(field) if "Offset" in field or "Scale" in field: retType = typeForScaledInt(field) elif "Enum" in field and namespace == "": retType = namespace+field["Enum"] access = retType + "(" + access + ")" ret = '''\ %s %s %s(%s)%s { return %s; }''' % (fnHdr(field), functionPrefix+retType, namespace+"Get"+field["Name"], params(firstParamDecl, param), const, access) if "float" in retType or "double" in retType: ret = "#ifndef DISABLE_FLOAT_ACCESSORS\n" + ret + "\n#endif\n" return ret
def getFn(msg, field): loc = str(1 + MsgParser.fieldLocation(field)) end_loc = str(1 + MsgParser.fieldLocation(field) + MsgParser.fieldSize(field) * MsgParser.fieldCount(field) - 1) param = "obj" access = "typecast(obj.m_data(%s:%s), '%s')" % (loc, end_loc, fieldType(field)) if MsgParser.big_endian: access = "swapbytes(%s)" % access access = getMath(access, field, typeForScaledInt(field)) retType = fieldType(field) if "Offset" in field or "Scale" in field: retType = typeForScaledInt(field) asInt = "" if "Enum" in field: asInt = "AsInt" ret = '''\ %s function ret = get.%s%s(%s) ret = %s; end ''' % (fnHdr(field), matlabFieldName(msg, field), asInt, param, access) if "Enum" in field: ret += '''\ %s function ret = get.%s(%s) ret = obj.%sAsInt; ''' % (fnHdr(field), matlabFieldName( msg, field), param, matlabFieldName(msg, field)) ret += " if isKey(obj." + field["Enum"] + "Enum, ret)\n" ret += " ret = obj." + field["Enum"] + "Enum(ret);\n" ret += " end\n" ret += "end\n" # Need to handle arrays of structs, where elements of array are not contiguous! if MsgParser.fieldSize(field) != MsgParser.fieldArrayElementOffset(field): ret = "ERROR! Need to handle arrays of structs, where elements of array are not contiguous!\n" + ret return ret
def setFn(field): paramType = fieldType(field) valueString = setMath("value", field, "(" + fieldType(field) + ")", 'f') if "Offset" in field or "Scale" in field: paramType = typeForScaledInt(field) elif "Enum" in field and namespace == "": valueString = "(" + paramType + ")" + "(" + valueString + ")" paramType = namespace + field["Enum"] param = paramType + " value" loc = str(MsgParser.fieldLocation(field)) if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += ", int idx" ret = '''\ %s %s %s(%s) { Set_%s(&m_data[%s], %s); }''' % (fnHdr(field), functionPrefix + "void", namespace + "Set" + field["Name"], params( firstParamDecl, param), fieldType(field), loc, valueString) if "float" in paramType or "double" in paramType: ret = "#ifndef DISABLE_FLOAT_ACCESSORS\n" + ret + "\n#endif\n" return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += "int idx" access = "Get_%s(&m_data[%s])" % (fieldType(field), loc) access = getMath(access, field, castForScaledInt(field), 'f') retType = fieldType(field) if "Offset" in field or "Scale" in field: retType = typeForScaledInt(field) elif "Enum" in field and namespace == "": retType = namespace + field["Enum"] access = retType + "(" + access + ")" ret = '''\ %s %s %s(%s)%s { return %s; }''' % (fnHdr(field), functionPrefix + retType, namespace + "Get" + field["Name"], params(firstParamDecl, param), const, access) if "float" in retType or "double" in retType: ret = "#ifndef DISABLE_FLOAT_ACCESSORS\n" + ret + "\n#endif\n" return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += "int idx" access = "m_data.get%s(%s)" % (fieldAccessorType(field), loc) if field["Type"].startswith("u"): access = fieldPromotionFn(field)+"("+access+")" access = "("+fieldType(field)+")"+access access = getMath(access, field, "("+typeForScaledInt(field)+")", 'f') retType = fieldType(field) if "Offset" in field or "Scale" in field: retType = typeForScaledInt(field) #elif "Enum" in field: # retType = field["Enum"] # access = retType + ".construct(" + access + ")" ret = '''\ %s public %s Get%s(%s) { return %s; }''' % (fnHdr(field), retType, field["Name"], param, access) return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += "int idx" access = "_data.get%s(%s%s)" % (fieldType(field), loc, endian_string()) access = getMath(access, field) retType = returnType(field, None) #elif "Enum" in field: # retType = field["Enum"] # access = retType + "(" + access + ")" ret = '''\ %s %s Get%s(%s) { return %s; }''' % (fnHdr(field), retType, field["Name"], param, access) if MsgParser.fieldUnits(field) == "ASCII" and (field["Type"] == "uint8" or field["Type"] == "int8"): ret += ''' %s String Get%sString() { final StringBuffer ret = new StringBuffer(); for(int i=0; i<%s && i<_hdr.GetDataLength()-%s; i++) { final String nextChar = new String.fromCharCode(Get%s(i)); if(nextChar == '\\0') break; ret.write(nextChar); } return ret.toString(); }''' % (fnHdr(field), field["Name"], str(MsgParser.fieldCount(field)), str(MsgParser.fieldLocation(field)), field["Name"]) return ret
def getFn(field): loc = str(MsgParser.fieldLocation(field)) param = "" if MsgParser.fieldCount(field) > 1: loc += "+idx*" + str(MsgParser.fieldArrayElementOffset(field)) param += "int idx" access = "m_data.get%s(%s)" % (fieldAccessorType(field), loc) if field["Type"].startswith("u"): access = fieldPromotionFn(field) + "(" + access + ")" access = "(" + fieldType(field) + ")" + access access = getMath(access, field, "(" + typeForScaledInt(field) + ")", 'f') retType = fieldType(field) if "Offset" in field or "Scale" in field: retType = typeForScaledInt(field) #elif "Enum" in field: # retType = field["Enum"] # access = retType + ".construct(" + access + ")" ret = '''\ %s public %s Get%s(%s) { return %s; }''' % (fnHdr(field), retType, field["Name"], param, access) return ret