/// <summary> /// Creates deserializer for the specified data type. /// </summary> /// <param name="dataType">Type of the data.</param> /// <returns>Serializer code for base types</returns> private string GenerateDeserializerDefinition(XerusBaseType dataType, string serializerName) { string name = dataType.GetType().XerusTypeName(TargetLanguage.Cpp); var tb = new TextBuilder(); tb.AppendLine(string.Format( @"/** Deserializer for data type {0} * @param data Buffer with the serialized data * @return Deserialized data type */", name)); tb.AppendLine("uint16 " + serializerName + "::Bytes_To_{0}(const uint8 *const data, {0}& output)", name); tb.AppendLine("{"); tb.PushIndent(); var languageSpecificTypeDefinition = dataType.GetType().TypeDefinition(TargetLanguage.Cpp); tb.AppendLine("output = ( *((const {0}*)(data)) );", name); tb.AppendLine("return {0};", languageSpecificTypeDefinition.NumberOfBytes); tb.PopIndent(); tb.AppendLine("}"); return(tb.ToString()); }
/// <summary> /// Creates deserializer for the specified data type. /// </summary> /// <param name="dataType">Type of the data.</param> /// <returns>Serializer code for base types</returns> private string GenerateDeserializerSignature(XerusBaseType dataType) { string name = dataType.GetType().XerusTypeName(TargetLanguage.Cpp); var tb = new TextBuilder(); tb.AppendLine(string.Format(@"/** Deserializer for data type {0} * @param data Buffer with the serialized data * @param output Data type * @return Length of the data in bytes */", name)); tb.AppendLine("static uint16 Bytes_To_{0}(const uint8 *const data, {0}& output);", name); return(tb.ToString()); }
/// <summary> /// Creates serializer for the specified data type. /// </summary> /// <param name="dataType">Type of the data.</param> /// <returns>Serializer code for base types</returns> private string GenerateSerializerDefinition(XerusBaseType dataType, string serializerName) { string name = dataType.GetType().XerusTypeName(TargetLanguage.Cpp); var tb = new TextBuilder(); tb.AppendLine(string.Format( @"/** Serializer for data type {0} * @param input Data type * @param data Buffer for the serialized data * @return Length of the serialized data in bytes */", name)); tb.AppendLine("uint16 " + serializerName + "::{0}_To_Bytes(const {0} input, uint8 *const data)", name); tb.AppendLine("{"); tb.PushIndent(); var languageSpecificTypeDefinition = dataType.GetType().TypeDefinition(TargetLanguage.Cpp); tb.AppendLine("*(({0}*)(data)) = input;", name); tb.AppendLine("return {0};", languageSpecificTypeDefinition.NumberOfBytes); tb.PopIndent(); tb.AppendLine("}"); return(tb.ToString()); }