Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect specification of directory contents in read dir resp [AP-945] #1379

Merged
merged 2 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions c/include/libsbp/legacy/file_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ typedef struct SBP_ATTR_PACKED {
*/

typedef struct SBP_ATTR_PACKED {
u32 sequence; /**< Read sequence number */
u8 contents[0]; /**< Contents of read directory */
u32 sequence; /**< Read sequence number */
char contents[0]; /**< Contents of read directory */
} msg_fileio_read_dir_resp_t;

/** Delete a file from the file system (host => device)
Expand Down
Binary file modified docs/sbp.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion haskell/sbp.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sbp
version: 5.0.3-alpha
version: 5.0.4-alpha
synopsis: SwiftNav's SBP Library
homepage: https://github.com/swift-nav/libsbp
license: MIT
Expand Down
6 changes: 3 additions & 3 deletions haskell/src/SwiftNav/SBP/FileIo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,19 @@ msgFileioReadDirResp = 0x00AA
data MsgFileioReadDirResp = MsgFileioReadDirResp
{ _msgFileioReadDirResp_sequence :: !Word32
-- ^ Read sequence number
, _msgFileioReadDirResp_contents :: ![Word8]
, _msgFileioReadDirResp_contents :: !Text
-- ^ Contents of read directory
} deriving ( Show, Read, Eq )

instance Binary MsgFileioReadDirResp where
get = do
_msgFileioReadDirResp_sequence <- getWord32le
_msgFileioReadDirResp_contents <- whileM (not <$> isEmpty) getWord8
_msgFileioReadDirResp_contents <- decodeUtf8 . toStrict <$> getRemainingLazyByteString
pure MsgFileioReadDirResp {..}

put MsgFileioReadDirResp {..} = do
putWord32le _msgFileioReadDirResp_sequence
mapM_ putWord8 _msgFileioReadDirResp_contents
putByteString $ encodeUtf8 _msgFileioReadDirResp_contents

$(makeSBP 'msgFileioReadDirResp ''MsgFileioReadDirResp)
$(makeJSON "_msgFileioReadDirResp_" ''MsgFileioReadDirResp)
Expand Down
9 changes: 4 additions & 5 deletions java/src/com/swiftnav/sbp/file_io/MsgFileioReadDirResp.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import com.swiftnav.sbp.SBPBinaryException;
import com.swiftnav.sbp.SBPMessage;
import org.json.JSONArray;
import org.json.JSONObject;

/**
Expand All @@ -37,7 +36,7 @@ public class MsgFileioReadDirResp extends SBPMessage {
public long sequence;

/** Contents of read directory */
public int[] contents;
public String contents;

public MsgFileioReadDirResp(int sender) {
super(sender, TYPE);
Expand All @@ -58,20 +57,20 @@ public MsgFileioReadDirResp(SBPMessage msg) throws SBPBinaryException {
protected void parse(Parser parser) throws SBPBinaryException {
/* Parse fields from binary */
sequence = parser.getU32();
contents = parser.getArrayofU8();
contents = parser.getString();
}

@Override
protected void build(Builder builder) {
builder.putU32(sequence);
builder.putArrayofU8(contents);
builder.putString(contents);
}

@Override
public JSONObject toJSON() {
JSONObject obj = super.toJSON();
obj.put("sequence", sequence);
obj.put("contents", new JSONArray(contents));
obj.put("contents", contents);
return obj;
}

Expand Down
2 changes: 1 addition & 1 deletion javascript/sbp.bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions javascript/sbp/file_io.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ MsgFileioReadDirReq.prototype.fieldSpec.push(['dirname', 'string', null]);
*
* Fields in the SBP payload (`sbp.payload`):
* @field sequence number (unsigned 32-bit int, 4 bytes) Read sequence number
* @field contents array Contents of read directory
* @field contents string Contents of read directory
*
* @param sbp An SBP object with a payload to be decoded.
*/
Expand All @@ -172,10 +172,10 @@ MsgFileioReadDirResp.prototype.constructor = MsgFileioReadDirResp;
MsgFileioReadDirResp.prototype.parser = new Parser()
.endianess('little')
.uint32('sequence')
.array('contents', { type: 'uint8', readUntil: 'eof' });
.string('contents', { greedy: true });
MsgFileioReadDirResp.prototype.fieldSpec = [];
MsgFileioReadDirResp.prototype.fieldSpec.push(['sequence', 'writeUInt32LE', 4]);
MsgFileioReadDirResp.prototype.fieldSpec.push(['contents', 'array', 'writeUInt8', function () { return 1; }, null]);
MsgFileioReadDirResp.prototype.fieldSpec.push(['contents', 'string', null]);

/**
* SBP class for message MSG_FILEIO_REMOVE (0x00AC).
Expand Down
5 changes: 3 additions & 2 deletions kaitai/ksy/file_io.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ types:
- id: contents
doc: |
Contents of read directory
type: u1
repeat: eos
type: str
encoding: ascii
size-eos: true

msg_fileio_remove:
doc: |
Expand Down
2 changes: 1 addition & 1 deletion kaitai/ksy/sbp.ksy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
#
# Kaitai Struct definition file for Swift Binary Protocol 4.15.1-alpha
# Kaitai Struct definition file for Swift Binary Protocol 5.0.4-alpha
#
# Automatically generated with generate.py. Do not hand edit!

Expand Down
2 changes: 1 addition & 1 deletion proto/file_io.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ message MsgFileioReadDirReq {
*/
message MsgFileioReadDirResp {
uint32 sequence = 1;
repeated uint32 contents = 2;
string contents = 2;
}

/** Delete a file from the file system (host => device)
Expand Down
4 changes: 2 additions & 2 deletions python/sbp/file_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,15 @@ class MsgFileioReadDirResp(SBP):
SBP parent object to inherit from.
sequence : int
Read sequence number
contents : array
contents : string
Contents of read directory
sender : int
Optional sender ID, defaults to SENDER_ID (see sbp/msg.py).
"""
_parser = construct.Struct(
'sequence' / construct.Int32ul,
'contents' / construct.GreedyRange(construct.Int8ul),)
'contents' / construct.GreedyBytes,)
__slots__ = [
'sequence',
'contents',
Expand Down
5 changes: 3 additions & 2 deletions rust/sbp/src/messages/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ pub mod msg_fileio_read_dir_resp {
pub sequence: u32,
/// Contents of read directory
#[cfg_attr(feature = "serde", serde(rename = "contents"))]
pub contents: Vec<u8>,
pub contents: SbpString<Vec<u8>, Multipart>,
}

impl ConcreteMessage for MsgFileioReadDirResp {
Expand Down Expand Up @@ -407,7 +407,8 @@ pub mod msg_fileio_read_dir_resp {
}

impl WireFormat for MsgFileioReadDirResp {
const MIN_LEN: usize = <u32 as WireFormat>::MIN_LEN + <Vec<u8> as WireFormat>::MIN_LEN;
const MIN_LEN: usize =
<u32 as WireFormat>::MIN_LEN + <SbpString<Vec<u8>, Multipart> as WireFormat>::MIN_LEN;
fn len(&self) -> usize {
WireFormat::len(&self.sequence) + WireFormat::len(&self.contents)
}
Expand Down
2 changes: 1 addition & 1 deletion spec/yaml/swiftnav/sbp/file_io.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ definitions:
type: u32
desc: Read sequence number
- contents:
type: array
type: string
encoding: multipart
fill: u8
desc: Contents of read directory
Expand Down
Loading