Fixed tiny issues, Added test

This commit is contained in:
2026-10-12 20:43:04 +02:00
parent 0b65e3949f
commit 9d7f45e1fc
6 changed files with 82 additions and 16 deletions
+12 -12
View File
@@ -85,11 +85,11 @@ Procedure.MsgPack_ErrorCode MsgPackWriteBin8(*MsgPackData.MsgPackData, *Buffer,
*MsgPackData\LastError = #MsgPack_Error_Success
If BufferSize < 0
CompilerWarning("Received negative size !")
DebuggerWarning("Received negative size !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsNegative
ProcedureReturn *MsgPackData\LastError
ElseIf BufferSize > 255
CompilerWarning("Binary buffer is bigger than `(2^8)-1` bytes !")
DebuggerWarning("Binary buffer is bigger than `(2^8)-1` bytes !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsTooBig
ProcedureReturn *MsgPackData\LastError
EndIf
@@ -128,11 +128,11 @@ Procedure.MsgPack_ErrorCode MsgPackWriteBin16(*MsgPackData.MsgPackData, *Buffer,
*MsgPackData\LastError = #MsgPack_Error_Success
If BufferSize < 0
CompilerWarning("Received negative size !")
DebuggerWarning("Received negative size !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsNegative
ProcedureReturn *MsgPackData\LastError
ElseIf BufferSize > 65535
CompilerWarning("Binary buffer is bigger than `(2^16)-1` bytes !")
DebuggerWarning("Binary buffer is bigger than `(2^16)-1` bytes !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsTooBig
ProcedureReturn *MsgPackData\LastError
EndIf
@@ -160,7 +160,7 @@ Procedure.MsgPack_ErrorCode MsgPackWriteBin16(*MsgPackData.MsgPackData, *Buffer,
EndProcedure
Procedure.MsgPack_ErrorCode MsgPackWriteBin16(*MsgPackData.MsgPackData, *Buffer, BufferSize.q)
Procedure.MsgPack_ErrorCode MsgPackWriteBin32(*MsgPackData.MsgPackData, *Buffer, BufferSize.q)
CompilerIf Not #MsgPack_DisableNullChecks
If Not *MsgPackData
DebuggerError("A #Null MsgPackData pointer was passed !")
@@ -171,11 +171,11 @@ Procedure.MsgPack_ErrorCode MsgPackWriteBin16(*MsgPackData.MsgPackData, *Buffer,
*MsgPackData\LastError = #MsgPack_Error_Success
If BufferSize < 0
CompilerWarning("Received negative size !")
DebuggerWarning("Received negative size !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsNegative
ProcedureReturn *MsgPackData\LastError
ElseIf BufferSize > 4294967295
CompilerWarning("Binary buffer is bigger than `(2^32)-1` bytes !")
DebuggerWarning("Binary buffer is bigger than `(2^32)-1` bytes !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsTooBig
ProcedureReturn *MsgPackData\LastError
EndIf
@@ -205,17 +205,17 @@ EndProcedure
Procedure.MsgPack_ErrorCode MsgPackWriteBinary(*MsgPackData.MsgPackData, *Buffer, BufferSize.q)
If BufferSize < 0
CompilerWarning("Received negative size !")
DebuggerWarning("Received negative size !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsNegative
ProcedureReturn *MsgPackData\LastError
ElseIf BufferSize <= 255
ProcedureReturn MsgPackWriteBin8(MsgPackData, *Buffer, BufferSize)
ProcedureReturn MsgPackWriteBin8(*MsgPackData, *Buffer, BufferSize)
ElseIf BufferSize <= 65535
ProcedureReturn MsgPackWriteBin16(MsgPackData, *Buffer, BufferSize)
ProcedureReturn MsgPackWriteBin16(*MsgPackData, *Buffer, BufferSize)
ElseIf BufferSize <= 4294967295
ProcedureReturn MsgPackWriteBin32(MsgPackData, *Buffer, BufferSize)
ProcedureReturn MsgPackWriteBin32(*MsgPackData, *Buffer, BufferSize)
Else
CompilerWarning("Binary buffer is bigger than `(2^32)-1` bytes !")
DebuggerWarning("Binary buffer is bigger than `(2^32)-1` bytes !")
*MsgPackData\LastError = #MsgPack_Error_BinaryDataSizeIsTooBig
ProcedureReturn *MsgPackData\LastError
EndIf
+10 -2
View File
@@ -41,8 +41,16 @@ XIncludeFile "./_Allocators.pbi"
;-> Utils
Procedure MsgPackGetFieldSize(*MsgPackData.MsgPackData)
Procedure MsgPackGetValueDynamicSize(*MsgPackData.MsgPackData)
CompilerIf Not #MsgPack_DisableNullChecks
If Not *MsgPackData
DebuggerError("A #Null MsgPackData pointer was passed !")
ProcedureReturn #MsgPack_Error_NullPointerGiven
EndIf
CompilerEndIf
EndProcedure
Procedure.q MsgPackGetFieldFullSize(*MsgPackData.MsgPackData)
+32 -2
View File
@@ -1,5 +1,30 @@
;{- Code Header
; ==- Basic Info -================================
; Name: _Utils.pbi
; Version: 0.0.0
; Author: Herwin Bozet (NibblePoker)
;
; ==- Compatibility -=============================
; Tested compiler version:
; * //PureBasic 5.73 LTS (x86/x64)
; * //PureBasic 6.21 (x86/x64)
; * //PureBasic 6.21 C Backend (arm64)
;
; ==- Links & License -===========================
; License: CC0 1.0 Universal (Public Domain)
; GitHub: https://github.com/aziascreations/PB-MessagePack
;}
; ------------------------------------------------------------------------------
;- Compiler directive
CompilerIf #PB_Compiler_IsMainFile
EnableExplicit
CompilerEndIf
XIncludeFile "./_Commons.pbi"
; ------------------------------------------------------------------------------
@@ -9,6 +34,8 @@
;-> Format Codes
Procedure.MsgPack_FormatCode MsgPackGetFormatCode(*MsgPackData.MsgPackData)
Protected DataFormatCode.MsgPack_FormatCode
If Not *MsgPackData
DebuggerError("A #Null MsgPackData pointer was passed !")
ProcedureReturn #MsgPack_FormatCode_Invalid
@@ -18,7 +45,9 @@ Procedure.MsgPack_FormatCode MsgPackGetFormatCode(*MsgPackData.MsgPackData)
DebuggerError("End of buffer reached, cannot check data format code !")
ProcedureReturn #MsgPack_FormatCode_Invalid
EndIf
DataFormatCode = PeekA(*MsgPackData\Buffer)
If DataFormatCode < $80
; 0x00 - 0x7F
ProcedureReturn #MsgPack_FormatCode_FixIntPositive
@@ -107,7 +136,8 @@ Procedure.MsgPack_DataType MsgPackFormatCodeToDataType(FormatCode.MsgPack_Format
Case #MsgPack_FormatCode_Invalid:
Default:
DebuggerError("FIXME: ADD MESSAGE HERE !!!")
; FIXME: ADD MESSAGE HERE !!!
DebuggerWarning("")
ProcedureReturn #MsgPack_DataTypes_Unknown
EndSelect
EndProcedure
@@ -0,0 +1,20 @@
EnableExplicit
XIncludeFile "../../Includes/MessagePack.pbi"
Define *MPack.MsgPackData = MsgPackCreate(1)
; Forcing overgrowth
*MPack\BufferGrowthIncrements = 128
MsgPackWriteUInt16(*MPack, $4267)
MsgPackWriteUInt16(*MPack, EndianSwapU($4267))
DeleteFile("./test.mpack")
CreateFile(0, "./test.mpack")
Define *Buffer = MsgPackFinalize(*MPack)
WriteData(0, *Buffer, 6)
CloseFile(0)
+7
View File
@@ -0,0 +1,7 @@
import msgpack
with open("./test.mpack", "rb") as f:
for value in msgpack.Unpacker(f):
print(hex(value))
input()
+1
View File
@@ -0,0 +1 @@
msgpack==1.2.3