mirror of
https://github.com/aziascreations/PB-MessagePack.git
synced 2026-11-24 10:18:46 +01:00
Implemented FastNumericPeekPoke
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
[submodule "Includes/PB-Endianness"]
|
||||
path = Includes/PB-Endianness
|
||||
url = https://github.com/aziascreations/PB-Endianness.git
|
||||
[submodule "Includes/PB-FastNumericPeekPoke"]
|
||||
path = Includes/PB-FastNumericPeekPoke
|
||||
url = https://github.com/aziascreations/PB-FastNumericPeekPoke.git
|
||||
|
||||
@@ -417,6 +417,7 @@ or subtract each top-level field's `MsgPackGetFieldFullSize` from the buffer's s
|
||||
* `Includes/MessagePack.pbi` - Main file, only includes the others.
|
||||
* `Includes/_*.pbi` - One file per family. (Allocators, Literals, Primitives, Strings, ...)
|
||||
* `Includes/PB-Endianness/` - Git submodule, don't edit it from here.
|
||||
* `Includes/PB-FastNumericPeekPoke/` - Git submodule, don't edit it from here. Use `FastPeekX()`/`FastPokeX()` instead of the numeric `PeekX()`/`PokeX()`.
|
||||
* `UnitTests/` - One folder per family, numbered like the includes' order.
|
||||
* `Examples/` - One folder per example, with a `.pb` of the same name.
|
||||
* `PerfTests/` - Benchmarks, one folder per workload, each with a `RunPerfTests.ps1`.
|
||||
|
||||
Submodule
+1
Submodule Includes/PB-FastNumericPeekPoke added at 4b71366a45
+12
-12
@@ -107,16 +107,16 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteSizedFieldHeader(*MsgPackData.MsgPackDa
|
||||
|
||||
Select SizeFieldByteLength
|
||||
Case 0
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | DataSize)
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | DataSize)
|
||||
Case 1
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, DataSize)
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, DataSize)
|
||||
Case 2
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
PokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(DataSize))
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(DataSize))
|
||||
Case 4
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
PokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(DataSize))
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(DataSize))
|
||||
EndSelect
|
||||
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 + SizeFieldByteLength
|
||||
|
||||
@@ -181,7 +181,7 @@ Procedure.MsgPack_ErrorCode _MsgPackReadSizedFieldHeader(*MsgPackData.MsgPackDat
|
||||
|
||||
FormatCode = MsgPackGetFormatCode(*MsgPackData)
|
||||
If MsgPackFormatCodeToDataType(FormatCode) <> ExpectedDataType
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
|
||||
ProcedureReturn #MsgPack_Error_InvalidFormatCode
|
||||
EndIf
|
||||
@@ -227,14 +227,14 @@ Procedure.MsgPack_ErrorCode _MsgPackReadSizedFieldHeader(*MsgPackData.MsgPackDat
|
||||
Case 0:
|
||||
; FixExt sizes were already set above.
|
||||
If FormatCode = #MsgPack_FormatCode_FixStr
|
||||
DataSize = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) & %00011111
|
||||
DataSize = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) & %00011111
|
||||
EndIf
|
||||
Case 1:
|
||||
DataSize = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
|
||||
DataSize = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
|
||||
Case 2:
|
||||
DataSize = EndianSwapU16(PeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
DataSize = EndianSwapU16(FastPeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
Case 4:
|
||||
DataSize = EndianSwapI32(PeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
|
||||
DataSize = EndianSwapI32(FastPeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
|
||||
EndSelect
|
||||
|
||||
If Not _MsgPackHasSpaceLeft(*MsgPackData, 1 + SizeFieldByteLength + ExtTypeByteLength + DataSize)
|
||||
|
||||
@@ -34,6 +34,12 @@ CompilerIf Not Defined(_NibblePoker_Endianness_WasIncluded, #PB_Constant) And No
|
||||
XIncludeFile "./PB-Endianness/Includes/Endianness.pbi"
|
||||
CompilerEndIf
|
||||
|
||||
; Skipped if "FastNumericPeekPoke.pbi" was already included from another path, by the program or another include.
|
||||
; Its procedures are only used on the C backend with "/OPTIMIZER", they alias the built-ins otherwise.
|
||||
CompilerIf Not Defined(_NibblePoker_FastNumericPeekPoke_WasIncluded, #PB_Constant)
|
||||
XIncludeFile "./PB-FastNumericPeekPoke/Includes/FastNumericPeekPoke.pbi"
|
||||
CompilerEndIf
|
||||
|
||||
|
||||
|
||||
; ------------------------------------------------------------------------------
|
||||
|
||||
@@ -96,7 +96,7 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteExtField(*MsgPackData.MsgPackData, Form
|
||||
ProcedureReturn ErrorCode
|
||||
EndIf
|
||||
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
|
||||
Else
|
||||
ErrorCode = _MsgPackWriteSizedFieldHeader(*MsgPackData, FormatCode, SizeFieldByteLength, DataSize, 1, *Data)
|
||||
@@ -105,7 +105,7 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteExtField(*MsgPackData.MsgPackData, Form
|
||||
EndIf
|
||||
EndIf
|
||||
|
||||
PokeB(*MsgPackData\Buffer + *MsgPackData\BufferOffset, ExtType)
|
||||
FastPokeB(*MsgPackData\Buffer + *MsgPackData\BufferOffset, ExtType)
|
||||
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
|
||||
|
||||
If DataSize > 0
|
||||
@@ -133,7 +133,7 @@ Procedure.b MsgPackGetExtensionType(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn 0
|
||||
EndIf
|
||||
|
||||
ProcedureReturn PeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset + HeaderSize - 1)
|
||||
ProcedureReturn FastPeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset + HeaderSize - 1)
|
||||
EndProcedure
|
||||
|
||||
|
||||
|
||||
+20
-20
@@ -46,7 +46,7 @@ XIncludeFile "./_Binary.pbi"
|
||||
; `XXX` is the format code bits and `YYYYY` the value's dynamic size.
|
||||
; Applies to: FixStr, FixArray, FixMap
|
||||
; Remark: Doesn't apply to FixInt variants since those have their own function for extracting the value.
|
||||
Macro _MsgPackGetFieldDynamicSize_Within(MsgPackData, Mask) : (PeekA(MsgPackData\Buffer + MsgPackData\BufferOffset) & Mask) : EndMacro
|
||||
Macro _MsgPackGetFieldDynamicSize_Within(MsgPackData, Mask) : (FastPeekA(MsgPackData\Buffer + MsgPackData\BufferOffset) & Mask) : EndMacro
|
||||
|
||||
; Returns the field's dynamic size based on the byte right after the format code.
|
||||
; Applies to: Str8, Bin8, Ext8
|
||||
@@ -57,7 +57,7 @@ Procedure.q _MsgPackGetFieldDynamicSize_1After(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn #MsgPack_InvalidSize
|
||||
EndIf
|
||||
|
||||
ProcedureReturn PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
|
||||
ProcedureReturn FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
|
||||
EndProcedure
|
||||
|
||||
; Returns the field's dynamic size based on the 2 bytes right after the format code.
|
||||
@@ -69,7 +69,7 @@ Procedure.q _MsgPackGetFieldDynamicSize_2After(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn #MsgPack_InvalidSize
|
||||
EndIf
|
||||
|
||||
ProcedureReturn EndianSwapU(PeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
ProcedureReturn EndianSwapU(FastPeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
EndProcedure
|
||||
|
||||
; Returns the field's dynamic size based on the 4 bytes right after the format code.
|
||||
@@ -81,7 +81,7 @@ Procedure.q _MsgPackGetFieldDynamicSize_4After(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn #MsgPack_InvalidSize
|
||||
EndIf
|
||||
|
||||
ProcedureReturn EndianSwapL(PeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
|
||||
ProcedureReturn EndianSwapL(FastPeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
|
||||
EndProcedure
|
||||
|
||||
; Returns a given format code's spacing info based on itself and the data in the given MsgPack buffer.
|
||||
@@ -110,20 +110,20 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
|
||||
Select ExaminedDataType
|
||||
Case #MsgPack_FormatCode_FixStr:
|
||||
If *VariableSizeQ <> #Null
|
||||
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00011111))
|
||||
FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00011111))
|
||||
EndIf
|
||||
If *ValueStartOffsetB <> #Null
|
||||
PokeB(*ValueStartOffsetB, 1)
|
||||
FastPokeB(*ValueStartOffsetB, 1)
|
||||
EndIf
|
||||
ProcedureReturn #True
|
||||
|
||||
Case #MsgPack_FormatCode_FixArray,
|
||||
#MsgPack_FormatCode_FixMap:
|
||||
If *VariableSizeQ <> #Null
|
||||
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00001111))
|
||||
FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_Within(*MsgPackData, %00001111))
|
||||
EndIf
|
||||
If *ValueStartOffsetB <> #Null
|
||||
PokeB(*ValueStartOffsetB, 1)
|
||||
FastPokeB(*ValueStartOffsetB, 1)
|
||||
EndIf
|
||||
ProcedureReturn #True
|
||||
|
||||
@@ -132,10 +132,10 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
|
||||
#MsgPack_FormatCode_Str8,
|
||||
#MsgPack_FormatCode_Bin8:
|
||||
If *VariableSizeQ <> #Null
|
||||
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_1After(*MsgPackData))
|
||||
FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_1After(*MsgPackData))
|
||||
EndIf
|
||||
If *ValueStartOffsetB <> #Null
|
||||
PokeB(*ValueStartOffsetB, 2)
|
||||
FastPokeB(*ValueStartOffsetB, 2)
|
||||
EndIf
|
||||
ProcedureReturn #True
|
||||
|
||||
@@ -146,10 +146,10 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
|
||||
#MsgPack_FormatCode_Array16,
|
||||
#MsgPack_FormatCode_Map16:
|
||||
If *VariableSizeQ <> #Null
|
||||
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_2After(*MsgPackData))
|
||||
FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_2After(*MsgPackData))
|
||||
EndIf
|
||||
If *ValueStartOffsetB <> #Null
|
||||
PokeB(*ValueStartOffsetB, 3)
|
||||
FastPokeB(*ValueStartOffsetB, 3)
|
||||
EndIf
|
||||
ProcedureReturn #True
|
||||
|
||||
@@ -160,19 +160,19 @@ Procedure _MsgPackGetFieldSpacingInfo(*MsgPackData.MsgPackData, ExaminedDataType
|
||||
#MsgPack_FormatCode_Array32,
|
||||
#MsgPack_FormatCode_Map32:
|
||||
If *VariableSizeQ <> #Null
|
||||
PokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_4After(*MsgPackData))
|
||||
FastPokeQ(*VariableSizeQ, _MsgPackGetFieldDynamicSize_4After(*MsgPackData))
|
||||
EndIf
|
||||
If *ValueStartOffsetB <> #Null
|
||||
PokeB(*ValueStartOffsetB, 5)
|
||||
FastPokeB(*ValueStartOffsetB, 5)
|
||||
EndIf
|
||||
ProcedureReturn #True
|
||||
|
||||
Default:
|
||||
If *VariableSizeQ <> #Null
|
||||
PokeQ(*VariableSizeQ, #MsgPack_InvalidSize)
|
||||
FastPokeQ(*VariableSizeQ, #MsgPack_InvalidSize)
|
||||
EndIf
|
||||
If *ValueStartOffsetB <> #Null
|
||||
PokeB(*ValueStartOffsetB, #MsgPack_InvalidSize)
|
||||
FastPokeB(*ValueStartOffsetB, #MsgPack_InvalidSize)
|
||||
EndIf
|
||||
ProcedureReturn #False
|
||||
EndSelect
|
||||
@@ -269,7 +269,7 @@ Procedure.MsgPack_ErrorCode _MsgPackGetFieldLayout(*MsgPackData.MsgPackData, *He
|
||||
*ChildCount\q = ChildCount
|
||||
|
||||
Default:
|
||||
Debug("Invalid format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
Debug("Invalid format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
|
||||
ProcedureReturn #MsgPack_Error_InvalidFormatCode
|
||||
EndSelect
|
||||
@@ -341,7 +341,7 @@ Procedure.MsgPack_ErrorCode _MsgPackSkipFields(*MsgPackData.MsgPackData, FieldCo
|
||||
EndIf
|
||||
|
||||
; Arrays and maps are at depth `Level + 1` from the structure's content.
|
||||
FormatByte = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
|
||||
FormatByte = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
|
||||
If _MsgPackIsContainerFormatByte(FormatByte) And *MsgPackData\IteratorDepth + Level + 1 > #MsgPack_MaxDepth
|
||||
Debug("Arrays and maps are nested deeper than " + Str(#MsgPack_MaxDepth) + " levels !")
|
||||
*MsgPackData\LastError = #MsgPack_Error_MaxDepthExceeded
|
||||
@@ -424,7 +424,7 @@ Procedure.q MsgPackGetEntryCount(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn ChildCount / 2
|
||||
EndSelect
|
||||
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
|
||||
ProcedureReturn #MsgPack_InvalidSize
|
||||
EndProcedure
|
||||
@@ -486,7 +486,7 @@ Procedure.i MsgPackExamine(*MsgPackData.MsgPackData, ExaminationOptions.MsgPack_
|
||||
DataType = MsgPackFormatCodeToDataType(MsgPackGetFormatCode(*MsgPackData))
|
||||
If DataType <> #MsgPack_DataTypes_Array And DataType <> #MsgPack_DataTypes_Map
|
||||
Debug("Attempted to examine format code 0x" +
|
||||
RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
|
||||
RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
|
||||
" as if it was an array or map !")
|
||||
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
|
||||
ProcedureReturn #Null
|
||||
|
||||
@@ -72,13 +72,13 @@ Procedure.b MsgPackReadBoolean(*MsgPackData.MsgPackData)
|
||||
|
||||
; We don't check if we're 1 byte off the end since the previous check implies it.
|
||||
|
||||
If PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_False
|
||||
If FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_False
|
||||
If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterRead)
|
||||
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
|
||||
EndIf
|
||||
|
||||
ProcedureReturn #False
|
||||
ElseIf PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_True
|
||||
ElseIf FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) = #MsgPack_FormatCode_True
|
||||
If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterRead)
|
||||
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
|
||||
EndIf
|
||||
@@ -86,7 +86,7 @@ Procedure.b MsgPackReadBoolean(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn #True
|
||||
Else
|
||||
Debug("The format code isn't the one for a boolean ! (" +
|
||||
RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
|
||||
RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
|
||||
" vs "+ RSet(Hex(#MsgPack_FormatCode_False), 2, "0") +
|
||||
"/"+ RSet(Hex(#MsgPack_FormatCode_True), 2, "0") + ")")
|
||||
|
||||
@@ -128,7 +128,7 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteLiteral(*MsgPackData.MsgPackData, Liter
|
||||
EndIf
|
||||
EndIf
|
||||
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, LiteralFormatCode)
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, LiteralFormatCode)
|
||||
|
||||
If _MsgPackHasFlag(*MsgPackData, #MsgPack_DataFlags_MoveOffsetAfterWrite)
|
||||
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1
|
||||
|
||||
+23
-23
@@ -91,9 +91,9 @@ Procedure.MsgPack_ErrorCode _MsgPackExpectRead(*MsgPackData.MsgPackData, FormatC
|
||||
ProcedureReturn #MsgPack_Error_AtOrPastTheEndOfBuffer
|
||||
EndIf
|
||||
|
||||
If PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) <> FormatCode
|
||||
If FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset) <> FormatCode
|
||||
Debug("Unexpected format code ! (" +
|
||||
RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
|
||||
RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") +
|
||||
" vs "+ RSet(Hex(FormatCode), 2, "0") + ")")
|
||||
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
|
||||
ProcedureReturn #MsgPack_Error_InvalidFormatCode
|
||||
@@ -134,19 +134,19 @@ Procedure.MsgPack_ErrorCode _MsgPackWriteFixedField(*MsgPackData.MsgPackData, Fo
|
||||
|
||||
Select ValueByteLength
|
||||
Case 0
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | (Value & $FF))
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode | (Value & $FF))
|
||||
Case 1
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, Value)
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, Value)
|
||||
Case 2
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
PokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(Value))
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapU16(Value))
|
||||
Case 4
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
PokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(Value))
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI32(Value))
|
||||
Case 8
|
||||
PokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
PokeQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI64(Value))
|
||||
FastPokeA(*MsgPackData\Buffer + *MsgPackData\BufferOffset, FormatCode)
|
||||
FastPokeQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1, EndianSwapI64(Value))
|
||||
EndSelect
|
||||
*MsgPackData\BufferOffset = *MsgPackData\BufferOffset + 1 + ValueByteLength
|
||||
_MsgPackRewindOffsetAfterWrite(*MsgPackData, 1 + ValueByteLength)
|
||||
@@ -168,13 +168,13 @@ Procedure.q _MsgPackReadFixedField(*MsgPackData.MsgPackData, FormatCode.MsgPack_
|
||||
|
||||
Select ValueByteLength
|
||||
Case 1
|
||||
ReturnedValue = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
|
||||
ReturnedValue = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)
|
||||
Case 2
|
||||
ReturnedValue = EndianSwapU16(PeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
ReturnedValue = EndianSwapU16(FastPeekU(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
Case 4
|
||||
ReturnedValue = EndianSwapI32(PeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
|
||||
ReturnedValue = EndianSwapI32(FastPeekL(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1)) & $FFFFFFFF
|
||||
Case 8
|
||||
ReturnedValue = EndianSwapI64(PeekQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
ReturnedValue = EndianSwapI64(FastPeekQ(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1))
|
||||
EndSelect
|
||||
_MsgPackMoveOffsetAfterRead(*MsgPackData, 1 + ValueByteLength)
|
||||
|
||||
@@ -359,7 +359,7 @@ Procedure.q MsgPackReadInteger(*MsgPackData.MsgPackData)
|
||||
Case #MsgPack_FormatCode_FixIntPositive,
|
||||
#MsgPack_FormatCode_FixIntNegative:
|
||||
; The whole byte is the value, both ranges are valid signed bytes.
|
||||
ReturnedValue = PeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
|
||||
ReturnedValue = FastPeekB(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
|
||||
_MsgPackMoveOffsetAfterRead(*MsgPackData, 1)
|
||||
*MsgPackData\LastError = #MsgPack_Error_Success
|
||||
ProcedureReturn ReturnedValue
|
||||
@@ -370,7 +370,7 @@ Procedure.q MsgPackReadInteger(*MsgPackData.MsgPackData)
|
||||
Case #MsgPack_FormatCode_UInt32:
|
||||
ProcedureReturn _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_UInt32, 4)
|
||||
Case #MsgPack_FormatCode_UInt64:
|
||||
If _MsgPackHasSpaceLeft(*MsgPackData, 9) And (PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1) & $80)
|
||||
If _MsgPackHasSpaceLeft(*MsgPackData, 9) And (FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset + 1) & $80)
|
||||
Debug("UInt64 value doesn't fit in a signed quad !")
|
||||
*MsgPackData\LastError = #MsgPack_Error_ValueOverflow
|
||||
ProcedureReturn 0
|
||||
@@ -386,7 +386,7 @@ Procedure.q MsgPackReadInteger(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn MsgPackReadInt64(*MsgPackData)
|
||||
EndSelect
|
||||
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
|
||||
ProcedureReturn 0
|
||||
EndProcedure
|
||||
@@ -397,14 +397,14 @@ EndProcedure
|
||||
; The value's bits are moved and swapped as an integer, since loading a byte-swapped
|
||||
; float into the FPU can alter its bits. (e.g.: NaN quieting on x87)
|
||||
Procedure.MsgPack_ErrorCode MsgPackWriteFloat32(*MsgPackData.MsgPackData, Value.f)
|
||||
ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4, PeekL(@Value))
|
||||
ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4, FastPeekL(@Value))
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure.f MsgPackReadFloat32(*MsgPackData.MsgPackData)
|
||||
Protected ReturnedValue.f
|
||||
|
||||
PokeL(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4))
|
||||
FastPokeL(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float32, 4))
|
||||
|
||||
ProcedureReturn ReturnedValue
|
||||
EndProcedure
|
||||
@@ -415,14 +415,14 @@ EndProcedure
|
||||
; The value's bits are moved and swapped as an integer, since loading a byte-swapped
|
||||
; float into the FPU can alter its bits. (e.g.: NaN quieting on x87)
|
||||
Procedure.MsgPack_ErrorCode MsgPackWriteFloat64(*MsgPackData.MsgPackData, Value.d)
|
||||
ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8, PeekQ(@Value))
|
||||
ProcedureReturn _MsgPackWriteFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8, FastPeekQ(@Value))
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure.d MsgPackReadFloat64(*MsgPackData.MsgPackData)
|
||||
Protected ReturnedValue.d
|
||||
|
||||
PokeQ(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8))
|
||||
FastPokeQ(@ReturnedValue, _MsgPackReadFixedField(*MsgPackData, #MsgPack_FormatCode_Float64, 8))
|
||||
|
||||
ProcedureReturn ReturnedValue
|
||||
EndProcedure
|
||||
@@ -454,7 +454,7 @@ Procedure.d MsgPackReadFloat(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn MsgPackReadFloat64(*MsgPackData)
|
||||
EndSelect
|
||||
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
Debug("Unexpected format code ! (" + RSet(Hex(FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)), 2, "0") + ")")
|
||||
*MsgPackData\LastError = #MsgPack_Error_InvalidFormatCode
|
||||
ProcedureReturn 0
|
||||
EndProcedure
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ Procedure.MsgPack_FormatCode MsgPackGetFormatCode(*MsgPackData.MsgPackData)
|
||||
ProcedureReturn #MsgPack_FormatCode_Invalid
|
||||
EndIf
|
||||
|
||||
DataFormatCode = PeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
|
||||
DataFormatCode = FastPeekA(*MsgPackData\Buffer + *MsgPackData\BufferOffset)
|
||||
|
||||
If DataFormatCode < $80
|
||||
; 0x00 - 0x7F
|
||||
|
||||
Reference in New Issue
Block a user