Skip to content

Commit

Permalink
Merge pull request #184 from pigwing/master
Browse files Browse the repository at this point in the history
修复meta.size获取错误长度问题
  • Loading branch information
maikebing authored Mar 28, 2022
2 parents 2fe8466 + 9f94ef8 commit 3ea6d64
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/IoTSharp.Data.Taos/Driver/TDengineDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,28 @@ static public IntPtr Query(IntPtr conn, string command)

public static List<TDengineMeta> FetchFields(IntPtr res)
{
// const int fieldSize = 68;

List<TDengineMeta> metas = new List<TDengineMeta>();
if (res == IntPtr.Zero)
{
return metas;
}

int fieldCount = FieldCount(res);
IntPtr fieldsPtr = taos_fetch_fields(res);

for (int i = 0; i < fieldCount; ++i)
{
int offset = i * (int)TaosField.STRUCT_SIZE;
#if NET45
taosField field = (taosField)Marshal.PtrToStructure(fieldsPtr + offset,typeof(taosField));
#else
taosField field = Marshal.PtrToStructure<taosField>(fieldsPtr + offset);
#endif
TDengineMeta meta = new TDengineMeta() { name = Encoding.Default.GetString(field.name)?.TrimEnd('\0'), size = field.bytes, type = field.type };
TDengineMeta meta = new TDengineMeta();
meta.name = Marshal.PtrToStringAnsi(fieldsPtr + offset);
meta.type = Marshal.ReadByte(fieldsPtr + offset + (int)TaosField.TYPE_OFFSET);
meta.size = Marshal.ReadInt16(fieldsPtr + offset + (int)TaosField.BYTES_OFFSET);
metas.Add(meta);
}


return metas;
}

Expand Down

0 comments on commit 3ea6d64

Please sign in to comment.