Search in sources :

Example 1 with BcsSerializer

use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.

the class BcsSerializeHelper method serializeListToBytes.

@SneakyThrows
public static Bytes serializeListToBytes(List<String> list) {
    List<Bytes> bytesList = list.stream().map(s -> serializeVectorU8ToBytes(s)).collect(Collectors.toList());
    BcsSerializer s = new BcsSerializer();
    s.serialize_len(bytesList.size());
    for (Bytes item : bytesList) {
        s.serialize_bytes(item);
    }
    byte[] bytes = s.get_bytes();
    return Bytes.valueOf(bytes);
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer) List(java.util.List) Bytes(com.novi.serde.Bytes) SneakyThrows(lombok.SneakyThrows) BigInteger(java.math.BigInteger) AccountAddress(org.starcoin.types.AccountAddress) Collectors(java.util.stream.Collectors) BcsSerializer(com.novi.bcs.BcsSerializer) Bytes(com.novi.serde.Bytes) SneakyThrows(lombok.SneakyThrows)

Example 2 with BcsSerializer

use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.

the class BcsSerializeHelper method serializeU128ToBytes.

@SneakyThrows
public static Bytes serializeU128ToBytes(BigInteger v) {
    BcsSerializer s = new BcsSerializer();
    s.serialize_u128(v);
    return Bytes.valueOf(s.get_bytes());
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer) SneakyThrows(lombok.SneakyThrows)

Example 3 with BcsSerializer

use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.

the class BcsSerializeHelper method serializeU64ToBytes.

@SneakyThrows
public static Bytes serializeU64ToBytes(Long v) {
    BcsSerializer s = new BcsSerializer();
    s.serialize_u64(v);
    return Bytes.valueOf(s.get_bytes());
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer) SneakyThrows(lombok.SneakyThrows)

Example 4 with BcsSerializer

use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.

the class Helpers method encode_bool_argument.

private static Bytes encode_bool_argument(Boolean arg) {
    try {
        BcsSerializer s = new BcsSerializer();
        s.serialize_bool(arg);
        return Bytes.valueOf(s.get_bytes());
    } catch (SerializationError e) {
        throw new IllegalArgumentException("Unable to serialize argument of type bool");
    }
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer)

Example 5 with BcsSerializer

use of com.novi.bcs.BcsSerializer in project starcoin-java by starcoinorg.

the class Helpers method encode_u8_argument.

private static Bytes encode_u8_argument(@Unsigned Byte arg) {
    try {
        BcsSerializer s = new BcsSerializer();
        s.serialize_u8(arg);
        return Bytes.valueOf(s.get_bytes());
    } catch (SerializationError e) {
        throw new IllegalArgumentException("Unable to serialize argument of type u8");
    }
}
Also used : BcsSerializer(com.novi.bcs.BcsSerializer)

Aggregations

BcsSerializer (com.novi.bcs.BcsSerializer)10 SneakyThrows (lombok.SneakyThrows)5 Bytes (com.novi.serde.Bytes)2 BigInteger (java.math.BigInteger)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AccountAddress (org.starcoin.types.AccountAddress)2 JSON (com.alibaba.fastjson.JSON)1 JSONObject (com.alibaba.fastjson.JSONObject)1 Joiner (com.google.common.base.Joiner)1 Lists (com.google.common.collect.Lists)1 BigDecimal (java.math.BigDecimal)1 RoundingMode (java.math.RoundingMode)1 Objects (java.util.Objects)1 Test (org.junit.Test)1 ResourceObj (org.starcoin.bean.ResourceObj)1 ScriptFunctionObj (org.starcoin.bean.ScriptFunctionObj)1 TypeObj (org.starcoin.bean.TypeObj)1 Ed25519PrivateKey (org.starcoin.types.Ed25519PrivateKey)1