# j_record.cc

Go to the documentation of this file.

    00001 ///
    00002 /// \file       j_record.cc
    00003 ///             Internal record manipulation functions for JDWP classes
    00004 ///
    00005
    00006 /*
    00007     Copyright (C) 2009, Nicolas VIVIEN
    00008
    00009     This program is free software; you can redistribute it and/or modify
    00010     it under the terms of the GNU General Public License as published by
    00011     the Free Software Foundation; either version 2 of the License, or
    00012     (at your option) any later version.
    00013
    00014     This program is distributed in the hope that it will be useful,
    00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00017
    00018     See the GNU General Public License in the COPYING file at the
    00019     root directory of this project for more details.
    00020 */
    00021
    00022 #include "record-internal.h"
    00023 #include "data.h"
    00024 #include "protostructs.h"
    00025 #include <string.h>
    00026
    00027 using namespace Barry::Protocol;
    00028
    00029 namespace Barry {
    00030
    00031 //////////////////////////////////////////////////////////////////////////////
    00032 // JDWField builder helper functions
    00033
    00034 void AddJDWByte(Data &data, size_t &size, const uint8_t value)
    00035 {
    00036         size_t fieldsize = sizeof(uint8_t);
    00037         unsigned char *pd = data.GetBuffer(size + fieldsize) + size;
    00038
    00039         uint8_t *field = (uint8_t *) pd;
    00040
    00041         *field = value;
    00042
    00043         size += sizeof(uint8_t);
    00044 }
    00045
    00046
    00047 void AddJDWInt(Data &data, size_t &size, const uint32_t value)
    00048 {
    00049         size_t fieldsize = sizeof(uint32_t);
    00050         unsigned char *pd = data.GetBuffer(size + fieldsize) + size;
    00051
    00052         uint32_t *field = (uint32_t *) pd;
    00053
    00054         *field = value;
    00055
    00056         size += sizeof(uint32_t);
    00057 }
    00058
    00059
    00060 void AddJDWChar(Data &data, size_t &size, const void *buf, size_t bufsize)
    00061 {
    00062         size_t fieldsize = JDWP_FIELD_HEADER_SIZE + bufsize;
    00063         unsigned char *pd = data.GetBuffer(size + fieldsize) + size;
    00064
    00065         JDWField *field = (JDWField *) pd;
    00066
    00067         field->size = be_htobl(bufsize);
    00068         memcpy(field->u.raw, buf, bufsize);
    00069
    00070         size += fieldsize;
    00071 }
    00072
    00073
    00074 void AddJDWString(Data &data, size_t &size, const std::string &str)
    00075 {
    00076         AddJDWChar(data, size, str.c_str(), str.size());
    00077 }
    00078
    00079 } // namespace Barry
    00080