Skip to content

Commit a3413df

Browse files
Get rid of StampFixed base class. It makes code more comples, instead of making it more simple
1 parent e42555e commit a3413df

File tree

4 files changed

+17
-29
lines changed

4 files changed

+17
-29
lines changed

blobstamper/stamp.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
*
3-
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
3+
* Copyright 2021-2023 Nikolay Shaplov (Postgres Professional)
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -107,15 +107,6 @@ StampBaseV<T>::ExtractBin(Blob &blob)
107107
return v;
108108
}
109109

110-
class StampFixed : public virtual StampBase
111-
{
112-
protected:
113-
int size;
114-
public:
115-
virtual int minSize() override {return size;}
116-
virtual int maxSize() override {return size;}
117-
};
118-
119110
class StampVariated : public virtual StampBase
120111
{
121112
protected:

blobstamper/stamp_arithm.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
#include "helpers.h"
2424
#include "stamp.h"
2525

26-
template<class T> class StampArithm: public StampFixed, public StampBaseStr, public StampBaseV<T>
26+
template<class T> class StampArithm: public StampBaseStr, public StampBaseV<T>
2727
{
2828
public:
29-
StampArithm() { size = sizeof(T);};
29+
virtual int minSize() override {return sizeof(T);}
30+
virtual int maxSize() override {return sizeof(T);}
3031
virtual std::string ExtractStr(Blob &blob) override;
3132
virtual T ExtractValue(Blob &blob) override;
3233
};

blobstamper/stamp_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include "stamp_arithm.h"
2727
#include "dict.h"
2828

29-
class StampDict: public StampFixed, public StampBaseStr
29+
class StampDict: public StampBaseStr
3030
{
3131
protected:
3232
StampArithm<unsigned char> stamp8;

t/test-chars-stamps.h

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/******************************************************************************
22
*
3-
* Copyright 2021 Nikolay Shaplov (Postgres Professional)
3+
* Copyright 2021-2023 Nikolay Shaplov (Postgres Professional)
44
*
55
* Licensed under the Apache License, Version 2.0 (the "License");
66
* you may not use this file except in compliance with the License.
@@ -19,39 +19,35 @@
1919
/* This stamps chops first two bytes and treat them as string */
2020
/* Never do this in real live, as blob is binary and may have \0 in the middle of it*/
2121

22-
class StampTwoChars: public StampFixed, public StampBaseStr
22+
class StampTwoChars: public StampBaseStr
2323
{
2424
public:
25-
StampTwoChars();
2625
std::string ExtractStr(Blob &blob) override;
27-
};
26+
virtual int minSize() override {return 2;} /* This stamp shifts two characters only */
27+
virtual int maxSize() override {return 2;} /* This stamp shifts two characters only */
2828

29-
StampTwoChars::StampTwoChars() : StampFixed()
30-
{
31-
size = 2; /* This stamp shifts two characters only */
32-
}
29+
};
3330

3431
std::string
3532
StampTwoChars::ExtractStr(Blob &blob)
3633
{
37-
char * buf;
38-
size_t buf_size;
34+
/* Chopping suitable data chunk from blob */
35+
std::vector<char> data = blob.ChopBlank(*this);
3936

40-
Blob blob2 = blob.ShiftBytes(size);
41-
if (blob2.isEmpty())
42-
return "";
37+
size_t buf_size = data.size() + 1;
38+
char * buf = (char *) malloc(buf_size);
39+
memcpy(buf, &data[0], data.size());
40+
buf[buf_size-1] = '\0';
4341

4442
/* Save shited data as string */
4543
/* NEVER do this in prod, as in real live blob is binary and may have 0 in the middle of it */
46-
blob2.DataDup(buf, buf_size);
47-
buf = (char *) realloc((void *)buf, buf_size + 1);
48-
buf[buf_size] = '\0';
4944
std::string res = buf;
5045
free(buf);
5146

5247
return res;
5348
}
5449

50+
/*****************************************************************************/
5551
class StampSeveralChars: public StampVariated, public StampBaseStr
5652
{
5753
public:

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy