/*-------------------------------------------------------------------------- Project: HorizonSDK File: rdt_Segment.cpp Copyright 2009 Nintendo. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Date:: 2010-09-14#$ $Rev: 25753 $ $Author: hiratsu_daisuke $ *-------------------------------------------------------------------------*/ #include "stdafx.h" #include "rdt_Segment.h" #include #include "rdt_Utility.h" namespace { } // end of anonymous namespace namespace nn { namespace rdt { namespace CTR { void Segment::SetData(const void *pBuf, u32 len) { ASSERT(pBuf!=NULL); ASSERTMSG(len <= PAYLOAD_SIZE, "Amount of data excees payload.\n");; memcpy(payload, pBuf, len); header.dataLength = len; } u32 Segment::GetData(void *pBuf, u32 len) const { ASSERT(pBuf!=NULL); WARNINGMSG((len <= PAYLOAD_SIZE), "You attempt to read too large size of data (bigger than payload size). Ignored."); u32 ret = min(header.dataLength, len); memcpy(pBuf, payload, ret); return ret; } void Segment::Clear(void) { header.Clear(); memset(payload, 0, PAYLOAD_SIZE); } void Segment::ClearHeader(void) { header.Clear(); } u32 Segment::GetLastSeqNumber(void) const { if(IsSyn() || IsAck() || IsFin() || IsRst()) { // 現状、これらの制御ビットはデータと混ぜずに単独で送っているはずだから。 ASSERT(GetDataLength()==0); return GetSeqNumber() + GetDataLength(); } else { // データのセグメントの場合。 return GetSeqNumber() + GetDataLength() - 1; } } /*! @brief セグメント長を取得(SYNとFINが勘定に入っている) */ u32 Segment::GetSegmentLength(void) const { u32 ret = header.dataLength; if(IsSyn()) { ++ret; } if(IsFin()) { ++ret; } return ret; } void Segment::PrintDebugInfo(void) const { LOG("--Header contents--\n"); header.PrintDebugInfo(); if(GetDataLength()==0) { LOG("--No data--\n"); } else { char buf[PAYLOAD_SIZE+1]; u32 len = GetData(buf, PAYLOAD_SIZE); buf[len] = '\0'; LOG("--Data(%d bytes)--\n", GetDataLength()); // LOG("%s\n", buf); } } }}} // namespace nn::rdt::CTR