| 1 | package Voldemort::ProtoBuff::DeleteMessage; | ||
| 2 | |||
| 3 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 0 | ▶ | use Voldemort::ProtoBuff::BaseMessage; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 5 | use Carp; | ||
| 6 | |||
| 7 | extends 'Voldemort::ProtoBuff::BaseMessage'; | ||
| 8 | |||
| 9 | sub write { | ||
| 10 | my $self = shift; | ||
| 11 | my $connection = shift; | ||
| 12 | my $store = shift; | ||
| 13 | my $key = shift; | ||
| 14 | my $node = shift || 0; | ||
| 15 | |||
| 16 | my $entries = $self->_get_entries($node); | ||
| 17 | |||
| 18 | my $data = Voldemort::ProtoBuff::Spec2::VoldemortRequest->encode( | ||
| 19 | { | ||
| 20 | 'type' => Voldemort::ProtoBuff::Spec2::RequestType::DELETE(), | ||
| 21 | 'store' => $store, | ||
| 22 | 'delete' => Voldemort::ProtoBuff::Spec2::DeleteRequest->new( | ||
| 23 | { | ||
| 24 | key => $key, | ||
| 25 | 'version' => Voldemort::ProtoBuff::Spec2::VectorClock->new( | ||
| 26 | { | ||
| 27 | timestamp => time(), | ||
| 28 | entries => $entries | ||
| 29 | } | ||
| 30 | ) | ||
| 31 | } | ||
| 32 | ) | ||
| 33 | } | ||
| 34 | ); | ||
| 35 | |||
| 36 | $connection->send( pack( 'N', length($data) ) ); | ||
| 37 | $connection->send($data); | ||
| 38 | } | ||
| 39 | |||
| 40 | sub read { | ||
| 41 | my $self = shift; | ||
| 42 | my $connection = shift; | ||
| 43 | my $store = shift; | ||
| 44 | my $key = shift; | ||
| 45 | |||
| 46 | my $size = $connection->recv(4); | ||
| 47 | $size = unpack( 'N', $size ); | ||
| 48 | return if !$size; | ||
| 49 | |||
| 50 | my $data = $connection->recv($size); | ||
| 51 | $data = Voldemort::ProtoBuff::Spec2::DeleteResponse->decode($data) | ||
| 52 | || carp($!); | ||
| 53 | |||
| 54 | my $message = | ||
| 55 | defined $data->error() ? $data->error()->error_message() : undef; | ||
| 56 | return $data->success(), $message; | ||
| 57 | } | ||
| 58 | |||
| 59 | 1; | ||