Package dev.blaauwendraad.masker.json
Class MaskingState
java.lang.Object
dev.blaauwendraad.masker.json.MaskingState
Represents the state of the
JsonMasker
at a given point in time during the JsonMasker.mask(byte[])
operation.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
Represents a delayed replacement that requires resizing of the message byte array.static class
A mutable reference to a sequence of bytes inmessage
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addReplacementOperation
(int startIndex, int endIndex, byte[] mask, int maskRepeat) Adds new delayed replacement operation to the list of operations to be applied to the message.void
Backtracks current jsonpath to the previous segment.byte
byte
int
void
Expands current jsonpath with a new array segment.void
expandCurrentJsonPath
(int start, int offset) Expands current jsonpath with a new "key" segment.Returns the iterator over the json path component references from head to tailbyte[]
Returns the list of replacement operations that need to be applied to the message.int
Returns the total difference between the masks and target values lengths of all replacement operations.void
void
Increments an array index in the last segment of the current jsonpath.boolean
Checks if the last segment of the current jsonpath is an array index.int
void
setCurrentIndex
(int currentIndex) void
setMessage
(byte[] newMessage) toString()
-
Constructor Details
-
MaskingState
public MaskingState(byte[] message, int currentIndex)
-
-
Method Details
-
incrementCurrentIndex
public void incrementCurrentIndex() -
setCurrentIndex
public void setCurrentIndex(int currentIndex) -
setMessage
public void setMessage(byte[] newMessage) -
byteAtCurrentIndex
public byte byteAtCurrentIndex() -
byteAtCurrentIndexMinusOne
public byte byteAtCurrentIndexMinusOne() -
currentIndex
public int currentIndex() -
messageLength
public int messageLength() -
getMessage
public byte[] getMessage() -
addReplacementOperation
public void addReplacementOperation(int startIndex, int endIndex, byte[] mask, int maskRepeat) Adds new delayed replacement operation to the list of operations to be applied to the message. -
getReplacementOperations
Returns the list of replacement operations that need to be applied to the message. -
getReplacementOperationsTotalDifference
public int getReplacementOperationsTotalDifference()Returns the total difference between the masks and target values lengths of all replacement operations. -
expandCurrentJsonPath
public void expandCurrentJsonPath(int start, int offset) Expands current jsonpath with a new "key" segment.- Parameters:
start
- the index of a new segment start inmessage
offset
- the length of a new segment.
-
expandCurrentJsonPath
public void expandCurrentJsonPath()Expands current jsonpath with a new array segment. -
backtrackCurrentJsonPath
public void backtrackCurrentJsonPath()Backtracks current jsonpath to the previous segment. -
isInArray
public boolean isInArray()Checks if the last segment of the current jsonpath is an array index. -
incrementCurrentJsonPathArrayIndex
public void incrementCurrentJsonPathArrayIndex()Increments an array index in the last segment of the current jsonpath. ThrowsIllegalStateException
if the last segment is not an array index. -
getCurrentJsonPath
Returns the iterator over the json path component references from head to tail -
toString
-