Comments (4)
Hey @tuaris. Could you please show your type transformer and the messagepack data you try to unpack?
from msgpack.php.
This is the type transformer:
final class MsgpackLiteJsDateTransformer implements \MessagePack\TypeTransformer\Unpackable {
public function getType(): int {
return 5;
}
public function unpack(\MessagePack\BufferUnpacker $unpacker, int $extLength): \DateTimeImmutable {
return \DateTimeImmutable::createFromFormat('U', $unpacker->unpackInt());
}
}
The data I'm trying to unpack is generated by this library: https://github.com/tinylib/msgp:
type Event struct {
Timestamp int64 `json:"timestamp" msg:"timestamp"`
Message string `json:"message,omitempty" msg:"message"`
}
func NewEvent() *Event {
return &Event{
Timestamp: time.Now().UnixNano(),
Message: "A message",
}
}
from msgpack.php.
Could you provide a full go script or data it generates? (from your example I don't see how you wrap event timestamps into extensions). I tried this (which obviously doesn't utilize msgpack extensions):
package main
import (
"fmt"
"time"
)
//go:generate msgp
type Event struct {
Timestamp int64 `json:"timestamp" msg:"timestamp"`
Message string `json:"message,omitempty" msg:"message"`
}
func NewEvent() *Event {
return &Event{
Timestamp: time.Now().UnixNano(),
Message: "A message",
}
}
func main() {
data, err := NewEvent().MarshalMsg(nil)
if err != nil {
panic(err)
}
fmt.Printf("Event is encoded as %x\n", data)
}
which outputs
Event is encoded as 82a974696d657374616d70d3156db5a268337dfba76d657373616765a941206d657373616765
Php script:
$packed = hex2bin('82a974696d657374616d70d3156db5fdd07481c9a76d657373616765a941206d657373616765');
$unpacker = new BufferUnpacker($packed);
var_dump($unpacker->unpack());
Output:
array(2) {
'timestamp' =>
int(1544090348986597833)
'message' =>
string(9) "A message"
}
from msgpack.php.
Closing as there is no feedback.
from msgpack.php.
Related Issues (14)
- Use generators for unpackArray/unpackMap HOT 4
- Add packer flags to disable utf8/bin and array/map auto-detection
- Add an ability to pack to single-precision floats
- Add support for the timestamp extension HOT 2
- tryUnpack - how do you know when to return while streaming HOT 2
- Bump minimum PHP version requirement to 7.x
- Optimize packing map keys
- Do you know the folks doing the PHP C module? HOT 4
- Installing without composer HOT 1
- PHP 8 support HOT 5
- Use array_is_list() for detecting array/map HOT 2
- Consider making PackOptions::FORCE_STR the default option
- Inline BufferUnpacker::ensureLength() and compare perf
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgpack.php.