github.com/hsfzxjy/dgo/go@v0.2.0/dart_callback.go (about) 1 package dgo 2 3 const ( 4 callbackIdBits = 32 5 callbackIdMask = (uint64(1) << 32) - 1 6 ) 7 8 type rawDartCallback interface{ ~uint32 } 9 10 type DartCallback struct { 11 id uint64 // Id (32 bits) 12 port *Port 13 } 14 15 func (dcb DartCallback) specialInt() {} 16 17 func WrapDartCallback[T rawDartCallback](rcb T, port *Port) DartCallback { 18 port = portMap.ResolvePort(port) 19 return DartCallback{uint64(rcb), port} 20 } 21 22 func (dcb DartCallback) Flag(cf CallbackFlag) CallableDartCallback { 23 if dcb.port == nil { 24 panic("dgo:go: dart callback with zero value found, maybe uninitialized") 25 } 26 return CallableDartCallback{uint64(cf) | dcb.id, dcb.port} 27 } 28 29 type CallableDartCallback struct { 30 payload uint64 // Flag (16 bits) | Id (32 bits) 31 port *Port 32 } 33 34 func (dcb CallableDartCallback) specialInt() {} 35 func (dcb CallableDartCallback) getPayload() uint64 { return dcb.payload } 36 func (dcb CallableDartCallback) getKind() _SpecialIntKind { return sikDartCallback } 37 func (dcb CallableDartCallback) serialize() uint64 { return serialize(dcb.getKind(), dcb.getPayload()) }