Skip to content

Commit

Permalink
Replace vector by span
Browse files Browse the repository at this point in the history
  • Loading branch information
uweseimet committed Sep 7, 2023
1 parent 72dd272 commit 1969055
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cpp/piscsi/piscsi_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ PbCommand PiscsiService::ReadCommand(CommandContext& context) const
PbCommand command;

// Read magic string
vector<byte> magic(6);
array<byte, 6> magic;
const size_t bytes_read = context.GetSerializer().ReadBytes(fd, magic);
if (!bytes_read) {
return command;
Expand Down
6 changes: 3 additions & 3 deletions cpp/shared/protobuf_serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
// Copyright (C) 2022-2023 Uwe Seimet
//
//---------------------------------------------------------------------------

Expand Down Expand Up @@ -42,7 +42,7 @@ void ProtobufSerializer::SerializeMessage(int fd, const google::protobuf::Messag
void ProtobufSerializer::DeserializeMessage(int fd, google::protobuf::Message& message) const
{
// Read the header with the size of the protobuf data
vector<byte> header_buf(4);
array<byte, 4> header_buf;
if (ReadBytes(fd, header_buf) < header_buf.size()) {
throw io_exception("Invalid protobuf message header");
}
Expand All @@ -64,7 +64,7 @@ void ProtobufSerializer::DeserializeMessage(int fd, google::protobuf::Message& m
message.ParseFromString(data);
}

size_t ProtobufSerializer::ReadBytes(int fd, vector<byte>& buf) const
size_t ProtobufSerializer::ReadBytes(int fd, span<byte> buf) const
{
size_t offset = 0;
while (offset < buf.size()) {
Expand Down
6 changes: 3 additions & 3 deletions cpp/shared/protobuf_serializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// SCSI Target Emulator PiSCSI
// for Raspberry Pi
//
// Copyright (C) 2022 Uwe Seimet
// Copyright (C) 2022-2023 Uwe Seimet
//
// Helper for serializing/deserializing protobuf messages
//
Expand All @@ -12,7 +12,7 @@
#pragma once

#include "google/protobuf/message.h"
#include <vector>
#include <span>

using namespace std;

Expand All @@ -25,5 +25,5 @@ class ProtobufSerializer

void SerializeMessage(int, const google::protobuf::Message&) const;
void DeserializeMessage(int, google::protobuf::Message&) const;
size_t ReadBytes(int, vector<byte>&) const;
size_t ReadBytes(int, span<byte>) const;
};

0 comments on commit 1969055

Please sign in to comment.