Skip to content

the checkCode isn't match #77

@wv1124-ui

Description

@wv1124-ui

`
@BeforeClass
public static void globalSetup() {
// 方式一:全局配置(推荐)
MagicByte.configMagicChecker(Utils::calculate);
}

@Test
public void testLogin() {
    LoginTest cmdReq = new LoginTest();
    cmdReq.setUserName("user");

    ByteBuffer byteBuf = MagicByte.unpack(cmdReq);
    byte[] bytes = byteBuf.array();
    System.out.println("登录请求:" + HexUtils.bytesToHex(bytes));
    LoginTest deCmd = MagicByte.pack(bytes, LoginTest.class);
    Assert.assertEquals(deCmd.getUserName(), cmdReq.getUserName());
}

@NoArgsConstructor
@Getter
@Setter
@MagicClass(byteOrder = ByteOrder.BIG_ENDIAN, strict = false)
public class LoginTest {

@MagicField(order = 2, size = 10, charset = "GBK")
private String userName;

@MagicField(order = 4, calcCheckCode = true)
private Short crc;

}

`

登录请求:757365720000000000009CC3

com.github.misterchangray.core.exception.InvalidCheckCodeException: the checkCode isn't match, data:dXNlcgAAAAAAAJzD

at com.github.misterchangray.core.Packer.verifyCheckCode(Packer.java:144)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions