コード例 #1
0
        public Guid ArrBinaryUUID()
        {
            var protoUUID = new UUIDbin {
                BinValue = ByteString.CopyFrom(src.ToByteArray())
            };
            var bytes      = protoUUID.ToByteArray();
            var contructed = new UUIDbin();

            contructed.MergeFrom(bytes);
            return(new Guid(contructed.BinValue.ToByteArray()));
        }
コード例 #2
0
        public Guid SpanBinaryUUID()
        {
            Span <byte> guidBuf = stackalloc byte[16];
            Span <byte> serializedDataMemorySrc = stackalloc byte[32];

            if (!src.TryWriteBytes(guidBuf))
            {
                throw new Exception();
            }
            var protoUUID = new UUIDbin {
                BinValue = ByteString.CopyFrom(guidBuf)
            };
            Span <byte> bytes = serializedDataMemorySrc.Slice(0, protoUUID.CalculateSize());

            //var bytes = protoUUID.ToByteArray();
            protoUUID.WriteTo(bytes);
            var contructed = new UUIDbin();

            contructed.MergeFrom(ByteString.CopyFrom(bytes));
            return(new Guid(contructed.BinValue.Span));
        }