@@ -521,6 +521,27 @@ export default defineComponent({
521521 }
522522 };
523523
524+ // For fixed-size integer types, allow equal or smaller widths.
525+ // Examples:
526+ // - uint32 accepts 1..4 bytes
527+ // - uint64 accepts 1..8 bytes
528+ const isCompatibleFixedTypeLength = (type : string , actualLength : number ): boolean => {
529+ const normalized = type .toLowerCase ();
530+ const expectedSize = getExpectedByteSize (normalized );
531+
532+ if (expectedSize === null ) {
533+ return true ;
534+ }
535+
536+ const isFixedInteger = / ^ (u? int)(8| 16| 32| 64)$ / .test (normalized );
537+ if (isFixedInteger ) {
538+ return actualLength >= 1 && actualLength <= expectedSize ;
539+ }
540+
541+ // Non-integer fixed-size types (e.g. float32/float64) must match exactly.
542+ return actualLength === expectedSize ;
543+ };
544+
524545 // Create annotated byte sections for display
525546 const byteSections = computed (() => {
526547 const bytes = byteArray .value .map (s => parseInt (s , 10 ));
@@ -663,7 +684,7 @@ export default defineComponent({
663684 if (props .showValidation ) {
664685 const expectedSize = getExpectedByteSize (headerValueType );
665686 const maxLength = headerType < 128 ? 255 : 65535 ;
666- if (expectedSize !== null && headerLength !== expectedSize ) {
687+ if (expectedSize !== null && ! isCompatibleFixedTypeLength ( headerValueType , headerLength ) ) {
667688 validation = ' invalid' ;
668689 displayValue += ` (expected ${expectedSize } bytes, got ${headerLength }) ` ;
669690 } else if (expectedSize === null && headerLength > maxLength ) {
@@ -681,7 +702,7 @@ export default defineComponent({
681702 if (props .showValidation ) {
682703 const expectedSize = getExpectedByteSize (customHeaderType );
683704 const maxLength = headerType < 128 ? 255 : 65535 ;
684- if (expectedSize !== null && headerLength !== expectedSize ) {
705+ if (expectedSize !== null && ! isCompatibleFixedTypeLength ( customHeaderType , headerLength ) ) {
685706 validation = ' invalid' ;
686707 displayValue += ` (expected ${expectedSize } bytes, got ${headerLength }) ` ;
687708 } else if (expectedSize === null && headerLength > maxLength ) {
@@ -833,7 +854,7 @@ export default defineComponent({
833854 if (props .showValidation ) {
834855 const expectedSize = getExpectedByteSize (payloadValueType );
835856 const maxLength = payloadType < 128 ? 255 : 65535 ;
836- if (expectedSize !== null && payloadLength !== expectedSize ) {
857+ if (expectedSize !== null && ! isCompatibleFixedTypeLength ( payloadValueType , payloadLength ) ) {
837858 validation = ' invalid' ;
838859 displayValue += ` (expected ${expectedSize } bytes, got ${payloadLength }) ` ;
839860 } else if (expectedSize === null && payloadLength > maxLength ) {
@@ -851,7 +872,7 @@ export default defineComponent({
851872 if (props .showValidation ) {
852873 const expectedSize = getExpectedByteSize (customPayloadType );
853874 const maxLength = payloadType < 128 ? 255 : 65535 ;
854- if (expectedSize !== null && payloadLength !== expectedSize ) {
875+ if (expectedSize !== null && ! isCompatibleFixedTypeLength ( customPayloadType , payloadLength ) ) {
855876 validation = ' invalid' ;
856877 displayValue += ` (expected ${expectedSize } bytes, got ${payloadLength }) ` ;
857878 } else if (expectedSize === null && payloadLength > maxLength ) {
0 commit comments