/// <summary> /// Serializes a <see cref="Mutation"/> into a byte array. /// </summary> /// <param name="mutation">The mutation to serialize.</param> /// <returns>The serialized mutation.</returns> public static byte[] SerializeMutation(Mutation mutation) { Messages.Mutation mutationBuilder = new Messages.Mutation() { Namespace = mutation.Namespace.ToProtocolBuffers(), Metadata = mutation.Metadata.ToProtocolBuffers() }; mutationBuilder.Records.Add( mutation.Records.Select( record => { var builder = new Messages.Record() { Key = record.Key.ToProtocolBuffers(), Version = record.Version.ToProtocolBuffers() }; if (record.Value != null) { builder.Value = new Messages.RecordValue() { Data = record.Value.ToProtocolBuffers() } } ; return(builder); })); return(mutationBuilder.ToByteArray()); }
/// <summary> /// Deserialize a <see cref="Mutation"/> from binary data. /// </summary> /// <param name="data">The binary data to deserialize.</param> /// <returns>The deserialized <see cref="Mutation"/>.</returns> public static Mutation DeserializeMutation(ByteString data) { Messages.Mutation mutation = new Messages.Mutation(); mutation.MergeFrom(data.ToProtocolBuffers()); return(new Mutation( new ByteString(mutation.Namespace.ToByteArray()), mutation.Records.Select( record => new Record( new ByteString(record.Key.ToByteArray()), record.Value != null ? new ByteString(record.Value.Data.ToByteArray()) : null, new ByteString(record.Version.ToByteArray()))), new ByteString(mutation.Metadata.ToByteArray()))); }
public override int GetHashCode() { int hash = 1; if (Mutation.Length != 0) { hash ^= Mutation.GetHashCode(); } if (Timestamp != 0L) { hash ^= Timestamp.GetHashCode(); } if (TransactionMetadata.Length != 0) { hash ^= TransactionMetadata.GetHashCode(); } return(hash); }