Why am I getting “Invalid value in field Password” for a fixed-length field in a binary protocol buffer?

I am implementing a binary protocol and sending a buffer to a server. One of the fields, Password, is defined as follows in the documentation:

Data Type: Fixed String
Length: 32 bytes
Offset: 58

Description:
Fixed size of 32 bytes.
Encoded as a character array.
Must be completely filled with valid characters (space padding if required).
Valid characters: 0-9, A-Z, a-z, !, #, $, %, &, *, +, -, ., /, =, @, _.

I have attched below images to get Idea of padding len and offset.

Image of Datatype table

Image of field details table

Here’s my code for constructing the buffer:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
const createGatewayRequest = () => {
const buffer = Buffer.alloc(96); // Total message size: 96 bytes
let offset = 0;
// 1. BodyLen: 4 bytes (unsigned int, little-endian)
buffer.writeUInt32LE(96, offset);
offset += 4;
// 2. TemplateID: 2 bytes (unsigned int, little-endian)
buffer.writeUInt16LE(10020, offset);
offset += 2;
// 3. NetworkMsgID: 8 bytes (Fixed String, zero-padded)
buffer.fill(0x00, offset, offset + 8);
offset += 8;
// 4. Pad2: 2 bytes (not used, zero-padded)
buffer.fill(0x00, offset, offset + 2);
offset += 2;
// 5. MsgSeqNum: 4 bytes (unsigned int, little-endian, must be set to 1)
buffer.writeUInt32LE(1, offset);
offset += 4;
// 6. SenderSubID: 4 bytes (not used, set to 0xFFFFFFFF)
buffer.writeUInt32LE(0xFFFFFFFF, offset);
offset += 4;
// 7. PartyIDSessionID: 4 bytes (unsigned int, little-endian)
const partyIDSessionID = 123123123;
buffer.writeUInt32LE(partyIDSessionID, offset);
offset += 4;
// 8. DefaultCstmApplVerID: 30 bytes (ASCII, padded with spaces)
const defaultCstmApplVerID = '2.4';
buffer.write(defaultCstmApplVerID.padEnd(30, ' '), offset, 30, 'ascii');
offset += 30;
// 9. Password: 32 bytes (ASCII, padded with spaces)
const Password = "pwd12345";
buffer.write(Password.padStart(32, ' '), offset, 32, 'ascii');
offset += 32;
buffer.fill(0x00, offset, offset + 6);
offset += 6;
console.log('Gateway Request (hex):', buffer.toString('hex'));
return buffer;
};
</code>
<code> const createGatewayRequest = () => { const buffer = Buffer.alloc(96); // Total message size: 96 bytes let offset = 0; // 1. BodyLen: 4 bytes (unsigned int, little-endian) buffer.writeUInt32LE(96, offset); offset += 4; // 2. TemplateID: 2 bytes (unsigned int, little-endian) buffer.writeUInt16LE(10020, offset); offset += 2; // 3. NetworkMsgID: 8 bytes (Fixed String, zero-padded) buffer.fill(0x00, offset, offset + 8); offset += 8; // 4. Pad2: 2 bytes (not used, zero-padded) buffer.fill(0x00, offset, offset + 2); offset += 2; // 5. MsgSeqNum: 4 bytes (unsigned int, little-endian, must be set to 1) buffer.writeUInt32LE(1, offset); offset += 4; // 6. SenderSubID: 4 bytes (not used, set to 0xFFFFFFFF) buffer.writeUInt32LE(0xFFFFFFFF, offset); offset += 4; // 7. PartyIDSessionID: 4 bytes (unsigned int, little-endian) const partyIDSessionID = 123123123; buffer.writeUInt32LE(partyIDSessionID, offset); offset += 4; // 8. DefaultCstmApplVerID: 30 bytes (ASCII, padded with spaces) const defaultCstmApplVerID = '2.4'; buffer.write(defaultCstmApplVerID.padEnd(30, ' '), offset, 30, 'ascii'); offset += 30; // 9. Password: 32 bytes (ASCII, padded with spaces) const Password = "pwd12345"; buffer.write(Password.padStart(32, ' '), offset, 32, 'ascii'); offset += 32; buffer.fill(0x00, offset, offset + 6); offset += 6; console.log('Gateway Request (hex):', buffer.toString('hex')); return buffer; }; </code>

const createGatewayRequest = () => {
    const buffer = Buffer.alloc(96); // Total message size: 96 bytes
    let offset = 0;

    // 1. BodyLen: 4 bytes (unsigned int, little-endian)
    buffer.writeUInt32LE(96, offset); 
    offset += 4;

    // 2. TemplateID: 2 bytes (unsigned int, little-endian)
    buffer.writeUInt16LE(10020, offset); 
    offset += 2;

    // 3. NetworkMsgID: 8 bytes (Fixed String, zero-padded)
    buffer.fill(0x00, offset, offset + 8); 
    offset += 8;

    // 4. Pad2: 2 bytes (not used, zero-padded)
    buffer.fill(0x00, offset, offset + 2);
    offset += 2;

    // 5. MsgSeqNum: 4 bytes (unsigned int, little-endian, must be set to 1)
    buffer.writeUInt32LE(1, offset); 
    offset += 4;

    // 6. SenderSubID: 4 bytes (not used, set to 0xFFFFFFFF)
    buffer.writeUInt32LE(0xFFFFFFFF, offset);
    offset += 4;

    // 7. PartyIDSessionID: 4 bytes (unsigned int, little-endian)
    const partyIDSessionID = 123123123;
    buffer.writeUInt32LE(partyIDSessionID, offset); 
    offset += 4;
    
    // 8. DefaultCstmApplVerID: 30 bytes (ASCII, padded with spaces)
    const defaultCstmApplVerID = '2.4';
    buffer.write(defaultCstmApplVerID.padEnd(30, ' '), offset, 30, 'ascii');
    offset += 30;

    // 9. Password: 32 bytes (ASCII, padded with spaces)
    const Password = "pwd12345";
    buffer.write(Password.padStart(32, ' '), offset, 32, 'ascii');
    offset += 32;

    buffer.fill(0x00, offset, offset + 6);
    offset += 6;

    console.log('Gateway Request (hex):', buffer.toString('hex'));

    return buffer; 
};

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật