8000 Write the GUIDs of form properties in upper case, as those of table values by dominion525 · Pull Request #108 · dominion525/jetdb · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 2 additions & 26 deletions crates/jetdb/src/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ fn entry_value(type_code: u32, bytes: &[u8]) -> BlobValue {
),
0x08 => <[u8; 8]>::try_from(bytes)
.map_or_else(|_| binary(), |b| BlobValue::Double(f64::from_le_bytes(b))),
0x09 if bytes.len() == 16 => BlobValue::Guid(format_guid(bytes)),
0x09 if bytes.len() == 16 => BlobValue::Guid(crate::data::format_guid(bytes)),
0x0A | 0x0C => BlobValue::Text(
encoding::decode_utf16le(bytes)
.unwrap_or_else(|_| String::from_utf8_lossy(bytes).into_owned()),
Expand Down Expand Up @@ -1024,30 +1024,6 @@ fn parse_section_props(data: &[u8], start: usize, end: usize) -> Vec<BlobPropert
parse_group(data, start, end).0
}

/// Format 16 bytes as a GUID string `{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}`.
pub(crate) fn format_guid(bytes: &[u8]) -> String {
if bytes.len() < 16 {
return format!("({} bytes)", bytes.len());
}
let d1 = u32::from_le_bytes([bytes[0], bytes[1], bytes[2], bytes[3]]);
let d2 = u16::from_le_bytes([bytes[4], bytes[5]]);
let d3 = u16::from_le_bytes([bytes[6], bytes[7]]);
format!(
"{{{:08x}-{:04x}-{:04x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}}}",
d1,
d2,
d3,
bytes[8],
bytes[9],
bytes[10],
bytes[11],
bytes[12],
bytes[13],
bytes[14],
bytes[15]
)
}

// ---------------------------------------------------------------------------
// Tests
// ---------------------------------------------------------------------------
Expand Down Expand Up @@ -1794,7 +1770,7 @@ mod tests {
let (props, _) = parse_blob(&make_blob(&entry(0x0178, 0x09, &guid_bytes))).unwrap();
assert_eq!(props.len(), 1);
match &props[0].value {
BlobValue::Guid(s) => assert_eq!(s, "{8d64a650-62e7-4903-9733-0d8ce84978bf}"),
BlobValue::Guid(s) => assert_eq!(s, "{8D64A650-62E7-4903-9733-0D8CE84978BF}"),
other => panic!("expected Guid, got {:?}", other),
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/jetdb/src/form2000.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
//! to 0xFC, the length byte 0xFF being followed by a length of 2 bytes. Of
//! 0x80 to 0xBC, only 0x9C to 0xA0 have been seen; 0xBD to 0xBF hold text.

use crate::data::format_guid;
use crate::encoding;
use crate::form::{format_guid, BlobProperty, BlobValue, ControlProperties};
use crate::form::{BlobProperty, BlobValue, ControlProperties};

/// The first byte of the Blob of a form or report in the Access 2000 format.
pub(crate) const VERSION: u8 = 0x13;
Expand Down
6 changes: 3 additions & 3 deletions crates/jetdb/src/save_as_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ fn hex_bytes(line: &str) -> Vec<u8> {
}

/// The GUID `bytes` holds, as jetdb writes one: its first three fields
/// little-endian, in lower case. Written here apart from the library, so that
/// little-endian, in upper case. Written here apart from the library, so that
/// the GUIDs jetdb reads are checked against SaveAsText on their own.
fn guid(bytes: &[u8]) -> Option<String> {
let b: [u8; 16] = bytes.try_into().ok()?;
let hex = |range: &[u8]| range.iter().map(|x| format!("{x:02x}")).collect::<String>();
let hex = |range: &[u8]| range.iter().map(|x| format!("{x:02X}")).collect::<String>();
Some(format!(
"{{{:08x}-{:04x}-{:04x}-{}-{}}}",
"{{{:08X}-{:04X}-{:04X}-{}-{}}}",
u32::from_le_bytes([b[0], b[1], b[2], b[3]]),
u16::from_le_bytes([b[4], b[5]]),
u16::from_le_bytes([b[6], b[7]]),
Expand Down
Loading
0