Skip to content

Commit

Permalink
Fix a test bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
braxtonmckee committed Nov 21, 2022
1 parent 533f146 commit 888662f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 32 deletions.
33 changes: 7 additions & 26 deletions typed_python/TupleOrListOfType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,6 @@ class TupleOrListOfType : public Type {
int64=5,
};

/* if (count > 2 && ptr[2] - ptr[1] == ptr[1] - ptr[0]) {
long sep = ptr[1] - ptr[0];
long topPt = 3;
while (topPt < count && topPt < 256 && ptr[topPt] - ptr[topPt - 1] == sep) {
topPt++;
}
buffer.write<uint8_t>(kind::sequence);
buffer.write<uint8_t>(topPt);
buffer.write<in64_t>(ptr[0]);
buffer.write<in64_t>(ptr[1]);
count -= topPt;
ptr += topPt;
} else */

// try to serialize a block of integers that fit into the limits of "T"
template<class buf_t, class T>
bool trySerializeIntListBlock(int64_t* &ptr, size_t &count, buf_t& buffer, int_block_type blockType, T* nullPtr) {
Expand Down Expand Up @@ -435,7 +419,6 @@ class TupleOrListOfType : public Type {
buffer.writeBeginCompound(fieldNumber);
}


if (ct && m_element_type->isPOD() && buffer.getContext().serializePodListsInline()) {
if (m_element_type->getTypeCategory() == TypeCategory::catInt64) {
buffer.writeUnsignedVarintObject(1, ct);
Expand All @@ -456,15 +439,13 @@ class TupleOrListOfType : public Type {
} else {
buffer.writeUnsignedVarintObject(0, ct);

m_element_type->check([&](auto& concrete_type) {
concrete_type.serializeMulti(
this->eltPtr(self, 0),
ct,
m_element_type->bytecount(),
buffer,
0
);
});
m_element_type->serializeMulti(
this->eltPtr(self, 0),
ct,
m_element_type->bytecount(),
buffer,
0
);
}

buffer.writeEndCompound();
Expand Down
5 changes: 3 additions & 2 deletions typed_python/WireType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#pragma once

#include <stdexcept>
#include "Format.hpp"

//every message in our serialization format starts with a 3-bit wire type
//plus a field-number or a count (shifted by 3 bits) encoded as a varint.
Expand All @@ -36,12 +37,12 @@ class WireType {

inline void assertWireTypesEqual(size_t found, size_t expected) {
if (found != expected) {
throw std::runtime_error("Invalid wire type encountered.");
throw std::runtime_error("Invalid wire type encountered: " + format(found) + " != " + format(expected));
}
}

inline void assertNonemptyCompoundWireType(size_t found) {
if (found != WireType::BEGIN_COMPOUND && found != WireType::SINGLE) {
throw std::runtime_error("Invalid wire type encountered.");
throw std::runtime_error("Invalid wire type encountered: " + format(found) + " != 6 or 5");
}
}
3 changes: 2 additions & 1 deletion typed_python/_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,8 @@ PyObject *decodeSerializedObject(PyObject* nullValue, PyObject* args) {
PyList_Append(result, tup);
}
}
throw std::runtime_error("Invalid wire type encountered.");

throw std::runtime_error("Invalid wire type encountered: " + format(wireType));
};

return translateExceptionToPyObject([&](){
Expand Down
9 changes: 6 additions & 3 deletions typed_python/types_serialization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,15 @@ def check_idempotence(self, obj, ser_ctx=None):

def test_serialize_lists_with_compression(self):
def check_idempotence(x):
s = SerializationContext().withSerializePodListsInline()
s1 = SerializationContext().withoutCompression()
s2 = SerializationContext().withoutCompression().withSerializePodListsInline()

assert x == s.deserialize(s.serialize(x))
assert x == s1.deserialize(s1.serialize(x))
assert x == s2.deserialize(s2.serialize(x))

# make sure its a valid 'encoded serialized object'
assert decodeSerializedObject(s.serialize(x))
assert decodeSerializedObject(s1.serialize(x))
assert decodeSerializedObject(s2.serialize(x))

check_idempotence(ListOf(int)([1, 2, 3]))
check_idempotence(ListOf(int)([1, 2, 3] * 1000))
Expand Down

0 comments on commit 888662f

Please sign in to comment.