Skip to content

Commit 9d8e6be

Browse files
committed
Fix issues with text strings in binary format
1 parent a10bdab commit 9d8e6be

3 files changed

Lines changed: 19 additions & 4 deletions

File tree

Source/Plugins/BinaryWriter/NpyFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ String NpyType::getTypeString() const
105105
switch (type)
106106
{
107107
case BaseType::CHAR:
108-
return "U" + String(length);
108+
return "S" + String(length + 1); //account for the null separator
109109
case BaseType::INT8:
110110
return "<i1";
111111
case BaseType::UINT8:

Source/Processors/Channel/MetaData.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ MetaDataDescriptor& MetaDataDescriptor::operator=(const MetaDataDescriptor& othe
7171

7272
MetaDataDescriptor::MetaDataTypes MetaDataDescriptor::getType() const { return m_type; }
7373
unsigned int MetaDataDescriptor::getLength() const { return m_length; }
74-
size_t MetaDataDescriptor::getDataSize() const { return m_length*getTypeSize(m_type); }
74+
size_t MetaDataDescriptor::getDataSize() const
75+
{
76+
if (m_type == CHAR)
77+
return m_length*getTypeSize(m_type) + 1; //account for the null-rerminator
78+
else
79+
return m_length*getTypeSize(m_type);
80+
}
7581
String MetaDataDescriptor::getName() const { return m_name; }
7682
String MetaDataDescriptor::getDescription() const { return m_description; }
7783
String MetaDataDescriptor::getIdentifier() const { return m_identifier; }
@@ -120,14 +126,14 @@ size_t MetaDataDescriptor::getTypeSize(MetaDataDescriptor::MetaDataTypes type)
120126

121127
//This would be so much easier if VS2012 supported delegating constructors...
122128
MetaDataValue::MetaDataValue(MetaDataDescriptor::MetaDataTypes t, unsigned int length, const void* d)
123-
: m_type(t), m_length(length), m_size(length*MetaDataDescriptor::getTypeSize(t))
129+
: m_type(t), m_length(length), m_size(getSize(t, length))
124130
{
125131
allocSpace();
126132
setValue(d);
127133
}
128134

129135
MetaDataValue::MetaDataValue(MetaDataDescriptor::MetaDataTypes t, unsigned int length)
130-
: m_type(t), m_length(length), m_size(length*MetaDataDescriptor::getTypeSize(t))
136+
: m_type(t), m_length(length), m_size(getSize(t, length))
131137
{
132138
allocSpace();
133139
}
@@ -175,6 +181,14 @@ void MetaDataValue::allocSpace()
175181
m_data.calloc(m_size);
176182
}
177183

184+
size_t MetaDataValue::getSize(MetaDataDescriptor::MetaDataTypes type, unsigned int length)
185+
{
186+
if (type == MetaDataDescriptor::CHAR)
187+
return length*MetaDataDescriptor::getTypeSize(type) + 1; //account for the null-rerminator
188+
else
189+
return length*MetaDataDescriptor::getTypeSize(type);
190+
}
191+
178192
MetaDataValue::MetaDataValue(const MetaDataValue& v)
179193
: ReferenceCountedObject(),
180194
m_type(v.m_type), m_length(v.m_length), m_size(v.m_size)

Source/Processors/Channel/MetaData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class PLUGIN_API MetaDataValue
162162
MetaDataValue() = delete;
163163
void setValue(const void* data);
164164
void allocSpace();
165+
static size_t getSize(MetaDataDescriptor::MetaDataTypes type, unsigned int length);
165166
HeapBlock<char> m_data;
166167
MetaDataDescriptor::MetaDataTypes m_type;
167168
unsigned int m_length;

0 commit comments

Comments
 (0)