Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
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
protobuf
Commits
f0e08fd4
Commit
f0e08fd4
authored
Feb 19, 2015
by
Jisi Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support maps in NanoPrinter.
parent
709164e7
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
0 deletions
+53
-0
MessageNanoPrinter.java
...ain/java/com/google/protobuf/nano/MessageNanoPrinter.java
+14
-0
NanoTest.java
...nano/src/test/java/com/google/protobuf/nano/NanoTest.java
+39
-0
No files found.
javanano/src/main/java/com/google/protobuf/nano/MessageNanoPrinter.java
View file @
f0e08fd4
...
@@ -35,6 +35,7 @@ import java.lang.reflect.Field;
...
@@ -35,6 +35,7 @@ import java.lang.reflect.Field;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Modifier
;
import
java.lang.reflect.Modifier
;
import
java.util.Map
;
/**
/**
* Static helper methods for printing nano protos.
* Static helper methods for printing nano protos.
...
@@ -170,6 +171,19 @@ public final class MessageNanoPrinter {
...
@@ -170,6 +171,19 @@ public final class MessageNanoPrinter {
indentBuf
.
setLength
(
origIndentBufLength
);
indentBuf
.
setLength
(
origIndentBufLength
);
buf
.
append
(
indentBuf
).
append
(
">\n"
);
buf
.
append
(
indentBuf
).
append
(
">\n"
);
}
}
}
else
if
(
object
instanceof
Map
)
{
Map
<?,?>
map
=
(
Map
<?,?>)
object
;
identifier
=
deCamelCaseify
(
identifier
);
for
(
Map
.
Entry
<?,?>
entry
:
map
.
entrySet
())
{
buf
.
append
(
indentBuf
).
append
(
identifier
).
append
(
" <\n"
);
int
origIndentBufLength
=
indentBuf
.
length
();
indentBuf
.
append
(
INDENT
);
print
(
"key"
,
entry
.
getKey
(),
indentBuf
,
buf
);
print
(
"value"
,
entry
.
getValue
(),
indentBuf
,
buf
);
indentBuf
.
setLength
(
origIndentBufLength
);
buf
.
append
(
indentBuf
).
append
(
">\n"
);
}
}
else
{
}
else
{
// Non-null primitive value
// Non-null primitive value
identifier
=
deCamelCaseify
(
identifier
);
identifier
=
deCamelCaseify
(
identifier
);
...
...
javanano/src/test/java/com/google/protobuf/nano/NanoTest.java
View file @
f0e08fd4
...
@@ -2731,6 +2731,45 @@ public class NanoTest extends TestCase {
...
@@ -2731,6 +2731,45 @@ public class NanoTest extends TestCase {
assertTrue
(
protoPrint
.
contains
(
"id: 33"
));
assertTrue
(
protoPrint
.
contains
(
"id: 33"
));
}
}
public
void
testMessageNanoPrinterForMaps
()
throws
Exception
{
TestMap
msg
=
new
TestMap
();
MessageValue
msgValues
[]
=
new
MessageValue
[]
{
new
MessageValue
(),
new
MessageValue
()
};
msgValues
[
0
].
value
=
1
;
msgValues
[
1
].
value
=
2
;
msg
.
int32ToBytesField
=
new
HashMap
<
Integer
,
byte
[]>();
msg
.
int32ToBytesField
.
put
(
1
,
new
byte
[]
{
'"'
,
'\0'
});
msg
.
int32ToBytesField
.
put
(
2
,
new
byte
[]
{
1
,
8
});
msg
.
stringToInt32Field
=
new
HashMap
<
String
,
Integer
>();
msg
.
stringToInt32Field
.
put
(
"hello"
,
1
);
msg
.
stringToInt32Field
.
put
(
"world"
,
2
);
msg
.
int32ToMessageField
=
new
HashMap
<
Integer
,
MapTestProto
.
TestMap
.
MessageValue
>();
msg
.
int32ToMessageField
.
put
(
0
,
msgValues
[
0
]);
msg
.
int32ToMessageField
.
put
(
1
,
msgValues
[
1
]);
msg
.
int32ToEnumField
=
new
HashMap
<
Integer
,
Integer
>();
msg
.
int32ToEnumField
.
put
(
1
,
2
);
msg
.
int32ToEnumField
.
put
(
2
,
3
);
String
protoPrint
=
msg
.
toString
();
assertTrue
(
protoPrint
.
contains
(
"int32_to_bytes_field <\n key: 1\n value: \"\\\"\\000\"\n>"
));
assertTrue
(
protoPrint
.
contains
(
"int32_to_bytes_field <\n key: 2\n value: \"\\001\\010\"\n>"
));
assertTrue
(
protoPrint
.
contains
(
"string_to_int32_field <\n key: \"hello\"\n value: 1\n>"
));
assertTrue
(
protoPrint
.
contains
(
"string_to_int32_field <\n key: \"world\"\n value: 2\n>"
));
assertTrue
(
protoPrint
.
contains
(
"int32_to_message_field <\n key: 0\n value <\n value: 1\n"
));
assertTrue
(
protoPrint
.
contains
(
"int32_to_message_field <\n key: 1\n value <\n value: 2\n"
));
assertTrue
(
protoPrint
.
contains
(
"int32_to_enum_field <\n key: 1\n value: 2\n>"
));
assertTrue
(
protoPrint
.
contains
(
"int32_to_enum_field <\n key: 2\n value: 3\n>"
));
}
public
void
testExtensions
()
throws
Exception
{
public
void
testExtensions
()
throws
Exception
{
Extensions
.
ExtendableMessage
message
=
new
Extensions
.
ExtendableMessage
();
Extensions
.
ExtendableMessage
message
=
new
Extensions
.
ExtendableMessage
();
message
.
field
=
5
;
message
.
field
=
5
;
...
...
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