Skip to content

Commit 888662f

Browse files
committed
Fix a test bug.
1 parent 533f146 commit 888662f

File tree

4 files changed

+18
-32
lines changed

4 files changed

+18
-32
lines changed

typed_python/TupleOrListOfType.hpp

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,6 @@ class TupleOrListOfType : public Type {
297297
int64=5,
298298
};
299299

300-
/* if (count > 2 && ptr[2] - ptr[1] == ptr[1] - ptr[0]) {
301-
long sep = ptr[1] - ptr[0];
302-
long topPt = 3;
303-
while (topPt < count && topPt < 256 && ptr[topPt] - ptr[topPt - 1] == sep) {
304-
topPt++;
305-
}
306-
307-
buffer.write<uint8_t>(kind::sequence);
308-
buffer.write<uint8_t>(topPt);
309-
buffer.write<in64_t>(ptr[0]);
310-
buffer.write<in64_t>(ptr[1]);
311-
312-
count -= topPt;
313-
ptr += topPt;
314-
} else */
315-
316300
// try to serialize a block of integers that fit into the limits of "T"
317301
template<class buf_t, class T>
318302
bool trySerializeIntListBlock(int64_t* &ptr, size_t &count, buf_t& buffer, int_block_type blockType, T* nullPtr) {
@@ -435,7 +419,6 @@ class TupleOrListOfType : public Type {
435419
buffer.writeBeginCompound(fieldNumber);
436420
}
437421

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

459-
m_element_type->check([&](auto& concrete_type) {
460-
concrete_type.serializeMulti(
461-
this->eltPtr(self, 0),
462-
ct,
463-
m_element_type->bytecount(),
464-
buffer,
465-
0
466-
);
467-
});
442+
m_element_type->serializeMulti(
443+
this->eltPtr(self, 0),
444+
ct,
445+
m_element_type->bytecount(),
446+
buffer,
447+
0
448+
);
468449
}
469450

470451
buffer.writeEndCompound();

typed_python/WireType.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#pragma once
1818

1919
#include <stdexcept>
20+
#include "Format.hpp"
2021

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

3738
inline void assertWireTypesEqual(size_t found, size_t expected) {
3839
if (found != expected) {
39-
throw std::runtime_error("Invalid wire type encountered.");
40+
throw std::runtime_error("Invalid wire type encountered: " + format(found) + " != " + format(expected));
4041
}
4142
}
4243

4344
inline void assertNonemptyCompoundWireType(size_t found) {
4445
if (found != WireType::BEGIN_COMPOUND && found != WireType::SINGLE) {
45-
throw std::runtime_error("Invalid wire type encountered.");
46+
throw std::runtime_error("Invalid wire type encountered: " + format(found) + " != 6 or 5");
4647
}
4748
}

typed_python/_types.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2266,7 +2266,8 @@ PyObject *decodeSerializedObject(PyObject* nullValue, PyObject* args) {
22662266
PyList_Append(result, tup);
22672267
}
22682268
}
2269-
throw std::runtime_error("Invalid wire type encountered.");
2269+
2270+
throw std::runtime_error("Invalid wire type encountered: " + format(wireType));
22702271
};
22712272

22722273
return translateExceptionToPyObject([&](){

typed_python/types_serialization_test.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,15 @@ def check_idempotence(self, obj, ser_ctx=None):
352352

353353
def test_serialize_lists_with_compression(self):
354354
def check_idempotence(x):
355-
s = SerializationContext().withSerializePodListsInline()
355+
s1 = SerializationContext().withoutCompression()
356+
s2 = SerializationContext().withoutCompression().withSerializePodListsInline()
356357

357-
assert x == s.deserialize(s.serialize(x))
358+
assert x == s1.deserialize(s1.serialize(x))
359+
assert x == s2.deserialize(s2.serialize(x))
358360

359361
# make sure its a valid 'encoded serialized object'
360-
assert decodeSerializedObject(s.serialize(x))
362+
assert decodeSerializedObject(s1.serialize(x))
363+
assert decodeSerializedObject(s2.serialize(x))
361364

362365
check_idempotence(ListOf(int)([1, 2, 3]))
363366
check_idempotence(ListOf(int)([1, 2, 3] * 1000))

0 commit comments

Comments
 (0)