@@ -29,6 +29,9 @@ public class MessagePackParser extends ParserMinimalBase {
2929 private final LinkedList <StackItem > stack = new LinkedList <StackItem >();
3030 private final ValueHolder valueHolder = new ValueHolder ();
3131 private boolean isClosed ;
32+ private long tokenPosition ;
33+ private long currentPosition ;
34+ private final IOContext ioContext ;
3235
3336 private static abstract class StackItem {
3437 private long numOfElements ;
@@ -67,6 +70,7 @@ public MessagePackParser(IOContext ctxt, int features, byte[] bytes) throws IOEx
6770 }
6871
6972 private MessagePackParser (IOContext ctxt , int features , MessageBufferInput input ) throws IOException {
73+ ioContext = ctxt ;
7074 DupDetector dups = Feature .STRICT_DUPLICATE_DETECTION .enabledIn (features )
7175 ? DupDetector .rootDetector (this ) : null ;
7276 parsingContext = JsonReadContext .createRootContext (dups );
@@ -99,6 +103,8 @@ public Version version() {
99103 @ Override
100104 public JsonToken nextToken () throws IOException , JsonParseException {
101105 MessageUnpacker messageUnpacker = getMessageUnpacker ();
106+ tokenPosition = messageUnpacker .getTotalReadBytes ();
107+
102108 JsonToken nextToken = null ;
103109 if (parsingContext .inObject () || parsingContext .inArray ()) {
104110 if (stack .getFirst ().isEmpty ()) {
@@ -158,6 +164,7 @@ public JsonToken nextToken() throws IOException, JsonParseException {
158164 default :
159165 throw new IllegalStateException ("Shouldn't reach here" );
160166 }
167+ currentPosition = messageUnpacker .getTotalReadBytes ();
161168
162169 if (parsingContext .inObject () && nextToken != JsonToken .FIELD_NAME || parsingContext .inArray ()) {
163170 stack .getFirst ().consume ();
@@ -302,17 +309,27 @@ public JsonStreamContext getParsingContext() {
302309
303310 @ Override
304311 public JsonLocation getTokenLocation () {
305- throw new UnsupportedOperationException ( "Not implemented yet" );
312+ return new JsonLocation ( ioContext . getSourceReference (), tokenPosition , - 1 , - 1 , ( int ) tokenPosition );
306313 }
307314
308315 @ Override
309316 public JsonLocation getCurrentLocation () {
310- throw new UnsupportedOperationException ( "Not implemented yet" );
317+ return new JsonLocation ( ioContext . getSourceReference (), currentPosition , - 1 , - 1 , ( int ) currentPosition );
311318 }
312319
313320 @ Override
314321 public void overrideCurrentName (String name ) {
315- throw new UnsupportedOperationException ("Not implemented yet" );
322+ try {
323+ if (_currToken == JsonToken .START_OBJECT || _currToken == JsonToken .START_ARRAY ) {
324+ JsonReadContext parent = parsingContext .getParent ();
325+ parent .setCurrentName (name );
326+ }
327+ else {
328+ parsingContext .setCurrentName (name );
329+ }
330+ } catch (JsonProcessingException e ) {
331+ throw new IllegalStateException (e );
332+ }
316333 }
317334
318335 @ Override public String getCurrentName () throws IOException {
0 commit comments