Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
74300ac7
Commit
74300ac7
authored
May 10, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Hasher::IsValid()
parent
c040d26c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
5 deletions
+14
-5
schema.h
include/rapidjson/schema.h
+12
-5
schematest.cpp
test/unittest/schematest.cpp
+2
-0
No files found.
include/rapidjson/schema.h
View file @
74300ac7
...
...
@@ -81,7 +81,7 @@ class Hasher {
public
:
typedef
typename
ValueType
::
Ch
Ch
;
Hasher
(
)
:
stack_
(
0
,
kDefaultSize
)
{}
Hasher
(
Allocator
*
allocator
=
0
)
:
stack_
(
allocator
,
kDefaultSize
)
{}
bool
Null
()
{
return
WriteType
(
kNullType
);
}
bool
Bool
(
bool
b
)
{
return
WriteType
(
b
?
kTrueType
:
kFalseType
);
}
...
...
@@ -96,10 +96,12 @@ public:
n
.
d
=
d
;
return
WriteNumber
(
n
);
}
bool
String
(
const
Ch
*
str
,
SizeType
len
,
bool
)
{
WriteBuffer
(
kStringType
,
str
,
len
*
sizeof
(
Ch
));
return
true
;
}
bool
StartObject
()
{
return
true
;
}
bool
Key
(
const
Ch
*
str
,
SizeType
len
,
bool
copy
)
{
return
String
(
str
,
len
,
copy
);
}
bool
EndObject
(
SizeType
memberCount
)
{
...
...
@@ -110,6 +112,7 @@ public:
*
stack_
.
template
Push
<
uint64_t
>
()
=
h
;
return
true
;
}
bool
StartArray
()
{
return
true
;
}
bool
EndArray
(
SizeType
elementCount
)
{
uint64_t
h
=
Hash
(
0
,
kArrayType
);
...
...
@@ -120,8 +123,10 @@ public:
return
true
;
}
bool
IsValid
()
const
{
return
stack_
.
GetSize
()
==
sizeof
(
uint64_t
);
}
uint64_t
GetHashCode
()
const
{
RAPIDJSON_ASSERT
(
stack_
.
GetSize
()
==
sizeof
(
uint64_t
));
RAPIDJSON_ASSERT
(
IsValid
(
));
return
*
stack_
.
template
Top
<
uint64_t
>
();
}
...
...
@@ -135,9 +140,11 @@ private:
double
d
;
};
bool
WriteType
(
unsigned
char
type
)
{
WriteBuffer
(
type
,
0
,
0
);
return
true
;
}
bool
WriteNumber
(
const
Number
&
n
)
{
WriteBuffer
(
kNumberType
,
&
n
,
sizeof
(
n
));
return
true
;
}
bool
WriteBuffer
(
unsigned
char
type
,
const
void
*
data
,
size_t
len
)
{
bool
WriteType
(
Type
type
)
{
return
WriteBuffer
(
type
,
0
,
0
);
}
bool
WriteNumber
(
const
Number
&
n
)
{
return
WriteBuffer
(
kNumberType
,
&
n
,
sizeof
(
n
));
}
bool
WriteBuffer
(
Type
type
,
const
void
*
data
,
size_t
len
)
{
// FNV-1a from http://isthe.com/chongo/tech/comp/fnv/
uint64_t
h
=
Hash
(
RAPIDJSON_UINT64_C2
(
0x84222325
,
0xcbf29ce4
),
type
);
const
unsigned
char
*
d
=
static_cast
<
const
unsigned
char
*>
(
data
);
...
...
test/unittest/schematest.cpp
View file @
74300ac7
...
...
@@ -27,6 +27,8 @@ using namespace rapidjson;
internal::Hasher<Value, CrtAllocator> h1, h2;\
d1.Accept(h1);\
d2.Accept(h2);\
ASSERT_TRUE(h1.IsValid());\
ASSERT_TRUE(h2.IsValid());\
/*printf("%s: 0x%016llx\n%s: 0x%016llx\n\n", json1, h1.GetHashCode(), json2, h2.GetHashCode());*/
\
EXPECT_TRUE(expected == (h1.GetHashCode() == h2.GetHashCode()));\
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment