LogCabin
RPC/Protocol.cc
Go to the documentation of this file.
00001 /* Copyright (c) 2012 Stanford University
00002  *
00003  * Permission to use, copy, modify, and distribute this software for any
00004  * purpose with or without fee is hereby granted, provided that the above
00005  * copyright notice and this permission notice appear in all copies.
00006  *
00007  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR(S) DISCLAIM ALL WARRANTIES
00008  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
00009  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL AUTHORS BE LIABLE FOR
00010  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00011  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00012  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00013  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00014  */
00015 
00016 #include "Core/Endian.h"
00017 #include "RPC/Protocol.h"
00018 
00019 namespace LogCabin {
00020 namespace RPC {
00021 namespace Protocol {
00022 
00023 void
00024 RequestHeaderPrefix::fromBigEndian()
00025 {
00026     // version is only 1 byte, nothing to flip
00027 }
00028 
00029 void
00030 RequestHeaderPrefix::toBigEndian()
00031 {
00032     // version is only 1 byte, nothing to flip
00033 }
00034 
00035 void
00036 RequestHeaderVersion1::fromBigEndian()
00037 {
00038     service = be16toh(service);
00039     // serviceSpecificErrorVersion is only 1 byte, nothing to flip
00040     opCode = be16toh(opCode);
00041 }
00042 
00043 void
00044 RequestHeaderVersion1::toBigEndian()
00045 {
00046     service = htobe16(service);
00047     // serviceSpecificErrorVersion is only 1 byte, nothing to flip
00048     opCode = htobe16(opCode);
00049 }
00050 
00051 ::std::ostream&
00052 operator<<(::std::ostream& stream, Status status)
00053 {
00054     switch (status) {
00055         case Status::OK:
00056             stream << "OK";
00057             break;
00058         case Status::SERVICE_SPECIFIC_ERROR:
00059             stream << "SERVICE_SPECIFIC_ERROR";
00060             break;
00061         case Status::INVALID_VERSION:
00062             stream << "INVALID_VERSION";
00063             break;
00064         case Status::INVALID_SERVICE:
00065             stream << "INVALID_SERVICE";
00066             break;
00067         case Status::INVALID_REQUEST:
00068             stream << "INVALID_REQUEST";
00069             break;
00070         default:
00071             stream << "(bad Status value " << uint8_t(status) << " )";
00072             break;
00073     }
00074     return stream;
00075 }
00076 
00077 void
00078 ResponseHeaderPrefix::fromBigEndian()
00079 {
00080     // status is only 1 byte, nothing to flip
00081 }
00082 
00083 void
00084 ResponseHeaderPrefix::toBigEndian()
00085 {
00086     // status is only 1 byte, nothing to flip
00087 }
00088 
00089 void
00090 ResponseHeaderVersion1::fromBigEndian()
00091 {
00092     // no fields, nothing to flip
00093 }
00094 
00095 void
00096 ResponseHeaderVersion1::toBigEndian()
00097 {
00098     // no fields, nothing to flip
00099 }
00100 
00101 } // namespace LogCabin::RPC::Protocol
00102 } // namespace LogCabin::RPC
00103 } // namespace LogCabin
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines