Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
sguruswamy-more committed Jun 11, 2024
2 parents bd0d795 + 51980dd commit 293572f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
3 changes: 2 additions & 1 deletion cpp/examples/protobuf/dynamic_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <google/protobuf/dynamic_message.h>

#include "mcap/reader.hpp"
#include <memory>
#include <vector>

namespace gp = google::protobuf;
Expand Down Expand Up @@ -82,7 +83,7 @@ int main(int argc, char** argv) {
return 1;
}
}
gp::Message* message = protoFactory.GetPrototype(descriptor)->New();
auto message = std::unique_ptr<gp::Message>(protoFactory.GetPrototype(descriptor)->New());
if (!message->ParseFromArray(it->message.data, static_cast<int>(it->message.dataSize))) {
std::cerr << "failed to parse message using included foxglove.PointCloud schema" << std::endl;
reader.close();
Expand Down
1 change: 0 additions & 1 deletion cpp/examples/protobuf/writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ int main(int argc, char** argv) {
if (!res.ok()) {
std::cerr << "Failed to write message: " << res.message << "\n";
writer.terminate();
writer.close();
std::ignore = std::remove(outputFilename);
return 1;
}
Expand Down
13 changes: 4 additions & 9 deletions go/mcap/indexed_message_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,8 @@ func (it *indexedMessageIterator) parseSummarySection() error {
return fmt.Errorf("failed to parse attachment index: %w", err)
}
// if the chunk overlaps with the requested parameters, load it
for _, channel := range it.channels.Slice() {
if channel != nil && idx.MessageIndexOffsets[channel.ID] > 0 {
if (it.end == 0 && it.start == 0) || (idx.MessageStartTime < it.end && idx.MessageEndTime >= it.start) {
it.chunkIndexes = append(it.chunkIndexes, idx)
}
break
}
if (it.end == 0 && it.start == 0) || (idx.MessageStartTime < it.end && idx.MessageEndTime >= it.start) {
it.chunkIndexes = append(it.chunkIndexes, idx)
}
case TokenStatistics:
stats, err := ParseStatistics(record)
Expand Down Expand Up @@ -200,8 +195,8 @@ func (it *indexedMessageIterator) loadChunk(chunkIndex *ChunkIndex) error {

compressedChunkLength := chunkIndex.ChunkLength
if uint64(cap(it.recordBuf)) < compressedChunkLength {
newSize := int(float64(compressedChunkLength) * chunkBufferGrowthMultiple)
it.recordBuf = make([]byte, newSize)
newCapacity := int(float64(compressedChunkLength) * chunkBufferGrowthMultiple)
it.recordBuf = make([]byte, compressedChunkLength, newCapacity)
} else {
it.recordBuf = it.recordBuf[:compressedChunkLength]
}
Expand Down
2 changes: 1 addition & 1 deletion go/mcap/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mcap

// Version of the MCAP library.
var Version = "v1.4.0"
var Version = "v1.4.1"
10 changes: 8 additions & 2 deletions website/docs/guides/cpp/protobuf.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ We also include the MCAP reader implementation:
#include "mcap/reader.hpp"
```

And standard library dependencies:

```cpp
#include <memory>
```

Use the `mcap::McapReader::open()` method to open an MCAP file for reading:

```cpp
Expand Down Expand Up @@ -103,7 +109,7 @@ auto messageView = reader.readMessages();

#### Load schema definitions

We build a `DynamicMessageFactory`, using a `google::Protobuf::SimpleDescriptorDatabase` as the underlying descriptor database. By constructing this ourselves and retaining a reference to the database, we can more easily load that database with definitions from the MCAP file.
We build a `DynamicMessageFactory`, using a `google::protobuf::SimpleDescriptorDatabase` as the underlying descriptor database. By constructing this ourselves and retaining a reference to the database, we can more easily load that database with definitions from the MCAP file.

```cpp
gp::SimpleDescriptorDatabase protoDb;
Expand Down Expand Up @@ -157,7 +163,7 @@ descriptor = protoPool.FindMessageTypeByName(it->schema->name);
We can use this descriptor to parse our message:

```cpp
gp::Message* message = protoFactory.GetPrototype(descriptor)->New();
auto message = std::unique_ptr<gp::Message>(protoFactory.GetPrototype(descriptor)->New());
if (!message->ParseFromArray(static_cast<const void*>(it->message.data),
it->message.dataSize)) {
std::cerr << "failed to parse message using included schema" << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion website/docs/spec/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Schema `encoding` may only be omitted for self-describing message encodings such

- `name`: Fully qualified name to the message within the descriptor set. For example, in a proto file containing `package foo.bar; message Baz {}` the fully qualified message name is `foo.bar.Baz`.
- `encoding`: `protobuf`
- `data`: A binary [FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto) as produced by `protoc --descriptor_set_out`.
- `data`: A binary [FileDescriptorSet](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto) as produced by `protoc --include_imports --descriptor_set_out`.

### flatbuffer

Expand Down

0 comments on commit 293572f

Please sign in to comment.