Skip to content

Commit b5abcb8

Browse files
committed
fmt
1 parent 1e337c4 commit b5abcb8

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/iceberg/expression/literal.cc

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class LiteralSerializer {
3838

3939
/// \brief Deserialize binary data to a literal value.
4040
static Result<Literal> FromBytes(std::span<const uint8_t> data,
41-
std::shared_ptr<PrimitiveType> type);
41+
const std::shared_ptr<PrimitiveType>& type);
4242
};
4343

4444
/// \brief LiteralCaster handles type casting operations for Literal.
@@ -501,7 +501,7 @@ Result<std::vector<uint8_t>> LiteralSerializer::ToBytes(const Literal& literal)
501501
}
502502

503503
Result<Literal> LiteralSerializer::FromBytes(std::span<const uint8_t> data,
504-
std::shared_ptr<PrimitiveType> type) {
504+
const std::shared_ptr<PrimitiveType>& type) {
505505
if (!type) {
506506
return InvalidArgument("Type cannot be null");
507507
}
@@ -515,17 +515,28 @@ Result<Literal> LiteralSerializer::FromBytes(std::span<const uint8_t> data,
515515

516516
switch (type_id) {
517517
case TypeId::kBoolean: {
518+
if (data.size() != 1) {
519+
return InvalidArgument("Boolean requires 1 byte, got {}", data.size());
520+
}
518521
ICEBERG_ASSIGN_OR_RAISE(auto value, util::ReadLittleEndian<uint8_t>(data));
519522
// 0x00 for false, non-zero byte for true
520523
return Literal::Boolean(value != 0x00);
521524
}
522525

523526
case TypeId::kInt: {
527+
if (data.size() != sizeof(int32_t)) {
528+
return InvalidArgument("Int requires {} bytes, got {}", sizeof(int32_t),
529+
data.size());
530+
}
524531
ICEBERG_ASSIGN_OR_RAISE(auto value, util::ReadLittleEndian<int32_t>(data));
525532
return Literal::Int(value);
526533
}
527534

528535
case TypeId::kDate: {
536+
if (data.size() != sizeof(int32_t)) {
537+
return InvalidArgument("Date requires {} bytes, got {}", sizeof(int32_t),
538+
data.size());
539+
}
529540
ICEBERG_ASSIGN_OR_RAISE(auto value, util::ReadLittleEndian<int32_t>(data));
530541
return Literal::Date(value);
531542
}
@@ -566,6 +577,10 @@ Result<Literal> LiteralSerializer::FromBytes(std::span<const uint8_t> data,
566577
}
567578

568579
case TypeId::kFloat: {
580+
if (data.size() != sizeof(float)) {
581+
return InvalidArgument("Float requires {} bytes, got {}", sizeof(float),
582+
data.size());
583+
}
569584
ICEBERG_ASSIGN_OR_RAISE(auto value, util::ReadLittleEndian<float>(data));
570585
return Literal::Float(value);
571586
}
@@ -605,6 +620,9 @@ Result<Literal> LiteralSerializer::FromBytes(std::span<const uint8_t> data,
605620
}
606621

607622
case TypeId::kUuid: {
623+
if (data.size() != 16) {
624+
return InvalidArgument("UUID requires 16 bytes, got {}", data.size());
625+
}
608626
ICEBERG_ASSIGN_OR_RAISE(auto uuid_value, util::ReadBigEndian16(data));
609627
return Literal(Literal::Value{uuid_value}, type);
610628
}

0 commit comments

Comments
 (0)