forked from zbackup/zbackup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.cc
44 lines (33 loc) · 1.08 KB
/
message.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (c) 2012-2014 Konstantin Isakov <[email protected]> and ZBackup contributors, see CONTRIBUTORS
// Part of ZBackup. Licensed under GNU GPLv2 or later + OpenSSL, see LICENSE
#include "message.hh"
#include <stdint.h>
namespace Message {
void serialize( MessageLite const & message, ZeroCopyOutputStream & stream )
{
CodedOutputStream cos( &stream );
serialize( message, cos );
}
void serialize( MessageLite const & message, CodedOutputStream & cos )
{
cos.WriteVarint32( message.ByteSize() );
message.SerializeWithCachedSizes( &cos );
if ( cos.HadError() )
throw exCantSerialize( message.GetTypeName() );
}
void parse( MessageLite & message, ZeroCopyInputStream & stream )
{
CodedInputStream cis( &stream );
parse( message, cis );
}
void parse( MessageLite & message, CodedInputStream & cis )
{
uint32_t v;
if ( !cis.ReadVarint32( &v ) )
throw exCantParse( message.GetTypeName() );
CodedInputStream::Limit limit = cis.PushLimit( v );
if( !message.ParseFromCodedStream( &cis ) )
throw exCantParse( message.GetTypeName() );
cis.PopLimit( limit );
}
}