Skip to content

Question about SimdJsonParser and JsonValue. #36

Open
@ZhaiMo15

Description

@ZhaiMo15

I'm running code below:

private final SimdJsonParser simdJsonParser = new SimdJsonParser();
String str1 = "{\"a\": \"1\", \"b\": \"11\", \"c\": \"111\"}";
byte[] buffer1 = str1.getBytes();
JsonValue simdJsonValue1 = simdJsonParser.parse(buffer1, buffer1.length);
System.out.println("a = " + simdJsonValue1.get("a").toString() + 
                   ", b = " + simdJsonValue1.get("b").toString() + 
                   ", c = " + simdJsonValue1.get("c").toString());

String str2 = "{\"a\": \"2\", \"b\": \"22\", \"c\": \"222\"}";
byte[] buffer2 = str2.getBytes();
JsonValue simdJsonValue2 = simdJsonParser.parse(buffer2, buffer2.length);
System.out.println("a = " + simdJsonValue2.get("a").toString() + 
                   ", b = " + simdJsonValue2.get("b").toString() + 
                   ", c = " + simdJsonValue2.get("c").toString());


System.out.println("a = " + simdJsonValue1.get("a").toString() + 
                   ", b = " + simdJsonValue1.get("b").toString() + 
                   ", c = " + simdJsonValue1.get("c").toString());

And the output is

a = 1, b = 11, c = 111
a = 2, b = 22, c = 222
a = 2, b = 22, c = 222

It looks like all the JsonValue share the same buffer if they are parsed by same parser.
What can I do to save the independent JsonValue for different buffer(JSON string)?

Plus, I don't think new SimdJsonParser for each JSON string is a good idea, cuz it costs performance and memory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions