Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
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
brpc
Commits
e3782eb8
Commit
e3782eb8
authored
Nov 25, 2020
by
jamesge
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SessionLog to remember session-level kv
parent
a624f995
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
session_log.h
src/brpc/session_log.h
+80
-0
No files found.
src/brpc/session_log.h
0 → 100644
View file @
e3782eb8
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#ifndef BRPC_SESSION_LOG_H
#define BRPC_SESSION_LOG_H
#include "butil/containers/flat_map.h"
namespace
brpc
{
class
SessionLog
{
public
:
class
Formatter
{
public
:
virtual
~
Formatter
()
{}
virtual
void
Print
(
std
::
ostream
&
,
const
SessionLog
&
)
=
0
;
};
typedef
butil
::
FlatMap
<
std
::
string
,
std
::
string
>
Map
;
typedef
Map
::
const_iterator
Iterator
;
SessionLog
()
{}
// Exchange internal fields with another SessionLog.
void
Swap
(
SessionLog
&
rhs
)
{
_entries
.
swap
(
rhs
.
_entries
);
}
// Reset internal fields as if they're just default-constructed.
void
Clear
()
{
_entries
.
clear
();
}
// Get value of a key(case-sensitive)
// Return pointer to the value, NULL on not found.
const
std
::
string
*
Get
(
const
char
*
key
)
const
{
return
_entries
.
seek
(
key
);
}
const
std
::
string
*
Get
(
const
std
::
string
&
key
)
const
{
return
_entries
.
seek
(
key
);
}
// Set value of a key
void
Set
(
const
std
::
string
&
key
,
const
std
::
string
&
value
)
{
GetOrAdd
(
key
)
=
value
;
}
void
Set
(
const
std
::
string
&
key
,
const
char
*
value
)
{
GetOrAdd
(
key
)
=
value
;
}
// Convert other types to string as well
template
<
typename
T
>
void
Set
(
const
std
::
string
&
key
,
const
T
&
value
)
{
GetOrAdd
(
key
)
=
std
::
to_string
(
value
);
}
// Remove a key
void
Remove
(
const
char
*
key
)
{
_entries
.
erase
(
key
);
}
void
Remove
(
const
std
::
string
&
key
)
{
_entries
.
erase
(
key
);
}
// Get iterators to iterate key/value
Iterator
Begin
()
const
{
return
_entries
.
begin
();
}
Iterator
End
()
const
{
return
_entries
.
end
();
}
// number of key/values
size_t
Count
()
const
{
return
_entries
.
size
();
}
private
:
std
::
string
&
GetOrAdd
(
const
std
::
string
&
key
)
{
if
(
!
_entries
.
initialized
())
{
_entries
.
init
(
29
);
}
return
_entries
[
key
];
}
Map
_entries
;
};
}
// namespace brpc
#endif // BRPC_SESSION_LOG_H
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