Actually the Message3 implementation was broken. It still is, because we lose one (but an important) byte somewhere when resizing the flat buffer. But at least the design flaws should be corrected with this commit. You can go ahead and review it Ingo.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13917 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Michael Lotz
2005-08-09 05:49:13 +00:00
parent 3019039f4f
commit 90dc946130
5 changed files with 92 additions and 79 deletions
+3 -2
View File
@@ -12,7 +12,6 @@
#define _MESSAGE_BODY_H_
#include <List.h>
#include "MessageField3.h"
enum {
B_FLATTENABLE_TYPE = 'FLAT'
@@ -20,6 +19,8 @@ enum {
namespace BPrivate {
class BMessageField;
class BMessageBody {
public:
BMessageBody();
@@ -68,7 +69,7 @@ public:
void PrintToStream() const;
// flat buffer management
uint8 *FlatBuffer() const { return (uint8 *)fFlatBuffer.Buffer(); };
inline uint8 *FlatBuffer() const { return (uint8 *)fFlatBuffer.Buffer(); };
uint8 *FlatInsert(int32 offset, ssize_t oldLength,
ssize_t newLength);
+11 -12
View File
@@ -14,6 +14,7 @@
#include <List.h>
#include <String.h>
#include <SupportDefs.h>
#include "MessageBody3.h"
// we only support those
#define MSG_FLAG_VALID 0x01
@@ -56,27 +57,24 @@ struct item_info_s {
typedef field_header_s FieldHeader;
typedef item_info_s ItemInfo;
class BMessageBody;
class BMessageField {
public:
BMessageField(BMessageBody *parent,
int32 offset, const char *name,
type_code type);
// only use this constructor to unflatten
BMessageField(BMessageBody *parent);
~BMessageField();
int32 Unflatten(int32 offset);
uint8 Flags() const { return fHeader->flags; };
uint8 Flags() const { return Header()->flags; };
status_t SetFixedSize(int32 itemSize);
bool FixedSize() const { return fHeader->flags & MSG_FLAG_FIXED_SIZE; };
bool FixedSize() const { return fFixedSize; };
void SetName(const char *newName);
const char *Name() const;
uint8 NameLength() const { return fHeader->nameLength; };
type_code Type() const { return fHeader->type; };
uint8 NameLength() const { return Header()->nameLength; };
type_code Type() const { return Header()->type; };
void AddItem(const void *item, ssize_t length);
uint8 *AddItem(ssize_t length);
@@ -88,11 +86,11 @@ public:
void *ItemAt(int32 index, ssize_t *size);
void RemoveItem(int32 index);
int32 CountItems() const { return fHeader->count; };
int32 CountItems() const { return Header()->count; };
void PrintToStream() const;
void SetOffset(int32 offset);
void SetOffset(int32 offset) { fOffset = offset; };
int32 Offset() const { return fOffset; };
// always do MakeEmpty -> RemoveSelf -> delete
@@ -104,12 +102,13 @@ public:
BMessageField *Next() const { return fNext; };
private:
bool IsFixedSize(type_code type);
inline FieldHeader *Header() const { return (FieldHeader *)(fParent->FlatBuffer() + fOffset); };
BMessageBody *fParent;
int32 fOffset;
FieldHeader *fHeader;
int32 fDataOffset;
bool fFixedSize;
int32 fItemSize;
BList fItemInfos;