鼠笼管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

30 lines
729 B

<?php
// namespace ISO8583\Mapper;
class AlphaNumeric extends AbstractMapper
{
public function pack($message)
{
$packed = bin2hex($message);
if ($this->getVariableLength() > 0) {
$length = bin2hex(sprintf('%0' . $this->getVariableLength() . 'd', strlen($packed) / 2));
$packed = $length . $packed;
}
return $packed;
}
public function unpack(&$message)
{
if ($this->getVariableLength() > 0) {
$length = (int)hex2bin(substr($message, 0, $this->getVariableLength() * 2));
} else {
$length = $this->getLength();
}
$parsed = hex2bin(substr($message, $this->getVariableLength() * 2, $length * 2));
$message = substr($message, $length * 2 + $this->getVariableLength() * 2);
return $parsed;
}
}