public byte[] Encode(object value) { var strValue = value as string; if ((strValue != null) && !strValue.StartsWith("0x", StringComparison.Ordinal)) { value = "0x" + value; } var addr = intTypeEncoder.Encode(value); for (var i = 0; i < 12; i++) { if ((addr[i] != 0) && (addr[i] != 0xFF)) { throw new Exception("Invalid address (should be 20 bytes length): " + addr.ToHex()); } if (addr[i] == 0xFF) { addr[i] = 0; } } return(addr); }
public byte[] Encode(object value) { var strValue = value as string; if (strValue != null && !strValue.StartsWith("0x", StringComparison.Ordinal)) { // address is supposed to be always in hex value = "0x" + value; } byte[] addr = intTypeEncoder.Encode(value); for (int i = 0; i < 12; i++) { if (addr[i] != 0 && addr[i] != 0xFF) { throw new Exception("Invalid address (should be 20 bytes length): " + addr.ToHex()); } if (addr[i] == 0xFF) { addr[i] = 0; } } return(addr); }
public byte[] Encode(object value) { if (!(value is bool)) { throw new Exception("Wrong value for bool type: " + value); } return(intTypeEncoder.Encode((bool)value ? 1 : 0)); }