Skip to content

Commit

Permalink
patterns/msgpack: Fixed endianess of lengths and fixint definition (#291
Browse files Browse the repository at this point in the history
)

* Fix endianness of msgpack ext datum lengths

* Fix formatting of negative fixints
  • Loading branch information
SpaceManiac authored Aug 20, 2024
1 parent d961271 commit 7c65d51
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions patterns/msgpack.hexpat
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,6 @@ enum Type : u8 {
NegativeFixInt = 0xE0 ... 0xFF
};

fn format_positive_fixint(u8 value) {
return value & 0b0111'1111;
};

fn format_negative_fixint(u8 value) {
return -(value & 0b0001'1111);
};

using MessagePack;

struct MapEntry {
Expand All @@ -62,10 +54,10 @@ struct MessagePack {

if (u8(type) <= 0x7F) {
$ -= 1;
u8 value [[format("format_positive_fixint")]];
u8 value;
} else if (u8(type) >= Type::NegativeFixInt) {
$ -= 1;
u8 value [[format("format_negative_fixint")]];
s8 value;
} else if (type == Type::Uint8)
be u8 value;
else if (type == Type::Uint16)
Expand Down Expand Up @@ -142,16 +134,14 @@ struct MessagePack {
s8 type;
u8 data[length];
} else if (type == Type::Ext16) {
u16 length;
be u16 length;
s8 type;
u8 data[length];
} else if (type == Type::Ext32) {
u32 length;
be u32 length;
s8 type;
u8 data[length];
}


};

MessagePack pack @ 0x00;
MessagePack pack @ 0x00;

0 comments on commit 7c65d51

Please sign in to comment.