/// <summary> /// Deserialize a <see cref="Transaction"/> from binary data. /// </summary> /// <param name="data">The binary data to deserialize.</param> /// <returns>The deserialized <see cref="Transaction"/>.</returns> public static Transaction DeserializeTransaction(ByteString data) { Messages.Transaction transaction = new Messages.Transaction(); transaction.MergeFrom(data.ToProtocolBuffers()); return(new Transaction( new ByteString(transaction.Mutation.ToByteArray()), epoch + TimeSpan.FromSeconds(transaction.Timestamp), new ByteString(transaction.TransactionMetadata.ToByteArray()))); }
/// <summary> /// Serializes a <see cref="Transaction"/> into a byte array. /// </summary> /// <param name="transaction">The transaction to serialize.</param> /// <returns>The serialized transaction.</returns> public static byte[] SerializeTransaction(Transaction transaction) { Messages.Transaction transactionBuilder = new Messages.Transaction() { Mutation = transaction.Mutation.ToProtocolBuffers(), Timestamp = (long)(transaction.Timestamp - epoch).TotalSeconds, TransactionMetadata = transaction.TransactionMetadata.ToProtocolBuffers() }; return(transactionBuilder.ToByteArray()); }