summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-serialize-types.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2021-10-04 14:15:51 -0400
committerGitHub <noreply@github.com>2021-10-04 14:15:51 -0400
commit97bb82ebcdf8f1391b9d93b5a8d7b1dfc4e88e52 (patch)
treef120ba282cbea96d23ed179737984a4610d3b520 /source/slang/slang-serialize-types.cpp
parentb3dfe383c6d31ff3dbd76dcfb32de8d536382f3e (diff)
Removing exceptions from core/compiler-core (#1953)
* #include an absolute path didn't work - because paths were taken to always be relative. * Refactor Stream. Working on all tests. * Split out CharEncode. * Make method names lower camel. m_prefix in Writer/Reader * Tidy up around CharEncode interface. * Small improvements around encode/decode. * Better use of types. * Remove readLine from TextReader. * Remove exceptions from Stream/Text handling. * Fix some typos. * Fix tabbing. * Fix missing override. * Remove remaining exception throw/catch via using signal mechanism. * Remove exceptions that are not used anymore. * Document the Stream interface. * Remove index for decoding 'get byte' function. * Fix CharReader -> ByteReader.
Diffstat (limited to 'source/slang/slang-serialize-types.cpp')
-rw-r--r--source/slang/slang-serialize-types.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/source/slang/slang-serialize-types.cpp b/source/slang/slang-serialize-types.cpp
index fc839afc1..6c4512b1d 100644
--- a/source/slang/slang-serialize-types.cpp
+++ b/source/slang/slang-serialize-types.cpp
@@ -14,10 +14,10 @@ namespace Slang {
namespace { // anonymous
-struct CharReader
+struct ByteReader
{
- char operator()(int pos) const { SLANG_UNUSED(pos); return *m_pos++; }
- CharReader(const char* pos) :m_pos(pos) {}
+ Byte operator()() const { return Byte(*m_pos++); }
+ ByteReader(const char* pos) :m_pos(pos) {}
mutable const char* m_pos;
};
@@ -37,11 +37,15 @@ struct CharReader
stringTable.clear();
for (const auto& slice : slices)
{
+ // TODO(JS):
+ // This is a bit of a hack. We need to store the string length, along with the string contents. We don't want to write
+ // the size as (say) uint32, because most strings are short. So we just save off the length as a utf8 encoding.
+ // As it stands this *does* have an arguable problem because encoding isn't of the full 32 bits.
const int len = int(slice.getLength());
// We need to write into the the string array
char prefixBytes[6];
- const int numPrefixBytes = EncodeUnicodePointToUTF8(prefixBytes, len);
+ const int numPrefixBytes = encodeUnicodePointToUTF8(len, prefixBytes);
const Index baseIndex = stringTable.getCount();
stringTable.setCount(baseIndex + numPrefixBytes + len);
@@ -61,8 +65,8 @@ struct CharReader
while (cur < end)
{
- CharReader reader(cur);
- const int len = GetUnicodePointFromUTF8(reader);
+ ByteReader reader(cur);
+ const int len = getUnicodePointFromUTF8(reader);
slicesOut.add(UnownedStringSlice(reader.m_pos, len));
cur = reader.m_pos + len;
}
@@ -87,8 +91,8 @@ struct CharReader
while (cur < end)
{
- CharReader reader(cur);
- const int len = GetUnicodePointFromUTF8(reader);
+ ByteReader reader(cur);
+ const int len = getUnicodePointFromUTF8(reader);
outPool.add(UnownedStringSlice(reader.m_pos, len));
cur = reader.m_pos + len;
}