/** * Compatibility method. Same as {@link #getStringOrThrow(String)}. * * @throws IllegalArgumentException */ public String getString(String key) throws IllegalArgumentException { return getStringOrThrow(key); }
public ErrorRecord(Binder binder) { this( Errors.valueOf(binder.getStringOrThrow("error")), binder.getStringOrThrow("object"), binder.getString("message", "") ); }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { super.deserialize(data, deserializer); roleName = data.getStringOrThrow("target_name"); }
public static String unpackJSString(Binder scriptBinder, byte[] jsFileContent) { JSApiCompressionEnum compression = JSApiCompressionEnum.valueOf(scriptBinder.getStringOrThrow("compression")); switch (compression) { case RAW: return new String(jsFileContent); case ZIP: return unpackJSString_fromZip(jsFileContent); } throw new IllegalArgumentException("missing script parameter field: compression"); }
@Override public Object deserialize(Binder binder, BiDeserializer deserializer) { return new ErrorRecord( Errors.valueOf(binder.getStringOrThrow("error")), binder.getStringOrThrow("object"), binder.getString("message", "") ); }
@Override public Object deserialize(Binder binder, BiDeserializer deserializer) { if(binder.containsKey("base58")) { return (Safe58.decode(binder.getStringOrThrow("base64"),true)); } if(binder.containsKey("safe58")) { return (Safe58.decode(binder.getStringOrThrow("base64"))); } return Base64.decodeLines(binder.getStringOrThrow("base64")); }
private NodeRecord(Binder data) throws IOException { url = data.getStringOrThrow("url"); try { key = new PublicKey(data.getBinaryOrThrow("key")); } catch (EncryptionError encryptionError) { throw new IOException("failed to construct node public key", encryptionError); } }
@Override public void deserialize(Binder data, BiDeserializer deserializer) { publicKey = deserializer.deserialize(data.getBinderOrThrow("publicKey")); publicHost = data.getStringOrThrow("publicHost"); String host = data.getStringOrThrow("host"); nodeAddress = new InetSocketAddress(host, data.getIntOrThrow("udpPort")); clientAddress = new InetSocketAddress(host, data.getIntOrThrow("clientPort")); serverAddress = new InetSocketAddress(host, data.getIntOrThrow("serverPort")); nodeName = data.getStringOrThrow("name"); number = data.getIntOrThrow("number"); }
@Override public Object deserialize(Binder binder, BiDeserializer deserializer) { if(binder.containsKey("base58")) { return new Bytes(Safe58.decode(binder.getStringOrThrow("base58"),true)); } if(binder.containsKey("safe58")) { return new Bytes(Safe58.decode(binder.getStringOrThrow("safe58"))); } return new Bytes(Base64.decodeLines(binder.getStringOrThrow("base64"))); }
/** * Get current network rate for operating SLOT1 contracts * @return kilobyte-days per U rate * @throws ClientError */ public Decimal storageGetRate() throws ClientError { return protect(() -> { Binder result = httpClient.command("storageGetRate"); String U = result.getStringOrThrow("U"); return new Decimal(U); }); }
/** * Get current network rate for operating UNS1 contracts * @return name-days per U rate * @throws ClientError */ public Decimal unsRate() throws ClientError { return protect(() -> { Binder result = httpClient.command("unsRate"); String U = result.getStringOrThrow("U"); return new Decimal(U); }); }
@Override public void deserialize(Binder data,BiDeserializer deserializer) { super.deserialize(data, deserializer); bar = data.getStringOrThrow("bar"); } }
protected void initFromParams() { fieldName = params.getStringOrThrow("field_name"); minValue = new Decimal(params.getString("min_value", "0")); minUnit = new Decimal(params.getString("min_unit", "1e-9")); mergeFields = params.getList("join_match_fields", asList("state.origin")); }
public static JSApiScriptParameters fromBinder(Binder binder) { JSApiScriptParameters scriptParameters = new JSApiScriptParameters(); JSApiCompressionEnum compression = JSApiCompressionEnum.valueOf(binder.getStringOrThrow("compression")); scriptParameters.isCompressed = (compression != JSApiCompressionEnum.RAW); scriptParameters.timeLimitMillis = binder.getIntOrThrow("time_limit"); scriptParameters.permissions = binder.getBinderOrThrow("permissions"); scriptParameters.domainMasks = binder.getListOrThrow("domainMasks"); scriptParameters.ipMasks = binder.getListOrThrow("ipMasks"); return scriptParameters; }
protected void initFromParams() { fieldName = params.getStringOrThrow("field_name"); minValue = new Decimal(params.getString("min_value", "0")); minStep = new Decimal(params.getString("min_step", ""+Integer.MIN_VALUE)); maxStep = new Decimal(params.getString("max_step", ""+Integer.MAX_VALUE)); maxValue = new Decimal(params.getString("max_value", ""+Integer.MAX_VALUE)); }
@Test public void transactionalData() throws Exception { Contract contract = new Contract(TestKeys.privateKey(0)); String testValue = HashId.createRandom().toBase64String(); contract.getTransactionalData().set("test_value", testValue); contract.seal(); byte[] packedData = contract.getPackedTransaction(); Contract unpackedContract = Contract.fromPackedTransaction(packedData); System.out.println("unpackedContract.transactional.data.test_value: " + unpackedContract.getTransactionalData().getStringOrThrow("test_value")); assertEquals(testValue, unpackedContract.getTransactionalData().getStringOrThrow("test_value")); }
@Test public void autoSerializable() throws Exception { Test1 t1 = new Test1("foo"); DefaultBiMapper.registerClass(Test1.class); Binder s = DefaultBiMapper.serialize(t1); assertEquals(s.getStringOrThrow("__type"), "foobar1"); assertEquals(s.getStringOrThrow("value"), "foo"); Test1 t2 = DefaultBiMapper.deserialize(s); assertThat(t2, instanceOf(Test1.class) ); assertEquals("foo", t2.getValue()); }
@Test public void emptyStrings() throws Exception { Object xo = JsonTool.fromJson("{\"text\":\"\",\"type\":\"p2pchat\",\"from_party_id\":\"1271\"}"); Binder b = Binder.from(xo); Bytes bb = Boss.dump(b); String x = (String)Boss.unpack(bb.toArray()).getStringOrThrow("text"); assertEquals("", x); }
@Test public void cachingNestedMaps() throws Exception { Binder a = Binder.fromKeysValues("foo", "bar"); Binder b = Binder.fromKeysValues("foo", "bar"); b.put("bar", "buzz"); Binder root = Binder.fromKeysValues("a", b, "b", b, "c", b); Binder res = Boss.unpack(Boss.pack(root)); assertEquals("buzz", res.getBinderOrThrow("c").getStringOrThrow("bar")); }
@Test public void autoSerializableInheritance() throws Exception { Test1 t1 = new Test2("foo"); DefaultBiMapper.registerClass(Test2.class); Binder s = DefaultBiMapper.serialize(t1); assertEquals(s.getStringOrThrow("__type"), "net.sergeych.biserializer.Test2"); Test2 t2 = DefaultBiMapper.deserialize(s); assertThat(t2, instanceOf(Test1.class) ); assertEquals("bad", t2.getValue()); assertEquals("foo", t2.getBar()); }