Skip to content

Commit

Permalink
Cyber: Simple code clean for record wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxq committed Nov 7, 2019
1 parent da65566 commit 8a27df0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
9 changes: 0 additions & 9 deletions cyber/py_wrapper/py_record.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
#include "cyber/record/record_reader.h"
#include "cyber/record/record_writer.h"

using ::apollo::cyber::proto::Header;
using ::apollo::cyber::record::RecordFileWriter;
using ::apollo::cyber::record::RecordReader;

namespace apollo {
namespace cyber {
namespace record {
Expand All @@ -55,7 +51,6 @@ class PyRecordReader {
explicit PyRecordReader(const std::string& file) {
record_reader_.reset(new RecordReader(file));
}
~PyRecordReader() {}

BagMessage ReadMessage(uint64_t begin_time = 0,
uint64_t end_time = UINT64_MAX) {
Expand Down Expand Up @@ -105,10 +100,6 @@ class PyRecordReader {

class PyRecordWriter {
public:
PyRecordWriter() {}

~PyRecordWriter() {}

bool Open(const std::string& path) { return record_writer_.Open(path); }

void Close() { record_writer_.Close(); }
Expand Down
6 changes: 3 additions & 3 deletions cyber/python/cyber_py/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def __del__(self):
#
# @param path the file path.
#
# @return Success is Ture, other False.
# @return Success is True, other False.
def open(self, path):
return _CYBER_RECORD.PyRecordWriter_Open(self.record_writer, path)

Expand All @@ -168,7 +168,7 @@ def close(self):
# @param type_name a string of message type name.
# @param proto_desc the message descriptor.
#
# @return Success is Ture, other False.
# @return Success is True, other False.
def write_channel(self, channel_name, type_name, proto_desc):
"""
Writer channel by channelname,typename,protodesc
Expand All @@ -184,7 +184,7 @@ def write_channel(self, channel_name, type_name, proto_desc):
# @param time message time.
# @param raw the flag implies data whether or not a rawdata.
#
# @return Success is Ture, other False.
# @return Success is True, other False.
def write_message(self, channel_name, data, time, raw=True):
"""
Writer msg:channelname,rawmsg,writer time
Expand Down
6 changes: 3 additions & 3 deletions cyber/python/cyber_py/record_py3.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __del__(self):
#
# @param path the file path.
#
# @return Success is Ture, other False.
# @return Success is True, other False.
def open(self, path):
return _CYBER_RECORD.PyRecordWriter_Open(self.record_writer, path)

Expand All @@ -171,7 +171,7 @@ def close(self):
# @param type_name a string of message type name.
# @param proto_desc the message descriptor.
#
# @return Success is Ture, other False.
# @return Success is True, other False.
def write_channel(self, channel_name, type_name, proto_desc):
"""
Writer channel by channelname,typename,protodesc
Expand All @@ -187,7 +187,7 @@ def write_channel(self, channel_name, type_name, proto_desc):
# @param time message time.
# @param raw the flag implies data whether or not a rawdata.
#
# @return Success is Ture, other False.
# @return Success is True, other False.
def write_message(self, channel_name, data, time, raw=True):
"""
Writer msg:channelname,rawmsg,writer time
Expand Down
11 changes: 6 additions & 5 deletions cyber/python/test/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
TEST_RECORD_FILE = "/tmp/test02.record"
CHAN_1 = "channel/chatter"
MSG_TYPE = "apollo.common.util.test.SimpleMessage"
STR_10B = "1234567890"
PROTO_DESC = "1234567890"
MSG_DATA = "0123456789"
TIME = 999


Expand All @@ -50,12 +51,12 @@ def test_record_writer_read(self):
fwriter.set_intervaltime_fileseg(0)

self.assertTrue(fwriter.open(TEST_RECORD_FILE))
fwriter.write_channel(CHAN_1, MSG_TYPE, STR_10B)
fwriter.write_message(CHAN_1, STR_10B, TIME)
fwriter.write_channel(CHAN_1, MSG_TYPE, PROTO_DESC)
fwriter.write_message(CHAN_1, MSG_DATA, TIME)

self.assertEqual(1, fwriter.get_messagenumber(CHAN_1))
self.assertEqual(MSG_TYPE, fwriter.get_messagetype(CHAN_1))
self.assertEqual(STR_10B, fwriter.get_protodesc(CHAN_1))
self.assertEqual(PROTO_DESC, fwriter.get_protodesc(CHAN_1))
fwriter.close()

# reader
Expand All @@ -74,7 +75,7 @@ def test_record_writer_read(self):

for channelname, msg, datatype, timestamp in fread.read_messages():
self.assertEqual(CHAN_1, channelname)
self.assertEqual(STR_10B, msg)
self.assertEqual(MSG_DATA, msg)
self.assertEqual(TIME, timestamp)
self.assertEqual(1, fread.get_messagenumber(channelname))
self.assertEqual(MSG_TYPE, datatype)
Expand Down

0 comments on commit 8a27df0

Please sign in to comment.